Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the AABB-tree to work in both 2D and 3D #8057

Merged
merged 102 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 100 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
006d46b
start updating the AABB-tree to work in both 2D and 3D
sloriot Mar 4, 2024
4a482dd
compatibility headers
sloriot Mar 4, 2024
2eff0eb
add missing files
sloriot Mar 4, 2024
26d40e7
rename concept
sloriot Mar 4, 2024
ae0f114
Update AABB_tree/include/CGAL/AABB_traits_3.h
sloriot Mar 4, 2024
ee187c5
use Search_traits_adapter instead of Decorated_point
sloriot Mar 4, 2024
c4a1197
AABB_traits_3 is model of Search_traits
sloriot Mar 4, 2024
32e68f8
fix concept doc
sloriot Mar 4, 2024
6453b08
more doc fixes
sloriot Mar 4, 2024
84362a2
Add Construct_projected_point_2::operator()(Segment_2,Point_2)
afabri Mar 4, 2024
26d8793
Changes so that the 2D example compiles
afabri Mar 4, 2024
a76cc2b
Typo in concept AABBGeomTraits_3
afabri Mar 4, 2024
14efb2c
whitespace
afabri Mar 4, 2024
b34c63c
Add AABBGeomTraits_2
afabri Mar 4, 2024
f0bdc2d
Make Minkowski_sum_2 work
afabri Mar 4, 2024
eb49100
Replace deprecated classes
afabri Mar 5, 2024
b70a736
Replace deprecated classes
afabri Mar 5, 2024
6c1185d
Add AABB_triangle_primitive_2
afabri Mar 5, 2024
56ac3a5
Replace deprecated classes
afabri Mar 5, 2024
911ac1a
added Construct_projected_point_2(Segment_2, Point_2)
soesau Mar 5, 2024
3f9c522
WIP: adding Construct_projected_point_2 for point onto segment and po…
soesau Mar 6, 2024
cda5d0a
adding AABB_polyline_segment_primitive_2 for Polygon_2 and PointRange
soesau Mar 6, 2024
1be8f23
Apply suggestions from code review
soesau Mar 7, 2024
6ae5c63
A _3 too much
afabri Mar 8, 2024
19725c0
Fix PMP testsuite
afabri Mar 8, 2024
37e36b8
fixed tests for point_2 on segment_2 and on triangle_2
soesau Mar 7, 2024
30cec7d
updating polyline segment primitive and example
soesau Mar 8, 2024
0e8f9c8
update doc in user manual
soesau Mar 8, 2024
83aa8cf
added AABB_indexed_triangle_primitive_2
soesau Mar 9, 2024
b02c409
polish examples
afabri Mar 12, 2024
2e4c576
Fix typo
afabri Mar 12, 2024
f9e5285
Add AABBRayIntersectionGeomTraits_2.h and fix \sa
afabri Mar 13, 2024
6e4092a
replace _3 with _2
afabri Mar 13, 2024
69ce2c1
Add 2D to the chapter title
afabri Mar 13, 2024
76dff00
Add for linking
afabri Mar 14, 2024
190608d
lowecase
afabri Mar 14, 2024
7e543dc
Add queries outside triangles
afabri Mar 14, 2024
e62f249
triangle is a not a ref
sloriot Mar 15, 2024
f231a3d
Enrich Projection_traits so that it can be used with AABB_traits_2
afabri Mar 15, 2024
4046453
bug fix
afabri Mar 15, 2024
a650d59
whitespace
afabri Mar 15, 2024
b9b1ac4
fixing search tests
soesau Mar 19, 2024
c331dd3
projection via pointmap
soesau Mar 20, 2024
7403de3
Update AABB_tree/examples/AABB_tree/AABB_indexed_triangle_2_example.cpp
soesau Mar 20, 2024
8583c4b
added wrapper to map ray/vector types from AABB_traits_2
soesau Mar 20, 2024
560e576
fix ci
soesau Mar 20, 2024
bc3e8fa
removed type wrapper
soesau Mar 21, 2024
c6ee406
undo projection traits changes
sloriot Mar 21, 2024
ee0a90b
undo more changes
sloriot Mar 21, 2024
cb21cbd
update changes
sloriot Mar 21, 2024
5706253
another forgotten revert
sloriot Mar 21, 2024
8059230
clean up
soesau Mar 21, 2024
86fe47c
re-add Construct_projected_point_2 for 2d closest point query
soesau Mar 21, 2024
00a77dc
cleaning types
soesau Mar 21, 2024
bc24d14
splitting example into declaration and test function
soesau Mar 21, 2024
c193cea
moving PointMap to end of template parameters
soesau Mar 21, 2024
0bc40dc
moving AABB_traits_base and Remove_optional into separate files
soesau Mar 21, 2024
98e5e95
license header fix
soesau Mar 21, 2024
3d87460
re-adding Point_2/3 to AABB_traits_2/3 for compatibility
soesau Mar 21, 2024
12fab6b
using functors from concept to access ray instead of using methods
soesau Mar 22, 2024
4c48945
doc fix 2D/3D
soesau Mar 22, 2024
cee30fb
cleanup traits
soesau Mar 26, 2024
65be613
removing deprecated AABB types
soesau Mar 26, 2024
f0d32fe
Merge branch 'master' into AABB_tree-2d_and_3d
soesau Mar 26, 2024
30d5ca7
added vertex point map
soesau Mar 27, 2024
d788500
doc fix
soesau Mar 27, 2024
149e63f
doc alias
sloriot Mar 28, 2024
8180546
added doc for deprecated types
soesau Mar 28, 2024
340de38
updated reference page
soesau Mar 31, 2024
3152519
Update Installation/CHANGES.md
afabri Apr 3, 2024
5edf512
Update AABB_tree/benchmark/AABB_tree/test.cpp
afabri Apr 10, 2024
1a3e163
Update AABB_tree/demo/AABB_tree/Scene.h
afabri Apr 10, 2024
99cca0f
Update AABB_tree/doc/AABB_tree/Concepts/AABBRayIntersectionGeomTraits…
afabri Apr 10, 2024
ed05a4e
Apply suggestions from code review
afabri Apr 10, 2024
f498daa
Apply suggestions from code review
afabri Apr 10, 2024
22496a8
Apply suggestions from code review
afabri Apr 10, 2024
0e9327e
fixes after review
afabri Apr 10, 2024
4015b2b
fixes after review
afabri Apr 10, 2024
5364629
fixes after review
afabri Apr 10, 2024
725c69b
fixes after review
afabri Apr 10, 2024
3d90915
fixes after review
afabri Apr 10, 2024
a393b8b
fixes after review
afabri Apr 10, 2024
f00844e
fixes after review
afabri Apr 10, 2024
aad631a
fixes after review
afabri Apr 11, 2024
78883c6
fixes after review
afabri Apr 11, 2024
3cd9368
added tests for deprecated classes/traits
soesau Apr 15, 2024
d9cd44e
AABBGeomTraits -> AABBGeomTraits_3
soesau Apr 15, 2024
69f5f23
fix comment ConstRange -> Range
soesau Apr 15, 2024
8e7b7da
fix doc
soesau Apr 15, 2024
7dd2d0b
fixed benchmark by switching to Rigid_triangle_mesh_collision_detection
soesau Apr 16, 2024
a933bf3
fix warnings and compilation issues + build maps for no caching case
sloriot Apr 16, 2024
d9ff3db
rename Polygon to Polygon_2 to avoid name collision
soesau Apr 17, 2024
bbafe6d
cleaned /sa section in primitives
soesau Apr 17, 2024
8cd4e29
update doc
soesau Apr 17, 2024
2c41686
added tests for untested aabb primitives
soesau Apr 17, 2024
0439ea2
fix warnings
soesau Apr 18, 2024
a5e7836
fix test
soesau Apr 18, 2024
ffba627
Merge remote-tracking branch 'cgal/master' into AABB_tree-2d_and_3d
soesau Apr 19, 2024
b49b2a8
update history
sloriot Apr 22, 2024
696683f
Apply suggestions from code review
soesau Apr 22, 2024
4f5bcc6
doc fixes
soesau Apr 25, 2024
6727f78
Fix tiny doc issues
MaelRL May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 30 additions & 31 deletions AABB_tree/benchmark/AABB_tree/test.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>

