Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Any ideas on how to make my segment extraction code given a mesh and its segments faster?

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Any ideas on how to make my segment extraction code given a mesh and its segments faster?


Chronological Thread 
  • From: "Sebastien Loriot (GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] Any ideas on how to make my segment extraction code given a mesh and its segments faster?
  • Date: Wed, 14 Feb 2018 16:48:31 +0100
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:rKIDDRK3k2aF1TgCwdmcpTZWNBhigK39O0sv0rFitYgeIvTxwZ3uMQTl6Ol3ixeRBMOHs6sC07KempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffxhEiCChbb9uMR67sRjfus4KjIV4N60/0AHJonxGe+RXwWNnO1eelAvi68mz4ZBu7T1et+ou+MBcX6r6eb84TaFDAzQ9L281/szrugLdQgaJ+3ART38ZkhtMAwjC8RH6QpL8uTb0u+ZhxCWXO9D9QrcoVDms7apmRgbkhDsIOjUk9G3aitB8gKddrRm8pRJw3pTUbZmIOvRgcKPTfdAUS2RPUcleVSNOHoyyYpATD+cDJ+tUs5XxqlUMoBa4GAKiBPnvyjhNhnLu06E0zvouHhrc0ww7A9IOsWrbrNPoP6kUVuC11qjIzTLfb/hL3Tvz6ZbHchckof6SQbJwa8rQx0k1GAzZklWQrpblPjOQ2ugDrmOW6PFgVeaoi249qgFxpSSvyt0pionNnY8VxVXE+j94wIYxP9G3VEl7Ydu9HZZWqiqUOYx2QsY4TGFpviY30rsGtoSgcycRzJQo2QTTZOCAc4iN+h7sSOmRLi18hH5/f7K/nRmy/E69weP/Tsm5yFRHoyVfntXRqHwA1wbf58uZRvdn/kqtxy6D2gLQ5+1eP0w5mqvWJ4Q8zrM0mJcfq0bOEy/wlU7rlqGZbF8k9fKt6+n/YrXpuJucN4hshwH7KKsum8i/Df02MwgLQ2SX4Oq82b398UHjT7VKifo2kqbdsJ/EP8gUuqm5AwpN3oYi7RawESum3cwakHQINl5JZQyLgojzN1zNPvz0F/eyj0q0nDdu3f/GP7nhApvXLnjElbfsZa1960pbyAopzNBf4I5UBqsEIPL3QULxu9nYAQU4Mwyw2eroFNJ91oYGVWKVHqCZKL/SsUOP5u83P+aMa5UauDLkJ/c45v7ulmM2mUIGfamyxpYXc3C5HvF+I0qDe3bsg9EBEX0LvgUkVuDqhkeCAnZvYCO5UKs4oz06E4m7FpzrR4a3gbXH0j3oMIdRYzUMMV2GGGz0doiCE9MLciOVPochvTEDULW9UZ4P3BqysxXrivAvevHQ/TcZso6l0dxd6OjalBV0/jtxWZfOm1qRRn15yztbDwQ927py9BElkwbR4e1Dm/VdUOdrybZMWwY+O4TbyrUjWd/3UwPFONyOTQT/G4n0MXQKVts0huQ2TQNlAdz710LM2iOrB/kekLnZXMVpoJKZ5GD4IoNG81iD1KQliAN7EM5GNGnjmasnsgaOXcjGlEKWk6vsfqMZjnbA

The user manual of the package was updated some time ago and we now
mention as way to extract each segment into a mesh:

https://doc.cgal.org/latest/Surface_mesh_segmentation/Surface_mesh_segmentation_2extract_segmentation_into_mesh_example_8cpp-example.html

Sebastien.

On 02/13/2018 04:15 PM, Iasonm wrote:
I am trying to make the following code faster. Initializing the size of
points and faces would make the code faster but is there a way to know the
number of unique vertices of a segment without traversing its faces? Any
other ideas are welcomed..

const auto &segmentMap = m_segmentFaceMap; //the output of the sdf
segmentation algorithm
std::vector<Kernel::Point_3> points;
std::vector<std::vector&lt;size_t>> faces;
for (CGALSurfaceMesh::Face_iterator it = M.faces_begin();
it != M.faces_end(); it++) {
CGALSurfaceMesh::Face_index fIndex(*it);
if (segmentMap[fIndex] == segmentIndex) {
CGALSurfaceMesh::Halfedge_index h =
M.halfedge(fIndex);

CGALSurfaceMesh::Vertex_index v1; //= M.source(h);
CGALSurfaceMesh::Vertex_index v2; //= M.target(h);
CGALSurfaceMesh::Vertex_index v3; //=
M.target(hNext);

auto vri = M.vertices_around_face(h);
v1 = *vri.begin();
v2 = *(++vri.begin());
v3 = *(++++vri.begin());

CGALSurfaceMesh::Point p1(M.point(v1));
CGALSurfaceMesh::Point p2(M.point(v2));
CGALSurfaceMesh::Point p3(M.point(v3));

size_t i1 = std::distance(
points.begin(),
std::find(points.begin(), points.end(), p1));
//find index of p1
if (i1 == points.size()) { //if p1 does not exist in
points add it and update its index
points.push_back(p1);
i1 = points.size() - 1;
}

size_t i2 = std::distance(
points.begin(),
std::find(points.begin(), points.end(), p2));
//same as p1
if (i2 == points.size()) {
points.push_back(p2);
i2 = points.size() - 1;
}

size_t i3 = std::distance(
points.begin(),
std::find(points.begin(), points.end(), p3));
//same as p1
if (i3 == points.size()) {
points.push_back(p3);
i3 = points.size() - 1;
}

std::vector<size_t> face{i1, i2, i3};
faces.push_back(face);
}
}
CGALSurfaceMesh outputMesh;
CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(
points, faces, outputMesh);
return outputMesh;




--
Sent from: http://cgal-discuss.949826.n4.nabble.com/




Archive powered by MHonArc 2.6.18.

Top of Page