Skip to content

Commit

Permalink
fix compilation with C++17
Browse files Browse the repository at this point in the history
  • Loading branch information
lrineau committed Jul 8, 2024
1 parent 8ad3541 commit b65c2ff
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ create_single_source_cgal_program(constrained_Delaunay_triangulation_3.cpp)
create_single_source_cgal_program(constrained_Delaunay_triangulation_3_from_soup.cpp)
create_single_source_cgal_program(remesh_constrained_Delaunay_triangulation_3.cpp)

target_compile_features(constrained_Delaunay_triangulation_3 PUBLIC cxx_std_20) # TODO: remove this line
target_compile_features(constrained_Delaunay_triangulation_3_from_soup PUBLIC cxx_std_20) # TODO: remove this line
target_compile_features(remesh_constrained_Delaunay_triangulation_3 PUBLIC cxx_std_20)

if(CGAL_Qt6_FOUND)
target_link_libraries(constrained_Delaunay_triangulation_3 PUBLIC CGAL::CGAL_Basic_viewer)
else()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ class Constrained_Delaunay_triangulation_3 {
{
auto mesh_vp_map = parameters::choose_parameter(parameters::get_parameter(np, internal_np::vertex_point),
get(CGAL::vertex_point, mesh));
// TODO: set the traits object in the triangulation

[[maybe_unused]] /* TODO */
auto mesh_face_patch_map = parameters::choose_parameter(parameters::get_parameter(np, internal_np::face_patch),
Expand All @@ -580,10 +579,20 @@ class Constrained_Delaunay_triangulation_3 {
hint_ch = vh->cell();
put(tr_vertex_map, v, vh);
}
struct {
decltype(tr_vertex_map)* vertex_map;
Vertex_handle operator()(typename boost::graph_traits<PolygonMesh>::vertex_descriptor v) const {
return get(*vertex_map, v);
}
} transform_function{&tr_vertex_map};

for(auto f : faces(mesh)) {
auto face_vertices = vertices_around_face(halfedge(f, mesh), mesh);
cdt_impl.insert_constrained_face(
face_vertices | std::views::transform([&](auto v) { return get(tr_vertex_map, v); }), false);

auto begin = boost::make_transform_iterator(face_vertices.begin(), transform_function);
auto end = boost::make_transform_iterator(face_vertices.end(), transform_function);

cdt_impl.insert_constrained_face(CGAL::make_range(begin, end), false);
}
cdt_impl.restore_Delaunay();
cdt_impl.restore_constrained_Delaunay();
Expand Down Expand Up @@ -646,6 +655,7 @@ class Constrained_Delaunay_triangulation_3 {
Constrained_Delaunay_triangulation_3(const PointRange& points,
const PolygonRange& polygons,
const NamedParams& np = parameters::default_values())
: cdt_impl(parameters::choose_parameter(parameters::get_parameter(np, internal_np::geom_traits), Traits{}))
{
using PointRange_const_iterator = typename PointRange::const_iterator;
using PointRange_value_type = typename std::iterator_traits<PointRange_const_iterator>::value_type;
Expand All @@ -657,7 +667,8 @@ class Constrained_Delaunay_triangulation_3 {
boost::identity_property_map{});
using Vertex_handle = typename Triangulation::Vertex_handle;
using Cell_handle = typename Triangulation::Cell_handle;
std::vector<Vertex_handle> vertices(points.size());
using Vec_vertex_handle = std::vector<Vertex_handle>;
Vec_vertex_handle vertices(points.size());
Cell_handle hint_ch{};
auto i = 0u;
for(auto p_descr : points) {
Expand All @@ -666,9 +677,15 @@ class Constrained_Delaunay_triangulation_3 {
hint_ch = vh->cell();
vertices[i++] = vh;
}

struct {
Vec_vertex_handle* vertices;
const Vertex_handle& operator()(std::size_t i) const { return (*vertices)[i]; }
} transform_function{&vertices};
for(auto polygon : polygons) {
cdt_impl.insert_constrained_face(
polygon | std::views::transform([&](auto i) { return vertices[i]; }), false);
auto begin = boost::make_transform_iterator(polygon.begin(), transform_function);
auto end = boost::make_transform_iterator(polygon.end(), transform_function);
cdt_impl.insert_constrained_face(CGAL::make_range(begin, end), false);
}
cdt_impl.restore_Delaunay();
cdt_impl.restore_constrained_Delaunay();
Expand Down Expand Up @@ -1803,12 +1820,12 @@ class Constrained_Delaunay_triangulation_3_impl : public Conforming_Delaunay_tri
return visited_edges.emplace(CGAL::make_sorted_pair(v0, v1), does_intersect);
};

#if CGAL_CDT_3_CAN_USE_CXX20_FORMAT
using Mesh = Surface_mesh<Point_3>;
using Face_index = typename Mesh::Face_index;
using EK = CGAL::Exact_predicates_exact_constructions_kernel;
const auto to_exact = CGAL::Cartesian_converter<Geom_traits, EK>();
const auto from_exact = CGAL::Cartesian_converter<EK, Geom_traits>();
#if CGAL_CDT_3_CAN_USE_CXX20_FORMAT
if(this->debug_regions()) {

Mesh tets_intersect_region_mesh;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct Default_constrained_Delaunay_triangulation_3_type_generator
*
*/
template <typename Traits>
using Default_constrained_Delaunay_triangulation_3 = Constrained_Delaunay_triangulation_3<Triangulation_3<Traits, Triangulation_data_structure_3<Constrained_Delaunay_triangulation_vertex_base_3<Traits>, Constrained_Delaunay_triangulation_cell_base_3<Traits>>>>;
using Default_constrained_Delaunay_triangulation_3 = Constrained_Delaunay_triangulation_3<Traits, Triangulation_3<Traits, Triangulation_data_structure_3<Constrained_Delaunay_triangulation_vertex_base_3<Traits>, Constrained_Delaunay_triangulation_cell_base_3<Traits>>>>;

/*!
* \ingroup PkgCT_3Functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ project(Constrained_triangulation_3_Tests)
find_package(CGAL REQUIRED)

create_single_source_cgal_program(test_constrained_Delaunay_triangulation_3.cpp)
target_compile_features(test_constrained_Delaunay_triangulation_3 PRIVATE cxx_std_20)
4 changes: 2 additions & 2 deletions Installation/include/CGAL/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@
#define CGAL_USE_SSE2_FABS
#endif

// Same for C++17
// Require C++17
#if !(__cplusplus >= 201703L || _MSVC_LANG >= 201703L)
#error "CGAL requires C++ 17"
#endif
// Same for C++20
// Detect C++20
#if __cplusplus >= 202002L || _MSVC_LANG >= 202002L
# define CGAL_CXX20 1
#endif
Expand Down
9 changes: 9 additions & 0 deletions STL_Extension/include/CGAL/Iterator_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,13 @@ namespace boost { namespace foreach
{
};
}}

#if CGAL_CXX20
# include <ranges>

template<typename I>
inline constexpr bool std::ranges::enable_borrowed_range<CGAL::Iterator_range<I>> = true;

#endif // C++20

#endif // CGAL_ITERATOR_RANGE_H

0 comments on commit b65c2ff

Please sign in to comment.