Skip to content

Commit 849027d

Browse files
committed
store also the radii of the skeleton
1 parent 5145b34 commit 849027d

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

AdTree/tree_viewer.cpp

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,8 @@ void TreeViewer::export_skeleton() const {
216216
return;
217217
}
218218

219-
#if 0
219+
#if 0 // save the simplified skeleton, for which each edge can have a radius.
220220
const ::Graph& skeleton = skeleton_->get_simplified_skeleton();
221-
#else
222-
const ::Graph& skeleton = skeleton_->get_smoothed_skeleton();
223-
#endif
224-
225221
if (boost::num_edges(skeleton) == 0) {
226222
std::cerr << "skeleton has 0 edges" << std::endl;
227223
return;
@@ -247,12 +243,54 @@ void TreeViewer::export_skeleton() const {
247243
}
248244
}
249245

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+
250284
auto egs = boost::edges(skeleton);
251285
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+
252289
SGraphVertexDescriptor s = boost::source(*iter, skeleton);
253290
SGraphVertexDescriptor t = boost::target(*iter, skeleton);
254291
g.add_edge(vvmap[s], vvmap[t]);
255292
}
293+
#endif
256294

257295
auto offset = cloud()->get_model_property<dvec3>("translation");
258296
if (offset) {

0 commit comments

Comments
 (0)