Skip to content

Commit 82206b5

Browse files
committed
CGAL: support version 6.0
- Support version 5 and 6 in CMakeLists.txt - Add version checks in cpp files. - Add include for generator functions. Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
1 parent 11f16f0 commit 82206b5

5 files changed

Lines changed: 112 additions & 10 deletions

File tree

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: 65 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>
@@ -33,6 +37,7 @@
3337

3438
#include <CGAL/algorithm.h>
3539
#include <CGAL/boost/graph/Euler_operations.h>
40+
#include <CGAL/boost/graph/generators.h>
3641
#include <CGAL/number_utils.h>
3742
#include <CGAL/point_generators_2.h>
3843

@@ -137,12 +142,23 @@ TEST(CGAL, SurfaceMesh) {
137142
typedef K::Segment_3 Segment;
138143
typedef CGAL::Surface_mesh<Point3> Mesh;
139144
typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
145+
#if CGAL_VERSION_MAJOR >= 6
146+
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
147+
#else
140148
typedef CGAL::AABB_traits<K, Primitive> Traits;
149+
#endif
141150
typedef CGAL::AABB_tree<Traits> Tree;
151+
#if CGAL_VERSION_MAJOR >= 6
152+
typedef std::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
153+
Segment_intersection;
154+
typedef std::optional<Tree::Intersection_and_primitive_id<Plane>::Type>
155+
Plane_intersection;
156+
#else
142157
typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
143158
Segment_intersection;
144159
typedef boost::optional<Tree::Intersection_and_primitive_id<Plane>::Type>
145160
Plane_intersection;
161+
#endif
146162
typedef Tree::Primitive_id Primitive_id;
147163

148164
Point3 p(1.0, 0.0, 0.0);
@@ -177,8 +193,13 @@ TEST(CGAL, SurfaceMesh) {
177193
tree.any_intersection(segment_query);
178194
if (intersection) {
179195
// gets intersection object
196+
#if CGAL_VERSION_MAJOR >= 6
197+
if (std::get_if<Point3>(&(intersection->first))) {
198+
// Point3* p = std::get_if<Point3>(&(intersection->first));
199+
#else
180200
if (boost::get<Point3>(&(intersection->first))) {
181201
// Point3* p = boost::get<Point3>(&(intersection->first));
202+
#endif
182203
// std::cout << "intersection object is a point " << *p << "\n";
183204
// std::cout << "with face "<< intersection->second << "\n";
184205
}
@@ -203,8 +224,13 @@ TEST(CGAL, SurfaceMesh) {
203224
// (generally a segment)
204225
Plane_intersection plane_intersection = tree.any_intersection(plane_query);
205226
if (plane_intersection) {
227+
#if CGAL_VERSION_MAJOR >= 6
228+
if (std::get_if<Segment>(&(plane_intersection->first))) {
229+
// Segment* s = std::get_if<Segment>(&(plane_intersection->first));
230+
#else
206231
if (boost::get<Segment>(&(plane_intersection->first))) {
207232
// Segment* s = boost::get<Segment>(&(plane_intersection->first));
233+
#endif
208234
// std::cout << "one intersection object is the segment " << s << "\n";
209235
// std::cout << "with face "<< intersection->second << "\n";
210236
}
@@ -223,7 +249,11 @@ TEST(CGAL, AABBPolyhedronFacetIntersection) {
223249
// typedef K::Segment_3 Segment;
224250
typedef CGAL::Polyhedron_3<K> Polyhedron;
225251
typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
252+
#if CGAL_VERSION_MAJOR >= 6
253+
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
254+
#else
226255
typedef CGAL::AABB_traits<K, Primitive> Traits;
256+
#endif
227257
typedef CGAL::AABB_tree<Traits> Tree;
228258
// typedef Tree::Point_and_primitive_id Point_and_primitive_id;
229259

@@ -276,17 +306,25 @@ TEST(CGAL, SurfaceMeshGridCell) {
276306
// typedef Mesh::Face_index face_descriptor;
277307

278308
typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
309+
#if CGAL_VERSION_MAJOR >= 6
310+
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
311+
#else
279312
typedef CGAL::AABB_traits<K, Primitive> Traits;
313+
#endif
280314
typedef CGAL::AABB_tree<Traits> Tree;
281315
// typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
282316
// Segment_intersection;
283317
// typedef boost::optional<Tree::Intersection_and_primitive_id<Plane>::Type>
284318
// Plane_intersection;
285319
// typedef Tree::Primitive_id Primitive_id;
286320

321+
#if CGAL_VERSION_MAJOR >= 6
322+
typedef std::optional<Tree::Intersection_and_primitive_id<Ray>::Type>
323+
Ray_intersection;
324+
#else
287325
typedef boost::optional<Tree::Intersection_and_primitive_id<Ray>::Type>
288326
Ray_intersection;
289-
327+
#endif
290328
typedef CGAL::Timer Timer;
291329

292330
Point3 p0(-1.0, -1.0, 1.0);
@@ -344,8 +382,13 @@ TEST(CGAL, SurfaceMeshGridCell) {
344382
// std::cout << "Intersect (x1000): " << t.time() << " sec" << "\n";
345383

346384
// if(intersection) {
385+
#if CGAL_VERSION_MAJOR >= 6
386+
// if(std::get_if<Point3>(&(intersection->first))) {
387+
// const Point3* p = std::get_if<Point3>(&(intersection->first));
388+
#else
347389
// if(boost::get<Point3>(&(intersection->first))) {
348-
// const Point3* p = boost::get<Point3>(&(intersection->first));
390+
// const Point3* p = boost::get<Point3>(&(intersection->first));
391+
#endif
349392
// std::cout << *p << "\n";
350393
// }
351394
// }
@@ -366,17 +409,25 @@ TEST(CGAL, SurfaceMeshGrid) {
366409
// typedef Mesh::Face_index face_descriptor;
367410

368411
typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
412+
#if CGAL_VERSION_MAJOR >= 6
413+
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
414+
#else
369415
typedef CGAL::AABB_traits<K, Primitive> Traits;
416+
#endif
370417
typedef CGAL::AABB_tree<Traits> Tree;
371418
// typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
372419
// Segment_intersection;
373420
// typedef boost::optional<Tree::Intersection_and_primitive_id<Plane>::Type>
374421
// Plane_intersection;
375422
// typedef Tree::Primitive_id Primitive_id;
376423

424+
#if CGAL_VERSION_MAJOR >= 6
425+
typedef std::optional<Tree::Intersection_and_primitive_id<Ray>::Type>
426+
Ray_intersection;
427+
#else
377428
typedef boost::optional<Tree::Intersection_and_primitive_id<Ray>::Type>
378429
Ray_intersection;
379-
430+
#endif
380431
typedef CGAL::Timer Timer;
381432

382433
// Create Grid
@@ -432,8 +483,13 @@ TEST(CGAL, SurfaceMeshGrid) {
432483
// << "): " << t.time() << " sec" << "\n";
433484

434485
// if(intersection) {
486+
#if CGAL_VERSION_MAJOR >= 6
487+
// if(std::get_if<Point3>(&(intersection->first))) {
488+
// const Point3* p = std::get_if<Point3>(&(intersection->first));
489+
#else
435490
// if(boost::get<Point3>(&(intersection->first))) {
436-
// const Point3* p = boost::get<Point3>(&(intersection->first));
491+
// const Point3* p = boost::get<Point3>(&(intersection->first));
492+
#endif
437493
// std::cout << *p << "\n";
438494
// }
439495
// }
@@ -454,7 +510,11 @@ TEST(CGAL, SurfaceMeshModifyGrid) {
454510
// typedef Mesh::Face_index face_descriptor;
455511

456512
// typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
513+
#if CGAL_VERSION_MAJOR >= 6
514+
// typedef CGAL::AABB_traits_3<K, Primitive> Traits;
515+
#else
457516
// typedef CGAL::AABB_traits<K, Primitive> Traits;
517+
#endif
458518
// typedef CGAL::AABB_tree<Traits> Tree;
459519
// typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
460520
// Segment_intersection;
@@ -507,7 +567,7 @@ TEST(CGAL, SurfaceMeshWavefield) {
507567
// typedef Mesh::Face_index face_descriptor;
508568

509569
// typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
510-
// typedef CGAL::AABB_traits<K, Primitive> Traits;
570+
// typedef CGAL::AABB_traits_3<K, Primitive> Traits;
511571
// typedef CGAL::AABB_tree<Traits> Tree;
512572
// typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
513573
// 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)