#include <CGAL/Polygon_mesh_processing/intersection.h>
#include <CGAL/Polygon_mesh_processing/transform.h>

#include <CGAL/boost/graph/copy_face_graph.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/Polygon_mesh_processing/internal/AABB_do_intersect_transform_traits.h>
#include <CGAL/AABB_traits_3.h>
#include <CGAL/Rigid_triangle_mesh_collision_detection.h>
#include <CGAL/AABB_face_graph_triangle_primitive.h>
#include <CGAL/Side_of_triangle_mesh.h>

Expand All @@ -18,12 +18,12 @@ typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Surface_mesh<K::Point_3> Surface_mesh;

typedef CGAL::AABB_face_graph_triangle_primitive<Surface_mesh> Primitive;
typedef CGAL::AABB_do_intersect_transform_traits<K, Primitive> Traits;
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> 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);
Expand All @@ -33,7 +33,7 @@ void naive_test(int k, const char* fname,
CGAL::Aff_transformation_3<K> init1(CGAL::SCALING, 6.0);
PMP::transform(init1, tm);
CGAL::Bbox_3 box = PMP::bbox(tm);
typedef CGAL::AABB_tree<CGAL::AABB_traits<K, Primitive> > Tree;

Tree tmTree(tm.faces_begin(), tm.faces_end(), tm);
Tree tmTree2(tm2.faces_begin(), tm2.faces_end(), tm2);
CGAL::Aff_transformation_3<K> init2(CGAL::TRANSLATION, - K::Vector_3(
Expand Down Expand Up @@ -86,7 +86,8 @@ void naive_test(int k, const char* fname,
T0 = CGAL::Aff_transformation_3<K>(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);
Expand All @@ -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<K> init2(CGAL::TRANSLATION, - K::Vector_3(
(box.xmax()-box.xmin()),0,0));

PMP::transform(init2, tm2);

tmTree.build();
Expand All @@ -113,6 +116,12 @@ void test_no_collision(int k, const char* fname,

CGAL::Side_of_triangle_mesh<Surface_mesh, K,
VPM, Tree> sotm1(tmTree);

CGAL::Rigid_triangle_mesh_collision_detection<Surface_mesh> collision_detection;

collision_detection.add_mesh(tm);
collision_detection.add_mesh(tm2);

for(int i=1; i<k+1; ++i)
{
K::FT rot[9];
Expand All @@ -130,47 +139,37 @@ void test_no_collision(int k, const char* fname,
rot[6], rot[7], rot[8]);
CGAL::Aff_transformation_3<K> T1 = CGAL::Aff_transformation_3<K>(CGAL::TRANSLATION, i*unit_vec);
CGAL::Aff_transformation_3<K> 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<std::size_t, bool> > 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<Surface_mesh, K,
VPM, Tree> 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 "<<path<<std::endl;
int nb_inter(0), nb_no_inter(0), nb_include(0),
naive_inter(0), naive_no_inter(0), naive_include(0);
auto start = std::chrono::steady_clock::now();
naive_test(k, path, naive_inter, naive_no_inter, naive_include);
auto end = std::chrono::steady_clock::now();
std::cout<<"Naive test :"<<naive_inter<<" collisions, "<<naive_include<<" inclusions, "<<naive_no_inter<<" no collision, calculated in "
<<std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << "μs." << std::endl;
std::cout<<"Naive test : "<<naive_inter<<" collisions, "<<naive_include<<" inclusions, "<<naive_no_inter<<" no collision, calculated in "
<<std::chrono::duration_cast<std::chrono::milliseconds>(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: "<<nb_inter<<" collisions, "<<nb_include<<" inclusions, "<<nb_no_inter<<" no collision, calculated in "
<<std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << "μs." << std::endl;
<<std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms." << std::endl;
return 0;
}
10 changes: 5 additions & 5 deletions AABB_tree/demo/AABB_tree/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ void Scene::generate_points_in(const unsigned int nb_points,
}

typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
typedef CGAL::AABB_traits<Kernel, Primitive> Traits;
typedef CGAL::AABB_traits_3<Kernel, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;

std::cout << "Construct AABB tree...";
Expand Down Expand Up @@ -920,7 +920,7 @@ void Scene::generate_inside_points(const unsigned int nb_points)
}

typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
typedef CGAL::AABB_traits<Kernel, Primitive> Traits;
typedef CGAL::AABB_traits_3<Kernel, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;

std::cout << "Construct AABB tree...";
Expand Down Expand Up @@ -962,7 +962,7 @@ void Scene::generate_boundary_segments(const unsigned int nb_slices)
}

typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
typedef CGAL::AABB_traits<Kernel, Primitive> Traits;
typedef CGAL::AABB_traits_3<Kernel, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;
typedef Tree::Object_and_primitive_id Object_and_primitive_id;

Expand Down Expand Up @@ -1012,7 +1012,7 @@ void Scene::generate_boundary_points(const unsigned int nb_points)
}

typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
typedef CGAL::AABB_traits<Kernel, Primitive> Traits;
typedef CGAL::AABB_traits_3<Kernel, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;
typedef Tree::Object_and_primitive_id Object_and_primitive_id;

Expand Down Expand Up @@ -1062,7 +1062,7 @@ void Scene::generate_edge_points(const unsigned int nb_points)
}

typedef CGAL::AABB_halfedge_graph_segment_primitive<Polyhedron> Primitive;
typedef CGAL::AABB_traits<Kernel, Primitive> Traits;
typedef CGAL::AABB_traits_3<Kernel, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;
typedef Tree::Object_and_primitive_id Object_and_primitive_id;

Expand Down
6 changes: 3 additions & 3 deletions AABB_tree/demo/AABB_tree/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "Color_ramp.h"

#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/AABB_traits_3.h>
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
#include <CGAL/AABB_halfedge_graph_segment_primitive.h>
#include <CGAL/AABB_face_graph_triangle_primitive.h>
Expand Down Expand Up @@ -62,11 +62,11 @@ class Scene : public QObject

private:
typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Facet_Primitive;
typedef CGAL::AABB_traits<Kernel, Facet_Primitive> Facet_Traits;
typedef CGAL::AABB_traits_3<Kernel, Facet_Primitive> Facet_Traits;
typedef CGAL::AABB_tree<Facet_Traits> Facet_tree;

typedef CGAL::AABB_halfedge_graph_segment_primitive<Polyhedron> Edge_Primitive;
typedef CGAL::AABB_traits<Kernel, Edge_Primitive> Edge_Traits;
typedef CGAL::AABB_traits_3<Kernel, Edge_Primitive> Edge_Traits;
typedef CGAL::AABB_tree<Edge_Traits> Edge_tree;

typedef CGAL::qglviewer::ManipulatedFrame ManipulatedFrame;
Expand Down
177 changes: 177 additions & 0 deletions AABB_tree/doc/AABB_tree/Concepts/AABBGeomTraits_2.h
Original file line number Diff line number Diff line change
@@ -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<AABBGeomTraits_2, AABBPrimitive>`. 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<AABBGeomTraits_2,AABBPrimitive>`
\sa `CGAL::AABB_tree<AABBTraits>`
\sa `AABBPrimitive`

*/

class AABBGeomTraits_2 {
afabri marked this conversation as resolved.
Show resolved Hide resolved
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 centered at one point and passing through another one.
MaelRL marked this conversation as resolved.
Show resolved Hide resolved
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`.
MaelRL marked this conversation as resolved.
Show resolved Hide resolved
*/
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 */
Loading