diff --git a/AABB_tree/benchmark/AABB_tree/test.cpp b/AABB_tree/benchmark/AABB_tree/test.cpp index eb2bb6318e4..623b608da01 100644 --- a/AABB_tree/benchmark/AABB_tree/test.cpp +++ b/AABB_tree/benchmark/AABB_tree/test.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -6,8 +6,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -18,12 +18,12 @@ typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Surface_mesh Surface_mesh; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; -typedef CGAL::AABB_do_intersect_transform_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; namespace PMP = CGAL::Polygon_mesh_processing; -void naive_test(int k, const char* fname, +void naive_test(int k, const std::string& fname, int& nb_inter, int& nb_no_inter, int& nb_include) { std::ifstream input(fname); @@ -33,7 +33,7 @@ void naive_test(int k, const char* fname, CGAL::Aff_transformation_3 init1(CGAL::SCALING, 6.0); PMP::transform(init1, tm); CGAL::Bbox_3 box = PMP::bbox(tm); - typedef CGAL::AABB_tree > Tree; + Tree tmTree(tm.faces_begin(), tm.faces_end(), tm); Tree tmTree2(tm2.faces_begin(), tm2.faces_end(), tm2); CGAL::Aff_transformation_3 init2(CGAL::TRANSLATION, - K::Vector_3( @@ -86,7 +86,8 @@ void naive_test(int k, const char* fname, T0 = CGAL::Aff_transformation_3(CGAL::TRANSLATION, -i*unit_vec); } } -void test_no_collision(int k, const char* fname, + +void test_no_collision(int k, const std::string &fname, int& nb_inter, int& nb_no_inter, int& nb_include) { std::ifstream input(fname); @@ -97,9 +98,11 @@ void test_no_collision(int k, const char* fname, PMP::transform(init1, tm); CGAL::Bbox_3 box = PMP::bbox(tm); Tree tmTree(tm.faces_begin(), tm.faces_end(), tm); + Tree tmTree2(tm2.faces_begin(), tm2.faces_end(), tm2); CGAL::Aff_transformation_3 init2(CGAL::TRANSLATION, - K::Vector_3( (box.xmax()-box.xmin()),0,0)); + PMP::transform(init2, tm2); tmTree.build(); @@ -113,6 +116,12 @@ void test_no_collision(int k, const char* fname, CGAL::Side_of_triangle_mesh sotm1(tmTree); + + CGAL::Rigid_triangle_mesh_collision_detection collision_detection; + + collision_detection.add_mesh(tm); + collision_detection.add_mesh(tm2); + for(int i=1; i T1 = CGAL::Aff_transformation_3(CGAL::TRANSLATION, i*unit_vec); CGAL::Aff_transformation_3 transfo = R*T1; - tmTree2.traits().set_transformation(transfo); - CGAL::Interval_nt_advanced::Protector protector; - if(tmTree2.do_intersect(tmTree)) + + collision_detection.set_transformation(1, transfo); + + std::vector< std::pair > res = collision_detection.get_all_intersections_and_inclusions(0); + + if (res.empty()) + nb_no_inter++; + else if(!res[0].second) ++nb_inter; else - { - if(sotm1(transfo.transform(vpm2[*tm2.vertices().begin()])) != CGAL::ON_UNBOUNDED_SIDE) - { - ++nb_include; - } - else - { - CGAL::Side_of_triangle_mesh sotm2(tmTree2); - if(sotm2(tm.point(*tm.vertices().begin())) != CGAL::ON_UNBOUNDED_SIDE) - ++nb_include; - else - ++nb_no_inter; - } - } + ++nb_include; } } int main(int argc, const char** argv) { - int k = (argc>1) ? atoi(argv[1]) : 10; - const char* path = (argc>2)?argv[2]:"data/handle" - ".off"; + int k = (argc>1) ? atoi(argv[1]) : 20; + std::string path = (argc>2)?argv[2]: CGAL::data_file_path("meshes/handle.off"); std::cout<< k<<" steps in "<(end - start).count() << "μs." << std::endl; + std::cout<<"Naive test : "<(end - start).count() << " ms." << std::endl; start = std::chrono::steady_clock::now(); test_no_collision(k, path,nb_inter, nb_no_inter, nb_include); end = std::chrono::steady_clock::now(); std::cout<<"With transform_traits: "<(end - start).count() << "μs." << std::endl; + <(end - start).count() << " ms." << std::endl; return 0; } diff --git a/AABB_tree/demo/AABB_tree/Scene.cpp b/AABB_tree/demo/AABB_tree/Scene.cpp index 41e11ac6209..a84d9d3f254 100644 --- a/AABB_tree/demo/AABB_tree/Scene.cpp +++ b/AABB_tree/demo/AABB_tree/Scene.cpp @@ -867,7 +867,7 @@ void Scene::generate_points_in(const unsigned int nb_points, } typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; std::cout << "Construct AABB tree..."; @@ -920,7 +920,7 @@ void Scene::generate_inside_points(const unsigned int nb_points) } typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; std::cout << "Construct AABB tree..."; @@ -962,7 +962,7 @@ void Scene::generate_boundary_segments(const unsigned int nb_slices) } typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; typedef Tree::Object_and_primitive_id Object_and_primitive_id; @@ -1012,7 +1012,7 @@ void Scene::generate_boundary_points(const unsigned int nb_points) } typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; typedef Tree::Object_and_primitive_id Object_and_primitive_id; @@ -1062,7 +1062,7 @@ void Scene::generate_edge_points(const unsigned int nb_points) } typedef CGAL::AABB_halfedge_graph_segment_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; typedef Tree::Object_and_primitive_id Object_and_primitive_id; diff --git a/AABB_tree/demo/AABB_tree/Scene.h b/AABB_tree/demo/AABB_tree/Scene.h index ae898f43daa..86854e4b988 100644 --- a/AABB_tree/demo/AABB_tree/Scene.h +++ b/AABB_tree/demo/AABB_tree/Scene.h @@ -9,7 +9,7 @@ #include "Color_ramp.h" #include -#include +#include #include #include #include @@ -62,11 +62,11 @@ public: private: typedef CGAL::AABB_face_graph_triangle_primitive Facet_Primitive; - typedef CGAL::AABB_traits Facet_Traits; + typedef CGAL::AABB_traits_3 Facet_Traits; typedef CGAL::AABB_tree Facet_tree; typedef CGAL::AABB_halfedge_graph_segment_primitive Edge_Primitive; - typedef CGAL::AABB_traits Edge_Traits; + typedef CGAL::AABB_traits_3 Edge_Traits; typedef CGAL::AABB_tree Edge_tree; typedef CGAL::qglviewer::ManipulatedFrame ManipulatedFrame; diff --git a/AABB_tree/doc/AABB_tree/Concepts/AABBGeomTraits_2.h b/AABB_tree/doc/AABB_tree/Concepts/AABBGeomTraits_2.h new file mode 100644 index 00000000000..82ab0e5a2e0 --- /dev/null +++ b/AABB_tree/doc/AABB_tree/Concepts/AABBGeomTraits_2.h @@ -0,0 +1,177 @@ + +/*! +\ingroup PkgAABBTreeConcepts +\cgalConcept + +The concept `AABBGeomTraits_2` defines the requirements for the first template parameter of the class +`CGAL::AABB_traits_2`. It provides predicates and constructors to detect +and compute intersections between query objects and the primitives stored in the AABB tree. +In addition, it contains predicates and constructors to compute distances between a point query +and the primitives stored in the AABB tree. + +\cgalRefines{SearchGeomTraits_2} + +\cgalHasModelsBegin +\cgalHasModelsBare{All models of the concept `Kernel`} +\cgalHasModelsEnd + +\sa `CGAL::AABB_traits_2` +\sa `CGAL::AABB_tree` +\sa `AABBPrimitive` + +*/ + +class AABBGeomTraits_2 { +public: + +/// \name Types +/// @{ + +/*! +A functor object to detect intersections between two geometric objects. +Provides the following operators: + +`bool operator()(const Query& q, const Bbox_2& b)`, + +`bool operator()(const Query& q, const Primitive::Datum& d)`, + +`bool operator()(const Circle_2& c, const Bbox_2& b)`. + +The operator returns `true` iff there is an intersection. +*/ +typedef unspecified_type Do_intersect_2; + +/*! +A functor object to construct the intersection between two geometric objects. + +Provides the operator: + +`return_type operator()(const Query& q, const Primitive::Datum& d)`, + +which computes the intersection between `q` and `d`. The type of the returned object +must be a `std::optional` of a `std::variant` of the possible intersection types. +*/ +typedef unspecified_type Intersect_2; + +/*! +A functor object to construct the circle specified by its center and squared radius. +Provides the operator: + +`Circle_2 operator()(const Point_2& p, const FT & sr)`, + +which returns the circle centered at `p` with `sr` as squared radius. +*/ +typedef unspecified_type Construct_circle_2; + +/*! +A functor object to compute the point on a geometric primitive which is closest from a query point. +Provides the operator: + +`Point_2 operator()(const Primitive::Datum& d, const Point_2& p)`, + +which returns the point on `d` that is closest to `p`. +*/ +typedef unspecified_type Construct_projected_point_2; + +/*! +A functor object to compare the distance of two points wrt a third one. Provides the operator: + +`CGAL::Comparison_result operator()(const Point_2& p1, const Point_2& p2, const Point_2& p3)`, + +which compares the distance between `p1` and `p2`, to the distance between `p1` and `p3`. +*/ +typedef unspecified_type Compare_distance_2; + + +/*! +A functor object to compute the squared distance between two points. Provides the operator: + +`FT operator()(const Point_2& p, const Point_2& q),` + +which returns the squared distance between `p` and `q`. +*/ +typedef unspecified_type Compute_squared_distance_2; + +/*! +A functor object to compare the x-coordinates of two points. Provides the operator: + +`bool operator()(const Point_2& p, const Point_2& q)`, + + which returns `true` iff the x-coordinate of `p` is smaller than the x-coordinate of `q`. +*/ +typedef unspecified_type Less_x_2; + +/*! +A functor object to compare the y-coordinates of two points. Provides the operator: + +`bool operator()(const Point_2& p, const Point_2& q)`, + +which returns `true` iff the y-coordinate of `p` is smaller than the y-coordinate of `q`. +*/ +typedef unspecified_type Less_y_2; + + +/*! +A functor object to compare two points. Provides the operator: + +`bool operator()(const Point_2& p, const Point_2& q)`, + +which returns `true` iff `p` is equal to `q`. +*/ +typedef unspecified_type Equal_2; + +/// @} + +/// \name Operations +/// @{ + +/*! +returns the intersection detection predicate. +*/ +Do_intersect_2 do_intersect_2_object(); + +/*! +returns the intersection constructor. +*/ +Intersect_2 intersect_2_object(); + +/*! +returns the circle constructor. +*/ +Construct_circle_2 construct_circle_2_object(); + +/*! +returns the closest point constructor. +*/ +Construct_projected_point_2 construct_projected_point_2_object(); + +/*! +returns the compare distance predicate. +*/ +Compare_distance_2 compare_distance_2_object(); + + +/*! +returns the squared distance functor. +*/ +Compute_squared_distance_2 compute_squared_distance_2_object(); + +/*! +returns the `Less_x_2` predicate. +*/ +Less_x_2 less_x_2_object(); + +/*! +returns the `Less_y_2` predicate. +*/ +Less_y_2 less_y_2_object(); + + +/*! +returns the equal predicate. +*/ +Equal_2 equal_2_object(); + +/// @} + +}; /* end AABBGeomTraits_2 */ diff --git a/AABB_tree/doc/AABB_tree/Concepts/AABBGeomTraits.h b/AABB_tree/doc/AABB_tree/Concepts/AABBGeomTraits_3.h similarity index 79% rename from AABB_tree/doc/AABB_tree/Concepts/AABBGeomTraits.h rename to AABB_tree/doc/AABB_tree/Concepts/AABBGeomTraits_3.h index ca49f3ab247..2f453f54670 100644 --- a/AABB_tree/doc/AABB_tree/Concepts/AABBGeomTraits.h +++ b/AABB_tree/doc/AABB_tree/Concepts/AABBGeomTraits_3.h @@ -3,8 +3,8 @@ \ingroup PkgAABBTreeConcepts \cgalConcept -The concept `AABBGeomTraits` defines the requirements for the first template parameter of the class -`CGAL::AABB_traits`. It provides predicates and constructors to detect +The concept `AABBGeomTraits_3` defines the requirements for the first template parameter of the class +`CGAL::AABB_traits_3`. It provides predicates and constructors to detect and compute intersections between query objects and the primitives stored in the AABB tree. In addition, it contains predicates and constructors to compute distances between a point query and the primitives stored in the AABB tree. @@ -15,13 +15,13 @@ and the primitives stored in the AABB tree. \cgalHasModelsBare{All models of the concept `Kernel`} \cgalHasModelsEnd -\sa `CGAL::AABB_traits` +\sa `CGAL::AABB_traits_3` \sa `CGAL::AABB_tree` \sa `AABBPrimitive` */ -class AABBGeomTraits { +class AABBGeomTraits_3 { public: /// \name Types @@ -31,13 +31,13 @@ public: A functor object to detect intersections between two geometric objects. Provides the following operators: -`bool operator()(Query, Bbox_3)`, +`bool operator()(const Query& q, const Bbox_3& b)`, -`bool operator()(Query, Primitive::Datum)`, +`bool operator()(const Query& q, const Primitive::Datum& d)`, -`bool operator()(Sphere_3, Bbox_3)`. +`bool operator()(const Sphere_3& s, const Bbox_3& b)`. -The operator returns `true` iff there exists a non-empty intersection. +The operator returns `true` iff there is an intersection. */ typedef unspecified_type Do_intersect_3; @@ -54,7 +54,7 @@ must be a `std::optional` of a `std::variant` of the possible intersection types typedef unspecified_type Intersect_3; /*! -A functor object to construct the sphere centered at one point and passing through another one. +A functor object to construct the sphere specified by its center and squared radius. Provides the operator: `Sphere_3 operator()(const Point_3& p, const FT & sr)`, @@ -64,7 +64,7 @@ which returns the sphere centered at `p` with `sr` as squared radius. typedef unspecified_type Construct_sphere_3; /*! -A functor object to compute the point on a geometric primitive which is closest from a query. +A functor object to compute the point on a geometric primitive which is closest from a query point. Provides the operator: `Point_3 operator()(const Primitive::Datum& d, const Point_3& p)`, @@ -78,19 +78,10 @@ A functor object to compare the distance of two points wrt a third one. Provides `CGAL::Comparison_result operator()(const Point_3& p1, const Point_3& p2, const Point_3& p3)`, -which compares the distance between `p1` and `p2`, and between `p2` and `p3`. +which compares the distance between `p1` and `p2`, to the distance between `p1` and `p3`. */ typedef unspecified_type Compare_distance_3; -/*! -A functor object to compute the squared radius of a sphere. -Provides the operator: - -`FT operator()(const Sphere_3& s),` - -which returns the squared radius of `s`. -*/ -typedef unspecified_type Compute_squared_radius_3; /*! A functor object to compute the squared distance between two points. Provides the operator: @@ -167,10 +158,6 @@ returns the compare distance predicate. */ Compare_distance_3 compare_distance_3_object(); -/*! -returns the squared radius functor. -*/ -Compute_squared_radius_3 compute_squared_radius_3_object(); /*! returns the squared distance functor. @@ -199,5 +186,4 @@ Equal_3 equal_3_object(); /// @} -}; /* end AABBGeomTraits */ - +}; /* end AABBGeomTraits_3 */ diff --git a/AABB_tree/doc/AABB_tree/Concepts/AABBPrimitive.h b/AABB_tree/doc/AABB_tree/Concepts/AABBPrimitive.h index 3abb0cf153b..5d8e1246a7c 100644 --- a/AABB_tree/doc/AABB_tree/Concepts/AABBPrimitive.h +++ b/AABB_tree/doc/AABB_tree/Concepts/AABBPrimitive.h @@ -14,8 +14,10 @@ The `Primitive` type can be, e.g., a wrapper around a `Handle`. Assume for insta \cgalHasModelsBegin \cgalHasModels{CGAL::AABB_primitive} -\cgalHasModels{CGAL::AABB_segment_primitive} -\cgalHasModels{CGAL::AABB_triangle_primitive} +\cgalHasModels{CGAL::AABB_segment_primitive_2} +\cgalHasModels{CGAL::AABB_segment_primitive_3} +\cgalHasModels{CGAL::AABB_triangle_primitive_2} +\cgalHasModels{CGAL::AABB_triangle_primitive_3} \cgalHasModels{CGAL::AABB_halfedge_graph_segment_primitive} \cgalHasModels{CGAL::AABB_face_graph_triangle_primitive} \cgalHasModelsEnd @@ -28,7 +30,7 @@ public: /// @{ /*! -3D point type. +Point type. */ typedef unspecified_type Point; @@ -68,7 +70,7 @@ returns the corresponding identifier. This identifier is only used as a referenc Id id(); /*! -returns a 3D point located on the geometric object represented by the primitive. This function is used to sort the primitives during the AABB tree construction as well as to construct the search KD-tree internal to the AABB tree used to accelerate distance queries. +returns a point located on the geometric object represented by the primitive. This function is used to sort the primitives during the AABB tree construction as well as to construct the search KD-tree internal to the AABB tree used to accelerate distance queries. */ Point_reference reference_point(); diff --git a/AABB_tree/doc/AABB_tree/Concepts/AABBPrimitiveWithSharedData.h b/AABB_tree/doc/AABB_tree/Concepts/AABBPrimitiveWithSharedData.h index 416cc785468..284c90b6038 100644 --- a/AABB_tree/doc/AABB_tree/Concepts/AABBPrimitiveWithSharedData.h +++ b/AABB_tree/doc/AABB_tree/Concepts/AABBPrimitiveWithSharedData.h @@ -34,7 +34,7 @@ public: /// \name Types /// @{ /*! -3D point type. +Point type. */ typedef unspecified_type Point; @@ -78,7 +78,7 @@ returns the corresponding identifier. This identifier is only used as a referenc Id id(); /*! -returns a 3D point located on the geometric object represented by the primitive. This function is used to sort the primitives during the AABB tree construction as well as to construct the search KD-tree internal to the AABB tree used to accelerate distance queries. +returns a point located on the geometric object represented by the primitive. This function is used to sort the primitives during the AABB tree construction as well as to construct the search KD-tree internal to the AABB tree used to accelerate distance queries. */ Point_reference reference_point(const Shared_data& data); diff --git a/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionGeomTraits_2.h b/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionGeomTraits_2.h new file mode 100644 index 00000000000..15e3050edee --- /dev/null +++ b/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionGeomTraits_2.h @@ -0,0 +1,69 @@ +/*! +\ingroup PkgAABBTreeConcepts +\cgalConcept + +The concept `AABBRayIntersectionGeomTraits_2` is a refinement of the +concept `AABBGeomTraits_2`. In addition to the types and functors required by +`AABBGeomTraits_2` it also requires types and functors necessary to +define the Intersection_distance functor (see `AABBRayIntersectionTraits`). + +\cgalRefines{AABBGeomTraits_2} + +\cgalHasModelsBegin +\cgalHasModelsBare{All models of the concept `Kernel`} +\cgalHasModelsEnd + +\sa `CGAL::AABB_traits_2` +\sa `CGAL::AABB_tree` +\sa `AABBPrimitive` + +*/ +class AABBRayIntersectionGeomTraits_2 { +public: + /*! + Type of a 2D ray. + */ + typedef unspecified_type Ray_2; + + /*! + Type of a 2D vector. + */ + typedef unspecified_type Vector_2; + + /*! + A functor object to construct the source point of a ray. Provides the operator: + `Point_2 operator()(const Ray_2&);` + */ + typedef unspecified_type Construct_source_2; + + /*! + returns the `Construct_source_2` functor. + */ + Construct_source_2 construct_source_2_object(); + + /*! + A model of `CartesianConstIterator_2`. + */ + typedef unspecified_type Cartesian_const_iterator_2; + + /*! + A model of `ConstructCartesianConstIterator_2`. + */ + typedef unspecified_type Construct_cartesian_const_iterator_2; + + /*! + returns the `Construct_cartesian_const_iterator_2` functor. + */ + Construct_cartesian_const_iterator_2 construct_cartesian_const_iterator_2_object(); + + /*! + A functor object to construct a vector having the same direction as a ray. Provides the operator: + `Vector_2 operator()(const Ray_2&);` + */ + typedef unspecified_type Construct_vector_2; + + /*! + returns the `Construct_vector_2` functor. + */ + Construct_vector_2 construct_vector_2_object(); +}; diff --git a/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionGeomTraits.h b/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionGeomTraits_3.h similarity index 52% rename from AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionGeomTraits.h rename to AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionGeomTraits_3.h index c34d88be491..508b656d1cd 100644 --- a/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionGeomTraits.h +++ b/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionGeomTraits_3.h @@ -2,23 +2,23 @@ \ingroup PkgAABBTreeConcepts \cgalConcept -The concept `AABBRayIntersectionGeomTraits` is a refinement of the -concept `AABBGeomTraits`. In addition to the types required by -`AABBGeomTraits` it also requires types and functors necessary to +The concept `AABBRayIntersectionGeomTraits_3` is a refinement of the +concept `AABBGeomTraits_3`. In addition to the types required by +`AABBGeomTraits_3` it also requires types and functors necessary to define the Intersection_distance functor. -\cgalRefines{AABBGeomTraits} +\cgalRefines{AABBGeomTraits_3} \cgalHasModelsBegin \cgalHasModelsBare{All models of the concept `Kernel`} \cgalHasModelsEnd -\sa `CGAL::AABB_traits` +\sa `CGAL::AABB_traits_3` \sa `CGAL::AABB_tree` \sa `AABBPrimitive` */ -class AABBRayIntersectionGeomTraits { +class AABBRayIntersectionGeomTraits_3 { public: /*! Type of a 3D ray. @@ -37,30 +37,33 @@ public: typedef unspecified_type Construct_source_3; /*! + returns the `Construct_source_3` functor. */ Construct_source_3 construct_source_3_object(); /*! - A model of `CartesianConstIterator3`. + A model of `CartesianConstIterator_3`. */ typedef unspecified_type Cartesian_const_iterator_3; /*! - A model of `ConstructCartesianConstIterator3`. + A model of `ConstructCartesianConstIterator_3`. */ typedef unspecified_type Construct_cartesian_const_iterator_3; /*! + returns the `Construct_cartesian_const_iterator_3` functor. */ - Construct_source_3 construct_cartesian_const_iterator_3_object(); + Construct_cartesian_const_iterator_3 construct_cartesian_const_iterator_3_object(); /*! - A functor object to construct a vector giving the direction of a ray. Provides the operator: + A functor object to construct a vector having the same direction as a ray. Provides the operator: `Vector_3 operator()(const Ray_3&);` */ typedef unspecified_type Construct_vector_3; /*! + returns the `Construct_vector_3` functor. */ - Construct_source_3 construct_vector_3_object(); + Construct_vector_3 construct_vector_3_object(); }; diff --git a/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionTraits.h b/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionTraits.h index 7b8b6dd4ec4..3940817c7ab 100644 --- a/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionTraits.h +++ b/AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionTraits.h @@ -7,8 +7,11 @@ The concept `AABBRayIntersectionTraits` is a refinement of the concept `AABBTraits` it also requires function objects to calculate the distance of an intersection along a ray. +\cgalRefines{AABBTraits} + \cgalHasModelsBegin -\cgalHasModels{CGAL::AABB_traits} +\cgalHasModels{CGAL::AABB_traits_2} +\cgalHasModels{CGAL::AABB_traits_3} \cgalHasModelsEnd \sa `CGAL::AABB_tree` @@ -17,11 +20,57 @@ distance of an intersection along a ray. */ class AABBRayIntersectionTraits { public: + /*! + Type of a ray. + */ + typedef unspecified_type Ray; /*! - Type of a 3D ray. + Type of a vector. */ - typedef unspecified_type Ray_3; + typedef unspecified_type Vector; + + /*! + Type of bounding box. + */ + typedef AABBTraits::Bounding_box Bounding_box; + + /*! + A functor object to construct the source point of a ray. Provides the operator: + `Point operator()(const Ray&);` + */ + typedef unspecified_type Construct_source; + + /*! + returns the `Construct_source` functor. + */ + Construct_source construct_source_object(); + + /*! + A model of `CartesianConstIterator_2` or `CartesianConstIterator_3`, depending on the dimension of `Vector`. + */ + typedef unspecified_type Cartesian_const_iterator; + + /*! + A model of `ConstructCartesianConstIterator_2` or `ConstructCartesianConstIterator_3`, depending on the dimension of `Vector`. + */ + typedef unspecified_type Construct_cartesian_const_iterator; + + /*! + returns the `Construct_cartesian_const_iterator` functor. + */ + Construct_cartesian_const_iterator construct_cartesian_const_iterator_object(); + + /*! + A functor object to construct a vector having the same direction as a ray. Provides the operator: + `Vector operator()(const Ray&);` + */ + typedef unspecified_type Construct_vector; + + /*! + returns the `Construct_vector` functor. + */ + Construct_vector construct_vector_object(); /*! @@ -34,9 +83,9 @@ public: respectively. Provides the operators: - `std::optional operator()(const Ray_3& r, const Bounding_box& bbox)`. - `std::optional::%Type > > - operator()(const Ray_3& r, const Primitive& primitive)`. + `std::optional operator()(const Ray& r, const Bounding_box& bbox)`. + `std::optional::%Type > > + operator()(const Ray& r, const Primitive& primitive)`. A common algorithm to compute the intersection between a bounding box and a ray is the diff --git a/AABB_tree/doc/AABB_tree/Concepts/AABBTraits.h b/AABB_tree/doc/AABB_tree/Concepts/AABBTraits.h index 3c101a2211b..40413193d54 100644 --- a/AABB_tree/doc/AABB_tree/Concepts/AABBTraits.h +++ b/AABB_tree/doc/AABB_tree/Concepts/AABBTraits.h @@ -6,12 +6,12 @@ The concept `AABBTraits` provides the geometric primitive types and methods for the class `CGAL::AABB_tree`. \cgalHasModelsBegin -\cgalHasModels{CGAL::AABB_traits} +\cgalHasModels{CGAL::AABB_traits_2} +\cgalHasModels{CGAL::AABB_traits_3} \cgalHasModelsEnd -\cgalRefines{SearchGeomTraits_3} +\cgalRefines{SearchTraits} -\sa `CGAL::AABB_traits` \sa `CGAL::AABB_tree` \sa `AABBPrimitive` @@ -28,9 +28,9 @@ Value type of the `Squared_distance` functor. typedef unspecified_type FT; /*! -Type of a 3D point. +Type of a point. */ -typedef unspecified_type Point_3; +typedef unspecified_type Point; /*! Type of primitive. @@ -43,19 +43,10 @@ Bounding box type. */ typedef unspecified_type Bounding_box; - /*! - enum required for axis selection - */ - enum Axis { - CGAL_X_AXIS, - CGAL_Y_AXIS, - CGAL_Z_AXIS - }; - /*! -3D Point and Primitive Id type +Point and Primitive Id type */ -typedef std::pair Point_and_primitive_id; +typedef std::pair Point_and_primitive_id; /*! \deprecated @@ -144,22 +135,22 @@ A functor object to compute distance comparisons between the query and the nodes typedef unspecified_type Compare_distance; /*! -A functor object to compute closest point from the query on a primitive. Provides the operator: -`Point_3 operator()(const Query& query, const Primitive& primitive, const Point_3 & closest);` which returns the closest point to `query`, among `closest` and all points of the primitive. +A functor object to compute the closest point from the query on a primitive. Provides the operator: +`Point operator()(const Query& query, const Primitive& primitive, const Point & closest);` which returns the closest point to `query`, among `closest` and all points of the primitive. */ typedef unspecified_type Closest_point; /*! A functor object to compute the squared distance between two points. Provides the operator: -`FT operator()(const Point& query, const Point_3 & p);` which returns the squared distance between `p` and `q`. +`FT operator()(const Point& query, const Point & p);` which returns the squared distance between `p` and `q`. */ typedef unspecified_type Squared_distance; /*! A functor object to compare two points. Provides the operator: -`bool operator()(const Point_3& p, const Point_3& q);}` which returns `true` if `p` is equal to `q`. +`bool operator()(const Point& p, const Point& q);}` which returns `true` if `p` is equal to `q`. */ -typedef unspecified_type Equal_3; +typedef unspecified_type Equal; /// @} /// \name Operations @@ -203,7 +194,7 @@ Squared_distance squared_distance_object(); /*! returns the equal functor. */ -Equal_3 equal_3_object(); +Equal equal_object(); /// @} @@ -231,4 +222,3 @@ const Primitive::Shared_data& shared_data() const; }; /* end AABBTraits */ - diff --git a/AABB_tree/doc/AABB_tree/Doxyfile.in b/AABB_tree/doc/AABB_tree/Doxyfile.in index b626c95c2da..fb005db4f91 100644 --- a/AABB_tree/doc/AABB_tree/Doxyfile.in +++ b/AABB_tree/doc/AABB_tree/Doxyfile.in @@ -1,10 +1,7 @@ @INCLUDE = ${CGAL_DOC_PACKAGE_DEFAULTS} -PROJECT_NAME = "CGAL ${CGAL_DOC_VERSION} - 3D Fast Intersection and Distance Computation (AABB Tree)" +PROJECT_NAME = "CGAL ${CGAL_DOC_VERSION} - Fast Intersection and Distance Computation (AABB Tree)" EXTRACT_ALL = false HIDE_UNDOC_MEMBERS = true HIDE_UNDOC_CLASSES = true - - - diff --git a/AABB_tree/doc/AABB_tree/PackageDescription.txt b/AABB_tree/doc/AABB_tree/PackageDescription.txt index c032420bb76..4aea07e8e6a 100644 --- a/AABB_tree/doc/AABB_tree/PackageDescription.txt +++ b/AABB_tree/doc/AABB_tree/PackageDescription.txt @@ -5,12 +5,12 @@ /*! \addtogroup PkgAABBTreeRef -\cgalPkgDescriptionBegin{3D Fast Intersection and Distance Computation,PkgAABBTree} +\cgalPkgDescriptionBegin{2D and 3D Fast Intersection and Distance Computation,PkgAABBTree} \cgalPkgPicture{aabb-teaser-thumb.png} \cgalPkgSummaryBegin \cgalPkgAuthors{Pierre Alliez, Stéphane Tayeb, and Camille Wormser} -\cgalPkgDesc{The AABB (axis-aligned bounding box) tree component offers a static data structure and algorithms to perform efficient intersection and distance queries on sets of finite 3D geometric objects.} -\cgalPkgManuals{Chapter_3D_Fast_Intersection_and_Distance_Computation,PkgAABBTreeRef} +\cgalPkgDesc{The AABB (axis-aligned bounding box) tree component offers a static data structure and algorithms to perform efficient intersection and distance queries on sets of finite 2D and 3D geometric objects.} +\cgalPkgManuals{Chapter_Fast_Intersection_and_Distance_Computation,PkgAABBTreeRef} \cgalPkgSummaryEnd \cgalPkgShortInfoBegin \cgalPkgSince{3.5} @@ -25,18 +25,28 @@ \cgalCRPSection{Concepts} - `AABBPrimitive` - `AABBPrimitiveWithSharedData` -- `AABBGeomTraits` +- `AABBGeomTraits_2` +- `AABBGeomTraits_3` - `AABBTraits` -- `AABBRayIntersectionGeomTraits` +- `AABBRayIntersectionGeomTraits_2` +- `AABBRayIntersectionGeomTraits_3` - `AABBRayIntersectionTraits` \cgalCRPSection{Classes} -- `CGAL::AABB_traits` +- `CGAL::AABB_traits` (deprecated, use `CGAL::AABB_traits_3`) +- `CGAL::AABB_traits_2` +- `CGAL::AABB_traits_3` - `CGAL::AABB_tree` \cgalCRPSection{Primitives} -- `CGAL::AABB_triangle_primitive` -- `CGAL::AABB_segment_primitive` +- `CGAL::AABB_triangle_primitive_2` +- `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` - `CGAL::AABB_face_graph_triangle_primitive` diff --git a/AABB_tree/doc/AABB_tree/aabb_tree.txt b/AABB_tree/doc/AABB_tree/aabb_tree.txt index bdeefbdd032..ca5f84e2fbf 100644 --- a/AABB_tree/doc/AABB_tree/aabb_tree.txt +++ b/AABB_tree/doc/AABB_tree/aabb_tree.txt @@ -3,7 +3,7 @@ namespace CGAL { /*! \mainpage User Manual -\anchor Chapter_3D_Fast_Intersection_and_Distance_Computation +\anchor Chapter_Fast_Intersection_and_Distance_Computation \cgalAutoToc \authors Pierre Alliez, Stephane Tayeb, and Camille Wormser @@ -12,7 +12,7 @@ namespace CGAL { The AABB tree component offers a static data structure and algorithms to perform efficient intersection and distance queries against sets of -finite 3D geometric objects. The set of geometric objects stored in +finite 2D or 3D geometric objects. The set of geometric objects stored in the data structure can be queried for intersection detection, intersection computation and distance. The intersection queries can be of any type, provided that the corresponding intersection predicates @@ -123,7 +123,7 @@ the squared distance from a point query. \subsection aabb_tree_examples_2 Tree of Polyhedron Triangle Facets for Intersection Queries - In the following example the AABB primitive wraps a facet handle of a +In the following example the AABB primitive wraps a facet handle of a triangle polyhedral surface as `id` and the corresponding 3D triangle as geometric object. From a segment query we test the intersections, then compute the number of intersections, compute the @@ -163,12 +163,17 @@ handle. \subsection aabb_tree_examples_4 Tree of Segments for Intersection and Distance Queries - In the following example the segments are stored into a list, and the +In the following example the segments are stored into a list, and the AABB primitive wraps a segment as `datum` and an iterator in the list as `id`. We compute the number of intersections with plane and triangles queries, and the closest point from a point query. \cgalExample{AABB_tree/AABB_segment_3_example.cpp} +\subsection aabb_tree_examples_8 Tree of Polyline and Polygon Segments for Intersection and Distance Queries + +The following example uses segments given by a polyline and a polygon. The difference is that the polygon is closed. The `id` in this case is the iterator pointing to a `Point_2` in the polyline or the polygon. The datum, a `Segment_2`, is created on the fly from the points using the `id` as the source and the following `Point_2` as the target. We count the intersections with a `Segment_2` and the closest point and id from a point query. +\cgalExample{AABB_tree/AABB_polyline_segment_2_example.cpp} + \subsection aabb_tree_examples_5 Tree of Polyhedron Edge Segments for Intersection and Distance Queries In the following example the AABB primitive wraps a halfedge handle as @@ -233,7 +238,7 @@ subdivision scheme which multiplies the number of triangles by four. \subsection aabb_tree_perf_mem Memory When using the polyhedron triangle facet primitive (defined in -`AABB_polyhedron_triangle_primitive.h`) the AABB tree occupies +`AABB_face_graph_triangle_primitive.h`) the AABB tree occupies approximately 61 bytes per primitive (without constructing the internal KD-tree). It increases to approximately 150 bytes per primitive when constructing the internal KD-tree with one reference @@ -426,7 +431,7 @@ initial ball radius to a small value still guaranteed to intersect the input primitives. This is achieved by constructing an internal secondary data structure which provides a good hint to the algorithm at the beginning of the traversal (done by default). -Calling `do_not_accelerate_distance_queries()` will disable +Calling `AABB_tree::do_not_accelerate_distance_queries()` will disable the construction and the usage of this internal secondary data structure. \section aabb_tree_history Design and Implementation History @@ -437,9 +442,14 @@ implementing both intersection and distance queries, and for generic queries and primitives was developed by Camille Wormser. In 2009, Pierre Alliez, Stéphane Tayeb and Camille Wormser made the implementation CGAL-compliant, with the help of Laurent Rineau for -optimizing the tree construction. The authors wish to thank Andreas -Fabri, Jane Tournois, Mariette Yvinec and Sylvain Lefèbvre for -helpful comments and discussions. +optimizing the tree construction. Additionally, Andreas +Fabri, Jane Tournois, Mariette Yvinec and Sylvain Lefèbvre are +given thanks for helpful comments and discussions during that period. +Later, Sébastien Loriot contributed several improvements: +thread-safe queries, introduction of shared data stored in the traits +for lighter primitive types, ... +In 2024, the package was made compatible with 2D and 3D primitives by +Andreas Fabri, Sébastien Loriot, and Sven Oesau. */ diff --git a/AABB_tree/doc/AABB_tree/dependencies b/AABB_tree/doc/AABB_tree/dependencies index 81058527aaf..6c6aa39dfe3 100644 --- a/AABB_tree/doc/AABB_tree/dependencies +++ b/AABB_tree/doc/AABB_tree/dependencies @@ -8,3 +8,4 @@ Box_intersection_d Polyhedron BGL Spatial_searching +Property_map diff --git a/AABB_tree/doc/AABB_tree/examples.txt b/AABB_tree/doc/AABB_tree/examples.txt index cc274a27469..d986357796c 100644 --- a/AABB_tree/doc/AABB_tree/examples.txt +++ b/AABB_tree/doc/AABB_tree/examples.txt @@ -7,8 +7,12 @@ \example AABB_tree/AABB_polyhedron_edge_example.cpp \example AABB_tree/AABB_polyhedron_facet_distance_example.cpp \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_cached_bbox_example.cpp b/AABB_tree/examples/AABB_tree/AABB_cached_bbox_example.cpp index b8af3f3f442..129d3e65c1d 100644 --- a/AABB_tree/examples/AABB_tree/AABB_cached_bbox_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_cached_bbox_example.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include #include #include @@ -23,7 +23,7 @@ template void triangle_mesh(std::string fname) { typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; TriangleMesh tmesh; @@ -56,7 +56,7 @@ void surface_mesh_cache_bbox(std::string fname) typedef boost::graph_traits::face_descriptor face_descriptor; typedef Surface_mesh::Property_map Bbox_pmap; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; Surface_mesh tmesh; diff --git a/AABB_tree/examples/AABB_tree/AABB_custom_example.cpp b/AABB_tree/examples/AABB_tree/AABB_custom_example.cpp index 5f225eef950..60696a0d144 100644 --- a/AABB_tree/examples/AABB_tree/AABB_custom_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_custom_example.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include @@ -91,7 +91,7 @@ public: -typedef CGAL::AABB_traits My_AABB_traits; +typedef CGAL::AABB_traits_3 My_AABB_traits; typedef CGAL::AABB_tree Tree; int main() diff --git a/AABB_tree/examples/AABB_tree/AABB_custom_indexed_triangle_set_array_example.cpp b/AABB_tree/examples/AABB_tree/AABB_custom_indexed_triangle_set_array_example.cpp index ab8f529f54c..0952cc15146 100644 --- a/AABB_tree/examples/AABB_tree/AABB_custom_indexed_triangle_set_array_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_custom_indexed_triangle_set_array_example.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include @@ -97,7 +97,7 @@ public: // types -typedef CGAL::AABB_traits My_AABB_traits; +typedef CGAL::AABB_traits_3 My_AABB_traits; typedef CGAL::AABB_tree Tree; const double* My_triangle_primitive::point_container = nullptr; diff --git a/AABB_tree/examples/AABB_tree/AABB_custom_indexed_triangle_set_example.cpp b/AABB_tree/examples/AABB_tree/AABB_custom_indexed_triangle_set_example.cpp index b864c08adba..f778a06edf8 100644 --- a/AABB_tree/examples/AABB_tree/AABB_custom_indexed_triangle_set_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_custom_indexed_triangle_set_example.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include @@ -104,7 +104,7 @@ public: // types -typedef CGAL::AABB_traits My_AABB_traits; +typedef CGAL::AABB_traits_3 My_AABB_traits; typedef CGAL::AABB_tree Tree; const std::vector* My_triangle_primitive::point_container = nullptr; diff --git a/AABB_tree/examples/AABB_tree/AABB_custom_triangle_soup_example.cpp b/AABB_tree/examples/AABB_tree/AABB_custom_triangle_soup_example.cpp index 0fe8ffb713a..62361baba69 100644 --- a/AABB_tree/examples/AABB_tree/AABB_custom_triangle_soup_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_custom_triangle_soup_example.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include @@ -95,7 +95,7 @@ public: }; // types -typedef CGAL::AABB_traits My_AABB_traits; +typedef CGAL::AABB_traits_3 My_AABB_traits; typedef CGAL::AABB_tree Tree; int main() diff --git a/AABB_tree/examples/AABB_tree/AABB_face_graph_triangle_example.cpp b/AABB_tree/examples/AABB_tree/AABB_face_graph_triangle_example.cpp index 244909cb1b1..2ce90dd2cfd 100644 --- a/AABB_tree/examples/AABB_tree/AABB_face_graph_triangle_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_face_graph_triangle_example.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include @@ -14,7 +14,7 @@ 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_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; template diff --git a/AABB_tree/examples/AABB_tree/AABB_halfedge_graph_edge_example.cpp b/AABB_tree/examples/AABB_tree/AABB_halfedge_graph_edge_example.cpp index 57eade14b28..76cb7eec177 100644 --- a/AABB_tree/examples/AABB_tree/AABB_halfedge_graph_edge_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_halfedge_graph_edge_example.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include @@ -14,7 +14,7 @@ typedef K::Point_3 Point; typedef K::Triangle_3 Triangle; typedef CGAL::Polyhedron_3 Polyhedron; typedef CGAL::AABB_halfedge_graph_segment_primitive Primitive; -typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; template diff --git a/AABB_tree/examples/AABB_tree/AABB_indexed_triangle_2_example.cpp b/AABB_tree/examples/AABB_tree/AABB_indexed_triangle_2_example.cpp new file mode 100644 index 00000000000..053c49467a4 --- /dev/null +++ b/AABB_tree/examples/AABB_tree/AABB_indexed_triangle_2_example.cpp @@ -0,0 +1,91 @@ +#include +#include +#include + +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K; +typedef K::Point_3 Point_3; +typedef K::Point_2 Point_2; +typedef K::Ray_2 Ray; + +template +struct Projection_xy_point_map { + + typedef typename GeomTraits::Point_3 key_type; + typedef typename GeomTraits::Point_2 value_type; + typedef value_type reference; + + typedef boost::readable_property_map_tag category; + typedef Projection_xy_point_map Self; + + Projection_xy_point_map() {} + + inline friend value_type get(Self, key_type p) + { + return value_type(p.x(), p.y()); + } +}; + +typedef std::vector >::const_iterator IndexIterator; +typedef std::vector PointRange; +typedef CGAL::AABB_indexed_triangle_primitive_2> Primitive; +typedef CGAL::AABB_traits_2 AABB_triangle_traits; +typedef CGAL::AABB_tree Tree; +typedef Tree::Point_and_primitive_id Point_and_primitive_id; +typedef std::optional::Type> Ray_intersection; + +int main() +{ + Point_3 a(0.0, 0.0, 0.0); + Point_3 b(0.0, 1.0, 0.0); + Point_3 c(1.0, 0.0, 0.0); + Point_3 d(1.0, 1.0, 0.0); + Point_3 e(2.0, 0.0, 0.0); + Point_3 f(2.0, 1.0, 0.0); + + std::vector points = { a, b, c, d, e, f }; + + std::vector > triangles; + triangles.push_back({ 0, 2, 1 }); + triangles.push_back({ 1, 2, 3 }); + triangles.push_back({ 3, 2, 4 }); + triangles.push_back({ 3, 4, 5 }); + + // constructs AABB tree + Tree tree(triangles.begin(), triangles.end(), points); + + // point sampling + Point_and_primitive_id id; + id = tree.closest_point_and_primitive(Point_2(0.5, 0.4)); + std::cout << std::distance(triangles.cbegin(), id.second) << ". triangle" << std::endl; + id = tree.closest_point_and_primitive(Point_2(0.5, 0.6)); + std::cout << std::distance(triangles.cbegin(), id.second) << ". triangle" << std::endl; + id = tree.closest_point_and_primitive(Point_2(1.5, 0.5)); + std::cout << std::distance(triangles.cbegin(), id.second) << ". triangle" << std::endl; + id = tree.closest_point_and_primitive(Point_2(1.5, 0.6)); + std::cout << std::distance(triangles.cbegin(), id.second) << ". triangle" << std::endl; + id = tree.closest_point_and_primitive(Point_2(1.0, 0.0)); + std::cout << std::distance(triangles.cbegin(), id.second) << ". triangle" << std::endl; + id = tree.closest_point_and_primitive(Point_2(3.0, 0.5)); + std::cout << std::distance(triangles.cbegin(), id.second) << ". triangle" << std::endl; + + Ray ray(Point_2(5.5, 0.5), Point_2(1.5, 0.5)); + Ray_intersection intersection = tree.first_intersection(ray); + + if (!intersection) { + std::cout << "Ray does not intersect with triangles although it should!" << std::endl; + return EXIT_FAILURE; + } + else { + std::cout << std::distance(triangles.cbegin(), intersection->second) << ". triangle" << std::endl; + } + + std::list intersections; + tree.all_intersections(ray, std::back_inserter(intersections)); + + return EXIT_SUCCESS; +} diff --git a/AABB_tree/examples/AABB_tree/AABB_insertion_example.cpp b/AABB_tree/examples/AABB_tree/AABB_insertion_example.cpp index 90719fda49f..a4db367629d 100644 --- a/AABB_tree/examples/AABB_tree/AABB_insertion_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_insertion_example.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include @@ -13,7 +13,7 @@ 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_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; typedef Tree::Point_and_primitive_id Point_and_primitive_id; 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 8e8c776032c..cd4c959c4ac 100644 --- a/AABB_tree/examples/AABB_tree/AABB_polyhedron_edge_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_polyhedron_edge_example.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include @@ -14,7 +14,7 @@ typedef K::Point_3 Point; typedef K::Triangle_3 Triangle; typedef CGAL::Polyhedron_3 Polyhedron; typedef CGAL::AABB_halfedge_graph_segment_primitive Primitive; -typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; int main() 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 5da2e15bd84..416954a8685 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 @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include @@ -15,7 +15,7 @@ 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_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; typedef Tree::Point_and_primitive_id Point_and_primitive_id; 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 6ced34c0234..fa7d6e19bf5 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 @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include @@ -17,7 +17,7 @@ typedef K::Segment_3 Segment; typedef K::Ray_3 Ray; typedef CGAL::Polyhedron_3 Polyhedron; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; -typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; typedef std::optional< Tree::Intersection_and_primitive_id::Type > Segment_intersection; typedef std::optional< Tree::Intersection_and_primitive_id::Type > Plane_intersection; diff --git a/AABB_tree/examples/AABB_tree/AABB_polyline_segment_2_example.cpp b/AABB_tree/examples/AABB_tree/AABB_polyline_segment_2_example.cpp new file mode 100644 index 00000000000..74d2f6c0321 --- /dev/null +++ b/AABB_tree/examples/AABB_tree/AABB_polyline_segment_2_example.cpp @@ -0,0 +1,71 @@ +#include +#include + +#include +#include +#include +#include +#include +#include + + +typedef CGAL::Simple_cartesian K; +typedef K::Segment_2 Segment; +typedef K::Point_2 Point; + +typedef std::vector PointRange; +typedef PointRange::const_iterator Iterator_pr; +typedef CGAL::AABB_polyline_segment_primitive_2 Primitive_pr; +typedef CGAL::AABB_traits_2 Traits_pr; +typedef CGAL::AABB_tree Tree_pr; +typedef Tree_pr::Point_and_primitive_id Point_and_primitive_id_pr; + +typedef CGAL::Polygon_2 Polygon_2; +typedef Polygon_2::const_iterator Iterator_poly; +typedef CGAL::AABB_polyline_segment_primitive_2 Primitive_poly; +typedef CGAL::AABB_traits_2 Traits_poly; +typedef CGAL::AABB_tree Tree_poly; +typedef Tree_poly::Point_and_primitive_id Point_and_primitive_id_poly; + +template +void test(AABBTree tree) { + tree.build(); + + tree.accelerate_distance_queries(); + + // counts #intersections with a segment query + Segment segment_query(Point(1.0, 0.0), Point(0.0, 7.0)); + + std::cout << tree.number_of_intersected_primitives(segment_query) + << " intersections(s) with segment" << std::endl; + + // computes the closest point from a point query + Point point_query(1.5, 3.0); + Point closest = tree.closest_point(point_query); + std::cerr << "closest point is: " << closest << std::endl; + + PPId id = tree.closest_point_and_primitive(point_query); + std::cout << id.first << "\n"; +} + + +int main() +{ + Point a(0.0, 0.0); + Point b(2.0, 1.0); + Point c(3.0, 4.0); + Point d(1.0, 6.0); + Point e(-1.0, 3.0); + + std::vector polyline = { a, b, c, d, e }; + + Polygon_2 poly(polyline.begin(), polyline.end()); + + test(Tree_poly(poly.begin(), poly.end(), poly)); + + // For a point range, the second iterator must be of the second-last point in the range. + // If it points to the end of the range, to polyline is considered to be closed. + test(Tree_pr(polyline.begin(), std::prev(polyline.end()), polyline)); + + return EXIT_SUCCESS; +} diff --git a/AABB_tree/examples/AABB_tree/AABB_ray_shooting_example.cpp b/AABB_tree/examples/AABB_tree/AABB_ray_shooting_example.cpp index e9ed0fe87c5..cd19eb94756 100644 --- a/AABB_tree/examples/AABB_tree/AABB_ray_shooting_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_ray_shooting_example.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -21,7 +21,7 @@ typedef boost::graph_traits::face_descriptor face_descriptor; typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; -typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; typedef std::optional::Type> Ray_intersection; diff --git a/AABB_tree/examples/AABB_tree/AABB_segment_2_example.cpp b/AABB_tree/examples/AABB_tree/AABB_segment_2_example.cpp new file mode 100644 index 00000000000..a599f01ff6c --- /dev/null +++ b/AABB_tree/examples/AABB_tree/AABB_segment_2_example.cpp @@ -0,0 +1,59 @@ +#include +#include + +#include +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K; + +typedef K::FT FT; +typedef K::Segment_2 Segment; +typedef K::Point_2 Point; + +typedef std::list SegmentRange; +typedef SegmentRange::const_iterator Iterator; +typedef CGAL::AABB_segment_primitive_2 Primitive; +typedef CGAL::AABB_traits_2 Traits; +typedef CGAL::AABB_tree Tree; +typedef Tree::Point_and_primitive_id Point_and_primitive_id; + +int main() +{ + Point a(0.0, 0.0); + Point b(2.0, 1.0); + Point c(3.0, 4.0); + Point d(1.0, 6.0); + Point e(-1.0, 3.0); + + std::list seg; + seg.push_back(Segment(a, b)); + seg.push_back(Segment(b, c)); + seg.push_back(Segment(c, d)); + seg.push_back(Segment(d, e)); + seg.push_back(Segment(e, a)); + + // constructs the AABB tree and the internal search tree for + // efficient distance computations. + Tree tree(seg.begin(), seg.end()); + tree.build(); + + tree.accelerate_distance_queries(); + + // counts #intersections with a segment query + Segment segment_query(Point(1.0, 0.0), Point(0.0, 7.0)); + std::cout << tree.number_of_intersected_primitives(segment_query) + << " intersections(s) with segment" << std::endl; + + // computes the closest point from a point query + Point point_query(1.5, 3.0); + Point closest = tree.closest_point(point_query); + std::cerr << "closest point is: " << closest << std::endl; + + Point_and_primitive_id id = tree.closest_point_and_primitive(point_query); + std::cout << id.second->source() << " " << id.second->target() << std::endl; + + return EXIT_SUCCESS; +} diff --git a/AABB_tree/examples/AABB_tree/AABB_segment_3_example.cpp b/AABB_tree/examples/AABB_tree/AABB_segment_3_example.cpp index 73b4d56e2d0..f3dd2ed5802 100644 --- a/AABB_tree/examples/AABB_tree/AABB_segment_3_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_segment_3_example.cpp @@ -5,8 +5,8 @@ #include #include -#include -#include +#include +#include typedef CGAL::Simple_cartesian K; @@ -17,8 +17,8 @@ typedef K::Segment_3 Segment; typedef K::Triangle_3 Triangle; typedef std::list::iterator Iterator; -typedef CGAL::AABB_segment_primitive Primitive; -typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_segment_primitive_3 Primitive; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; int main() 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/examples/AABB_tree/AABB_triangle_3_example.cpp b/AABB_tree/examples/AABB_tree/AABB_triangle_3_example.cpp index 1898ccc4edf..6b963379b3b 100644 --- a/AABB_tree/examples/AABB_tree/AABB_triangle_3_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_triangle_3_example.cpp @@ -5,20 +5,19 @@ #include #include -#include -#include +#include +#include typedef CGAL::Simple_cartesian K; typedef K::FT FT; typedef K::Ray_3 Ray; -typedef K::Line_3 Line; typedef K::Point_3 Point; typedef K::Triangle_3 Triangle; -typedef std::list::iterator Iterator; -typedef CGAL::AABB_triangle_primitive Primitive; -typedef CGAL::AABB_traits AABB_triangle_traits; +typedef std::list::const_iterator Iterator; +typedef CGAL::AABB_triangle_primitive_3 Primitive; +typedef CGAL::AABB_traits_3 AABB_triangle_traits; typedef CGAL::AABB_tree Tree; int main() 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 021cdc6270a..0a826f8c24c 100644 --- a/AABB_tree/include/CGAL/AABB_face_graph_triangle_primitive.h +++ b/AABB_tree/include/CGAL/AABB_face_graph_triangle_primitive.h @@ -48,7 +48,7 @@ namespace CGAL { * The default is `CGAL::Tag_false` (datum is not stored). *\sa `AABBPrimitive` *\sa `AABB_primitive` - *\sa `AABB_halfedge_graph_segment_primitive` + *\sa `AABB_halfedge_graph_segment_primitive` */ template < class FaceGraph, class VertexPointPMap = Default, 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 3f5481d0cfe..d8005eb4558 100644 --- a/AABB_tree/include/CGAL/AABB_halfedge_graph_segment_primitive.h +++ b/AABB_tree/include/CGAL/AABB_halfedge_graph_segment_primitive.h @@ -60,7 +60,8 @@ namespace CGAL { * * \sa `AABBPrimitive` * \sa `AABB_primitive` - * \sa `AABB_face_graph_triangle_primitive` + * \sa `AABB_face_graph_triangle_primitive` + * \sa `AABB_segment_primitive_3` * \sa \link BGLPolyGT `boost::graph_traits` \endlink */ template < class HalfedgeGraph, diff --git a/AABB_tree/include/CGAL/AABB_indexed_triangle_primitive_2.h b/AABB_tree/include/CGAL/AABB_indexed_triangle_primitive_2.h new file mode 100644 index 00000000000..400cfb6cac8 --- /dev/null +++ b/AABB_tree/include/CGAL/AABB_indexed_triangle_primitive_2.h @@ -0,0 +1,134 @@ +// Copyright (c) 2024 GeometryFactory (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sven Oesau +// + + +#ifndef CGAL_AABB_INDEXED_TRIANGLE_PRIMITIVE_2_H_ +#define CGAL_AABB_INDEXED_TRIANGLE_PRIMITIVE_2_H_ + +#include + +#include +#include + +namespace CGAL { + +namespace internal { + +template +struct Triangle_2_from_index_range_iterator_property_map { + //classical typedefs + typedef Iterator key_type; + typedef typename GeomTraits::Triangle_2 value_type; + typedef typename GeomTraits::Triangle_2 reference; + + typedef boost::readable_property_map_tag category; + typedef Triangle_2_from_index_range_iterator_property_map Self; + + Triangle_2_from_index_range_iterator_property_map() {} + Triangle_2_from_index_range_iterator_property_map(PointIterator b, PointMap& pmap) : begin(b), pmap(pmap) {} + + inline friend value_type + get(Self s, key_type it) + { + return typename GeomTraits::Construct_triangle_2()(get(s.pmap, s.begin[(*it)[0]]), get(s.pmap, s.begin[(*it)[1]]), get(s.pmap, s.begin[(*it)[2]])); + } + + PointIterator begin; + PointMap pmap; +}; + +template +struct Point_from_indexed_triangle_2_iterator_property_map { + //classical typedefs + typedef Iterator key_type; + typedef typename PointMap::value_type value_type; + typedef const value_type reference; + + typedef boost::readable_property_map_tag category; + typedef Point_from_indexed_triangle_2_iterator_property_map Self; + + Point_from_indexed_triangle_2_iterator_property_map() {} + Point_from_indexed_triangle_2_iterator_property_map(PointIterator b, PointMap &pmap) : begin(b), pmap(pmap) {} + + inline friend reference + get(Self s, key_type it) + { + return get(s.pmap, s.begin[((*it)[0])]); + } + + PointIterator begin; + PointMap pmap; +}; +}//namespace internal + + +/*! + * \ingroup PkgAABBTreeRef + * Primitive type that uses as identifier an iterator with a range of three indices as `value_type`. + * The iterator from which the primitive is built should not be invalided + * while the AABB tree holding the primitive is in use. + * + * \cgalModels{AABBPrimitive} + * + * \tparam GeomTraits is a traits class providing the nested type `Point_2` and `Triangle_2`. + * It also provides the functor `Construct_triangle_2` that has an operator taking three `Point_2` as + * parameters and returns a `Triangle_2` + * \tparam IndexIterator is a model of `ForwardIterator` with its value type being a `RandomAccessRange` of size 3 with an index type as `value_type`, e.g., `uint8_t`, `uint16_t` or int. + * \tparam PointRange is a model of `RandomAccessRange`. Its value type needs to be compatible to `PointMap` or `Point_2` in the default case. + * \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. + * The default is `CGAL::Tag_false` (datum is not stored). + * \tparam PointMap is a model of `ReadablePropertyMap` with its key type being the value type of `PointRange` and the value type being a `Point_2`. + * The default is \link Identity_property_map `CGAL::Identity_property_map`\endlink. + * + * \sa `AABBPrimitive` + * \sa `AABB_primitive` + * \sa `AABB_segment_primitive_2` + * \sa `AABB_triangle_primitive_2` + * \sa `AABB_triangle_primitive_3` + */ +template < class GeomTraits, + class IndexIterator, + class PointRange, + class CacheDatum = Tag_false, + class PointMap = Identity_property_map> +class AABB_indexed_triangle_primitive_2 +#ifndef DOXYGEN_RUNNING + : public AABB_primitive< IndexIterator, + internal::Triangle_2_from_index_range_iterator_property_map, + internal::Point_from_indexed_triangle_2_iterator_property_map, + Tag_true, + CacheDatum > +#endif +{ + typedef AABB_primitive< IndexIterator, + internal::Triangle_2_from_index_range_iterator_property_map, + internal::Point_from_indexed_triangle_2_iterator_property_map, + Tag_true, + CacheDatum > Base; +public: + ///constructor from an iterator + AABB_indexed_triangle_primitive_2(IndexIterator it, PointRange&) : Base(it) {} + + /// \internal + static typename Base::Shared_data construct_shared_data(PointRange &range, PointMap pmap = PointMap()) { + return std::make_pair( + internal::Triangle_2_from_index_range_iterator_property_map(range.begin(), pmap), + internal::Point_from_indexed_triangle_2_iterator_property_map(range.begin(), pmap)); + } +}; + +} // end namespace CGAL + +#endif // CGAL_AABB_INDEXED_TRIANGLE_PRIMITIVE_2_H_ diff --git a/AABB_tree/include/CGAL/AABB_polyhedron_segment_primitive.h b/AABB_tree/include/CGAL/AABB_polyhedron_segment_primitive.h deleted file mode 100644 index 7b8b72697f9..00000000000 --- a/AABB_tree/include/CGAL/AABB_polyhedron_segment_primitive.h +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright (c) 2009 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// -// -// Author(s) : Pierre Alliez, Stephane Tayeb -// -//****************************************************************************** -// File Description : -// -//****************************************************************************** - -#ifndef CGAL_AABB_POLYHEDRON_SEGMENT_PRIMITIVE_H_ -#define CGAL_AABB_POLYHEDRON_SEGMENT_PRIMITIVE_H_ - -#include - -#include - -#define CGAL_DEPRECATED_HEADER "" -#define CGAL_REPLACEMENT_HEADER "" -#include - -#include - -namespace CGAL { - -/// \addtogroup PkgAABBTreeRef -/// @{ - /// \deprecated This class is deprecated since \cgal 4.3, the class - /// `AABB_halfedge_graph_segment_primitive` should be used instead. - /// - /// Primitive type that wraps a halfedge handle of a - /// polyhedron, which is used as id, and allows the construction - /// of the datum on the fly. Since only the halfedge handle is - /// stored in this primitive, the polyhedron from which the - /// AABB tree is built should not be deleted while the AABB tree - /// is in use. - /// - /// \cgalModels{AABBPrimitive} - /// \tparam GeomTraits must provide a \c %Point_3 - /// type, used as \c Point, and a \c %Segment_3 type, used as \c - /// Datum and constructible from two arguments of type \c - /// Point. - /// \tparam Polyhedron must be a - /// \c CGAL::Polyhedron_3 whose points have type \c Point. - /// - /// \sa `AABBPrimitive` - /// \sa `AABB_polyhedron_triangle_primitive` - template - class AABB_polyhedron_segment_primitive - { - public: - // AABBTrianglePrimitive types - typedef typename GeomTraits::Point_3 Point; - - /// \name Types - /// @{ - - /// Geometric data type. - typedef typename GeomTraits::Segment_3 Datum; - /// Id type. - typedef typename Polyhedron::Halfedge_handle Id; - /// @} - - // Self - typedef AABB_polyhedron_segment_primitive Self; - - // Constructor - AABB_polyhedron_segment_primitive() {} - AABB_polyhedron_segment_primitive(const Id& handle) - : m_halfedge_handle(handle) { }; - AABB_polyhedron_segment_primitive(const Id* ptr) - : m_halfedge_handle(*ptr) { }; - template - AABB_polyhedron_segment_primitive( Iterator it, - std::enable_if_t< - std::is_same::value - >* =0 - ) : m_halfedge_handle(*it) { } - - AABB_polyhedron_segment_primitive(const Self& primitive) - : m_halfedge_handle(primitive.m_halfedge_handle) {} - - // Default destructor, copy constructor and assignment operator are ok - - // Returns by constructing on the fly the geometric datum wrapped by the primitive - Datum datum() const - { - const Point& a = m_halfedge_handle->vertex()->point(); - const Point& b = m_halfedge_handle->opposite()->vertex()->point(); - return Datum(a,b); // returns a 3D segment - } - - // Returns the identifier - Id& id() { return m_halfedge_handle; } - const Id& id() const { return m_halfedge_handle; } - - // Returns a point on the primitive - Point reference_point() const - { - return m_halfedge_handle->vertex()->point(); - } - - private: - // Id, here a polyhedron halfedge handle - Id m_halfedge_handle; - }; // end class AABB_polyhedron_segment_primitive - - ///@} - - template - class AABB_const_polyhedron_edge_primitive - { - public: - /// AABBTrianglePrimitive types - typedef typename GeomTraits::Point_3 Point; - typedef typename GeomTraits::Segment_3 Datum; - typedef typename Polyhedron::Halfedge_const_handle Id; - - /// Constructor - AABB_const_polyhedron_edge_primitive(const Id& handle) - : m_halfedge_handle(handle) { }; - - // Default destructor, copy constructor and assignment operator are ok - - /// Returns by constructing on the fly the geometric datum wrapped by the primitive - Datum datum() const - { - const Point& a = m_halfedge_handle->vertex()->point(); - const Point& b = m_halfedge_handle->opposite()->vertex()->point(); - return Datum(a,b); // returns a 3D segment - } - - /// Returns the identifier - const Id id() const { return m_halfedge_handle; } - - /// Returns a point on the primitive - Point reference_point() const - { - return m_halfedge_handle->vertex()->point(); - } - - private: - /// Id, here a polyhedron halfedge handle - Id m_halfedge_handle; - }; // end class AABB_const_polyhedron_edge_primitive - -} // end namespace CGAL - -#include - -#endif // CGAL_AABB_POLYHEDRON_SEGMENT_PRIMITIVE_H_ diff --git a/AABB_tree/include/CGAL/AABB_polyhedron_triangle_primitive.h b/AABB_tree/include/CGAL/AABB_polyhedron_triangle_primitive.h deleted file mode 100644 index 647ae48b415..00000000000 --- a/AABB_tree/include/CGAL/AABB_polyhedron_triangle_primitive.h +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright (c) 2009 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// -// -// Author(s) : Stéphane Tayeb, Pierre Alliez -// - -#ifndef CGAL_AABB_POLYHEDRON_TRIANGLE_PRIMITIVE_H_ -#define CGAL_AABB_POLYHEDRON_TRIANGLE_PRIMITIVE_H_ - -#include - -#include - -#define CGAL_DEPRECATED_HEADER "" -#define CGAL_REPLACEMENT_HEADER "" -#include - -#include - -namespace CGAL { - /// \ingroup PkgAABBTreeRef - /// \deprecated This class is deprecated since \cgal 4.3, the class - /// `AABB_face_graph_triangle_primitive` should be used instead. - /// - /// Primitive type that wraps a facet handle of a polyhedron, - /// which is used as id, and allows the construction of the datum on - /// the fly. Since only the facet handle is stored in this primitive, - /// the polyhedron from which the AABB tree is built should not be - /// deleted while the AABB tree is in use. - /// - /// \cgalModels{AABBPrimitive} - /// \tparam GeomTraits must provides a \c %Point_3 - /// type, used as \c Point, and a \c %Triangle_3 type, used as \c - /// Datum and constructible from three arguments of type \c - /// Point. - /// \tparam Polyhedron must be a - /// \c CGAL::Polyhedron_3 whose points have type \c Point. - /// - /// \sa `AABBPrimitive` - /// \sa `AABB_polyhedron_segment_primitive` - template - class AABB_polyhedron_triangle_primitive - { - public: - typedef typename GeomTraits::Point_3 Point; - /// \name Types - /// @{ - - /// Id type. - typedef typename Polyhedron::Facet_handle Id; - /// Geometric data type. - typedef typename GeomTraits::Triangle_3 Datum; - - /// @} - - // Self - typedef AABB_polyhedron_triangle_primitive Self; - - // Constructors - AABB_polyhedron_triangle_primitive() {} - AABB_polyhedron_triangle_primitive(const AABB_polyhedron_triangle_primitive& primitive) - { - m_facet_handle = primitive.id(); - } - AABB_polyhedron_triangle_primitive(const Id& handle) - : m_facet_handle(handle) { }; - AABB_polyhedron_triangle_primitive(const Id* ptr) - : m_facet_handle(*ptr) { }; - template - AABB_polyhedron_triangle_primitive( Iterator it, - std::enable_if_t< - std::is_same::value - >* =0 - ) : m_facet_handle(*it) { } - - - // Default destructor, copy constructor and assignment operator are ok - - // Returns by constructing on the fly the geometric datum wrapped by the primitive - Datum datum() const - { - const Point& a = m_facet_handle->halfedge()->vertex()->point(); - const Point& b = m_facet_handle->halfedge()->next()->vertex()->point(); - const Point& c = m_facet_handle->halfedge()->next()->next()->vertex()->point(); - return Datum(a,b,c); - } - - // Returns a point on the primitive - Point reference_point() const - { - return m_facet_handle->halfedge()->vertex()->point(); - } - - // Returns the identifier - const Id& id() const { return m_facet_handle; } - Id& id() { return m_facet_handle; } - - private: - /// The id, here a polyhedron facet handle - Id m_facet_handle; - }; // end class AABB_polyhedron_triangle_primitive - - template - class AABB_const_polyhedron_triangle_primitive - { - public: - /// AABBPrimitive types - typedef typename GeomTraits::Point_3 Point; - typedef typename GeomTraits::Triangle_3 Datum; - typedef typename Polyhedron::Facet_const_handle Id; - - /// Constructors - AABB_const_polyhedron_triangle_primitive(const Id& handle) - : m_facet_handle(handle) { }; - - // Default destructor, copy constructor and assignment operator are ok - - /// Returns by constructing on the fly the geometric datum wrapped by the primitive - Datum datum() const - { - const Point& a = m_facet_handle->halfedge()->vertex()->point(); - const Point& b = m_facet_handle->halfedge()->next()->vertex()->point(); - const Point& c = m_facet_handle->halfedge()->next()->next()->vertex()->point(); - return Datum(a,b,c); - } - - /// Returns a point on the primitive - Point reference_point() const - { - return m_facet_handle->halfedge()->vertex()->point(); - } - - /// Returns the identifier - Id id() const { return m_facet_handle; } - - private: - /// The id, here a polyhedron facet handle - Id m_facet_handle; - }; // end class AABB_polyhedron_triangle_primitive - - - -} // end namespace CGAL - -#include - -#endif // CGAL_AABB_POLYHEDRON_TRIANGLE_PRIMITIVE_H_ diff --git a/AABB_tree/include/CGAL/AABB_polyline_segment_primitive_2.h b/AABB_tree/include/CGAL/AABB_polyline_segment_primitive_2.h new file mode 100644 index 00000000000..696d3c9b31a --- /dev/null +++ b/AABB_tree/include/CGAL/AABB_polyline_segment_primitive_2.h @@ -0,0 +1,140 @@ +// Copyright (c) 2024 GeometryFactory. +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sven Oesau +// + + +#ifndef CGAL_AABB_POLYLINE_SEGMENT_PRIMITIVE_2_H_ +#define CGAL_AABB_POLYLINE_SEGMENT_PRIMITIVE_2_H_ + +#include + + +#include +#include + +namespace CGAL { + +namespace internal { + template + struct Segment_2_from_point_iterator_property_map { + //classical typedefs + typedef Iterator key_type; + typedef typename GeomTraits::Segment_2 value_type; + typedef typename GeomTraits::Segment_2 reference; // The segments are created on the fly, so working with references is not possible. + typedef boost::readable_property_map_tag category; + typedef Segment_2_from_point_iterator_property_map Self; + + Segment_2_from_point_iterator_property_map(Iterator b, Iterator e, PointMap& pmap) : begin(b), end(e), pmap(pmap) {} + Segment_2_from_point_iterator_property_map() {} + + inline friend reference // Cannot return reference as the Segment does not exist, only the points exist. + get(Self s, key_type it) + { + Iterator it2 = std::next(it); + if (it2 == s.end) + return typename GeomTraits::Construct_segment_2()(get(s.pmap, *it), get(s.pmap, *s.begin)); + else + return typename GeomTraits::Construct_segment_2()(get(s.pmap, *it), get(s.pmap, *it2)); + } + + Iterator begin, end; + PointMap pmap; + }; + + template + struct Point_from_iterator_property_map { + //classical typedefs + typedef Iterator key_type; + typedef typename PointMap::value_type value_type; + typedef const value_type reference; + + typedef boost::readable_property_map_tag category; + typedef Point_from_iterator_property_map Self; + + Point_from_iterator_property_map() {} + Point_from_iterator_property_map(PointMap& pmap) : pmap(pmap) {} + + inline friend reference + get(Self s, key_type it) + { + return get(s.pmap, *it); + } + + PointMap pmap; + }; +}//namespace internal + + +/*! + * \ingroup PkgAABBTreeRef + * Primitive type that uses as identifier an iterator with a 2D point as `value_type`. + * The iterator from which the primitive is built should not be invalided + * while the AABB tree holding the primitive is in use. The `Segment_2` is constructed on the fly using the `Point_2` + * the identifier is pointing to as source and the `Point_2` the next identifier is pointing to as target. + * + * \cgalModels{AABBPrimitive} + * + * \tparam GeomTraits is a traits class providing the nested type `Point_2` and `Segment_2`. + * It also provides the functor `Construct_segment_2` that has an operator taking two `Point_2` + * and returning a `Segment_2`. + * \tparam Iterator is a model of `ForwardIterator` whose value type is convertible to `GeomTraits::Point_2` + * \tparam PointRange is a model of `ConstRange` whose iterator is a model of `ForwardIterator`. Its value type needs to be the key type of `PointMap`. + * \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. + * The default is `CGAL::Tag_false` (datum is not stored). + * \tparam PointMap is a model of `ReadablePropertyMap` whose key type is the value type of `PointRange` and whose value type is `Point_2`. + * The default is \link Identity_property_map `CGAL::Identity_property_map`\endlink. + * + * \sa `AABBPrimitive` + * \sa `AABB_primitive` + * \sa `AABB_segment_primitive_2` + * \sa `AABB_segment_primitive_3` + * \sa `AABB_halfedge_graph_segment_primitive` + */ +template < class GeomTraits, + class Iterator, + class PointRange, + class CacheDatum = Tag_false, + class PointMap = Identity_property_map> +class AABB_polyline_segment_primitive_2 +#ifndef DOXYGEN_RUNNING + : public AABB_primitive< Iterator, + internal::Segment_2_from_point_iterator_property_map, + internal::Point_from_iterator_property_map, + Tag_true, + CacheDatum > +#endif +{ + typedef internal::Segment_2_from_point_iterator_property_map Segment_map; + typedef internal::Point_from_iterator_property_map Point_primitive_map; + typedef AABB_primitive< Iterator, + Segment_map, + Point_primitive_map, + Tag_true, + CacheDatum > Base; + +public: + AABB_polyline_segment_primitive_2(Iterator it, PointRange& poly, PointMap pmap = PointMap()) + : Base(it,Segment_map(poly.begin(), poly.end(), pmap), Point_primitive_map(pmap)) + {} + + /// \internal + static typename Base::Shared_data construct_shared_data(PointRange& range, PointMap pmap = PointMap()) { + return std::make_pair(internal::Segment_2_from_point_iterator_property_map(range.begin(), range.end(), pmap), internal::Point_from_iterator_property_map(pmap)); + } +}; + +} // end namespace CGAL + + +#endif // CGAL_AABB_POLYLINE_SEGMENT_PRIMITIVE_2_H_ diff --git a/AABB_tree/include/CGAL/AABB_primitive.h b/AABB_tree/include/CGAL/AABB_primitive.h index 4c58b83f4db..de71fb89b8e 100644 --- a/AABB_tree/include/CGAL/AABB_primitive.h +++ b/AABB_tree/include/CGAL/AABB_primitive.h @@ -71,10 +71,12 @@ public: * it is constructed on the fly to reduce the memory footprint. * The default is `CGAL::Tag_false` (datum is not stored). * - * \sa `AABB_segment_primitive` - * \sa `AABB_triangle_primitive` - * \sa `AABB_halfedge_graph_segment_primitive` - * \sa `AABB_face_graph_triangle_primitive` + * \sa `AABB_segment_primitive_2` + * \sa `AABB_segment_primitive_3` + * \sa `AABB_triangle_primitive_2` + * \sa `AABB_triangle_primitive_3` + * \sa `AABB_halfedge_graph_segment_primitive` + * \sa `AABB_face_graph_triangle_primitive` */ template < class Id, class ObjectPropertyMap, @@ -251,4 +253,3 @@ public: #include #endif // CGAL_AABB_PRIMITIVE_H - diff --git a/AABB_tree/include/CGAL/AABB_segment_primitive.h b/AABB_tree/include/CGAL/AABB_segment_primitive.h index f13523ba40c..2ecb294c83c 100644 --- a/AABB_tree/include/CGAL/AABB_segment_primitive.h +++ b/AABB_tree/include/CGAL/AABB_segment_primitive.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 INRIA Sophia-Antipolis (France). +// Copyright (c) 2024 INRIA Sophia-Antipolis (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org). @@ -11,91 +11,38 @@ // Author(s) : Sebastien Loriot // - #ifndef CGAL_AABB_SEGMENT_PRIMITIVE_H_ #define CGAL_AABB_SEGMENT_PRIMITIVE_H_ #include -#include +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include -#include -#include +#ifndef CGAL_NO_DEPRECATED_CODE + +#include + +/// \file AABB_segment_primitive.h namespace CGAL { -namespace internal { - template - struct Source_of_segment_3_iterator_property_map{ - //classical typedefs - typedef Iterator key_type; - typedef typename GeomTraits::Point_3 value_type; - // typedef decltype( - // std::declval()( - // std::declval())) reference; - typedef decltype( - typename GeomTraits::Construct_source_3()( - *std::declval())) reference; - typedef boost::readable_property_map_tag category; - typedef Source_of_segment_3_iterator_property_map Self; - inline friend reference - get(Self, key_type it) - { - return typename GeomTraits::Construct_source_3()( *it ); - } - }; -}//namespace internal +/// \addtogroup PkgAABBTreeRef +/// @{ +/// template alias for backward compatibility -/*! - * \ingroup PkgAABBTreeRef - * Primitive type that uses as identifier an iterator with a 3D segment as `value_type`. - * The iterator from which the primitive is built should not be invalided - * while the AABB tree holding the primitive is in use. - * - * \cgalModels{AABBPrimitive} - * - * \tparam GeomTraits is a traits class providing the nested type `Point_3` and `Segment_3`. - * It also provides the functor `Construct_source_3` that has an operator taking a `Segment_3` - * and returning its source as a type convertible to `Point_3`. - * \tparam Iterator is a model of `ForwardIterator` with its value type convertible to `GeomTraits::Segment_3` - * \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. - * The default is `CGAL::Tag_false` (datum is not stored). - * - * \sa `AABBPrimitive` - * \sa `AABB_primitive` - * \sa `AABB_triangle_primitive` - * \sa `AABB_halfedge_graph_segment_primitive` - * \sa `AABB_face_graph_triangle_primitive` - */ template < class GeomTraits, class Iterator, class CacheDatum=Tag_false> -class AABB_segment_primitive -#ifndef DOXYGEN_RUNNING - : public AABB_primitive< Iterator, - Input_iterator_property_map, - internal::Source_of_segment_3_iterator_property_map, - Tag_false, - CacheDatum > -#endif -{ - typedef AABB_primitive< Iterator, - Input_iterator_property_map, - internal::Source_of_segment_3_iterator_property_map, - Tag_false, - CacheDatum > Base; -public: - ///constructor from an iterator - AABB_segment_primitive(Iterator it) : Base(it){} -}; +using AABB_segment_primitive = AABB_segment_primitive_3; -} // end namespace CGAL +///@} -#include +} // CGAL namespace -#endif // CGAL_AABB_SEGMENT_PRIMITIVE_H_ +#endif // CGAL_NO_DEPRECATED_CODE +#endif //CGAL_AABB_SEGMENT_PRIMITIVE_H_ diff --git a/AABB_tree/include/CGAL/AABB_segment_primitive_2.h b/AABB_tree/include/CGAL/AABB_segment_primitive_2.h new file mode 100644 index 00000000000..71e76f72cde --- /dev/null +++ b/AABB_tree/include/CGAL/AABB_segment_primitive_2.h @@ -0,0 +1,99 @@ +// Copyright (c) 2012 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sebastien Loriot +// + + +#ifndef CGAL_AABB_SEGMENT_PRIMITIVE_2_H_ +#define CGAL_AABB_SEGMENT_PRIMITIVE_2_H_ + +#include + +#include + +#include +#include + +namespace CGAL { + +namespace internal { + template + struct Source_of_segment_2_iterator_property_map{ + //classical typedefs + typedef Iterator key_type; + typedef typename GeomTraits::Point_2 value_type; + // typedef decltype( + // std::declval()( + // std::declval())) reference; + typedef decltype( + typename GeomTraits::Construct_source_2()( + *std::declval())) reference; + typedef boost::readable_property_map_tag category; + typedef Source_of_segment_2_iterator_property_map Self; + + inline friend reference + get(Self, key_type it) + { + return typename GeomTraits::Construct_source_2()( *it ); + } + }; +}//namespace internal + + +/*! + * \ingroup PkgAABBTreeRef + * Primitive type that uses as identifier an iterator with a 2D segment as `value_type`. + * The iterator from which the primitive is built should not be invalided + * while the AABB tree holding the primitive is in use. + * + * \cgalModels{AABBPrimitive} + * + * \tparam GeomTraits is a traits class providing the nested type `Point_2` and `Segment_2`. + * It also provides the functor `Construct_source_2` that has an operator taking a `Segment_2` + * and returning its source as a type convertible to `Point_2`. + * \tparam Iterator is a model of `ForwardIterator` with its value type convertible to `GeomTraits::Segment_2` + * \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. + * The default is `CGAL::Tag_false` (datum is not stored). + * + * \sa `AABBPrimitive` + * \sa `AABB_primitive` + * \sa `AABB_segment_primitive_3` + * \sa `AABB_triangle_primitive_2` + */ +template < class GeomTraits, + class Iterator, + class CacheDatum=Tag_false> +class AABB_segment_primitive_2 +#ifndef DOXYGEN_RUNNING + : public AABB_primitive< Iterator, + Input_iterator_property_map, + internal::Source_of_segment_2_iterator_property_map, + Tag_false, + CacheDatum > +#endif +{ + typedef AABB_primitive< Iterator, + Input_iterator_property_map, + internal::Source_of_segment_2_iterator_property_map, + Tag_false, + CacheDatum > Base; +public: + ///constructor from an iterator + AABB_segment_primitive_2(Iterator it) : Base(it){} +}; + +} // end namespace CGAL + +#include + +#endif // CGAL_AABB_SEGMENT_PRIMITIVE_2_H_ diff --git a/AABB_tree/include/CGAL/AABB_segment_primitive_3.h b/AABB_tree/include/CGAL/AABB_segment_primitive_3.h new file mode 100644 index 00000000000..a1af115ae28 --- /dev/null +++ b/AABB_tree/include/CGAL/AABB_segment_primitive_3.h @@ -0,0 +1,100 @@ +// Copyright (c) 2012 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sebastien Loriot +// + + +#ifndef CGAL_AABB_SEGMENT_PRIMITIVE_3_H_ +#define CGAL_AABB_SEGMENT_PRIMITIVE_3_H_ + +#include + +#include + +#include +#include + +namespace CGAL { + +namespace internal { + template + struct Source_of_segment_3_iterator_property_map{ + //classical typedefs + typedef Iterator key_type; + typedef typename GeomTraits::Point_3 value_type; + // typedef decltype( + // std::declval()( + // std::declval())) reference; + typedef decltype( + typename GeomTraits::Construct_source_3()( + *std::declval())) reference; + typedef boost::readable_property_map_tag category; + typedef Source_of_segment_3_iterator_property_map Self; + + inline friend reference + get(Self, key_type it) + { + return typename GeomTraits::Construct_source_3()( *it ); + } + }; +}//namespace internal + + +/*! + * \ingroup PkgAABBTreeRef + * Primitive type that uses as identifier an iterator with a 3D segment as `value_type`. + * The iterator from which the primitive is built should not be invalided + * while the AABB tree holding the primitive is in use. + * + * \cgalModels{AABBPrimitive} + * + * \tparam GeomTraits is a traits class providing the nested type `Point_3` and `Segment_3`. + * It also provides the functor `Construct_source_3` that has an operator taking a `Segment_3` + * and returning its source as a type convertible to `Point_3`. + * \tparam Iterator is a model of `ForwardIterator` with its value type convertible to `GeomTraits::Segment_3` + * \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. + * The default is `CGAL::Tag_false` (datum is not stored). + * + * \sa `AABBPrimitive` + * \sa `AABB_primitive` + * \sa `AABB_segment_primitive_2` + * \sa `AABB_triangle_primitive_3` + * \sa `AABB_halfedge_graph_segment_primitive` + */ +template < class GeomTraits, + class Iterator, + class CacheDatum=Tag_false> +class AABB_segment_primitive_3 +#ifndef DOXYGEN_RUNNING + : public AABB_primitive< Iterator, + Input_iterator_property_map, + internal::Source_of_segment_3_iterator_property_map, + Tag_false, + CacheDatum > +#endif +{ + typedef AABB_primitive< Iterator, + Input_iterator_property_map, + internal::Source_of_segment_3_iterator_property_map, + Tag_false, + CacheDatum > Base; +public: + ///constructor from an iterator + AABB_segment_primitive_3(Iterator it) : Base(it){} +}; + +} // end namespace CGAL + +#include + +#endif // CGAL_AABB_SEGMENT_PRIMITIVE_3_H_ diff --git a/AABB_tree/include/CGAL/AABB_traits.h b/AABB_tree/include/CGAL/AABB_traits.h index f7d52f9968c..9b70f622c76 100644 --- a/AABB_tree/include/CGAL/AABB_traits.h +++ b/AABB_tree/include/CGAL/AABB_traits.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 INRIA Sophia-Antipolis (France). +// Copyright (c) 2024 INRIA Sophia-Antipolis (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org). @@ -14,524 +14,35 @@ #ifndef CGAL_AABB_TRAITS_H_ #define CGAL_AABB_TRAITS_H_ +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include + +#ifndef CGAL_NO_DEPRECATED_CODE + #include -#include - -#include -#include -#include -#include -#include -#include -#include - - -#include +#include /// \file AABB_traits.h -namespace CGAL { -namespace internal{ namespace AABB_tree { +namespace CGAL +{ -template -struct Remove_optional { typedef T type; }; -template -struct Remove_optional< ::std::optional > { typedef T type; }; - -//helper controlling whether extra data should be stored in the AABB_tree traits class -template ::value> -struct AABB_traits_base; - -template -struct AABB_traits_base{}; - -template -struct AABB_traits_base{ - typename Primitive::Shared_data m_primitive_data; - - template - void set_shared_data(T&& ... t){ - m_primitive_data=Primitive::construct_shared_data(std::forward(t)...); - } - const typename Primitive::Shared_data& shared_data() const {return m_primitive_data;} -}; - -// AABB_traits_base_2 brings in the Intersection_distance predicate, -// if GeomTraits is a model RayIntersectionGeomTraits. -template ::value> -struct AABB_traits_base_2; - -template -struct AABB_traits_base_2{}; - -template -struct AABB_traits_base_2{ - typedef typename GeomTraits::Ray_3 Ray_3; - typedef typename GeomTraits::Point_3 Point_3; - typedef typename GeomTraits::Vector_3 Vector_3; - 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 - // 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_3 Bounding_box; - - struct Intersection_distance { - std::optional operator()(const Ray_3& 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 - = 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); - - for(int i = 0; i < 3; ++i, ++source_iter, ++direction_iter) { - if(*direction_iter == 0) { - if((*source_iter < (bbox.min)(i)) || (*source_iter > (bbox.max)(i))) { - return std::nullopt; - } - } else { - FT t1 = ((bbox.min)(i) - *source_iter) / *direction_iter; - FT t2 = ((bbox.max)(i) - *source_iter) / *direction_iter; - - t_near = (std::max)(t_near, (std::min)(t1, t2)); - t_far = (std::min)(t_far, (std::max)(t1, t2)); - - // if(t1 > t2) - // std::swap(t1, t2); - // if(t1 > t_near) - // t_near = t1; - // if(t2 < t_far) - // t_far = t2; - - if(t_near > t_far || t_far < FT(0.)) - return std::nullopt; - } - } - - if(t_near < FT(0.)) - return FT(0.); - else - return t_near; - } - }; - - Intersection_distance intersection_distance_object() const { return Intersection_distance(); } -}; - -} } //end of namespace internal::AABB_tree /// \addtogroup PkgAABBTreeRef /// @{ -// forward declaration -template< typename AABBTraits> -class AABB_tree; +/// template alias for backward compatibility +template +using AABB_traits = AABB_traits_3; +///@} -/// This traits class handles any type of 3D geometric -/// primitives provided that the proper intersection tests and -/// constructions are implemented. It handles points, rays, lines and -/// segments as query types for intersection detection and -/// computations, and it handles points as query type for distance -/// queries. -/// -/// \cgalModels{AABBTraits,AABBRayIntersectionTraits} -/// -/// \tparam GeomTraits must be a model of the concept \ref AABBGeomTraits, -/// and provide the geometric types as well as the intersection tests and computations. -/// \tparam Primitive provide the type of primitives stored in the AABB_tree. -/// It is a model of the concept `AABBPrimitive` or `AABBPrimitiveWithSharedData`. -/// -/// \tparam BboxMap must be a model of `ReadablePropertyMap` that has as key type a primitive id, -/// and as value type a `Bounding_box`. -/// If the type is `Default` the `Datum` must have the -/// member function `bbox()` that returns the bounding box of the primitive. -/// -/// If the argument `GeomTraits` is a model of the concept \ref -/// AABBRayIntersectionGeomTraits, this class is also a model of \ref -/// AABBRayIntersectionTraits. -/// -/// \sa `AABBTraits` -/// \sa `AABB_tree` -/// \sa `AABBPrimitive` -/// \sa `AABBPrimitiveWithSharedData` +} // namespace CGAL - template -class AABB_traits -#ifndef DOXYGEN_RUNNING -: public internal::AABB_tree::AABB_traits_base, - public internal::AABB_tree::AABB_traits_base_2 -#endif -{ - typedef typename CGAL::Object Object; -public: - typedef GeomTraits Geom_traits; - - typedef AABB_traits AT; - // AABBTraits concept types - typedef typename GeomTraits::FT FT; - typedef AABBPrimitive Primitive; - - typedef typename std::pair Object_and_primitive_id; - - typedef typename std::pair Point_and_primitive_id; - - /// `Intersection_and_primitive_id::%Type::first_type` is found according to - /// the result type of `GeomTraits::Intersect_3::operator()`. If it is - /// `std::optional` then it is `T`, and the result type otherwise. - template - struct Intersection_and_primitive_id { - typedef decltype( - std::declval()( - std::declval(), - std::declval())) Intersection_type; - - typedef std::pair< - typename internal::AABB_tree::Remove_optional::type, - typename Primitive::Id > Type; - }; - - // types for search tree - /// \name Types - /// @{ - - /// Point query type. - typedef typename GeomTraits::Point_3 Point_3; - - /// additional types for the search tree, required by the RangeSearchTraits concept - /// \bug This is not documented for now in the AABBTraits concept. - typedef typename GeomTraits::Iso_cuboid_3 Iso_cuboid_3; - - /// Bounding box type. - typedef typename CGAL::Bbox_3 Bounding_box; - - /// @} - - typedef typename GeomTraits::Sphere_3 Sphere_3; - 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_center_3 Construct_center_3; - typedef typename GeomTraits::Compute_squared_radius_3 Compute_squared_radius_3; - typedef typename GeomTraits::Construct_min_vertex_3 Construct_min_vertex_3; - typedef typename GeomTraits::Construct_max_vertex_3 Construct_max_vertex_3; - typedef typename GeomTraits::Construct_iso_cuboid_3 Construct_iso_cuboid_3; - - BboxMap bbm; - - /// Default constructor. - AABB_traits() { } - - AABB_traits(BboxMap bbm) - : bbm(bbm) - {} - - - typedef typename GeomTraits::Compute_squared_distance_3 Squared_distance; - Squared_distance squared_distance_object() const { return GeomTraits().compute_squared_distance_3_object(); } - - typedef typename GeomTraits::Equal_3 Equal_3; - Equal_3 equal_3_object() const { return GeomTraits().equal_3_object(); } - - /** - * @internal - * @brief Sorts [first,beyond[ - * @param first iterator on first element - * @param beyond iterator on beyond element - * @param bbox the bounding box of [first,beyond[ - * - * Sorts the range defined by [first,beyond[. Sort is achieved on bbox longest - * axis, using the comparison function `_less_than` (dim in {x,y,z}) - */ - class Split_primitives - { - typedef AABB_traits Traits; - const Traits& m_traits; - public: - Split_primitives(const AABB_traits& traits) - : m_traits(traits) {} - - typedef void result_type; - template - void operator()(PrimitiveIterator first, - PrimitiveIterator beyond, - const typename AT::Bounding_box& bbox) const - { - PrimitiveIterator middle = first + (beyond - first)/2; - switch(Traits::longest_axis(bbox)) - { - case AT::CGAL_AXIS_X: // sort along x - std::nth_element(first, middle, beyond, [this](const Primitive& p1, const Primitive& p2){ return Traits::less_x(p1, p2, this->m_traits); }); - break; - case AT::CGAL_AXIS_Y: // sort along y - std::nth_element(first, middle, beyond, [this](const Primitive& p1, const Primitive& p2){ return Traits::less_y(p1, p2, this->m_traits); }); - break; - case AT::CGAL_AXIS_Z: // sort along z - std::nth_element(first, middle, beyond, [this](const Primitive& p1, const Primitive& p2){ return Traits::less_z(p1, p2, this->m_traits); }); - break; - default: - CGAL_error(); - } - } - }; - - Split_primitives split_primitives_object() const {return Split_primitives(*this);} - - - /* - * Computes the bounding box of a set of primitives - * @param first an iterator on the first primitive - * @param beyond an iterator on the past-the-end primitive - * @return the bounding box of the primitives of the iterator range - */ - class Compute_bbox { - const AABB_traits& m_traits; - public: - Compute_bbox(const AABB_traits& traits) - :m_traits (traits) {} - - template - typename AT::Bounding_box operator()(ConstPrimitiveIterator first, - ConstPrimitiveIterator beyond) const - { - typename AT::Bounding_box bbox = m_traits.compute_bbox(*first,m_traits.bbm); - for(++first; first != beyond; ++first) - { - bbox = bbox + m_traits.compute_bbox(*first,m_traits.bbm); - } - return bbox; - } - - }; - - Compute_bbox compute_bbox_object() const {return Compute_bbox(*this);} - - /// \brief Function object using `GeomTraits::Do_intersect`. - /// In the case the query is a `CGAL::AABB_tree`, the `do_intersect()` - /// function of this tree is used. - class Do_intersect { - const AABB_traits& m_traits; - public: - Do_intersect(const AABB_traits& traits) - :m_traits(traits) {} - - template - bool operator()(const Query& q, const Bounding_box& bbox) const - { - return GeomTraits().do_intersect_3_object()(q, bbox); - } - - template - bool operator()(const Query& q, const Primitive& pr) const - { - return GeomTraits().do_intersect_3_object()(q, internal::Primitive_helper::get_datum(pr,m_traits)); - } - - // intersection with AABB-tree - template - bool operator()(const CGAL::AABB_tree& other_tree, const Primitive& pr) const - { - return other_tree.do_intersect( internal::Primitive_helper::get_datum(pr,m_traits) ); - } - - template - bool operator()(const CGAL::AABB_tree& other_tree, const Bounding_box& bbox) const - { - return other_tree.do_intersect(bbox); - } - }; - - Do_intersect do_intersect_object() const {return Do_intersect(*this);} - - - class Intersection { - const AABB_traits& m_traits; - public: - Intersection(const AABB_traits& traits) - :m_traits(traits) {} - template - std::optional< typename Intersection_and_primitive_id::Type > - operator()(const Query& query, const typename AT::Primitive& primitive) const { - auto inter_res = GeomTraits().intersect_3_object()(query, internal::Primitive_helper::get_datum(primitive,m_traits)); - if (!inter_res) - return std::nullopt; - return std::make_optional( std::make_pair(*inter_res, primitive.id()) ); - } - }; - - Intersection intersection_object() const {return Intersection(*this);} - - - // This should go down to the GeomTraits, i.e. the kernel - class Closest_point { - typedef typename AT::Point_3 Point; - typedef typename AT::Primitive Primitive; - const AABB_traits& m_traits; - public: - Closest_point(const AABB_traits& traits) - : m_traits(traits) {} - - - Point operator()(const Point& p, const Primitive& pr, const Point& bound) const - { - GeomTraits geom_traits; - Point closest_point = geom_traits.construct_projected_point_3_object()( - internal::Primitive_helper::get_datum(pr,m_traits), p); - - return (geom_traits.compare_distance_3_object()(p, closest_point, bound) == LARGER) ? - bound : closest_point; - } - }; - - // This should go down to the GeomTraits, i.e. the kernel - // and the internal implementation should change its name from - // do_intersect to something like does_contain (this is what we compute, - // this is not the same do_intersect as the spherical kernel) - class Compare_distance { - typedef typename AT::Point_3 Point; - typedef typename AT::FT FT; - typedef typename AT::Primitive Primitive; - public: - CGAL::Comparison_result operator()(const Point& p, const Bounding_box& bb, const Point& bound, Tag_true) const - { - return GeomTraits().do_intersect_3_object() - (GeomTraits().construct_sphere_3_object() - (p, GeomTraits().compute_squared_distance_3_object()(p, bound)), bb,true)? - CGAL::SMALLER : CGAL::LARGER; - } - - CGAL::Comparison_result operator()(const Point& p, const Bounding_box& bb, const Point& bound, Tag_false) const - { - return GeomTraits().do_intersect_3_object() - (GeomTraits().construct_sphere_3_object() - (p, GeomTraits().compute_squared_distance_3_object()(p, bound)), bb)? - CGAL::SMALLER : CGAL::LARGER; - } - - CGAL::Comparison_result operator()(const Point& p, const Bounding_box& bb, const Point& bound) const - { - return (*this)(p, bb, bound, Boolean_tag::value>()); - } - - // The following functions seem unused...? - template - CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const Point& bound) const - { - return GeomTraits().do_intersect_3_object() - (GeomTraits().construct_sphere_3_object() - (p, GeomTraits().compute_squared_distance_3_object()(p, bound)), pr)? - CGAL::SMALLER : CGAL::LARGER; - } - - template - CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const FT& sq_distance) const - { - return GeomTraits().do_intersect_3_object() - (GeomTraits().construct_sphere_3_object()(p, sq_distance), - pr) ? - CGAL::SMALLER : - CGAL::LARGER; - } - }; - - Closest_point closest_point_object() const {return Closest_point(*this);} - Compare_distance compare_distance_object() const {return Compare_distance();} - - typedef enum { CGAL_AXIS_X = 0, - CGAL_AXIS_Y = 1, - CGAL_AXIS_Z = 2} Axis; - - static Axis longest_axis(const Bounding_box& bbox); - -private: - /** - * @brief Computes bounding box of one primitive - * @param pr the primitive - * @return the bounding box of the primitive \c pr - */ - template - Bounding_box compute_bbox(const Primitive& pr, const PM&)const - { - return get(bbm, pr.id()); - } - - Bounding_box compute_bbox(const Primitive& pr, const Default&)const - { - return internal::Primitive_helper::get_datum(pr,*this).bbox(); - } - - /// Comparison functions - static bool less_x(const Primitive& pr1, const Primitive& pr2,const AABB_traits& traits) - { - return GeomTraits().less_x_3_object()( internal::Primitive_helper::get_reference_point(pr1,traits), - internal::Primitive_helper::get_reference_point(pr2,traits) ); - } - static bool less_y(const Primitive& pr1, const Primitive& pr2,const AABB_traits& traits) - { - return GeomTraits().less_y_3_object()( internal::Primitive_helper::get_reference_point(pr1,traits), - internal::Primitive_helper::get_reference_point(pr2,traits) ); - } - static bool less_z(const Primitive& pr1, const Primitive& pr2,const AABB_traits& traits) - { - return GeomTraits().less_z_3_object()( internal::Primitive_helper::get_reference_point(pr1,traits), - internal::Primitive_helper::get_reference_point(pr2,traits) ); - } - -}; // end class AABB_traits - - -//------------------------------------------------------- -// Private methods -//------------------------------------------------------- - template - typename AABB_traits::Axis - AABB_traits::longest_axis(const Bounding_box& bbox) -{ - const double dx = bbox.xmax() - bbox.xmin(); - const double dy = bbox.ymax() - bbox.ymin(); - const double dz = bbox.zmax() - bbox.zmin(); - - if(dx>=dy) - { - if(dx>=dz) - { - return CGAL_AXIS_X; - } - else // dz>dx and dx>=dy - { - return CGAL_AXIS_Z; - } - } - else // dy>dx - { - if(dy>=dz) - { - return CGAL_AXIS_Y; - } - else // dz>dy and dy>dx - { - return CGAL_AXIS_Z; - } - } -} - -/// @} - -} // end namespace CGAL - -#include +#endif // CGAL_NO_DEPRECATED_CODE #endif // CGAL_AABB_TRAITS_H_ diff --git a/AABB_tree/include/CGAL/AABB_traits_2.h b/AABB_tree/include/CGAL/AABB_traits_2.h new file mode 100644 index 00000000000..fe863e2d008 --- /dev/null +++ b/AABB_tree/include/CGAL/AABB_traits_2.h @@ -0,0 +1,504 @@ +// Copyright (c) 2009 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Stéphane Tayeb, Pierre Alliez, Camille Wormser +// + +#ifndef CGAL_AABB_TRAITS_2_H_ +#define CGAL_AABB_TRAITS_2_H_ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/// \file AABB_traits_2.h + +namespace CGAL { + +namespace internal{ namespace AABB_tree { + + +// AABB_traits_intersection_base_2 brings in the Intersection_distance predicate, +// if GeomTraits is a model RayIntersectionGeomTraits. +template ::value> +struct AABB_traits_intersection_base_2; + +template +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; + typedef typename GeomTraits::Cartesian_const_iterator_2 Cartesian_const_iterator; + typedef typename GeomTraits::Construct_cartesian_const_iterator_2 Construct_cartesian_const_iterator; + + 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(); + } + + static Construct_vector construct_vector_object() { + return GeomTraits().construct_vector_2_object(); + } + + // Defining Bounding_box and other types from the full AABB_traits_2 + // here 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 + FT t_far = DBL_MAX; + + const Construct_cartesian_const_iterator construct_cartesian_const_iterator_2 + = GeomTraits().construct_cartesian_const_iterator_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 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) { + if((*source_iter < (bbox.min)(i)) || (*source_iter > (bbox.max)(i))) { + return std::nullopt; + } + } else { + FT t1 = ((bbox.min)(i) - *source_iter) / *direction_iter; + FT t2 = ((bbox.max)(i) - *source_iter) / *direction_iter; + + t_near = (std::max)(t_near, (std::min)(t1, t2)); + t_far = (std::min)(t_far, (std::max)(t1, t2)); + + if(t_near > t_far || t_far < FT(0.)) + return std::nullopt; + } + } + + if(t_near < FT(0.)) + return FT(0.); + else + return t_near; + } + }; + + Intersection_distance intersection_distance_object() const { return Intersection_distance(); } +}; + +} } //end of namespace internal::AABB_tree + +/// \addtogroup PkgAABBTreeRef +/// @{ + +// forward declaration +template< typename AABBTraits> +class AABB_tree; + + +/// This traits class handles any type of 2D geometric +/// primitives provided that the proper intersection tests and +/// constructions are implemented. It handles points, rays, lines and +/// segments as query types for intersection detection and +/// computations, and it handles points as query type for distance +/// queries. +/// +/// \cgalModels{AABBTraits,AABBRayIntersectionTraits} +/// +/// \tparam GeomTraits must be a model of the concept \ref AABBGeomTraits_2, +/// and provide the geometric types as well as the intersection tests and computations. +/// \tparam Primitive provide the type of primitives stored in the AABB_tree. +/// It is a model of the concept `AABBPrimitive` or `AABBPrimitiveWithSharedData`. +/// +/// \tparam BboxMap must be a model of `ReadablePropertyMap` that has as key type a primitive id, +/// and as value type a `Bounding_box`. +/// If the type is `Default` the `Datum` must have the +/// member function `bbox()` that returns the bounding box of the primitive. +/// +/// If the argument `GeomTraits` is a model of the concept \ref +/// AABBRayIntersectionGeomTraits_2, this class is also a model of \ref +/// AABBRayIntersectionTraits. +/// +/// \sa `AABBTraits` +/// \sa `AABB_tree` +/// \sa `AABBPrimitive` +/// \sa `AABBPrimitiveWithSharedData` + +template +class AABB_traits_2 +#ifndef DOXYGEN_RUNNING +: public internal::AABB_tree::AABB_traits_base, + public internal::AABB_tree::AABB_traits_intersection_base_2, + public Search_traits_2 +#endif +{ + typedef typename CGAL::Object Object; + typedef GeomTraits Geom_traits; +public: + + typedef AABB_traits_2 AT; + // AABBTraits concept types + typedef typename GeomTraits::FT FT; + typedef AABBPrimitive Primitive; + + typedef typename std::pair Object_and_primitive_id; + + typedef typename std::pair Point_and_primitive_id; + + /// `Intersection_and_primitive_id::%Type::first_type` is found according to + /// the result type of `GeomTraits::Intersect_2::operator()`. If it is + /// `std::optional` then it is `T`, and the result type otherwise. + template + struct Intersection_and_primitive_id { + typedef decltype( + std::declval()( + std::declval(), + std::declval())) Intersection_type; + + typedef std::pair< + typename internal::Remove_optional::type, + typename Primitive::Id > Type; + }; + + // types for search tree + /// \name Types + /// @{ + + /// + /// point type + /// + typedef typename GeomTraits::Point_2 Point; + + /// additional types for the search tree, required by the RangeSearchTraits concept + /// \bug This is not documented for now in the AABBTraits concept. + typedef typename GeomTraits::Iso_rectangle_2 Iso_rectangle_2; + + /// Bounding box type. + typedef typename CGAL::Bbox_2 Bounding_box; + + /// @} + + typedef typename GeomTraits::Circle_2 Circle_2; + 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_center_2 Construct_center_2; + typedef typename GeomTraits::Compute_squared_radius_2 Compute_squared_radius_2; + typedef typename GeomTraits::Construct_min_vertex_2 Construct_min_vertex_2; + typedef typename GeomTraits::Construct_max_vertex_2 Construct_max_vertex_2; + typedef typename GeomTraits::Construct_iso_rectangle_2 Construct_iso_rectangle_2; + + BboxMap bbm; + + /// Default constructor. + AABB_traits_2() { } + + AABB_traits_2(BboxMap bbm) + : bbm(bbm) + {} + + + typedef typename GeomTraits::Compute_squared_distance_2 Squared_distance; + Squared_distance squared_distance_object() const { return GeomTraits().compute_squared_distance_2_object(); } + + typedef typename GeomTraits::Equal_2 Equal; + Equal equal_object() const { return GeomTraits().equal_2_object(); } + + /** + * @internal + * @brief Sorts [first,beyond[ + * @param first iterator on first element + * @param beyond iterator on beyond element + * @param bbox the bounding box of [first,beyond[ + * + * Sorts the range defined by [first,beyond[. Sort is achieved on bbox longest + * axis, using the comparison function `_less_than` (dim in {x,y,z}) + */ + class Split_primitives + { + typedef AABB_traits_2 Traits; + const Traits& m_traits; + public: + Split_primitives(const AABB_traits_2& traits) + : m_traits(traits) {} + + typedef void result_type; + template + void operator()(PrimitiveIterator first, + PrimitiveIterator beyond, + const typename AT::Bounding_box& bbox) const + { + PrimitiveIterator middle = first + (beyond - first)/2; + switch(Traits::longest_axis(bbox)) + { + case AT::CGAL_AXIS_X: // sort along x + std::nth_element(first, middle, beyond, [this](const Primitive& p1, const Primitive& p2){ return Traits::less_x(p1, p2, this->m_traits); }); + break; + case AT::CGAL_AXIS_Y: // sort along y + std::nth_element(first, middle, beyond, [this](const Primitive& p1, const Primitive& p2){ return Traits::less_y(p1, p2, this->m_traits); }); + break; + default: + CGAL_error(); + } + } + }; + + Split_primitives split_primitives_object() const {return Split_primitives(*this);} + + + /* + * Computes the bounding box of a set of primitives + * @param first an iterator on the first primitive + * @param beyond an iterator on the past-the-end primitive + * @return the bounding box of the primitives of the iterator range + */ + class Compute_bbox { + const AABB_traits_2& m_traits; + public: + Compute_bbox(const AABB_traits_2& traits) + :m_traits (traits) {} + + template + typename AT::Bounding_box operator()(ConstPrimitiveIterator first, + ConstPrimitiveIterator beyond) const + { + typename AT::Bounding_box bbox = m_traits.compute_bbox(*first,m_traits.bbm); + for(++first; first != beyond; ++first) + { + bbox = bbox + m_traits.compute_bbox(*first,m_traits.bbm); + } + return bbox; + } + + }; + + Compute_bbox compute_bbox_object() const {return Compute_bbox(*this);} + + /// \brief Function object using `GeomTraits::Do_intersect`. + /// In the case the query is a `CGAL::AABB_tree`, the `do_intersect()` + /// function of this tree is used. + class Do_intersect { + const AABB_traits_2& m_traits; + public: + Do_intersect(const AABB_traits_2& traits) + :m_traits(traits) {} + + template + bool operator()(const Query& q, const Bounding_box& bbox) const + { + return GeomTraits().do_intersect_2_object()(q, bbox); + } + + template + bool operator()(const Query& q, const Primitive& pr) const + { + return GeomTraits().do_intersect_2_object()(q, internal::Primitive_helper::get_datum(pr,m_traits)); + } + + // intersection with AABB-tree + template + bool operator()(const CGAL::AABB_tree& other_tree, const Primitive& pr) const + { + return other_tree.do_intersect( internal::Primitive_helper::get_datum(pr,m_traits) ); + } + + template + bool operator()(const CGAL::AABB_tree& other_tree, const Bounding_box& bbox) const + { + return other_tree.do_intersect(bbox); + } + }; + + Do_intersect do_intersect_object() const {return Do_intersect(*this);} + + + class Intersection { + const AABB_traits_2& m_traits; + public: + Intersection(const AABB_traits_2& traits) + :m_traits(traits) {} + template + std::optional< typename Intersection_and_primitive_id::Type > + operator()(const Query& query, const typename AT::Primitive& primitive) const { + auto inter_res = GeomTraits().intersect_2_object()(query, internal::Primitive_helper::get_datum(primitive,m_traits)); + if (!inter_res) + return std::nullopt; + return std::make_optional( std::make_pair(*inter_res, primitive.id()) ); + } + }; + + Intersection intersection_object() const {return Intersection(*this);} + + + // This should go down to the GeomTraits, i.e. the kernel + class Closest_point { + typedef typename AT::Point Point; + typedef typename AT::Primitive Primitive; + const AABB_traits_2& m_traits; + public: + Closest_point(const AABB_traits_2& traits) + : m_traits(traits) {} + + + Point operator()(const Point& p, const Primitive& pr, const Point& bound) const + { + GeomTraits geom_traits; + Point closest_point = geom_traits.construct_projected_point_2_object()( + internal::Primitive_helper::get_datum(pr,m_traits), p); + + return (geom_traits.compare_distance_2_object()(p, closest_point, bound) == LARGER) ? + bound : closest_point; + } + }; + + // This should go down to the GeomTraits, i.e. the kernel + // and the internal implementation should change its name from + // do_intersect to something like does_contain (this is what we compute, + // this is not the same do_intersect as the spherical kernel) + class Compare_distance { + typedef typename AT::Point Point; + typedef typename AT::FT FT; + typedef typename AT::Primitive Primitive; + public: + CGAL::Comparison_result operator()(const Point& p, const Bounding_box& bb, const Point& bound, Tag_true) const + { + return GeomTraits().do_intersect_2_object() + (GeomTraits().construct_circle_2_object() + (p, GeomTraits().compute_squared_distance_2_object()(p, bound)), bb,true)? + CGAL::SMALLER : CGAL::LARGER; + } + + CGAL::Comparison_result operator()(const Point& p, const Bounding_box& bb, const Point& bound, Tag_false) const + { + return GeomTraits().do_intersect_2_object() + (GeomTraits().construct_circle_2_object() + (p, GeomTraits().compute_squared_distance_2_object()(p, bound)), bb)? + CGAL::SMALLER : CGAL::LARGER; + } + + CGAL::Comparison_result operator()(const Point& p, const Bounding_box& bb, const Point& bound) const + { + return (*this)(p, bb, bound, Boolean_tag::value>()); + } + + // The following functions seem unused...? + template + CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const Point& bound) const + { + return GeomTraits().do_intersect_2_object() + (GeomTraits().construct_circle_2_object() + (p, GeomTraits().compute_squared_distance_2_object()(p, bound)), pr)? + CGAL::SMALLER : CGAL::LARGER; + } + + template + CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const FT& sq_distance) const + { + return GeomTraits().do_intersect_2_object() + (GeomTraits().construct_circle_2_object()(p, sq_distance), + pr) ? + CGAL::SMALLER : + CGAL::LARGER; + } + }; + + Closest_point closest_point_object() const {return Closest_point(*this);} + Compare_distance compare_distance_object() const {return Compare_distance();} + + typedef enum { CGAL_AXIS_X = 0, + CGAL_AXIS_Y = 1} Axis; + + static Axis longest_axis(const Bounding_box& bbox); + +private: + /** + * @brief Computes bounding box of one primitive + * @param pr the primitive + * @return the bounding box of the primitive \c pr + */ + template + Bounding_box compute_bbox(const Primitive& pr, const PM&)const + { + return get(bbm, pr.id()); + } + + Bounding_box compute_bbox(const Primitive& pr, const Default&)const + { + return GeomTraits().construct_bbox_2_object()(internal::Primitive_helper::get_datum(pr, *this)); + } + + /// Comparison functions + static bool less_x(const Primitive& pr1, const Primitive& pr2,const AABB_traits_2& traits) + { + return GeomTraits().less_x_2_object()( internal::Primitive_helper::get_reference_point(pr1,traits), + internal::Primitive_helper::get_reference_point(pr2,traits) ); + } + static bool less_y(const Primitive& pr1, const Primitive& pr2,const AABB_traits_2& traits) + { + return GeomTraits().less_y_2_object()( internal::Primitive_helper::get_reference_point(pr1,traits), + internal::Primitive_helper::get_reference_point(pr2,traits) ); + } + +}; // end class AABB_traits_2 + + +//------------------------------------------------------- +// Private methods +//------------------------------------------------------- + template + typename AABB_traits_2::Axis + AABB_traits_2::longest_axis(const Bounding_box& bbox) +{ + const double dx = bbox.xmax() - bbox.xmin(); + const double dy = bbox.ymax() - bbox.ymin(); + + if(dx>=dy) + { + return CGAL_AXIS_X; + } + else + { + return CGAL_AXIS_Y; + } +} + +/// @} + +} // end namespace CGAL + +#include + +#endif // CGAL_AABB_TRAITS_2_H_ diff --git a/AABB_tree/include/CGAL/AABB_traits_3.h b/AABB_tree/include/CGAL/AABB_traits_3.h new file mode 100644 index 00000000000..30a3fa77cd3 --- /dev/null +++ b/AABB_tree/include/CGAL/AABB_traits_3.h @@ -0,0 +1,532 @@ +// Copyright (c) 2009 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Stéphane Tayeb, Pierre Alliez, Camille Wormser +// + +#ifndef CGAL_AABB_TRAITS_3_H_ +#define CGAL_AABB_TRAITS_3_H_ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/// \file AABB_traits_3.h + +namespace CGAL { + +namespace internal { + +namespace AABB_tree { + +// AABB_traits_intersection_base_3 brings in the Intersection_distance predicate, +// if GeomTraits is a model RayIntersectionGeomTraits. +template ::value> +struct AABB_traits_intersection_base_3; + +template +struct AABB_traits_intersection_base_3{}; + +template +struct AABB_traits_intersection_base_3 { + template + friend class AABB_ray_intersection; + +private: + typedef typename GeomTraits::Point_3 Point; + typedef typename GeomTraits::FT FT; + + // Defining Bounding_box and other types from the full AABB_traits_3 + // here 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_3 Bounding_box; + + typedef typename GeomTraits::Cartesian_const_iterator_3 Cartesian_const_iterator; + typedef typename GeomTraits::Construct_cartesian_const_iterator_3 Construct_cartesian_const_iterator; + + 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(); + } + + 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 construct_cartesian_const_iterator + = GeomTraits().construct_cartesian_const_iterator_3_object(); + 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) { + if((*source_iter < (bbox.min)(i)) || (*source_iter > (bbox.max)(i))) { + return std::nullopt; + } + } else { + FT t1 = ((bbox.min)(i) - *source_iter) / *direction_iter; + FT t2 = ((bbox.max)(i) - *source_iter) / *direction_iter; + + t_near = (std::max)(t_near, (std::min)(t1, t2)); + t_far = (std::min)(t_far, (std::max)(t1, t2)); + + if(t_near > t_far || t_far < FT(0.)) + return std::nullopt; + } + } + + if(t_near < FT(0.)) + return FT(0.); + else + return t_near; + } + }; + + Intersection_distance intersection_distance_object() const { return Intersection_distance(); } +}; + +} } //end of namespace internal::AABB_tree + +/// \addtogroup PkgAABBTreeRef +/// @{ + +// forward declaration +template< typename AABBTraits> +class AABB_tree; + + +/// This traits class handles any type of 3D geometric +/// primitives provided that the proper intersection tests and +/// constructions are implemented. It handles points, rays, lines and +/// segments as query types for intersection detection and +/// computations, and it handles points as query type for distance +/// queries. +/// +/// \cgalModels{AABBTraits,AABBRayIntersectionTraits} +/// +/// \tparam GeomTraits must be a model of the concept \ref AABBGeomTraits_3, +/// and provide the geometric types as well as the intersection tests and computations. +/// \tparam Primitive provide the type of primitives stored in the AABB_tree. +/// It is a model of the concept `AABBPrimitive` or `AABBPrimitiveWithSharedData`. +/// +/// \tparam BboxMap must be a model of `ReadablePropertyMap` that has as key type a primitive id, +/// and as value type a `Bounding_box`. +/// If the type is `Default` the `Datum` must have the +/// member function `bbox()` that returns the bounding box of the primitive. +/// +/// If the argument `GeomTraits` is a model of the concept \ref +/// AABBRayIntersectionGeomTraits_3, this class is also a model of \ref +/// AABBRayIntersectionTraits. +/// +/// \sa `AABBTraits` +/// \sa `AABB_tree` +/// \sa `AABBPrimitive` +/// \sa `AABBPrimitiveWithSharedData` + +template +class AABB_traits_3 +#ifndef DOXYGEN_RUNNING +: public internal::AABB_tree::AABB_traits_base, + public internal::AABB_tree::AABB_traits_intersection_base_3, + public Search_traits_3 +#endif +{ + typedef typename CGAL::Object Object; +public: + typedef GeomTraits Geom_traits; + + typedef AABB_traits_3 AT; + // AABBTraits concept types + typedef typename GeomTraits::FT FT; + typedef AABBPrimitive Primitive; + + typedef typename std::pair Object_and_primitive_id; + + typedef typename std::pair Point_and_primitive_id; + + /// `Intersection_and_primitive_id::%Type::first_type` is found according to + /// the result type of `GeomTraits::Intersect_3::operator()`. If it is + /// `std::optional` then it is `T`, and the result type otherwise. + template + struct Intersection_and_primitive_id { + typedef decltype( + std::declval()( + std::declval(), + std::declval())) Intersection_type; + + typedef std::pair< + typename internal::Remove_optional::type, + typename Primitive::Id > Type; + }; + + // types for search tree + /// \name Types + /// @{ + + /// Point type + typedef typename GeomTraits::Point_3 Point; // because the AABB_tree is dimension agnostic + /// Deprecated point type + 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. + typedef typename GeomTraits::Iso_cuboid_3 Iso_cuboid_3; + + /// Bounding box type. + typedef typename CGAL::Bbox_3 Bounding_box; + + /// @} + + typedef typename GeomTraits::Sphere_3 Sphere_3; + 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_center_3 Construct_center_3; + typedef typename GeomTraits::Compute_squared_radius_3 Compute_squared_radius_3; + typedef typename GeomTraits::Construct_min_vertex_3 Construct_min_vertex_3; + typedef typename GeomTraits::Construct_max_vertex_3 Construct_max_vertex_3; + typedef typename GeomTraits::Construct_iso_cuboid_3 Construct_iso_cuboid_3; + + BboxMap bbm; + + /// Default constructor. + AABB_traits_3() { } + + AABB_traits_3(BboxMap bbm) + : bbm(bbm) + {} + + + typedef typename GeomTraits::Compute_squared_distance_3 Squared_distance; + Squared_distance squared_distance_object() const { return GeomTraits().compute_squared_distance_3_object(); } + + typedef typename GeomTraits::Equal_3 Equal; + Equal equal_object() const { return GeomTraits().equal_3_object(); } + + /** + * @internal + * @brief Sorts [first,beyond[ + * @param first iterator on first element + * @param beyond iterator on beyond element + * @param bbox the bounding box of [first,beyond[ + * + * Sorts the range defined by [first,beyond[. Sort is achieved on bbox longest + * axis, using the comparison function `_less_than` (dim in {x,y,z}) + */ + class Split_primitives + { + typedef AABB_traits_3 Traits; + const Traits& m_traits; + public: + Split_primitives(const AABB_traits_3& traits) + : m_traits(traits) {} + + typedef void result_type; + template + void operator()(PrimitiveIterator first, + PrimitiveIterator beyond, + const typename AT::Bounding_box& bbox) const + { + PrimitiveIterator middle = first + (beyond - first)/2; + switch(Traits::longest_axis(bbox)) + { + case AT::CGAL_AXIS_X: // sort along x + std::nth_element(first, middle, beyond, [this](const Primitive& p1, const Primitive& p2){ return Traits::less_x(p1, p2, this->m_traits); }); + break; + case AT::CGAL_AXIS_Y: // sort along y + std::nth_element(first, middle, beyond, [this](const Primitive& p1, const Primitive& p2){ return Traits::less_y(p1, p2, this->m_traits); }); + break; + case AT::CGAL_AXIS_Z: // sort along z + std::nth_element(first, middle, beyond, [this](const Primitive& p1, const Primitive& p2){ return Traits::less_z(p1, p2, this->m_traits); }); + break; + default: + CGAL_error(); + } + } + }; + + Split_primitives split_primitives_object() const {return Split_primitives(*this);} + + + /* + * Computes the bounding box of a set of primitives + * @param first an iterator on the first primitive + * @param beyond an iterator on the past-the-end primitive + * @return the bounding box of the primitives of the iterator range + */ + class Compute_bbox { + const AABB_traits_3& m_traits; + public: + Compute_bbox(const AABB_traits_3& traits) + :m_traits (traits) {} + + template + typename AT::Bounding_box operator()(ConstPrimitiveIterator first, + ConstPrimitiveIterator beyond) const + { + typename AT::Bounding_box bbox = m_traits.compute_bbox(*first,m_traits.bbm); + for(++first; first != beyond; ++first) + { + bbox = bbox + m_traits.compute_bbox(*first,m_traits.bbm); + } + return bbox; + } + + }; + + Compute_bbox compute_bbox_object() const {return Compute_bbox(*this);} + + /// \brief Function object using `GeomTraits::Do_intersect`. + /// In the case the query is a `CGAL::AABB_tree`, the `do_intersect()` + /// function of this tree is used. + class Do_intersect { + const AABB_traits_3& m_traits; + public: + Do_intersect(const AABB_traits_3& traits) + :m_traits(traits) {} + + template + bool operator()(const Query& q, const Bounding_box& bbox) const + { + return GeomTraits().do_intersect_3_object()(q, bbox); + } + + template + bool operator()(const Query& q, const Primitive& pr) const + { + return GeomTraits().do_intersect_3_object()(q, internal::Primitive_helper::get_datum(pr,m_traits)); + } + + // intersection with AABB-tree + template + bool operator()(const CGAL::AABB_tree& other_tree, const Primitive& pr) const + { + return other_tree.do_intersect( internal::Primitive_helper::get_datum(pr,m_traits) ); + } + + template + bool operator()(const CGAL::AABB_tree& other_tree, const Bounding_box& bbox) const + { + return other_tree.do_intersect(bbox); + } + }; + + Do_intersect do_intersect_object() const {return Do_intersect(*this);} + + + class Intersection { + const AABB_traits_3& m_traits; + public: + Intersection(const AABB_traits_3& traits) + :m_traits(traits) {} + template + std::optional< typename Intersection_and_primitive_id::Type > + operator()(const Query& query, const typename AT::Primitive& primitive) const { + auto inter_res = GeomTraits().intersect_3_object()(query, internal::Primitive_helper::get_datum(primitive,m_traits)); + if (!inter_res) + return std::nullopt; + return std::make_optional( std::make_pair(*inter_res, primitive.id()) ); + } + }; + + Intersection intersection_object() const {return Intersection(*this);} + + + // This should go down to the GeomTraits, i.e. the kernel + class Closest_point { + typedef typename AT::Point Point; + typedef typename AT::Primitive Primitive; + const AABB_traits_3& m_traits; + public: + Closest_point(const AABB_traits_3& traits) + : m_traits(traits) {} + + + Point operator()(const Point& p, const Primitive& pr, const Point& bound) const + { + GeomTraits geom_traits; + Point closest_point = geom_traits.construct_projected_point_3_object()( + internal::Primitive_helper::get_datum(pr,m_traits), p); + + return (geom_traits.compare_distance_3_object()(p, closest_point, bound) == LARGER) ? + bound : closest_point; + } + }; + + // This should go down to the GeomTraits, i.e. the kernel + // and the internal implementation should change its name from + // do_intersect to something like does_contain (this is what we compute, + // this is not the same do_intersect as the spherical kernel) + class Compare_distance { + typedef typename AT::Point Point; + typedef typename AT::FT FT; + typedef typename AT::Primitive Primitive; + public: + CGAL::Comparison_result operator()(const Point& p, const Bounding_box& bb, const Point& bound, Tag_true) const + { + return GeomTraits().do_intersect_3_object() + (GeomTraits().construct_sphere_3_object() + (p, GeomTraits().compute_squared_distance_3_object()(p, bound)), bb,true)? + CGAL::SMALLER : CGAL::LARGER; + } + + CGAL::Comparison_result operator()(const Point& p, const Bounding_box& bb, const Point& bound, Tag_false) const + { + return GeomTraits().do_intersect_3_object() + (GeomTraits().construct_sphere_3_object() + (p, GeomTraits().compute_squared_distance_3_object()(p, bound)), bb)? + CGAL::SMALLER : CGAL::LARGER; + } + + CGAL::Comparison_result operator()(const Point& p, const Bounding_box& bb, const Point& bound) const + { + return (*this)(p, bb, bound, Boolean_tag::value>()); + } + + // The following functions seem unused...? + template + CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const Point& bound) const + { + return GeomTraits().do_intersect_3_object() + (GeomTraits().construct_sphere_3_object() + (p, GeomTraits().compute_squared_distance_3_object()(p, bound)), pr)? + CGAL::SMALLER : CGAL::LARGER; + } + + template + CGAL::Comparison_result operator()(const Point& p, const Solid& pr, const FT& sq_distance) const + { + return GeomTraits().do_intersect_3_object() + (GeomTraits().construct_sphere_3_object()(p, sq_distance), + pr) ? + CGAL::SMALLER : + CGAL::LARGER; + } + }; + + Closest_point closest_point_object() const {return Closest_point(*this);} + Compare_distance compare_distance_object() const {return Compare_distance();} + + typedef enum { CGAL_AXIS_X = 0, + CGAL_AXIS_Y = 1, + CGAL_AXIS_Z = 2} Axis; + + static Axis longest_axis(const Bounding_box& bbox); + +private: + /** + * @brief Computes bounding box of one primitive + * @param pr the primitive + * @return the bounding box of the primitive \c pr + */ + template + Bounding_box compute_bbox(const Primitive& pr, const PM&)const + { + return get(bbm, pr.id()); + } + + Bounding_box compute_bbox(const Primitive& pr, const Default&)const + { + return internal::Primitive_helper::get_datum(pr,*this).bbox(); + } + + /// Comparison functions + static bool less_x(const Primitive& pr1, const Primitive& pr2,const AABB_traits_3& traits) + { + return GeomTraits().less_x_3_object()( internal::Primitive_helper::get_reference_point(pr1,traits), + internal::Primitive_helper::get_reference_point(pr2,traits) ); + } + static bool less_y(const Primitive& pr1, const Primitive& pr2,const AABB_traits_3& traits) + { + return GeomTraits().less_y_3_object()( internal::Primitive_helper::get_reference_point(pr1,traits), + internal::Primitive_helper::get_reference_point(pr2,traits) ); + } + static bool less_z(const Primitive& pr1, const Primitive& pr2,const AABB_traits_3& traits) + { + return GeomTraits().less_z_3_object()( internal::Primitive_helper::get_reference_point(pr1,traits), + internal::Primitive_helper::get_reference_point(pr2,traits) ); + } + +}; // end class AABB_traits_3 + + +//------------------------------------------------------- +// Private methods +//------------------------------------------------------- + template + typename AABB_traits_3::Axis + AABB_traits_3::longest_axis(const Bounding_box& bbox) +{ + const double dx = bbox.xmax() - bbox.xmin(); + const double dy = bbox.ymax() - bbox.ymin(); + const double dz = bbox.zmax() - bbox.zmin(); + + if(dx>=dy) + { + if(dx>=dz) + { + return CGAL_AXIS_X; + } + else // dz>dx and dx>=dy + { + return CGAL_AXIS_Z; + } + } + else // dy>dx + { + if(dy>=dz) + { + return CGAL_AXIS_Y; + } + else // dz>dy and dy>dx + { + return CGAL_AXIS_Z; + } + } +} + +/// @} + +} // end namespace CGAL + +#include + +#endif // CGAL_AABB_TRAITS_3_H_ diff --git a/AABB_tree/include/CGAL/AABB_tree.h b/AABB_tree/include/CGAL/AABB_tree.h index 16c39099b38..c63fdf38679 100644 --- a/AABB_tree/include/CGAL/AABB_tree.h +++ b/AABB_tree/include/CGAL/AABB_tree.h @@ -41,9 +41,9 @@ namespace CGAL { /** * Static data structure for efficient - * intersection and distance computations in 3D. It builds a + * intersection and distance computations in 2D and 3D. It builds a * hierarchy of axis-aligned bounding boxes (an AABB tree) from a set - * of 3D geometric objects, and can receive intersection and distance + * of geometric objects, and can receive intersection and distance * queries, provided that the corresponding predicates are * implemented in the traits class AABBTraits. * An instance of the class `AABBTraits` is internally stored. @@ -74,9 +74,8 @@ namespace CGAL { /// Number type returned by the distance queries. typedef typename AABBTraits::FT FT; - - /// Type of 3D point. - typedef typename AABBTraits::Point_3 Point; + /// Type of point. + typedef typename AABBTraits::Point Point; /// Type of input primitive. typedef typename AABBTraits::Primitive Primitive; @@ -86,7 +85,7 @@ namespace CGAL { typedef typename Primitives::size_type size_type; /// Type of bounding box. typedef typename AABBTraits::Bounding_box Bounding_box; - /// 3D Point and Primitive Id type + /// Point and Primitive Id type typedef typename AABBTraits::Point_and_primitive_id Point_and_primitive_id; /// \deprecated typedef typename AABBTraits::Object_and_primitive_id Object_and_primitive_id; @@ -125,7 +124,7 @@ namespace CGAL { Self& operator=(const Self&) = delete; /** - * @brief Builds the data structure from a sequence of primitives. + * @brief builds the data structure from a sequence of primitives. * @param first iterator over first primitive to insert * @param beyond past-the-end iterator * @@ -300,7 +299,7 @@ public: /// returns the intersection and primitive id closest to the source point of the ray /// query. - /// \tparam Ray must be the same as `AABBTraits::Ray_3` and + /// \tparam Ray must be the same as `AABBTraits::Ray` and /// `do_intersect` predicates and intersections for it must be /// defined. /// \tparam Skip a functor with an operator @@ -331,7 +330,7 @@ public: /// returns the primitive id closest to the source point of the ray /// query. - /// \tparam Ray must be the same as `AABBTraits::Ray_3` and + /// \tparam Ray must be the same as `AABBTraits::Ray` and /// `do_intersect` predicates and intersections for it must be /// defined. /// \tparam Skip a functor with an operator 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 fd11f41492c..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 @@ -36,9 +36,13 @@ namespace CGAL { template class AABB_ray_intersection { typedef typename AABBTree::AABB_traits AABB_traits; - typedef typename AABB_traits::Ray_3 Ray; + static const int dimension = AABB_traits::Point::Ambient_dimension::value; + typedef typename AABB_traits::Ray Ray; + typedef typename AABB_traits::Vector Vector; + 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) {} @@ -48,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 @@ -167,8 +170,8 @@ private: as_ray_param_visitor(const Ray* ray) : ray(ray), max_i(0) { - typename AABB_traits::Geom_traits::Vector_3 v = ray->to_vector(); - for (int i=1; i<3; ++i) + Vector v = AABB_traits().construct_vector_object()(*ray); + for (int i=1; i CGAL::abs(v[max_i]) ) max_i = i; } @@ -184,8 +187,8 @@ private: } FT operator()(const Point& point) { - typename AABB_traits::Geom_traits::Vector_3 x(ray->source(), point); - typename AABB_traits::Geom_traits::Vector_3 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]; } @@ -200,8 +203,8 @@ template std::optional< typename AABB_tree::template Intersection_and_primitive_id::Type > AABB_tree::first_intersection(const Ray& query, const SkipFunctor& skip) const { - static_assert(std::is_same::value, - "Ray and Ray_3 must be the same type"); + static_assert(std::is_same::value, + "Ray and AABBTraits::Ray must be the same type"); switch(size()) // copy-paste from AABB_tree::traversal { diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_search_tree.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_search_tree.h index 9ba3cf2481b..f44130eda28 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_search_tree.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_search_tree.h @@ -15,110 +15,60 @@ #include - #include -#include +#include +#include namespace CGAL { - template - class Add_decorated_point: public Underlying - { - class Decorated_point: public Underlying::Point_3 - { - public: - const Id& id() const { return m_id; } - Decorated_point() - : Underlying::Point_3() - , m_id() - , m_is_id_initialized(false) {} +template +struct AABB_search_tree +{ - // Allows the user not to provide the id - // so that we don't break existing code - Decorated_point(const typename Underlying::Point_3& p) - : Underlying::Point_3(p) - , m_id() - , m_is_id_initialized(false) {} + typedef typename Traits::Point_and_primitive_id Point_and_primitive_id; + typedef typename Point_and_primitive_id::first_type Point; + typedef typename Point_and_primitive_id::second_type Id; + typedef First_of_pair_property_map Pmap; + typedef Search_traits_adapter TreeTraits; + typedef typename CGAL::Orthogonal_k_neighbor_search Neighbor_search; + typedef typename Neighbor_search::Tree Tree; +private: + Tree m_tree; - Decorated_point(const typename Underlying::Point_3& p, - const Id& id) - : Underlying::Point_3(p) - , m_id(id) - , m_is_id_initialized(true) {} + Point_and_primitive_id get_p_and_p(const Point_and_primitive_id& p) + { + return p; + } - Decorated_point(const Decorated_point& rhs) - : Underlying::Point_3(rhs) - , m_id() - , m_is_id_initialized(rhs.m_is_id_initialized) - { - if ( m_is_id_initialized ) - m_id = rhs.m_id; - } + Point_and_primitive_id get_p_and_p(const Point& p) + { + return Point_and_primitive_id(p, Id()); + } - Decorated_point& operator=(const Decorated_point&)=default; - private: - Id m_id; +public: + template + AABB_search_tree(ConstPointIterator begin, ConstPointIterator beyond) + : m_tree{} + { + std::vector points; + while (begin != beyond) { + Point_and_primitive_id pp = get_p_and_p(*begin); + points.emplace_back(pp); + ++begin; + } + m_tree.insert(points.begin(), points.end()); + m_tree.build(); + } - // Needed to avoid exception (depending on Id type) - // "error: attempt to copy-construct an iterator from a singular iterator." - // This exception may appear if we copy-construct an Id - // which has Id() as value (It is done when constructing - // Neighbor_search since we pass the Point only as query) - bool m_is_id_initialized; - }; - public: - typedef Decorated_point Point_3; - }; - - template - class AABB_search_tree - { - public: - typedef typename Traits::FT FT; - typedef typename Traits::Point_3 Point; - typedef typename Traits::Primitive Primitive; - typedef typename Traits::Point_and_primitive_id Point_and_primitive_id; - typedef typename CGAL::Search_traits_3 > TreeTraits; - typedef typename CGAL::Orthogonal_k_neighbor_search Neighbor_search; - typedef typename Neighbor_search::Tree Tree; - private: - Tree m_tree; - - - Point_and_primitive_id get_p_and_p(const Point_and_primitive_id& p) - { - return p; - } - Point_and_primitive_id get_p_and_p(const Point& p) - { - return Point_and_primitive_id(p, typename Primitive::Id()); - } - - public: - template - AABB_search_tree(ConstPointIterator begin, ConstPointIterator beyond) - : m_tree{} - { - typedef typename Add_decorated_point::Point_3 Decorated_point; - std::vector points; - while(begin != beyond) { - Point_and_primitive_id pp = get_p_and_p(*begin); - points.emplace_back(pp.first, pp.second); - ++begin; - } - m_tree.insert(points.begin(), points.end()); - m_tree.build(); - } - - Point_and_primitive_id closest_point(const Point& query) const - { - Neighbor_search search(m_tree, query, 1); - return Point_and_primitive_id(static_cast(search.begin()->first), search.begin()->first.id()); - } - }; + template + Point_and_primitive_id closest_point(const Point& query) const + { + Neighbor_search search(m_tree, query, 1); + return search.begin()->first; + } +}; } #endif // CGAL_AABB_SEARCH_TREE_H - diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traits_base.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traits_base.h new file mode 100644 index 00000000000..3fc4968c3c6 --- /dev/null +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traits_base.h @@ -0,0 +1,47 @@ +// Copyright (c) 2024 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Stéphane Tayeb, Pierre Alliez, Camille Wormser +// + +#ifndef CGAL_AABB_TRAITS_BASE_H +#define CGAL_AABB_TRAITS_BASE_H + +#include + +#include + +namespace CGAL { +namespace internal { +namespace AABB_tree { + +//helper controlling whether extra data should be stored in the AABB_tree traits class +template ::value> +struct AABB_traits_base; + +template +struct AABB_traits_base {}; + +template +struct AABB_traits_base { + typename Primitive::Shared_data m_primitive_data; + + template + void set_shared_data(T&& ... t) { + m_primitive_data = Primitive::construct_shared_data(std::forward(t)...); + } + const typename Primitive::Shared_data& shared_data() const { return m_primitive_data; } +}; + +} +} +} + +#endif diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h index ce9a56e15b9..11fe903df93 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/AABB_traversal_traits.h @@ -59,7 +59,7 @@ template class First_intersection_traits { typedef typename AABBTraits::FT FT; - typedef typename AABBTraits::Point_3 Point; + typedef typename AABBTraits::Point Point; typedef typename AABBTraits::Primitive Primitive; typedef typename AABBTraits::Bounding_box Bounding_box; typedef typename AABBTraits::Primitive::Id Primitive_id; @@ -108,7 +108,7 @@ template class Listing_intersection_traits { typedef typename AABBTraits::FT FT; - typedef typename AABBTraits::Point_3 Point; + typedef typename AABBTraits::Point Point; typedef typename AABBTraits::Primitive Primitive; typedef typename AABBTraits::Bounding_box Bounding_box; typedef typename AABBTraits::Primitive::Id Primitive_id; @@ -151,7 +151,7 @@ template class Listing_primitive_traits { typedef typename AABBTraits::FT FT; - typedef typename AABBTraits::Point_3 Point; + typedef typename AABBTraits::Point Point; typedef typename AABBTraits::Primitive Primitive; typedef typename AABBTraits::Bounding_box Bounding_box; typedef typename AABBTraits::Primitive::Id Primitive_id; @@ -191,7 +191,7 @@ template class First_primitive_traits { typedef typename AABBTraits::FT FT; - typedef typename AABBTraits::Point_3 Point; + typedef typename AABBTraits::Point Point; typedef typename AABBTraits::Primitive Primitive; typedef typename AABBTraits::Bounding_box Bounding_box; typedef typename AABBTraits::Primitive::Id Primitive_id; @@ -237,7 +237,7 @@ template class Do_intersect_traits { typedef typename AABBTraits::FT FT; - typedef typename AABBTraits::Point_3 Point; + typedef typename AABBTraits::Point Point; typedef typename AABBTraits::Primitive Primitive; typedef typename AABBTraits::Bounding_box Bounding_box; typedef typename AABBTraits::Primitive::Id Primitive_id; @@ -278,7 +278,7 @@ template class Projection_traits { typedef typename AABBTraits::FT FT; - typedef typename AABBTraits::Point_3 Point; + typedef typename AABBTraits::Point Point; typedef typename AABBTraits::Primitive Primitive; typedef typename AABBTraits::Bounding_box Bounding_box; typedef typename AABBTraits::Primitive::Id Primitive_id; @@ -301,7 +301,7 @@ public: { Point new_closest_point = m_traits.closest_point_object() (query, primitive, m_closest_point); - if( !m_traits.equal_3_object()(new_closest_point, m_closest_point) ) + if( !m_traits.equal_object()(new_closest_point, m_closest_point) ) { m_closest_primitive = primitive.id(); m_closest_point = new_closest_point; // this effectively shrinks the sphere diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/Is_ray_intersection_geomtraits.h b/AABB_tree/include/CGAL/AABB_tree/internal/Is_ray_intersection_geomtraits.h index 3d02204b9d0..f77b59d6085 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/Is_ray_intersection_geomtraits.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/Is_ray_intersection_geomtraits.h @@ -24,18 +24,33 @@ namespace CGAL { namespace internal { namespace AABB_tree { -BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_ray_3,Ray_3,false) -BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_construct_source_3,Construct_source_3,false) -BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_vector_3,Construct_vector_3,false) -BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_construct_cartesian_const_iterator_3,Construct_cartesian_const_iterator_3,false) -BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_cartesian_const_iterator_3,Cartesian_const_iterator_3,false) +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_ray_3, Ray_3, false) +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_construct_source_3, Construct_source_3, false) +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_vector_3, Construct_vector_3, false) +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_construct_cartesian_const_iterator_3, Construct_cartesian_const_iterator_3, false) +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_cartesian_const_iterator_3, Cartesian_const_iterator_3, false) + +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_ray_2, Ray_2, false) +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_construct_source_2, Construct_source_2, false) +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_vector_2, Construct_vector_2, false) +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_construct_cartesian_const_iterator_2, Construct_cartesian_const_iterator_2, false) +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_cartesian_const_iterator_2, Cartesian_const_iterator_2, false) + +template +struct Is_ray_intersection_geomtraits_2 +: std::bool_constant< Has_ray_2::value && + Has_construct_source_2::value && + Has_vector_2::value && + Has_construct_cartesian_const_iterator_2::value && + Has_cartesian_const_iterator_2::value > +{}; template struct Is_ray_intersection_geomtraits -: std::bool_constant< Has_ray_3::value && - Has_construct_source_3::value && - Has_vector_3::value && - Has_construct_cartesian_const_iterator_3::value && +: std::bool_constant< Has_ray_3::value&& + Has_construct_source_3::value&& + Has_vector_3::value&& + Has_construct_cartesian_const_iterator_3::value&& Has_cartesian_const_iterator_3::value > {}; diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/Remove_optional.h b/AABB_tree/include/CGAL/AABB_tree/internal/Remove_optional.h new file mode 100644 index 00000000000..f831d84fa9f --- /dev/null +++ b/AABB_tree/include/CGAL/AABB_tree/internal/Remove_optional.h @@ -0,0 +1,33 @@ +// Copyright (c) 2024 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Stéphane Tayeb, Pierre Alliez, Camille Wormser +// + +#ifndef CGAL_REMOVE_OPTIONAL_H_ +#define CGAL_REMOVE_OPTIONAL_H_ + +#include + +#include + +namespace CGAL { +namespace internal { + +template +struct Remove_optional { typedef T type; }; + +template +struct Remove_optional< ::std::optional > { typedef T type; }; + +} // end namespace internal +} // end namespace CGAL + +#endif \ No newline at end of file diff --git a/AABB_tree/include/CGAL/AABB_tree/internal/triangle_datum_covering.h b/AABB_tree/include/CGAL/AABB_tree/internal/triangle_datum_covering.h index 69babb2c160..ca017919e3f 100644 --- a/AABB_tree/include/CGAL/AABB_tree/internal/triangle_datum_covering.h +++ b/AABB_tree/include/CGAL/AABB_tree/internal/triangle_datum_covering.h @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include #include @@ -161,7 +161,7 @@ struct AABB_covered_triangle_tree_traits CGAL::Tag_false /*no caching*/>; using AABB_geom_traits = Kernel; - using AABB_traits = CGAL::AABB_traits; + using AABB_traits = CGAL::AABB_traits_3; using AABB_tree = CGAL::AABB_tree; }; diff --git a/AABB_tree/include/CGAL/AABB_triangle_primitive.h b/AABB_tree/include/CGAL/AABB_triangle_primitive.h index 1fc1b140c58..f37a3540d92 100644 --- a/AABB_tree/include/CGAL/AABB_triangle_primitive.h +++ b/AABB_tree/include/CGAL/AABB_triangle_primitive.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 INRIA Sophia-Antipolis (France). +// Copyright (c) 2024 INRIA Sophia-Antipolis (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org). @@ -11,92 +11,38 @@ // Author(s) : Sebastien Loriot // - #ifndef CGAL_AABB_TRIANGLE_PRIMITIVE_H_ #define CGAL_AABB_TRIANGLE_PRIMITIVE_H_ #include -#include +#define CGAL_DEPRECATED_HEADER "" +#define CGAL_REPLACEMENT_HEADER "" +#include -#include -#include +#ifndef CGAL_NO_DEPRECATED_CODE + +#include + +/// \file AABB_triangle_primitive.h namespace CGAL { -namespace internal { - template - struct Point_from_triangle_3_iterator_property_map{ - //classical typedefs - typedef Iterator key_type; - typedef typename GeomTraits::Point_3 value_type; - // typedef decltype( - // std::declval()( - // std::declval(), - // std::declval())) reference; - typedef decltype( - typename GeomTraits::Construct_vertex_3()( - *std::declval(), 0)) reference; - typedef boost::readable_property_map_tag category; - typedef Point_from_triangle_3_iterator_property_map Self; - inline friend reference - get(Self, key_type it) - { - return typename GeomTraits::Construct_vertex_3()( *it, 0 ); - } - }; -}//namespace internal +/// \addtogroup PkgAABBTreeRef +/// @{ +/// template alias for backward compatibility -/*! - * \ingroup PkgAABBTreeRef - * Primitive type that uses as identifier an iterator with a 3D triangle as `value_type`. - * The iterator from which the primitive is built should not be invalided - * while the AABB tree holding the primitive is in use. - * - * \cgalModels{AABBPrimitive} - * - * \tparam GeomTraits is a traits class providing the nested type `Point_3` and `Triangle_3`. - * It also provides the functor `Construct_vertex_3` that has an operator taking a `Triangle_3` - * and an integer as parameters and returning a triangle point as a type convertible to `Point_3`. - * \tparam Iterator is a model of `ForwardIterator` with its value type convertible to `GeomTraits::Triangle_3` - * \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. - * The default is `CGAL::Tag_false` (datum is not stored). - * - * \sa `AABBPrimitive` - * \sa `AABB_primitive` - * \sa `AABB_segment_primitive` - * \sa `AABB_halfedge_graph_segment_primitive` - * \sa `AABB_face_graph_triangle_primitive` - */ template < class GeomTraits, class Iterator, class CacheDatum=Tag_false> -class AABB_triangle_primitive -#ifndef DOXYGEN_RUNNING - : public AABB_primitive< Iterator, - Input_iterator_property_map, - internal::Point_from_triangle_3_iterator_property_map, - Tag_false, - CacheDatum > -#endif -{ - typedef AABB_primitive< Iterator, - Input_iterator_property_map, - internal::Point_from_triangle_3_iterator_property_map, - Tag_false, - CacheDatum > Base; -public: - ///constructor from an iterator - AABB_triangle_primitive(Iterator it) : Base(it){} -}; +using AABB_triangle_primitive = AABB_triangle_primitive_3; -} // end namespace CGAL +///@} -#include +} //CGAL namespace -#endif // CGAL_AABB_TRIANGLE_PRIMITIVE_H_ +#endif // CGAL_NO_DEPRECATED_CODE +#endif //CGAL_AABB_TRIANGLE_PRIMITIVE_H_ diff --git a/AABB_tree/include/CGAL/AABB_triangle_primitive_2.h b/AABB_tree/include/CGAL/AABB_triangle_primitive_2.h new file mode 100644 index 00000000000..0472b4ab08a --- /dev/null +++ b/AABB_tree/include/CGAL/AABB_triangle_primitive_2.h @@ -0,0 +1,100 @@ +// Copyright (c) 2012 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sebastien Loriot +// + + +#ifndef CGAL_AABB_TRIANGLE_PRIMITIVE_2_H_ +#define CGAL_AABB_TRIANGLE_PRIMITIVE_2_H_ + +#include + +#include + +#include +#include + +namespace CGAL { + +namespace internal { + template + struct Point_from_triangle_2_iterator_property_map{ + //classical typedefs + typedef Iterator key_type; + typedef typename GeomTraits::Point_2 value_type; + // typedef decltype( + // std::declval()( + // std::declval(), + // std::declval())) reference; + typedef decltype( + typename GeomTraits::Construct_vertex_2()( + *std::declval(), 0)) reference; + typedef boost::readable_property_map_tag category; + typedef Point_from_triangle_2_iterator_property_map Self; + + inline friend reference + get(Self, key_type it) + { + return typename GeomTraits::Construct_vertex_2()( *it, 0 ); + } + }; +}//namespace internal + + +/*! + * \ingroup PkgAABBTreeRef + * Primitive type that uses as identifier an iterator with a 2D triangle as `value_type`. + * The iterator from which the primitive is built should not be invalided + * while the AABB tree holding the primitive is in use. + * + * \cgalModels{AABBPrimitive} + * + * \tparam GeomTraits is a traits class providing the nested type `Point_2` and `Triangle_2`. + * It also provides the functor `Construct_vertex_2` that has an operator taking a `Triangle_2` + * and an integer as parameters and returning a triangle point as a type convertible to `Point_2`. + * \tparam Iterator is a model of `ForwardIterator` with its value type convertible to `GeomTraits::Triangle_2` + * \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. + * The default is `CGAL::Tag_false` (datum is not stored). + * + * \sa `AABBPrimitive` + * \sa `AABB_primitive` + * \sa `AABB_segment_primitive_2` + * \sa `AABB_triangle_primitive_3` + */ +template < class GeomTraits, + class Iterator, + class CacheDatum=Tag_false> +class AABB_triangle_primitive_2 +#ifndef DOXYGEN_RUNNING + : public AABB_primitive< Iterator, + Input_iterator_property_map, + internal::Point_from_triangle_2_iterator_property_map, + Tag_false, + CacheDatum > +#endif +{ + typedef AABB_primitive< Iterator, + Input_iterator_property_map, + internal::Point_from_triangle_2_iterator_property_map, + Tag_false, + CacheDatum > Base; +public: + ///constructor from an iterator + AABB_triangle_primitive_2(Iterator it) : Base(it){} +}; + +} // end namespace CGAL + +#include + +#endif // CGAL_AABB_TRIANGLE_PRIMITIVE_2_H_ diff --git a/AABB_tree/include/CGAL/AABB_triangle_primitive_3.h b/AABB_tree/include/CGAL/AABB_triangle_primitive_3.h new file mode 100644 index 00000000000..0b709d855d6 --- /dev/null +++ b/AABB_tree/include/CGAL/AABB_triangle_primitive_3.h @@ -0,0 +1,101 @@ +// Copyright (c) 2012 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sebastien Loriot +// + + +#ifndef CGAL_AABB_TRIANGLE_PRIMITIVE_3_H_ +#define CGAL_AABB_TRIANGLE_PRIMITIVE_3_H_ + +#include + +#include + +#include +#include + +namespace CGAL { + +namespace internal { + template + struct Point_from_triangle_3_iterator_property_map{ + //classical typedefs + typedef Iterator key_type; + typedef typename GeomTraits::Point_3 value_type; + // typedef decltype( + // std::declval()( + // std::declval(), + // std::declval())) reference; + typedef decltype( + typename GeomTraits::Construct_vertex_3()( + *std::declval(), 0)) reference; + typedef boost::readable_property_map_tag category; + typedef Point_from_triangle_3_iterator_property_map Self; + + inline friend reference + get(Self, key_type it) + { + return typename GeomTraits::Construct_vertex_3()( *it, 0 ); + } + }; +}//namespace internal + + +/*! + * \ingroup PkgAABBTreeRef + * Primitive type that uses as identifier an iterator with a 3D triangle as `value_type`. + * The iterator from which the primitive is built should not be invalided + * while the AABB tree holding the primitive is in use. + * + * \cgalModels{AABBPrimitive} + * + * \tparam GeomTraits is a traits class providing the nested type `Point_3` and `Triangle_3`. + * It also provides the functor `Construct_vertex_3` that has an operator taking a `Triangle_3` + * and an integer as parameters and returning a triangle point as a type convertible to `Point_3`. + * \tparam Iterator is a model of `ForwardIterator` with its value type convertible to `GeomTraits::Triangle_3` + * \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. + * The default is `CGAL::Tag_false` (datum is not stored). + * + * \sa `AABBPrimitive` + * \sa `AABB_primitive` + * \sa `AABB_segment_primitive_3` + * \sa `AABB_triangle_primitive_2` + * \sa `AABB_face_graph_triangle_primitive` + */ +template < class GeomTraits, + class Iterator, + class CacheDatum=Tag_false> +class AABB_triangle_primitive_3 +#ifndef DOXYGEN_RUNNING + : public AABB_primitive< Iterator, + Input_iterator_property_map, + internal::Point_from_triangle_3_iterator_property_map, + Tag_false, + CacheDatum > +#endif +{ + typedef AABB_primitive< Iterator, + Input_iterator_property_map, + internal::Point_from_triangle_3_iterator_property_map, + Tag_false, + CacheDatum > Base; +public: + ///constructor from an iterator + AABB_triangle_primitive_3(Iterator it) : Base(it){} +}; + +} // end namespace CGAL + +#include + +#endif // CGAL_AABB_TRIANGLE_PRIMITIVE_3_H_ diff --git a/AABB_tree/package_info/AABB_tree/description.txt b/AABB_tree/package_info/AABB_tree/description.txt index 0f6f1e2664c..4defc25a858 100644 --- a/AABB_tree/package_info/AABB_tree/description.txt +++ b/AABB_tree/package_info/AABB_tree/description.txt @@ -1 +1 @@ -Data structure for efficient intersection and distance queries over sets of 3D geometric primitives. +Data structure for efficient intersection and distance queries over sets of 2D and 3D geometric primitives. diff --git a/AABB_tree/package_info/AABB_tree/long_description.txt b/AABB_tree/package_info/AABB_tree/long_description.txt index ad49fc371b0..73985b7a90f 100644 --- a/AABB_tree/package_info/AABB_tree/long_description.txt +++ b/AABB_tree/package_info/AABB_tree/long_description.txt @@ -1 +1 @@ -This component implements a hierarchy of axis-aligned bounding boxes (a AABB tree) for efficient intersection and distance computations between 3D queries and sets of input 3D geometric objects. +This component implements a hierarchy of axis-aligned bounding boxes (a AABB tree) for efficient intersection and distance computations between 2D/3D queries and sets of input 2D/3D geometric objects. diff --git a/AABB_tree/test/AABB_tree/AABB_test_util.h b/AABB_tree/test/AABB_tree/AABB_test_util.h index fae5abfe17c..a0cbef01e49 100644 --- a/AABB_tree/test/AABB_tree/AABB_test_util.h +++ b/AABB_tree/test/AABB_tree/AABB_test_util.h @@ -246,7 +246,7 @@ void test(const std::string filename, typedef CGAL::Polyhedron_3 Polyhedron; typedef Primitive_generator Pr_generator; typedef typename Pr_generator::Primitive Pr; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; Polyhedron polyhedron; @@ -316,13 +316,13 @@ class Naive_implementations { typedef Primitive_generator Pr_generator; typedef typename Pr_generator::Primitive Pr; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef typename Pr_generator::iterator Polyhedron_primitive_iterator; typedef unsigned int size_type; typedef typename Traits::Object_and_primitive_id Object_and_primitive_id; typedef typename Pr::Id Primitive_id; typedef typename Traits::FT FT; - typedef typename Traits::Point_3 Point; + typedef typename Traits::Point Point; typedef typename Traits::Point_and_primitive_id Point_and_primitive_id; typedef std::optional Intersection_result; diff --git a/AABB_tree/test/AABB_tree/aabb_any_all_benchmark.cpp b/AABB_tree/test/AABB_tree/aabb_any_all_benchmark.cpp index eb6fef9082a..d4af45426aa 100644 --- a/AABB_tree/test/AABB_tree/aabb_any_all_benchmark.cpp +++ b/AABB_tree/test/AABB_tree/aabb_any_all_benchmark.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -64,7 +64,7 @@ std::tuple test(const char* name) { typedef CGAL::Polyhedron_3 Polyhedron; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; std::ifstream ifs(name); 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 54ef4c600f6..39a1cfc9baa 100644 --- a/AABB_tree/test/AABB_tree/aabb_correctness_triangle_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_correctness_triangle_test.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include template @@ -43,7 +43,7 @@ int test() // construct tree from facets typedef typename CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef typename CGAL::AABB_traits Traits; + typedef typename CGAL::AABB_traits_3 Traits; typedef typename CGAL::AABB_tree Tree; typedef typename Tree::Object_and_primitive_id Object_and_primitive_id; Tree tree(faces(polyhedron).first, faces(polyhedron).second, polyhedron); diff --git a/AABB_tree/test/AABB_tree/aabb_deprecated_segment_test.cpp b/AABB_tree/test/AABB_tree/aabb_deprecated_segment_test.cpp new file mode 100644 index 00000000000..f7f13eaf7b5 --- /dev/null +++ b/AABB_tree/test/AABB_tree/aabb_deprecated_segment_test.cpp @@ -0,0 +1,56 @@ +#include + +#include +#include + +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K; + +typedef K::FT FT; +typedef K::Point_3 Point; +typedef K::Plane_3 Plane; +typedef K::Segment_3 Segment; +typedef K::Triangle_3 Triangle; + +typedef std::list::iterator Iterator; +typedef CGAL::AABB_segment_primitive Primitive; +typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_tree Tree; + +int main() +{ + Point a(1.0, 0.0, 0.0); + Point b(0.0, 1.0, 0.0); + Point c(0.0, 0.0, 1.0); + Point d(0.0, 0.0, 0.0); + + std::list segments; + segments.push_back(Segment(a,b)); + segments.push_back(Segment(a,c)); + segments.push_back(Segment(c,d)); + + // constructs the AABB tree and the internal search tree for + // efficient distance computations. + Tree tree(segments.begin(),segments.end()); + + // counts #intersections with a plane query + Plane plane_query(a,b,d); + std::cout << tree.number_of_intersected_primitives(plane_query) + << " intersections(s) with plane" << std::endl; + + // counts #intersections with a triangle query + Triangle triangle_query(a,b,c); + std::cout << tree.number_of_intersected_primitives(triangle_query) + << " intersections(s) with triangle" << std::endl; + + // computes the closest point from a point query + Point point_query(2.0, 2.0, 2.0); + Point closest = tree.closest_point(point_query); + + std::cerr << "closest point is: " << closest << std::endl; + return EXIT_SUCCESS; +} diff --git a/AABB_tree/test/AABB_tree/aabb_deprecated_triangle_primitive_test.cpp b/AABB_tree/test/AABB_tree/aabb_deprecated_triangle_primitive_test.cpp new file mode 100644 index 00000000000..4881e0a8f8b --- /dev/null +++ b/AABB_tree/test/AABB_tree/aabb_deprecated_triangle_primitive_test.cpp @@ -0,0 +1,51 @@ +#include + +#include +#include + +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K; + +typedef K::FT FT; +typedef K::Ray_3 Ray; +typedef K::Point_3 Point; +typedef K::Triangle_3 Triangle; + +typedef std::list::iterator Iterator; +typedef CGAL::AABB_triangle_primitive Primitive; +typedef CGAL::AABB_traits AABB_triangle_traits; +typedef CGAL::AABB_tree Tree; + +int main() +{ + Point a(1.0, 0.0, 0.0); + Point b(0.0, 1.0, 0.0); + Point c(0.0, 0.0, 1.0); + Point d(0.0, 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); + assert(tree.number_of_intersected_primitives(ray_query) != 0); + + // compute closest point and squared distance + Point point_query(2.0, 2.0, 2.0); + Point closest_point = tree.closest_point(point_query); + std::cout << closest_point << std::endl; + + FT sqd = tree.squared_distance(point_query); + std::cout << sqd << std::endl; + + return EXIT_SUCCESS; +} diff --git a/AABB_tree/test/AABB_tree/aabb_distance_edge_test.cpp b/AABB_tree/test/AABB_tree/aabb_distance_edge_test.cpp index 36c3ab9f83a..de9ec85e764 100644 --- a/AABB_tree/test/AABB_tree/aabb_distance_edge_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_distance_edge_test.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include diff --git a/AABB_tree/test/AABB_tree/aabb_distance_triangle_hint_test.cpp b/AABB_tree/test/AABB_tree/aabb_distance_triangle_hint_test.cpp index 28186a346c8..5d1c7cf1271 100644 --- a/AABB_tree/test/AABB_tree/aabb_distance_triangle_hint_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_distance_triangle_hint_test.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include diff --git a/AABB_tree/test/AABB_tree/aabb_distance_triangle_test.cpp b/AABB_tree/test/AABB_tree/aabb_distance_triangle_test.cpp index 4bc056680f1..6e52a364d92 100644 --- a/AABB_tree/test/AABB_tree/aabb_distance_triangle_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_distance_triangle_test.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include "AABB_test_util.h" diff --git a/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp b/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp index 36682056700..b335cd5adfe 100644 --- a/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include "AABB_test_util.h" diff --git a/AABB_tree/test/AABB_tree/aabb_naive_vs_tree_distance_segment_test.cpp b/AABB_tree/test/AABB_tree/aabb_naive_vs_tree_distance_segment_test.cpp index 24d7ae9f502..85507b16b55 100644 --- a/AABB_tree/test/AABB_tree/aabb_naive_vs_tree_distance_segment_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_naive_vs_tree_distance_segment_test.cpp @@ -27,7 +27,7 @@ #include #include -#include +#include #include "AABB_test_util.h" diff --git a/AABB_tree/test/AABB_tree/aabb_naive_vs_tree_distance_triangle_test.cpp b/AABB_tree/test/AABB_tree/aabb_naive_vs_tree_distance_triangle_test.cpp index dc63bbb5253..ceea242df17 100644 --- a/AABB_tree/test/AABB_tree/aabb_naive_vs_tree_distance_triangle_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_naive_vs_tree_distance_triangle_test.cpp @@ -27,7 +27,7 @@ #include #include -#include +#include #include "AABB_test_util.h" diff --git a/AABB_tree/test/AABB_tree/aabb_naive_vs_tree_triangle_test.cpp b/AABB_tree/test/AABB_tree/aabb_naive_vs_tree_triangle_test.cpp index 2d8b5e7a3ac..4c1660be97e 100644 --- a/AABB_tree/test/AABB_tree/aabb_naive_vs_tree_triangle_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_naive_vs_tree_triangle_test.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include "AABB_test_util.h" diff --git a/AABB_tree/test/AABB_tree/aabb_test_all_intersected_primitives_tree.cpp b/AABB_tree/test/AABB_tree/aabb_test_all_intersected_primitives_tree.cpp index c0c7d160fd0..d3d735a6d65 100644 --- a/AABB_tree/test/AABB_tree/aabb_test_all_intersected_primitives_tree.cpp +++ b/AABB_tree/test/AABB_tree/aabb_test_all_intersected_primitives_tree.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include #include @@ -24,8 +24,8 @@ CGAL::Tag_false> S_Primitive; typedef CGAL::AABB_face_graph_triangle_primitive T_Primitive; -typedef CGAL::AABB_traits T_Traits; -typedef CGAL::AABB_traits S_Traits; +typedef CGAL::AABB_traits_3 T_Traits; +typedef CGAL::AABB_traits_3 S_Traits; typedef CGAL::AABB_tree T_Tree; typedef CGAL::AABB_tree S_Tree; typedef T_Tree::Primitive_id T_Primitive_id; diff --git a/AABB_tree/test/AABB_tree/aabb_test_datum.cpp b/AABB_tree/test/AABB_tree/aabb_test_datum.cpp index dc732d40265..5cac9a6f3f2 100644 --- a/AABB_tree/test/AABB_tree/aabb_test_datum.cpp +++ b/AABB_tree/test/AABB_tree/aabb_test_datum.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include @@ -15,22 +15,22 @@ typedef K::Point_3 Point; typedef K::Triangle_3 Triangle; typedef CGAL::Surface_mesh Mesh; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; -typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; typedef CGAL::AABB_face_graph_triangle_primitive Primitive2; -typedef CGAL::AABB_traits Traits2; +typedef CGAL::AABB_traits_3 Traits2; typedef CGAL::AABB_tree Tree2; typedef CGAL::AABB_face_graph_triangle_primitive Primitive3; -typedef CGAL::AABB_traits Traits3; +typedef CGAL::AABB_traits_3 Traits3; typedef CGAL::AABB_tree Tree3; typedef CGAL::AABB_face_graph_triangle_primitive Primitive4; -typedef CGAL::AABB_traits Traits4; +typedef CGAL::AABB_traits_3 Traits4; typedef CGAL::AABB_tree Tree4; int main(void) diff --git a/AABB_tree/test/AABB_tree/aabb_test_empty_tree.cpp b/AABB_tree/test/AABB_tree/aabb_test_empty_tree.cpp index c10ea5f1acf..9c939a58314 100644 --- a/AABB_tree/test/AABB_tree/aabb_test_empty_tree.cpp +++ b/AABB_tree/test/AABB_tree/aabb_test_empty_tree.cpp @@ -3,8 +3,8 @@ #include #include -#include -#include +#include +#include #include typedef CGAL::Simple_cartesian K; @@ -16,8 +16,8 @@ typedef K::Segment_3 Segment; typedef K::Triangle_3 Triangle; typedef std::vector::iterator Iterator; -typedef CGAL::AABB_segment_primitive Primitive; -typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_segment_primitive_3 Primitive; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; int main() diff --git a/AABB_tree/test/AABB_tree/aabb_test_indexed_triangle_2.cpp b/AABB_tree/test/AABB_tree/aabb_test_indexed_triangle_2.cpp new file mode 100644 index 00000000000..3f7b5fc5bb1 --- /dev/null +++ b/AABB_tree/test/AABB_tree/aabb_test_indexed_triangle_2.cpp @@ -0,0 +1,86 @@ +#include +#include +#include + +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K; +typedef K::Point_3 Point_3; +typedef K::Point_2 Point_2; +typedef K::Ray_2 Ray; + +template +struct Projection_xy_point_map { + + typedef typename GeomTraits::Point_3 key_type; + typedef typename GeomTraits::Point_2 value_type; + typedef value_type reference; + + typedef boost::readable_property_map_tag category; + typedef Projection_xy_point_map Self; + + Projection_xy_point_map() {} + + inline friend value_type get(Self, key_type p) + { + return value_type(p.x(), p.y()); + } +}; + +typedef std::vector >::const_iterator IndexIterator; +typedef std::vector PointRange; +typedef CGAL::AABB_indexed_triangle_primitive_2> Primitive; +typedef CGAL::AABB_traits_2 AABB_triangle_traits; +typedef CGAL::AABB_tree Tree; +typedef Tree::Point_and_primitive_id Point_and_primitive_id; +typedef std::optional::Type> Ray_intersection; + +int main() +{ + Point_3 a(0.0, 0.0, 0.0); + Point_3 b(0.0, 1.0, 0.0); + Point_3 c(1.0, 0.0, 0.0); + Point_3 d(1.0, 1.0, 0.0); + Point_3 e(2.0, 0.0, 0.0); + Point_3 f(2.0, 1.0, 0.0); + + std::vector points = { a, b, c, d, e, f }; + + std::vector > triangles; + triangles.push_back({ 0, 2, 1 }); + triangles.push_back({ 1, 2, 3 }); + triangles.push_back({ 3, 2, 4 }); + triangles.push_back({ 3, 4, 5 }); + + // constructs AABB tree + Tree tree(triangles.begin(), triangles.end(), points); + + // point sampling + Point_and_primitive_id id; + id = tree.closest_point_and_primitive(Point_2(0.5, 0.4)); + assert(std::distance(triangles.cbegin(), id.second) == 0); + id = tree.closest_point_and_primitive(Point_2(0.5, 0.6)); + assert(std::distance(triangles.cbegin(), id.second) == 1); + id = tree.closest_point_and_primitive(Point_2(1.5, 0.4)); + assert(std::distance(triangles.cbegin(), id.second) == 2); + id = tree.closest_point_and_primitive(Point_2(1.5, 0.6)); + assert(std::distance(triangles.cbegin(), id.second) == 3); + id = tree.closest_point_and_primitive(Point_2(3.0, 0.5)); + assert(std::distance(triangles.cbegin(), id.second) == 3); + + Ray ray(Point_2(5.5, 0.5), Point_2(1.5, 0.4)); + Ray_intersection intersection = tree.first_intersection(ray); + + assert(intersection.has_value()); + + assert(std::distance(triangles.cbegin(), intersection->second) == 3); + + std::list intersections; + tree.all_intersections(ray, std::back_inserter(intersections)); + assert(intersections.size() == 4); + + return EXIT_SUCCESS; +} diff --git a/AABB_tree/test/AABB_tree/aabb_test_move_constructor.cpp b/AABB_tree/test/AABB_tree/aabb_test_move_constructor.cpp index 7f61faf6b7c..b9e61b4ece2 100644 --- a/AABB_tree/test/AABB_tree/aabb_test_move_constructor.cpp +++ b/AABB_tree/test/AABB_tree/aabb_test_move_constructor.cpp @@ -6,8 +6,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -32,8 +32,8 @@ class TestCase<0> typedef K::Segment_3 Segment; typedef K::Triangle_3 Triangle; typedef std::vector::iterator Iterator; - typedef CGAL::AABB_segment_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_segment_primitive_3 Primitive; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; public: @@ -106,8 +106,8 @@ class TestCase<1> typedef CGAL::AABB_face_graph_triangle_primitive T_Primitive; - typedef CGAL::AABB_traits T_Traits; - typedef CGAL::AABB_traits S_Traits; + typedef CGAL::AABB_traits_3 T_Traits; + typedef CGAL::AABB_traits_3 S_Traits; typedef CGAL::AABB_tree T_Tree; typedef CGAL::AABB_tree S_Tree; typedef T_Tree::Primitive_id T_Primitive_id; diff --git a/AABB_tree/test/AABB_tree/aabb_test_multi_mesh.cpp b/AABB_tree/test/AABB_tree/aabb_test_multi_mesh.cpp index 3b2307a134b..858db52e1b4 100644 --- a/AABB_tree/test/AABB_tree/aabb_test_multi_mesh.cpp +++ b/AABB_tree/test/AABB_tree/aabb_test_multi_mesh.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include @@ -25,14 +25,14 @@ typedef CGAL::Surface_mesh > Mesh; typedef CGAL::AABB_face_graph_triangle_primitive T_Primitive; -typedef CGAL::AABB_traits T_Traits; +typedef CGAL::AABB_traits_3 T_Traits; typedef CGAL::AABB_tree T_Tree; typedef T_Tree::Primitive_id T_Primitive_id; typedef CGAL::AABB_halfedge_graph_segment_primitive E_Primitive; -typedef CGAL::AABB_traits E_Traits; +typedef CGAL::AABB_traits_3 E_Traits; typedef CGAL::AABB_tree E_Tree; typedef E_Tree::Primitive_id E_Primitive_id; diff --git a/AABB_tree/test/AABB_tree/aabb_test_polyline_segment_2.cpp b/AABB_tree/test/AABB_tree/aabb_test_polyline_segment_2.cpp new file mode 100644 index 00000000000..63df363e357 --- /dev/null +++ b/AABB_tree/test/AABB_tree/aabb_test_polyline_segment_2.cpp @@ -0,0 +1,66 @@ +#include +#include + +#include +#include +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K; +typedef K::Segment_2 Segment; +typedef K::Point_2 Point; + +typedef std::vector PointRange; +typedef PointRange::const_iterator Iterator_pr; +typedef CGAL::AABB_polyline_segment_primitive_2 Primitive_pr; +typedef CGAL::AABB_traits_2 Traits_pr; +typedef CGAL::AABB_tree Tree_pr; +typedef Tree_pr::Point_and_primitive_id Point_and_primitive_id_pr; + +typedef CGAL::Polygon_2 Polygon_2; +typedef Polygon_2::const_iterator Iterator_poly; +typedef CGAL::AABB_polyline_segment_primitive_2 Primitive_poly; +typedef CGAL::AABB_traits_2 Traits_poly; +typedef CGAL::AABB_tree Tree_poly; +typedef Tree_poly::Point_and_primitive_id Point_and_primitive_id_poly; + +template +void test(AABBTree tree) { + tree.build(); + + tree.accelerate_distance_queries(); + + // counts #intersections with a segment query + Segment segment_query(Point(1.0, 0.0), Point(0.0, 7.0)); + + assert(tree.number_of_intersected_primitives(segment_query) == 2); + + // computes the closest point from a point query + Point point_query(4.0, 5.0); + Point closest = tree.closest_point(point_query); + assert(closest == Point(3.0, 4.0)); + + PPId id = tree.closest_point_and_primitive(point_query); + assert(id.first == closest); +} + +int main() +{ + Point a(0.0, 0.0); + Point b(2.0, 1.0); + Point c(3.0, 4.0); + Point d(1.0, 6.0); + Point e(-1.0, 3.0); + + std::vector polyline = { a, b, c, d, e }; + + Polygon_2 poly(polyline.begin(), polyline.end()); + + test(Tree_poly(poly.begin(), poly.end(), poly)); + + test(Tree_pr(polyline.begin(), std::prev(polyline.end()), polyline)); + + return EXIT_SUCCESS; +} diff --git a/AABB_tree/test/AABB_tree/aabb_test_ray_intersection.cpp b/AABB_tree/test/AABB_tree/aabb_test_ray_intersection.cpp index 8ca781ff114..aa4668273aa 100644 --- a/AABB_tree/test/AABB_tree/aabb_test_ray_intersection.cpp +++ b/AABB_tree/test/AABB_tree/aabb_test_ray_intersection.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include @@ -23,7 +23,7 @@ typedef K::Segment_3 Segment; typedef K::Ray_3 Ray; typedef CGAL::Polyhedron_3 Polyhedron; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; -typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; typedef Tree::Primitive_id Primitive_id; typedef CGAL::Timer Timer; diff --git a/AABB_tree/test/AABB_tree/aabb_test_segment_2.cpp b/AABB_tree/test/AABB_tree/aabb_test_segment_2.cpp new file mode 100644 index 00000000000..2ccfa1f2f97 --- /dev/null +++ b/AABB_tree/test/AABB_tree/aabb_test_segment_2.cpp @@ -0,0 +1,58 @@ +#include +#include + +#include +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K; + +typedef K::FT FT; +typedef K::Segment_2 Segment; +typedef K::Point_2 Point; + +typedef std::list SegmentRange; +typedef SegmentRange::const_iterator Iterator; +typedef CGAL::AABB_segment_primitive_2 Primitive; +typedef CGAL::AABB_traits_2 Traits; +typedef CGAL::AABB_tree Tree; +typedef Tree::Point_and_primitive_id Point_and_primitive_id; + +int main() +{ + Point a(0.0, 0.0); + Point b(2.0, 1.0); + Point c(3.0, 4.0); + Point d(1.0, 6.0); + Point e(-1.0, 3.0); + + std::list seg; + seg.push_back(Segment(a, b)); + seg.push_back(Segment(b, c)); + seg.push_back(Segment(c, d)); + seg.push_back(Segment(d, e)); + seg.push_back(Segment(e, a)); + + // constructs the AABB tree and the internal search tree for + // efficient distance computations. + Tree tree(seg.begin(), seg.end()); + tree.build(); + + tree.accelerate_distance_queries(); + + // counts #intersections with a segment query + Segment segment_query(Point(1.0, 0.0), Point(0.0, 7.0)); + assert(tree.number_of_intersected_primitives(segment_query) == 2); + + // computes the closest point from a point query + Point point_query(5.0, 5.0); + Point closest = tree.closest_point(point_query); + assert(closest == c); + + Point_and_primitive_id id = tree.closest_point_and_primitive(Point(1.5, 3.0)); + assert(id.second->source() == b && id.second->target() == c); + + return EXIT_SUCCESS; +} diff --git a/AABB_tree/test/AABB_tree/aabb_test_singleton_tree.cpp b/AABB_tree/test/AABB_tree/aabb_test_singleton_tree.cpp index cc26689d64e..84e5cd5d934 100644 --- a/AABB_tree/test/AABB_tree/aabb_test_singleton_tree.cpp +++ b/AABB_tree/test/AABB_tree/aabb_test_singleton_tree.cpp @@ -3,8 +3,8 @@ #include #include -#include -#include +#include +#include #include typedef CGAL::Simple_cartesian K; @@ -16,8 +16,8 @@ typedef K::Segment_3 Segment; typedef K::Triangle_3 Triangle; typedef std::vector::iterator Iterator; -typedef CGAL::AABB_segment_primitive Primitive; -typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_segment_primitive_3 Primitive; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; int main() diff --git a/AABB_tree/test/AABB_tree/aabb_test_triangle_2.cpp b/AABB_tree/test/AABB_tree/aabb_test_triangle_2.cpp new file mode 100644 index 00000000000..ede2cc4d2af --- /dev/null +++ b/AABB_tree/test/AABB_tree/aabb_test_triangle_2.cpp @@ -0,0 +1,50 @@ +// 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::const_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); + assert(tree.number_of_intersected_primitives(ray_query) == 3); + + // compute closest point and squared distance + Point point_query(2.0, 2.0); + Point closest_point = tree.closest_point(point_query); + assert(closest_point == c); + + assert(tree.squared_distance(point_query) == 2); + + return EXIT_SUCCESS; +} diff --git a/AABB_tree/test/AABB_tree/aabb_test_triangle_3.cpp b/AABB_tree/test/AABB_tree/aabb_test_triangle_3.cpp new file mode 100644 index 00000000000..12c2366260e --- /dev/null +++ b/AABB_tree/test/AABB_tree/aabb_test_triangle_3.cpp @@ -0,0 +1,49 @@ +// Author(s) : Camille Wormser, Pierre Alliez + +#include +#include + +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K; + +typedef K::FT FT; +typedef K::Ray_3 Ray; +typedef K::Point_3 Point; +typedef K::Triangle_3 Triangle; + +typedef std::list::const_iterator Iterator; +typedef CGAL::AABB_triangle_primitive_3 Primitive; +typedef CGAL::AABB_traits_3 AABB_triangle_traits; +typedef CGAL::AABB_tree Tree; + +int main() +{ + Point a(1.0, 0.0, 0.0); + Point b(0.0, 1.0, 0.0); + Point c(0.0, 0.0, 1.0); + Point d(0.0, 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); + assert(tree.number_of_intersected_primitives(ray_query) == 3); + + // compute closest point and squared distance + Point point_query(3.0, 2.0, 2.0); + Point closest_point = tree.closest_point(point_query); + assert(closest_point == a); + assert(tree.squared_distance(point_query) == 12); + + return EXIT_SUCCESS; +} diff --git a/AABB_tree/test/AABB_tree/aabb_triangle_datum_covering.cpp b/AABB_tree/test/AABB_tree/aabb_triangle_datum_covering.cpp index bfd756fd0ae..e13416a9888 100644 --- a/AABB_tree/test/AABB_tree/aabb_triangle_datum_covering.cpp +++ b/AABB_tree/test/AABB_tree/aabb_triangle_datum_covering.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include @@ -29,7 +29,7 @@ void test_no_cover(const Mesh& mesh) using Line_3 = typename GT::Line_3; using Primitive = CGAL::AABB_face_graph_triangle_primitive; - using Traits = CGAL::AABB_traits; + using Traits = CGAL::AABB_traits_3; using Tree = CGAL::AABB_tree; // Build @@ -99,7 +99,7 @@ void test_cover(const Mesh& mesh, using AABB_tree = CGAL::AABB_trees::internal::AABB_covered_triangle_tree; using FG_Primitive = CGAL::AABB_face_graph_triangle_primitive; - using FG_Traits = CGAL::AABB_traits; + using FG_Traits = CGAL::AABB_traits_3; using FG_Tree = CGAL::AABB_tree; CGAL::Bbox_3 bbox = CGAL::Polygon_mesh_processing::bbox(mesh); diff --git a/Alpha_wrap_3/benchmark/Alpha_wrap_3/Quality/distance_utils.h b/Alpha_wrap_3/benchmark/Alpha_wrap_3/Quality/distance_utils.h index 379573e9c90..28af30181d4 100644 --- a/Alpha_wrap_3/benchmark/Alpha_wrap_3/Quality/distance_utils.h +++ b/Alpha_wrap_3/benchmark/Alpha_wrap_3/Quality/distance_utils.h @@ -15,7 +15,7 @@ #define CGAL_ALPHA_WRAP_3_BENCHMARK_ALPHA_WRAP_3_QUALITY_DISTANCE_H_ #include -#include +#include #include #include #include @@ -87,7 +87,7 @@ inline double approximate_distance(const TriangleMesh& tm1, using Point_3 = typename GT::Point_3; using Primitive = CGAL::AABB_face_graph_triangle_primitive; - using AABB_traits = CGAL::AABB_traits; + using AABB_traits = CGAL::AABB_traits_3; using AABB_tree = CGAL::AABB_tree; using CGAL::parameters::choose_parameter; diff --git a/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Oracle_base.h b/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Oracle_base.h index 7f3534a484c..5e105f83047 100644 --- a/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Oracle_base.h +++ b/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Oracle_base.h @@ -49,7 +49,7 @@ struct AABB_tree_oracle_helper using GT = typename AABB_traits::Geom_traits; using FT = typename AABB_traits::FT; - using Point_3 = typename AABB_traits::Point_3; + using Point_3 = typename AABB_traits::Point; template static bool do_intersect(const Query& query, diff --git a/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Point_set_oracle.h b/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Point_set_oracle.h index 33f8a52b178..d35a20c93fa 100644 --- a/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Point_set_oracle.h +++ b/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Point_set_oracle.h @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include @@ -51,7 +51,7 @@ struct PS_oracle_traits CGAL::Tag_false, // not external CGAL::Tag_false>; // no caching - using AABB_traits = CGAL::AABB_traits; + using AABB_traits = CGAL::AABB_traits_3; using AABB_tree = CGAL::AABB_tree; }; diff --git a/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Segment_soup_oracle.h b/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Segment_soup_oracle.h index 349cd012ef7..88d565c6b66 100644 --- a/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Segment_soup_oracle.h +++ b/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Segment_soup_oracle.h @@ -17,9 +17,9 @@ #include #include -#include +#include #include -#include +#include #include #include #include @@ -52,7 +52,7 @@ struct SS_oracle_traits CGAL::Tag_false, // not external CGAL::Tag_false>; // no caching - using AABB_traits = CGAL::AABB_traits; + using AABB_traits = CGAL::AABB_traits_3; using AABB_tree = CGAL::AABB_tree; }; diff --git a/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Triangle_soup_oracle.h b/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Triangle_soup_oracle.h index dadfb5d8be1..d066107f620 100644 --- a/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Triangle_soup_oracle.h +++ b/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/Triangle_soup_oracle.h @@ -18,8 +18,8 @@ #include #include -#include -#include +#include +#include #include #include #include diff --git a/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/splitting_helper.h b/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/splitting_helper.h index 617c76fd104..4f72b5583ed 100644 --- a/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/splitting_helper.h +++ b/Alpha_wrap_3/include/CGAL/Alpha_wrap_3/internal/splitting_helper.h @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include @@ -83,7 +83,7 @@ struct Splitter_traversal_traits : public CGAL::internal::AABB_tree::Projection_traits { using Base = CGAL::internal::AABB_tree::Projection_traits; - using Point = typename AABBTraits::Point_3; + using Point = typename AABBTraits::Point; using Primitive = typename AABBTraits::Primitive; std::unordered_set visited_data; @@ -192,7 +192,7 @@ struct AABB_tree_splitter_traits CGAL::Tag_true /*external pmaps*/, CGAL::Tag_false /*no caching*/>; - using AABB_traits = CGAL::AABB_traits; + using AABB_traits = CGAL::AABB_traits_3; using AABB_tree = CGAL::AABB_tree; }; diff --git a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h index 737a52dfc14..8b0153f03e1 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h @@ -3278,6 +3278,8 @@ namespace CartesianKernelFunctors { { typedef typename K::Point_2 Point_2; typedef typename K::Line_2 Line_2; + typedef typename K::Segment_2 Segment_2; + typedef typename K::Triangle_2 Triangle_2; public: typedef Point_2 result_type; @@ -3289,6 +3291,14 @@ namespace CartesianKernelFunctors { line_project_pointC2(l.a(), l.b(), l.c(), p.x(), p.y(), x, y); return construct_point_2(x, y); } + + Point_2 + operator()(const Segment_2& s, const Point_2& p) const + { return CommonKernelFunctors::Construct_projected_point_2()(s, p, K()); } + + Point_2 + operator()(const Triangle_2& t, const Point_2& p) const + { return CommonKernelFunctors::Construct_projected_point_2()(t, p, K()); } }; diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index 7bf361cec58..d0ce193ea84 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -28,6 +28,18 @@ Release date: June 2024 - This package provides functions to repair polygons, polygons with holes, and multipolygons with holes using the odd-even heuristic. +### [2D and 3D Fast Intersection and Distance Computation (AABB Tree)](https://doc.cgal.org/6.0/Manual/packages.html#PkgAABBTree) + +- **Breaking change**: The concept `AABBTraits` now refines the `SearchTraits` concept. +- The AABB tree is now working with 2D and 3D primitives: + - Replacement of `AABBGeomTraits` concept by `AABBGeomTraits_3` and `AABBRayIntersectionGeomTraits` by `AABBRayIntersectionGeomTraits_3`. + - Addition of `AABBGeomTraits_2` and `AABBRayIntersectionGeomTraits_2` concepts + - `CGAL::AABB_traits` is deprecated and replaced by `CGAL::AABB_traits_3` + - Addition of `CGAL::AABB_traits_2` + - `CGAL::AABB_segment_primitive` is deprecated and replaced by `CGAL::AABB_segment_primitive_3` + - `CGAL::AABB_triangle_primitive` is deprecated and replaced by `CGAL::AABB_triangle_primitive_3` + - Addition of 2D primitive classes: `CGAL::AABB_segment_primitive_2`, `CGAL::AABB_polyline_segment_primitive_2`, `CGAL::AABB_triangle_primitive_2`, `CGAL::AABB_indexed_triangle_primitive_2` + #### 2D Arrangements - **Breaking change**: The type of the result of point location queries changed to diff --git a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h index 7e4e6661523..77cd20715ad 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h +++ b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h @@ -6078,6 +6078,18 @@ public: Kernel::Point_2 operator()(const Kernel::Line_2& l, const Kernel::Point_2& p); + /*! + returns the point of `s` that is the closest to `p`. + */ + Kernel::Point_2 operator()(const Kernel::Segment_2& s, + const Kernel::Point_2& p); + + /*! + returns the point of `t` that is the closest to `p`. + */ + Kernel::Point_2 operator()(const Kernel::Triangle_2& t, + const Kernel::Point_3& p); + /// @} }; /* end Kernel::ConstructProjectedPoint_2 */ diff --git a/Kernel_23/include/CGAL/Kernel/function_objects.h b/Kernel_23/include/CGAL/Kernel/function_objects.h index 084a6578913..71e56de4785 100644 --- a/Kernel_23/include/CGAL/Kernel/function_objects.h +++ b/Kernel_23/include/CGAL/Kernel/function_objects.h @@ -2874,6 +2874,206 @@ namespace CommonKernelFunctors { } }; + template + class Construct_projected_point_2 + { + bool + is_inside_triangle_2_aux( + const typename K::Point_2& p1, + const typename K::Point_2& p2, + const typename K::Point_2& q, + typename K::Point_2& result, + bool& outside, + const K& k) + { + typedef typename K::Vector_2 Vector_2; + typedef typename K::FT FT; + + typename K::Construct_vector_2 vector = + k.construct_vector_2_object(); + typename K::Construct_projected_point_2 projection = + k.construct_projected_point_2_object(); + typename K::Construct_line_2 line = + k.construct_line_2_object(); + typename K::Compute_scalar_product_2 scalar_product = + k.compute_scalar_product_2_object(); + typename K::Construct_direction_2 direction = + k.construct_direction_2_object(); + typename K::Construct_perpendicular_direction_2 perpendicular = + k.construct_perpendicular_direction_2_object(); + + // Check whether the point is cw or ccw with the triangle side (p1,p2) + Vector_2 orth = vector(p1, p2); + + if (scalar_product(vector(p1, q), vector(perpendicular(direction(orth), CGAL::COUNTERCLOCKWISE))) < FT(0)) + { + if (scalar_product(vector(p1, q), vector(p1, p2)) >= FT(0) + && scalar_product(vector(p2, q), vector(p2, p1)) >= FT(0)) + { + result = projection(line(p1, p2), q); + return true; + } + outside = true; + } + + return false; + } + + /** + * Returns the nearest point of `p1`, `p2`, `p3` from origin + * @param origin the origin point + * @param p1 the first point + * @param p2 the second point + * @param p3 the third point + * @param k the kernel + * @return the nearest point from origin + */ + typename K::Point_2 + nearest_point_2(const typename K::Point_2& origin, + const typename K::Point_2& p1, + const typename K::Point_2& p2, + const typename K::Point_2& p3, + const K& k) + { + typedef typename K::FT FT; + + typename K::Compute_squared_distance_2 sq_distance = + k.compute_squared_distance_2_object(); + + const FT dist_origin_p1 = sq_distance(origin, p1); + const FT dist_origin_p2 = sq_distance(origin, p2); + const FT dist_origin_p3 = sq_distance(origin, p3); + + if (dist_origin_p2 >= dist_origin_p1 + && dist_origin_p3 >= dist_origin_p1) + { + return p1; + } + if (dist_origin_p3 >= dist_origin_p2) + { + return p2; + } + + return p3; + } + + /** + * @brief returns true if p is inside triangle t. If p is not inside t, + * result is the nearest point of t from p. + * @param p the reference point + * @param t the triangle + * @param result if p is not inside t, the nearest point of t from p + * @param k the kernel + * @return true if p is inside t + */ + bool + is_inside_triangle_2(const typename K::Point_2& p, + const typename K::Triangle_2& t, + typename K::Point_2& result, + const K& k) + { + typedef typename K::Point_2 Point_2; + + typename K::Construct_vertex_2 vertex_on = + k.construct_vertex_2_object(); + + const Point_2& t0 = vertex_on(t, 0); + const Point_2& t1 = vertex_on(t, 1); + const Point_2& t2 = vertex_on(t, 2); + + bool outside = false; + if (is_inside_triangle_2_aux(t0, t1, p, result, outside, k) + || is_inside_triangle_2_aux(t1, t2, p, result, outside, k) + || is_inside_triangle_2_aux(t2, t0, p, result, outside, k)) + { + return false; + } + + if (outside) + { + result = nearest_point_2(p, t0, t1, t2, k); + return false; + } + else + { + return true; + } + } + + public: + typename K::Point_2 + operator()(const typename K::Triangle_2& triangle, + const typename K::Point_2& origin, + const K& k) + { + typedef typename K::Point_2 Point_2; + typename K::Construct_vertex_2 vertex_on; + typename K::Construct_segment_2 segment; + + // Check if triangle is degenerated to call segment operator. + const Point_2& t0 = vertex_on(triangle, 0); + const Point_2& t1 = vertex_on(triangle, 1); + const Point_2& t2 = vertex_on(triangle, 2); + + if (t0 == t1) + return (*this)(segment(t1, t2), origin, k); + if (t1 == t2) + return (*this)(segment(t2, t0), origin, k); + if (t2 == t0) + return (*this)(segment(t0, t1), origin, k); + + Point_2 moved_point; + bool inside = is_inside_triangle_2(origin, triangle, moved_point, k); + + // If proj is inside triangle, return it + if (inside) + { + return origin; + } + + // Else return the constructed point + return moved_point; + } + + typename K::Point_2 + operator()(const typename K::Segment_2& s, + const typename K::Point_2& query, + const K& k) { + + typename K::Construct_vector_2 vector = + k.construct_vector_2_object(); + + typename K::Compute_scalar_product_2 scalar_product = + k.compute_scalar_product_2_object(); + + typename K::Construct_scaled_vector_2 scaled_vector = + k.construct_scaled_vector_2_object(); + + const typename K::Point_2& a = s.source(); + const typename K::Point_2& b = s.target(); + const typename K::Vector_2 d = vector(a, b); + + typename K::FT sqlen = scalar_product(d, d); + + // Degenerate segment + if (is_zero(sqlen)) + return a; + + const typename K::Vector_2 p = vector(a, query); + + typename K::FT proj = (scalar_product(p, d)) / sqlen; + + if (!is_positive(proj)) + return a; + + if (proj >= 1.0) + return b; + + typename K::Construct_point_2 construct_point_2; + return construct_point_2(a + scaled_vector(d, proj)); + } + }; + template class Construct_projected_point_3 { diff --git a/Lab/demo/Lab/Plugins/AABB_tree/Cut_plugin.cpp b/Lab/demo/Lab/Plugins/AABB_tree/Cut_plugin.cpp index c5d3dda9825..e3df0223e50 100644 --- a/Lab/demo/Lab/Plugins/AABB_tree/Cut_plugin.cpp +++ b/Lab/demo/Lab/Plugins/AABB_tree/Cut_plugin.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include @@ -216,11 +216,11 @@ struct PPMAP }; typedef CGAL::AABB_face_graph_triangle_primitive > Facet_sm_primitive; -typedef CGAL::AABB_traits Facet_sm_traits; +typedef CGAL::AABB_traits_3 Facet_sm_traits; typedef CGAL::AABB_tree Facet_sm_tree; typedef CGAL::AABB_halfedge_graph_segment_primitive > Edge_sm_primitive; -typedef CGAL::AABB_traits Edge_sm_traits; +typedef CGAL::AABB_traits_3 Edge_sm_traits; typedef CGAL::AABB_tree Edge_sm_tree; typedef QMap Facet_sm_trees; diff --git a/Lab/demo/Lab/Plugins/Mesh_3/Offset_meshing_plugin.cpp b/Lab/demo/Lab/Plugins/Mesh_3/Offset_meshing_plugin.cpp index a6bee4c8a12..85a1022efc0 100644 --- a/Lab/demo/Lab/Plugins/Mesh_3/Offset_meshing_plugin.cpp +++ b/Lab/demo/Lab/Plugins/Mesh_3/Offset_meshing_plugin.cpp @@ -8,7 +8,7 @@ #include "C3t3_type.h" #include -#include +#include #include #include @@ -53,7 +53,7 @@ template class Offset_function { using Primitive = AABB_face_graph_triangle_primitive; - using Traits = AABB_traits; + using Traits = AABB_traits_3; using Tree = AABB_tree; using Side_of = Side_of_triangle_mesh; @@ -198,7 +198,7 @@ class Polygon_soup_offset_function } }; // struct template Polygon_soup_primitive - using AABB_traits = CGAL::AABB_traits; + using AABB_traits = CGAL::AABB_traits_3; using AABB_tree = CGAL::AABB_tree; std::shared_ptr m_tree_ptr; diff --git a/Lab/demo/Lab/Plugins/PMP/Distance_plugin.cpp b/Lab/demo/Lab/Plugins/PMP/Distance_plugin.cpp index 38fbd35c7cb..aff6a22227c 100644 --- a/Lab/demo/Lab/Plugins/PMP/Distance_plugin.cpp +++ b/Lab/demo/Lab/Plugins/PMP/Distance_plugin.cpp @@ -130,13 +130,13 @@ private: std::vector& out)const { typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree< Traits > Tree; Tree tree( faces(m).first, faces(m).second, m); tree.build(); boost::graph_traits::vertex_descriptor vd = *(vertices(m).first); - Traits::Point_3 hint = get(CGAL::vertex_point,m, vd); + Traits::Point hint = get(CGAL::vertex_point,m, vd); #if !defined(CGAL_LINKED_WITH_TBB) double hdist = 0; diff --git a/Lab/demo/Lab/Plugins/PMP/Engrave_text_plugin.cpp b/Lab/demo/Lab/Plugins/PMP/Engrave_text_plugin.cpp index b02afe6fb9f..e10df4a485c 100644 --- a/Lab/demo/Lab/Plugins/PMP/Engrave_text_plugin.cpp +++ b/Lab/demo/Lab/Plugins/PMP/Engrave_text_plugin.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -307,7 +307,7 @@ private: typedef CGAL::Surface_mesh_shortest_path Surface_mesh_shortest_path; typedef Surface_mesh_shortest_path::Face_location Face_location; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Tree_traits; + typedef CGAL::AABB_traits_3 Tree_traits; typedef CGAL::AABB_tree Tree; typedef EPICK::Point_3 Point_3; Messages_interface* messages; diff --git a/Lab/demo/Lab/Plugins/Point_set/Point_set_to_mesh_distance_plugin.cpp b/Lab/demo/Lab/Plugins/Point_set/Point_set_to_mesh_distance_plugin.cpp index 7cd98d08b0f..2be25bdecc2 100644 --- a/Lab/demo/Lab/Plugins/Point_set/Point_set_to_mesh_distance_plugin.cpp +++ b/Lab/demo/Lab/Plugins/Point_set/Point_set_to_mesh_distance_plugin.cpp @@ -15,8 +15,8 @@ #include -#include -#include +#include +#include #include #include #ifdef CGAL_LINKED_WITH_TBB @@ -73,14 +73,14 @@ double compute_distances(const Mesh& m, std::vector& out) { typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree< Traits > Tree; Tree tree( faces(m).first, faces(m).second, m); tree.build(); typedef typename boost::property_map::const_type VPMap; VPMap vpmap = get(boost::vertex_point, m); - typename Traits::Point_3 hint = get(vpmap, *vertices(m).begin()); + typename Traits::Point hint = get(vpmap, *vertices(m).begin()); #if !defined(CGAL_LINKED_WITH_TBB) double hdist = 0; @@ -97,7 +97,7 @@ double compute_distances(const Mesh& m, #else std::atomic distance; distance.store(0); - Distance_computation f(tree, hint, point_set, &distance, out); + Distance_computation f(tree, hint, point_set, &distance, out); tbb::parallel_for(tbb::blocked_range(point_set.begin(), point_set.end()), f); return distance; #endif diff --git a/Lab/demo/Lab/Plugins/Point_set/Surface_reconstruction_poisson_impl.cpp b/Lab/demo/Lab/Plugins/Point_set/Surface_reconstruction_poisson_impl.cpp index 56b882dd652..11a8fe9a7b3 100644 --- a/Lab/demo/Lab/Plugins/Point_set/Surface_reconstruction_poisson_impl.cpp +++ b/Lab/demo/Lab/Plugins/Point_set/Surface_reconstruction_poisson_impl.cpp @@ -5,7 +5,7 @@ // CGAL #include // must be included before kernel -#include +#include #include #include #include @@ -186,7 +186,7 @@ SMesh* poisson_reconstruct(Point_set& points, // AABB tree typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits AABB_traits; + typedef CGAL::AABB_traits_3 AABB_traits; typedef CGAL::AABB_tree AABB_tree; CGAL::Timer task_timer; task_timer.start(); @@ -393,4 +393,3 @@ SMesh* poisson_reconstruct(Point_set& points, } return mesh; } - diff --git a/Lab/demo/Lab/Plugins/Surface_mesh/Offset_meshing_plugin.cpp b/Lab/demo/Lab/Plugins/Surface_mesh/Offset_meshing_plugin.cpp index 11e779948e8..1c74b95f6fa 100644 --- a/Lab/demo/Lab/Plugins/Surface_mesh/Offset_meshing_plugin.cpp +++ b/Lab/demo/Lab/Plugins/Surface_mesh/Offset_meshing_plugin.cpp @@ -21,7 +21,7 @@ #include "C3t3_type.h" #include -#include +#include #include #include @@ -45,7 +45,7 @@ template class Offset_function { typedef AABB_face_graph_triangle_primitive Primitive; - typedef AABB_traits Traits; + typedef AABB_traits_3 Traits; typedef AABB_tree Tree; typedef Side_of_triangle_mesh Side_of; @@ -169,7 +169,7 @@ class Polygon_soup_offset_function { }; // end struct template AABB_primitive - typedef CGAL::AABB_traits AABB_traits; + typedef CGAL::AABB_traits_3 AABB_traits; typedef CGAL::AABB_tree AABB_tree; std::shared_ptr m_tree_ptr; diff --git a/Lab/demo/Lab/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.cpp b/Lab/demo/Lab/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.cpp index f32bef66a0f..90477043da7 100644 --- a/Lab/demo/Lab/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.cpp +++ b/Lab/demo/Lab/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.cpp @@ -37,7 +37,7 @@ struct Scene_polyhedron_shortest_path_item_priv typedef Surface_mesh_shortest_path::Face_location Face_location; typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; - typedef CGAL::AABB_traits AABB_face_graph_traits; + typedef CGAL::AABB_traits_3 AABB_face_graph_traits; typedef CGAL::AABB_tree AABB_face_graph_tree; typedef Surface_mesh_shortest_path_traits::Barycentric_coordinates diff --git a/Lab/demo/Lab/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.h b/Lab/demo/Lab/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.h index 91962532d80..499ad356c80 100644 --- a/Lab/demo/Lab/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.h +++ b/Lab/demo/Lab/Plugins/Surface_mesh/Scene_polyhedron_shortest_path_item.h @@ -24,7 +24,7 @@ #endif #include -#include +#include #include #include @@ -50,7 +50,7 @@ public: typedef CGAL::Surface_mesh_shortest_path Surface_mesh_shortest_path; typedef Surface_mesh_shortest_path::Face_location Face_location; typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; - typedef CGAL::AABB_traits AABB_face_graph_traits; + typedef CGAL::AABB_traits_3 AABB_face_graph_traits; typedef CGAL::AABB_tree AABB_face_graph_tree; typedef Surface_mesh_shortest_path_traits::Barycentric_coordinates Barycentric_coordinates; diff --git a/Lab/demo/Lab/Scene_c3t3_item.cpp b/Lab/demo/Lab/Scene_c3t3_item.cpp index 47bfe0edbb7..e90c719cec8 100644 --- a/Lab/demo/Lab/Scene_c3t3_item.cpp +++ b/Lab/demo/Lab/Scene_c3t3_item.cpp @@ -33,7 +33,7 @@ #include #include -#include +#include #include #include @@ -42,7 +42,7 @@ typedef CGAL::AABB_triangulation_3_cell_primitive Primitive; -typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; typedef Tree::Point_and_primitive_id Point_and_primitive_id; using namespace CGAL::Three; diff --git a/Lab/demo/Lab/Scene_surface_mesh_item.cpp b/Lab/demo/Lab/Scene_surface_mesh_item.cpp index d17c3b6f248..36d75aaa6b5 100644 --- a/Lab/demo/Lab/Scene_surface_mesh_item.cpp +++ b/Lab/demo/Lab/Scene_surface_mesh_item.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include @@ -91,7 +91,7 @@ public: }; -typedef CGAL::AABB_traits AABB_traits; +typedef CGAL::AABB_traits_3 AABB_traits; typedef CGAL::AABB_tree Input_facets_AABB_tree; diff --git a/Lab/demo/Lab/Scene_triangulation_3_item.cpp b/Lab/demo/Lab/Scene_triangulation_3_item.cpp index 673c0562ee7..66e87e7af6b 100644 --- a/Lab/demo/Lab/Scene_triangulation_3_item.cpp +++ b/Lab/demo/Lab/Scene_triangulation_3_item.cpp @@ -38,7 +38,7 @@ #include #include -#include +#include #include #include #include @@ -49,7 +49,7 @@ typedef CGAL::AABB_triangulation_3_cell_primitive Primitive; -typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; typedef Tree::Point_and_primitive_id Point_and_primitive_id; using namespace CGAL::Three; diff --git a/Mesh_3/benchmark/Mesh_3/StdAfx.h b/Mesh_3/benchmark/Mesh_3/StdAfx.h index 9648697498a..e7ee9da0a03 100644 --- a/Mesh_3/benchmark/Mesh_3/StdAfx.h +++ b/Mesh_3/benchmark/Mesh_3/StdAfx.h @@ -141,7 +141,7 @@ #include // CGAL -//#include +//#include //#include #include #include diff --git a/Mesh_3/include/CGAL/Mesh_3/experimental/AABB_filtered_projection_traits.h b/Mesh_3/include/CGAL/Mesh_3/experimental/AABB_filtered_projection_traits.h index ac5c1d30496..d14daec010b 100644 --- a/Mesh_3/include/CGAL/Mesh_3/experimental/AABB_filtered_projection_traits.h +++ b/Mesh_3/include/CGAL/Mesh_3/experimental/AABB_filtered_projection_traits.h @@ -37,7 +37,7 @@ template #include -#include -#include +#include +#include #include #include @@ -58,8 +58,8 @@ public: typedef typename Kernel::Point_3 Point_3; typedef typename std::list::iterator Tr_iterator; - typedef CGAL::AABB_triangle_primitive Primitive; - typedef CGAL::AABB_traits AABB_tr_traits; + typedef CGAL::AABB_triangle_primitive_3 Primitive; + typedef CGAL::AABB_traits_3 AABB_tr_traits; typedef CGAL::AABB_tree AABB_tree; typedef typename CGAL::Default::Get::type Tree; diff --git a/Mesh_3/include/CGAL/Mesh_3/experimental/Lipschitz_sizing_polyhedron.h b/Mesh_3/include/CGAL/Mesh_3/experimental/Lipschitz_sizing_polyhedron.h index df2c3e0bd46..24db03f7546 100644 --- a/Mesh_3/include/CGAL/Mesh_3/experimental/Lipschitz_sizing_polyhedron.h +++ b/Mesh_3/include/CGAL/Mesh_3/experimental/Lipschitz_sizing_polyhedron.h @@ -17,8 +17,8 @@ #include #include -#include -#include +#include +#include #include @@ -51,8 +51,8 @@ public: typedef typename Kernel::Point_3 Point_3; typedef typename std::list::iterator Tr_iterator; - typedef CGAL::AABB_triangle_primitive Primitive; - typedef CGAL::AABB_traits AABB_tr_traits; + typedef CGAL::AABB_triangle_primitive_3 Primitive; + typedef CGAL::AABB_traits_3 AABB_tr_traits; typedef CGAL::AABB_tree AABB_tree; typedef typename CGAL::Default::Get::type Tree; diff --git a/Mesh_3/include/CGAL/Mesh_3/polyhedral_to_labeled_function_wrapper.h b/Mesh_3/include/CGAL/Mesh_3/polyhedral_to_labeled_function_wrapper.h index 940a08eb03c..ba1b5285945 100644 --- a/Mesh_3/include/CGAL/Mesh_3/polyhedral_to_labeled_function_wrapper.h +++ b/Mesh_3/include/CGAL/Mesh_3/polyhedral_to_labeled_function_wrapper.h @@ -23,7 +23,7 @@ #include -#include +#include #include #include @@ -68,7 +68,7 @@ public: // AABB_tree Types typedef class AABB_const_polyhedron_triangle_primitive AABB_primitive; - typedef class AABB_traits AABB_traits; + typedef class AABB_traits_3 AABB_traits; typedef class AABB_tree AABB_tree; typedef typename AABB_traits::Bounding_box Bounding_box; @@ -189,7 +189,7 @@ public: // AABB_tree Types typedef class AABB_const_polyhedron_triangle_primitive AABB_primitive; - typedef class AABB_traits AABB_traits; + typedef class AABB_traits_3 AABB_traits; typedef class AABB_tree AABB_tree; typedef typename AABB_traits::Bounding_box Bounding_box; @@ -264,7 +264,7 @@ public: // AABB_tree Types typedef class AABB_const_polyhedron_edge_primitive AABB_primitive; - typedef class AABB_traits AABB_traits; + typedef class AABB_traits_3 AABB_traits; typedef class AABB_tree AABB_tree; typedef typename AABB_traits::Bounding_box Bounding_box; diff --git a/Mesh_3/include/CGAL/Mesh_domain_with_polyline_features_3.h b/Mesh_3/include/CGAL/Mesh_domain_with_polyline_features_3.h index 1792177d9d5..61eb0682d83 100644 --- a/Mesh_3/include/CGAL/Mesh_domain_with_polyline_features_3.h +++ b/Mesh_3/include/CGAL/Mesh_domain_with_polyline_features_3.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -848,8 +848,8 @@ private: GT, typename Edges::const_iterator> Curves_primitives; - typedef CGAL::AABB_traits AABB_curves_traits; + typedef CGAL::AABB_traits_3 AABB_curves_traits; Corners corners_; Corners_tmp_incidences corners_tmp_incidences_; diff --git a/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h b/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h index 1f9551ef1ac..9173ee75d06 100644 --- a/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h +++ b/Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h @@ -212,7 +212,7 @@ public: public: typedef typename Primitive_type::type Ins_fctor_primitive; - typedef CGAL::AABB_traits Ins_fctor_traits; + typedef CGAL::AABB_traits_3 Ins_fctor_traits; typedef CGAL::AABB_tree Ins_fctor_AABB_tree; typedef Side_of_triangle_mesh #include #include -#include +#include #include diff --git a/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_collision_detector_2.h b/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_collision_detector_2.h index b926d680806..4a4d8ab4757 100644 --- a/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_collision_detector_2.h +++ b/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_collision_detector_2.h @@ -37,7 +37,7 @@ public: typedef typename Polygon_2::Edge_const_iterator Edge_iterator; typedef AABB_segment_2_primitive Tree_segment_2; - typedef AABB_traits_2 Tree_traits; + typedef Minkowski_sum::AABB_traits_2 Tree_traits; typedef AABB_tree_with_join Tree_2; public: diff --git a/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_traits_2.h b/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_traits_2.h index 601fc8febc7..8317616c9a0 100644 --- a/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_traits_2.h +++ b/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_traits_2.h @@ -13,12 +13,16 @@ #define CGAL_AABB_TRAITS_2_H #include +#include namespace CGAL { +namespace Minkowski_sum { + template class AABB_traits_2 + :public Search_traits_2 { public: @@ -37,18 +41,18 @@ public: // Types for AABB_tree typedef typename GeomTraits::FT FT; - typedef typename GeomTraits::Point_2 Point_3; - typedef typename GeomTraits::Circle_2 Sphere_3; - typedef typename GeomTraits::Iso_rectangle_2 Iso_cuboid_3; - typedef typename GeomTraits::Construct_center_2 Construct_center_3; - typedef typename GeomTraits::Construct_iso_rectangle_2 Construct_iso_cuboid_3; - typedef typename GeomTraits::Construct_min_vertex_2 Construct_min_vertex_3; - typedef typename GeomTraits::Construct_max_vertex_2 Construct_max_vertex_3; - typedef typename GeomTraits::Compute_squared_radius_2 Compute_squared_radius_3; + typedef typename GeomTraits::Point_2 Point_2; + typedef typename GeomTraits::Circle_2 Circle_2; + typedef typename GeomTraits::Iso_rectangle_2 Iso_rectangle_2; + typedef typename GeomTraits::Construct_center_2 Construct_center_2; + typedef typename GeomTraits::Construct_iso_rectangle_2 Construct_iso_cuboid_2; + typedef typename GeomTraits::Construct_min_vertex_2 Construct_min_vertex_2; + typedef typename GeomTraits::Construct_max_vertex_2 Construct_max_vertex_2; + typedef typename GeomTraits::Compute_squared_radius_2 Compute_squared_radius_2; typedef typename GeomTraits::Cartesian_const_iterator_2 - Cartesian_const_iterator_3; + Cartesian_const_iterator_2; typedef typename GeomTraits::Construct_cartesian_const_iterator_2 - Construct_cartesian_const_iterator_3; + Construct_cartesian_const_iterator_2; AABB_traits_2(const Point &translation_point): m_translation_point( translation_point) @@ -214,6 +218,8 @@ private: } }; +} // namespace Minkowski_sum + } // namespace CGAL #endif diff --git a/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_traversal_traits_with_join.h b/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_traversal_traits_with_join.h index b44438f24e8..50a50030075 100644 --- a/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_traversal_traits_with_join.h +++ b/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_traversal_traits_with_join.h @@ -277,7 +277,7 @@ private: template class Do_intersect_joined_traits { - typedef typename AABBTraits::Point_3 Point; + typedef typename AABBTraits::Point Point; typedef typename AABBTraits::Primitive Primitive; typedef AABB_node_with_join Node; diff --git a/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_tree_with_join.h b/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_tree_with_join.h index aabc398f739..9c97212c8c5 100644 --- a/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_tree_with_join.h +++ b/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_tree_with_join.h @@ -70,7 +70,7 @@ namespace CGAL { /// Type of 3D point. - typedef typename AABBTraits::Point_3 Point; + typedef typename AABBTraits::Point Point; /// Type of input primitive. typedef typename AABBTraits::Primitive Primitive; diff --git a/Optimal_bounding_box/examples/Optimal_bounding_box/rotated_aabb_tree_example.cpp b/Optimal_bounding_box/examples/Optimal_bounding_box/rotated_aabb_tree_example.cpp index f16c2ab3f4a..0ce81603de8 100644 --- a/Optimal_bounding_box/examples/Optimal_bounding_box/rotated_aabb_tree_example.cpp +++ b/Optimal_bounding_box/examples/Optimal_bounding_box/rotated_aabb_tree_example.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -52,7 +52,7 @@ int main(int argc, char** argv) // rotated AABB tree typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; - typedef CGAL::AABB_traits AABB_face_graph_traits; + typedef CGAL::AABB_traits_3 AABB_face_graph_traits; CGAL::AABB_tree tree(faces(sm).begin(), faces(sm).end(), sm, aff_tr_vpm); diff --git a/Poisson_surface_reconstruction_3/examples/Poisson_surface_reconstruction_3/poisson_reconstruction.cpp b/Poisson_surface_reconstruction_3/examples/Poisson_surface_reconstruction_3/poisson_reconstruction.cpp index f552cf357dc..19b2afb4942 100644 --- a/Poisson_surface_reconstruction_3/examples/Poisson_surface_reconstruction_3/poisson_reconstruction.cpp +++ b/Poisson_surface_reconstruction_3/examples/Poisson_surface_reconstruction_3/poisson_reconstruction.cpp @@ -10,7 +10,7 @@ // CGAL #include // must be included before kernel -#include +#include #include #include #include @@ -57,7 +57,7 @@ typedef CGAL::Poisson_implicit_surface_3 Primitive; -typedef CGAL::AABB_traits AABB_traits; +typedef CGAL::AABB_traits_3 AABB_traits; typedef CGAL::AABB_tree AABB_tree; struct Counter { diff --git a/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/polygon_mesh_slicer.cpp b/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/polygon_mesh_slicer.cpp index ae1fd002a92..efc64fae2d7 100644 --- a/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/polygon_mesh_slicer.cpp +++ b/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/polygon_mesh_slicer.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include @@ -34,7 +34,7 @@ typedef CGAL::Polyhedron_3 Mesh; #endif typedef CGAL::AABB_halfedge_graph_segment_primitive HGSP; -typedef CGAL::AABB_traits AABB_traits; +typedef CGAL::AABB_traits_3 AABB_traits; typedef CGAL::AABB_tree AABB_tree; typedef std::vector Polyline; typedef std::list< Polyline > Polylines; diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/Concepts/PMPDistanceTraits.h b/Polygon_mesh_processing/doc/Polygon_mesh_processing/Concepts/PMPDistanceTraits.h index 8c153a122ac..96e6d276d68 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/Concepts/PMPDistanceTraits.h +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/Concepts/PMPDistanceTraits.h @@ -2,11 +2,11 @@ /// \cgalConcept /// /// The concept `PMPDistanceTraits` is a refinement of the -/// concepts `AABBGeomTraits` and `SpatialSortingTraits_3`. In addition to the types required by +/// concepts `AABBGeomTraits_3` and `SpatialSortingTraits_3`. In addition to the types required by /// those concepts, it also requires types and functors needed by the functions `approximate_max_distance_to_point_set()`, /// `sample_triangle_mesh()`, `approximate_Hausdorff_distance()` and `max_distance_to_triangle_mesh()` /// -/// \cgalRefines{AABBGeomTraits,SpatialSortingTraits_3} +/// \cgalRefines{AABBGeomTraits_3, SpatialSortingTraits_3} /// \cgalHasModelsBegin /// \cgalHasModelsBare{Any 3D Kernel is a model of this concept} /// \cgalHasModelsEnd diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/locate_example.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/locate_example.cpp index 829af8a5da3..d765f8692af 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/locate_example.cpp +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/locate_example.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include @@ -58,7 +58,7 @@ int main(int /*argc*/, char** /*argv*/) // The AABB tree can be cached in case many queries are performed (otherwise, it is rebuilt // on each call, which is expensive). typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; - typedef CGAL::AABB_traits AABB_face_graph_traits; + typedef CGAL::AABB_traits_3 AABB_face_graph_traits; CGAL::AABB_tree tree; PMP::build_AABB_tree(tm, tree); diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/mesh_slicer_example.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/mesh_slicer_example.cpp index 5f4b1cd78d5..1957c103596 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/mesh_slicer_example.cpp +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/mesh_slicer_example.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include @@ -20,7 +20,7 @@ typedef std::vector Polyline_type; typedef std::list Polylines; typedef CGAL::AABB_halfedge_graph_segment_primitive HGSP; -typedef CGAL::AABB_traits AABB_traits; +typedef CGAL::AABB_traits_3 AABB_traits; typedef CGAL::AABB_tree AABB_tree; namespace PMP = CGAL::Polygon_mesh_processing; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/angle_and_area_smoothing.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/angle_and_area_smoothing.h index 0166c85e58f..beda665855a 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/angle_and_area_smoothing.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/angle_and_area_smoothing.h @@ -168,9 +168,9 @@ void angle_and_area_smoothing(const FaceRange& faces, typedef typename GeomTraits::Triangle_3 Triangle; typedef std::vector Triangle_container; - typedef CGAL::AABB_triangle_primitive AABB_Primitive; - typedef CGAL::AABB_traits AABB_Traits; + typedef CGAL::AABB_traits_3 AABB_Traits; typedef CGAL::AABB_tree Tree; if(std::begin(faces) == std::end(faces)) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/clip.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/clip.h index 5926bab0020..46abaee2bfd 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/clip.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/clip.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h index a071b3591d0..a3df6d5d9c5 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/distance.h @@ -21,8 +21,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -1116,7 +1116,7 @@ double max_distance_to_triangle_mesh(const PointRange& points, spatial_sort(points_cpy.begin(), points_cpy.end()); typedef AABB_face_graph_triangle_primitive Primitive; - typedef AABB_traits Tree_traits; + typedef AABB_traits_3 Tree_traits; typedef AABB_tree Tree; Tree_traits tgt/*(gt)*/; @@ -2009,8 +2009,8 @@ bounded_error_squared_one_sided_Hausdorff_distance_impl(const TriangleMesh1& tm1 using TM1_primitive = AABB_face_graph_triangle_primitive; using TM2_primitive = AABB_face_graph_triangle_primitive; - using TM1_traits = AABB_traits; - using TM2_traits = AABB_traits; + using TM1_traits = AABB_traits_3; + using TM2_traits = AABB_traits_3; using TM1_tree = AABB_tree; using TM2_tree = AABB_tree; @@ -2026,7 +2026,7 @@ bounded_error_squared_one_sided_Hausdorff_distance_impl(const TriangleMesh1& tm1 #if defined(CGAL_LINKED_WITH_TBB) && defined(CGAL_METIS_ENABLED) && defined(USE_PARALLEL_BEHD) using TMF = CGAL::Face_filtered_graph; using TMF_primitive = AABB_face_graph_triangle_primitive; - using TMF_traits = AABB_traits; + using TMF_traits = AABB_traits_3; using TMF_tree = AABB_tree; using TM1_wrapper = Triangle_mesh_wrapper; using TM2_wrapper = Triangle_mesh_wrapper; @@ -2285,8 +2285,8 @@ bounded_error_squared_symmetric_Hausdorff_distance_impl(const TriangleMesh1& tm1 using TM1_primitive = AABB_face_graph_triangle_primitive; using TM2_primitive = AABB_face_graph_triangle_primitive; - using TM1_traits = AABB_traits; - using TM2_traits = AABB_traits; + using TM1_traits = AABB_traits_3; + using TM2_traits = AABB_traits_3; using TM1_tree = AABB_tree; using TM2_tree = AABB_tree; @@ -2419,7 +2419,7 @@ bounded_error_squared_Hausdorff_distance_naive_impl(const TriangleMesh1& tm1, using Triangle_3 = typename Kernel::Triangle_3; using TM2_primitive = AABB_face_graph_triangle_primitive; - using TM2_traits = AABB_traits; + using TM2_traits = AABB_traits_3; using TM2_tree = AABB_tree; using TM1_face_to_triangle_map = Triangle_from_face_descriptor_map; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/AABB_traversal_traits_with_Hausdorff_distance.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/AABB_traversal_traits_with_Hausdorff_distance.h index ccf77246ee6..e1eb934042a 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/AABB_traversal_traits_with_Hausdorff_distance.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/AABB_traversal_traits_with_Hausdorff_distance.h @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include @@ -379,7 +379,7 @@ class Hausdorff_primitive_traits_tm1 using Triangle_3 = typename Kernel::Triangle_3; using TM2_primitive = AABB_face_graph_triangle_primitive; - using TM2_traits = AABB_traits; + using TM2_traits = AABB_traits_3; using TM2_tree = AABB_tree; using TM2_hd_traits = Hausdorff_primitive_traits_tm2; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h index 68f0c9e5e6c..ef7db058587 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Corefinement/face_graph_utils.h @@ -255,7 +255,7 @@ struct Side_of_helper typedef Node_vector_exact_vertex_point_map VPM; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree_type; static @@ -331,7 +331,7 @@ struct Side_of_helper Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree_type; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h index f98373a0424..4d5622c6f0d 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h @@ -25,8 +25,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -290,9 +290,9 @@ namespace internal { typedef std::vector Patch_id_list; typedef std::map Patch_id_to_index_map; - typedef CGAL::AABB_triangle_primitive AABB_primitive; - typedef CGAL::AABB_traits AABB_traits; + typedef CGAL::AABB_traits_3 AABB_traits; typedef CGAL::AABB_tree AABB_tree; typedef typename boost::property_map< diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Smoothing/mesh_smoothing_impl.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Smoothing/mesh_smoothing_impl.h index 54b15c7777a..d43041251cb 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Smoothing/mesh_smoothing_impl.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Smoothing/mesh_smoothing_impl.h @@ -24,8 +24,8 @@ #include #include -#include -#include +#include +#include #include #include #include diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Snapping/snap.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Snapping/snap.h index 6dd55b9fc62..22054b8413f 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Snapping/snap.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Snapping/snap.h @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include #include @@ -226,7 +226,7 @@ template ::value_type Point; typedef CGAL::AABB_halfedge_graph_segment_primitive Primitive; - typedef CGAL::AABB_traits AABB_Traits; + typedef CGAL::AABB_traits_3 AABB_Traits; typedef CGAL::AABB_tree AABB_tree; typedef std::pair Vertex_with_new_position; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h index 650268e1c40..c047eeb407e 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/intersection.h @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include @@ -1109,7 +1109,7 @@ bool is_mesh2_in_mesh1(const TriangleMesh& tm1, const GT& gt) { typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree AABBTree; AABBTree tree1(faces(tm1).begin(), faces(tm1).end(), tm1, vpm1); @@ -1464,7 +1464,7 @@ struct Mesh_callback typedef typename boost::range_value::type NamedParameters; typedef typename GetVertexPointMap::const_type VPM; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree AABBTree; typedef typename boost::graph_traits::face_descriptor face_descriptor; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/locate.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/locate.h index b99ed460a6f..c8653c0196d 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/locate.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/locate.h @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include #include @@ -1522,7 +1522,7 @@ template locate_with_AABB_tree(const Point& p, - const AABB_tree > >& tree, #else typename internal::Location_traits::Face_location locate_with_AABB_tree(const typename internal::Location_traits::Point& p, - const AABB_tree::type, CGAL::AABB_face_graph_triangle_primitive > >& tree, #endif @@ -1613,7 +1613,7 @@ locate_with_AABB_tree(const typename internal::Location_traits::type Geom_traits; typedef typename CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef typename CGAL::AABB_traits AABB_traits; + typedef typename CGAL::AABB_traits_3 AABB_traits; typedef typename Primitive::Point Point_3; static_assert(std::is_same::value); @@ -1701,7 +1701,7 @@ locate(const typename internal::Location_traits:: typedef typename GetGeomTraits::type Geom_traits; typedef AABB_face_graph_triangle_primitive AABB_face_graph_primitive; - typedef CGAL::AABB_traits AABB_face_graph_traits; + typedef CGAL::AABB_traits_3 AABB_face_graph_traits; typedef internal::Point_to_Point_3 P_to_P3; typedef typename AABB_face_graph_traits::Point_3 Point_3; @@ -1772,12 +1772,12 @@ template locate_with_AABB_tree(const Ray& ray, - const AABB_tree > >& tree, + const AABB_tree > >& tree, #else typename internal::Location_traits::Face_location locate_with_AABB_tree(const typename internal::Location_traits::Ray& ray, const AABB_tree< - CGAL::AABB_traits< + CGAL::AABB_traits_3< typename GetGeomTraits::type, CGAL::AABB_face_graph_triangle_primitive > >& tree, @@ -1798,7 +1798,7 @@ locate_with_AABB_tree(const typename internal::Location_traits R_to_R3; typedef typename CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef typename CGAL::AABB_traits AABB_traits; + typedef typename CGAL::AABB_traits_3 AABB_traits; typedef AABB_tree AABB_face_graph_tree; typedef typename AABB_face_graph_tree::template Intersection_and_primitive_id::Type Intersection_type; typedef std::optional Ray_intersection; @@ -1919,7 +1919,7 @@ locate(const typename internal::Location_traits:: typedef typename GetGeomTraits::type Geom_traits; typedef AABB_face_graph_triangle_primitive AABB_face_graph_primitive; - typedef CGAL::AABB_traits AABB_face_graph_traits; + typedef CGAL::AABB_traits_3 AABB_face_graph_traits; using parameters::get_parameter; using parameters::choose_parameter; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orient_polygon_soup_extension.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orient_polygon_soup_extension.h index c2f32374480..0b1a7ae9588 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orient_polygon_soup_extension.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orient_polygon_soup_extension.h @@ -19,8 +19,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -190,8 +190,8 @@ void orient_triangle_soup_with_reference_triangle_soup(const ReferencePointRange } typedef typename std::vector::const_iterator Iterator; - typedef CGAL::AABB_triangle_primitive Primitive; - typedef CGAL::AABB_traits Tree_traits; + typedef CGAL::AABB_triangle_primitive_3 Primitive; + typedef CGAL::AABB_traits_3 Tree_traits; CGAL::AABB_tree tree(ref_triangles.begin(), ref_triangles.end()); @@ -326,7 +326,7 @@ void orient_triangle_soup_with_reference_triangle_mesh(const TriangleMesh& tm_re }; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Tree_traits; + typedef CGAL::AABB_traits_3 Tree_traits; boost::filter_iterator begin(is_not_deg, faces(tm_ref).begin(), faces(tm_ref).end()), diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/random_perturbation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/random_perturbation.h index 08875a0b9e8..8afb829b4b2 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/random_perturbation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/random_perturbation.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include @@ -67,7 +67,7 @@ namespace internal { typedef typename GT::Point_3 Point_3; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; Tree tree; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_self_intersections.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_self_intersections.h index ed92f836dec..364a8dc624b 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_self_intersections.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/repair_self_intersections.h @@ -29,8 +29,8 @@ #endif #include -#include -#include +#include +#include #include #include #include @@ -1070,8 +1070,8 @@ struct Mesh_projection_functor typedef typename GeomTraits::Triangle_3 Triangle_3; typedef std::vector Triangle_container; - typedef CGAL::AABB_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_triangle_primitive_3 Primitive; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; template diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_slicer.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_slicer.h index a608179f49a..2edb5a70391 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_slicer.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_slicer.h @@ -17,7 +17,7 @@ #include -#include +#include #include #include @@ -41,14 +41,14 @@ namespace CGAL { /// a triangulated surface mesh. /// /// \tparam TriangleMesh a triangulated surface mesh, model of `FaceGraph` and `HalfedgeListGraph` -/// \tparam Traits a model of `AABBGeomTraits` +/// \tparam Traits a model of `AABBGeomTraits_3` /// \tparam VertexPointMap a model of `ReadablePropertyMap` with /// `boost::graph_traits::%vertex_descriptor` as key and /// `Traits::Point_3` as value type. /// The default is `typename boost::property_map< TriangleMesh, vertex_point_t>::%type`. /// \tparam AABBTree must be an instantiation of `CGAL::AABB_tree` able to handle /// the edges of `TriangleMesh`, having its `edge_descriptor` as primitive id. -/// The default is `CGAL::AABB_tree > >` /// \tparam UseParallelPlaneOptimization if `true`, the code will use specific /// predicates and constructions in case the functor is called with a plane @@ -76,7 +76,7 @@ template::type, class AABBTree = AABB_tree< - AABB_traits #include -#include +#include #include #include @@ -283,7 +283,7 @@ private: }; typedef AABB_primitive, Point_map, Tag_true /*UseSharedData*/, Tag_false /*CacheDatum*/> Primitive; - typedef AABB_traits Tree_traits; + typedef AABB_traits_3 Tree_traits; typedef AABB_tree Tree; // Data members diff --git a/Polygon_mesh_processing/include/CGAL/Rigid_triangle_mesh_collision_detection.h b/Polygon_mesh_processing/include/CGAL/Rigid_triangle_mesh_collision_detection.h index bde9c86826e..36b7e965c88 100644 --- a/Polygon_mesh_processing/include/CGAL/Rigid_triangle_mesh_collision_detection.h +++ b/Polygon_mesh_processing/include/CGAL/Rigid_triangle_mesh_collision_detection.h @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include #include @@ -76,7 +76,7 @@ class Rigid_triangle_mesh_collision_detection // AABB-tree type typedef AABB_face_graph_triangle_primitive Default_primitive; - typedef AABB_traits Default_tree_traits; + typedef AABB_traits_3 Default_tree_traits; typedef CGAL::AABB_tree Default_tree; typedef typename Default::Get::type Tree; typedef typename Tree::AABB_traits Tree_traits; diff --git a/Polygon_mesh_processing/include/CGAL/Side_of_triangle_mesh.h b/Polygon_mesh_processing/include/CGAL/Side_of_triangle_mesh.h index eff54edea7c..85f9f4c8f60 100644 --- a/Polygon_mesh_processing/include/CGAL/Side_of_triangle_mesh.h +++ b/Polygon_mesh_processing/include/CGAL/Side_of_triangle_mesh.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include namespace CGAL { @@ -81,7 +81,7 @@ class Side_of_triangle_mesh struct AABB_tree_default { typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree type; }; typedef typename Default::Lazy_get FGTP; - typedef CGAL::AABB_traits AABB_traits; + typedef CGAL::AABB_traits_3 AABB_traits; typedef CGAL::AABB_tree AABB_tree; AABB_tree tree(faces(poly).first, faces(poly).second, poly); diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/point_inside_surface_mesh_test.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/point_inside_surface_mesh_test.cpp index ef7bf8f9e99..9338820c000 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/point_inside_surface_mesh_test.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/point_inside_surface_mesh_test.cpp @@ -39,7 +39,7 @@ int test_surface_mesh(const std::string filename) //test compilation of constructor from AABB_tree typedef CGAL::AABB_face_graph_triangle_primitive FGTP; - typedef CGAL::AABB_traits AABB_traits; + typedef CGAL::AABB_traits_3 AABB_traits; typedef CGAL::AABB_tree AABB_tree; AABB_tree tree(faces(mesh).first, faces(mesh).second, mesh); diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/polygon_mesh_slicer_test.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/polygon_mesh_slicer_test.cpp index d74eb2fba20..79d4a68fdfc 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/polygon_mesh_slicer_test.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/polygon_mesh_slicer_test.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include @@ -50,7 +50,7 @@ int test_slicer() #endif typedef CGAL::AABB_halfedge_graph_segment_primitive HGSP; - typedef CGAL::AABB_traits AABB_traits; + typedef CGAL::AABB_traits_3 AABB_traits; typedef CGAL::AABB_tree AABB_tree; typedef std::vector Polyline_type; typedef std::vector< Polyline_type > Polylines; diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp index 5ecd9b9530b..b2b8aa26f59 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp @@ -85,7 +85,7 @@ struct Custom_traits_Hausdorff Compute_squared_area_3 compute_squared_area_3_object(){return Compute_squared_area_3();} // } end of new requirements -// requirements from AABBGeomTraits { +// requirements from AABBGeomTraits_3 { struct Sphere_3 {}; @@ -144,7 +144,7 @@ struct Custom_traits_Hausdorff Compute_squared_distance_3 compute_squared_distance_3_object() const {return Compute_squared_distance_3();} Do_intersect_3 do_intersect_3_object() const {return Do_intersect_3();} Equal_3 equal_3_object() const {return Equal_3();} -// } end of requirements from AABBGeomTraits +// } end of requirements from AABBGeomTraits_3 // requirements from SearchGeomTraits_3 { diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_locate.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_locate.cpp index c0b57f62449..b2250c03641 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_locate.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_locate.cpp @@ -519,7 +519,7 @@ struct Locate_with_AABB_tree_Tester // 2D case typedef PMP::internal::Point_to_Point_3 Intrinsic_point_to_Point_3; typedef PMP::internal::Point_to_Point_3_VPM WrappedVPM; typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; - typedef CGAL::AABB_traits AABB_face_graph_traits; + typedef CGAL::AABB_traits_3 AABB_face_graph_traits; static_assert(std::is_same::value); @@ -629,7 +629,7 @@ struct Locate_with_AABB_tree_Tester // 3D // --------------------------------------------------------------------------- typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; - typedef CGAL::AABB_traits AABB_face_graph_traits; + typedef CGAL::AABB_traits_3 AABB_face_graph_traits; typedef typename K::Point_3 Point_3; static_assert(std::is_same::value); @@ -643,7 +643,7 @@ struct Locate_with_AABB_tree_Tester // 3D typedef boost::associative_property_map Custom_VPM; typedef PMP::internal::Point_to_Point_3_VPM WrappedVPM; typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive_with_WVPM; - typedef CGAL::AABB_traits AABB_face_graph_traits_with_WVPM; + typedef CGAL::AABB_traits_3 AABB_face_graph_traits_with_WVPM; CGAL::AABB_tree tree_b; Custom_map custom_map; diff --git a/Surface_mesh/examples/Surface_mesh/sm_aabbtree.cpp b/Surface_mesh/examples/Surface_mesh/sm_aabbtree.cpp index ba18732911d..c0a73838ce3 100644 --- a/Surface_mesh/examples/Surface_mesh/sm_aabbtree.cpp +++ b/Surface_mesh/examples/Surface_mesh/sm_aabbtree.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -15,7 +15,7 @@ typedef K::Vector_3 Vector; typedef K::Segment_3 Segment; typedef CGAL::Surface_mesh Mesh; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; -typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; typedef std::optional< Tree::Intersection_and_primitive_id::Type > Segment_intersection; typedef std::optional< Tree::Intersection_and_primitive_id::Type > Plane_intersection; diff --git a/Surface_mesh_segmentation/doc/Surface_mesh_segmentation/Concepts/SegmentationGeomTraits.h b/Surface_mesh_segmentation/doc/Surface_mesh_segmentation/Concepts/SegmentationGeomTraits.h index 81e7848328b..5bc4502ca4b 100644 --- a/Surface_mesh_segmentation/doc/Surface_mesh_segmentation/Concepts/SegmentationGeomTraits.h +++ b/Surface_mesh_segmentation/doc/Surface_mesh_segmentation/Concepts/SegmentationGeomTraits.h @@ -9,7 +9,7 @@ of the geometric traits needed by the segmentation functions. \cgalHasModelsBare{All models of the \cgal concept `Kernel`} \cgalHasModelsEnd -\cgalRefines{AABBGeomTraits} +\cgalRefines{AABBGeomTraits_3} */ @@ -130,4 +130,3 @@ collinear_3_object()const /// @} }; /* end SegmentationGeomTraits */ - diff --git a/Surface_mesh_segmentation/include/CGAL/Surface_mesh_segmentation/internal/AABB_traits.h b/Surface_mesh_segmentation/include/CGAL/Surface_mesh_segmentation/internal/AABB_traits.h index ae2a6de7ae0..2bac1f13889 100644 --- a/Surface_mesh_segmentation/include/CGAL/Surface_mesh_segmentation/internal/AABB_traits.h +++ b/Surface_mesh_segmentation/include/CGAL/Surface_mesh_segmentation/internal/AABB_traits.h @@ -16,7 +16,7 @@ #include -#include +#include #include #include @@ -27,18 +27,18 @@ namespace CGAL /// @cond CGAL_DOCUMENT_INTERNAL template class AABB_traits_SDF : - public AABB_traits + public AABB_traits_3 { public: - typedef AABB_traits Base_traits; + typedef AABB_traits_3 Base_traits; typedef typename Base_traits::Bounding_box Bounding_box; - typedef typename Base_traits::Point_3 Point_3; + typedef typename Base_traits::Point Point_3; class Do_intersect : public Base_traits::Do_intersect { public: - Do_intersect(const AABB_traits& traits) + Do_intersect(const AABB_traits_3& traits) :Base_traits::Do_intersect(traits) {} // not sure is it safe on templated funcs ? may be do not inherit and repeat functions... diff --git a/Surface_mesh_shortest_path/examples/Surface_mesh_shortest_path/shortest_path_with_locate.cpp b/Surface_mesh_shortest_path/examples/Surface_mesh_shortest_path/shortest_path_with_locate.cpp index b984075eb2e..6ee95b209dc 100644 --- a/Surface_mesh_shortest_path/examples/Surface_mesh_shortest_path/shortest_path_with_locate.cpp +++ b/Surface_mesh_shortest_path/examples/Surface_mesh_shortest_path/shortest_path_with_locate.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include @@ -27,7 +27,7 @@ typedef typename Surface_mesh_shortest_path::Barycentric_coordinates Barycent typedef typename Surface_mesh_shortest_path::Face_location Face_location; typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; -typedef CGAL::AABB_traits AABB_face_graph_traits; +typedef CGAL::AABB_traits_3 AABB_face_graph_traits; typedef CGAL::AABB_tree AABB_tree; int main(int argc, char** argv) diff --git a/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/Surface_mesh_shortest_path_test_3.cpp b/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/Surface_mesh_shortest_path_test_3.cpp index 2f1c8790fd1..26da5f2d915 100644 --- a/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/Surface_mesh_shortest_path_test_3.cpp +++ b/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/Surface_mesh_shortest_path_test_3.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -40,7 +40,7 @@ int main(int argc, char* argv[]) typedef boost::property_map::const_type FIM; typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; - typedef CGAL::AABB_traits AABB_face_graph_traits; + typedef CGAL::AABB_traits_3 AABB_face_graph_traits; Traits traits; diff --git a/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/Surface_mesh_shortest_path_test_4.cpp b/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/Surface_mesh_shortest_path_test_4.cpp index 2eb7248f38d..1774d928a24 100644 --- a/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/Surface_mesh_shortest_path_test_4.cpp +++ b/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/Surface_mesh_shortest_path_test_4.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -43,7 +43,7 @@ int main(int argc, char* argv[]) typedef boost::property_map::const_type FIM; typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; - typedef CGAL::AABB_traits AABB_face_graph_traits; + typedef CGAL::AABB_traits_3 AABB_face_graph_traits; Traits traits; diff --git a/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/Surface_mesh_shortest_path_test_6.cpp b/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/Surface_mesh_shortest_path_test_6.cpp index 8ee21f598e9..bce2226d839 100644 --- a/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/Surface_mesh_shortest_path_test_6.cpp +++ b/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/Surface_mesh_shortest_path_test_6.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include @@ -21,7 +21,7 @@ typedef CGAL::Surface_mesh_shortest_path Surface_mesh_shortest_path; typedef boost::property_map::const_type VPM; typedef CGAL::AABB_face_graph_triangle_primitive AABB_face_graph_primitive; -typedef CGAL::AABB_traits AABB_face_graph_traits; +typedef CGAL::AABB_traits_3 AABB_face_graph_traits; void test_all_pairs() { diff --git a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Bounded_distance_placement.h b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Bounded_distance_placement.h index 0e88fec1c8c..81824c17c9b 100644 --- a/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Bounded_distance_placement.h +++ b/Surface_mesh_simplification/include/CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Bounded_distance_placement.h @@ -15,8 +15,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -41,8 +41,8 @@ class Bounded_distance_placement typedef std::vector Triangle_container; typedef typename Triangle_container::iterator TC_iterator; - typedef CGAL::AABB_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_triangle_primitive_3 Primitive; + typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree AABB_tree; private: diff --git a/Surface_mesh_simplification/test/Surface_mesh_simplification/test_edge_collapse_bounded_distance.cpp b/Surface_mesh_simplification/test/Surface_mesh_simplification/test_edge_collapse_bounded_distance.cpp index f6cd535bf50..bdf57a591b7 100644 --- a/Surface_mesh_simplification/test/Surface_mesh_simplification/test_edge_collapse_bounded_distance.cpp +++ b/Surface_mesh_simplification/test/Surface_mesh_simplification/test_edge_collapse_bounded_distance.cpp @@ -10,7 +10,7 @@ //AABB_tree #include -#include +#include #include //bbox @@ -30,7 +30,7 @@ typedef SMS::LindstromTurk_cost Cost; typedef SMS::LindstromTurk_placement Placement; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; -typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_traits_3 Traits; typedef CGAL::AABB_tree Tree; typedef SMS::Bounded_distance_placement Filtered_placement; diff --git a/Surface_mesher/include/CGAL/AABB_polyhedral_oracle.h b/Surface_mesher/include/CGAL/AABB_polyhedral_oracle.h index d03fe0b0fe5..0f05ae1f18e 100644 --- a/Surface_mesher/include/CGAL/AABB_polyhedral_oracle.h +++ b/Surface_mesher/include/CGAL/AABB_polyhedral_oracle.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include @@ -46,7 +46,7 @@ namespace CGAL { // AABB tree typedef AABB_face_graph_triangle_primitive AABB_primitive; - typedef class AABB_traits AABB_traits; + typedef class AABB_traits_3 AABB_traits; typedef AABB_tree Tree; typedef typename AABB_traits::Bounding_box Bounding_box;