diff --git a/gz-waves/CMakeLists.txt b/gz-waves/CMakeLists.txt index 64e812de..5755769b 100644 --- a/gz-waves/CMakeLists.txt +++ b/gz-waves/CMakeLists.txt @@ -244,8 +244,12 @@ if(NOT CGAL_FOUND) return() endif() -# include helper file -include(${CGAL_USE_FILE}) +message("CGAL_VERSION_MAJOR: ${CGAL_VERSION_MAJOR}") + +if (${CGAL_VERSION_MAJOR} LESS 6) + # include helper file + include(${CGAL_USE_FILE}) +endif() #-------------------------------------- # Find FFTW3 (double-precision) (GPL) as FFT library. diff --git a/gz-waves/include/gz/waves/CGALTypes.hh b/gz-waves/include/gz/waves/CGALTypes.hh index 2f747994..82f97c72 100644 --- a/gz-waves/include/gz/waves/CGALTypes.hh +++ b/gz-waves/include/gz/waves/CGALTypes.hh @@ -20,7 +20,14 @@ #define GZ_WAVES_CGALTYPES_HH_ #include +#ifndef CGAL_VERSION_MAJOR +#error +#endif +#if CGAL_VERSION_MAJOR >= 6 +#include +#else #include +#endif #include #include #include @@ -53,7 +60,11 @@ typedef Mesh::Vertex_index VertexIndex; // AABB Tree typedef CGAL::AABB_face_graph_triangle_primitive Primitive; +#if CGAL_VERSION_MAJOR >= 6 +typedef CGAL::AABB_traits_3 Traits; +#else typedef CGAL::AABB_traits Traits; +#endif typedef CGAL::AABB_tree AABBTree; // Pointers diff --git a/gz-waves/src/CGAL_TEST.cc b/gz-waves/src/CGAL_TEST.cc index 6f5df69a..f2c312d0 100644 --- a/gz-waves/src/CGAL_TEST.cc +++ b/gz-waves/src/CGAL_TEST.cc @@ -16,7 +16,11 @@ #include #include +#if CGAL_VERSION_MAJOR >= 6 +#include +#else #include +#endif #include #include #include @@ -137,12 +141,23 @@ TEST(CGAL, SurfaceMesh) { typedef K::Segment_3 Segment; typedef CGAL::Surface_mesh Mesh; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; +#if CGAL_VERSION_MAJOR >= 6 + typedef CGAL::AABB_traits_3 Traits; +#else typedef CGAL::AABB_traits Traits; +#endif typedef CGAL::AABB_tree Tree; +#if CGAL_VERSION_MAJOR >= 6 + typedef std::optional::Type> + Segment_intersection; + typedef std::optional::Type> + Plane_intersection; +#else typedef boost::optional::Type> Segment_intersection; typedef boost::optional::Type> Plane_intersection; +#endif typedef Tree::Primitive_id Primitive_id; Point3 p(1.0, 0.0, 0.0); @@ -177,8 +192,13 @@ TEST(CGAL, SurfaceMesh) { tree.any_intersection(segment_query); if (intersection) { // gets intersection object +#if CGAL_VERSION_MAJOR >= 6 + if (std::get_if(&(intersection->first))) { + // Point3* p = std::get_if(&(intersection->first)); +#else if (boost::get(&(intersection->first))) { // Point3* p = boost::get(&(intersection->first)); +#endif // std::cout << "intersection object is a point " << *p << "\n"; // std::cout << "with face "<< intersection->second << "\n"; } @@ -203,8 +223,13 @@ TEST(CGAL, SurfaceMesh) { // (generally a segment) Plane_intersection plane_intersection = tree.any_intersection(plane_query); if (plane_intersection) { +#if CGAL_VERSION_MAJOR >= 6 + if (std::get_if(&(plane_intersection->first))) { + // Segment* s = std::get_if(&(plane_intersection->first)); +#else if (boost::get(&(plane_intersection->first))) { // Segment* s = boost::get(&(plane_intersection->first)); +#endif // std::cout << "one intersection object is the segment " << s << "\n"; // std::cout << "with face "<< intersection->second << "\n"; } @@ -223,7 +248,11 @@ TEST(CGAL, AABBPolyhedronFacetIntersection) { // typedef K::Segment_3 Segment; typedef CGAL::Polyhedron_3 Polyhedron; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; +#if CGAL_VERSION_MAJOR >= 6 + typedef CGAL::AABB_traits_3 Traits; +#else typedef CGAL::AABB_traits Traits; +#endif typedef CGAL::AABB_tree Tree; // typedef Tree::Point_and_primitive_id Point_and_primitive_id; @@ -276,7 +305,11 @@ TEST(CGAL, SurfaceMeshGridCell) { // typedef Mesh::Face_index face_descriptor; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; +#if CGAL_VERSION_MAJOR >= 6 + typedef CGAL::AABB_traits_3 Traits; +#else typedef CGAL::AABB_traits Traits; +#endif typedef CGAL::AABB_tree Tree; // typedef boost::optional::Type> // Segment_intersection; @@ -284,9 +317,13 @@ TEST(CGAL, SurfaceMeshGridCell) { // Plane_intersection; // typedef Tree::Primitive_id Primitive_id; +#if CGAL_VERSION_MAJOR >= 6 + typedef std::optional::Type> + Ray_intersection; +#else typedef boost::optional::Type> Ray_intersection; - +#endif typedef CGAL::Timer Timer; Point3 p0(-1.0, -1.0, 1.0); @@ -344,8 +381,13 @@ TEST(CGAL, SurfaceMeshGridCell) { // std::cout << "Intersect (x1000): " << t.time() << " sec" << "\n"; // if(intersection) { +#if CGAL_VERSION_MAJOR >= 6 + // if(std::get_if(&(intersection->first))) { + // const Point3* p = std::get_if(&(intersection->first)); +#else // if(boost::get(&(intersection->first))) { - // const Point3* p = boost::get(&(intersection->first)); + // const Point3* p = boost::get(&(intersection->first)); +#endif // std::cout << *p << "\n"; // } // } @@ -366,7 +408,11 @@ TEST(CGAL, SurfaceMeshGrid) { // typedef Mesh::Face_index face_descriptor; typedef CGAL::AABB_face_graph_triangle_primitive Primitive; +#if CGAL_VERSION_MAJOR >= 6 + typedef CGAL::AABB_traits_3 Traits; +#else typedef CGAL::AABB_traits Traits; +#endif typedef CGAL::AABB_tree Tree; // typedef boost::optional::Type> // Segment_intersection; @@ -374,9 +420,13 @@ TEST(CGAL, SurfaceMeshGrid) { // Plane_intersection; // typedef Tree::Primitive_id Primitive_id; +#if CGAL_VERSION_MAJOR >= 6 + typedef std::optional::Type> + Ray_intersection; +#else typedef boost::optional::Type> Ray_intersection; - +#endif typedef CGAL::Timer Timer; // Create Grid @@ -432,8 +482,13 @@ TEST(CGAL, SurfaceMeshGrid) { // << "): " << t.time() << " sec" << "\n"; // if(intersection) { +#if CGAL_VERSION_MAJOR >= 6 + // if(std::get_if(&(intersection->first))) { + // const Point3* p = std::get_if(&(intersection->first)); +#else // if(boost::get(&(intersection->first))) { - // const Point3* p = boost::get(&(intersection->first)); + // const Point3* p = boost::get(&(intersection->first)); +#endif // std::cout << *p << "\n"; // } // } @@ -454,7 +509,11 @@ TEST(CGAL, SurfaceMeshModifyGrid) { // typedef Mesh::Face_index face_descriptor; // typedef CGAL::AABB_face_graph_triangle_primitive Primitive; +#if CGAL_VERSION_MAJOR >= 6 + // typedef CGAL::AABB_traits_3 Traits; +#else // typedef CGAL::AABB_traits Traits; +#endif // typedef CGAL::AABB_tree Tree; // typedef boost::optional::Type> // Segment_intersection; @@ -507,7 +566,7 @@ TEST(CGAL, SurfaceMeshWavefield) { // typedef Mesh::Face_index face_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 boost::optional::Type> // Segment_intersection; diff --git a/gz-waves/src/CMakeLists.txt b/gz-waves/src/CMakeLists.txt index 36aeebb9..32f54ced 100644 --- a/gz-waves/src/CMakeLists.txt +++ b/gz-waves/src/CMakeLists.txt @@ -63,6 +63,12 @@ target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME} sdformat${SDF_VER}::sdformat${SDF_VER} ${FFT_LIBRARIES} ) +if (${CGAL_VERSION_MAJOR} GREATER_EQUAL 6) + target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME} + PUBLIC + CGAL::CGAL + ) +endif() if (UNIX AND NOT APPLE) target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME} PRIVATE stdc++fs) diff --git a/gz-waves/src/Geometry.cc b/gz-waves/src/Geometry.cc index c8da5367..d9c2d0fd 100644 --- a/gz-waves/src/Geometry.cc +++ b/gz-waves/src/Geometry.cc @@ -17,7 +17,11 @@ #include #include +#if CGAL_VERSION_MAJOR >= 6 +#include +#else #include +#endif #include #include #include @@ -29,15 +33,20 @@ #include #include #include +#include namespace gz { namespace waves { // Typedefs +#if CGAL_VERSION_MAJOR >= 6 +typedef std::optional::Type> RayIntersection; +#else typedef boost::optional::Type> RayIntersection; - +#endif double Geometry::TriangleArea( const cgal::Point3& _p0, const cgal::Point3& _p1, @@ -305,9 +314,15 @@ bool Geometry::SearchMesh( // Retrieve intersection point if (intersection) { +#if CGAL_VERSION_MAJOR >= 6 + if (std::get_if(&(intersection->first))) + { + const cgal::Point3* p = std::get_if(&(intersection->first)); +#else if (boost::get(&(intersection->first))) { - const cgal::Point3* p = boost::get(&(intersection->first)); + const cgal::Point3* p = boost::get(&(intersection->first)); +#endif _intersection = *p; return true; } @@ -333,9 +348,15 @@ bool Geometry::SearchMesh( // Retrieve intersection point if (intersection) { +#if CGAL_VERSION_MAJOR >= 6 + if (std::get_if(&(intersection->first))) + { + const cgal::Point3* p = std::get_if(&(intersection->first)); +#else if (boost::get(&(intersection->first))) { - const cgal::Point3* p = boost::get(&(intersection->first)); + const cgal::Point3* p = boost::get(&(intersection->first)); +#endif _intersection = *p; return true; }