diff --git a/AABB_tree/demo/AABB_tree/Scene.cpp b/AABB_tree/demo/AABB_tree/Scene.cpp index cd44d369355..2e3a9c7801f 100644 --- a/AABB_tree/demo/AABB_tree/Scene.cpp +++ b/AABB_tree/demo/AABB_tree/Scene.cpp @@ -401,7 +401,7 @@ void Scene::build_facet_tree() CGAL::Timer timer; timer.start(); std::cout << "Construct Facet AABB tree..."; - m_facet_tree.rebuild(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + m_facet_tree.rebuild(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end(),*m_pPolyhedron); m_facet_tree.accelerate_distance_queries(); std::cout << "done (" << timer.time() << " s)" << std::endl; } @@ -421,7 +421,7 @@ void Scene::build_edge_tree() CGAL::Timer timer; timer.start(); std::cout << "Construct Edge AABB tree..."; - m_edge_tree.rebuild(m_pPolyhedron->edges_begin(),m_pPolyhedron->edges_end()); + m_edge_tree.rebuild(boost::edges(*m_pPolyhedron).first,boost::edges(*m_pPolyhedron).second,*m_pPolyhedron); m_edge_tree.accelerate_distance_queries(); std::cout << "done (" << timer.time() << " s)" << std::endl; } diff --git a/AABB_tree/demo/AABB_tree/benchmarks.cpp b/AABB_tree/demo/AABB_tree/benchmarks.cpp index 9dc53b58948..5bcfc18f105 100644 --- a/AABB_tree/demo/AABB_tree/benchmarks.cpp +++ b/AABB_tree/demo/AABB_tree/benchmarks.cpp @@ -16,7 +16,7 @@ void Scene::benchmark_intersections(const double duration) std::cout << "Construct AABB tree..."; CGAL::Timer timer; timer.start(); - Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end(),*m_pPolyhedron); std::cout << "done (" << timer.time() << " s)" << std::endl; // generates random queries @@ -76,7 +76,7 @@ void Scene::benchmark_distances(const double duration) CGAL::Timer timer; timer.start(); std::cout << "Construct AABB tree and internal KD tree..."; - Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end(),*m_pPolyhedron); tree.accelerate_distance_queries(); std::cout << "done (" << timer.time() << " s)" << std::endl; @@ -122,7 +122,7 @@ void Scene::bench_memory() // constructs tree and measure memory before then after typedef CGAL::Memory_sizer::size_type size_type; size_type before = CGAL::Memory_sizer().virtual_size(); - Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end(),*m_pPolyhedron); // tree.accelerate_distance_queries(); // 150 vs 61 bytes per primitive! size_type after = CGAL::Memory_sizer().virtual_size(); @@ -159,12 +159,12 @@ void Scene::bench_construction() // constructs tree CGAL::Timer time1; time1.start(); - Facet_tree tree1(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + Facet_tree tree1(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end(),*m_pPolyhedron); double duration_construction_alone = time1.time(); CGAL::Timer time2; time2.start(); - Facet_tree tree2(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + Facet_tree tree2(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end(),*m_pPolyhedron); tree2.accelerate_distance_queries(); double duration_construction_and_kdtree = time2.time(); @@ -203,7 +203,7 @@ void Scene::bench_intersections_vs_nbt() refiner.run_nb_splits(nb_splits); // constructs tree (out of timing) - Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end(),*m_pPolyhedron); // calls ray queries CGAL::Timer timer; @@ -247,7 +247,7 @@ void Scene::bench_distances_vs_nbt() refiner.run_nb_splits(nb_splits); // constructs tree (out of timing) - Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end(),*m_pPolyhedron); tree.accelerate_distance_queries(); // calls queries diff --git a/AABB_tree/examples/AABB_tree/AABB_insertion_example.cpp b/AABB_tree/examples/AABB_tree/AABB_insertion_example.cpp index 8f9a6b26401..68e91a53c9b 100644 --- a/AABB_tree/examples/AABB_tree/AABB_insertion_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_insertion_example.cpp @@ -12,7 +12,7 @@ typedef K::FT FT; typedef K::Point_3 Point; typedef K::Segment_3 Segment; typedef CGAL::Polyhedron_3 Polyhedron; -typedef CGAL::AABB_face_graph_triangle_primitive Primitive; +typedef CGAL::AABB_face_graph_triangle_primitive Primitive; typedef CGAL::AABB_traits Traits; typedef CGAL::AABB_tree Tree; typedef Tree::Point_and_primitive_id Point_and_primitive_id; @@ -33,13 +33,13 @@ int main() Point s2(10.0, 0.0, 0.0); Polyhedron polyhedron2; polyhedron2.make_tetrahedron(p2, q2, r2, s2); - // constructs AABB tree and computes internal KD-tree + // constructs AABB tree and computes internal KD-tree // data structure to accelerate distance queries - Tree tree(polyhedron1.facets_begin(),polyhedron1.facets_end()); + Tree tree(polyhedron1.facets_begin(),polyhedron1.facets_end(), polyhedron1); tree.accelerate_distance_queries(); - tree.insert(polyhedron2.facets_begin(),polyhedron2.facets_end()); + tree.insert(polyhedron2.facets_begin(),polyhedron2.facets_end(), polyhedron2); // query point Point query(0.0, 0.0, 3.0); diff --git a/AABB_tree/examples/AABB_tree/AABB_polyhedron_edge_example.cpp b/AABB_tree/examples/AABB_tree/AABB_polyhedron_edge_example.cpp index 5391a0f854d..1b3c1be3f32 100644 --- a/AABB_tree/examples/AABB_tree/AABB_polyhedron_edge_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_polyhedron_edge_example.cpp @@ -7,7 +7,8 @@ #include #include #include - +#include +#include typedef CGAL::Simple_cartesian K; typedef K::FT FT; @@ -29,7 +30,9 @@ int main() // constructs the AABB tree and the internal search tree for // efficient distance queries. - Tree tree(polyhedron.edges_begin(),polyhedron.edges_end()); + Tree tree( CGAL::undirected_edges(polyhedron).first, + CGAL::undirected_edges(polyhedron).second, + polyhedron); tree.accelerate_distance_queries(); // counts #intersections with a triangle query diff --git a/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_distance_example.cpp b/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_distance_example.cpp index e2a0c9a61b5..cfdea47dc84 100644 --- a/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_distance_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_distance_example.cpp @@ -30,7 +30,7 @@ int main() // constructs AABB tree and computes internal KD-tree // data structure to accelerate distance queries - Tree tree(polyhedron.facets_begin(),polyhedron.facets_end()); + Tree tree(polyhedron.facets_begin(),polyhedron.facets_end(),polyhedron); tree.accelerate_distance_queries(); // query point diff --git a/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_intersection_example.cpp b/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_intersection_example.cpp index f2fb6da0957..60935e6d88f 100644 --- a/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_intersection_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_intersection_example.cpp @@ -31,7 +31,7 @@ int main() polyhedron.make_tetrahedron(p, q, r, s); // constructs AABB tree - Tree tree(polyhedron.facets_begin(),polyhedron.facets_end()); + Tree tree(polyhedron.facets_begin(),polyhedron.facets_end(),polyhedron); // constructs segment query Point a(-0.2, 0.2, -0.2); 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 fc937d9b0f8..3cb48837ec2 100644 --- a/AABB_tree/include/CGAL/AABB_face_graph_triangle_primitive.h +++ b/AABB_tree/include/CGAL/AABB_face_graph_triangle_primitive.h @@ -41,7 +41,11 @@ namespace CGAL { *\tparam FaceGraph is a \cgal polyhedron. *\tparam VertexPointPMap must be set to `CGAL::Default` * This parameter is useless for the moment and will be useful in an upcoming release of \cgal. - *\tparam OneFaceGraphPerTree must be set to `CGAL::Default` + *\tparam OneFaceGraphPerTree is either `CGAL::Tag_true or `CGAL::Tag_false`. + * In the former case, we guarantee that all the primitives will be from a + * common polyhedron and some data will be factorized so that the size of + * the primitive is reduced. In the latter case, the primitives can be from + * different polyhedra and extra storage is required in the primitives. The default is `CGAL::Tag_true`. * This parameter is useless for the moment and will be useful in an upcoming release of \cgal. *\tparam CacheDatum is either `CGAL::Tag_true` or `CGAL::Tag_false`. In the former case, the datum is stored * in the primitive, while in the latter it is constructed on the fly to reduce the memory footprint. @@ -52,7 +56,7 @@ namespace CGAL { */ template < class FaceGraph, class VertexPointPMap = Default, - class OneFaceGraphPerTree = Default, + class OneFaceGraphPerTree = Tag_true, class CacheDatum=Tag_false > class AABB_face_graph_triangle_primitive #ifndef DOXYGEN_RUNNING @@ -63,7 +67,7 @@ class AABB_face_graph_triangle_primitive >::type, Triangle_from_facet_handle_property_map, One_point_from_facet_handle_property_map, - Tag_true, + OneFaceGraphPerTree, CacheDatum > #endif { @@ -77,7 +81,7 @@ class AABB_face_graph_triangle_primitive typedef AABB_primitive< Id_, Triangle_property_map, Point_property_map, - Tag_true, + OneFaceGraphPerTree, CacheDatum > Base; public: @@ -97,6 +101,11 @@ public: */ typedef 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 ); #endif // constructors @@ -110,22 +119,14 @@ public: Triangle_property_map(&graph), Point_property_map(&graph) ){} - /// For backward-compatibility with AABB_polyhedron_triangle_primitive only. - /// `Id_` is `Facet_const_handle` if `FaceGraph` is const and `Facet_handle` otherwise. - AABB_face_graph_triangle_primitive(Id_ id) - : Base( id, - Triangle_property_map(NULL), - Point_property_map(NULL) ){} - - static typename Base::Shared_data construct_shared_data( FaceGraph& graph ) + /// \internal + typedef internal::Cstr_shared_data Cstr_shared_data; + /// \internal + static + typename Cstr_shared_data::Shared_data + construct_shared_data(FaceGraph& graph) { - return Base::construct_shared_data(Triangle_property_map(&graph), Point_property_map(&graph)); - } - - /// For backward-compatibility with AABB_polyhedron_triangle_primitive only - static typename Base::Shared_data construct_shared_data() - { - return Base::construct_shared_data(Triangle_property_map(NULL), Point_property_map(NULL)); + return Cstr_shared_data::construct_shared_data(graph); } }; diff --git a/AABB_tree/include/CGAL/AABB_halfedge_graph_segment_primitive.h b/AABB_tree/include/CGAL/AABB_halfedge_graph_segment_primitive.h index 9373a04fb9b..2e383e42aaf 100644 --- a/AABB_tree/include/CGAL/AABB_halfedge_graph_segment_primitive.h +++ b/AABB_tree/include/CGAL/AABB_halfedge_graph_segment_primitive.h @@ -31,7 +31,6 @@ #include #include #include -#include namespace CGAL { @@ -84,7 +83,7 @@ class AABB_halfedge_graph_segment_primitive typedef AABB_primitive< Id_, Segment_property_map, Point_property_map, - Tag_true, + OneHalfedgeGraphPerTree, CacheDatum > Base; public: @@ -105,6 +104,11 @@ public: */ typedef boost::graph_traits::edge_descriptor Id; /// @} + + /*! + If `OneHalfedgeGraphPerTreeGraphPerTree` is CGAL::Tag_true, constructs a `Shared_data` object from a reference to the halfedge graph. + */ + static unspecified_type construct_shared_data( HalfedgeGraph& graph ); #endif /*! @@ -130,21 +134,14 @@ public: Point_property_map(&graph) ){} #endif - /// For backward-compatibility with AABB_polyhedron_segment_primitive only - AABB_halfedge_graph_segment_primitive(Id_ id) - : Base( id, - Segment_property_map(NULL), - Point_property_map(NULL) ){} - - static typename Base::Shared_data construct_shared_data( HalfedgeGraph& graph ) + /// \internal + typedef internal::Cstr_shared_data Cstr_shared_data; + /// \internal + static + typename Cstr_shared_data::Shared_data + construct_shared_data(HalfedgeGraph& graph) { - return Base::construct_shared_data(Segment_property_map(&graph), Point_property_map(&graph)); - } - - ///For backward-compatibility with AABB_polyhedron_segment_primitive only - static typename Base::Shared_data construct_shared_data() - { - return Base::construct_shared_data(Segment_property_map(NULL), Point_property_map(NULL)); + return Cstr_shared_data::construct_shared_data(graph); } }; diff --git a/AABB_tree/include/CGAL/AABB_primitive.h b/AABB_tree/include/CGAL/AABB_primitive.h index 3dbedd155a4..61dae693a30 100644 --- a/AABB_tree/include/CGAL/AABB_primitive.h +++ b/AABB_tree/include/CGAL/AABB_primitive.h @@ -22,6 +22,7 @@ #ifndef CGAL_AABB_PRIMITIVE_H #define CGAL_AABB_PRIMITIVE_H +#include #include #include diff --git a/AABB_tree/include/CGAL/internal/AABB_tree/Has_nested_type_Shared_data.h b/AABB_tree/include/CGAL/internal/AABB_tree/Has_nested_type_Shared_data.h index 7005cb1b157..c8312750cd7 100644 --- a/AABB_tree/include/CGAL/internal/AABB_tree/Has_nested_type_Shared_data.h +++ b/AABB_tree/include/CGAL/internal/AABB_tree/Has_nested_type_Shared_data.h @@ -12,8 +12,8 @@ // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // -// $URL: svn+ssh://sloriot@scm.gforge.inria.fr/svn/cgal/branches/features/AABB_tree-one_primitive_per_object-sloriot/AABB_tree/include/CGAL/AABB_triangle_primitive.h $ -// $Id: AABB_triangle_primitive.h 69127 2012-05-14 16:10:00Z sloriot $ +// $URL$ +// $Id$ // // // Author(s) : Sebastien Loriot @@ -33,7 +33,32 @@ namespace CGAL{ namespace internal{ BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_nested_type_Shared_data,Shared_data,false) - + +// Utility class used by AABB_face_graph_triangle_primitive and AABB_halfedge_graph_segment_primitive +// to implement the Consruct_shared_data static function. +template +struct Cstr_shared_data; + +template +struct Cstr_shared_data +{ + typedef typename Base::Shared_data Shared_data; + static Shared_data construct_shared_data(Graph& graph) + { + return Base::construct_shared_data(ObjectPropertyMap(&graph), PointPropertyMap(&graph)); + } +}; + +template +struct Cstr_shared_data +{ + typedef void* Shared_data; + static Shared_data construct_shared_data(Graph&) + { + return NULL; + } +}; + } } //namespace CGAL #endif //CGAL_INTERNAL_AABB_TREE_HAS_NESTED_TYPE_SHARED_DATA_H diff --git a/AABB_tree/test/AABB_tree/AABB_test_util.h b/AABB_tree/test/AABB_tree/AABB_test_util.h index c93d1de1bab..01b51e3963f 100644 --- a/AABB_tree/test/AABB_tree/AABB_test_util.h +++ b/AABB_tree/test/AABB_tree/AABB_test_util.h @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -216,9 +217,10 @@ struct Primitive_generator { typedef CGAL::AABB_halfedge_graph_segment_primitive Primitive; - typedef typename Polyhedron::Edge_iterator iterator; - iterator begin(Polyhedron& p) { return p.edges_begin(); } - iterator end(Polyhedron& p) { return p.edges_end(); } + typedef typename CGAL::halfedge_graph_traits + ::undirected_edge_iterator iterator; + iterator begin(Polyhedron& p) { return CGAL::undirected_edges(p).first; } + iterator end(Polyhedron& p) { return CGAL::undirected_edges(p).second; } }; template @@ -259,7 +261,7 @@ void test(const char *filename, // constructs AABB tree and internal search KD-tree with // the points of the polyhedron - Tree tree(Pr_generator().begin(polyhedron),Pr_generator().end(polyhedron)); + Tree tree(Pr_generator().begin(polyhedron),Pr_generator().end(polyhedron), polyhedron); //tree.accelerate_distance_queries(polyhedron.points_begin(),polyhedron.points_end()); // call all tests @@ -341,7 +343,7 @@ public: Polyhedron_primitive_iterator it = Pr_generator().begin(p); for ( ; it != Pr_generator().end(p) ; ++it ) { - if ( m_traits.do_intersect_object()(query, Pr(it) ) ) + if ( m_traits.do_intersect_object()(query, Pr(it,p) ) ) return true; } @@ -357,7 +359,7 @@ public: Polyhedron_primitive_iterator it = Pr_generator().begin(p); for ( ; it != Pr_generator().end(p) ; ++it ) { - if ( m_traits.do_intersect_object()(query, Pr(it) ) ) + if ( m_traits.do_intersect_object()(query, Pr(it,p) ) ) ++result; } @@ -372,8 +374,8 @@ public: Polyhedron_primitive_iterator it = Pr_generator().begin(p); for ( ; it != Pr_generator().end(p) ; ++it ) { - if ( m_traits.do_intersect_object()(query, Pr(it) ) ) - *out++ = Pr(it).id(); + if ( m_traits.do_intersect_object()(query, Pr(it,p) ) ) + *out++ = Pr(it,p).id(); } return out; @@ -389,10 +391,10 @@ public: { #if CGAL_INTERSECTION_VERSION < 2 Intersection_result - intersection = Traits().intersection_object()(query, Pr(it)); + intersection = Traits().intersection_object()(query, Pr(it,p)); #else boost::optional< typename Traits::template Intersection_and_primitive_id::Type > - intersection = m_traits.intersection_object()(query, Pr(it)); + intersection = m_traits.intersection_object()(query, Pr(it,p)); #endif if ( intersection ) *out++ = *intersection; @@ -409,11 +411,11 @@ public: assert ( it != Pr_generator().end(p) ); // Get a point on the primitive - Point closest_point = CGAL::internal::Primitive_helper::get_reference_point(Pr(it),m_traits); + Point closest_point = CGAL::internal::Primitive_helper::get_reference_point(Pr(it,p),m_traits); for ( ; it != Pr_generator().end(p) ; ++it ) { - closest_point = m_traits.closest_point_object()(query, Pr(it), closest_point); + closest_point = m_traits.closest_point_object()(query, Pr(it,p), closest_point); } return closest_point; @@ -427,12 +429,12 @@ public: assert ( it != Pr_generator().end(p) ); // Get a point on the primitive - Pr closest_primitive = Pr(it); + Pr closest_primitive = Pr(it,p); Point closest_point = CGAL::internal::Primitive_helper::get_reference_point(closest_primitive,m_traits); for ( ; it != Pr_generator().end(p) ; ++it ) { - Pr tmp_pr(it); + Pr tmp_pr(it,p); Point tmp_pt = m_traits.closest_point_object()(query, tmp_pr, closest_point); if ( tmp_pt != closest_point ) { diff --git a/AABB_tree/test/AABB_tree/aabb_correctness_triangle_test.cpp b/AABB_tree/test/AABB_tree/aabb_correctness_triangle_test.cpp index ecbc63b215f..8022c0777f9 100644 --- a/AABB_tree/test/AABB_tree/aabb_correctness_triangle_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_correctness_triangle_test.cpp @@ -59,7 +59,7 @@ int test() typedef typename CGAL::AABB_traits Traits; typedef typename CGAL::AABB_tree Tree; typedef typename Tree::Object_and_primitive_id Object_and_primitive_id; - Tree tree(polyhedron.facets_begin(),polyhedron.facets_end()); + Tree tree(polyhedron.facets_begin(),polyhedron.facets_end(), polyhedron); // segment intersection query Point p((FT)-0.25, (FT)0.251, (FT)0.255);