@@ -216,12 +216,8 @@ void TreeViewer::export_skeleton() const {
216
216
return ;
217
217
}
218
218
219
- #if 0
219
+ #if 0 // save the simplified skeleton, for which each edge can have a radius.
220
220
const ::Graph& skeleton = skeleton_->get_simplified_skeleton();
221
- #else
222
- const ::Graph& skeleton = skeleton_->get_smoothed_skeleton ();
223
- #endif
224
-
225
221
if (boost::num_edges(skeleton) == 0) {
226
222
std::cerr << "skeleton has 0 edges" << std::endl;
227
223
return;
@@ -247,12 +243,54 @@ void TreeViewer::export_skeleton() const {
247
243
}
248
244
}
249
245
246
+ auto egs = boost::edges(skeleton);
247
+ auto edgeRadius = g.add_edge_property<float>("e:radius");
248
+ for (SGraphEdgeIterator iter = egs.first; iter != egs.second; ++iter) {
249
+ SGraphVertexDescriptor s = boost::source(*iter, skeleton);
250
+ SGraphVertexDescriptor t = boost::target(*iter, skeleton);
251
+ auto e = g.add_edge(vvmap[s], vvmap[t]);
252
+ edgeRadius[e] = skeleton[*iter].nRadius;
253
+ }
254
+ #else // save the smoothed skeleton, for which each very has a radius.
255
+ const ::Graph& skeleton = skeleton_->get_smoothed_skeleton ();
256
+ if (boost::num_edges (skeleton) == 0 ) {
257
+ std::cerr << " skeleton has 0 edges" << std::endl;
258
+ return ;
259
+ }
260
+
261
+ const std::vector<std::string> filetypes = {" *.ply" };
262
+ const std::string& initial_name = file_system::base_name (cloud ()->name ()) + " _skeleton.ply" ;
263
+ const std::string& file_name = FileDialog::save (filetypes, initial_name);
264
+ if (file_name.empty ())
265
+ return ;
266
+
267
+ // convert the boost graph to Graph (avoid modifying easy3d's GraphIO, or writing IO for boost graph)
268
+
269
+ std::unordered_map<SGraphVertexDescriptor, easy3d::Graph::Vertex> vvmap;
270
+ easy3d::Graph g;
271
+
272
+ auto vertexRadius = g.add_vertex_property <float >(" v:radius" );
273
+ auto vts = boost::vertices (skeleton);
274
+ for (SGraphVertexIterator iter = vts.first ; iter != vts.second ; ++iter) {
275
+ SGraphVertexDescriptor vd = *iter;
276
+ if (boost::degree (vd, skeleton) != 0 ) { // ignore isolated vertices
277
+ const vec3& vp = skeleton[vd].cVert ;
278
+ auto v = g.add_vertex (vp);
279
+ vertexRadius[v] = skeleton[vd].radius ;
280
+ vvmap[vd] = v;
281
+ }
282
+ }
283
+
250
284
auto egs = boost::edges (skeleton);
251
285
for (SGraphEdgeIterator iter = egs.first ; iter != egs.second ; ++iter) {
286
+ SGraphEdgeDescriptor ed = *iter; // the edge descriptor
287
+ SGraphEdgeProp ep = skeleton[ed]; // the edge property
288
+
252
289
SGraphVertexDescriptor s = boost::source (*iter, skeleton);
253
290
SGraphVertexDescriptor t = boost::target (*iter, skeleton);
254
291
g.add_edge (vvmap[s], vvmap[t]);
255
292
}
293
+ #endif
256
294
257
295
auto offset = cloud ()->get_model_property <dvec3>(" translation" );
258
296
if (offset) {
0 commit comments