Skip to content

Commit

Permalink
Merge pull request #8040 from janetournois/Tet_remeshing-add_corners-…
Browse files Browse the repository at this point in the history
…jtournois

Tetrahedral_remeshing - add `vertex_is_constrained_map` to set input corners
  • Loading branch information
lrineau committed Feb 28, 2024
2 parents 7767510 + 26639f4 commit 89c8b9d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ using Vertex_pair = std::pair<Vertex_handle, Vertex_handle>;
using Constraints_set = std::unordered_set<Vertex_pair, boost::hash<Vertex_pair>>;
using Constraints_pmap = CGAL::Boolean_property_map<Constraints_set>;

using Corners_set = std::unordered_set<Vertex_handle, boost::hash<Vertex_handle>>;
using Corners_pmap = CGAL::Boolean_property_map<Corners_set>;

// To avoid verbose function and named parameters call
using namespace CGAL::parameters;
Expand Down Expand Up @@ -72,8 +74,12 @@ int main(int argc, char* argv[])
Constraints_set constraints;
Constraints_pmap constraints_pmap(constraints);

Corners_set corners;
Corners_pmap corners_pmap(corners);

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

//note we use the move semantic, with std::move(c3t3),
// to avoid a copy of the triangulation by the function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct All_cells_selected

