diff --git a/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionTraits.h b/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionTraits.h index e234eba160c..e2385baac64 100644 --- a/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionTraits.h +++ b/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionTraits.h @@ -17,12 +17,50 @@ distance of an intersection along a ray. */ class AABBRayIntersectionTraits { public: - /*! Type of a ray. */ typedef unspecified_type Ray; + /*! + Type of a vector. + */ + typedef unspecified_type Vector; + + /*! + A functor object to construct the source point of a ray. Provides the operator: + `Point operator()(const Ray&);` + */ + typedef unspecified_type Construct_source; + + /*! + */ + Construct_source construct_source_object(); + + /*! + A model of `CartesianConstIterator2` or `CartesianConstIterator3`, must compatible with `Vector`. + */ + typedef unspecified_type Cartesian_const_iterator; + + /*! + A model of `ConstructCartesianConstIterator2` or `ConstructCartesianConstIterator3`, must compatible with `Vector`. + */ + typedef unspecified_type Construct_cartesian_const_iterator; + + /*! + */ + Construct_source construct_cartesian_const_iterator_object(); + + /*! + A functor object to construct a vector giving the direction of a ray. Provides the operator: + `Vector operator()(const Ray&);` + */ + typedef unspecified_type Construct_vector; + + /*! + */ + Construct_source construct_vector_object(); + /*! A functor object to compute the distance between the source of a ray and its diff --git a/AABB_tree/include/CGAL/AABB_traits_2.h b/AABB_tree/include/CGAL/AABB_traits_2.h index f91c7fdbea4..480c00aa4f0 100644 --- a/AABB_tree/include/CGAL/AABB_traits_2.h +++ b/AABB_tree/include/CGAL/AABB_traits_2.h @@ -47,14 +47,17 @@ struct AABB_traits_intersection_base_2{}; template struct AABB_traits_intersection_base_2{ - typedef typename GeomTraits::Ray_2 Ray; - typedef typename GeomTraits::Point_2 Point; - typedef typename GeomTraits::Vector_2 Vector; +private: typedef typename GeomTraits::FT FT; - typedef typename GeomTraits::Cartesian_const_iterator_2 Cartesian_const_iterator_2; - typedef typename GeomTraits::Construct_cartesian_const_iterator_2 Construct_cartesian_const_iterator_2; - typedef typename GeomTraits::Construct_source_2 Construct_source_2; - typedef typename GeomTraits::Construct_vector_2 Construct_vector_2; + 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 @@ -62,19 +65,31 @@ struct AABB_traits_intersection_base_2{ // 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(); + } + + static Construct_source construct_source_object() { + return GeomTraits().construct_source_2_object(); + } + + static Construct_vector construct_vector_object() { + return GeomTraits().construct_vector_2_object(); + } + 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 FT t_far = DBL_MAX; - const Construct_cartesian_const_iterator_2 construct_cartesian_const_iterator_2 + const Construct_cartesian_const_iterator construct_cartesian_const_iterator_2 = GeomTraits().construct_cartesian_const_iterator_2_object(); - const Construct_source_2 construct_source_2 = GeomTraits().construct_source_2_object(); - const Construct_vector_2 construct_vector_2 = GeomTraits().construct_vector_2_object(); + const Construct_source construct_source_2 = GeomTraits().construct_source_2_object(); + const Construct_vector construct_vector_2 = GeomTraits().construct_vector_2_object(); const Point source = construct_source_2(ray); const Vector direction = construct_vector_2(ray); - Cartesian_const_iterator_2 source_iter = construct_cartesian_const_iterator_2(source); - Cartesian_const_iterator_2 direction_iter = construct_cartesian_const_iterator_2(direction); + Cartesian_const_iterator source_iter = construct_cartesian_const_iterator_2(source); + Cartesian_const_iterator direction_iter = construct_cartesian_const_iterator_2(direction); for(int i = 0; i < 2; ++i, ++source_iter, ++direction_iter) { if(*direction_iter == 0) { diff --git a/AABB_tree/include/CGAL/AABB_traits_3.h b/AABB_tree/include/CGAL/AABB_traits_3.h index f84a81c2c85..5bd128cce32 100644 --- a/AABB_tree/include/CGAL/AABB_traits_3.h +++ b/AABB_tree/include/CGAL/AABB_traits_3.h @@ -47,14 +47,9 @@ struct AABB_traits_intersection_base_3{}; template struct AABB_traits_intersection_base_3{ - typedef typename GeomTraits::Ray_3 Ray; +private: typedef typename GeomTraits::Point_3 Point; - typedef typename GeomTraits::Vector_3 Vector; typedef typename GeomTraits::FT FT; - typedef typename GeomTraits::Cartesian_const_iterator_3 Cartesian_const_iterator_3; - typedef typename GeomTraits::Construct_cartesian_const_iterator_3 Construct_cartesian_const_iterator_3; - typedef typename GeomTraits::Construct_source_3 Construct_source_3; - typedef typename GeomTraits::Construct_vector_3 Construct_vector_3; // Defining Bounding_box and other types from the full AABB_traits_3 // here is might seem strange, but otherwise we would need to use @@ -62,19 +57,39 @@ struct AABB_traits_intersection_base_3{ // 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(); + } + + Construct_source construct_source_object() { + return GeomTraits().construct_source_3_object(); + } + + Construct_vector construct_vector_object() { + return GeomTraits().construct_vector_3_object(); + } + 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 FT t_far = DBL_MAX; - const Construct_cartesian_const_iterator_3 construct_cartesian_const_iterator_3 + const Construct_cartesian_const_iterator construct_cartesian_const_iterator = GeomTraits().construct_cartesian_const_iterator_3_object(); - const Construct_source_3 construct_source_3 = GeomTraits().construct_source_3_object(); - const Construct_vector_3 construct_vector_3 = GeomTraits().construct_vector_3_object(); - const Point_3 source = construct_source_3(ray); - const Vector_3 direction = construct_vector_3(ray); - Cartesian_const_iterator_3 source_iter = construct_cartesian_const_iterator_3(source); - Cartesian_const_iterator_3 direction_iter = construct_cartesian_const_iterator_3(direction); + const Construct_source construct_source = GeomTraits().construct_source_3_object(); + const Construct_vector construct_vector = GeomTraits().construct_vector_3_object(); + const Point source = construct_source(ray); + const Vector direction = construct_vector(ray); + Cartesian_const_iterator source_iter = construct_cartesian_const_iterator(source); + Cartesian_const_iterator direction_iter = construct_cartesian_const_iterator(direction); for(int i = 0; i < 3; ++i, ++source_iter, ++direction_iter) { if(*direction_iter == 0) { diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_ray_intersection.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_ray_intersection.h index 9103b05e6b7..9aa8ba6980b 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_ray_intersection.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_ray_intersection.h @@ -42,6 +42,7 @@ class AABB_ray_intersection { typedef typename AABBTree::template Intersection_and_primitive_id::Type Ray_intersection_and_primitive_id; typedef typename Ray_intersection_and_primitive_id::first_type Ray_intersection; + public: AABB_ray_intersection(const AABBTree& tree) : tree_(tree) {} @@ -51,8 +52,7 @@ public: // nb_primitives through a variable in each Node on the stack. In // BVH_node::traversal this is done through the function parameter // nb_primitives in the recursion. - typedef - boost::heap::priority_queue< Node_ptr_with_ft, boost::heap::compare< std::greater > > + typedef boost::heap::priority_queue< Node_ptr_with_ft, boost::heap::compare< std::greater > > Heap_type; typename AABB_traits::Intersection @@ -170,7 +170,7 @@ private: as_ray_param_visitor(const Ray* ray) : ray(ray), max_i(0) { - Vector v = ray->to_vector(); + Vector v = AABB_traits().construct_vector_object()(*ray); for (int i=1; i CGAL::abs(v[max_i]) ) max_i = i; @@ -187,8 +187,8 @@ private: } FT operator()(const Point& point) { - Vector x(ray->source(), point); - Vector v = ray->to_vector(); + Vector x = Vector(AABB_traits().construct_source_object()(*ray), point); + Vector v = AABB_traits().construct_vector_object()(*ray); return x[max_i] / v[max_i]; }