From bd64af08fd3598631ae44d8621924d440e8fd066 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 4 Mar 2025 16:32:15 +0000 Subject: [PATCH 1/5] Mesh_2: make lloyd_optimize_mesh_2() deterministic --- .../CGAL/Mesh_2/Mesh_global_optimizer_2.h | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Mesh_2/include/CGAL/Mesh_2/Mesh_global_optimizer_2.h b/Mesh_2/include/CGAL/Mesh_2/Mesh_global_optimizer_2.h index d2df50df3fa..2501a07b83a 100644 --- a/Mesh_2/include/CGAL/Mesh_2/Mesh_global_optimizer_2.h +++ b/Mesh_2/include/CGAL/Mesh_2/Mesh_global_optimizer_2.h @@ -61,7 +61,14 @@ class Mesh_global_optimizer_2 typedef typename Gt::Vector_2 Vector_2; typedef typename std::vector Face_vector; - typedef typename std::set Vertex_set; + typedef std::pair IndexVertexPair; + struct IVP_less { + bool operator()(const IndexVertexPair& ivp1, const IndexVertexPair& ivp2) const + { + return ivp1.first < ivp2.first; + } + }; + typedef typename std::set Vertex_set; typedef typename std::list FT_list; typedef typename std::pair Move; @@ -114,13 +121,14 @@ public: // Fill set containing moving vertices Vertex_set moving_vertices; + std::size_t ind = 0; for(typename Tr::Finite_vertices_iterator vit = cdt_.finite_vertices_begin(); vit != cdt_.finite_vertices_end(); ++vit ) { if(!cdt_.are_there_incident_constraints(vit)) - moving_vertices.insert(vit); + moving_vertices.insert(std::make_pair(ind++, vit)); } double initial_vertices_nb = static_cast(moving_vertices.size()); @@ -236,11 +244,12 @@ private: std::fill(big_moves_.begin(), big_moves_.end(), FT(0)); // Get move for each moving vertex - for ( typename Vertex_set::const_iterator vit = moving_vertices.begin() ; - vit != moving_vertices.end() ; ) + for ( typename Vertex_set::iterator vit = moving_vertices.begin() ; + vit != moving_vertices.end() ;) { - Vertex_handle oldv = *vit; + Vertex_handle oldv = vit->second; Vector_2 move = compute_move(oldv); + typename Vertex_set::iterator old_vit = vit; ++vit; if ( CGAL::NULL_VECTOR != move ) @@ -249,7 +258,7 @@ private: moves.push_back(std::make_pair(oldv, new_position)); } else if(sq_freeze_ratio_ > 0.) //freezing ON - moving_vertices.erase(oldv); + moving_vertices.erase(old_vit); // Stop if time_limit_ is reached if ( is_time_limit_reached() ) From b607697dd988dcfba7b8c831afddcc5a2c0822f6 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 14 Mar 2025 18:28:04 +0100 Subject: [PATCH 2/5] Add test program for the issue --- Mesh_2/test/Mesh_2/issue8719.cpp | 193 +++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 Mesh_2/test/Mesh_2/issue8719.cpp diff --git a/Mesh_2/test/Mesh_2/issue8719.cpp b/Mesh_2/test/Mesh_2/issue8719.cpp new file mode 100644 index 00000000000..d333c9cd901 --- /dev/null +++ b/Mesh_2/test/Mesh_2/issue8719.cpp @@ -0,0 +1,193 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Delaunay_mesh_vertex_base_2 Vb; +typedef CGAL::Delaunay_mesh_face_base_2 Fb; +typedef CGAL::Triangulation_data_structure_2 Tds; +typedef CGAL::Constrained_Delaunay_triangulation_2 CDT; +typedef CGAL::Delaunay_mesh_size_criteria_2 Criteria; +typedef CGAL::Delaunay_mesher_2 Mesher; +typedef CDT::Vertex_handle Vertex_handle; +typedef CDT::Point Point; + + +using namespace std; + +std::string result; + +void CGAL_Remesh(double* vert_xyz_array, size_t vert_count, double criteria_a, double criteria_b, int iteration_number, double*& newVertices, int*& vCount, int*& newFaces, int*& fCount, int fileNum) +{ + CDT cdt; + + + + vector cdt_Vh_Boundary; + + for (int i = 0; i < vert_count; ++i) + { + Vertex_handle vh = cdt.insert(Point(vert_xyz_array[3 * i + 0], vert_xyz_array[3 * i + 1])); + cdt_Vh_Boundary.push_back(vh); + } + + // insert Constrain + for (int i = 0; i < cdt_Vh_Boundary.size() - 1; ++i) + { + cdt.insert_constraint(cdt_Vh_Boundary[i], cdt_Vh_Boundary[i + 1]); + } + cdt.insert_constraint(cdt_Vh_Boundary[cdt_Vh_Boundary.size() - 1], cdt_Vh_Boundary[0]); + + // refine and optimize mesh + + Mesher mesher(cdt); + mesher.set_criteria(Criteria(criteria_a, criteria_b)); + mesher.refine_mesh(); + CGAL::lloyd_optimize_mesh_2(cdt, CGAL::parameters::max_iteration_number = iteration_number); + + + // make index pair + vector visitedVertices; // collect visited vertices + + map indexList; // create a map to note the index + + int i = 0; + for (CDT::Vertex_iterator v_it = cdt.vertices_begin(); v_it != cdt.vertices_end(); ++v_it) + { + + CDT::Vertex_handle vh = v_it->handle(); + indexList[vh] = i; + visitedVertices.push_back(vh); + i++; + } + + // Convert data into double array + int vNum = cdt.number_of_vertices(); + + newVertices = new double[vNum * 3]; + + i = 0; + for (CDT::Vertex_iterator vi = cdt.vertices_begin(); vi != cdt.vertices_end(); ++vi) + { + newVertices[i] = vi->point()[0]; + i += 1; + newVertices[i] = vi->point()[1]; + i += 1; + newVertices[i] = 0; + i += 1; + } + + + int vertexCount = vNum; + vCount = &vertexCount; + + int num_face_in_domain = 0; + + for (CDT::Face_iterator f_it = cdt.faces_begin(); f_it != cdt.faces_end(); ++f_it) + { + CDT::Face_handle face = f_it; + if (face->is_in_domain()) + { + num_face_in_domain++; + } + } + + + newFaces = new int[num_face_in_domain * 3]; + + + i = 0; + for (CDT::Face_iterator f_it = cdt.faces_begin(); f_it != cdt.faces_end(); ++f_it) + { + CDT::Face_handle face = f_it; + + if (face->is_in_domain()) + { + newFaces[i] = int(indexList.find(face->vertex(0)->handle())->second); + i += 1; + newFaces[i] = int(indexList.find(face->vertex(1)->handle())->second); + i += 1; + newFaces[i] = int(indexList.find(face->vertex(2)->handle())->second); + i += 1; + } + } + int faceCount = num_face_in_domain; + fCount = &faceCount; + + + // print + std::stringstream outputFile; + + if (fCount && newFaces) { + outputFile << "\nRemeshed faces (" << *fCount << "):\n"; + for (int i = 0; i < (*fCount) * 3; i += 3) { + outputFile << newFaces[i] << " " << newFaces[i + 1] << " " << newFaces[i + 2] << "\n"; + } + } + + if(fileNum == 1) + { + result = outputFile.str(); + } + else + { + assert(result == outputFile.str()); + } + +} + +int main() +{ + // + double vert_xyz_array[] = { + 3375.4981, 1935.35224056, 0.0, + 3350.77259333, 2066.38188194, 0.0, + 3210.83712383, 2054.53004190, 0.0, + 3068.88, 2060.98161842, 0.0, + 3034.24939361, 2066.55369658, 0.0, + 3025.6776, 2008.40156297, 0.0, + 3013.23241519, 1927.9864, 0.0, + 3033.36312437, 1924.87291062, 0.0, + 3078.68871988, 1917.86131994, 0.0, + 3124.01437021, 1910.85008365, 0.0, + 3167.66255113, 1908.86629111, 0.0, + 3169.83178711, 1908.76770020, 0.0, + 3215.64920401, 1906.68531674, 0.0, + 3260.96808047, 1913.74020504, 0.0, + 3306.03738982, 1922.24487242, 0.0, + 3351.10669914, 1930.74953992, 0.0 + }; + + + size_t vert_count = 16; + double criteria_a = 0.125; + double criteria_b = 36.691771392; + int iteration_number = 20; + + double* newVertices = nullptr; + int* vCount = nullptr; + int* newFaces = nullptr; + int* fCount = nullptr; + + for (int i = 1; i <= 2; ++i) + { + CGAL_Remesh(vert_xyz_array, vert_count, criteria_a, criteria_b, iteration_number, newVertices, vCount, newFaces, fCount, i); + } + + + std::cout << "\nDone"; + + + return 0; +} From 7d755732708b541e839a6e7ea1ba949be5b688da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 14 Mar 2025 20:15:09 +0100 Subject: [PATCH 3/5] no tabs --- Mesh_2/test/Mesh_2/issue8719.cpp | 236 +++++++++++++++---------------- 1 file changed, 118 insertions(+), 118 deletions(-) diff --git a/Mesh_2/test/Mesh_2/issue8719.cpp b/Mesh_2/test/Mesh_2/issue8719.cpp index d333c9cd901..326174e58f6 100644 --- a/Mesh_2/test/Mesh_2/issue8719.cpp +++ b/Mesh_2/test/Mesh_2/issue8719.cpp @@ -30,164 +30,164 @@ std::string result; void CGAL_Remesh(double* vert_xyz_array, size_t vert_count, double criteria_a, double criteria_b, int iteration_number, double*& newVertices, int*& vCount, int*& newFaces, int*& fCount, int fileNum) { - CDT cdt; + CDT cdt; - vector cdt_Vh_Boundary; + vector cdt_Vh_Boundary; - for (int i = 0; i < vert_count; ++i) - { - Vertex_handle vh = cdt.insert(Point(vert_xyz_array[3 * i + 0], vert_xyz_array[3 * i + 1])); - cdt_Vh_Boundary.push_back(vh); - } + for (int i = 0; i < vert_count; ++i) + { + Vertex_handle vh = cdt.insert(Point(vert_xyz_array[3 * i + 0], vert_xyz_array[3 * i + 1])); + cdt_Vh_Boundary.push_back(vh); + } - // insert Constrain - for (int i = 0; i < cdt_Vh_Boundary.size() - 1; ++i) - { - cdt.insert_constraint(cdt_Vh_Boundary[i], cdt_Vh_Boundary[i + 1]); - } - cdt.insert_constraint(cdt_Vh_Boundary[cdt_Vh_Boundary.size() - 1], cdt_Vh_Boundary[0]); + // insert Constrain + for (int i = 0; i < cdt_Vh_Boundary.size() - 1; ++i) + { + cdt.insert_constraint(cdt_Vh_Boundary[i], cdt_Vh_Boundary[i + 1]); + } + cdt.insert_constraint(cdt_Vh_Boundary[cdt_Vh_Boundary.size() - 1], cdt_Vh_Boundary[0]); - // refine and optimize mesh + // refine and optimize mesh - Mesher mesher(cdt); - mesher.set_criteria(Criteria(criteria_a, criteria_b)); - mesher.refine_mesh(); + Mesher mesher(cdt); + mesher.set_criteria(Criteria(criteria_a, criteria_b)); + mesher.refine_mesh(); CGAL::lloyd_optimize_mesh_2(cdt, CGAL::parameters::max_iteration_number = iteration_number); - // make index pair - vector visitedVertices; // collect visited vertices + // make index pair + vector visitedVertices; // collect visited vertices - map indexList; // create a map to note the index + map indexList; // create a map to note the index - int i = 0; - for (CDT::Vertex_iterator v_it = cdt.vertices_begin(); v_it != cdt.vertices_end(); ++v_it) - { + int i = 0; + for (CDT::Vertex_iterator v_it = cdt.vertices_begin(); v_it != cdt.vertices_end(); ++v_it) + { - CDT::Vertex_handle vh = v_it->handle(); - indexList[vh] = i; - visitedVertices.push_back(vh); - i++; - } + CDT::Vertex_handle vh = v_it->handle(); + indexList[vh] = i; + visitedVertices.push_back(vh); + i++; + } - // Convert data into double array - int vNum = cdt.number_of_vertices(); + // Convert data into double array + int vNum = cdt.number_of_vertices(); - newVertices = new double[vNum * 3]; + newVertices = new double[vNum * 3]; - i = 0; - for (CDT::Vertex_iterator vi = cdt.vertices_begin(); vi != cdt.vertices_end(); ++vi) - { - newVertices[i] = vi->point()[0]; - i += 1; - newVertices[i] = vi->point()[1]; - i += 1; - newVertices[i] = 0; - i += 1; - } + i = 0; + for (CDT::Vertex_iterator vi = cdt.vertices_begin(); vi != cdt.vertices_end(); ++vi) + { + newVertices[i] = vi->point()[0]; + i += 1; + newVertices[i] = vi->point()[1]; + i += 1; + newVertices[i] = 0; + i += 1; + } - int vertexCount = vNum; - vCount = &vertexCount; + int vertexCount = vNum; + vCount = &vertexCount; - int num_face_in_domain = 0; + int num_face_in_domain = 0; - for (CDT::Face_iterator f_it = cdt.faces_begin(); f_it != cdt.faces_end(); ++f_it) - { - CDT::Face_handle face = f_it; - if (face->is_in_domain()) - { - num_face_in_domain++; - } - } + for (CDT::Face_iterator f_it = cdt.faces_begin(); f_it != cdt.faces_end(); ++f_it) + { + CDT::Face_handle face = f_it; + if (face->is_in_domain()) + { + num_face_in_domain++; + } + } - newFaces = new int[num_face_in_domain * 3]; + newFaces = new int[num_face_in_domain * 3]; - i = 0; - for (CDT::Face_iterator f_it = cdt.faces_begin(); f_it != cdt.faces_end(); ++f_it) - { - CDT::Face_handle face = f_it; + i = 0; + for (CDT::Face_iterator f_it = cdt.faces_begin(); f_it != cdt.faces_end(); ++f_it) + { + CDT::Face_handle face = f_it; - if (face->is_in_domain()) - { - newFaces[i] = int(indexList.find(face->vertex(0)->handle())->second); - i += 1; - newFaces[i] = int(indexList.find(face->vertex(1)->handle())->second); - i += 1; - newFaces[i] = int(indexList.find(face->vertex(2)->handle())->second); - i += 1; - } - } - int faceCount = num_face_in_domain; - fCount = &faceCount; + if (face->is_in_domain()) + { + newFaces[i] = int(indexList.find(face->vertex(0)->handle())->second); + i += 1; + newFaces[i] = int(indexList.find(face->vertex(1)->handle())->second); + i += 1; + newFaces[i] = int(indexList.find(face->vertex(2)->handle())->second); + i += 1; + } + } + int faceCount = num_face_in_domain; + fCount = &faceCount; - // print - std::stringstream outputFile; + // print + std::stringstream outputFile; - if (fCount && newFaces) { - outputFile << "\nRemeshed faces (" << *fCount << "):\n"; - for (int i = 0; i < (*fCount) * 3; i += 3) { - outputFile << newFaces[i] << " " << newFaces[i + 1] << " " << newFaces[i + 2] << "\n"; - } - } + if (fCount && newFaces) { + outputFile << "\nRemeshed faces (" << *fCount << "):\n"; + for (int i = 0; i < (*fCount) * 3; i += 3) { + outputFile << newFaces[i] << " " << newFaces[i + 1] << " " << newFaces[i + 2] << "\n"; + } + } - if(fileNum == 1) - { - result = outputFile.str(); - } - else - { - assert(result == outputFile.str()); - } + if(fileNum == 1) + { + result = outputFile.str(); + } + else + { + assert(result == outputFile.str()); + } } int main() { - // - double vert_xyz_array[] = { - 3375.4981, 1935.35224056, 0.0, - 3350.77259333, 2066.38188194, 0.0, - 3210.83712383, 2054.53004190, 0.0, - 3068.88, 2060.98161842, 0.0, - 3034.24939361, 2066.55369658, 0.0, - 3025.6776, 2008.40156297, 0.0, - 3013.23241519, 1927.9864, 0.0, - 3033.36312437, 1924.87291062, 0.0, - 3078.68871988, 1917.86131994, 0.0, - 3124.01437021, 1910.85008365, 0.0, - 3167.66255113, 1908.86629111, 0.0, - 3169.83178711, 1908.76770020, 0.0, - 3215.64920401, 1906.68531674, 0.0, - 3260.96808047, 1913.74020504, 0.0, - 3306.03738982, 1922.24487242, 0.0, - 3351.10669914, 1930.74953992, 0.0 - }; + // + double vert_xyz_array[] = { + 3375.4981, 1935.35224056, 0.0, + 3350.77259333, 2066.38188194, 0.0, + 3210.83712383, 2054.53004190, 0.0, + 3068.88, 2060.98161842, 0.0, + 3034.24939361, 2066.55369658, 0.0, + 3025.6776, 2008.40156297, 0.0, + 3013.23241519, 1927.9864, 0.0, + 3033.36312437, 1924.87291062, 0.0, + 3078.68871988, 1917.86131994, 0.0, + 3124.01437021, 1910.85008365, 0.0, + 3167.66255113, 1908.86629111, 0.0, + 3169.83178711, 1908.76770020, 0.0, + 3215.64920401, 1906.68531674, 0.0, + 3260.96808047, 1913.74020504, 0.0, + 3306.03738982, 1922.24487242, 0.0, + 3351.10669914, 1930.74953992, 0.0 + }; - size_t vert_count = 16; - double criteria_a = 0.125; - double criteria_b = 36.691771392; - int iteration_number = 20; + size_t vert_count = 16; + double criteria_a = 0.125; + double criteria_b = 36.691771392; + int iteration_number = 20; - double* newVertices = nullptr; - int* vCount = nullptr; - int* newFaces = nullptr; - int* fCount = nullptr; + double* newVertices = nullptr; + int* vCount = nullptr; + int* newFaces = nullptr; + int* fCount = nullptr; - for (int i = 1; i <= 2; ++i) - { - CGAL_Remesh(vert_xyz_array, vert_count, criteria_a, criteria_b, iteration_number, newVertices, vCount, newFaces, fCount, i); - } + for (int i = 1; i <= 2; ++i) + { + CGAL_Remesh(vert_xyz_array, vert_count, criteria_a, criteria_b, iteration_number, newVertices, vCount, newFaces, fCount, i); + } - std::cout << "\nDone"; + std::cout << "\nDone"; - return 0; + return 0; } From 3df849036fc14fac8c2e2d9aa921486f36d14f08 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 18 Mar 2025 08:22:46 +0100 Subject: [PATCH 4/5] warnings --- Mesh_2/test/Mesh_2/issue8719.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mesh_2/test/Mesh_2/issue8719.cpp b/Mesh_2/test/Mesh_2/issue8719.cpp index 326174e58f6..d7bec6e9872 100644 --- a/Mesh_2/test/Mesh_2/issue8719.cpp +++ b/Mesh_2/test/Mesh_2/issue8719.cpp @@ -36,14 +36,14 @@ void CGAL_Remesh(double* vert_xyz_array, size_t vert_count, double criteria_a, d vector cdt_Vh_Boundary; - for (int i = 0; i < vert_count; ++i) + for (size_t i = 0; i < vert_count; ++i) { Vertex_handle vh = cdt.insert(Point(vert_xyz_array[3 * i + 0], vert_xyz_array[3 * i + 1])); cdt_Vh_Boundary.push_back(vh); } // insert Constrain - for (int i = 0; i < cdt_Vh_Boundary.size() - 1; ++i) + for (size_t i = 0; i < cdt_Vh_Boundary.size() - 1; ++i) { cdt.insert_constraint(cdt_Vh_Boundary[i], cdt_Vh_Boundary[i + 1]); } From 7da3375f9e756a7cbfe155bba0eddeea087cacee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 24 Mar 2025 11:48:32 +0100 Subject: [PATCH 5/5] do not use deprecated handle() function --- Mesh_2/test/Mesh_2/issue8719.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Mesh_2/test/Mesh_2/issue8719.cpp b/Mesh_2/test/Mesh_2/issue8719.cpp index d7bec6e9872..3ca90ac4b24 100644 --- a/Mesh_2/test/Mesh_2/issue8719.cpp +++ b/Mesh_2/test/Mesh_2/issue8719.cpp @@ -66,7 +66,7 @@ void CGAL_Remesh(double* vert_xyz_array, size_t vert_count, double criteria_a, d for (CDT::Vertex_iterator v_it = cdt.vertices_begin(); v_it != cdt.vertices_end(); ++v_it) { - CDT::Vertex_handle vh = v_it->handle(); + CDT::Vertex_handle vh = v_it; indexList[vh] = i; visitedVertices.push_back(vh); i++; @@ -114,11 +114,11 @@ void CGAL_Remesh(double* vert_xyz_array, size_t vert_count, double criteria_a, d if (face->is_in_domain()) { - newFaces[i] = int(indexList.find(face->vertex(0)->handle())->second); + newFaces[i] = int(indexList.find(face->vertex(0))->second); i += 1; - newFaces[i] = int(indexList.find(face->vertex(1)->handle())->second); + newFaces[i] = int(indexList.find(face->vertex(1))->second); i += 1; - newFaces[i] = int(indexList.find(face->vertex(2)->handle())->second); + newFaces[i] = int(indexList.find(face->vertex(2))->second); i += 1; } }