mirror of https://github.com/CGAL/cgal
Test refinements
This commit is contained in:
parent
0629a1bf56
commit
d0eb2877ca
|
|
@ -1,178 +0,0 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Polyhedron_items_with_id_3.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
|
||||
#include <CGAL/boost/graph/properties_Polyhedron_3.h>
|
||||
|
||||
#include <CGAL/Timer.h>
|
||||
|
||||
#define CGAL_EIGEN3_ENABLED
|
||||
//#define CGAL_SUPERLU_ENABLED
|
||||
#include <CGAL/Deform_mesh.h>
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3> Polyhedron;
|
||||
|
||||
template<class PolyhedronWithId, class KeyType>
|
||||
struct Polyhedron_with_id_property_map
|
||||
: public boost::put_get_helper<std::size_t&,
|
||||
Polyhedron_with_id_property_map<PolyhedronWithId, KeyType> >
|
||||
{
|
||||
public:
|
||||
typedef KeyType key_type;
|
||||
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 boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor;
|
||||
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, Vertex_index_map, Edge_index_map, CGAL::ORIGINAL_ARAP> Deform_mesh_original;
|
||||
typedef CGAL::Deform_mesh<Polyhedron, Vertex_index_map, Edge_index_map, CGAL::SPOKES_AND_RIMS> Deform_mesh_spokes;
|
||||
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_iterator vertex_iterator;
|
||||
typedef boost::graph_traits<Polyhedron>::edge_iterator edge_iterator;
|
||||
|
||||
const double squared_threshold = 0.0001; // alert if average difs between precomputed and deformed mesh models is above threshold
|
||||
|
||||
#define PERFORMANCE // define for checking performance
|
||||
// #define MESH_DIFFERENCE // define for checking difs with precomputed-saved deformations
|
||||
|
||||
|
||||
template <class T>
|
||||
std::string toString(const T& t)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << t;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<class DeformMesh>
|
||||
typename DeformMesh::Handle_group read_rois(DeformMesh& deform_mesh)
|
||||
{
|
||||
// load handles and roi from txt
|
||||
std::ifstream handle_stream("data/cactus_handle.txt"); // there is only one handle in cactus_handle.txt
|
||||
std::ifstream roi_stream("data/cactus_roi.txt");
|
||||
std::vector<int> handles;
|
||||
std::vector<int> rois;
|
||||
int id;
|
||||
while(handle_stream >> id) { handles.push_back(id); }
|
||||
while(roi_stream >> id) { rois.push_back(id); }
|
||||
|
||||
typename DeformMesh::Handle_group active_handle_group = deform_mesh.create_handle_group();
|
||||
|
||||
typename DeformMesh::Polyhedron const& polyhedron = deform_mesh.halfedge_graph();
|
||||
id = 0;
|
||||
vertex_iterator vb, ve;
|
||||
for(boost::tie(vb, ve) = boost::vertices(polyhedron); vb != ve; ++vb, ++id)
|
||||
{
|
||||
// not efficient but small poly
|
||||
if(std::find(handles.begin(), handles.end(), id) != handles.end()) {
|
||||
deform_mesh.insert_handle(active_handle_group, *vb);
|
||||
}
|
||||
|
||||
if(std::find(rois.begin(), rois.end(), id) != rois.end()) {
|
||||
deform_mesh.insert_roi(*vb);
|
||||
}
|
||||
}
|
||||
|
||||
return active_handle_group;
|
||||
}
|
||||
|
||||
bool compare_mesh(const Polyhedron& mesh_1, const Polyhedron& mesh_2)
|
||||
{
|
||||
Polyhedron::Vertex_const_iterator it_1 = mesh_1.vertices_begin();
|
||||
Polyhedron::Vertex_const_iterator it_2 = mesh_2.vertices_begin();
|
||||
Kernel::Vector_3 total_dif(0,0,0);
|
||||
for( ; it_1 != mesh_1.vertices_end(); ++it_1 , ++it_2)
|
||||
{
|
||||
total_dif = total_dif + (it_1->point() - it_2->point());
|
||||
}
|
||||
total_dif = total_dif / mesh_1.size_of_vertices();
|
||||
|
||||
std::cout << total_dif << std::endl;
|
||||
|
||||
bool fail = total_dif.squared_length() > squared_threshold;
|
||||
return fail;
|
||||
}
|
||||
|
||||
// read deformation session saved as a handle differences
|
||||
template<class DeformMesh>
|
||||
bool read_handle_difs_and_deform(DeformMesh& deform_mesh, typename DeformMesh::Handle_group& active_handle_group)
|
||||
{
|
||||
std::ifstream dif_stream("data/cactus_handle_differences.txt");
|
||||
std::vector<Kernel::Vector_3> dif_vector;
|
||||
double x, y, z;
|
||||
while(dif_stream >> x >> y >> z)
|
||||
{
|
||||
dif_vector.push_back(Kernel::Vector_3(x, y, z));
|
||||
}
|
||||
CGAL::Timer timer;
|
||||
|
||||
for(std::size_t i = 0; i < dif_vector.size(); ++i)
|
||||
{
|
||||
timer.start();
|
||||
deform_mesh.translate(active_handle_group, dif_vector[i]);
|
||||
deform_mesh.deform();
|
||||
timer.stop();
|
||||
#ifdef MESH_DIFFERENCE
|
||||
// read pre-deformed cactus
|
||||
std::string predeformed_cactus_file = "data/cactus_deformed/cactus_deformed_" + toString(i) + ".off";
|
||||
Polyhedron predeformed_cactus;
|
||||
|
||||
std::ifstream(predeformed_cactus_file) >> predeformed_cactus;
|
||||
bool fail = compare_mesh(predeformed_cactus, deform_mesh.halfedge_graph());
|
||||
if( fail ) { return true; }
|
||||
#endif
|
||||
// for saving deformation
|
||||
//std::ofstream(predeformed_cactus_file) << deform_mesh.halfedge_graph();
|
||||
//std::cout << predeformed_cactus_file << std::endl;
|
||||
}
|
||||
|
||||
#ifdef PERFORMANCE
|
||||
std::cout << "---------------------------------------" << std::endl;
|
||||
std::cout << "Deformation performance: " << timer.time() << std::endl;
|
||||
std::cout << "---------------------------------------" << std::endl;
|
||||
std::cout << "Press ENTER to continue...";
|
||||
std::cin.get();
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Polyhedron mesh;
|
||||
std::ifstream("data/cactus.off") >> mesh;
|
||||
|
||||
Deform_mesh_original deform_mesh_1(mesh, Vertex_index_map(), Edge_index_map());
|
||||
// load handles and roi from txt
|
||||
Deform_mesh_original::Handle_group active_handle_group_1 = read_rois(deform_mesh_1);
|
||||
deform_mesh_1.preprocess();
|
||||
|
||||
bool fail_1 = read_handle_difs_and_deform(deform_mesh_1, active_handle_group_1);
|
||||
if(fail_1) { return EXIT_FAILURE; }
|
||||
std::cout << "ORIGINAL ARAP Success!" << std::endl;
|
||||
|
||||
Deform_mesh_spokes deform_mesh_2(mesh, Vertex_index_map(), Edge_index_map());
|
||||
// load handles and roi from txt
|
||||
Deform_mesh_spokes::Handle_group active_handle_group_2 = read_rois(deform_mesh_2);
|
||||
deform_mesh_2.preprocess();
|
||||
|
||||
bool fail_2 = read_handle_difs_and_deform(deform_mesh_2, active_handle_group_2);
|
||||
if(fail_2) { return EXIT_FAILURE; }
|
||||
std::cout << "SPOKES AND RIMS ARAP Success!" << std::endl;
|
||||
}
|
||||
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Polyhedron_items_with_id_3.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
|
||||
#include <CGAL/Timer.h>
|
||||
|
||||
#define CGAL_EIGEN3_ENABLED
|
||||
//#define CGAL_SUPERLU_ENABLED
|
||||
#include <CGAL/Deform_mesh.h>
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3> Polyhedron;
|
||||
|
||||
template<class PolyhedronWithId, class KeyType>
|
||||
struct Polyhedron_with_id_property_map
|
||||
: public boost::put_get_helper<std::size_t&,
|
||||
Polyhedron_with_id_property_map<PolyhedronWithId, KeyType> >
|
||||
{
|
||||
public:
|
||||
typedef KeyType key_type;
|
||||
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 boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor;
|
||||
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, Vertex_index_map, Edge_index_map, CGAL::ORIGINAL_ARAP> Deform_mesh_original;
|
||||
typedef CGAL::Deform_mesh<Polyhedron, Vertex_index_map, Edge_index_map, CGAL::SPOKES_AND_RIMS> Deform_mesh_spokes;
|
||||
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_iterator vertex_iterator;
|
||||
typedef boost::graph_traits<Polyhedron>::edge_iterator edge_iterator;
|
||||
|
||||
template<class DeformMesh>
|
||||
typename DeformMesh::Handle_group read_rois(DeformMesh& deform_mesh)
|
||||
{
|
||||
// load handles and roi from txt
|
||||
std::ifstream handle_stream("data/cactus_handle.txt"); // there is only one handle in cactus_handle.txt
|
||||
std::ifstream roi_stream("data/cactus_roi.txt");
|
||||
std::vector<int> handles;
|
||||
std::vector<int> rois;
|
||||
int id;
|
||||
while(handle_stream >> id) { handles.push_back(id); }
|
||||
while(roi_stream >> id) { rois.push_back(id); }
|
||||
|
||||
typename DeformMesh::Handle_group active_handle_group = deform_mesh.create_handle_group();
|
||||
|
||||
typename DeformMesh::Polyhedron const& polyhedron = deform_mesh.halfedge_graph();
|
||||
id = 0;
|
||||
vertex_iterator vb, ve;
|
||||
for(boost::tie(vb, ve) = boost::vertices(polyhedron); vb != ve; ++vb, ++id)
|
||||
{
|
||||
// not efficient but small poly
|
||||
if(std::find(handles.begin(), handles.end(), id) != handles.end()) {
|
||||
deform_mesh.insert_handle(active_handle_group, *vb);
|
||||
}
|
||||
|
||||
if(std::find(rois.begin(), rois.end(), id) != rois.end()) {
|
||||
deform_mesh.insert_roi(*vb);
|
||||
}
|
||||
}
|
||||
|
||||
return active_handle_group;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Polyhedron mesh;
|
||||
std::ifstream("data/cactus.off") >> mesh;
|
||||
|
||||
Deform_mesh_original deform_mesh(mesh, Vertex_index_map(), Edge_index_map());
|
||||
// load handles and roi from txt
|
||||
Deform_mesh_original::Handle_group active_handle_group = read_rois(deform_mesh);
|
||||
deform_mesh.preprocess();
|
||||
|
||||
deform_mesh.translate(active_handle_group, Deform_mesh_original::Vector(-0.55, -0.30, 0.0) );
|
||||
|
||||
CGAL::Timer timer; timer.start();
|
||||
deform_mesh.deform(500, 0);
|
||||
timer.stop();
|
||||
|
||||
std::cout << "---------------------------------------" << std::endl;
|
||||
std::cout << "Deformation performance: " << timer.time() << std::endl;
|
||||
std::cout << "---------------------------------------" << std::endl;
|
||||
|
||||
// std::ofstream("data/deformed_cactus.off") << mesh;
|
||||
|
||||
std::cout << "Press ENTER to continue...";
|
||||
std::cin.get();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
#include "Surface_modeling_test_commons.h"
|
||||
#include <algorithm>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Polyhedron_items_with_id_3.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/Deform_mesh.h>
|
||||
|
||||
#include <CGAL/Timer.h>
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3> Polyhedron;
|
||||
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor;
|
||||
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, Vertex_index_map, Edge_index_map, CGAL::ORIGINAL_ARAP> Deform_mesh_arap;
|
||||
typedef CGAL::Deform_mesh<Polyhedron, Vertex_index_map, Edge_index_map, CGAL::SPOKES_AND_RIMS> Deform_mesh_spoke;
|
||||
|
||||
const double squared_threshold = 0.001; // alert if average difs between precomputed and deformed mesh models is above threshold
|
||||
|
||||
bool compare_mesh(const Polyhedron& mesh_1, const Polyhedron& mesh_2)
|
||||
{
|
||||
Polyhedron::Vertex_const_iterator it_1 = mesh_1.vertices_begin();
|
||||
Polyhedron::Vertex_const_iterator it_2 = mesh_2.vertices_begin();
|
||||
Kernel::Vector_3 total_dif(0,0,0);
|
||||
for( ; it_1 != mesh_1.vertices_end(); ++it_1 , ++it_2)
|
||||
{
|
||||
total_dif = total_dif + (it_1->point() - it_2->point());
|
||||
}
|
||||
double average_mesh_dif = (total_dif / mesh_1.size_of_vertices()).squared_length();
|
||||
|
||||
std::cerr << "Average mesh difference: " << average_mesh_dif << std::endl;
|
||||
|
||||
bool close_enough = average_mesh_dif < squared_threshold;
|
||||
return close_enough;
|
||||
}
|
||||
|
||||
// read deformation session saved as a handle differences
|
||||
template<class DeformMesh>
|
||||
bool read_handle_difs_and_deform(DeformMesh& deform_mesh, typename DeformMesh::Handle_group& active_handle_group)
|
||||
{
|
||||
typedef typename DeformMesh::Vector Vector;
|
||||
|
||||
if(!deform_mesh.preprocess()) {
|
||||
std::cerr << "Error: preprocess() failed!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ifstream dif_stream("data/cactus_handle_differences.txt");
|
||||
std::vector<Vector> dif_vector;
|
||||
double x, y, z;
|
||||
while(dif_stream >> x >> y >> z)
|
||||
{ dif_vector.push_back(Vector(x, y, z)); }
|
||||
|
||||
CGAL::Timer timer;
|
||||
|
||||
for(std::size_t i = 0; i < dif_vector.size(); ++i)
|
||||
{
|
||||
timer.start();
|
||||
deform_mesh.translate(active_handle_group, dif_vector[i]);
|
||||
deform_mesh.deform();
|
||||
timer.stop();
|
||||
|
||||
// read pre-deformed cactus
|
||||
std::stringstream predeformed_cactus_file;
|
||||
predeformed_cactus_file << "data/cactus_deformed/cactus_deformed_" << i << ".off";
|
||||
Polyhedron predeformed_cactus;
|
||||
|
||||
if(!read_to_polyhedron(predeformed_cactus_file.str().c_str(), predeformed_cactus))
|
||||
{ return false; }
|
||||
if(!compare_mesh(predeformed_cactus, deform_mesh.halfedge_graph()) )
|
||||
{ return false; }
|
||||
|
||||
// for saving deformation
|
||||
//std::ofstream(predeformed_cactus_file) << deform_mesh.halfedge_graph();
|
||||
//std::cerr << predeformed_cactus_file << std::endl;
|
||||
}
|
||||
std::cerr << "Deformation performance (with default number_of_iteration and tolerance) " << std::endl
|
||||
<< dif_vector.size() << " translation: " << timer.time() << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Polyhedron mesh_1;
|
||||
if(!read_to_polyhedron("data/cactus.off", mesh_1)) { return EXIT_FAILURE; }
|
||||
Polyhedron mesh_2 = mesh_1;
|
||||
|
||||
Deform_mesh_arap deform_mesh_arap(mesh_1, Vertex_index_map(), Edge_index_map());
|
||||
Deform_mesh_spoke deform_mesh_spoke(mesh_2, Vertex_index_map(), Edge_index_map());
|
||||
// For original arap
|
||||
boost::optional<Deform_mesh_arap::Handle_group> active_handle_group_1 =
|
||||
read_rois(deform_mesh_arap, "data/cactus_roi.txt", "data/cactus_handle.txt");
|
||||
if(!active_handle_group_1) { return EXIT_FAILURE; }
|
||||
|
||||
bool close_enough = read_handle_difs_and_deform(deform_mesh_arap, *active_handle_group_1);
|
||||
if(!close_enough) { return EXIT_FAILURE; }
|
||||
std::cerr << "ORIGINAL ARAP Success!" << std::endl;
|
||||
// For spokes rims
|
||||
boost::optional<Deform_mesh_spoke::Handle_group> active_handle_group_2 =
|
||||
read_rois(deform_mesh_spoke, "data/cactus_roi.txt", "data/cactus_handle.txt");
|
||||
if(!active_handle_group_2) { return EXIT_FAILURE; }
|
||||
|
||||
close_enough = read_handle_difs_and_deform(deform_mesh_spoke, *active_handle_group_2);
|
||||
if(!close_enough) { return EXIT_FAILURE; }
|
||||
std::cerr << "SPOKES AND RIMS ARAP Success!" << std::endl;
|
||||
std::cerr << "All done!" << std::endl
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
#include "Surface_modeling_test_commons.h"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Polyhedron_items_with_id_3.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
|
||||
#include <CGAL/Timer.h>
|
||||
#include <CGAL/Deform_mesh.h>
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3> Polyhedron;
|
||||
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor;
|
||||
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
|
||||
|
||||
// #define CGAL_USE_EXPERIMENTAL_POLAR
|
||||
#ifdef CGAL_USE_EXPERIMENTAL_POLAR
|
||||
#include <CGAL/internal/Surface_modeling/Deformation_Eigen_polar_closest_rotation_traits_3.h>
|
||||
typedef CGAL::Deformation_Eigen_polar_closest_rotation_traits_3 Closest_rotation_model;
|
||||
#else
|
||||
typedef CGAL::Deformation_Eigen_closest_rotation_traits_3 Closest_rotation_model;
|
||||
#endif
|
||||
|
||||
typedef CGAL::Deform_mesh<Polyhedron, Vertex_index_map, Edge_index_map,
|
||||
CGAL::ORIGINAL_ARAP, CGAL::Default, CGAL::Default, Closest_rotation_model> Deform_mesh_arap;
|
||||
|
||||
typedef CGAL::Deform_mesh<Polyhedron, Vertex_index_map, Edge_index_map,
|
||||
CGAL::SPOKES_AND_RIMS, CGAL::Default, CGAL::Default, Closest_rotation_model> Deform_mesh_spoke;
|
||||
|
||||
|
||||
template<class DeformMesh>
|
||||
bool preprocess_and_deform(DeformMesh& deform_mesh, int deformation_iteration)
|
||||
{
|
||||
boost::optional<typename DeformMesh::Handle_group> active_handle_group =
|
||||
read_rois(deform_mesh, "data/cactus_roi.txt", "data/cactus_handle.txt");
|
||||
if(!active_handle_group) { return false; }
|
||||
|
||||
CGAL::Timer timer; timer.start();
|
||||
|
||||
if(!deform_mesh.preprocess()) {
|
||||
std::cerr << "Error: preprocess() failed!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::cerr << "Preprocess time: " << timer.time() << std::endl;
|
||||
timer.reset();
|
||||
|
||||
deform_mesh.translate(*active_handle_group, typename DeformMesh::Vector(-0.55, -0.30, 0.0) );
|
||||
deform_mesh.deform(deformation_iteration, 0);
|
||||
timer.stop();
|
||||
|
||||
std::cerr << "Deformation time (one handle translated and deform method iterated " <<
|
||||
deformation_iteration << " times): " << timer.time() << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Polyhedron mesh_1;
|
||||
if(!read_to_polyhedron("data/cactus.off", mesh_1)) { return EXIT_FAILURE; }
|
||||
Polyhedron mesh_2 = mesh_1;
|
||||
|
||||
Deform_mesh_arap deform_mesh_arap(mesh_1, Vertex_index_map(), Edge_index_map());
|
||||
Deform_mesh_spoke deform_mesh_spoke(mesh_2, Vertex_index_map(), Edge_index_map());
|
||||
|
||||
const int deformation_iteration = 500;
|
||||
const double x = -0.55; const double y = -0.50; const double z = -0.0;
|
||||
|
||||
std::cerr << "ORIGINAL_ARAP performance: " << std::endl;
|
||||
bool successed = preprocess_and_deform(deform_mesh_arap,
|
||||
"data/cactus_roi.txt",
|
||||
"data/cactus_handle.txt",
|
||||
Deform_mesh_arap::Vector(x, y, z),
|
||||
deformation_iteration);
|
||||
if(!successed) { return EXIT_FAILURE; }
|
||||
|
||||
std::cerr << "SPOKES_AND_RIMS performance: " << std::endl;
|
||||
successed = preprocess_and_deform(deform_mesh_spoke,
|
||||
"data/cactus_roi.txt",
|
||||
"data/cactus_handle.txt",
|
||||
Deform_mesh_spoke::Vector(x, y, z),
|
||||
deformation_iteration);
|
||||
if(!successed) { return EXIT_FAILURE; }
|
||||
|
||||
std::cerr << "Save deformed models" << std::endl;
|
||||
std::ofstream("data/cactus_deformed_arap.off") << mesh_1;
|
||||
std::ofstream("data/cactus_deformed_spokes.off") << mesh_2;
|
||||
std::cerr << "All done!" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
0
Surface_modeling/test/Eigen-Test-2/A.txt → Surface_modeling/test/Surface_modeling/Eigen-Test-2/A.txt
Executable file → Normal file
0
Surface_modeling/test/Eigen-Test-2/A.txt → Surface_modeling/test/Surface_modeling/Eigen-Test-2/A.txt
Executable file → Normal file
0
Surface_modeling/test/Eigen-Test-2/Bx.txt → Surface_modeling/test/Surface_modeling/Eigen-Test-2/Bx.txt
Executable file → Normal file
0
Surface_modeling/test/Eigen-Test-2/Bx.txt → Surface_modeling/test/Surface_modeling/Eigen-Test-2/Bx.txt
Executable file → Normal file
0
Surface_modeling/test/Eigen-Test-2/CMakeLists.txt → Surface_modeling/test/Surface_modeling/Eigen-Test-2/CMakeLists.txt
Executable file → Normal file
0
Surface_modeling/test/Eigen-Test-2/CMakeLists.txt → Surface_modeling/test/Surface_modeling/Eigen-Test-2/CMakeLists.txt
Executable file → Normal file
0
Surface_modeling/test/Eigen-Test-2/main.cpp → Surface_modeling/test/Surface_modeling/Eigen-Test-2/main.cpp
Executable file → Normal file
0
Surface_modeling/test/Eigen-Test-2/main.cpp → Surface_modeling/test/Surface_modeling/Eigen-Test-2/main.cpp
Executable file → Normal file
|
|
@ -0,0 +1,100 @@
|
|||
#include <boost/property_map/property_map.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
template<class PolyhedronWithId, class KeyType>
|
||||
struct Polyhedron_with_id_property_map
|
||||
: public boost::put_get_helper<std::size_t&,
|
||||
Polyhedron_with_id_property_map<PolyhedronWithId, KeyType> >
|
||||
{
|
||||
public:
|
||||
typedef KeyType key_type;
|
||||
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(); }
|
||||
};
|
||||
|
||||
template<class Polyhedron>
|
||||
bool read_to_polyhedron(const char* file_name, Polyhedron& mesh)
|
||||
{
|
||||
std::ifstream input(file_name);
|
||||
|
||||
if ( !input || !(input >> mesh) || mesh.empty() ){
|
||||
std::cerr << "Error: can not read " << file_name << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class DeformMesh>
|
||||
boost::optional<typename DeformMesh::Handle_group>
|
||||
read_rois(DeformMesh& deform_mesh,
|
||||
const std::string& roi_file,
|
||||
const std::string& handle_file)
|
||||
{
|
||||
std::ifstream roi_stream(roi_file);
|
||||
std::ifstream handle_stream(handle_file);
|
||||
if(!roi_stream || !handle_stream) {
|
||||
std::cerr << "Error: can not read roi or handle files" << std::endl;
|
||||
return boost::optional<typename DeformMesh::Handle_group>();
|
||||
}
|
||||
|
||||
typedef typename boost::graph_traits<typename DeformMesh::Polyhedron>::vertex_iterator vertex_iterator;
|
||||
typedef typename DeformMesh::vertex_descriptor vertex_descriptor;
|
||||
// put all vertices to a vector
|
||||
typename DeformMesh::Polyhedron const& polyhedron = deform_mesh.halfedge_graph();
|
||||
|
||||
std::vector<vertex_descriptor> vertices;
|
||||
vertices.reserve(boost::num_edges(polyhedron));
|
||||
vertex_iterator vb, ve;
|
||||
for(boost::tie(vb, ve) = boost::vertices(polyhedron); vb != ve; ++vb) {
|
||||
vertices.push_back(*vb);
|
||||
}
|
||||
// load handles and roi from txt
|
||||
|
||||
// put all handles into one handle group
|
||||
std::size_t id;
|
||||
typename DeformMesh::Handle_group active_handle_group = deform_mesh.create_handle_group();
|
||||
|
||||
while(handle_stream >> id) {
|
||||
deform_mesh.insert_handle(active_handle_group, vertices[id]);
|
||||
}
|
||||
while(roi_stream >> id) {
|
||||
deform_mesh.insert_roi(vertices[id]);
|
||||
}
|
||||
|
||||
return boost::make_optional(active_handle_group);
|
||||
}
|
||||
|
||||
template<class DeformMesh>
|
||||
bool preprocess_and_deform(DeformMesh& deform_mesh,
|
||||
const std::string& roi_file,
|
||||
const std::string& handle_file,
|
||||
typename DeformMesh::Vector translate,
|
||||
int deformation_iteration)
|
||||
{
|
||||
boost::optional<typename DeformMesh::Handle_group> active_handle_group =
|
||||
read_rois(deform_mesh, roi_file, handle_file);
|
||||
if(!active_handle_group) { return false; }
|
||||
|
||||
CGAL::Timer timer; timer.start();
|
||||
|
||||
if(!deform_mesh.preprocess()) {
|
||||
std::cerr << "Error: preprocess() failed!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::cerr << "Preprocess time: " << timer.time() << std::endl;
|
||||
timer.reset();
|
||||
|
||||
deform_mesh.translate(*active_handle_group, translate);
|
||||
deform_mesh.deform(deformation_iteration, 0);
|
||||
|
||||
std::cerr << "Deformation time (one handle translated and deform method iterated " <<
|
||||
deformation_iteration << " times): " << timer.time() << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
#include "Surface_modeling_test_commons.h"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/Polyhedron_items_with_id_3.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Deform_mesh.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3> Polyhedron;
|
||||
|
||||
typedef boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor;
|
||||
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, Vertex_index_map, Edge_index_map, CGAL::ORIGINAL_ARAP> Deform_mesh_arap;
|
||||
typedef CGAL::Deform_mesh<Polyhedron, Vertex_index_map, Edge_index_map, CGAL::SPOKES_AND_RIMS> Deform_mesh_spoke;
|
||||
|
||||
int main()
|
||||
{
|
||||
Polyhedron mesh_1;
|
||||
if(!read_to_polyhedron("data/square.off", mesh_1)) { return EXIT_FAILURE; }
|
||||
Polyhedron mesh_2 = mesh_1;
|
||||
|
||||
Deform_mesh_arap deform_mesh_arap(mesh_1, Vertex_index_map(), Edge_index_map());
|
||||
Deform_mesh_spoke deform_mesh_spoke(mesh_2, Vertex_index_map(), Edge_index_map());
|
||||
|
||||
const int deformation_iteration = 500;
|
||||
const double x = -0.45; const double y = -0.65; const double z = -0.0;
|
||||
|
||||
std::cerr << "ORIGINAL_ARAP performance: " << std::endl;
|
||||
bool successed = preprocess_and_deform(deform_mesh_arap,
|
||||
"data/Symmetry_test_roi.txt",
|
||||
"data/Symmetry_test_handle.txt",
|
||||
Deform_mesh_arap::Vector(x, y, z),
|
||||
deformation_iteration);
|
||||
if(!successed) { return EXIT_FAILURE; }
|
||||
|
||||
std::cerr << "SPOKES_AND_RIMS performance: " << std::endl;
|
||||
successed = preprocess_and_deform(deform_mesh_spoke,
|
||||
"data/Symmetry_test_roi.txt",
|
||||
"data/Symmetry_test_handle.txt",
|
||||
Deform_mesh_spoke::Vector(x, y, z),
|
||||
deformation_iteration);
|
||||
if(!successed) { return EXIT_FAILURE; }
|
||||
|
||||
std::cerr << "Save deformed models" << std::endl;
|
||||
std::ofstream("data/Symmetry_test_deformed_arap.off") << mesh_1;
|
||||
std::ofstream("data/Symmetry_test_deformed_spokes.off") << mesh_2;
|
||||
std::cerr << "All done!" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
419 418 417 416 415 414 435 434 433 432 440 439 438 437 436 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 431 430 429 428 427 426 425 424 423 422 421 420
|
||||
|
|
@ -0,0 +1 @@
|
|||
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 381 380 379 378 419 418 417 416 415 414 435 434 433 432 440 439 438 437 436 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 431 430 429 428 427 426 425 424 423 422 421 420
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue