Skip to content

Commit cad7002

Browse files
committed
CGAL: support version 6.0
- Support version 5 and 6 in CMakeLists.txt - Add version checks in cpp files. Signed-off-by: Rhys Mainwaring <[email protected]> CGAL: support version 6.0 Signed-off-by: Rhys Mainwaring <[email protected]>
1 parent cca5db0 commit cad7002

File tree

5 files changed

+111
-10
lines changed

5 files changed

+111
-10
lines changed

gz-waves/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,12 @@ if(NOT CGAL_FOUND)
244244
return()
245245
endif()
246246

247-
# include helper file
248-
include(${CGAL_USE_FILE})
247+
message("CGAL_VERSION_MAJOR: ${CGAL_VERSION_MAJOR}")
248+
249+
if (${CGAL_VERSION_MAJOR} LESS 6)
250+
# include helper file
251+
include(${CGAL_USE_FILE})
252+
endif()
249253

250254
#--------------------------------------
251255
# Find FFTW3 (double-precision) (GPL) as FFT library.

gz-waves/include/gz/waves/CGALTypes.hh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@
2020
#define GZ_WAVES_CGALTYPES_HH_
2121

2222
#include <CGAL/AABB_face_graph_triangle_primitive.h>
23+
#ifndef CGAL_VERSION_MAJOR
24+
#error
25+
#endif
26+
#if CGAL_VERSION_MAJOR >= 6
27+
#include <CGAL/AABB_traits_3.h>
28+
#else
2329
#include <CGAL/AABB_traits.h>
30+
#endif
2431
#include <CGAL/AABB_tree.h>
2532
#include <CGAL/Simple_cartesian.h>
2633
#include <CGAL/Surface_mesh.h>
@@ -53,7 +60,11 @@ typedef Mesh::Vertex_index VertexIndex;
5360

5461
// AABB Tree
5562
typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
63+
#if CGAL_VERSION_MAJOR >= 6
64+
typedef CGAL::AABB_traits_3<Kernel, Primitive> Traits;
65+
#else
5666
typedef CGAL::AABB_traits<Kernel, Primitive> Traits;
67+
#endif
5768
typedef CGAL::AABB_tree<Traits> AABBTree;
5869

5970
// Pointers

gz-waves/src/CGAL_TEST.cc

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
#include <gtest/gtest.h>
1717

1818
#include <CGAL/AABB_face_graph_triangle_primitive.h>
19+
#if CGAL_VERSION_MAJOR >= 6
20+
#include <CGAL/AABB_traits_3.h>
21+
#else
1922
#include <CGAL/AABB_traits.h>
23+
#endif
2024
#include <CGAL/AABB_tree.h>
2125
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
2226
#include <CGAL/Constrained_triangulation_2.h>
@@ -137,12 +141,23 @@ TEST(CGAL, SurfaceMesh) {
137141
typedef K::Segment_3 Segment;
138142
typedef CGAL::Surface_mesh<Point3> Mesh;
139143
typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
144+
#if CGAL_VERSION_MAJOR >= 6
145+
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
146+
#else
140147
typedef CGAL::AABB_traits<K, Primitive> Traits;
148+
#endif
141149
typedef CGAL::AABB_tree<Traits> Tree;
150+
#if CGAL_VERSION_MAJOR >= 6
151+
typedef std::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
152+
Segment_intersection;
153+
typedef std::optional<Tree::Intersection_and_primitive_id<Plane>::Type>
154+
Plane_intersection;
155+
#else
142156
typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
143157
Segment_intersection;
144158
typedef boost::optional<Tree::Intersection_and_primitive_id<Plane>::Type>
145159
Plane_intersection;
160+
#endif
146161
typedef Tree::Primitive_id Primitive_id;
147162

148163
Point3 p(1.0, 0.0, 0.0);
@@ -177,8 +192,13 @@ TEST(CGAL, SurfaceMesh) {
177192
tree.any_intersection(segment_query);
178193
if (intersection) {
179194
// gets intersection object
195+
#if CGAL_VERSION_MAJOR >= 6
196+
if (std::get_if<Point3>(&(intersection->first))) {
197+
// Point3* p = std::get_if<Point3>(&(intersection->first));
198+
#else
180199
if (boost::get<Point3>(&(intersection->first))) {
181200
// Point3* p = boost::get<Point3>(&(intersection->first));
201+
#endif
182202
// std::cout << "intersection object is a point " << *p << "\n";
183203
// std::cout << "with face "<< intersection->second << "\n";
184204
}
@@ -203,8 +223,13 @@ TEST(CGAL, SurfaceMesh) {
203223
// (generally a segment)
204224
Plane_intersection plane_intersection = tree.any_intersection(plane_query);
205225
if (plane_intersection) {
226+
#if CGAL_VERSION_MAJOR >= 6
227+
if (std::get_if<Segment>(&(plane_intersection->first))) {
228+
// Segment* s = std::get_if<Segment>(&(plane_intersection->first));
229+
#else
206230
if (boost::get<Segment>(&(plane_intersection->first))) {
207231
// Segment* s = boost::get<Segment>(&(plane_intersection->first));
232+
#endif
208233
// std::cout << "one intersection object is the segment " << s << "\n";
209234
// std::cout << "with face "<< intersection->second << "\n";
210235
}
@@ -223,7 +248,11 @@ TEST(CGAL, AABBPolyhedronFacetIntersection) {
223248
// typedef K::Segment_3 Segment;
224249
typedef CGAL::Polyhedron_3<K> Polyhedron;
225250
typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
251+
#if CGAL_VERSION_MAJOR >= 6
252+
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
253+
#else
226254
typedef CGAL::AABB_traits<K, Primitive> Traits;
255+
#endif
227256
typedef CGAL::AABB_tree<Traits> Tree;
228257
// typedef Tree::Point_and_primitive_id Point_and_primitive_id;
229258

@@ -276,17 +305,25 @@ TEST(CGAL, SurfaceMeshGridCell) {
276305
// typedef Mesh::Face_index face_descriptor;
277306

278307
typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
308+
#if CGAL_VERSION_MAJOR >= 6
309+
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
310+
#else
279311
typedef CGAL::AABB_traits<K, Primitive> Traits;
312+
#endif
280313
typedef CGAL::AABB_tree<Traits> Tree;
281314
// typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
282315
// Segment_intersection;
283316
// typedef boost::optional<Tree::Intersection_and_primitive_id<Plane>::Type>
284317
// Plane_intersection;
285318
// typedef Tree::Primitive_id Primitive_id;
286319

320+
#if CGAL_VERSION_MAJOR >= 6
321+
typedef std::optional<Tree::Intersection_and_primitive_id<Ray>::Type>
322+
Ray_intersection;
323+
#else
287324
typedef boost::optional<Tree::Intersection_and_primitive_id<Ray>::Type>
288325
Ray_intersection;
289-
326+
#endif
290327
typedef CGAL::Timer Timer;
291328

292329
Point3 p0(-1.0, -1.0, 1.0);
@@ -344,8 +381,13 @@ TEST(CGAL, SurfaceMeshGridCell) {
344381
// std::cout << "Intersect (x1000): " << t.time() << " sec" << "\n";
345382

346383
// if(intersection) {
384+
#if CGAL_VERSION_MAJOR >= 6
385+
// if(std::get_if<Point3>(&(intersection->first))) {
386+
// const Point3* p = std::get_if<Point3>(&(intersection->first));
387+
#else
347388
// if(boost::get<Point3>(&(intersection->first))) {
348-
// const Point3* p = boost::get<Point3>(&(intersection->first));
389+
// const Point3* p = boost::get<Point3>(&(intersection->first));
390+
#endif
349391
// std::cout << *p << "\n";
350392
// }
351393
// }
@@ -366,17 +408,25 @@ TEST(CGAL, SurfaceMeshGrid) {
366408
// typedef Mesh::Face_index face_descriptor;
367409

368410
typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
411+
#if CGAL_VERSION_MAJOR >= 6
412+
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
413+
#else
369414
typedef CGAL::AABB_traits<K, Primitive> Traits;
415+
#endif
370416
typedef CGAL::AABB_tree<Traits> Tree;
371417
// typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
372418
// Segment_intersection;
373419
// typedef boost::optional<Tree::Intersection_and_primitive_id<Plane>::Type>
374420
// Plane_intersection;
375421
// typedef Tree::Primitive_id Primitive_id;
376422

423+
#if CGAL_VERSION_MAJOR >= 6
424+
typedef std::optional<Tree::Intersection_and_primitive_id<Ray>::Type>
425+
Ray_intersection;
426+
#else
377427
typedef boost::optional<Tree::Intersection_and_primitive_id<Ray>::Type>
378428
Ray_intersection;
379-
429+
#endif
380430
typedef CGAL::Timer Timer;
381431

382432
// Create Grid
@@ -432,8 +482,13 @@ TEST(CGAL, SurfaceMeshGrid) {
432482
// << "): " << t.time() << " sec" << "\n";
433483

434484
// if(intersection) {
485+
#if CGAL_VERSION_MAJOR >= 6
486+
// if(std::get_if<Point3>(&(intersection->first))) {
487+
// const Point3* p = std::get_if<Point3>(&(intersection->first));
488+
#else
435489
// if(boost::get<Point3>(&(intersection->first))) {
436-
// const Point3* p = boost::get<Point3>(&(intersection->first));
490+
// const Point3* p = boost::get<Point3>(&(intersection->first));
491+
#endif
437492
// std::cout << *p << "\n";
438493
// }
439494
// }
@@ -454,7 +509,11 @@ TEST(CGAL, SurfaceMeshModifyGrid) {
454509
// typedef Mesh::Face_index face_descriptor;
455510

456511
// typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
512+
#if CGAL_VERSION_MAJOR >= 6
513+
// typedef CGAL::AABB_traits_3<K, Primitive> Traits;
514+
#else
457515
// typedef CGAL::AABB_traits<K, Primitive> Traits;
516+
#endif
458517
// typedef CGAL::AABB_tree<Traits> Tree;
459518
// typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
460519
// Segment_intersection;
@@ -507,7 +566,7 @@ TEST(CGAL, SurfaceMeshWavefield) {
507566
// typedef Mesh::Face_index face_descriptor;
508567

509568
// typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
510-
// typedef CGAL::AABB_traits<K, Primitive> Traits;
569+
// typedef CGAL::AABB_traits_3<K, Primitive> Traits;
511570
// typedef CGAL::AABB_tree<Traits> Tree;
512571
// typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
513572
// Segment_intersection;

gz-waves/src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
6363
sdformat${SDF_VER}::sdformat${SDF_VER}
6464
${FFT_LIBRARIES}
6565
)
66+
if (${CGAL_VERSION_MAJOR} GREATER_EQUAL 6)
67+
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
68+
PUBLIC
69+
CGAL::CGAL
70+
)
71+
endif()
6672
if (UNIX AND NOT APPLE)
6773
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
6874
PRIVATE stdc++fs)

gz-waves/src/Geometry.cc

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717

1818
#include <CGAL/AABB_face_graph_triangle_primitive.h>
1919
#include <CGAL/AABB_tree.h>
20+
#if CGAL_VERSION_MAJOR >= 6
21+
#include <CGAL/AABB_traits_3.h>
22+
#else
2023
#include <CGAL/AABB_traits.h>
24+
#endif
2125
#include <CGAL/Simple_cartesian.h>
2226
#include <CGAL/Surface_mesh.h>
2327
#include <CGAL/Timer.h>
@@ -29,15 +33,20 @@
2933
#include <limits>
3034
#include <memory>
3135
#include <string>
36+
#include <variant>
3237

3338
namespace gz
3439
{
3540
namespace waves
3641
{
3742
// Typedefs
43+
#if CGAL_VERSION_MAJOR >= 6
44+
typedef std::optional<cgal::AABBTree::Intersection_and_primitive_id<
45+
cgal::Ray>::Type> RayIntersection;
46+
#else
3847
typedef boost::optional<cgal::AABBTree::Intersection_and_primitive_id<
3948
cgal::Ray>::Type> RayIntersection;
40-
49+
#endif
4150
double Geometry::TriangleArea(
4251
const cgal::Point3& _p0,
4352
const cgal::Point3& _p1,
@@ -305,9 +314,15 @@ bool Geometry::SearchMesh(
305314
// Retrieve intersection point
306315
if (intersection)
307316
{
317+
#if CGAL_VERSION_MAJOR >= 6
318+
if (std::get_if<cgal::Point3>(&(intersection->first)))
319+
{
320+
const cgal::Point3* p = std::get_if<cgal::Point3>(&(intersection->first));
321+
#else
308322
if (boost::get<cgal::Point3>(&(intersection->first)))
309323
{
310-
const cgal::Point3* p = boost::get<cgal::Point3>(&(intersection->first));
324+
const cgal::Point3* p = boost::get<cgal::Point3>(&(intersection->first));
325+
#endif
311326
_intersection = *p;
312327
return true;
313328
}
@@ -333,9 +348,15 @@ bool Geometry::SearchMesh(
333348
// Retrieve intersection point
334349
if (intersection)
335350
{
351+
#if CGAL_VERSION_MAJOR >= 6
352+
if (std::get_if<cgal::Point3>(&(intersection->first)))
353+
{
354+
const cgal::Point3* p = std::get_if<cgal::Point3>(&(intersection->first));
355+
#else
336356
if (boost::get<cgal::Point3>(&(intersection->first)))
337357
{
338-
const cgal::Point3* p = boost::get<cgal::Point3>(&(intersection->first));
358+
const cgal::Point3* p = boost::get<cgal::Point3>(&(intersection->first));
359+
#endif
339360
_intersection = *p;
340361
return true;
341362
}

0 commit comments

Comments
 (0)