Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions SMDS_3/include/CGAL/to_triangulation_3_complex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) 2026 GeometryFactory (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL$
// $Id$
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s) : Jane Tournois

#ifndef CGAL_TO_TRIANGULATION_3_COMPLEX_H
#define CGAL_TO_TRIANGULATION_3_COMPLEX_H

#include <CGAL/license/SMDS_3.h>

#include <CGAL/Mesh_complex_3_in_triangulation_3.h>
#include <CGAL/Triangulation_3.h>

namespace CGAL
{

/*!
* \ingroup PkgSMDS3Functions
* converts a `Mesh_complex_3_in_triangulation_3`
* to a `Mesh_complex_3_in_triangulation_3` with a `Triangulation_3` as
* underlying triangulation.
*
* @tparam C3t3 model of `MeshComplex_3InTriangulation_3`
* @tparam CornerIndex is the type of the corner indices
* @tparam CurveIndex is the type of the curve indices
* @tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
*
* @todo
*/
template <typename C3t3,
typename NamedParameters = parameters::Default_named_parameters>
CGAL::Mesh_complex_3_in_triangulation_3<
CGAL::Triangulation_3<typename C3t3::Triangulation::Geom_traits,
typename C3t3::Triangulation::Triangulation_data_structure>>
to_triangulation_3_complex(
C3t3 c3t3,
const NamedParameters& np = parameters::default_values())
{
using GT = typename C3t3::Triangulation::Geom_traits;
using TDS = typename C3t3::Triangulation::Triangulation_data_structure;
using Corner_index = typename C3t3::Corner_index;
using Curve_index = typename C3t3::Curve_index;

using T3 = CGAL::Triangulation_3<GT, TDS>;
using C3t3_new = CGAL::Mesh_complex_3_in_triangulation_3<T3, Corner_index, Curve_index>;

T3 tr;
tr.swap(c3t3.triangulation());
C3t3_new c3t3_new;
c3t3_new.triangulation().swap(tr);

// todo : port metadata from input c3t3 to the new one

return c3t3_new;
}

} // end namespace CGAL

#endif // CGAL_TO_TRIANGULATION_3_COMPLEX_H
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <CGAL/make_mesh_3.h>
#include <CGAL/property_map.h>

#include <CGAL/to_triangulation_3_complex.h>
#include <CGAL/tetrahedral_remeshing.h>

#include <CGAL/IO/File_medit.h>
Expand Down Expand Up @@ -72,7 +73,7 @@ int main(int argc, char* argv[])
cell_radius_edge_ratio = 3, cell_size = 0.05);

// Mesh generation
C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria);
C3t3 c3t3_mesh_3 = CGAL::make_mesh_3<C3t3>(domain, criteria);

// Property map of constraints
Constraints_set constraints;
Expand All @@ -81,7 +82,7 @@ int main(int argc, char* argv[])
Corners_set corners;
Corners_pmap corners_pmap(corners);

Triangulation_3 tr = CGAL::convert_to_triangulation_3(std::move(c3t3),
auto c3t3 = CGAL::to_triangulation_3_complex(std::move(c3t3_mesh_3),
edge_is_constrained_map(constraints_pmap).
vertex_is_constrained_map(corners_pmap));

Expand All @@ -93,13 +94,13 @@ int main(int argc, char* argv[])
// Then the triangulation is copied and duplicated, and c3t3 remains as is.

const double target_edge_length = 0.1;//coarsen the mesh
CGAL::tetrahedral_isotropic_remeshing(tr, target_edge_length,
CGAL::tetrahedral_isotropic_remeshing(c3t3, target_edge_length,
number_of_iterations(5)
.smooth_constrained_edges(true)
.edge_is_constrained_map(constraints_pmap));

std::ofstream out("out_remeshed.mesh");
CGAL::IO::write_MEDIT(out, tr);
CGAL::IO::write_MEDIT(out, c3t3);
out.close();

return EXIT_SUCCESS;
Expand Down
Loading