using functors from concept to access ray instead of using methods

This commit is contained in:
Sven Oesau 2024-03-22 16:31:42 +01:00
parent 3d87460083
commit 12fab6bb09
4 changed files with 99 additions and 31 deletions

View File

@ -17,12 +17,50 @@ distance of an intersection along a ray.
*/ */
class AABBRayIntersectionTraits { class AABBRayIntersectionTraits {
public: public:
/*! /*!
Type of a ray. Type of a ray.
*/ */
typedef unspecified_type 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 A functor object to compute the distance between the source of a ray and its

View File

@ -47,14 +47,17 @@ struct AABB_traits_intersection_base_2<GeomTraits,false>{};
template <typename GeomTraits> template <typename GeomTraits>
struct AABB_traits_intersection_base_2<GeomTraits,true>{ struct AABB_traits_intersection_base_2<GeomTraits,true>{
typedef typename GeomTraits::Ray_2 Ray; private:
typedef typename GeomTraits::Point_2 Point;
typedef typename GeomTraits::Vector_2 Vector;
typedef typename GeomTraits::FT FT; typedef typename GeomTraits::FT FT;
typedef typename GeomTraits::Cartesian_const_iterator_2 Cartesian_const_iterator_2; typedef typename GeomTraits::Point_2 Point;
typedef typename GeomTraits::Construct_cartesian_const_iterator_2 Construct_cartesian_const_iterator_2;
typedef typename GeomTraits::Construct_source_2 Construct_source_2; public:
typedef typename GeomTraits::Construct_vector_2 Construct_vector_2; 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 // Defining Bounding_box and other types from the full AABB_traits_2
// here is might seem strange, but otherwise we would need to use // here is might seem strange, but otherwise we would need to use
@ -62,19 +65,31 @@ struct AABB_traits_intersection_base_2<GeomTraits,true>{
// code more. // code more.
typedef typename CGAL::Bbox_2 Bounding_box; 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 { struct Intersection_distance {
std::optional<FT> operator()(const Ray& ray, const Bounding_box& bbox) const { std::optional<FT> operator()(const Ray& ray, const Bounding_box& bbox) const {
FT t_near = -DBL_MAX; // std::numeric_limits<FT>::lowest(); C++1903 FT t_near = -DBL_MAX; // std::numeric_limits<FT>::lowest(); C++1903
FT t_far = DBL_MAX; 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(); = GeomTraits().construct_cartesian_const_iterator_2_object();
const Construct_source_2 construct_source_2 = GeomTraits().construct_source_2_object(); const Construct_source construct_source_2 = GeomTraits().construct_source_2_object();
const Construct_vector_2 construct_vector_2 = GeomTraits().construct_vector_2_object(); const Construct_vector construct_vector_2 = GeomTraits().construct_vector_2_object();
const Point source = construct_source_2(ray); const Point source = construct_source_2(ray);
const Vector direction = construct_vector_2(ray); const Vector direction = construct_vector_2(ray);
Cartesian_const_iterator_2 source_iter = construct_cartesian_const_iterator_2(source); Cartesian_const_iterator source_iter = construct_cartesian_const_iterator_2(source);
Cartesian_const_iterator_2 direction_iter = construct_cartesian_const_iterator_2(direction); Cartesian_const_iterator direction_iter = construct_cartesian_const_iterator_2(direction);
for(int i = 0; i < 2; ++i, ++source_iter, ++direction_iter) { for(int i = 0; i < 2; ++i, ++source_iter, ++direction_iter) {
if(*direction_iter == 0) { if(*direction_iter == 0) {

View File

@ -47,14 +47,9 @@ struct AABB_traits_intersection_base_3<GeomTraits,false>{};
template <typename GeomTraits> template <typename GeomTraits>
struct AABB_traits_intersection_base_3<GeomTraits,true>{ struct AABB_traits_intersection_base_3<GeomTraits,true>{
typedef typename GeomTraits::Ray_3 Ray; private:
typedef typename GeomTraits::Point_3 Point; typedef typename GeomTraits::Point_3 Point;
typedef typename GeomTraits::Vector_3 Vector;
typedef typename GeomTraits::FT FT; 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 // Defining Bounding_box and other types from the full AABB_traits_3
// here is might seem strange, but otherwise we would need to use // here is might seem strange, but otherwise we would need to use
@ -62,19 +57,39 @@ struct AABB_traits_intersection_base_3<GeomTraits,true>{
// code more. // code more.
typedef typename CGAL::Bbox_3 Bounding_box; 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 { struct Intersection_distance {
std::optional<FT> operator()(const Ray& ray, const Bounding_box& bbox) const { std::optional<FT> operator()(const Ray& ray, const Bounding_box& bbox) const {
FT t_near = -DBL_MAX; // std::numeric_limits<FT>::lowest(); C++1903 FT t_near = -DBL_MAX; // std::numeric_limits<FT>::lowest(); C++1903
FT t_far = DBL_MAX; 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(); = GeomTraits().construct_cartesian_const_iterator_3_object();
const Construct_source_3 construct_source_3 = GeomTraits().construct_source_3_object(); const Construct_source construct_source = GeomTraits().construct_source_3_object();
const Construct_vector_3 construct_vector_3 = GeomTraits().construct_vector_3_object(); const Construct_vector construct_vector = GeomTraits().construct_vector_3_object();
const Point_3 source = construct_source_3(ray); const Point source = construct_source(ray);
const Vector_3 direction = construct_vector_3(ray); const Vector direction = construct_vector(ray);
Cartesian_const_iterator_3 source_iter = construct_cartesian_const_iterator_3(source); Cartesian_const_iterator source_iter = construct_cartesian_const_iterator(source);
Cartesian_const_iterator_3 direction_iter = construct_cartesian_const_iterator_3(direction); Cartesian_const_iterator direction_iter = construct_cartesian_const_iterator(direction);
for(int i = 0; i < 3; ++i, ++source_iter, ++direction_iter) { for(int i = 0; i < 3; ++i, ++source_iter, ++direction_iter) {
if(*direction_iter == 0) { if(*direction_iter == 0) {

View File

@ -42,6 +42,7 @@ class AABB_ray_intersection {
typedef typename AABBTree::template Intersection_and_primitive_id<Ray>::Type Ray_intersection_and_primitive_id; typedef typename AABBTree::template Intersection_and_primitive_id<Ray>::Type Ray_intersection_and_primitive_id;
typedef typename Ray_intersection_and_primitive_id::first_type Ray_intersection; typedef typename Ray_intersection_and_primitive_id::first_type Ray_intersection;
public: public:
AABB_ray_intersection(const AABBTree& tree) : tree_(tree) {} 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 // nb_primitives through a variable in each Node on the stack. In
// BVH_node::traversal this is done through the function parameter // BVH_node::traversal this is done through the function parameter
// nb_primitives in the recursion. // nb_primitives in the recursion.
typedef typedef boost::heap::priority_queue< Node_ptr_with_ft, boost::heap::compare< std::greater<Node_ptr_with_ft> > >
boost::heap::priority_queue< Node_ptr_with_ft, boost::heap::compare< std::greater<Node_ptr_with_ft> > >
Heap_type; Heap_type;
typename AABB_traits::Intersection typename AABB_traits::Intersection
@ -170,7 +170,7 @@ private:
as_ray_param_visitor(const Ray* ray) as_ray_param_visitor(const Ray* ray)
: ray(ray), max_i(0) : ray(ray), max_i(0)
{ {
Vector v = ray->to_vector(); Vector v = AABB_traits().construct_vector_object()(*ray);
for (int i=1; i<dimension; ++i) for (int i=1; i<dimension; ++i)
if( CGAL::abs(v[i]) > CGAL::abs(v[max_i]) ) if( CGAL::abs(v[i]) > CGAL::abs(v[max_i]) )
max_i = i; max_i = i;
@ -187,8 +187,8 @@ private:
} }
FT operator()(const Point& point) { FT operator()(const Point& point) {
Vector x(ray->source(), point); Vector x = Vector(AABB_traits().construct_source_object()(*ray), point);
Vector v = ray->to_vector(); Vector v = AABB_traits().construct_vector_object()(*ray);
return x[max_i] / v[max_i]; return x[max_i] / v[max_i];
} }