44 #include <ObjectTypes/PolyLine/PolyLineCircleData.hh> 45 #include <ObjectTypes/PolyLine/PolyLineBezierSplineData.hh> 47 PolyLineObjectSerializer::PolyLineObjectSerializer(
PolyLineObject* _object)
52 void PolyLineObjectSerializer::serialize(std::ostream& _stream) {
53 std::ostream& fout = _stream;
54 PolyLine& _polyLine = *instance->line();
56 fout << _polyLine.
is_closed() << std::endl;
62 std::cerr <<
"#points: " << _polyLine.
n_vertices() << std::endl;
67 for(
unsigned int i=0; i< _polyLine.
n_vertices(); ++i)
70 const PolyLine::Point& current_point = _polyLine.
point(i);
71 fout << current_point[0] <<
" ";
72 fout << current_point[1] <<
" ";
73 fout << current_point[2] << std::endl;
76 fout <<
"VERTEXRADIUS" << std::endl << _polyLine.
vertex_radius() << std::endl;
77 fout <<
"EDGERADIUS" << std::endl << _polyLine.
edge_radius() << std::endl;
83 if(_polyLine.vertex_vhandles_available())
85 fout <<
"VVHANDLES" << std::endl;
86 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
87 fout << _polyLine.vertex_vhandle(i) << std::endl;
90 if(_polyLine.vertex_ehandles_available())
92 fout <<
"VEHANDLES" << std::endl;
93 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
94 fout << _polyLine.vertex_ehandle(i) << std::endl;
97 if(_polyLine.vertex_fhandles_available())
99 fout <<
"VFHANDLES" << std::endl;
100 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
101 fout << _polyLine.vertex_fhandle(i) << std::endl;
104 if(_polyLine.vertex_scalars_available())
106 fout <<
"VSCALARS" << std::endl;
107 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
108 fout << _polyLine.vertex_scalar(i) << std::endl;
111 if(_polyLine.vertex_normals_available())
113 fout <<
"VNORMALS" << std::endl;
114 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
116 const PolyLine::Point& current_vnormal = _polyLine.vertex_normal(i);
117 fout << current_vnormal[0] <<
" ";
118 fout << current_vnormal[1] <<
" ";
119 fout << current_vnormal[2] << std::endl;
123 if(_polyLine.vertex_binormals_available())
125 fout <<
"VBINORMALS" << std::endl;
126 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
128 const PolyLine::Point& current_bnormal = _polyLine.vertex_binormal(i);
129 fout << current_bnormal[0] <<
" ";
130 fout << current_bnormal[1] <<
" ";
131 fout << current_bnormal[2] << std::endl;
137 fout <<
"CIRCLEDATA" << std::endl;
138 fout << circleData->circleCenter_ << std::endl;
139 fout << circleData->circleMainAxis_ << std::endl;
140 fout << circleData->circleMainRadius_ << std::endl;
141 fout << circleData->circleNormal_ << std::endl;
142 fout << circleData->circleSideAxis_ << std::endl;
143 fout << circleData->circleSideRadius_ << std::endl;
148 fout <<
"SPLINEDATA" << std::endl;
149 fout << (
unsigned int)splineData->points_.size() << std::endl;
150 for(
unsigned int i = 0; i < splineData->points_.size(); i++) {
151 fout << splineData->points_[i].normal << std::endl;
152 fout << splineData->points_[i].position << std::endl;
154 fout << (
unsigned int)splineData->handles_.size() << std::endl;
155 for(
unsigned int i = 0; i < splineData->handles_.size(); i++)
156 fout << splineData->handles_[i] << std::endl;
161 void PolyLineObjectSerializer::deserialize(std::istream& _stream) {
162 std::istream& fin = _stream;
163 PolyLine& _polyLine = *instance->line();
178 for(
int i=0; i<num_points; ++i)
180 PolyLine::Point::value_type x,y,z;
184 PolyLine::Point p(x,y,z);
196 if(token ==
"VERTEXRADIUS")
202 else if(token ==
"EDGERADIUS")
208 else if(token ==
"VVHANDLES")
210 if(!_polyLine.vertex_vhandles_available()) _polyLine.request_vertex_vhandles();
211 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
212 fin >> _polyLine.vertex_vhandle(i);
214 else if(token ==
"VEHANDLES")
216 if(!_polyLine.vertex_ehandles_available()) _polyLine.request_vertex_ehandles();
217 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
218 fin >> _polyLine.vertex_ehandle(i);
220 else if(token ==
"VFHANDLES")
222 if(!_polyLine.vertex_fhandles_available()) _polyLine.request_vertex_fhandles();
223 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
224 fin >> _polyLine.vertex_fhandle(i);
226 else if(token ==
"VSCALARS")
228 if(!_polyLine.vertex_scalars_available()) _polyLine.request_vertex_scalars();
229 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
230 fin >> _polyLine.vertex_scalar(i);
232 else if(token ==
"VNORMALS")
234 if(!_polyLine.vertex_normals_available()) _polyLine.request_vertex_normals();
235 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
237 fin >> _polyLine.vertex_normal(i)[0];
238 fin >> _polyLine.vertex_normal(i)[1];
239 fin >> _polyLine.vertex_normal(i)[2];
242 else if(token ==
"VBINORMALS")
244 if(!_polyLine.vertex_binormals_available()) _polyLine.request_vertex_binormals();
245 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
247 fin >> _polyLine.vertex_binormal(i)[0];
248 fin >> _polyLine.vertex_binormal(i)[1];
249 fin >> _polyLine.vertex_binormal(i)[2];
252 else if(token ==
"CIRCLEDATA") {
262 instance->setObjectData(CIRCLE_DATA, circleData);
264 else if(token ==
"SPLINEDATA") {
266 unsigned int pointCount, handleCount;
269 for(
unsigned int i = 0; i < pointCount; i++) {
271 fin >> point.position;
272 splineData->points_.push_back(point);
275 for(
unsigned int i = 0; i < handleCount; i++) {
276 fin >> point.position;
277 splineData->handles_.push_back(point.position);
279 instance->setObjectData(BEZSPLINE_DATA, splineData);
281 else if(token !=
"")
break;
void set_edge_radius(const Scalar _r)
set cylinder-radius of edges
void add_point(const Point &_p)
Append a point to the polyline.
void set_vertex_radius(const Scalar _r)
set ball-radius of vertices
Scalar vertex_radius() const
get ball-radius of vertices
Point & point(unsigned int _i)
Get a point of the polyline.
size_t n_vertices() const
Get number of vertices.
void set_closed(const bool _c)
Set if the polyline should be closed and therefore forms a loop.
void clear()
Clear the current polyline.
bool is_closed() const
Check if the polyline is marked as closed.
Scalar edge_radius() const
get cylinder-radius of edges