Skip to content

Commit

Permalink
CGAL: support version 6.0
Browse files Browse the repository at this point in the history
- Support version 5 and 6 in CMakeLists.txt
- Add version checks in cpp files.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

CGAL: support version 6.0

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
  • Loading branch information
srmainwaring committed Dec 30, 2024
1 parent f86c2b2 commit aefbecd
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 10 deletions.
8 changes: 6 additions & 2 deletions gz-waves/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions gz-waves/include/gz/waves/CGALTypes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@
#define GZ_WAVES_CGALTYPES_HH_

#include <CGAL/AABB_face_graph_triangle_primitive.h>
#ifndef CGAL_VERSION_MAJOR
#error
#endif
#if CGAL_VERSION_MAJOR >= 6
#include <CGAL/AABB_traits_3.h>
#else
#include <CGAL/AABB_traits.h>
#endif
#include <CGAL/AABB_tree.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
Expand Down Expand Up @@ -53,7 +60,11 @@ typedef Mesh::Vertex_index VertexIndex;

// AABB Tree
typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
#if CGAL_VERSION_MAJOR >= 6
typedef CGAL::AABB_traits_3<Kernel, Primitive> Traits;
#else
typedef CGAL::AABB_traits<Kernel, Primitive> Traits;
#endif
typedef CGAL::AABB_tree<Traits> AABBTree;

// Pointers
Expand Down
69 changes: 64 additions & 5 deletions gz-waves/src/CGAL_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
#include <gtest/gtest.h>