template<typename Triangulation
, typename SizingFunction
, typename VertexIsConstrainedMap
, typename EdgeIsConstrainedMap
, typename FacetIsConstrainedMap
, typename CellSelector
Expand Down Expand Up @@ -116,6 +117,7 @@ class Adaptive_remesher
Adaptive_remesher(Triangulation& tr
, const SizingFunction& sizing
, const bool protect_boundaries
, VertexIsConstrainedMap vcmap
, EdgeIsConstrainedMap ecmap
, FacetIsConstrainedMap fcmap
, bool smooth_constrained_edges
Expand All @@ -132,7 +134,7 @@ class Adaptive_remesher
{
m_c3t3.triangulation().swap(tr);

init_c3t3(ecmap, fcmap);
init_c3t3(vcmap, ecmap, fcmap);
m_vertex_smoother.init(m_c3t3, m_cell_selector, smooth_constrained_edges);

#ifdef CGAL_DUMP_REMESHING_STEPS
Expand All @@ -145,6 +147,7 @@ class Adaptive_remesher
Adaptive_remesher(C3t3& c3t3
, const SizingFunction& sizing
, const bool protect_boundaries
, VertexIsConstrainedMap vcmap
, EdgeIsConstrainedMap ecmap
, FacetIsConstrainedMap fcmap
, bool smooth_constrained_edges
Expand All @@ -161,7 +164,7 @@ class Adaptive_remesher
{
m_c3t3.swap(c3t3);

init_c3t3(ecmap, fcmap);
init_c3t3(vcmap, ecmap, fcmap);
m_vertex_smoother.init(m_c3t3, m_cell_selector, smooth_constrained_edges);

#ifdef CGAL_DUMP_REMESHING_STEPS
Expand Down Expand Up @@ -324,7 +327,8 @@ class Adaptive_remesher
}

private:
void init_c3t3(const EdgeIsConstrainedMap& ecmap,
void init_c3t3(const VertexIsConstrainedMap& vcmap,
const EdgeIsConstrainedMap& ecmap,
const FacetIsConstrainedMap& fcmap)
{
#ifdef CGAL_TETRAHEDRAL_REMESHING_DEBUG
Expand Down Expand Up @@ -444,6 +448,7 @@ class Adaptive_remesher
incident_complex_edges(vit, m_c3t3, std::back_inserter(incident_edges));
if ( incident_edges.size() == 1 //tip or endpoint
|| incident_edges.size() > 2 //corner
|| get(vcmap, vit) // constrained vertex
|| (incident_edges.size() == 2
&& edges_form_a_sharp_angle(incident_edges, 60, m_c3t3)))
{
Expand Down
87 changes: 68 additions & 19 deletions Tetrahedral_remeshing/include/CGAL/tetrahedral_remeshing.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ namespace CGAL
* by `Remeshing_edge_is_constrained_map` and `Remeshing_facet_is_constrained_map`.}
* \cgalParamNEnd
*
* \cgalParamNBegin{facet_is_constrained_map}
* \cgalParamDescription{a property map containing the constrained-or-not status of each facet of `tr`.}
* \cgalParamType{a class model of `ReadablePropertyMap` with `Triangulation_3::Facet`
* as key type and `bool` as value type. It must be default constructible.}
* \cgalParamDefault{a default property map where no facet is constrained}
* \cgalParamExtra{A constrained facet can be split or collapsed, but not flipped.}
* \cgalParamExtra{This map, contrary to the others, is not updated throughout the remeshing process.}
* \cgalParamNEnd
*
* \cgalParamNBegin{edge_is_constrained_map}
* \cgalParamDescription{a property map containing the constrained-or-not status of each edge of `tr`.}
* \cgalParamType{a class model of `ReadWritePropertyMap` with `std::pair<Triangulation_3::Vertex_handle, Triangulation_3::Vertex_handle>`
Expand All @@ -118,13 +127,12 @@ namespace CGAL
* with edge splits and collapses, so the property map must be writable.}
* \cgalParamNEnd
*
* \cgalParamNBegin{facet_is_constrained_map}
* \cgalParamDescription{a property map containing the constrained-or-not status of each facet of `tr`.}
* \cgalParamType{a class model of `ReadablePropertyMap` with `Triangulation_3::Facet`
* \cgalParamNBegin{vertex_is_constrained_map}
* \cgalParamDescription{a property map containing the constrained-or-not status of each vertex of `tr`.}
* \cgalParamType{a class model of `ReadWritePropertyMap` with `Triangulation_3::Vertex_handle`
* as key type and `bool` as value type. It must be default constructible.}
* \cgalParamDefault{a default property map where no facet is constrained}
* \cgalParamExtra{A constrained facet can be split or collapsed, but not flipped.}
* \cgalParamExtra{This map, contrary to the others, is not updated throughout the remeshing process.}
* \cgalParamDefault{a default property map where no vertex is constrained}
* \cgalParamExtra{A constrained vertex cannot be removed by collapse, nor moved by smoothing.}
* \cgalParamNEnd
*
* \cgalParamNBegin{cell_is_selected_map}
Expand All @@ -147,7 +155,8 @@ namespace CGAL
* \cgalParamExtra{The endvertices of constraints listed
* by `edge_is_constrained_map`, and edges incident to at least three subdomains
* are made eligible to one dimensional smoothing, along the constrained polylines they belong to.
* Corners (i.e. vertices incident to more than 2 constrained edges) are not allowed
* Corners (i.e. vertices listed by `vertex_is_constrained_map` or
* incident to more than 2 constrained edges) are not allowed
* to move at all.\n
* Note that activating the smoothing step on polyline constraints tends to reduce
* the quality of the minimal dihedral angle in the mesh.\n
Expand Down Expand Up @@ -225,6 +234,15 @@ void tetrahedral_isotropic_remeshing(
= choose_parameter(get_parameter(np, internal_np::cell_selector),
Tetrahedral_remeshing::internal::All_cells_selected<Tr>());

typedef typename Tr::Vertex_handle Vertex_handle;
typedef typename internal_np::Lookup_named_param_def <
internal_np::vertex_is_constrained_t,
NamedParameters,
Constant_property_map<Vertex_handle, bool>//default
> ::type VCMap;
VCMap vcmap = choose_parameter(get_parameter(np, internal_np::vertex_is_constrained),
Constant_property_map<Vertex_handle, bool>(false));

typedef std::pair<typename Tr::Vertex_handle, typename Tr::Vertex_handle> Edge_vv;
typedef typename internal_np::Lookup_named_param_def <
internal_np::edge_is_constrained_t,
Expand Down Expand Up @@ -263,9 +281,9 @@ void tetrahedral_isotropic_remeshing(
#endif

typedef Tetrahedral_remeshing::internal::Adaptive_remesher<
Tr, SizingFunction, ECMap, FCMap, SelectionFunctor, Visitor> Remesher;
Tr, SizingFunction, VCMap, ECMap, FCMap, SelectionFunctor, Visitor> Remesher;
Remesher remesher(tr, sizing, protect
, ecmap, fcmap
, vcmap, ecmap, fcmap
, smooth_constrained_edges
, cell_select
, visitor);
Expand Down Expand Up @@ -331,7 +349,16 @@ void tetrahedral_isotropic_remeshing(
* as key type and `bool` as value type. It must be default constructible.}
* \cgalParamDefault{a default property map where no edge is constrained}
* \cgalParamNEnd
*
* \cgalParamNBegin{vertex_is_constrained_map}
* \cgalParamDescription{a property map containing the constrained-or-not status of each vertex of
* `c3t3.triangulation()`.
* For each vertex `v` for which `c3t3.is_in_complex(v)` returns `true`,
* the constrained status of `v` is set to `true`.}
* \cgalParamType{a class model of `ReadWritePropertyMap`
* with `Triangulation_3::Vertex_handle`
* as key type and `bool` as value type. It must be default constructible.}
* \cgalParamDefault{a default property map where no vertex is constrained}
* \cgalParamNEnd
* \cgalNamedParamsEnd
*/

Expand All @@ -353,16 +380,25 @@ convert_to_triangulation_3(

using Vertex_handle = typename Tr::Vertex_handle;
using Edge_vv = std::pair<Vertex_handle, Vertex_handle>;
using Default_pmap = Constant_property_map<Edge_vv, bool>;
using Default_edge_pmap = Constant_property_map<Edge_vv, bool>;
using ECMap = typename internal_np::Lookup_named_param_def <
internal_np::edge_is_constrained_t,
NamedParameters,
Default_pmap
Default_edge_pmap
>::type;
using Default_vertex_pmap = Constant_property_map<Vertex_handle, bool>;
using VCMap = typename internal_np::Lookup_named_param_def <
internal_np::vertex_is_constrained_t,
NamedParameters,
Default_vertex_pmap
>::type;

ECMap ecmap = choose_parameter(get_parameter(np, internal_np::edge_is_constrained),
Default_pmap(false));
Default_edge_pmap(false));
VCMap vcmap = choose_parameter(get_parameter(np, internal_np::vertex_is_constrained),
Default_vertex_pmap(false));

if (!std::is_same_v<ECMap, Default_pmap>)
if (!std::is_same_v<ECMap, Default_edge_pmap>)
{
for (auto e : c3t3.edges_in_complex())
{
Expand All @@ -371,6 +407,13 @@ convert_to_triangulation_3(
put(ecmap, evv, true);
}
}
if (!std::is_same_v<VCMap, Default_vertex_pmap>)
{
for (auto v : c3t3.vertices_in_complex())
{
put(vcmap, v, true);
}
}

CGAL::Triangulation_3<GT, TDS> tr;
tr.swap(c3t3.triangulation());
Expand Down Expand Up @@ -448,6 +491,15 @@ void tetrahedral_isotropic_remeshing(
= choose_parameter(get_parameter(np, internal_np::cell_selector),
Tetrahedral_remeshing::internal::All_cells_selected<Tr>());

typedef typename Tr::Vertex_handle Vertex_handle;
typedef typename internal_np::Lookup_named_param_def <
internal_np::vertex_is_constrained_t,
NamedParameters,
Constant_property_map<Vertex_handle, bool>//default
> ::type VCMap;
VCMap vcmap = choose_parameter(get_parameter(np, internal_np::vertex_is_constrained),
Constant_property_map<Vertex_handle, bool>(false));

typedef std::pair<typename Tr::Vertex_handle, typename Tr::Vertex_handle> Edge_vv;
typedef typename internal_np::Lookup_named_param_def <
internal_np::edge_is_constrained_t,
Expand Down Expand Up @@ -486,12 +538,9 @@ void tetrahedral_isotropic_remeshing(
#endif

typedef Tetrahedral_remeshing::internal::Adaptive_remesher<
Tr, SizingFunction, ECMap, FCMap, SelectionFunctor,
Visitor,
CornerIndex, CurveIndex
> Remesher;
Tr, SizingFunction, VCMap, ECMap, FCMap, SelectionFunctor, Visitor> Remesher;
Remesher remesher(c3t3, sizing, protect
, ecmap, fcmap
, vcmap, ecmap, fcmap
, smooth_constrained_edges
, cell_select
, visitor);
Expand Down

0 comments on commit 89c8b9d

Please sign in to comment.