52 #include <ObjectTypes/PolyLine/PolyLineCircleData.hh> 53 #include <ObjectTypes/PolyLine/PolyLineBezierSplineData.hh> 55 PolyLineObjectSerializer::PolyLineObjectSerializer(
PolyLineObject* _object)
60 void PolyLineObjectSerializer::serialize(std::ostream& _stream) {
61 std::ostream& fout = _stream;
62 PolyLine& _polyLine = *instance->line();
64 fout << _polyLine.
is_closed() << std::endl;
70 std::cerr <<
"#points: " << _polyLine.
n_vertices() << std::endl;
75 for(
unsigned int i=0; i< _polyLine.
n_vertices(); ++i)
78 const PolyLine::Point& current_point = _polyLine.
point(i);
79 fout << current_point[0] <<
" ";
80 fout << current_point[1] <<
" ";
81 fout << current_point[2] << std::endl;
84 fout <<
"VERTEXRADIUS" << std::endl << _polyLine.
vertex_radius() << std::endl;
85 fout <<
"EDGERADIUS" << std::endl << _polyLine.
edge_radius() << std::endl;
91 if(_polyLine.vertex_vhandles_available())
93 fout <<
"VVHANDLES" << std::endl;
94 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
95 fout << _polyLine.vertex_vhandle(i) << std::endl;
98 if(_polyLine.vertex_ehandles_available())
100 fout <<
"VEHANDLES" << std::endl;
101 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
102 fout << _polyLine.vertex_ehandle(i) << std::endl;
105 if(_polyLine.vertex_fhandles_available())
107 fout <<
"VFHANDLES" << std::endl;
108 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
109 fout << _polyLine.vertex_fhandle(i) << std::endl;
112 if(_polyLine.vertex_scalars_available())
114 fout <<
"VSCALARS" << std::endl;
115 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
116 fout << _polyLine.vertex_scalar(i) << std::endl;
119 if(_polyLine.vertex_normals_available())
121 fout <<
"VNORMALS" << std::endl;
122 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
124 const PolyLine::Point& current_vnormal = _polyLine.vertex_normal(i);
125 fout << current_vnormal[0] <<
" ";
126 fout << current_vnormal[1] <<
" ";
127 fout << current_vnormal[2] << std::endl;
131 if(_polyLine.vertex_binormals_available())
133 fout <<
"VBINORMALS" << std::endl;
134 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
136 const PolyLine::Point& current_bnormal = _polyLine.vertex_binormal(i);
137 fout << current_bnormal[0] <<
" ";
138 fout << current_bnormal[1] <<
" ";
139 fout << current_bnormal[2] << std::endl;
145 fout <<
"CIRCLEDATA" << std::endl;
146 fout << circleData->circleCenter_ << std::endl;
147 fout << circleData->circleMainAxis_ << std::endl;
148 fout << circleData->circleMainRadius_ << std::endl;
149 fout << circleData->circleNormal_ << std::endl;
150 fout << circleData->circleSideAxis_ << std::endl;
151 fout << circleData->circleSideRadius_ << std::endl;
156 fout <<
"SPLINEDATA" << std::endl;
157 fout << (
unsigned int)splineData->points_.size() << std::endl;
158 for(
unsigned int i = 0; i < splineData->points_.size(); i++) {
159 fout << splineData->points_[i].normal << std::endl;
160 fout << splineData->points_[i].position << std::endl;
162 fout << (
unsigned int)splineData->handles_.size() << std::endl;
163 for(
unsigned int i = 0; i < splineData->handles_.size(); i++)
164 fout << splineData->handles_[i] << std::endl;
169 void PolyLineObjectSerializer::deserialize(std::istream& _stream) {
170 std::istream& fin = _stream;
171 PolyLine& _polyLine = *instance->line();
186 for(
int i=0; i<num_points; ++i)
188 PolyLine::Point::value_type x,y,z;
192 PolyLine::Point p(x,y,z);
204 if(token ==
"VERTEXRADIUS")
210 else if(token ==
"EDGERADIUS")
216 else if(token ==
"VVHANDLES")
218 if(!_polyLine.vertex_vhandles_available()) _polyLine.request_vertex_vhandles();
219 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
220 fin >> _polyLine.vertex_vhandle(i);
222 else if(token ==
"VEHANDLES")
224 if(!_polyLine.vertex_ehandles_available()) _polyLine.request_vertex_ehandles();
225 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
226 fin >> _polyLine.vertex_ehandle(i);
228 else if(token ==
"VFHANDLES")
230 if(!_polyLine.vertex_fhandles_available()) _polyLine.request_vertex_fhandles();
231 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
232 fin >> _polyLine.vertex_fhandle(i);
234 else if(token ==
"VSCALARS")
236 if(!_polyLine.vertex_scalars_available()) _polyLine.request_vertex_scalars();
237 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
238 fin >> _polyLine.vertex_scalar(i);
240 else if(token ==
"VNORMALS")
242 if(!_polyLine.vertex_normals_available()) _polyLine.request_vertex_normals();
243 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
245 fin >> _polyLine.vertex_normal(i)[0];
246 fin >> _polyLine.vertex_normal(i)[1];
247 fin >> _polyLine.vertex_normal(i)[2];
250 else if(token ==
"VBINORMALS")
252 if(!_polyLine.vertex_binormals_available()) _polyLine.request_vertex_binormals();
253 for(
unsigned int i=0; i<_polyLine.
n_vertices(); ++i)
255 fin >> _polyLine.vertex_binormal(i)[0];
256 fin >> _polyLine.vertex_binormal(i)[1];
257 fin >> _polyLine.vertex_binormal(i)[2];
260 else if(token ==
"CIRCLEDATA") {
270 instance->setObjectData(CIRCLE_DATA, circleData);
272 else if(token ==
"SPLINEDATA") {
274 unsigned int pointCount, handleCount;
277 for(
unsigned int i = 0; i < pointCount; i++) {
279 fin >> point.position;
280 splineData->points_.push_back(point);
283 for(
unsigned int i = 0; i < handleCount; i++) {
284 fin >> point.position;
285 splineData->handles_.push_back(point.position);
287 instance->setObjectData(BEZSPLINE_DATA, splineData);
289 else if(token !=
"")
break;
Scalar vertex_radius() const
get ball-radius of vertices
bool is_closed() const
Check if the polyline is marked as closed.
void set_closed(const bool _c)
Set if the polyline should be closed and therefore forms a loop.
void clear()
Clear the current polyline.
void set_vertex_radius(const Scalar _r)
set ball-radius of vertices
void set_edge_radius(const Scalar _r)
set cylinder-radius of edges
Scalar edge_radius() const
get cylinder-radius of edges
Point & point(unsigned int _i)
Get a point of the polyline.
void add_point(const Point &_p)
Append a point to the polyline.
size_t n_vertices() const
Get number of vertices.