10#ifndef GRIDFORMAT_TRAITS_CGAL_HPP_
11#define GRIDFORMAT_TRAITS_CGAL_HPP_
21#ifdef GRIDFORMAT_IGNORE_CGAL_WARNINGS
22#pragma GCC diagnostic push
23#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
24#pragma GCC diagnostic ignored "-Wnull-dereference"
26#include <CGAL/number_utils.h>
27#include <CGAL/Point_2.h>
28#include <CGAL/Point_3.h>
29#include <CGAL/Triangulation_2.h>
30#include <CGAL/Triangulation_3.h>
31#ifdef GRIDFORMAT_IGNORE_CGAL_WARNINGS
32#pragma GCC diagnostic pop
35#include <gridformat/common/type_traits.hpp>
36#include <gridformat/grid/traits.hpp>
37#include <gridformat/grid/type_traits.hpp>
38#include <gridformat/grid/cell_type.hpp>
51 template<
typename K,
typename TDS>
52 TDS deduce_tds(
const CGAL::Triangulation_2<K, TDS>&) {
return {}; }
53 template<
typename K,
typename TDS,
typename LDS>
54 TDS deduce_tds(
const CGAL::Triangulation_3<K, TDS, LDS>&) {
return {}; }
55 template<
typename K,
typename TDS,
typename LDS>
56 LDS deduce_lds(
const CGAL::Triangulation_3<K, TDS, LDS>&) {
return {}; }
58 template<
typename T>
struct IsPoint :
public std::false_type {};
59 template<
typename K>
struct IsPoint<CGAL::Point_2<K>> :
public std::true_type {};
60 template<
typename K>
struct IsPoint<CGAL::Point_3<K>> :
public std::true_type {};
61 template<
typename T>
concept Point = IsPoint<std::remove_cvref_t<T>>::value;
68 typename T::Geom_traits;
69 typename T::Triangulation_data_structure;
70 requires std::derived_from<T, CGAL::Triangulation_2<
71 typename T::Geom_traits,
72 decltype(CGALDetail::deduce_tds(grid))
78 typename T::Geom_traits;
79 typename T::Triangulation_data_structure;
80 typename T::Lock_data_structure;
81 requires std::derived_from<T, CGAL::Triangulation_3<
82 typename T::Geom_traits,
83 decltype(CGALDetail::deduce_tds(grid)),
84 decltype(CGALDetail::deduce_lds(grid))
94 { wrapper.point() } -> CGALDetail::Point;
102template<
typename T>
struct CellType;
103template<Concepts::CGALGr
id2D T>
struct CellType<T> :
public std::type_identity<typename T::Face_handle> {};
104template<Concepts::CGALGr
id3D T>
struct CellType<T> :
public std::type_identity<typename T::Cell_handle> {};
105template<Concepts::CGALGr
id T>
using Cell =
typename CellType<T>::type;
107template<Concepts::CGALGr
id T>
108inline constexpr int dimension = Concepts::CGALGrid2D<T> ? 2 : 3;
111std::array<double, 2> to_double_array(const ::CGAL::Point_2<K>& p) {
112 return {::CGAL::to_double(p.x()), ::CGAL::to_double(p.y())};
116std::array<double, 3> to_double_array(const ::CGAL::Point_3<K>& p) {
117 return {::CGAL::to_double(p.x()), ::CGAL::to_double(p.y()), ::CGAL::to_double(p.z())};
119template<Concepts::CGALPo
intWrapper W>
120auto to_double_array(
const W& wrapper) {
return to_double_array(wrapper.point()); }
127template<Concepts::CGALGr
id Gr
id>
129 static std::ranges::range
auto get(
const Grid& grid) {
131 return grid.finite_face_handles()
132 | std::views::transform([] (
auto it) ->
typename Grid::Face_handle {
return it; });
134 return grid.finite_cell_handles()
135 | std::views::transform([] (
auto it) ->
typename Grid::Cell_handle {
return it; });
139template<Concepts::CGALGr
id Gr
id>
141 static std::ranges::range
auto get(
const Grid& grid) {
142 return grid.finite_vertex_handles()
143 | std::views::transform([] (
auto it) ->
typename Grid::Vertex_handle {
return it; });
147template<Concepts::CGALGr
id Gr
id>
148struct CellPoints<Grid, GridFormat::CGAL::Cell<Grid>> {
149 static std::ranges::range
auto get(
const Grid&,
const GridFormat::CGAL::Cell<Grid>& cell) {
151 return std::views::iota(0, num_corners) | std::views::transform([=] (
int i) {
152 return cell->vertex(i);
157template<Concepts::CGALGr
id Gr
id>
158struct PointCoordinates<Grid, typename Grid::Vertex_handle> {
159 static std::ranges::range
auto get(
const Grid&,
const typename Grid::Vertex_handle& vertex) {
160 return CGAL::to_double_array(vertex->point());
164template<Concepts::CGALGr
id Gr
id>
165struct PointId<Grid, typename Grid::Vertex_handle> {
166 static std::size_t get(
const Grid&,
const typename Grid::Vertex_handle& v) {
167 return ::CGAL::Handle_hash_function{}(v);
171template<Concepts::CGALGr
id Gr
id>
172struct CellType<Grid, GridFormat::CGAL::Cell<Grid>> {
173 static GridFormat::CellType get(
const Grid&,
const GridFormat::CGAL::Cell<Grid>&) {
175 return GridFormat::CellType::triangle;
177 return GridFormat::CellType::tetrahedron;
181template<Concepts::CGALGr
id Gr
id>
182struct NumberOfPoints<Grid> {
183 static std::integral
auto get(
const Grid& grid) {
184 return grid.number_of_vertices();
188template<Concepts::CGALGr
id Gr
id>
189struct NumberOfCells<Grid> {
190 static std::integral
auto get(
const Grid& grid) {
192 return grid.number_of_faces();
194 return grid.number_of_finite_cells();
198template<Concepts::CGALGr
id Gr
id>
199struct NumberOfCellPoints<Grid, GridFormat::CGAL::Cell<Grid>> {
200 static constexpr unsigned int get(
const Grid&,
const GridFormat::CGAL::Cell<Grid>&) {