Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tetrahedral_remeshing - add vertex_is_constrained_map to set input corners #8040

Merged
merged 2 commits into from
Feb 28, 2024
Merged
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
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 @@ -73,8 +75,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 @@ -76,6 +76,7 @@ struct All_cells_selected

template<typename Triangulation
, typename SizingFunction
, typename VertexIsConstrainedMap
, typename EdgeIsConstrainedMap
, typename FacetIsConstrainedMap
, typename CellSelector
Expand Down Expand Up @@ -115,6 +116,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 @@ -131,7 +133,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 @@ -144,6 +146,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 @@ -160,7 +163,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 @@ -315,7 +318,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 @@ -431,6 +435,7 @@ class Adaptive_remesher
for (Vertex_handle vit : tr().finite_vertex_handles())
{
if ( vit->in_dimension() == 0
|| get(vcmap, vit)
|| nb_incident_complex_edges(vit, m_c3t3) > 2)
{
if (!m_c3t3.is_in_complex(vit))
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 @@ -327,7 +345,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 @@ -349,16 +376,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 @@ -367,6 +403,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 @@ -444,6 +487,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 @@ -482,12 +534,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