#include <CGAL/AABB_face_graph_triangle_primitive.h>
#if CGAL_VERSION_MAJOR >= 6
#include <CGAL/AABB_traits_3.h>
#else
#include <CGAL/AABB_traits.h>
#endif
#include <CGAL/AABB_tree.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Constrained_triangulation_2.h>
Expand Down Expand Up @@ -137,12 +141,23 @@ TEST(CGAL, SurfaceMesh) {
typedef K::Segment_3 Segment;
typedef CGAL::Surface_mesh<Point3> Mesh;
typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
#if CGAL_VERSION_MAJOR >= 6
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
#else
typedef CGAL::AABB_traits<K, Primitive> Traits;
#endif
typedef CGAL::AABB_tree<Traits> Tree;
#if CGAL_VERSION_MAJOR >= 6
typedef std::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
Segment_intersection;
typedef std::optional<Tree::Intersection_and_primitive_id<Plane>::Type>
Plane_intersection;
#else
typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
Segment_intersection;
typedef boost::optional<Tree::Intersection_and_primitive_id<Plane>::Type>
Plane_intersection;
#endif
typedef Tree::Primitive_id Primitive_id;

Point3 p(1.0, 0.0, 0.0);
Expand Down Expand Up @@ -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<Point3>(&(intersection->first))) {
// Point3* p = std::get_if<Point3>(&(intersection->first));
#else
if (boost::get<Point3>(&(intersection->first))) {
// Point3* p = boost::get<Point3>(&(intersection->first));
#endif
// std::cout << "intersection object is a point " << *p << "\n";
// std::cout << "with face "<< intersection->second << "\n";
}
Expand All @@ -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<Segment>(&(plane_intersection->first))) {
// Segment* s = std::get_if<Segment>(&(plane_intersection->first));
#else
if (boost::get<Segment>(&(plane_intersection->first))) {
// Segment* s = boost::get<Segment>(&(plane_intersection->first));
#endif
// std::cout << "one intersection object is the segment " << s << "\n";
// std::cout << "with face "<< intersection->second << "\n";
}
Expand All @@ -223,7 +248,11 @@ TEST(CGAL, AABBPolyhedronFacetIntersection) {
// typedef K::Segment_3 Segment;
typedef CGAL::Polyhedron_3<K> Polyhedron;
typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
#if CGAL_VERSION_MAJOR >= 6
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
#else
typedef CGAL::AABB_traits<K, Primitive> Traits;
#endif
typedef CGAL::AABB_tree<Traits> Tree;
// typedef Tree::Point_and_primitive_id Point_and_primitive_id;

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

typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
#if CGAL_VERSION_MAJOR >= 6
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
#else
typedef CGAL::AABB_traits<K, Primitive> Traits;
#endif
typedef CGAL::AABB_tree<Traits> Tree;
// typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
// Segment_intersection;
// typedef boost::optional<Tree::Intersection_and_primitive_id<Plane>::Type>
// Plane_intersection;
// typedef Tree::Primitive_id Primitive_id;

#if CGAL_VERSION_MAJOR >= 6
typedef std::optional<Tree::Intersection_and_primitive_id<Ray>::Type>
Ray_intersection;
#else
typedef boost::optional<Tree::Intersection_and_primitive_id<Ray>::Type>
Ray_intersection;

#endif
typedef CGAL::Timer Timer;

Point3 p0(-1.0, -1.0, 1.0);
Expand Down Expand Up @@ -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<Point3>(&(intersection->first))) {
// const Point3* p = std::get_if<Point3>(&(intersection->first));
#else
// if(boost::get<Point3>(&(intersection->first))) {
// const Point3* p = boost::get<Point3>(&(intersection->first));
// const Point3* p = boost::get<Point3>(&(intersection->first));
#endif
// std::cout << *p << "\n";
// }
// }
Expand All @@ -366,17 +408,25 @@ TEST(CGAL, SurfaceMeshGrid) {
// typedef Mesh::Face_index face_descriptor;

typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
#if CGAL_VERSION_MAJOR >= 6
typedef CGAL::AABB_traits_3<K, Primitive> Traits;
#else
typedef CGAL::AABB_traits<K, Primitive> Traits;
#endif
typedef CGAL::AABB_tree<Traits> Tree;
// typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
// Segment_intersection;
// typedef boost::optional<Tree::Intersection_and_primitive_id<Plane>::Type>
// Plane_intersection;
// typedef Tree::Primitive_id Primitive_id;

#if CGAL_VERSION_MAJOR >= 6
typedef std::optional<Tree::Intersection_and_primitive_id<Ray>::Type>
Ray_intersection;
#else
typedef boost::optional<Tree::Intersection_and_primitive_id<Ray>::Type>
Ray_intersection;

#endif
typedef CGAL::Timer Timer;

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

// if(intersection) {
#if CGAL_VERSION_MAJOR >= 6
// if(std::get_if<Point3>(&(intersection->first))) {
// const Point3* p = std::get_if<Point3>(&(intersection->first));
#else
// if(boost::get<Point3>(&(intersection->first))) {
// const Point3* p = boost::get<Point3>(&(intersection->first));
// const Point3* p = boost::get<Point3>(&(intersection->first));
#endif
// std::cout << *p << "\n";
// }
// }
Expand All @@ -454,7 +509,11 @@ TEST(CGAL, SurfaceMeshModifyGrid) {
// typedef Mesh::Face_index face_descriptor;

// typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
#if CGAL_VERSION_MAJOR >= 6
// typedef CGAL::AABB_traits_3<K, Primitive> Traits;
#else
// typedef CGAL::AABB_traits<K, Primitive> Traits;
#endif
// typedef CGAL::AABB_tree<Traits> Tree;
// typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
// Segment_intersection;
Expand Down Expand Up @@ -507,7 +566,7 @@ TEST(CGAL, SurfaceMeshWavefield) {
// typedef Mesh::Face_index face_descriptor;

// typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
// typedef CGAL::AABB_traits<K, Primitive> Traits;
// typedef CGAL::AABB_traits_3<K, Primitive> Traits;
// typedef CGAL::AABB_tree<Traits> Tree;
// typedef boost::optional<Tree::Intersection_and_primitive_id<Segment>::Type>
// Segment_intersection;
Expand Down
6 changes: 6 additions & 0 deletions gz-waves/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 24 additions & 3 deletions gz-waves/src/Geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

#include <CGAL/AABB_face_graph_triangle_primitive.h>
#include <CGAL/AABB_tree.h>
#if CGAL_VERSION_MAJOR >= 6
#include <CGAL/AABB_traits_3.h>
#else
#include <CGAL/AABB_traits.h>
#endif
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Timer.h>
Expand All @@ -29,15 +33,20 @@
#include <limits>
#include <memory>
#include <string>
#include <variant>

namespace gz
{
namespace waves
{
// Typedefs
#if CGAL_VERSION_MAJOR >= 6
typedef std::optional<cgal::AABBTree::Intersection_and_primitive_id<
cgal::Ray>::Type> RayIntersection;
#else
typedef boost::optional<cgal::AABBTree::Intersection_and_primitive_id<
cgal::Ray>::Type> RayIntersection;

#endif
double Geometry::TriangleArea(
const cgal::Point3& _p0,
const cgal::Point3& _p1,
Expand Down Expand Up @@ -305,9 +314,15 @@ bool Geometry::SearchMesh(
// Retrieve intersection point
if (intersection)
{
#if CGAL_VERSION_MAJOR >= 6
if (std::get_if<cgal::Point3>(&(intersection->first)))
{
const cgal::Point3* p = std::get_if<cgal::Point3>(&(intersection->first));
#else
if (boost::get<cgal::Point3>(&(intersection->first)))
{
const cgal::Point3* p = boost::get<cgal::Point3>(&(intersection->first));
const cgal::Point3* p = boost::get<cgal::Point3>(&(intersection->first));
#endif
_intersection = *p;
return true;
}
Expand All @@ -333,9 +348,15 @@ bool Geometry::SearchMesh(
// Retrieve intersection point
if (intersection)
{
#if CGAL_VERSION_MAJOR >= 6
if (std::get_if<cgal::Point3>(&(intersection->first)))
{
const cgal::Point3* p = std::get_if<cgal::Point3>(&(intersection->first));
#else
if (boost::get<cgal::Point3>(&(intersection->first)))
{
const cgal::Point3* p = boost::get<cgal::Point3>(&(intersection->first));
const cgal::Point3* p = boost::get<cgal::Point3>(&(intersection->first));
#endif
_intersection = *p;
return true;
}
Expand Down

0 comments on commit aefbecd

Please sign in to comment.