From ef4df5f47d246f0d7d1d7a6a924f11cee3406bf6 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 16 Jan 2015 16:12:30 +0100 Subject: [PATCH] add constructor for Polygon_mesh_slicer_3 taking a pre-built AABB_tree of edges AABB_tree is made a template parameter of Polygon_mesh_slicer_3 also add a test for compilation of this new constructor --- .../include/CGAL/Polygon_mesh_slicer_3.h | 49 +++++++++++++------ .../Polygon_mesh_processing/CMakeLists.txt | 1 + .../polygon_mesh_slicer_test.cpp | 35 +++++++++++++ 3 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 Polygon_mesh_processing/test/Polygon_mesh_processing/polygon_mesh_slicer_test.cpp diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_slicer_3.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_slicer_3.h index 7cfc47e452b..adaed983742 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_slicer_3.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_slicer_3.h @@ -49,18 +49,14 @@ namespace CGAL { /// /// Depends on \ref PkgAABB_treeSummary /// \todo `PolygonMesh` should be a model of `FaceListGraph` -/// \todo Add a constructor from an AABB-tree (the type is hardcoded given `PolygonMesh`) -template +template > > > class Polygon_mesh_slicer_3 { private: - typedef AABB_halfedge_graph_segment_primitive AABB_primitive; - typedef AABB_traits AABB_traits_; - typedef AABB_tree AABB_tree_; - - typedef typename AABB_tree_::Object_and_primitive_id Object_and_primitive_id; - typedef typename AABB_tree_::Primitive_id Primitive_id; - typedef typename Kernel::Plane_3 Plane; typedef typename Kernel::Segment_3 Segment; typedef typename Kernel::Point_3 Point; @@ -132,7 +128,7 @@ private: // member variables // typename Kernel::Intersect_3 intersect_3_functor; - AABB_tree_ tree; + const AABB_tree_* tree_ptr; mutable Node_graph node_graph; PolygonMesh& m_pmesh; @@ -244,9 +240,9 @@ private: { node_graph.clear(); - // find out intersecting halfedges (note that tree contains edges only with custom comparator) + // find out intersecting halfedges (note that tree_ptr contains edges only with custom comparator) std::vector intersected_edges; - tree.all_intersected_primitives(plane, std::back_inserter(intersected_edges)); + tree_ptr->all_intersected_primitives(plane, std::back_inserter(intersected_edges)); // create node graph from segments // each node is associated with multiple edges @@ -425,12 +421,28 @@ public: * @param pmesh the polygon mesh to be cut * @param kernel the kernel */ - Polygon_mesh_slicer_3(const PolygonMesh& pmesh, const Kernel& kernel = Kernel()) + Polygon_mesh_slicer_3(const PolygonMesh& pmesh, + const Kernel& kernel = Kernel()) : intersect_3_functor(kernel.intersect_3_object()), - tree( edges(pmesh).first, - edges(pmesh).second, - pmesh), m_pmesh(const_cast(pmesh)) + { + tree_ptr = new AABB_tree_(edges(pmesh).first, + edges(pmesh).second, + pmesh); + } + + /** + * Constructor. `pmesh` must be a valid polygon mesh as long as this functor is used. + * @param pmesh the polygon mesh to be cut + * @param tree a `CGAL::AABB_tree` containing the edges of `pmesh` + * @param kernel the kernel + */ + Polygon_mesh_slicer_3(const PolygonMesh& pmesh, + const AABB_tree_& tree, + const Kernel& kernel = Kernel()) + : intersect_3_functor(kernel.intersect_3_object()), + tree_ptr(&tree), + m_pmesh(const_cast(pmesh)) { } /** @@ -445,6 +457,11 @@ public: CGAL_precondition(!plane.is_degenerate()); return intersect_plane(plane, out); } + + ~Polygon_mesh_slicer_3() + { + delete tree_ptr; + } }; }// end of namespace CGAL diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt b/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt index 3cd6604d1eb..926bb1af806 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt @@ -66,6 +66,7 @@ create_single_source_cgal_program( "test_polyhedron_stitching.cpp" ) create_single_source_cgal_program( "orient_polygon_soup_test.cpp" ) create_single_source_cgal_program( "orient_polyhedron_3_test.cpp" ) create_single_source_cgal_program( "point_inside_polyhedron_boundary_test.cpp" ) +create_single_source_cgal_program( "polygon_mesh_slicer_test.cpp" ) create_single_source_cgal_program( "self_intersection_polyhedron_test.cpp" ) create_single_source_cgal_program( "self_intersection_surface_mesh_test.cpp" ) create_single_source_cgal_program( "triangulate_hole_Polyhedron_3_test.cpp" ) diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/polygon_mesh_slicer_test.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/polygon_mesh_slicer_test.cpp new file mode 100644 index 00000000000..0e0e514bbd5 --- /dev/null +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/polygon_mesh_slicer_test.cpp @@ -0,0 +1,35 @@ + +#include +#include +#include +#include + +#include +#include +#include + +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Surface_mesh Mesh; + +typedef CGAL::AABB_halfedge_graph_segment_primitive HGSP; +typedef CGAL::AABB_traits AABB_traits; +typedef CGAL::AABB_tree AABB_tree; + +int main(int, char** argv) +{ + std::ifstream input("data/U.off"); + Mesh m; + + if (!input || !(input >> m)){ + std::cerr << "Error: can not read file."; + return 1; + } + + AABB_tree tree(edges(m).first, edges(m).second, m); + + CGAL::Polygon_mesh_slicer_3 slicer(m, tree); + + return 0; +}