mirror of https://github.com/CGAL/cgal
update examples and make them compile on linux
This commit is contained in:
parent
7ecfe2a1c0
commit
707e9fcccf
|
|
@ -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.")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include <CGAL/Deform_mesh.h>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Deform_mesh.h>
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/Eigen_solver_traits.h>
|
||||
|
||||
|
|
@ -9,15 +8,11 @@
|
|||
#include <map>
|
||||
#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::Polyhedron_3<Kernel> Polyhedron;
|
||||
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor;
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_iterator vertex_iterator;
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_iterator vertex_iterator;
|
||||
typedef boost::graph_traits<Polyhedron>::edge_descriptor edge_descriptor;
|
||||
|
||||
typedef std::map<vertex_descriptor, std::size_t> Internal_vertex_map;
|
||||
|
|
@ -26,29 +21,36 @@ 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_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>
|
||||
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;
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
#include <CGAL/Deform_mesh.h>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Deform_mesh.h>
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/Eigen_solver_traits.h>
|
||||
|
||||
|
|
@ -9,17 +8,13 @@
|
|||
#include <map>
|
||||
#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::Polyhedron_3<Kernel> Polyhedron;
|
||||
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor;
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_iterator vertex_iterator;
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_iterator vertex_iterator;
|
||||
typedef boost::graph_traits<Polyhedron>::edge_descriptor edge_descriptor;
|
||||
typedef boost::graph_traits<Polyhedron>::edge_iterator edge_iterator;
|
||||
typedef boost::graph_traits<Polyhedron>::edge_iterator edge_iterator;
|
||||
|
||||
typedef std::map<vertex_descriptor, std::size_t> Internal_vertex_map;
|
||||
typedef std::map<edge_descriptor, std::size_t> Internal_edge_map;
|
||||
|
|
@ -38,12 +33,19 @@ struct Weights_from_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()
|
||||
{
|
||||
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;
|
||||
// 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
|
||||
}
|
||||
|
|
@ -1,15 +1,12 @@
|
|||
#include <CGAL/Deform_mesh.h>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Deform_mesh.h>
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/Eigen_solver_traits.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <boost/property_map/property_map.hpp>
|
||||
|
||||
#include <Eigen/SuperLUSupport>
|
||||
|
||||
#include <CGAL/Polyhedron_items_with_id_3.h>
|
||||
|
||||
// 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<Eigen::SuperLU<CGAL::Eigen_sparse_matrix<double>::EigenType> > DefaultSolver;
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3> Polyhedron; //enriched polyhedron
|
||||
|
||||
|
|
@ -38,14 +33,21 @@ 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, 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()
|
||||
{
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include <CGAL/Deform_mesh.h>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Deform_mesh.h>
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/Eigen_solver_traits.h>
|
||||
|
||||
|
|
@ -10,15 +9,11 @@
|
|||
#include <queue>
|
||||
#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::Polyhedron_3<Kernel> Polyhedron;
|
||||
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor;
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_iterator vertex_iterator;
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_iterator vertex_iterator;
|
||||
typedef boost::graph_traits<Polyhedron>::edge_descriptor edge_descriptor;
|
||||
typedef boost::graph_traits<Polyhedron>::out_edge_iterator out_edge_iterator;
|
||||
|
||||
|
|
@ -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_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
|
||||
std::map<vertex_descriptor, int> extract_k_ring(const Polyhedron &P, vertex_descriptor v, int k)
|
||||
|
|
@ -49,27 +44,34 @@ std::map<vertex_descriptor, int> 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<class Iterator>
|
||||
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<vertex_descriptor, int>::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<vertex_descriptor, int>::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<double> 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue