diff --git a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/CMakeLists.txt b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/CMakeLists.txt index a2b1f926b21..646c604e206 100644 --- a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/CMakeLists.txt +++ b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/CMakeLists.txt @@ -26,8 +26,10 @@ if ( CGAL_FOUND ) create_single_source_cgal_program( "simple_mcfskel_example.cpp" ) create_single_source_cgal_program( "simple_mcfskel_sm_example.cpp" ) + create_single_source_cgal_program( "simple_mcfskel_LCC_example.cpp" ) create_single_source_cgal_program( "MCF_Skeleton_example.cpp" ) create_single_source_cgal_program( "MCF_Skeleton_sm_example.cpp" ) + create_single_source_cgal_program( "MCF_Skeleton_LCC_example.cpp" ) create_single_source_cgal_program( "segmentation_example.cpp" ) else() message(STATUS "These programs require the Eigen library (3.2 or greater), and will not be compiled.") diff --git a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/MCF_Skeleton_LCC_example.cpp b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/MCF_Skeleton_LCC_example.cpp new file mode 100644 index 00000000000..070d52102e6 --- /dev/null +++ b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/MCF_Skeleton_LCC_example.cpp @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include + +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point; + +typedef CGAL::Linear_cell_complex_traits<3, Kernel> MyTraits; + +struct Myitem +{ + template + struct Dart_wrapper + { + typedef CGAL::Tag_true Darts_with_id; + typedef CGAL::Cell_attribute_with_point_and_id< Refs > Vertex_attribute; + typedef CGAL::Cell_attribute_with_id< Refs > Face_attribute; + typedef CGAL::cpp11::tuple Attributes; + }; +}; + +typedef CGAL::Linear_cell_complex_for_combinatorial_map<2, 3, MyTraits, Myitem> LCC; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; + +typedef CGAL::Mean_curvature_flow_skeletonization Skeletonization; +typedef Skeletonization::Skeleton Skeleton; + +typedef Skeleton::vertex_descriptor Skeleton_vertex; +typedef Skeleton::edge_descriptor Skeleton_edge; + + +int main(int argc, char* argv[]) +{ + LCC lcc; + CGAL::load_off_v2(lcc, "data/elephant.off"); + + Skeleton skeleton; + Skeletonization mcs(lcc); + + // 1. Contract the mesh by mean curvature flow. + mcs.contract_geometry(); + + // 2. Collapse short edges and split bad triangles. + mcs.collapse_edges(); + mcs.split_faces(); + + // 3. Fix degenerate vertices. + mcs.detect_degeneracies(); + + // Perform the above three steps in one iteration. + mcs.contract(); + + // Iteratively apply step 1 to 3 until convergence. + mcs.contract_until_convergence(); + + // Convert the contracted mesh into a curve skeleton and + // get the correspondent surface points + mcs.convert_to_skeleton(skeleton); + + std::cout << "Number of vertices of the skeleton: " << boost::num_vertices(skeleton) << "\n"; + std::cout << "Number of edges of the skeleton: " << boost::num_edges(skeleton) << "\n"; + + // Output all the edges of the skeleton. + std::ofstream output("skel-lcc.cgal"); + BOOST_FOREACH(Skeleton_edge e, edges(skeleton)) + { + const Point& s = skeleton[source(e, skeleton)].point; + const Point& t = skeleton[target(e, skeleton)].point; + output << "2 "<< s << " " << t << "\n"; + } + output.close(); + + // Output skeleton points and the corresponding surface points + output.open("correspondance-lcc.cgal"); + BOOST_FOREACH(Skeleton_vertex v, vertices(skeleton)) + BOOST_FOREACH(vertex_descriptor vd, skeleton[v].vertices) + output << "2 " << skeleton[v].point << " " << get(CGAL::vertex_point, lcc, vd) << "\n"; + + return 0; +} + diff --git a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/MCF_Skeleton_example.cpp b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/MCF_Skeleton_example.cpp index 7206f93d026..34f0d564751 100644 --- a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/MCF_Skeleton_example.cpp +++ b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/MCF_Skeleton_example.cpp @@ -52,7 +52,7 @@ int main(int argc, char* argv[]) std::cout << "Number of edges of the skeleton: " << boost::num_edges(skeleton) << "\n"; // Output all the edges of the skeleton. - std::ofstream output("skel.cgal"); + std::ofstream output("skel-poly.cgal"); BOOST_FOREACH(Skeleton_edge e, edges(skeleton)) { const Point& s = skeleton[source(e, skeleton)].point; @@ -62,7 +62,7 @@ int main(int argc, char* argv[]) output.close(); // Output skeleton points and the corresponding surface points - output.open("correspondance.cgal"); + output.open("correspondance-poly.cgal"); BOOST_FOREACH(Skeleton_vertex v, vertices(skeleton)) BOOST_FOREACH(vertex_descriptor vd, skeleton[v].vertices) output << "2 " << skeleton[v].point << " " << get(CGAL::vertex_point, tmesh, vd) << "\n"; diff --git a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/MCF_Skeleton_sm_example.cpp b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/MCF_Skeleton_sm_example.cpp index 6df14b3fd31..61595e87052 100644 --- a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/MCF_Skeleton_sm_example.cpp +++ b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/MCF_Skeleton_sm_example.cpp @@ -51,7 +51,7 @@ int main(int argc, char* argv[]) std::cout << "Number of edges of the skeleton: " << boost::num_edges(skeleton) << "\n"; // Output all the edges of the skeleton. - std::ofstream output("skel.cgal"); + std::ofstream output("skel-sm.cgal"); BOOST_FOREACH(Skeleton_edge e, edges(skeleton)) { const Point& s = skeleton[source(e, skeleton)].point; @@ -61,7 +61,7 @@ int main(int argc, char* argv[]) output.close(); // Output skeleton points and the corresponding surface points - output.open("correspondance.cgal"); + output.open("correspondance-sm.cgal"); BOOST_FOREACH(Skeleton_vertex v, vertices(skeleton)) BOOST_FOREACH(vertex_descriptor vd, skeleton[v].vertices) output << "2 " << skeleton[v].point << " " << get(CGAL::vertex_point, tmesh, vd) << "\n"; diff --git a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/simple_mcfskel_LCC_example.cpp b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/simple_mcfskel_LCC_example.cpp new file mode 100644 index 00000000000..fd5be7360d6 --- /dev/null +++ b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/simple_mcfskel_LCC_example.cpp @@ -0,0 +1,92 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point; +typedef CGAL::Linear_cell_complex_traits<3, Kernel> MyTraits; + +struct Myitem +{ + template + struct Dart_wrapper + { + typedef CGAL::Tag_true Darts_with_id; + typedef CGAL::Cell_attribute_with_point_and_id< Refs > Vertex_attribute; + typedef CGAL::Cell_attribute_with_id< Refs > Face_attribute; + typedef CGAL::cpp11::tuple Attributes; + }; +}; + +typedef CGAL::Linear_cell_complex_for_combinatorial_map<2, 3, MyTraits, Myitem> LCC; + +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; + +typedef CGAL::Mean_curvature_flow_skeletonization Skeletonization; +typedef Skeletonization::Skeleton Skeleton; + +typedef Skeleton::vertex_descriptor Skeleton_vertex; +typedef Skeleton::edge_descriptor Skeleton_edge; + +//only needed for the display of the skeleton as maximal polylines +struct Display_polylines{ + const Skeleton& skeleton; + std::ofstream& out; + int polyline_size; + std::stringstream sstr; + + Display_polylines(const Skeleton& skeleton, std::ofstream& out) + : skeleton(skeleton), out(out) + {} + + void start_new_polyline(){ + polyline_size=0; + sstr.str(""); + sstr.clear(); + } + void add_node(Skeleton_vertex v){ + ++polyline_size; + sstr << " " << skeleton[v].point; + } + void end_polyline() + { + out << polyline_size << sstr.str() << "\n"; + } +}; + +// This example extracts a medially centered skeleton from a given mesh. +int main(int argc, char* argv[]) +{ + LCC lcc; + CGAL::load_off_v2(lcc, "data/elephant.off"); + + Skeleton skeleton; + + CGAL::extract_mean_curvature_flow_skeleton(lcc, skeleton); + + std::cout << "Number of vertices of the skeleton: " << boost::num_vertices(skeleton) << "\n"; + std::cout << "Number of edges of the skeleton: " << boost::num_edges(skeleton) << "\n"; + + // Output all the edges of the skeleton. + std::ofstream output("skel-lcc.cgal"); + Display_polylines display(skeleton,output); + CGAL::split_graph_into_polylines(skeleton, display); + output.close(); + + // Output skeleton points and the corresponding surface points + output.open("correspondance-lcc.cgal"); + BOOST_FOREACH(Skeleton_vertex v, vertices(skeleton)) + BOOST_FOREACH(vertex_descriptor vd, skeleton[v].vertices) + output << "2 " << skeleton[v].point << " " + << get(CGAL::vertex_point, lcc, vd) << "\n"; + + return 0; +} + diff --git a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/simple_mcfskel_example.cpp b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/simple_mcfskel_example.cpp index c21af6dc5b3..9234c753d53 100644 --- a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/simple_mcfskel_example.cpp +++ b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/simple_mcfskel_example.cpp @@ -62,13 +62,13 @@ int main(int argc, char* argv[]) std::cout << "Number of edges of the skeleton: " << boost::num_edges(skeleton) << "\n"; // Output all the edges of the skeleton. - std::ofstream output("skel.cgal"); + std::ofstream output("skel-poly.cgal"); Display_polylines display(skeleton,output); CGAL::split_graph_into_polylines(skeleton, display); output.close(); // Output skeleton points and the corresponding surface points - output.open("correspondance.cgal"); + output.open("correspondance-poly.cgal"); BOOST_FOREACH(Skeleton_vertex v, vertices(skeleton)) BOOST_FOREACH(vertex_descriptor vd, skeleton[v].vertices) output << "2 " << skeleton[v].point << " " diff --git a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/simple_mcfskel_sm_example.cpp b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/simple_mcfskel_sm_example.cpp index 2b6a52ce52f..ab328e5988a 100644 --- a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/simple_mcfskel_sm_example.cpp +++ b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/simple_mcfskel_sm_example.cpp @@ -36,7 +36,7 @@ int main(int argc, char* argv[]) std::cout << "Number of edges of the skeleton: " << boost::num_edges(skeleton) << "\n"; // Output all the edges of the skeleton. - std::ofstream output("skel.cgal"); + std::ofstream output("skel-sm.cgal"); BOOST_FOREACH(Skeleton_edge e, edges(skeleton)) { const Point& s = skeleton[source(e, skeleton)].point; @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) output.close(); // Output skeleton points and the corresponding surface points - output.open("correspondance.cgal"); + output.open("correspondance-sm.cgal"); BOOST_FOREACH(Skeleton_vertex v, vertices(skeleton)) BOOST_FOREACH(vertex_descriptor vd, skeleton[v].vertices) output << "2 " << skeleton[v].point << " " << get(CGAL::vertex_point, tmesh, vd) << "\n"; diff --git a/TODO-some-files-cgal-bgl.txt b/TODO-some-files-cgal-bgl.txt index fd085e6fe5d..0a4345e8b48 100644 --- a/TODO-some-files-cgal-bgl.txt +++ b/TODO-some-files-cgal-bgl.txt @@ -19,8 +19,15 @@ Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_l ./Surface_mesh_segmentation/examples/Surface_mesh_segmentation/segmentation_from_sdf_values_LCC_example.cpp +./Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/MCF_Skeleton_LCC_example.cpp +./Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/simple_mcfskel_LCC_example.cpp + + Les 3 versions donnent un résultat différent !! + ============================================= +TODO + ./Polygon_mesh_processing/examples/Polygon_mesh_processing/corefinement_LCC.cpp Compile pas @@ -30,8 +37,3 @@ Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_l Compile pas ============================================= - - TODO - -./Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/MCF_Skeleton_sm_example.cpp -./Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/simple_mcfskel_sm_example.cpp