Created
August 15, 2017 14:01
-
-
Save Maghoumi/b13f061aecd7db7057d596388bbc4014 to your computer and use it in GitHub Desktop.
The code for problem described in (http://cgal-discuss.949826.n4.nabble.com/Mesh-deformation-produces-strange-results-td4662924.html)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef CGAL::Exact_predicates_inexact_constructions_kernel K; | |
typedef K::Point_3 Point_3; | |
typedef CGAL::Surface_mesh<Point_3> Mesh; | |
typedef boost::graph_traits<Mesh>::vertex_descriptor vertex_descriptor; | |
typedef boost::graph_traits<Mesh>::vertex_iterator vertex_iterator; | |
typedef boost::graph_traits<Mesh>::halfedge_iterator halfedge_iterator; | |
typedef CGAL::Surface_mesh_deformation<Mesh, CGAL::Default, CGAL::Default, CGAL::Deformation_algorithm_tag::SRE_ARAP> Surface_mesh_deformation; | |
void deformMesh(Mesh &cgalMesh, int* ctrlPtIdx, Vector3* targetPositions, int pointCount, int iterations, double tolerance) | |
{ | |
// Create a deformation object | |
Surface_mesh_deformation deform_mesh(cgalMesh); | |
deform_mesh.set_sre_arap_alpha(0); | |
// Definition of the region of interest (use the whole mesh) | |
vertex_iterator vb, ve; | |
boost::tie(vb, ve) = vertices(cgalMesh); | |
deform_mesh.insert_roi_vertices(vb, ve); | |
vector<vertex_descriptor> _ctrlPtIdx; | |
vector<Surface_mesh_deformation::Point> _targetPositions; | |
for (int i = 0; i < pointCount; i++) { | |
vertex_descriptor control_p = *CGAL::cpp11::next(vb, ctrlPtIdx[i]); | |
_ctrlPtIdx.push_back(control_p); | |
deform_mesh.insert_control_vertex(control_p); | |
_targetPositions.push_back(Surface_mesh_deformation::Point(targetPositions[i].x, targetPositions[i].y, targetPositions[i].z)); | |
} | |
cout << "Preprocessing..." << endl; | |
bool is_matrix_factorization_OK = deform_mesh.preprocess(); | |
if (!is_matrix_factorization_OK) { | |
std::cerr << "Error in preprocessing, check documentation of preprocess()" << std::endl; | |
return; | |
} | |
for (int j = 0; j < pointCount; j++) | |
deform_mesh.set_target_position(_ctrlPtIdx[j], _targetPositions[j]); | |
cout << "Deforming..." << endl; | |
deform_mesh.deform(iterations, tolerance); | |
cout << "Saving..." << endl; | |
// Save the deformed mesh into a file | |
std::ofstream out1("deform.off"); | |
out1 << cgalMesh; | |
out1.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment