From 078e89f55f19407a413fdb37ed5c39b70b48526c Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Tue, 8 Jul 2014 15:37:59 +0200 Subject: [PATCH] Add the possibility to remove the far points The far points are added by the parallel version to reduce the contention on the infinite vertex --- Mesh_3/include/CGAL/Mesh_3/Mesher_3.h | 8 +- .../CGAL/Mesh_complex_3_in_triangulation_3.h | 84 ++++++++++++++++++- Mesh_3/include/CGAL/refine_mesh_3.h | 16 ++++ .../Mesh_3/test_backward_compatibility.cpp | 2 + .../Mesh_3/test_meshing_implicit_function.cpp | 6 +- .../test/Mesh_3/test_meshing_polyhedron.cpp | 4 +- .../test_meshing_polyhedron_with_features.cpp | 2 + .../Mesh_3/test_meshing_unit_tetrahedron.cpp | 5 +- Mesh_3/test/Mesh_3/test_meshing_utilities.h | 2 +- .../include/CGAL/Regular_triangulation_3.h | 12 +++ 10 files changed, 128 insertions(+), 13 deletions(-) diff --git a/Mesh_3/include/CGAL/Mesh_3/Mesher_3.h b/Mesh_3/include/CGAL/Mesh_3/Mesher_3.h index 71e9e6c2fcc..cea06d3fbf6 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Mesher_3.h +++ b/Mesh_3/include/CGAL/Mesh_3/Mesher_3.h @@ -508,7 +508,7 @@ initialize() # ifndef CGAL_PARALLEL_MESH_3_DO_NOT_ADD_OUTSIDE_POINTS_ON_A_FAR_SPHERE - if (r_c3t3_.number_of_facets() == 0) + if (r_c3t3_.number_of_far_points() == 0 && r_c3t3_.number_of_facets() == 0) { const Bbox_3 &bbox = estimated_bbox; @@ -531,7 +531,7 @@ initialize() tbb::task_scheduler_init::default_num_threads() * Concurrent_mesher_config::get().num_pseudo_infinite_vertices_per_core); for (int i = 0 ; i < NUM_PSEUDO_INFINITE_VERTICES ; ++i, ++random_point) - r_c3t3_.triangulation().insert(*random_point + center); + r_c3t3_.add_far_point(*random_point + center); # ifdef CGAL_CONCURRENT_MESH_3_VERBOSE std::cerr << "done." << std::endl; @@ -555,7 +555,7 @@ initialize() #endif // CGAL_LINKED_WITH_TBB { #ifdef CGAL_SEQUENTIAL_MESH_3_ADD_OUTSIDE_POINTS_ON_A_FAR_SPHERE - if (r_c3t3_.number_of_facets() == 0) + if (r_c3t3_.number_of_far_points() == 0 && r_c3t3_.number_of_facets() == 0) { /*std::cerr << "A little bit of refinement... "; @@ -590,7 +590,7 @@ initialize() Random_points_on_sphere_3 random_point(radius); const int NUM_PSEUDO_INFINITE_VERTICES = 12*2; for (int i = 0 ; i < NUM_PSEUDO_INFINITE_VERTICES ; ++i, ++random_point) - r_c3t3_.triangulation().insert(*random_point + center); + r_c3t3_.add_far_point(*random_point + center); # ifdef CGAL_MESH_3_VERBOSE std::cerr << "done." << std::endl; # endif diff --git a/Mesh_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h b/Mesh_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h index 999f921061d..ffb0de11bae 100644 --- a/Mesh_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h +++ b/Mesh_3/include/CGAL/Mesh_complex_3_in_triangulation_3.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009-2010 INRIA Sophia-Antipolis (France). +// Copyright (c) 2009-2014 INRIA Sophia-Antipolis (France). // Copyright (c) 2010-2013 GeometryFactory Sarl (France). // All rights reserved. // @@ -17,7 +17,7 @@ // $Id$ // // -// Author(s) : Stephane Tayeb +// Author(s) : Stephane Tayeb, Clement Jamin // //****************************************************************************** // File Description : @@ -60,7 +60,8 @@ private: public: typedef typename Base::size_type size_type; - + + typedef typename Tr::Point Point; typedef typename Base::Edge Edge; typedef typename Base::Vertex_handle Vertex_handle; typedef CornerIndex Corner_index; @@ -83,6 +84,8 @@ private: // Type to store the corners typedef std::map Corner_map; + // Type to store far vertices + typedef std::vector Far_vertices_vec; public: /** @@ -120,6 +123,7 @@ public: Base::swap(rhs); edges_.swap(rhs.edges_); corners_.swap(rhs.corners_); + far_vertices_.swap(rhs.far_vertices_); } /** @@ -136,6 +140,9 @@ public: using Base::is_in_complex; using Base::add_to_complex; using Base::remove_from_complex; + using Base::triangulation; + using Base::set_surface_patch_index; + /** @@ -193,6 +200,62 @@ public: v->set_dimension(-1); } + std::size_t number_of_far_points() const + { + return far_vertices_.size(); + } + + void add_far_point(const Point &p) + { + far_vertices_.push_back(triangulation().insert(p)); + } + + void add_far_point(Vertex_handle vh) + { + far_vertices_.push_back(vh); + } + + void remove_far_points() + { + Triangulation &tr = triangulation(); + //triangulation().remove(far_vertices_.begin(), far_vertices_.end()); + Far_vertices_vec::const_iterator it = far_vertices_.begin(); + Far_vertices_vec::const_iterator it_end = far_vertices_.end(); + for ( ; it != it_end ; ++it) + { + std::vector new_cells; + new_cells.reserve(32); + tr.remove_and_give_new_cells(*it, std::back_inserter(new_cells)); + + std::vector::iterator nc_it = new_cells.begin(); + std::vector::iterator nc_it_end = new_cells.end(); + for ( ; nc_it != nc_it_end ; ++nc_it) + { + Cell_handle c = *nc_it; + for (int i = 0 ; i < 4 ; ++i) + { + Facet mirror_facet = tr.mirror_facet(std::make_pair(c, i)); + if (is_in_complex(mirror_facet)) + { + set_surface_patch_index(c, i, + surface_patch_index(mirror_facet)); + } + } + /*int i_inf; + if (c->has_vertex(tr.infinite_vertex(), i_inf)) + { + Facet mirror_facet = tr.mirror_facet(std::make_pair(c, i_inf)); + if (is_in_complex(mirror_facet)) + { + set_surface_patch_index(c, i_inf, + surface_patch_index(mirror_facet)); + } + }*/ + } + } + far_vertices_.clear(); + } + /** * Returns the number of edges of c3t3 */ @@ -479,6 +542,7 @@ private: private: Edge_map edges_; Corner_map corners_; + Far_vertices_vec far_vertices_; }; @@ -513,6 +577,20 @@ Mesh_complex_3_in_triangulation_3(const Self& rhs) this->triangulation().is_vertex(it->first->point(), new_v); this->add_to_complex(new_v, it->second); } + + // Parse vertices to identify far vertices + if (rhs.far_vertices_.size() > 0) + { + Triangulation &tr = triangulation(); + typename Tr::Finite_vertices_iterator vit = tr.finite_vertices_begin(); + for(typename Tr::Finite_vertices_iterator end = tr.finite_vertices_end(); + vit != end ; ++vit) + { + if (vit->in_dimension() == -1) + far_vertices_.push_back(vit); + } + CGAL_assertion(far_vertices_.size() == rhs.far_vertices_.size()); + } } diff --git a/Mesh_3/include/CGAL/refine_mesh_3.h b/Mesh_3/include/CGAL/refine_mesh_3.h index 0c4cc81a56f..ec861a810d0 100644 --- a/Mesh_3/include/CGAL/refine_mesh_3.h +++ b/Mesh_3/include/CGAL/refine_mesh_3.h @@ -70,6 +70,22 @@ namespace CGAL { Vertex_handle new_vertex = r_c3t3_.triangulation().insert(point); r_c3t3_.set_index(new_vertex, index); r_c3t3_.set_dimension(new_vertex, dimension); + +#if defined(CGAL_LINKED_WITH_TBB)\ + && !defined(CGAL_PARALLEL_MESH_3_DO_NOT_ADD_OUTSIDE_POINTS_ON_A_FAR_SPHERE) + if (boost::is_convertible::value) + { + if (dimension == -1) + r_c3t3_.add_far_point(new_vertex); + } +#endif +#ifdef CGAL_SEQUENTIAL_MESH_3_ADD_OUTSIDE_POINTS_ON_A_FAR_SPHERE + if (boost::is_convertible::value) + { + if (dimension == -1) + r_c3t3_.add_far_point(new_vertex); + } +#endif } private: diff --git a/Mesh_3/test/Mesh_3/test_backward_compatibility.cpp b/Mesh_3/test/Mesh_3/test_backward_compatibility.cpp index dc108a3dacf..6b121ed4486 100644 --- a/Mesh_3/test/Mesh_3/test_backward_compatibility.cpp +++ b/Mesh_3/test/Mesh_3/test_backward_compatibility.cpp @@ -85,6 +85,7 @@ struct Mesh_new_facet_criteria { #include #include +#include // Domain typedef CGAL::Exact_predicates_inexact_constructions_kernel K; @@ -128,6 +129,7 @@ void test() // Mesh generation C3t3 c3t3 = CGAL::make_mesh_3(domain, criteria, no_exude(), no_perturb()); CGAL::refine_mesh_3(c3t3, domain, new_criteria, no_exude(), no_perturb()); + CGAL::remove_far_points_in_mesh_3(c3t3); std::cout << "Number of vertices: " << c3t3.triangulation().number_of_vertices() << "\n" diff --git a/Mesh_3/test/Mesh_3/test_meshing_implicit_function.cpp b/Mesh_3/test/Mesh_3/test_meshing_implicit_function.cpp index 427e2f37695..4455640b763 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_implicit_function.cpp +++ b/Mesh_3/test/Mesh_3/test_meshing_implicit_function.cpp @@ -85,9 +85,11 @@ struct Implicit_tester : public Tester CGAL::refine_mesh_3(c3t3, domain, criteria, CGAL::parameters::no_exude(), CGAL::parameters::no_perturb()); - + + CGAL::remove_far_points_in_mesh_3(c3t3); + // Verify - this->verify(c3t3,domain,criteria,Bissection_tag(),50,58,80,90); + this->verify(c3t3,domain,criteria,Bissection_tag(), 50, 58, 70, 90); } }; diff --git a/Mesh_3/test/Mesh_3/test_meshing_polyhedron.cpp b/Mesh_3/test/Mesh_3/test_meshing_polyhedron.cpp index 606ace1e4a3..a6b29c05b8d 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_polyhedron.cpp +++ b/Mesh_3/test/Mesh_3/test_meshing_polyhedron.cpp @@ -75,12 +75,14 @@ struct Polyhedron_tester : public Tester CGAL::refine_mesh_3(c3t3, domain, criteria, CGAL::parameters::no_exude(), CGAL::parameters::no_perturb()); + + CGAL::remove_far_points_in_mesh_3(c3t3); // Verify double vol = 0.479171765761454; this->verify_c3t3_volume(c3t3, vol*0.95, vol*1.05); this->verify(c3t3,domain,criteria,Polyhedral_tag(), - 119, 121, 200, 204, 350, 360); } + 110, 140, 190, 230, 350, 420); } }; int main() diff --git a/Mesh_3/test/Mesh_3/test_meshing_polyhedron_with_features.cpp b/Mesh_3/test/Mesh_3/test_meshing_polyhedron_with_features.cpp index 48bc8172b62..7d6e0867fca 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_polyhedron_with_features.cpp +++ b/Mesh_3/test/Mesh_3/test_meshing_polyhedron_with_features.cpp @@ -68,6 +68,8 @@ struct Polyhedron_with_features_tester : public Tester CGAL::parameters::no_exude(), CGAL::parameters::no_perturb()); + CGAL::remove_far_points_in_mesh_3(c3t3); + // Verify this->verify(c3t3,domain,criteria, Polyhedral_tag()); //, 1099, 1099, 1158, 1158, 4902, 4902); diff --git a/Mesh_3/test/Mesh_3/test_meshing_unit_tetrahedron.cpp b/Mesh_3/test/Mesh_3/test_meshing_unit_tetrahedron.cpp index 6c87faf72dc..19aac665802 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_unit_tetrahedron.cpp +++ b/Mesh_3/test/Mesh_3/test_meshing_unit_tetrahedron.cpp @@ -58,10 +58,11 @@ struct Polyhedron_tester : public Tester cell_size = cs); // Mesh generation C3t3 c3t3 = CGAL::make_mesh_3(domain, criteria); - + + CGAL::remove_far_points_in_mesh_3(c3t3); + double vol = 1/6.; this->verify_c3t3_volume(c3t3, vol*0.95, vol*1.05); - this->verify_c3t3(c3t3,domain,Polyhedral_tag(), 55, 65, 110, 125, 85, 120); } diff --git a/Mesh_3/test/Mesh_3/test_meshing_utilities.h b/Mesh_3/test/Mesh_3/test_meshing_utilities.h index 72c2b85735f..1449d44c6bd 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_utilities.h +++ b/Mesh_3/test/Mesh_3/test_meshing_utilities.h @@ -377,7 +377,7 @@ struct Tester const double reference_value) const { double hdist = compute_hausdorff_distance(c3t3, domain, Polyhedral_tag()); - assert(hdist <= reference_value*1.01); + assert(hdist <= reference_value*1.05); } template diff --git a/Triangulation_3/include/CGAL/Regular_triangulation_3.h b/Triangulation_3/include/CGAL/Regular_triangulation_3.h index 7f86a6c33e7..cd47e98642b 100644 --- a/Triangulation_3/include/CGAL/Regular_triangulation_3.h +++ b/Triangulation_3/include/CGAL/Regular_triangulation_3.h @@ -660,6 +660,18 @@ namespace CGAL { return n - number_of_vertices(); } + + template + void remove_and_give_new_cells(Vertex_handle v, OutputItCells cit) + { + Self tmp; + Vertex_remover remover (tmp); + Tr_Base::remove_and_give_new_cells(v, remover, cit); + + CGAL_triangulation_expensive_postcondition(is_valid()); + } + + // DISPLACEMENT Vertex_handle move_point(Vertex_handle v, const Weighted_point & p);