Skip to content

Commit

Permalink
CGAL: support version 6.0
Browse files Browse the repository at this point in the history
- Add version checks.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
  • Loading branch information
srmainwaring committed Dec 30, 2024
1 parent a0b92d7 commit 12e4957
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
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
59 changes: 55 additions & 4 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;
typedef CGAL::<K, Primitive> Traits;
#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 (std::get_if<Point3>(&(intersection->first))) {
#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,7 +305,11 @@ 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;
Expand Down Expand Up @@ -344,8 +377,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));
// const Point3* p = std::get_if<Point3>(&(intersection->first));
#else
// if(boost::get<Point3>(&(intersection->first))) {
// const Point3* p = boost::get<Point3>(&(intersection->first));
#endif
// std::cout << *p << "\n";
// }
// }
Expand All @@ -366,7 +404,11 @@ 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;
Expand Down Expand Up @@ -432,8 +474,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));
// const Point3* p = std::get_if<Point3>(&(intersection->first));
#else
// if(boost::get<Point3>(&(intersection->first))) {
// const Point3* p = boost::get<Point3>(&(intersection->first));
#endif
// std::cout << *p << "\n";
// }
// }
Expand All @@ -454,7 +501,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
22 changes: 21 additions & 1 deletion 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 @@ -36,9 +40,13 @@ 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 @@ -306,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));
#endif
_intersection = *p;
return true;
}
Expand All @@ -334,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));
#endif
_intersection = *p;
return true;
}
Expand Down

0 comments on commit 12e4957

Please sign in to comment.