From 232373c9ca3a672dac2ae68d8c76515e277c134c Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 4 Oct 2018 12:31:34 +0200 Subject: [PATCH] Change the Id of the AABB_face_graph_triangle_primitive so it contains the mesh if necessary. --- .../CGAL/AABB_face_graph_triangle_primitive.h | 72 +++++++++++++++---- .../test/AABB_tree/aabb_test_multi_mesh.cpp | 67 +++++++++++++++++ 2 files changed, 126 insertions(+), 13 deletions(-) create mode 100644 AABB_tree/test/AABB_tree/aabb_test_multi_mesh.cpp diff --git a/AABB_tree/include/CGAL/AABB_face_graph_triangle_primitive.h b/AABB_tree/include/CGAL/AABB_face_graph_triangle_primitive.h index 83e01c72d6c..ca50f5898ec 100644 --- a/AABB_tree/include/CGAL/AABB_face_graph_triangle_primitive.h +++ b/AABB_tree/include/CGAL/AABB_face_graph_triangle_primitive.h @@ -32,7 +32,36 @@ #include namespace CGAL { +namespace internal{ +//helper struct for creating the right Id: just a face_descriptor if OneFaceGraphPerTree +// is true,else : a pair with the corresponding graph. +template +struct Primitive_id; +template +struct Primitive_id +{ + typedef typename boost::graph_traits::face_descriptor Id_; + template + static Id_ from_iterator(Iterator it, const FaceGraph&) + { + return Id_(*it); + } +}; + +template +struct Primitive_id +{ + typedef std::pair::face_descriptor, + FaceGraph> Id_; + template + static Id_ from_iterator(Iterator it, const FaceGraph& f) + { + return std::make_pair(*it, f); + } +}; +} /*! * \ingroup PkgAABB_tree * Primitive type for a facet of a polyhedral surface. @@ -81,7 +110,6 @@ class AABB_face_graph_triangle_primitive #endif { typedef typename Default::Get::type >::type VertexPointPMap_; - typedef typename boost::graph_traits::face_descriptor Id_; typedef Triangle_from_face_descriptor_map Triangle_property_map; typedef One_point_from_face_descriptor_map Point_property_map; @@ -91,7 +119,10 @@ class AABB_face_graph_triangle_primitive Point_property_map, OneFaceGraphPerTree, CacheDatum > Base; - +public: + typedef typename internal::Primitive_id::Id_ Id; +protected: + Id this_id; public: #ifdef DOXYGEN_RUNNING /// \name Types @@ -105,19 +136,24 @@ public: */ typedef Kernel_traits::Kernel::Triangle_3 Datum; /*! - Id type. + Id type: + - boost::graph_traits::face_descriptor Id if OneFaceGraphPerTree is `CGAL::Tag_true + - std::pair::face_descriptor, FaceGraph> Id if OneFaceGraphPerTree is `CGAL::Tag_false` */ - typedef boost::graph_traits::face_descriptor Id; + Unspecified_type Id; + /*! + Id type of the Base: + */ + typedef typename boost::graph_traits::face_descriptor Id_; + /// @} /*! If `OneFaceGraphPerTree` is CGAL::Tag_true, constructs a `Shared_data` object from a reference to the polyhedon `graph`. */ static unspecified_type construct_shared_data( FaceGraph& graph ); - #else - typedef typename Base::Id Id; #endif - + Id id() const {return this_id;} // constructors /*! \tparam Iterator an input iterator with `Id` as value type. @@ -127,21 +163,27 @@ public: */ template AABB_face_graph_triangle_primitive(Iterator it, const FaceGraph& graph, VertexPointPMap_ vppm) - : Base( Id_(*it), + : Base( it, Triangle_property_map(const_cast(&graph),vppm), Point_property_map(const_cast(&graph),vppm) ) - {} + { + this_id = + internal::Primitive_id::from_iterator(it, graph); + } /*! Constructs a primitive. If `VertexPointPMap` is the default of the class, an additional constructor is available with `vppm` set to `get(vertex_point, graph)`. */ - AABB_face_graph_triangle_primitive(Id id, const FaceGraph& graph, VertexPointPMap_ vppm) + AABB_face_graph_triangle_primitive(Id_ id, const FaceGraph& graph, VertexPointPMap_ vppm) : Base( Id_(id), Triangle_property_map(const_cast(&graph),vppm), Point_property_map(const_cast(&graph),vppm) ) - {} + { + this_id = + internal::Primitive_id::from_iterator(id, graph); + } #ifndef DOXYGEN_RUNNING template @@ -149,13 +191,17 @@ public: : Base( Id_(*it), Triangle_property_map(const_cast(&graph)), Point_property_map(const_cast(&graph)) ) - {} + { + this_id = + internal::Primitive_id::from_iterator(it, graph);} AABB_face_graph_triangle_primitive(Id id, const FaceGraph& graph) : Base( Id_(id), Triangle_property_map(const_cast(&graph)), Point_property_map(const_cast(&graph)) ) - {} + { + this_id = + internal::Primitive_id::from_iterator(id, graph);} #endif /// \internal diff --git a/AABB_tree/test/AABB_tree/aabb_test_multi_mesh.cpp b/AABB_tree/test/AABB_tree/aabb_test_multi_mesh.cpp new file mode 100644 index 00000000000..a7274011158 --- /dev/null +++ b/AABB_tree/test/AABB_tree/aabb_test_multi_mesh.cpp @@ -0,0 +1,67 @@ +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +typedef CGAL::Epick K; +typedef K::FT FT; +typedef K::Point_3 Point; +typedef K::Vector_3 Vector; +typedef K::Segment_3 Segment; +typedef K::Ray_3 Ray; +typedef CGAL::Surface_mesh > Mesh; +typedef CGAL::AABB_face_graph_triangle_primitive Primitive; +typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_tree Tree; +typedef Tree::Primitive_id Primitive_id; +typedef CGAL::Timer Timer; + +int main() +{ + CGAL::Surface_mesh > m1, m2; + std::ifstream in("data/cube.off"); + if(in) + in >> m1; + else{ + std::cout << "error reading cube" << std::endl; + return 1; + } + in.close(); + in.open("data/tetrahedron.off"); + if(in) + in >> m2; + else{ + std::cout << "error reading tetrahedron" << std::endl; + return 1; + } + in.close(); + Tree tree(faces(m1).first, faces(m1).second, m1); + tree.insert(faces(m2).first, faces(m2).second, m2); + //tree.insert(faces(m1).first, faces(m1).second, m1); + tree.build(); + Tree::Bounding_box bbox = tree.bbox(); + Point bbox_center((bbox.xmin() + bbox.xmax()) / 2, + (bbox.ymin() + bbox.ymax()) / 2, + (bbox.zmin() + bbox.zmax()) / 2); + std::vector< Primitive_id > intersections; + Ray ray(bbox_center+Vector(3,-0.25,0),bbox_center+Vector(-3,+0.25,0)); + tree.all_intersected_primitives(ray, + std::back_inserter(intersections)); + + return 0; +}