From 9cb1747bd4a8207b3d686a0ffb1cafc35b66eb84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rik=20B=C3=A4hnemann?= Date: Fri, 19 May 2023 11:14:21 +0200 Subject: [PATCH] Circular kernel conversion and kernel redefinition. --- polygon_coverage_geometry/CMakeLists.txt | 1 + .../cgal_definitions.h | 25 ++++++++++++++- .../circular_segments.h | 32 +++++++++++++++++++ .../src/circular_segments.cc | 15 +++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 polygon_coverage_geometry/include/polygon_coverage_geometry/circular_segments.h create mode 100644 polygon_coverage_geometry/src/circular_segments.cc diff --git a/polygon_coverage_geometry/CMakeLists.txt b/polygon_coverage_geometry/CMakeLists.txt index 7c4eda8..4f6021a 100644 --- a/polygon_coverage_geometry/CMakeLists.txt +++ b/polygon_coverage_geometry/CMakeLists.txt @@ -22,6 +22,7 @@ include_directories(include ${catkin_INCLUDE_DIRS}) add_library(${PROJECT_NAME} src/bcd.cc src/boolean.cc + src/circular_segments.cc src/cgal_comm.cc src/decomposition.cc src/offset.cc diff --git a/polygon_coverage_geometry/include/polygon_coverage_geometry/cgal_definitions.h b/polygon_coverage_geometry/include/polygon_coverage_geometry/cgal_definitions.h index f2b1002..1a5992d 100644 --- a/polygon_coverage_geometry/include/polygon_coverage_geometry/cgal_definitions.h +++ b/polygon_coverage_geometry/include/polygon_coverage_geometry/cgal_definitions.h @@ -24,7 +24,25 @@ #include #include -typedef CGAL::Exact_predicates_exact_constructions_kernel K; +#include + +// Explicitely define the EPECK to use for CGAL that uses Gmpq to allow conversion to circular kernel. +// See https://stackoverflow.com/questions/67141983/cgal-coordinate-value-transformation-not-working-anymore-in-5-2-1 +namespace CGAL +{ + class Kernel + : public Type_equality_wrapper< + Lazy_kernel_base, + Simple_cartesian, + Cartesian_converter, + Simple_cartesian>, + Kernel>, + Kernel> + { + }; +} // namespace CGAL + +typedef CGAL::Kernel K; typedef K::FT FT; typedef K::Point_2 Point_2; typedef K::Point_3 Point_3; @@ -46,4 +64,9 @@ typedef Polygon_2::Edge_const_circulator EdgeConstCirculator; typedef CGAL::Polygon_with_holes_2 PolygonWithHoles; typedef CGAL::Exact_predicates_inexact_constructions_kernel InexactKernel; +typedef CGAL::Exact_circular_kernel_2 Kc; +typedef Kc::Point_2 Point_2c; +typedef CGAL::Cartesian_converter K_to_Kc; +typedef CGAL::Cartesian_converter Kc_to_K; + #endif // POLYGON_COVERAGE_GEOMETRY_CGAL_DEFINITIONS_H_ diff --git a/polygon_coverage_geometry/include/polygon_coverage_geometry/circular_segments.h b/polygon_coverage_geometry/include/polygon_coverage_geometry/circular_segments.h new file mode 100644 index 0000000..8299153 --- /dev/null +++ b/polygon_coverage_geometry/include/polygon_coverage_geometry/circular_segments.h @@ -0,0 +1,32 @@ +/* + * polygon_coverage_planning implements algorithms for coverage planning in + * general polygons with holes. Copyright (C) 2019, Rik Bähnemann, Autonomous + * Systems Lab, ETH Zürich + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef POLYGON_COVERAGE_GEOMETRY_CIRCULAR_SEGMENTS_H_ +#define POLYGON_COVERAGE_GEOMETRY_CIRCULAR_SEGMENTS_H_ +#include "polygon_coverage_geometry/cgal_definitions.h" + +namespace polygon_coverage_planning { + +Point_2c toCircular(const Point_2& p); + +Point_2 fromCircular(const Point_2c& p); + +} // namespace polygon_coverage_planning + +#endif // POLYGON_COVERAGE_GEOMETRY_CIRCULAR_SEGMENTS_H_ \ No newline at end of file diff --git a/polygon_coverage_geometry/src/circular_segments.cc b/polygon_coverage_geometry/src/circular_segments.cc new file mode 100644 index 0000000..dc3dd4c --- /dev/null +++ b/polygon_coverage_geometry/src/circular_segments.cc @@ -0,0 +1,15 @@ +#include "polygon_coverage_geometry/circular_segments.h" + +namespace polygon_coverage_planning { + +Point_2c toCircular(const Point_2& p) { + K_to_Kc to_circular; + return to_circular(p); +} + +Point_2 fromCircular(const Point_2c& p) { + Kc_to_K from_circular; + return from_circular(p); +} + +} // namespace polygon_coverage_planning \ No newline at end of file