cleanup traits

This commit is contained in:
Sven Oesau 2024-03-26 14:31:02 +01:00
parent 4c48945048
commit cee30fb51a
5 changed files with 85 additions and 20 deletions

View File

@ -33,6 +33,7 @@
- `AABBRayIntersectionTraits`
\cgalCRPSection{Classes}
- `CGAL::AABB_traits<GeomTraits,Primitive>` (deprecated, use `CGAL::AABB_traits_3<GeomTraits,Primitive>`)
- `CGAL::AABB_traits_2<GeomTraits,Primitive>`
- `CGAL::AABB_traits_3<GeomTraits,Primitive>`
- `CGAL::AABB_tree<AT>`
@ -42,7 +43,9 @@
- `CGAL::AABB_indexed_triangle_primitive_2<GeomTraits, IndexIterator, PointRange, CacheDatum>`
- `CGAL::AABB_segment_primitive_2<GeomTraits, Iterator, CacheDatum>`
- `CGAL::AABB_polyline_segment_primitive_2<GeomTraits, Iterator, PointRange, CacheDatum>`
- `CGAL::AABB_triangle_primitive<GeomTraits, Iterator, CacheDatum>` (deprecated, use `CGAL::AABB_triangle_primitive_3<GeomTraits, Iterator, CacheDatum>`)
- `CGAL::AABB_triangle_primitive_3<GeomTraits, Iterator, CacheDatum>`
- `CGAL::AABB_segment_primitive<GeomTraits, Iterator, CacheDatum>` (deprecated, use `CGAL::AABB_segment_primitive_3<GeomTraits, Iterator, CacheDatum>`)
- `CGAL::AABB_segment_primitive_3<GeomTraits, Iterator, CacheDatum>`
- `CGAL::AABB_primitive<Id,ObjectPropertyMap,PointPropertyMap,ExternalPropertyMaps,CacheDatum>`
- `CGAL::AABB_halfedge_graph_segment_primitive<HalfedgeGraph,Vpm,OneHalfedgeGraphPerTree,CacheDatum>`

View File

@ -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

View File

@ -0,0 +1,52 @@
// Author(s) : Camille Wormser, Pierre Alliez
#include <iostream>
#include <list>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits_2.h>
#include <CGAL/AABB_triangle_primitive_2.h>
typedef CGAL::Simple_cartesian<double> K;
typedef K::FT FT;
typedef K::Ray_2 Ray;
typedef K::Point_2 Point;
typedef K::Triangle_2 Triangle;
typedef std::list<Triangle>::iterator Iterator;
typedef CGAL::AABB_triangle_primitive_2<K, Iterator> Primitive;
typedef CGAL::AABB_traits_2<K, Primitive> AABB_triangle_traits;
typedef CGAL::AABB_tree<AABB_triangle_traits> 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<Triangle> 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;
}

View File

@ -47,28 +47,24 @@ struct AABB_traits_intersection_base_2<GeomTraits,false>{};
template <typename GeomTraits>
struct AABB_traits_intersection_base_2<GeomTraits,true>{
template<typename AABBTree, typename SkipFunctor>
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<FT> operator()(const Ray& ray, const Bounding_box& bbox) const {
FT t_near = -DBL_MAX; // std::numeric_limits<FT>::lowest(); C++1903

View File

@ -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 <typename GeomTraits>
struct AABB_traits_intersection_base_3<GeomTraits,false>{};
template <typename GeomTraits>
struct AABB_traits_intersection_base_3<GeomTraits,true>{
struct AABB_traits_intersection_base_3<GeomTraits, true> {
template<class, class>
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.