From 707e9fcccf11b8dbf79031aa6a4e3ebb67529fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 12 Apr 2013 17:30:48 +0200 Subject: [PATCH] update examples and make them compile on linux --- .../examples/Surface_modeling/CMakeLists.txt | 27 +++++++--- .../all_roi_assign_example.cpp | 51 ++++++++++--------- .../custom_weight_for_edges_example.cpp | 28 +++++----- ...ed_polyhedron_with_custom_pmap_example.cpp | 24 +++++---- .../k_ring_roi_translate_rotate_example.cpp | 43 +++++++++------- 5 files changed, 100 insertions(+), 73 deletions(-) diff --git a/Surface_modeling/examples/Surface_modeling/CMakeLists.txt b/Surface_modeling/examples/Surface_modeling/CMakeLists.txt index 2317567bdef..06c257d5f50 100644 --- a/Surface_modeling/examples/Surface_modeling/CMakeLists.txt +++ b/Surface_modeling/examples/Surface_modeling/CMakeLists.txt @@ -2,9 +2,16 @@ # This is the CMake script for compiling a CGAL application. -project( Surface_modeling_example ) +project( Surface_modeling_ ) cmake_minimum_required(VERSION 2.6.2) +if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) + if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) + cmake_policy(VERSION 2.8.4) + else() + cmake_policy(VERSION 2.6) + endif() +endif() find_package(CGAL QUIET COMPONENTS Core ) @@ -12,15 +19,21 @@ if ( CGAL_FOUND ) include( ${CGAL_USE_FILE} ) - include( CGAL_CreateSingleSourceCGALProgram ) + find_package(Eigen3 3.1.91) #(requires 3.2.0 or greater) + if (EIGEN3_FOUND) + include( ${EIGEN3_USE_FILE} ) + include( CGAL_CreateSingleSourceCGALProgram ) - include_directories (BEFORE ../../include) + include_directories (BEFORE "../../include") - create_single_source_cgal_program( "hello.cpp" ) - create_single_source_cgal_program( "k-ring.cpp" ) - create_single_source_cgal_program( "k-ring_BGL.cpp" ) - create_single_source_cgal_program( "example.cpp" ) + create_single_source_cgal_program( "all_roi_assign_example.cpp" ) + create_single_source_cgal_program( "custom_weight_for_edges_example.cpp" ) + create_single_source_cgal_program( "enriched_polyhedron_with_custom_pmap_example.cpp" ) + create_single_source_cgal_program( "k_ring_roi_translate_rotate_example.cpp" ) + else() + message(STATUS "This program requires the Eigen library, version 3.2 or later and will not be compiled.") + endif() else() message(STATUS "This program requires the CGAL library, and will not be compiled.") diff --git a/Surface_modeling/examples/Surface_modeling/all_roi_assign_example.cpp b/Surface_modeling/examples/Surface_modeling/all_roi_assign_example.cpp index c03decd856a..e372d4fe3f4 100644 --- a/Surface_modeling/examples/Surface_modeling/all_roi_assign_example.cpp +++ b/Surface_modeling/examples/Surface_modeling/all_roi_assign_example.cpp @@ -1,7 +1,6 @@ -#include - -#include #include +#include +#include #include #include @@ -9,15 +8,11 @@ #include #include -#include - -typedef CGAL::Eigen_solver_traits::EigenType> > DefaultSolver; - typedef CGAL::Simple_cartesian Kernel; typedef CGAL::Polyhedron_3 Polyhedron; typedef boost::graph_traits::vertex_descriptor vertex_descriptor; -typedef boost::graph_traits::vertex_iterator vertex_iterator; +typedef boost::graph_traits::vertex_iterator vertex_iterator; typedef boost::graph_traits::edge_descriptor edge_descriptor; typedef std::map Internal_vertex_map; @@ -26,29 +21,36 @@ typedef std::map Internal_edge_map; typedef boost::associative_property_map Vertex_index_map; typedef boost::associative_property_map Edge_index_map; -typedef CGAL::Deform_mesh Deform_mesh; +typedef CGAL::Deform_mesh Deform_mesh; template -Iterator next_helper(Iterator it, std::size_t n) { +Iterator next_helper(Iterator it, std::size_t n) { Iterator it_next = it; while(n-- > 0) { ++it_next; } return it_next; -} +} int main() { Polyhedron mesh; - std::ifstream("models/plane.off") >> mesh; + std::ifstream input("models/plane.off"); + + if (input) + input >> mesh; + else{ + std::cerr<< "Cannot open models/plane.off\n"; + return 1; + } Internal_vertex_map vertex_index_map; Internal_edge_map edge_index_map; //// PREPROCESS SECTION //// - Deform_mesh deform_mesh(mesh, Vertex_index_map(vertex_index_map), Edge_index_map(edge_index_map)); + Deform_mesh deform_mesh(mesh, Vertex_index_map(vertex_index_map), Edge_index_map(edge_index_map)); // insert region of interest vertex_iterator vb, ve; - boost::tie(vb, ve) = boost::vertices(mesh); - + boost::tie(vb, ve) = boost::vertices(mesh); + deform_mesh.insert_roi(vb, ve); // insert whole mesh as roi // insert handles @@ -58,21 +60,21 @@ int main() vertex_descriptor handle_2 = *next_helper(vb, 157); deform_mesh.insert_handle(handles_ref, handle_1); // insert handles - deform_mesh.insert_handle(handles_ref, handle_2); + deform_mesh.insert_handle(handles_ref, handle_2); // insertion of roi and handles completed, call preprocess bool is_matrix_factorization_OK = deform_mesh.preprocess(); - if(!is_matrix_factorization_OK) + if(!is_matrix_factorization_OK) { std::cerr << "Check documentation of preprocess()" << std::endl; } //// DEFORM SECTION //// - // now use assign() to provide constained positions of handles + // now use assign() to provide constained positions of handles Deform_mesh::Point constrained_pos_1(-0.35, 0.40, 0.60); // target position of handle_1 deform_mesh.assign(handle_1, constrained_pos_1); // note that we only assign a constraint for handle_1, other handles will be constained to last assigned positions // deform the mesh, now positions of vertices of 'mesh' will be changed - deform_mesh.deform(); + deform_mesh.deform(); deform_mesh.deform(); // you can call deform multiple times if you like Deform_mesh::Point constrained_pos_2(0.55, -0.30, 0.70); @@ -82,21 +84,24 @@ int main() deform_mesh.deform(10, 0.0); // deform(unsigned int iterations, double tolerance) can be called with instant parameters // this time iterate 10 times, and do not use energy based termination - std::ofstream("deform_1.off") << mesh; // save deformed mesh + std::ofstream output("deform_1.off"); + output << mesh; // save deformed mesh + output.close(); // want to add another handle //// PREPROCESS SECTION AGAIN//// vertex_descriptor handle_3 = *next_helper(vb, 92); deform_mesh.insert_handle(handles_ref, handle_3); // now I need to prepocess again - if(!deform_mesh.preprocess()) + if(!deform_mesh.preprocess()) { std::cerr << "Check documentation of preprocess()" << std::endl; } //// DEFORM SECTION AGAIN//// - Deform_mesh::Point constrained_pos_3(0.55, 0.30, -0.70); + Deform_mesh::Point constrained_pos_3(0.55, 0.30, -0.70); deform_mesh.assign(handle_3, constrained_pos_3); deform_mesh.deform(15, 0.0); - std::ofstream("deform_2.off") << mesh; + output.open("deform_2.off"); + output << mesh; } \ No newline at end of file diff --git a/Surface_modeling/examples/Surface_modeling/custom_weight_for_edges_example.cpp b/Surface_modeling/examples/Surface_modeling/custom_weight_for_edges_example.cpp index ad93dfaefe6..f648e6411f1 100644 --- a/Surface_modeling/examples/Surface_modeling/custom_weight_for_edges_example.cpp +++ b/Surface_modeling/examples/Surface_modeling/custom_weight_for_edges_example.cpp @@ -1,7 +1,6 @@ -#include - -#include #include +#include +#include #include #include @@ -9,17 +8,13 @@ #include #include -#include - -typedef CGAL::Eigen_solver_traits::EigenType> > DefaultSolver; - typedef CGAL::Simple_cartesian Kernel; typedef CGAL::Polyhedron_3 Polyhedron; typedef boost::graph_traits::vertex_descriptor vertex_descriptor; -typedef boost::graph_traits::vertex_iterator vertex_iterator; +typedef boost::graph_traits::vertex_iterator vertex_iterator; typedef boost::graph_traits::edge_descriptor edge_descriptor; -typedef boost::graph_traits::edge_iterator edge_iterator; +typedef boost::graph_traits::edge_iterator edge_iterator; typedef std::map Internal_vertex_map; typedef std::map Internal_edge_map; @@ -38,12 +33,19 @@ struct Weights_from_map std::map* weight_map; }; -typedef CGAL::Deform_mesh Deform_mesh; +typedef CGAL::Deform_mesh Deform_mesh; int main() { Polyhedron mesh; - std::ifstream("models/plane.off") >> mesh; + std::ifstream input("models/plane.off"); + + if (input) + input >> mesh; + else{ + std::cerr << "Cannot open models/plane.off\n"; + return 1; + } std::map weight_map; // Store all weights @@ -52,10 +54,10 @@ int main() { weight_map[*eb] = 1.0; // store your precomputed weights } - + Internal_vertex_map vertex_index_map; Internal_edge_map edge_index_map; - Deform_mesh deform_mesh(mesh, Vertex_index_map(vertex_index_map), Edge_index_map(edge_index_map), 5, 1e-4, Weights_from_map(&weight_map)); + Deform_mesh deform_mesh(mesh, Vertex_index_map(vertex_index_map), Edge_index_map(edge_index_map), 5, 1e-4, Weights_from_map(&weight_map)); // Deform mesh as you wish } \ No newline at end of file diff --git a/Surface_modeling/examples/Surface_modeling/enriched_polyhedron_with_custom_pmap_example.cpp b/Surface_modeling/examples/Surface_modeling/enriched_polyhedron_with_custom_pmap_example.cpp index a4d14b3f997..c5d9c3bc586 100644 --- a/Surface_modeling/examples/Surface_modeling/enriched_polyhedron_with_custom_pmap_example.cpp +++ b/Surface_modeling/examples/Surface_modeling/enriched_polyhedron_with_custom_pmap_example.cpp @@ -1,15 +1,12 @@ -#include - -#include #include +#include +#include #include #include #include #include -#include - #include // Property map using extra field in KeyType @@ -23,12 +20,10 @@ public: typedef std::size_t value_type; typedef value_type& reference; typedef boost::lvalue_property_map_tag category; - + reference operator[](key_type key) const { return key->id(); } }; -typedef CGAL::Eigen_solver_traits::EigenType> > DefaultSolver; - typedef CGAL::Simple_cartesian Kernel; typedef CGAL::Polyhedron_3 Polyhedron; //enriched polyhedron @@ -38,14 +33,21 @@ typedef boost::graph_traits::edge_descriptor edge_descriptor; typedef Polyhedron_with_id_property_map Vertex_index_map; // use id field of vertices typedef Polyhedron_with_id_property_map Edge_index_map; // use id field of edges -typedef CGAL::Deform_mesh Deform_mesh; +typedef CGAL::Deform_mesh Deform_mesh; int main() { Polyhedron mesh; - std::ifstream("models/plane.off") >> mesh; + std::ifstream input("models/plane.off"); - Deform_mesh deform_mesh(mesh, Vertex_index_map(), Edge_index_map()); + if (input) + input >> mesh; + else{ + std::cerr<< "Cannot open models/plane.off"; + return 1; + } + + Deform_mesh deform_mesh(mesh, Vertex_index_map(), Edge_index_map()); // Deform mesh as you wish } diff --git a/Surface_modeling/examples/Surface_modeling/k_ring_roi_translate_rotate_example.cpp b/Surface_modeling/examples/Surface_modeling/k_ring_roi_translate_rotate_example.cpp index b345bc5486b..b57595e374a 100644 --- a/Surface_modeling/examples/Surface_modeling/k_ring_roi_translate_rotate_example.cpp +++ b/Surface_modeling/examples/Surface_modeling/k_ring_roi_translate_rotate_example.cpp @@ -1,7 +1,6 @@ -#include - -#include #include +#include +#include #include #include @@ -10,15 +9,11 @@ #include #include -#include - -typedef CGAL::Eigen_solver_traits::EigenType> > DefaultSolver; - typedef CGAL::Simple_cartesian Kernel; typedef CGAL::Polyhedron_3 Polyhedron; typedef boost::graph_traits::vertex_descriptor vertex_descriptor; -typedef boost::graph_traits::vertex_iterator vertex_iterator; +typedef boost::graph_traits::vertex_iterator vertex_iterator; typedef boost::graph_traits::edge_descriptor edge_descriptor; typedef boost::graph_traits::out_edge_iterator out_edge_iterator; @@ -28,7 +23,7 @@ typedef std::map Internal_edge_map; typedef boost::associative_property_map Vertex_index_map; typedef boost::associative_property_map Edge_index_map; -typedef CGAL::Deform_mesh Deform_mesh; +typedef CGAL::Deform_mesh Deform_mesh; // extract vertices which are at most k (inclusive) far from vertex v std::map extract_k_ring(const Polyhedron &P, vertex_descriptor v, int k) @@ -49,27 +44,34 @@ std::map extract_k_ring(const Polyhedron &P, vertex_desc if(D.insert(std::make_pair(new_v, dist_v + 1)).second) { Q.push(new_v); } - } + } } return D; } template -Iterator next_helper(Iterator it, std::size_t n) { +Iterator next_helper(Iterator it, std::size_t n) { Iterator it_next = it; while(n-- > 0) { ++it_next; } return it_next; -} +} int main() { Polyhedron mesh; - std::ifstream("models/plane.off") >> mesh; + std::ifstream input("models/plane.off"); + + if (input) + input >> mesh; + else{ + std::cerr<< "Cannot open models/plane.off"; + return 1; + } Internal_vertex_map vertex_index_map; Internal_edge_map edge_index_map; //// PREPROCESS SECTION //// - Deform_mesh deform_mesh(mesh, Vertex_index_map(vertex_index_map), Edge_index_map(edge_index_map)); + Deform_mesh deform_mesh(mesh, Vertex_index_map(vertex_index_map), Edge_index_map(edge_index_map)); // insert region of interest vertex_iterator vb, ve; @@ -87,7 +89,7 @@ int main() for(std::map::iterator it = handles_1_map.begin(); it != handles_1_map.end(); ++it) { deform_mesh.insert_handle(handles_1, it->first); } - + Deform_mesh::Handle_group handles_2 = deform_mesh.create_handle_group(); for(std::map::iterator it = handles_2_map.begin(); it != handles_2_map.end(); ++it) { deform_mesh.insert_handle(handles_2, it->first); @@ -96,7 +98,7 @@ int main() deform_mesh.preprocess(); //// DEFORM SECTION //// - deform_mesh.translate(handles_1, Deform_mesh::Vector(0,0,1)); + deform_mesh.translate(handles_1, Deform_mesh::Vector(0,0,1)); // overrides any previous call Eigen::Quaternion quad(0.92, 0, 0, -0.38); @@ -107,8 +109,10 @@ int main() deform_mesh.deform(); - std::ofstream("deform_1.off") << mesh; // save deformed mesh - + std::ofstream output("deform_1.off"); + output << mesh; // save deformed mesh + output.close(); + // Note that translate and rotate are not cumulative, // they just use original positions (positions at the time of construction) of the handles while calculating target positions deform_mesh.translate(handles_1, Deform_mesh::Vector(0,0.30,0)); @@ -118,6 +122,7 @@ int main() deform_mesh.set_tolerance(0.0); deform_mesh.deform(); // will iterate 10 times - std::ofstream("deform_2.off") << mesh; + output.open("deform_2.off"); + output << mesh; }