Ok for Surface_mesh_skeletonization for BGL LCC

This commit is contained in:
Guillaume Damiand 2017-03-31 10:34:49 -04:00
parent d7e40dc40d
commit 73adec542f
8 changed files with 194 additions and 13 deletions

View File

@ -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.")

View File

@ -0,0 +1,85 @@
#include <CGAL/Linear_cell_complex_for_combinatorial_map.h>
#include <CGAL/Linear_cell_complex_incremental_builder_v2.h>
#include <CGAL/boost/graph/graph_traits_Linear_cell_complex.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Mean_curvature_flow_skeletonization.h>
#include <fstream>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point;
typedef CGAL::Linear_cell_complex_traits<3, Kernel> MyTraits;
struct Myitem
{
template<class Refs>
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<Vertex_attribute, void, Face_attribute> Attributes;
};
};
typedef CGAL::Linear_cell_complex_for_combinatorial_map<2, 3, MyTraits, Myitem> LCC;
typedef boost::graph_traits<LCC>::vertex_descriptor vertex_descriptor;
typedef CGAL::Mean_curvature_flow_skeletonization<LCC> 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;
}

View File

@ -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";

View File

@ -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";

View File

@ -0,0 +1,92 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Linear_cell_complex_for_combinatorial_map.h>
#include <CGAL/Linear_cell_complex_incremental_builder_v2.h>
#include <CGAL/boost/graph/graph_traits_Linear_cell_complex.h>
#include <CGAL/boost/graph/properties_Linear_cell_complex.h>
#include <CGAL/extract_mean_curvature_flow_skeleton.h>
#include <CGAL/boost/graph/split_graph_into_polylines.h>
#include <fstream>
#include <boost/foreach.hpp>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point;
typedef CGAL::Linear_cell_complex_traits<3, Kernel> MyTraits;
struct Myitem
{
template<class Refs>
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<Vertex_attribute, void, Face_attribute> Attributes;
};
};
typedef CGAL::Linear_cell_complex_for_combinatorial_map<2, 3, MyTraits, Myitem> LCC;
typedef boost::graph_traits<LCC>::vertex_descriptor vertex_descriptor;
typedef CGAL::Mean_curvature_flow_skeletonization<LCC> 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;
}

View File

@ -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 << " "

View File

@ -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";

View File

@ -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