diff --git a/AABB_tree/doc/AABB_tree/PackageDescription.txt b/AABB_tree/doc/AABB_tree/PackageDescription.txt index 3e78bb5404b..961b8ae6c05 100644 --- a/AABB_tree/doc/AABB_tree/PackageDescription.txt +++ b/AABB_tree/doc/AABB_tree/PackageDescription.txt @@ -33,6 +33,7 @@ - `AABBRayIntersectionTraits` \cgalCRPSection{Classes} +- `CGAL::AABB_traits` (deprecated, use `CGAL::AABB_traits_3`) - `CGAL::AABB_traits_2` - `CGAL::AABB_traits_3` - `CGAL::AABB_tree` @@ -42,7 +43,9 @@ - `CGAL::AABB_indexed_triangle_primitive_2` - `CGAL::AABB_segment_primitive_2` - `CGAL::AABB_polyline_segment_primitive_2` +- `CGAL::AABB_triangle_primitive` (deprecated, use `CGAL::AABB_triangle_primitive_3`) - `CGAL::AABB_triangle_primitive_3` +- `CGAL::AABB_segment_primitive` (deprecated, use `CGAL::AABB_segment_primitive_3`) - `CGAL::AABB_segment_primitive_3` - `CGAL::AABB_primitive` - `CGAL::AABB_halfedge_graph_segment_primitive` diff --git a/AABB_tree/doc/AABB_tree/examples.txt b/AABB_tree/doc/AABB_tree/examples.txt index a98d2c35aaf..d986357796c 100644 --- a/AABB_tree/doc/AABB_tree/examples.txt +++ b/AABB_tree/doc/AABB_tree/examples.txt @@ -9,8 +9,10 @@ \example AABB_tree/AABB_polyhedron_facet_intersection_example.cpp \example AABB_tree/AABB_polyline_segment_2_example.cpp \example AABB_tree/AABB_segment_3_example.cpp +\example AABB_tree/AABB_segment_2_example.cpp \example AABB_tree/AABB_ray_shooting_example.cpp \example AABB_tree/AABB_indexed_triangle_2_example.cpp +\example AABB_tree/AABB_triangle_2_example.cpp \example AABB_tree/AABB_triangle_3_example.cpp \example AABB_tree/AABB_halfedge_graph_edge_example.cpp \example AABB_tree/AABB_face_graph_triangle_example.cpp diff --git a/AABB_tree/examples/AABB_tree/AABB_triangle_2_example.cpp b/AABB_tree/examples/AABB_tree/AABB_triangle_2_example.cpp new file mode 100644 index 00000000000..631990224e9 --- /dev/null +++ b/AABB_tree/examples/AABB_tree/AABB_triangle_2_example.cpp @@ -0,0 +1,52 @@ +// Author(s) : Camille Wormser, Pierre Alliez + +#include +#include + +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K; + +typedef K::FT FT; +typedef K::Ray_2 Ray; +typedef K::Point_2 Point; +typedef K::Triangle_2 Triangle; + +typedef std::list::iterator Iterator; +typedef CGAL::AABB_triangle_primitive_2 Primitive; +typedef CGAL::AABB_traits_2 AABB_triangle_traits; +typedef CGAL::AABB_tree Tree; + +int main() +{ + Point a(1.0, 0.0); + Point b(0.0, 1.0); + Point c(1.0, 1.0); + Point d(0.0, 0.0); + + std::list triangles; + triangles.push_back(Triangle(a,b,c)); + triangles.push_back(Triangle(a,b,d)); + triangles.push_back(Triangle(a,d,c)); + + // constructs AABB tree + Tree tree(triangles.begin(),triangles.end()); + + // counts #intersections + Ray ray_query(a,b); + std::cout << tree.number_of_intersected_primitives(ray_query) + << " intersections(s) with ray query" << std::endl; + + // compute closest point and squared distance + Point point_query(2.0, 2.0); + Point closest_point = tree.closest_point(point_query); + std::cerr << "closest point is: " << closest_point << std::endl; + + FT sqd = tree.squared_distance(point_query); + std::cout << "squared distance: " << sqd << std::endl; + + return EXIT_SUCCESS; +} diff --git a/AABB_tree/include/CGAL/AABB_traits_2.h b/AABB_tree/include/CGAL/AABB_traits_2.h index 6cc94837f83..673ead172fb 100644 --- a/AABB_tree/include/CGAL/AABB_traits_2.h +++ b/AABB_tree/include/CGAL/AABB_traits_2.h @@ -47,28 +47,24 @@ struct AABB_traits_intersection_base_2{}; template struct AABB_traits_intersection_base_2{ + template + friend class AABB_ray_intersection; private: typedef typename GeomTraits::FT FT; typedef typename GeomTraits::Point_2 Point; - -public: - typedef typename GeomTraits::Ray_2 Ray; - typedef typename GeomTraits::Vector_2 Vector; typedef typename GeomTraits::Cartesian_const_iterator_2 Cartesian_const_iterator; typedef typename GeomTraits::Construct_cartesian_const_iterator_2 Construct_cartesian_const_iterator; - typedef typename GeomTraits::Construct_source_2 Construct_source; - typedef typename GeomTraits::Construct_vector_2 Construct_vector; - - // Defining Bounding_box and other types from the full AABB_traits_2 - // here is might seem strange, but otherwise we would need to use - // CRTP to get access to the derived class, which would bloat the - // code more. - typedef typename CGAL::Bbox_2 Bounding_box; static Construct_cartesian_const_iterator construct_cartesian_const_iterator_object() { return GeomTraits().construct_cartesian_const_iterator_2_object(); } +public: + typedef typename GeomTraits::Ray_2 Ray; + typedef typename GeomTraits::Vector_2 Vector; + typedef typename GeomTraits::Construct_source_2 Construct_source; + typedef typename GeomTraits::Construct_vector_2 Construct_vector; + static Construct_source construct_source_object() { return GeomTraits().construct_source_2_object(); } @@ -77,6 +73,12 @@ public: return GeomTraits().construct_vector_2_object(); } + // Defining Bounding_box and other types from the full AABB_traits_2 + // here is might seem strange, but otherwise we would need to use + // CRTP to get access to the derived class, which would bloat the + // code more. + typedef typename CGAL::Bbox_2 Bounding_box; + struct Intersection_distance { std::optional operator()(const Ray& ray, const Bounding_box& bbox) const { FT t_near = -DBL_MAX; // std::numeric_limits::lowest(); C++1903 diff --git a/AABB_tree/include/CGAL/AABB_traits_3.h b/AABB_tree/include/CGAL/AABB_traits_3.h index 5bd128cce32..d7e0b0d17af 100644 --- a/AABB_tree/include/CGAL/AABB_traits_3.h +++ b/AABB_tree/include/CGAL/AABB_traits_3.h @@ -35,7 +35,9 @@ namespace CGAL { -namespace internal{ namespace AABB_tree { +namespace internal { + +namespace AABB_tree { // AABB_traits_intersection_base_3 brings in the Intersection_distance predicate, // if GeomTraits is a model RayIntersectionGeomTraits. @@ -46,7 +48,10 @@ template struct AABB_traits_intersection_base_3{}; template -struct AABB_traits_intersection_base_3{ +struct AABB_traits_intersection_base_3 { + template + friend class AABB_ray_intersection; + private: typedef typename GeomTraits::Point_3 Point; typedef typename GeomTraits::FT FT; @@ -57,18 +62,19 @@ private: // code more. typedef typename CGAL::Bbox_3 Bounding_box; -public: - typedef typename GeomTraits::Ray_3 Ray; - typedef typename GeomTraits::Vector_3 Vector; typedef typename GeomTraits::Cartesian_const_iterator_3 Cartesian_const_iterator; typedef typename GeomTraits::Construct_cartesian_const_iterator_3 Construct_cartesian_const_iterator; - typedef typename GeomTraits::Construct_source_3 Construct_source; - typedef typename GeomTraits::Construct_vector_3 Construct_vector; Construct_cartesian_const_iterator construct_cartesian_const_iterator_object() { return GeomTraits().construct_cartesian_const_iterator_3_object(); } +public: + typedef typename GeomTraits::Ray_3 Ray; + typedef typename GeomTraits::Vector_3 Vector; + typedef typename GeomTraits::Construct_source_3 Construct_source; + typedef typename GeomTraits::Construct_vector_3 Construct_vector; + Construct_source construct_source_object() { return GeomTraits().construct_source_3_object(); } @@ -198,7 +204,7 @@ public: /// Point type typedef typename GeomTraits::Point_3 Point; // because the AABB_tree is dimension agnostic - typedef typename GeomTraits::Point_3 Point_3; + typedef typename GeomTraits::Point_3 Point_3; // kept for backward compatibility /// additional types for the search tree, required by the RangeSearchTraits concept /// \bug This is not documented for now in the AABBTraits concept.