update examples and make them compile on linux

This commit is contained in:
Sébastien Loriot 2013-04-12 17:30:48 +02:00
parent 7ecfe2a1c0
commit 707e9fcccf
5 changed files with 100 additions and 73 deletions

View File

@ -2,9 +2,16 @@
# This is the CMake script for compiling a CGAL application. # This is the CMake script for compiling a CGAL application.
project( Surface_modeling_example ) project( Surface_modeling_ )
cmake_minimum_required(VERSION 2.6.2) 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 ) find_package(CGAL QUIET COMPONENTS Core )
@ -12,15 +19,21 @@ if ( CGAL_FOUND )
include( ${CGAL_USE_FILE} ) include( ${CGAL_USE_FILE} )
find_package(Eigen3 3.1.91) #(requires 3.2.0 or greater)
if (EIGEN3_FOUND)
include( ${EIGEN3_USE_FILE} )
include( CGAL_CreateSingleSourceCGALProgram ) include( CGAL_CreateSingleSourceCGALProgram )
include_directories (BEFORE ../../include) include_directories (BEFORE "../../include")
create_single_source_cgal_program( "hello.cpp" ) create_single_source_cgal_program( "all_roi_assign_example.cpp" )
create_single_source_cgal_program( "k-ring.cpp" ) create_single_source_cgal_program( "custom_weight_for_edges_example.cpp" )
create_single_source_cgal_program( "k-ring_BGL.cpp" ) create_single_source_cgal_program( "enriched_polyhedron_with_custom_pmap_example.cpp" )
create_single_source_cgal_program( "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() else()
message(STATUS "This program requires the CGAL library, and will not be compiled.") message(STATUS "This program requires the CGAL library, and will not be compiled.")

View File

@ -1,7 +1,6 @@
#include <CGAL/Deform_mesh.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Simple_cartesian.h> #include <CGAL/Simple_cartesian.h>
#include <CGAL/Deform_mesh.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h> #include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Eigen_solver_traits.h> #include <CGAL/Eigen_solver_traits.h>
@ -9,10 +8,6 @@
#include <map> #include <map>
#include <boost/property_map/property_map.hpp> #include <boost/property_map/property_map.hpp>
#include <Eigen/SuperLUSupport>
typedef CGAL::Eigen_solver_traits<Eigen::SuperLU<CGAL::Eigen_sparse_matrix<double>::EigenType> > DefaultSolver;
typedef CGAL::Simple_cartesian<double> Kernel; typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron; typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
@ -26,7 +21,7 @@ typedef std::map<edge_descriptor, std::size_t> Internal_edge_map;
typedef boost::associative_property_map<Internal_vertex_map> Vertex_index_map; typedef boost::associative_property_map<Internal_vertex_map> Vertex_index_map;
typedef boost::associative_property_map<Internal_edge_map> Edge_index_map; typedef boost::associative_property_map<Internal_edge_map> Edge_index_map;
typedef CGAL::Deform_mesh<Polyhedron, DefaultSolver, Vertex_index_map, Edge_index_map, CGAL::ORIGINAL_ARAP> Deform_mesh; typedef CGAL::Deform_mesh<Polyhedron, Vertex_index_map, Edge_index_map> Deform_mesh;
template<class Iterator> template<class Iterator>
Iterator next_helper(Iterator it, std::size_t n) { Iterator next_helper(Iterator it, std::size_t n) {
@ -38,7 +33,14 @@ Iterator next_helper(Iterator it, std::size_t n) {
int main() int main()
{ {
Polyhedron mesh; 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_vertex_map vertex_index_map;
Internal_edge_map edge_index_map; Internal_edge_map edge_index_map;
@ -82,7 +84,9 @@ int main()
deform_mesh.deform(10, 0.0); // deform(unsigned int iterations, double tolerance) can be called with instant parameters 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 // 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 // want to add another handle
//// PREPROCESS SECTION AGAIN//// //// PREPROCESS SECTION AGAIN////
@ -98,5 +102,6 @@ int main()
deform_mesh.deform(15, 0.0); deform_mesh.deform(15, 0.0);
std::ofstream("deform_2.off") << mesh; output.open("deform_2.off");
output << mesh;
} }

View File

@ -1,7 +1,6 @@
#include <CGAL/Deform_mesh.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Simple_cartesian.h> #include <CGAL/Simple_cartesian.h>
#include <CGAL/Deform_mesh.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h> #include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Eigen_solver_traits.h> #include <CGAL/Eigen_solver_traits.h>
@ -9,10 +8,6 @@
#include <map> #include <map>
#include <boost/property_map/property_map.hpp> #include <boost/property_map/property_map.hpp>
#include <Eigen/SuperLUSupport>
typedef CGAL::Eigen_solver_traits<Eigen::SuperLU<CGAL::Eigen_sparse_matrix<double>::EigenType> > DefaultSolver;
typedef CGAL::Simple_cartesian<double> Kernel; typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron; typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
@ -38,12 +33,19 @@ struct Weights_from_map
std::map<edge_descriptor, double>* weight_map; std::map<edge_descriptor, double>* weight_map;
}; };
typedef CGAL::Deform_mesh<Polyhedron, DefaultSolver, Vertex_index_map, Edge_index_map, CGAL::ORIGINAL_ARAP, Weights_from_map> Deform_mesh; typedef CGAL::Deform_mesh<Polyhedron, Vertex_index_map, Edge_index_map, CGAL::ORIGINAL_ARAP, Weights_from_map> Deform_mesh;
int main() int main()
{ {
Polyhedron mesh; 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<edge_descriptor, double> weight_map; std::map<edge_descriptor, double> weight_map;
// Store all weights // Store all weights

View File

@ -1,15 +1,12 @@
#include <CGAL/Deform_mesh.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Simple_cartesian.h> #include <CGAL/Simple_cartesian.h>
#include <CGAL/Deform_mesh.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h> #include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Eigen_solver_traits.h> #include <CGAL/Eigen_solver_traits.h>
#include <fstream> #include <fstream>
#include <boost/property_map/property_map.hpp> #include <boost/property_map/property_map.hpp>
#include <Eigen/SuperLUSupport>
#include <CGAL/Polyhedron_items_with_id_3.h> #include <CGAL/Polyhedron_items_with_id_3.h>
// Property map using extra field in KeyType // Property map using extra field in KeyType
@ -27,8 +24,6 @@ public:
reference operator[](key_type key) const { return key->id(); } reference operator[](key_type key) const { return key->id(); }
}; };
typedef CGAL::Eigen_solver_traits<Eigen::SuperLU<CGAL::Eigen_sparse_matrix<double>::EigenType> > DefaultSolver;
typedef CGAL::Simple_cartesian<double> Kernel; typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3> Polyhedron; //enriched polyhedron typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3> Polyhedron; //enriched polyhedron
@ -38,12 +33,19 @@ typedef boost::graph_traits<Polyhedron>::edge_descriptor edge_descriptor;
typedef Polyhedron_with_id_property_map<Polyhedron, vertex_descriptor> Vertex_index_map; // use id field of vertices typedef Polyhedron_with_id_property_map<Polyhedron, vertex_descriptor> Vertex_index_map; // use id field of vertices
typedef Polyhedron_with_id_property_map<Polyhedron, edge_descriptor> Edge_index_map; // use id field of edges typedef Polyhedron_with_id_property_map<Polyhedron, edge_descriptor> Edge_index_map; // use id field of edges
typedef CGAL::Deform_mesh<Polyhedron, DefaultSolver, Vertex_index_map, Edge_index_map> Deform_mesh; typedef CGAL::Deform_mesh<Polyhedron, Vertex_index_map, Edge_index_map> Deform_mesh;
int main() int main()
{ {
Polyhedron mesh; 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;
}
Deform_mesh deform_mesh(mesh, Vertex_index_map(), Edge_index_map()); Deform_mesh deform_mesh(mesh, Vertex_index_map(), Edge_index_map());

View File

@ -1,7 +1,6 @@
#include <CGAL/Deform_mesh.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Simple_cartesian.h> #include <CGAL/Simple_cartesian.h>
#include <CGAL/Deform_mesh.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h> #include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Eigen_solver_traits.h> #include <CGAL/Eigen_solver_traits.h>
@ -10,10 +9,6 @@
#include <queue> #include <queue>
#include <boost/property_map/property_map.hpp> #include <boost/property_map/property_map.hpp>
#include <Eigen/SuperLUSupport>
typedef CGAL::Eigen_solver_traits<Eigen::SuperLU<CGAL::Eigen_sparse_matrix<double>::EigenType> > DefaultSolver;
typedef CGAL::Simple_cartesian<double> Kernel; typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron; typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
@ -28,7 +23,7 @@ typedef std::map<edge_descriptor, std::size_t> Internal_edge_map;
typedef boost::associative_property_map<Internal_vertex_map> Vertex_index_map; typedef boost::associative_property_map<Internal_vertex_map> Vertex_index_map;
typedef boost::associative_property_map<Internal_edge_map> Edge_index_map; typedef boost::associative_property_map<Internal_edge_map> Edge_index_map;
typedef CGAL::Deform_mesh<Polyhedron, DefaultSolver, Vertex_index_map, Edge_index_map, CGAL::ORIGINAL_ARAP> Deform_mesh; typedef CGAL::Deform_mesh<Polyhedron, Vertex_index_map, Edge_index_map> Deform_mesh;
// extract vertices which are at most k (inclusive) far from vertex v // extract vertices which are at most k (inclusive) far from vertex v
std::map<vertex_descriptor, int> extract_k_ring(const Polyhedron &P, vertex_descriptor v, int k) std::map<vertex_descriptor, int> extract_k_ring(const Polyhedron &P, vertex_descriptor v, int k)
@ -64,7 +59,14 @@ Iterator next_helper(Iterator it, std::size_t n) {
int main() int main()
{ {
Polyhedron mesh; 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_vertex_map vertex_index_map;
Internal_edge_map edge_index_map; Internal_edge_map edge_index_map;
@ -107,7 +109,9 @@ int main()
deform_mesh.deform(); 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, // 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 // they just use original positions (positions at the time of construction) of the handles while calculating target positions
@ -118,6 +122,7 @@ int main()
deform_mesh.set_tolerance(0.0); deform_mesh.set_tolerance(0.0);
deform_mesh.deform(); // will iterate 10 times deform_mesh.deform(); // will iterate 10 times
std::ofstream("deform_2.off") << mesh; output.open("deform_2.off");
output << mesh;
} }