From 2e7e6341dde68d4df33bbdee58ea399d274743f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 8 Jun 2022 23:24:25 +0200 Subject: [PATCH] update tests --- .../facets_in_complex_3_to_triangle_mesh.h | 74 +++++++++++-------- SMDS_3/test/SMDS_3/test_c3t3.cpp | 2 +- .../test/SMDS_3/test_c3t3_into_facegraph.cpp | 17 ++--- SMDS_3/test/SMDS_3/test_c3t3_io.cpp | 4 +- 4 files changed, 53 insertions(+), 44 deletions(-) diff --git a/SMDS_3/include/CGAL/facets_in_complex_3_to_triangle_mesh.h b/SMDS_3/include/CGAL/facets_in_complex_3_to_triangle_mesh.h index 1e3ce6fd164..c4d801129bb 100644 --- a/SMDS_3/include/CGAL/facets_in_complex_3_to_triangle_mesh.h +++ b/SMDS_3/include/CGAL/facets_in_complex_3_to_triangle_mesh.h @@ -18,19 +18,18 @@ #include #include +#include +#include #include #include -#include -#include #include -#include -#include -#include +#include #include #include #include +#include #include namespace CGAL { @@ -39,6 +38,18 @@ namespace SMDS_3 { namespace internal { +template +void resize(Polygon& p, std::size_t size) +{ + p.resize(size); +} + +template +void resize(std::array&, std::size_t CGAL_assertion_code(size)) +{ + CGAL_assertion(size == N); +} + template void facets_in_complex_3_to_triangle_soup(const C3T3& c3t3, const typename C3T3::Subdomain_index sd_index, @@ -54,22 +65,26 @@ void facets_in_complex_3_to_triangle_soup(const C3T3& c3t3, typedef typename C3T3::Triangulation Tr; typedef typename C3T3::Surface_patch_index Surface_patch_index; - typedef typename Tr::Vertex_handle Vertex_handle; typedef typename Tr::Cell_handle Cell_handle; typedef typename Tr::Weighted_point Weighted_point; typedef typename Tr::Facet Facet; - typedef CGAL::Hash_handles_with_or_without_timestamps Hash_fct; - typedef boost::unordered_map VHmap; + typedef typename C3T3::Facets_in_complex_iterator Ficit; + + typedef std::unordered_map PIM; typedef typename C3T3::size_type size_type; + // triangulation point to range point + CGAL::Cartesian_converter::type, + typename CGAL::Kernel_traits::type> t2r; + size_type nf = c3t3.number_of_facets_in_complex(); faces.reserve(faces.size() + nf); patches.reserve(faces.size() + nf); points.reserve(points.size() + nf/2); // approximating Euler - VHmap vh_to_ids; + PIM p_to_ids; std::size_t inum = 0; for(Facet fit : c3t3.facets_in_complex()) @@ -78,7 +93,7 @@ void facets_in_complex_3_to_triangle_soup(const C3T3& c3t3, int s = fit.second; const Surface_patch_index spi = c->surface_patch_index(s); Face f; - CGAL::internal::resize(f, 3); + resize(f, 3); typename C3T3::Subdomain_index cell_sdi = c3t3.subdomain_index(c); typename C3T3::Subdomain_index opp_sdi = c3t3.subdomain_index(c->neighbor(s)); @@ -88,23 +103,21 @@ void facets_in_complex_3_to_triangle_soup(const C3T3& c3t3, for(std::size_t i=1; i<4; ++i) { - typename VHmap::iterator map_entry; - bool is_new; - Vertex_handle v = c->vertex((s+i)&3); + CGAL_assertion_code(typedef typename Tr::Vertex_handle Vertex_handle;) + CGAL_assertion_code(Vertex_handle v = c->vertex((s+i)&3);) CGAL_assertion(v != Vertex_handle() && !c3t3.triangulation().is_infinite(v)); - boost::tie(map_entry, is_new) = vh_to_ids.insert(std::make_pair(v, inum)); - if(is_new) + const Weighted_point& wp = c3t3.triangulation().point(c, (s+i)&3); + const Point_3& bp = t2r(c3t3.triangulation().geom_traits().construct_point_3_object()(wp)); + + auto insertion_res = p_to_ids.emplace(bp, inum); + if(insertion_res.second) // new point { - const Weighted_point& p = c3t3.triangulation().point(c, (s+i)&3); - const Point_3 bp = Point_3(CGAL::to_double(p.x()), - CGAL::to_double(p.y()), - CGAL::to_double(p.z())); points.push_back(bp); ++inum; } - f[i-1] = map_entry->second; + f[i-1] = insertion_res.first->second; } if(export_all_facets) @@ -163,21 +176,24 @@ void set_face_patches(const Index2FaceMap& i2f, /** * @ingroup PkgSMDS3Functions * - * @brief builds a `TriangleMesh` from the surface facets, with a consistent orientation at the interface of two subdomains. + * @brief builds a `TriangleMesh` from the surface facets, with a consistent orientation + * at the interface of two subdomains. * - * This function exports the surface as a `TriangleMesh` and appends it to `tm`, using `orient_polygon_soup()`. + * This function exports the surface as a `TriangleMesh` and appends it to `graph`, using + * `orient_polygon_soup()`. * * @tparam C3T3 a model of `MeshComplexWithFeatures_3InTriangulation_3`. - * @tparam TriangleMesh a model of `MutableFaceGraph` with an internal point property map. The point type must be compatible with the one used in `C3T3`. + * @tparam TriangleMesh a model of `MutableFaceGraph` with an internal point property map. + * The point type must be compatible with the one used in `C3T3`. * @tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" * * @param c3t3 an instance of `C3T3` - * @param tm an instance of `TriangleMesh` + * @param graph an instance of `TriangleMesh` * @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below * * \cgalNamedParamsBegin * \cgalParamNBegin{face_patch_map} - * \cgalParamDescription{a property map with the patch id's associated to the faces of `faces(tm)`} + * \cgalParamDescription{a property map with the patch id's associated to the faces of `faces(graph)`} * \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits::%face_descriptor` * as key type and the desired property, model of `CopyConstructible` and `LessThanComparable` as value type.} * \cgalParamDefault{If not provided, faces patch ids are ignored.} @@ -187,7 +203,7 @@ void set_face_patches(const Index2FaceMap& i2f, */ template void facets_in_complex_3_to_triangle_mesh(const C3T3& c3t3, - TriangleMesh& tm, + TriangleMesh& graph, const NamedParameters& np) { namespace PMP = CGAL::Polygon_mesh_processing; @@ -209,13 +225,11 @@ void set_face_patches(const Index2FaceMap& i2f, PMP::orient_polygon_soup(points, faces); CGAL_postcondition(PMP::is_polygon_soup_a_polygon_mesh(faces)); - boost::unordered_map i2f; - PMP::polygon_soup_to_polygon_mesh(points, faces, tm, + std::unordered_map i2f; + PMP::polygon_soup_to_polygon_mesh(points, faces, graph, CGAL::parameters::polygon_to_face_output_iterator(std::inserter(i2f, i2f.end()))); - using parameters::choose_parameter; using parameters::get_parameter; - SMDS_3::internal::set_face_patches(i2f, patches, get_parameter(np, internal_np::face_patch)); diff --git a/SMDS_3/test/SMDS_3/test_c3t3.cpp b/SMDS_3/test/SMDS_3/test_c3t3.cpp index eb855052f68..78835c78fda 100644 --- a/SMDS_3/test/SMDS_3/test_c3t3.cpp +++ b/SMDS_3/test/SMDS_3/test_c3t3.cpp @@ -250,7 +250,7 @@ struct Tester //------------------------------------------------------- std::cout << "Insert 6 points from domain in c3t3_bis, add 1 cell to c3t3_bis\n"; Polyhedron polyhedron; - std::ifstream input("data/sphere.off"); + std::ifstream input(CGAL::data_file_path("meshes/sphere.off")); input >> polyhedron; input.close(); Mesh_domain domain(polyhedron); diff --git a/SMDS_3/test/SMDS_3/test_c3t3_into_facegraph.cpp b/SMDS_3/test/SMDS_3/test_c3t3_into_facegraph.cpp index b194de2d093..b31fbe22f0a 100644 --- a/SMDS_3/test/SMDS_3/test_c3t3_into_facegraph.cpp +++ b/SMDS_3/test/SMDS_3/test_c3t3_into_facegraph.cpp @@ -33,10 +33,10 @@ int main (int argc, char** argv){ Cell_base_with_info>::type Tr; typedef CGAL::Mesh_complex_3_in_triangulation_3 C3t3; - + typedef C3t3::Triangulation::Cell_handle Cell_handle; // Open file - std::ifstream in (argc > 1 ? argv[1] : "data/elephant.mesh", + std::ifstream in (argc > 1 ? argv[1] : CGAL::data_file_path("meshes/elephant.mesh"), std::ios_base::in); if(!in) { std::cerr << "Error! Cannot open file " << argv[1] << std::endl; @@ -45,13 +45,11 @@ int main (int argc, char** argv){ C3t3 c3t3; if(CGAL::SMDS_3::build_triangulation_from_file(in, c3t3.triangulation())) { - for( C3t3::Triangulation::Finite_cells_iterator - cit = c3t3.triangulation().finite_cells_begin(); - cit != c3t3.triangulation().finite_cells_end(); - ++cit) + for( Cell_handle cit : c3t3.triangulation().finite_cell_handles()) { assert(cit->subdomain_index() >= 0); - c3t3.add_to_complex(cit, cit->subdomain_index()); + if(cit->subdomain_index() > 0) + c3t3.add_to_complex(cit, cit->subdomain_index()); for(int i=0; i < 4; ++i) { if(cit->surface_patch_index(i)>0) @@ -64,10 +62,7 @@ int main (int argc, char** argv){ //if there is no facet in the complex, we add the border facets. if(c3t3.number_of_facets_in_complex() == 0) { - for( C3t3::Triangulation::All_cells_iterator - cit = c3t3.triangulation().all_cells_begin(); - cit != c3t3.triangulation().all_cells_end(); - ++cit) + for( Cell_handle cit : c3t3.triangulation().all_cell_handles()) { if(c3t3.triangulation().is_infinite(cit)) { diff --git a/SMDS_3/test/SMDS_3/test_c3t3_io.cpp b/SMDS_3/test/SMDS_3/test_c3t3_io.cpp index ef8d9e16d7a..ed44dd9016f 100644 --- a/SMDS_3/test/SMDS_3/test_c3t3_io.cpp +++ b/SMDS_3/test/SMDS_3/test_c3t3_io.cpp @@ -462,13 +462,13 @@ struct Test_c3t3_io { int main() { std::cout << "First test I/O when all indices are integers" << std::endl; - bool ok = Test_c3t3_io()("data/c3t3_io-homo"); + bool ok = Test_c3t3_io()("c3t3_io-homo"); if(!ok) { std::cerr << "Error\n"; return -1; } std::cout << "Then test I/O when all indices are different types" << std::endl; - ok = Test_c3t3_io()("data/c3t3_io-hetero"); + ok = Test_c3t3_io()("c3t3_io-hetero"); if(!ok) { std::cerr << "Error\n"; return -1;