10#include <CGAL/squared_distance_3.h>
11#include <CGAL/Tetrahedral_remeshing/Remeshing_triangulation_3.h>
12#include <CGAL/version.h>
13#if CGAL_VERSION_NR >= 1060200000
14 #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
15 #include <CGAL/Conforming_constrained_Delaunay_triangulation_cell_base_3.h>
16 #include <CGAL/Conforming_constrained_Delaunay_triangulation_vertex_base_3.h>
17 #include <CGAL/make_conforming_constrained_Delaunay_triangulation_3.h>
18 #include <CGAL/Polygon_mesh_processing/self_intersections.h>
20#include <CGAL/AABB_segment_primitive_3.h>
21#include <CGAL/tetrahedral_remeshing.h>
22#include <CGAL/AABB_tree.h>
23#include <CGAL/AABB_traits_3.h>
24#include <CGAL/AABB_triangle_primitive_3.h>
25#include <CGAL/box_intersection_d.h>
26#include <CGAL/Box_intersection_d/Box_with_info_d.h>
27#include <boost/property_map/property_map.hpp>
37void logWarning(
const std::string &message) {
39 logging::core::get()->add_sink(
44 MOFEM_LOG(
"CGALTools", Sev::warning) << message;
48using RemeshPoint = RemeshKernel::Point_3;
49using RemeshFace = std::array<int, 3>;
50using RemeshEdge = std::array<int, 2>;
51using Triangles = std::vector<RemeshKernel::Triangle_3>;
52using TrianglePrimitive =
53 CGAL::AABB_triangle_primitive_3<RemeshKernel, Triangles::const_iterator>;
55 CGAL::AABB_tree<CGAL::AABB_traits_3<RemeshKernel, TrianglePrimitive>>;
59struct ClosestAlignedTriangle {
63 size_t best = std::numeric_limits<size_t>::max();
64 double distance = std::numeric_limits<double>::infinity();
65 bool go_further()
const {
return true; }
67 bool do_intersect(
const RemeshPoint &point,
const Node &node)
const {
68 const auto &box = node.bbox();
69 const double lo[] = {box.xmin(), box.ymin(), box.zmin()},
70 hi[] = {box.xmax(), box.ymax(), box.zmax()};
71 long double lower = 0;
72 for (
int d = 0;
d != 3; ++
d) {
73 const long double x = point[
d];
74 const auto delta = std::max({0.L, lo[
d] - x, x - hi[
d]});
77 return lower <= distance + 64 * std::numeric_limits<double>::epsilon() *
78 std::max(1., distance);
80 void intersection(
const RemeshPoint &point,
81 const TrianglePrimitive &primitive) {
86 CGAL::to_double(CGAL::squared_distance(point, triangles[
index]));
87 if (value < distance ||
88 (value == distance && (best == std::numeric_limits<size_t>::max() ||
95template <
class Base>
struct RemeshCellBase : Base {
98 template <
class TDS>
struct Rebind_TDS {
100 RemeshCellBase<typename Base::template Rebind_TDS<TDS>::Other>;
103template <
class Tr>
struct RemeshSelection {
104 using key_type =
typename Tr::Cell_handle;
105 using value_type =
bool;
106 using reference =
bool;
107 using category = boost::read_write_property_map_tag;
108 friend bool get(
const RemeshSelection &, key_type cell) {
109 return cell->selected;
111 friend void put(
const RemeshSelection &, key_type cell,
bool value) {
112 cell->selected = value;
115template <
class T> T simplexKey(T value) {
116 std::sort(value.begin(), value.end());
119RemeshPoint remeshPoint(
const TetMeshData &
mesh,
int i) {
120 const auto &p =
mesh.points.at(
i);
121 return {p[0], p[1], p[2]};
123using RemeshFaces = std::map<RemeshFace, std::vector<int>>;
127RemeshFaces remeshFaces(
const TetMeshData &
mesh,
bool check_embedding =
true) {
129 std::set<std::array<int, 4>> unique;
130 for (
size_t i = 0;
i !=
mesh.cells.size(); ++
i) {
131 const auto &
c =
mesh.cells[
i];
135 const auto key = simplexKey(
c);
136 if (std::adjacent_find(
key.begin(),
key.end()) !=
key.end() ||
137 !unique.insert(
key).second ||
138 CGAL::orientation(remeshPoint(
mesh,
c[0]), remeshPoint(
mesh,
c[1]),
139 remeshPoint(
mesh,
c[2]),
140 remeshPoint(
mesh,
c[3])) != CGAL::POSITIVE)
141 THROW_MESSAGE(
"Remeshing requires unique positive tetrahedra");
142 for (
int d = 0;
d != 4; ++
d) {
145 for (
int j = 0;
j != 4; ++
j)
148 auto &incident =
faces[simplexKey(
f)];
149 incident.push_back(
i);
150 if (incident.size() > 2)
155 for (
const auto &[
f, incident] :
faces) {
157 for (
int i : incident) {
158 const auto &
c =
mesh.cells[
i];
159 const int v = *std::find_if(
c.begin(),
c.end(), [&](
int v) {
160 return std::find(f.begin(), f.end(), v) == f.end();
163 CGAL::orientation(remeshPoint(
mesh,
f[0]), remeshPoint(
mesh,
f[1]),
164 remeshPoint(
mesh,
f[2]), remeshPoint(
mesh,
v));
174using PatchTopology = std::map<int, std::vector<std::pair<int, int>>>;
175PatchTopology patchTopology(
const TetMeshData &
mesh) {
176 std::map<int, std::vector<RemeshFace>> patches;
177 for (
size_t i = 0;
i !=
mesh.boundary.size(); ++
i)
178 patches[
mesh.surfaceLabels.at(
i)].push_back(
mesh.boundary[
i]);
181 std::map<RemeshEdge, std::vector<int>> edges;
182 std::map<int, std::vector<RemeshEdge>> links;
183 std::set<RemeshFace> unique;
186 if (!unique.insert(simplexKey(
f)).second ||
187 CGAL::collinear(remeshPoint(
mesh,
f[0]), remeshPoint(
mesh,
f[1]),
188 remeshPoint(
mesh,
f[2])))
190 for (
int d = 0;
d != 3; ++
d) {
192 simplexKey(RemeshEdge{
f[(
d + 1) % 3],
f[(
d + 2) % 3]});
193 edges[e].push_back(
i);
194 links[
f[
d]].push_back(e);
197 for (
const auto &[
v, link] : links) {
198 std::map<int, std::vector<int>> graph;
199 for (
const auto &e : link) {
200 graph[e[0]].push_back(e[1]);
201 graph[e[1]].push_back(e[0]);
203 std::set<int> reached;
204 std::vector<int> queue{graph.begin()->first};
206 for (
const auto &[
n, neighbours] : graph) {
207 if (neighbours.size() == 1)
209 else if (neighbours.size() != 2)
212 for (
size_t i = 0;
i != queue.size(); ++
i)
213 if (reached.insert(queue[
i]).second)
214 queue.insert(queue.end(), graph.at(queue[
i]).begin(),
215 graph.at(queue[
i]).end());
216 if (reached.size() != graph.size() || (endpoints != 0 && endpoints != 2))
219 std::vector<std::vector<int>> neighbours(
triangles.size());
220 for (
const auto &[e, adjacent] : edges) {
221 if (adjacent.size() > 2)
223 if (adjacent.size() == 2) {
224 neighbours[adjacent[0]].push_back(adjacent[1]);
225 neighbours[adjacent[1]].push_back(adjacent[0]);
228 std::set<int> visited;
229 for (
size_t seed = 0; seed !=
triangles.size(); ++seed) {
230 if (visited.count(seed))
232 std::vector<int> queue{
static_cast<int>(seed)};
234 std::set<RemeshEdge> component_edges;
235 std::map<int, std::vector<int>>
boundary;
237 for (
size_t i = 0;
i != queue.size(); ++
i) {
238 const int f = queue[
i];
239 if (!visited.insert(
f).second)
243 for (
int d = 0;
d != 3; ++
d) {
244 const auto e = simplexKey(
246 component_edges.insert(e);
247 if (edges.at(e).size() == 1) {
252 queue.insert(queue.end(), neighbours[
f].begin(), neighbours[
f].end());
262 std::vector<int> walk{
v};
263 for (
size_t i = 0;
i != walk.size(); ++
i)
264 if (seen.insert(walk[
i]).second)
265 walk.insert(walk.end(),
boundary.at(walk[
i]).begin(),
270 static_cast<int>(component_edges.size()) + count,
278double remeshQuality(
const TetMeshData &
mesh) {
282 for (
int i = 0;
i != 4; ++
i)
283 for (
int j = 0;
j !=
i; ++
j)
284 sum += CGAL::to_double(CGAL::squared_distance(remeshPoint(
mesh,
c[
i]),
285 remeshPoint(
mesh,
c[
j])));
286 const double volume = CGAL::to_double(
287 CGAL::volume(remeshPoint(
mesh,
c[0]), remeshPoint(
mesh,
c[1]),
288 remeshPoint(
mesh,
c[2]), remeshPoint(
mesh,
c[3])));
289 minimum = std::min(minimum, 12. * std::pow(3. * volume, 2. / 3.) / sum);
297std::map<int, int> classifySurfacePatches(TetMeshData &
mesh,
298 double crease_angle) {
299 std::map<RemeshEdge, std::vector<int>> edges;
300 std::map<std::pair<int, int>, std::vector<int>> vertex_faces;
301 for (
size_t i = 0;
i !=
mesh.boundary.size(); ++
i) {
302 const auto &
f =
mesh.boundary[
i];
303 for (
int d = 0;
d != 3; ++
d) {
304 edges[simplexKey(RemeshEdge{
f[
d],
f[(
d + 1) % 3]})].push_back(
i);
305 vertex_faces[{
mesh.surfaceLabels[
i],
f[
d]}].push_back(
i);
308 std::set<int> isolated;
309 for (
const auto &[
key, incident] : vertex_faces) {
310 const int vertex =
key.second;
311 std::map<int, std::vector<int>> link;
312 for (
int i : incident) {
320 link[opposite[0]].push_back(opposite[1]);
321 link[opposite[1]].push_back(opposite[0]);
323 bool pinched =
false;
325 for (
const auto &[
v, adj] : link) {
326 ends += adj.size() == 1;
327 pinched |= adj.size() > 2;
329 std::set<int> reached;
330 std::vector<int> queue{link.begin()->first};
331 for (
size_t i = 0;
i != queue.size(); ++
i)
332 if (reached.insert(queue[
i]).second)
333 queue.insert(queue.end(), link.at(queue[
i]).begin(),
334 link.at(queue[
i]).end());
335 if (pinched || reached.size() != link.size() || (ends != 0 && ends != 2))
336 isolated.insert(incident.begin(), incident.end());
338 std::vector<std::vector<int>> neighbours(
mesh.boundary.size());
339 const double cosine = std::cos(crease_angle * std::acos(-1.) / 180.);
340 auto normal = [&](
int i) {
341 const auto &
f =
mesh.boundary[
i];
342 return CGAL::cross_product(
343 remeshPoint(
mesh,
f[1]) - remeshPoint(
mesh,
f[0]),
344 remeshPoint(
mesh,
f[2]) - remeshPoint(
mesh,
f[0]));
346 for (
const auto &[edge, incident] : edges) {
347 std::map<int, std::vector<int>> classes;
348 for (
int i : incident)
349 classes[
mesh.surfaceLabels[
i]].push_back(
i);
351 if (
faces.size() != 2 || isolated.count(
faces[0]) ||
352 isolated.count(
faces[1]))
354 const auto a = normal(
faces[0]), b = normal(
faces[1]);
355 if (std::abs(CGAL::to_double(
a * b)) <
356 cosine * std::sqrt(CGAL::to_double(
a.squared_length() *
357 b.squared_length())))
363 std::vector<int>
labels(
mesh.boundary.size());
364 std::map<int, int> classes;
365 for (
size_t seed = 0; seed !=
mesh.boundary.size(); ++seed) {
368 const int patch = classes.size() + 1;
369 classes.emplace(patch,
mesh.surfaceLabels[seed]);
370 std::vector<int> queue{
static_cast<int>(seed)};
371 for (
size_t i = 0;
i != queue.size(); ++
i) {
372 const int face = queue[
i];
376 queue.insert(queue.end(), neighbours[face].begin(),
377 neighbours[face].end());
383#if CGAL_VERSION_NR >= 1060200000
384using Vb = CgalVertexBase<
386 CGAL::Tetrahedral_remeshing::Remeshing_vertex_base_3<RemeshKernel>>;
387using Cb = RemeshCellBase<
388 CGAL::Tetrahedral_remeshing::Remeshing_cell_base_3<RemeshKernel>>;
389using Tr = CGAL::Triangulation_3<RemeshKernel,
390 CGAL::Triangulation_data_structure_3<Vb, Cb>>;
391using ExactKernel = CGAL::Exact_predicates_exact_constructions_kernel;
393 CGAL::Conforming_constrained_Delaunay_triangulation_vertex_base_3<
395 CGAL::Tetrahedral_remeshing::Remeshing_vertex_base_3<ExactKernel>>;
396using ExactCb = CGAL::Conforming_constrained_Delaunay_triangulation_cell_base_3<
398 CGAL::Tetrahedral_remeshing::Remeshing_cell_base_3<ExactKernel>>;
399using ExactTr = CGAL::Triangulation_3<
400 ExactKernel, CGAL::Triangulation_data_structure_3<ExactVb, ExactCb>>;
402 CGAL::Conforming_constrained_Delaunay_triangulation_3<ExactKernel, ExactTr>;
409 std::pair<int, int> regions;
416void constructConstrained(Tr &tr,
417 const std::vector<std::array<double, 3>> &
coordinates,
418 const std::vector<std::vector<int>> &polygons,
420 const std::vector<Region> ®ions,
bool strict) {
421 using CH = Tr::Cell_handle;
424 std::vector<ExactKernel::Point_3> exact_points;
426 exact_points.emplace_back(p[0], p[1], p[2]);
427 auto ccdt = CGAL::make_conforming_constrained_Delaunay_triangulation_3<CCDT>(
428 exact_points, polygons);
430 std::set<ExactKernel::Point_3> original(exact_points.begin(),
432 for (
auto vertex : ccdt.finite_vertex_handles())
433 if (!original.erase(vertex->point()))
435 "CGAL constrained recovery required additional points; strict "
436 "reconstruction preserves exactly the source vertices and IDs");
437 if (!original.empty())
438 THROW_MESSAGE(
"Constrained recovery omitted a source vertex");
441 CGAL::Tetrahedral_remeshing::get_remeshing_triangulation(std::move(ccdt));
446 const ExactTr::Vertex *infinite;
447 Tr::Vertex operator()(
const ExactTr::Vertex &)
const {
return {}; }
448 void operator()(
const ExactTr::Vertex &from, Tr::Vertex &to)
const {
449 if (&from != infinite) {
450 const auto &p = from.point();
451 to.set_point(RemeshPoint(CGAL::to_double(CGAL::exact(p.x())),
452 CGAL::to_double(CGAL::exact(p.y())),
453 CGAL::to_double(CGAL::exact(p.z()))));
458 Tr::Cell operator()(
const ExactTr::Cell &)
const {
return {}; }
459 void operator()(
const ExactTr::Cell &from, Tr::Cell &to)
const {
460 for (
int d = 0;
d != 4; ++
d)
461 to.set_surface_patch_index(
d, from.surface_patch_index(
d));
464 tr.set_infinite_vertex(
465 tr.tds().copy_tds(exact.tds(), exact.infinite_vertex(),
466 CopyVertex{&*exact.infinite_vertex()}, CopyCell{}));
474 int component_count = 0;
475 for (
auto seed : tr.all_cell_handles()) {
478 const int component = component_count++;
479 std::vector<CH> queue{seed};
480 for (
size_t i = 0;
i != queue.size(); ++
i) {
481 const auto cell = queue[
i];
482 if (!
components.emplace(cell, component).second)
484 for (
int d = 0;
d != 4; ++
d)
485 if (!cell->is_facet_on_surface(
d))
486 queue.push_back(cell->neighbor(
d));
491 std::pair<int, int> regions;
493 std::vector<std::vector<Transition>> graph(component_count);
494 for (
auto f : tr.finite_facets()) {
495 const int index =
f.first->surface_patch_index(
f.second);
499 const auto other = tr.mirror_facet(
f);
504 std::vector<int> component_regions(component_count, -1);
505 const int exterior =
components.at(tr.infinite_cell());
506 component_regions[exterior] = 0;
507 std::vector<int> queue{exterior};
508 for (
size_t i = 0;
i != queue.size(); ++
i) {
509 const int component = queue[
i], region = component_regions[component];
510 for (
const auto &edge : graph[component]) {
511 const auto [
a, b] = edge.regions;
512 if (region !=
a && region != b)
513 THROW_MESSAGE(
"Inconsistent constrained source region boundary");
514 const int next = region ==
a ? b :
a;
515 if (component_regions[edge.component] == -1) {
516 component_regions[edge.component] = next;
517 queue.push_back(edge.component);
518 }
else if (component_regions[edge.component] != next)
519 THROW_MESSAGE(
"Ambiguous constrained source region classification");
522 std::vector<size_t> region_cell_counts(regions.size());
523 for (
auto c : tr.finite_cell_handles()) {
524 const int region = component_regions.at(
components.at(
c));
526 ++region_cell_counts.at(region);
528 for (
auto c : tr.all_cell_handles()) {
529 const int region = component_regions.at(
components.at(
c));
532 c->set_subdomain_index(regions.at(region).material);
535 c->selected = regions.at(region).selected ||
536 (region != 0 && region_cell_counts.at(region) > 1);
542std::vector<std::vector<int>>
543planarConstraintGroups(
const TetMeshData &
source,
const RemeshFaces &
faces,
544 const std::set<RemeshEdge> &protected_edges) {
545 std::map<RemeshEdge, std::vector<int>> incident;
546 for (
size_t i = 0;
i !=
source.boundary.size(); ++
i)
547 for (
int d = 0;
d != 3; ++
d)
548 incident[simplexKey(RemeshEdge{
source.boundary[
i][
d],
551 std::vector<std::vector<int>> neighbours(
source.boundary.size());
552 for (
const auto &[edge, adjacent] : incident) {
553 if (adjacent.size() != 2 || protected_edges.count(edge))
555 const int a = adjacent[0], b = adjacent[1];
561 if (!std::all_of(
source.boundary[b].begin(),
source.boundary[b].end(),
563 return CGAL::coplanar(
564 remeshPoint(source, f[0]), remeshPoint(source, f[1]),
565 remeshPoint(source, f[2]), remeshPoint(source, v));
568 neighbours[
a].push_back(b);
569 neighbours[b].push_back(
a);
571 std::vector<bool> visited(
source.boundary.size());
572 std::vector<std::vector<int>> groups;
573 for (
size_t seed = 0; seed != visited.size(); ++seed) {
576 std::vector<int> group{
int(seed)};
577 visited[seed] =
true;
578 for (
size_t i = 0;
i != group.size(); ++
i)
579 for (
int next : neighbours[group[
i]])
580 if (!visited[next]) {
581 visited[next] =
true;
582 group.push_back(next);
584 groups.push_back(std::move(group));
589std::vector<int> reconstructConstrained(TetMeshData &
result,
590 const TetMeshData &
source) {
592 source.surfaceLabels.size() !=
source.boundary.size() ||
593 (!
source.cellLabels.empty() &&
598 for (
size_t i = 0;
i !=
source.points.size(); ++
i) {
600 if (!
std::isfinite(x))
602 if (
source.vertexIds[
i] <= 0 || !ids.insert(
source.vertexIds[
i]).second ||
604 THROW_MESSAGE(
"Reconstruction requires unique IDs and coordinates");
606 TetMeshData input =
source;
607 for (
auto &cell : input.
cells) {
611 if (CGAL::orientation(remeshPoint(input, cell[0]),
612 remeshPoint(input, cell[1]),
613 remeshPoint(input, cell[2]),
614 remeshPoint(input, cell[3])) == CGAL::NEGATIVE)
615 std::swap(cell[0], cell[1]);
617 const auto faces = remeshFaces(input);
619 source.cellLabels.empty() ? 1 :
source.cellLabels.front();
621 std::any_of(
source.cellLabels.begin(),
source.cellLabels.end(),
622 [&](
int label) { return label != material; }))
623 THROW_MESSAGE(
"Reconstruction requires uniform volume classification");
624 std::map<RemeshFace, int> protected_faces;
625 for (
size_t i = 0;
i !=
source.boundary.size(); ++
i)
627 source.surfaceLabels[
i] <= 0 ||
628 !protected_faces.emplace(simplexKey(
source.boundary[
i]),
i).second)
630 for (
const auto &[face, adjacent] :
faces)
631 if (adjacent.
size() == 1 && !protected_faces.count(face))
633 "Constrained reconstruction requires the complete exterior");
634 std::set<RemeshEdge> source_edges, protected_edges;
636 for (
int i = 0;
i != 4; ++
i)
637 for (
int j = 0;
j !=
i; ++
j)
638 source_edges.insert(simplexKey(RemeshEdge{cell[
i], cell[
j]}));
639 for (
auto edge :
source.featureEdges) {
640 edge = simplexKey(edge);
641 if (!source_edges.count(edge))
643 protected_edges.insert(edge);
645 std::vector<RemeshPoint>
points;
646 for (
size_t i = 0;
i !=
source.points.size(); ++
i)
648 if (CGAL::Polygon_mesh_processing::does_polygon_soup_self_intersect(
650 THROW_MESSAGE(
"Protected reconstruction surfaces self-intersect");
652 std::map<RemeshEdge, std::vector<int>> surface_edge_faces;
653 for (
size_t i = 0;
i !=
source.boundary.size(); ++
i) {
654 const auto &face =
source.boundary[
i];
655 for (
int d = 0;
d != 3; ++
d)
656 surface_edge_faces[simplexKey(RemeshEdge{face[
d], face[(
d + 1) % 3]})]
659 std::vector<std::vector<int>> polygons, carriers;
661 auto append = [&](
const std::vector<int> &
polygon,
662 const std::vector<int> &parents,
663 std::pair<int, int> regions) {
665 carriers.push_back(parents);
668 for (
const auto &group :
669 planarConstraintGroups(
source,
faces, protected_edges)) {
670 std::map<RemeshEdge, int> counts;
672 for (
int d = 0;
d != 3; ++
d)
673 ++counts[simplexKey(RemeshEdge{
source.boundary[
i][
d],
675 std::map<int, std::vector<int>>
boundary;
677 for (
const auto &[edge, count] : counts) {
679 boundary[edge[0]].push_back(edge[1]);
680 boundary[edge[1]].push_back(edge[0]);
681 }
else if (count != 2 || protected_edges.count(edge) ||
682 surface_edge_faces.at(edge).size() != 2)
691 for (
const auto &[vertex, neighbours] :
boundary)
698 const auto &adjacent =
boundary.at(vertex);
699 const int next = adjacent[0] ==
previous ? adjacent[1] : adjacent[0];
707 faces.at(simplexKey(
source.boundary[group.front()])).size() == 1
708 ? std::make_pair(0, 1)
709 :
std::make_pair(1, 1);
711 append(
polygon, group, regions);
715 std::set<int> remaining(group.begin(), group.end());
716 for (
int i : group) {
717 if (!remaining.erase(
i))
719 const auto &face =
source.boundary[
i];
721 for (
int d = 0;
d != 3; ++
d) {
722 const RemeshEdge edge =
723 simplexKey(RemeshEdge{face[
d], face[(
d + 1) % 3]});
724 const auto &incident = surface_edge_faces.at(edge);
725 if (incident.size() != 2 || protected_edges.count(edge))
727 const int j = incident[0] ==
i ? incident[1] : incident[0];
728 if (!remaining.count(
j))
730 const auto &next =
source.boundary[
j];
732 std::find_if(next.begin(), next.end(),
733 [&](
int v) { return v != edge[0] && v != edge[1]; });
734 append({face[(
d + 2) % 3], edge[0], *unique, edge[1]}, {
i,
j},
741 append({face.begin(), face.end()}, {
i}, regions);
747 for (
const auto &edge : protected_edges) {
748 const auto supported =
749 std::any_of(polygons.begin(), polygons.end(), [&](
const auto &p) {
750 for (size_t d = 0; d != p.size(); ++d)
751 if (simplexKey(RemeshEdge{p[d], p[(d + 1) % p.size()]}) == edge)
757 std::find_if(
faces.begin(),
faces.end(), [&](
const auto &entry) {
758 return std::find(entry.first.begin(), entry.first.end(), edge[0]) !=
760 std::find(entry.first.begin(), entry.first.end(), edge[1]) !=
763 if (!protected_faces.count(found->first))
764 append({found->first.begin(), found->first.end()}, {}, {1, 1});
768 std::vector<RemeshFace> plc =
source.boundary;
769 for (
size_t i = 0;
i != carriers.size(); ++
i)
771 plc.push_back({polygons[
i][0], polygons[
i][1], polygons[
i][2]});
772 if (CGAL::Polygon_mesh_processing::does_polygon_soup_self_intersect(
points,
774 THROW_MESSAGE(
"Protected curve support cannot form a valid PLC");
777 {{0, false, -1}, {material, false, -1}},
true);
778 std::map<RemeshPoint, int> indices;
779 for (
size_t i = 0;
i !=
points.size(); ++
i)
781 auto index = [&](Tr::Vertex_handle vertex) {
782 return indices.at(vertex->point());
785 next.points =
source.points;
786 next.vertexIds =
source.vertexIds;
788 std::set<RemeshEdge> output_edges;
789 for (
auto cell : tr.finite_cell_handles())
790 if (cell->subdomain_index()) {
791 std::array<int, 4> conn;
792 for (
int d = 0;
d != 4; ++
d)
793 conn[
d] =
index(cell->vertex(
d));
794 next.cells.push_back(conn);
795 next.cellLabels.push_back(material);
796 used.insert(conn.begin(), conn.end());
797 for (
int i = 0;
i != 4; ++
i)
798 for (
int j = 0;
j !=
i; ++
j)
799 output_edges.insert(simplexKey(RemeshEdge{conn[
i], conn[
j]}));
801 if (used.size() !=
source.points.size())
802 THROW_MESSAGE(
"Physical reconstruction omitted a source vertex");
803 for (
const auto &edge : protected_edges)
804 if (!output_edges.count(edge))
805 THROW_MESSAGE(
"Constrained recovery lost a protected curve");
806 std::vector<ExactKernel::Point_3> exact;
808 exact.emplace_back(p[0], p[1], p[2]);
809 auto identity = [&](
int i) {
813 return simplexKey(
key);
815 std::vector<Triangles> patch_triangles(carriers.size());
816 std::vector<std::unique_ptr<TriangleTree>> patch_trees(carriers.size());
817 for (
size_t i = 0;
i != carriers.size(); ++
i) {
819 for (
int parent : carriers[
i]) {
827 TetMeshData before =
source, after = next;
828 before.boundary.clear();
829 before.surfaceLabels.clear();
830 std::vector<int> parents;
831 for (
auto facet : tr.finite_facets()) {
832 const int id = facet.first->surface_patch_index(facet.second);
833 if (!
id || carriers.at(
id - 1).empty())
835 if (!facet.first->subdomain_index() &&
836 !facet.first->neighbor(facet.second)->subdomain_index())
837 THROW_MESSAGE(
"A protected surface lies outside the physical domain");
840 for (
int d = 0;
d != 4; ++
d)
841 if (
d != facet.second)
842 face[
n++] =
index(facet.first->vertex(
d));
844 CGAL::centroid(exact[face[0]], exact[face[1]], exact[face[2]]);
847 const auto &
triangles = patch_triangles.at(
id - 1);
848 std::vector<Triangles::const_iterator> hits;
852 const auto box = centre.bbox();
853 const RemeshKernel::Iso_cuboid_3 bounds(box.xmin(), box.ymin(),
854 box.zmin(), box.xmax(),
855 box.ymax(), box.zmax());
856 patch_trees[
id - 1]->all_intersected_primitives(bounds,
857 std::back_inserter(hits));
860 for (
auto hit : hits) {
861 const int i = carriers[
id - 1][hit -
triangles.cbegin()];
863 if (ExactKernel::Triangle_3(exact[
f[0]], exact[
f[1]], exact[
f[2]])
869 THROW_MESSAGE(
"A recovered facet leaves its exact source patch");
871 if (CGAL::cross_product(exact[face[1]] - exact[face[0]],
872 exact[face[2]] - exact[face[0]]) *
873 CGAL::cross_product(exact[
f[1]] - exact[
f[0]],
874 exact[
f[2]] - exact[
f[0]]) <
876 std::swap(face[1], face[2]);
877 next.boundary.push_back(face);
878 next.surfaceLabels.push_back(
source.surfaceLabels[
parent]);
879 after.boundary.push_back(face);
880 after.surfaceLabels.push_back(
id);
881 parents.push_back(
parent);
883 for (
size_t i = 0;
i != carriers.size(); ++
i)
884 for (
int parent : carriers[
i]) {
886 before.surfaceLabels.push_back(
i + 1);
890 if (patchTopology(before) != patchTopology(after))
891 THROW_MESSAGE(
"Constrained recovery changes protected patch topology");
892 auto nodes = [](
const TetMeshData &
mesh) {
893 std::map<int, std::set<int>>
result;
894 for (
size_t i = 0;
i !=
mesh.boundary.size(); ++
i)
896 mesh.boundary[
i].end());
899 if (nodes(before) != nodes(after))
900 THROW_MESSAGE(
"Constrained recovery changes protected patch nodes");
902 auto volume = [&](
const TetMeshData &
mesh) {
904 auto total = CGAL::exact(ExactKernel::FT(0));
906 total += CGAL::exact(CGAL::volume(exact[cell[0]], exact[cell[1]],
907 exact[cell[2]], exact[cell[3]]));
910 if (volume(input) != volume(next))
911 THROW_MESSAGE(
"Constrained reconstruction changes the source volume");
912 next.featureEdges =
source.featureEdges;
913 next.edgeLabels =
source.edgeLabels;
914 next.fixedVertices =
source.fixedVertices;
923 const std::vector<int> &selected_cells,
926#if CGAL_VERSION_NR < 1060200000
927 THROW_MESSAGE(
"Constrained tetrahedral remeshing requires CGAL 6.2");
929 const bool optimise =
settings.targetEdgeLength > 0;
930 if (!std::isfinite(
settings.targetEdgeLength) ||
934 !std::isfinite(
settings.relativeSurfaceTolerance) ||
935 settings.relativeSurfaceTolerance <= 0 ||
940 (!
source.cellLabels.empty() &&
942 source.surfaceLabels.size() !=
source.boundary.size() ||
947 for (
size_t i = 0;
i !=
source.points.size(); ++
i) {
948 for (
double x :
source.points[
i])
949 if (!std::isfinite(x))
951 if (
source.vertexIds[
i] <= 0 || !ids.insert(
source.vertexIds[
i]).second ||
953 THROW_MESSAGE(
"Remeshing requires unique vertex IDs and coordinates");
961 THROW_MESSAGE(
"Physical remeshing cell labels must be positive");
963 for (
auto &
c : input.
cells) {
965 if (
v < 0 ||
static_cast<size_t>(
v) >= input.
points.size())
967 if (CGAL::orientation(remeshPoint(input,
c[0]), remeshPoint(input,
c[1]),
968 remeshPoint(input,
c[2]),
969 remeshPoint(input,
c[3])) == CGAL::NEGATIVE)
970 std::swap(
c[0],
c[1]);
972 const auto faces = remeshFaces(input,
false);
973 std::set<RemeshEdge> cell_edges;
974 std::set<int> used_vertices;
975 for (
const auto &
c : input.
cells) {
976 used_vertices.insert(
c.begin(),
c.end());
977 for (
int i = 0;
i != 4; ++
i)
978 for (
int j = 0;
j !=
i; ++
j)
979 cell_edges.insert(simplexKey(RemeshEdge{
c[
i],
c[
j]}));
981 if (used_vertices.size() != input.
points.size())
988 if (!used_vertices.count(
i))
991 for (
int i : selected_cells) {
992 if (
i < 0 ||
static_cast<size_t>(
i) >= input.
cells.size())
1001 for (
const auto &[face, adjacent] :
faces) {
1002 if (adjacent.size() != 2)
1005 for (
int d = 0;
d != 2; ++
d) {
1006 const auto &cell = input.
cells[adjacent[
d]];
1007 const int opposite =
1008 *std::find_if(cell.begin(), cell.end(), [&](
int v) {
1009 return std::find(face.begin(), face.end(), v) == face.end();
1011 sides[
d] = CGAL::orientation(
1012 remeshPoint(input, face[0]), remeshPoint(input, face[1]),
1013 remeshPoint(input, face[2]), remeshPoint(input, opposite));
1015 if (sides[0] == sides[1] &&
1017 expanded |=
selected.insert(adjacent[0]).second;
1018 expanded |=
selected.insert(adjacent[1]).second;
1023 std::map<RemeshFace, int> patches;
1024 for (
size_t i = 0;
i != input.
boundary.size(); ++
i) {
1025 const auto f = simplexKey(input.
boundary[
i]);
1031 std::map<std::pair<int, int>,
int> inferred;
1032 for (
const auto &[
f, adjacent] :
faces) {
1034 const int b = adjacent.size() == 2 ? input.
cellLabels[adjacent[1]] : 0;
1035 if ((
a != b || adjacent.size() == 1) && !patches.count(
f)) {
1036 const auto pair = std::minmax(
a, b);
1037 const auto [
it, added] = inferred.emplace(pair, max_label + 1);
1040 patches.emplace(
f,
it->second);
1049 std::map<std::pair<int, RemeshEdge>,
unsigned> boundary_edges;
1050 for (
size_t i = 0;
i != input.
boundary.size(); ++
i)
1051 for (
int d = 0;
d != 3; ++
d)
1058 for (
const auto &[
key, count] : boundary_edges)
1060 fixed_vertices.insert(
key.second.begin(),
key.second.end());
1061 input.
fixedVertices.assign(fixed_vertices.begin(), fixed_vertices.end());
1063 const auto surface_classes =
1064 classifySurfacePatches(input,
settings.creaseAngle);
1066 for (
size_t i = 0;
i != input.
boundary.size(); ++
i)
1068 max_label = surface_classes.size();
1069 const auto topology = patchTopology(input);
1070 std::set<int> auxiliary_labels;
1071 std::set<RemeshEdge> auxiliary_edges;
1072 std::set<int> auxiliary_vertices;
1079 result = std::move(input);
1080 report = std::move(next_report);
1083 using VH = Tr::Vertex_handle;
1084 std::vector<RemeshPoint>
points;
1085 for (
size_t i = 0;
i != input.
points.size(); ++
i)
1086 points.push_back(remeshPoint(input,
i));
1089 for (
const auto &p :
points)
1090 scale = std::max(
scale, std::sqrt(CGAL::to_double(
1091 CGAL::squared_distance(p,
points.front()))));
1092 const double tolerance2 =
1097 std::vector<Region> regions;
1098 std::vector<std::vector<int>> polygons;
1101 regions = {{0,
false, -1}};
1104 max_label = surface_classes.size();
1105 auxiliary_labels.clear();
1106 auxiliary_edges.clear();
1107 std::map<std::pair<int, int>,
int> region_ids;
1108 std::vector<int> cell_regions;
1109 for (
size_t i = 0;
i != input.
cells.size(); ++
i) {
1113 auto [
it, added] = region_ids.emplace(
key, regions.size());
1116 cell_regions.push_back(
it->second);
1118 auto add_constraint = [&](
const RemeshFace &face,
1119 const std::vector<int> &adjacent,
int patch) {
1120 const int a = cell_regions[adjacent[0]],
1121 b = adjacent.size() == 2 ? cell_regions[adjacent[1]] : 0;
1123 patch = ++max_label;
1124 auxiliary_labels.insert(patch);
1125 for (
int d = 0;
d != 3; ++
d)
1126 auxiliary_edges.insert(
1127 simplexKey(RemeshEdge{face[
d], face[(
d + 1) % 3]}));
1129 polygons.emplace_back(face.begin(), face.end());
1132 std::set<RemeshEdge> constrained_source_edges;
1133 for (
const auto &[face, adjacent] :
faces) {
1134 const int a = cell_regions[adjacent[0]],
1135 b = adjacent.size() == 2 ? cell_regions[adjacent[1]] : 0;
1136 if (patches.count(face) ||
a != b) {
1137 add_constraint(face, adjacent,
1138 patches.count(face) ? patches.at(face) : 0);
1139 for (
int d = 0;
d != 3; ++
d)
1140 constrained_source_edges.insert(
1141 simplexKey(RemeshEdge{face[
d], face[(
d + 1) % 3]}));
1145 if (adjacent.size() == 2 &&
1148 for (
int d = 0;
d != 2; ++
d) {
1149 const auto &cell = input.
cells[adjacent[
d]];
1150 const int opposite =
1151 *std::find_if(cell.begin(), cell.end(), [&](
int v) {
1152 return std::find(face.begin(), face.end(), v) == face.end();
1154 sides[
d] = CGAL::orientation(
points[face[0]],
points[face[1]],
1157 if (sides[0] == sides[1])
1159 "cells; expand the selection");
1164 if (!constrained_source_edges.count(simplexKey(edge))) {
1166 std::find_if(
faces.begin(),
faces.end(), [&](
const auto &entry) {
1167 return std::find(entry.first.begin(), entry.first.end(),
1168 edge[0]) != entry.first.end() &&
1169 std::find(entry.first.begin(), entry.first.end(),
1170 edge[1]) != entry.first.end();
1172 add_constraint(found->first, found->second, 0);
1173 for (
int d = 0;
d != 3; ++
d)
1174 constrained_source_edges.insert(simplexKey(
1175 RemeshEdge{found->first[
d], found->first[(
d + 1) % 3]}));
1177 std::vector<std::pair<size_t, size_t>> intersections;
1178 CGAL::Polygon_mesh_processing::triangle_soup_self_intersections(
1179 points, polygons, std::back_inserter(intersections));
1180 if (intersections.empty())
1183 for (
const auto &[
a, b] : intersections) {
1186 THROW_MESSAGE(
"Physical remeshing surfaces self-intersect");
1187 for (
auto index : {
a, b}) {
1192 const auto source_cell = regions[region].sourceCell;
1193 if (source_cell >= 0)
1200 "Protected curve support cannot form a valid remeshing PLC");
1206 std::map<RemeshPoint, int> point_indices;
1207 for (
size_t i = 0;
i !=
points.size(); ++
i)
1208 point_indices.emplace(
points[
i],
i);
1209 for (
auto v : tr.finite_vertex_handles()) {
1210 const auto found = point_indices.find(
v->point());
1211 v->moabHandle = found == point_indices.end() ? 0 : found->second + 1;
1213 v->set_dimension(3);
1215 std::set<VH> fixed_support;
1216 for (
auto f : tr.finite_facets()) {
1217 const int index =
f.first->surface_patch_index(
f.second);
1221 f.first->set_surface_patch_index(
f.second, patch);
1222 const auto other = tr.mirror_facet(
f);
1223 other.first->set_surface_patch_index(other.second, patch);
1224 if (auxiliary_labels.count(patch))
1225 for (
int d = 0;
d != 4; ++
d)
1226 if (
d !=
f.second) {
1227 auto v =
f.first->vertex(
d);
1228 if (
v->moabHandle) {
1229 fixed_support.insert(
v);
1230 auxiliary_vertices.insert(
v->moabHandle - 1);
1236 std::map<RemeshEdge, std::vector<int>> edge_faces;
1237 for (
size_t i = 0;
i != input.
boundary.size(); ++
i)
1238 for (
int d = 0;
d != 3; ++
d)
1239 edge_faces[simplexKey(RemeshEdge{input.
boundary[
i][
d],
1242 std::set<RemeshEdge> feature_edges;
1245 feature_edges.insert(auxiliary_edges.begin(), auxiliary_edges.end());
1247 if (e[0] < 0 || e[1] < 0 || e[0] == e[1] ||
1248 static_cast<size_t>(std::max(e[0], e[1])) >=
points.size())
1250 feature_edges.insert(simplexKey(e));
1252 const double cosine = std::cos(
settings.creaseAngle * std::acos(-1.) / 180.);
1253 for (
const auto &[edge, incident] : edge_faces) {
1254 bool feature = incident.size() != 2;
1256 const auto &
a = input.
boundary[incident[0]],
1262 const double dot = std::abs(CGAL::to_double(na *
nb));
1263 const int opposite = *std::find_if(b.begin(), b.end(), [&](
int v) {
1264 return v != edge[0] && v != edge[1];
1270 CGAL::squared_distance(
1273 points[
a[2]])) > tolerance2 ||
1274 dot < cosine * std::sqrt(CGAL::to_double(na.squared_length() *
1275 nb.squared_length()));
1278 feature_edges.insert(edge);
1281 for (
auto v : tr.finite_vertex_handles())
1284 std::map<std::pair<VH, VH>,
bool> constrained_edges;
1285 using FeatureSegment = RemeshKernel::Segment_3;
1286 using FeatureSegments = std::vector<FeatureSegment>;
1287 using FeaturePrimitive =
1288 CGAL::AABB_segment_primitive_3<RemeshKernel,
1289 FeatureSegments::const_iterator>;
1291 CGAL::AABB_tree<CGAL::AABB_traits_3<RemeshKernel, FeaturePrimitive>>;
1292 FeatureSegments feature_segments;
1293 for (
const auto &e : feature_edges)
1294 feature_segments.emplace_back(
points[e[0]],
points[e[1]]);
1297 double coordinate_scale = 1;
1298 for (
const auto &p : input.
points)
1300 coordinate_scale = std::max(coordinate_scale, std::abs(x));
1301 const double feature_tolerance2 = std::pow(
1302 128 * std::numeric_limits<double>::epsilon() * coordinate_scale, 2);
1303 if (!feature_segments.empty()) {
1304 const FeatureTree tree(feature_segments.cbegin(), feature_segments.cend());
1305 for (
const auto &e : tr.finite_edges()) {
1306 auto a = e.first->vertex(e.second), b = e.first->vertex(e.third);
1307 const auto segment = tree.closest_point_and_primitive(
1308 CGAL::midpoint(
a->point(), b->point()))
1310 if (CGAL::squared_distance(
a->point(), *segment) <= feature_tolerance2 &&
1311 CGAL::squared_distance(b->point(), *segment) <= feature_tolerance2)
1312 constrained_edges[std::minmax(
a, b)] =
true;
1315 std::map<VH, bool> constrained_vertices;
1316 for (
auto v : fixed_support)
1317 constrained_vertices[
v] =
true;
1318 std::map<int, std::set<int>> curve_classes;
1323 for (
const auto &[
v,
labels] : curve_classes)
1325 constrained_vertices[
vertices.at(
v)] =
true;
1329 constrained_vertices[
vertices.at(
i)] =
true;
1332 CGAL::tetrahedral_isotropic_remeshing(
1334 CGAL::parameters::number_of_iterations(
settings.iterations)
1335 .remesh_boundaries(
settings.remeshSurfaces)
1336 .cell_is_selected_map(RemeshSelection<Tr>())
1337 .edge_is_constrained_map(
1338 boost::make_assoc_property_map(constrained_edges))
1339 .vertex_is_constrained_map(
1340 boost::make_assoc_property_map(constrained_vertices)));
1344 std::map<VH, int> output_indices;
1345 std::set<int> retained;
1346 int max_id = *ids.rbegin();
1347 std::set<VH> physical_vertices;
1348 for (
auto c : tr.finite_cell_handles())
1349 if (
c->subdomain_index())
1350 for (
int d = 0;
d != 4; ++
d)
1351 physical_vertices.insert(
c->vertex(
d));
1352 for (
auto v : physical_vertices) {
1353 const auto &p =
v->point();
1354 const std::array<double, 3> x{p.x(), p.y(), p.z()};
1356 if (
v->moabHandle && x == input.
points.at(
v->moabHandle - 1)) {
1357 const int i =
v->moabHandle - 1;
1361 if (max_id == INT_MAX)
1369 output_indices.emplace(
v, next.
points.size());
1370 next.
points.push_back(x);
1375 if (!optimise && retained.size() != input.
points.size())
1376 THROW_MESSAGE(
"Constraint recovery did not retain every source vertex");
1377 for (
int i : auxiliary_vertices)
1378 if (!retained.count(
i))
1379 THROW_MESSAGE(
"Remeshing changed a selection-interface vertex");
1381 if (!retained.count(
i))
1385 for (
auto c : tr.finite_cell_handles()) {
1386 if (!
c->subdomain_index())
1388 std::array<int, 4> conn;
1389 for (
int d = 0;
d != 4; ++
d)
1390 conn[
d] = output_indices.at(
c->vertex(
d));
1391 next.
cells.push_back(conn);
1394 for (
auto f : tr.finite_facets()) {
1395 if (!
f.first->is_facet_on_surface(
f.second))
1397 const int label =
f.first->surface_patch_index(
f.second);
1398 if (label <= 0 || label > max_label)
1400 if (auxiliary_labels.count(
label))
1404 for (
int d = 0;
d != 4; ++
d)
1406 conn[
n++] = output_indices.at(
f.first->vertex(
d));
1411 if (patchTopology(next) !=
topology)
1412 THROW_MESSAGE(
"Remeshing changes protected surface topology");
1415 using Triangle = RemeshKernel::Triangle_3;
1416 using Triangles = std::vector<Triangle>;
1418 CGAL::AABB_triangle_primitive_3<RemeshKernel, Triangles::const_iterator>;
1419 using Tree = CGAL::AABB_tree<CGAL::AABB_traits_3<RemeshKernel, Primitive>>;
1421 std::map<int, Triangles>
values;
1422 for (
size_t i = 0;
i !=
mesh.boundary.size(); ++
i) {
1423 const auto &
f =
mesh.boundary[
i];
1425 remeshPoint(
mesh,
f[1]),
1426 remeshPoint(
mesh,
f[2]));
1431 for (
const auto &[
label, old] : old_triangles) {
1432 const auto ¤t = new_triangles.at(
label);
1433 Tree old_tree(old.begin(), old.end()),
1434 new_tree(current.begin(), current.end());
1435 auto maximum_distance = [&](
const Triangles &from,
const Tree &to) {
1437 for (
const auto &triangle : from) {
1438 for (
int d = 0;
d != 3; ++
d)
1439 maximum = std::max(maximum, CGAL::to_double(to.squared_distance(
1440 triangle.vertex(
d))));
1441 maximum = std::max(maximum, CGAL::to_double(to.squared_distance(
1442 CGAL::centroid(triangle))));
1446 const double deviation2 = std::max(maximum_distance(old, new_tree),
1447 maximum_distance(current, old_tree));
1448 if (deviation2 > tolerance2) {
1449 std::ostringstream message;
1451 <<
"Remeshing surface patch " <<
label
1452 <<
" exceeds surface geometry tolerance: maximum sampled distance "
1453 << std::sqrt(deviation2) <<
", allowed " << std::sqrt(tolerance2)
1454 <<
"; retaining the candidate";
1455 logWarning(message.str());
1458 for (
size_t i = 0;
i != next.
boundary.size(); ++
i) {
1462 const Triangle triangle(remeshPoint(next,
f[0]), remeshPoint(next,
f[1]),
1463 remeshPoint(next,
f[2]));
1464 const auto reference =
1465 old_tree.closest_point_and_primitive(CGAL::centroid(triangle)).second;
1466 const auto normal = CGAL::cross_product(triangle[1] - triangle[0],
1467 triangle[2] - triangle[0]);
1468 const auto old_normal = CGAL::cross_product(
1469 (*reference)[1] - (*reference)[0], (*reference)[2] - (*reference)[0]);
1470 if (normal * old_normal < 0)
1471 std::swap(
f[1],
f[2]);
1476 using Segment = RemeshKernel::Segment_3;
1478 std::map<int, std::vector<Segment>>
values;
1479 for (
size_t i = 0;
i !=
mesh.featureEdges.size(); ++
i) {
1480 const auto &e =
mesh.featureEdges[
i];
1482 remeshPoint(
mesh, e[1]));
1486 const auto old_curves =
curves(input);
1487 FeatureSegments curve_segments;
1488 std::vector<int> curve_labels;
1489 for (
const auto &[
label, segments] : old_curves)
1490 for (
const auto &segment : segments) {
1491 curve_segments.push_back(segment);
1492 curve_labels.push_back(
label);
1494 const FeatureTree curve_tree(curve_segments.cbegin(), curve_segments.cend());
1495 auto covers_edge = [&](
const RemeshPoint &
a,
const RemeshPoint &b,
1496 const auto &segments) {
1497 const auto direction = b -
a;
1498 const double length2 = CGAL::to_double(direction.squared_length());
1499 const RemeshKernel::Line_3 line(
a, b);
1500 std::vector<std::pair<double, double>> intervals;
1501 for (
const auto &segment : segments) {
1502 if (CGAL::squared_distance(segment.source(), line) > feature_tolerance2 ||
1503 CGAL::squared_distance(segment.target(), line) > feature_tolerance2)
1505 const double s = CGAL::to_double((segment.source() -
a) * direction) /
1507 t = CGAL::to_double((segment.target() -
a) * direction) /
1509 const auto [lo, hi] = std::minmax(
s,
t);
1510 if (hi >= 0 && lo <= 1)
1511 intervals.emplace_back(std::max(0., lo), std::min(1., hi));
1513 std::sort(intervals.begin(), intervals.end());
1514 const double epsilon = std::sqrt(feature_tolerance2 / length2);
1516 for (
const auto &[lo, hi] : intervals) {
1517 if (lo > reached + epsilon)
1519 reached = std::max(reached, hi);
1520 if (reached >= 1 - epsilon)
1525 for (
const auto &e : tr.finite_edges()) {
1526 const std::pair<VH, VH> edge{e.first->vertex(e.second),
1527 e.first->vertex(e.third)};
1528 if (!output_indices.count(edge.first) || !output_indices.count(edge.second))
1530 const auto &
a = edge.first->point(), &b = edge.second->point();
1531 const double margin = std::sqrt(feature_tolerance2);
1532 const RemeshKernel::Iso_cuboid_3 bounds(
1533 std::min(
a.x(), b.x()) - margin, std::min(
a.y(), b.y()) - margin,
1534 std::min(
a.z(), b.z()) - margin, std::max(
a.x(), b.x()) + margin,
1535 std::max(
a.y(), b.y()) + margin, std::max(
a.z(), b.z()) + margin);
1536 std::vector<FeatureSegments::const_iterator> hits;
1537 curve_tree.all_intersected_primitives(bounds, std::back_inserter(hits));
1538 std::map<int, FeatureSegments> candidates;
1539 for (
auto hit : hits)
1540 candidates[curve_labels[hit - curve_segments.cbegin()]].push_back(*hit);
1542 for (
const auto &[
id, segments] : candidates) {
1543 if (covers_edge(edge.first->point(), edge.second->point(), segments)) {
1551 {output_indices.at(edge.first), output_indices.at(edge.second)});
1555 const auto new_curves =
curves(next);
1556 std::map<int, std::unique_ptr<FeatureTree>> curve_trees;
1557 for (
const auto &[
label, segments] : new_curves)
1558 curve_trees.emplace(
label, std::make_unique<FeatureTree>(segments.cbegin(),
1561 std::map<int, std::map<int, std::vector<int>>> graphs;
1562 for (
size_t i = 0;
i !=
mesh.featureEdges.size(); ++
i) {
1563 const auto &e =
mesh.featureEdges[
i];
1564 graphs[
mesh.edgeLabels[
i]][e[0]].push_back(e[1]);
1565 graphs[
mesh.edgeLabels[
i]][e[1]].push_back(e[0]);
1567 std::map<int, std::pair<int, std::map<int, size_t>>> signatures;
1568 for (
const auto &[
label, graph] : graphs) {
1569 auto &value = signatures[
label];
1570 std::set<int> visited;
1571 for (
const auto &[
v, adj] : graph) {
1572 if (adj.size() != 2)
1573 value.second.emplace(
mesh.vertexIds[
v], adj.size());
1574 if (visited.count(
v))
1577 std::vector<int> queue{
v};
1578 for (
size_t i = 0;
i != queue.size(); ++
i)
1579 if (visited.insert(queue[
i]).second)
1580 queue.insert(queue.end(), graph.at(queue[
i]).begin(),
1581 graph.at(queue[
i]).end());
1586 const auto old_graphs = curve_topology(input),
1587 new_graphs = curve_topology(next);
1588 if (old_graphs != new_graphs) {
1589 std::ostringstream message;
1590 message <<
"Remeshing changes a protected curve graph";
1591 for (
const auto &[
label, original] : old_graphs) {
1592 const auto found = new_graphs.find(
label);
1593 if (found == new_graphs.end()) {
1594 message <<
": missing curve class " <<
label;
1597 if (original == found->second)
1599 message <<
": class " <<
label <<
", components " << original.first
1600 <<
" -> " << found->second.first;
1601 for (
const auto &[
id, degree] : original.second) {
1602 const auto node = found->second.second.find(
id);
1603 if (node == found->second.second.end() || node->second != degree) {
1604 message <<
", source junction GLOBAL_ID " <<
id <<
" degree "
1606 << (node == found->second.second.end() ? 0 : node->second);
1614 for (
const auto &[
label, segments] : old_curves) {
1615 double deviation2 = 0;
1616 for (
const auto &segment : segments) {
1617 const auto &tree = *curve_trees.at(
label);
1618 deviation2 = std::max(
1619 {deviation2, CGAL::to_double(tree.squared_distance(segment.source())),
1620 CGAL::to_double(tree.squared_distance(segment.target())),
1621 CGAL::to_double(tree.squared_distance(CGAL::midpoint(segment)))});
1623 if (deviation2 > tolerance2) {
1624 std::ostringstream message;
1625 message <<
"Remeshing protected curve " <<
label
1626 <<
" exceeds geometry tolerance: maximum sampled distance "
1627 << std::sqrt(deviation2) <<
", allowed " << std::sqrt(tolerance2)
1628 <<
"; retaining the candidate";
1629 logWarning(message.str());
1632 std::set<std::array<int, 4>> output_cells;
1633 for (
const auto &
c : next.
cells) {
1634 std::array<int, 4>
key;
1635 for (
int d = 0;
d != 4; ++
d)
1637 output_cells.insert(simplexKey(
key));
1639 for (
size_t i = 0;
i != input.
cells.size(); ++
i) {
1640 std::array<int, 4>
key;
1641 for (
int d = 0;
d != 4; ++
d)
1643 if (!output_cells.count(simplexKey(
key)))
1650 std::ostringstream message;
1651 message <<
"Remeshing candidate is below the minimum tetrahedron quality: "
1658 result = std::move(next);
1659 report = std::move(next_report);
1666 if (method == ReconstructionMethod::ConstrainedStrict) {
1667#if CGAL_VERSION_NR >= 1060200000
1670 THROW_MESSAGE(
"Strict constrained reconstruction requires CGAL 6.2");
1673 if (method != ReconstructionMethod::PointDelaunay)
1677 [](
int id) { return id <= 0; }))
1678 THROW_MESSAGE(
"Reconstruction requires positive vertex IDs");
1681 std::vector<std::uint64_t>(
vertices.vertexIds.begin(),
1683 if (
mesh.tr.dimension() != 3)
1688 std::map<std::uint64_t, int> indices;
1691 for (
auto c =
mesh.tr.finite_cells_begin();
c !=
mesh.tr.finite_cells_end();
1693 std::array<int, 4> cell;
1694 for (
int n = 0;
n != 4; ++
n)
1695 cell[
n] = indices.at(
c->vertex(
n)->moabHandle);
1696 next.
cells.push_back(cell);
1698 for (
auto f =
mesh.tr.finite_facets_begin();
f !=
mesh.tr.finite_facets_end();
1700 if (
mesh.tr.is_infinite(
f->first) ||
1701 mesh.tr.is_infinite(
f->first->neighbor(
f->second))) {
1703 if (
mesh.tr.is_infinite(face.first))
1704 face =
mesh.tr.mirror_facet(face);
1705 std::array<int, 3> conn;
1707 for (
int d = 0;
d != 4; ++
d)
1708 if (
d != face.second)
1709 conn[
n++] = indices.at(face.first->vertex(
d)->moabHandle);
1714 result = std::move(next);
1718std::vector<int> CGALTools::validateReconstruction(
1720 const std::vector<std::array<int, 2>> &protected_edges,
1721 const std::function<
void(
const std::string &)> &warning)
const {
1722 const auto report_warning = [&](
const std::string &message) {
1723 logWarning(message);
1727 if (!std::isfinite(surfaceFlipAngle) || surfaceFlipAngle < 0 ||
1728 surfaceFlipAngle > 90)
1729 THROW_MESSAGE(
"Surface flip angle must be between 0 and 90 degrees");
1732 THROW_MESSAGE(
"Invalid reconstruction vertices or patch labels");
1734 using Face = std::array<int, 3>;
1735 using Edge = std::array<int, 2>;
1736 using Normal = std::array<double, 3>;
1741 auto point = [&](
int i) {
1742 const auto &x =
source.points.at(
i);
1743 return K::Point_3(x[0], x[1], x[2]);
1745 auto normal = [&](
const Face &face) {
1746 const auto n = CGAL::cross_product(point(face[1]) - point(face[0]),
1747 point(face[2]) - point(face[0]));
1748 const double scale =
1749 std::max({std::abs(
n.x()), std::abs(
n.y()), std::abs(
n.z())});
1753 const double length = std::hypot(value[0], value[1], value[2]);
1754 for (
auto &x : value)
1758 auto dot = [](
const Normal &
a,
const Normal &b) {
1759 return std::inner_product(
a.begin(),
a.end(), b.begin(), 0.);
1761 const double chord = 2. * std::sin(surfaceFlipAngle * std::acos(-1.) / 360.);
1762 const double eps = std::numeric_limits<double>::epsilon();
1763 const double limit = chord * chord * (1. + 32. *
eps) + 256. *
eps *
eps;
1764 auto aligned = [&](
const Normal &
a,
const Normal &b) {
1767 const double sign = dot(
a, b) < 0 ? -1. : 1.;
1769 for (
int d = 0;
d != 3; ++
d)
1774 std::map<Face, int> counts;
1775 std::set<std::array<int, 4>>
cells;
1776 for (
auto cell :
mesh.cells) {
1777 const auto sorted =
key(cell);
1778 if (!
cells.insert(sorted).second ||
1779 std::adjacent_find(sorted.begin(), sorted.end()) != sorted.end())
1781 if (CGAL::orientation(point(cell[0]), point(cell[1]), point(cell[2]),
1782 point(cell[3])) == CGAL::COPLANAR)
1784 for (
int opposite = 0; opposite != 4; ++opposite) {
1787 for (
int d = 0;
d != 4; ++
d)
1789 face[
n++] = cell[
d];
1790 if (++counts[
key(face)] > 2)
1798 bool *disconnected_links =
nullptr) {
1799 std::map<Edge, int> counts;
1800 std::map<int, std::map<int, std::set<int>>> links;
1802 for (
int i = 0;
i != 3; ++
i) {
1803 const int v = face[
i],
a = face[(
i + 1) % 3], b = face[(
i + 2) % 3];
1804 links[
v][
a].insert(b);
1805 links[
v][b].insert(
a);
1807 for (
int j =
i + 1;
j != 3; ++
j)
1808 if (++counts[{face[
i], face[
j]}] > 2)
1813 std::set<int> boundary_nodes;
1814 for (
const auto &[edge, count] : counts)
1817 boundary_nodes.insert(edge.begin(), edge.end());
1819 for (
const auto &[
v, link] : links) {
1821 for (
const auto &[node, neighbors] : link) {
1822 ends += neighbors.size() == 1;
1823 if (neighbors.empty() || neighbors.size() > 2)
1827 std::vector<int> queue{link.begin()->first};
1828 for (
size_t i = 0;
i != queue.size(); ++
i)
1829 if (seen.insert(queue[
i]).second) {
1830 const auto &next = link.at(queue[
i]);
1831 queue.insert(queue.end(), next.begin(), next.end());
1833 if (seen.size() != link.size() ||
1834 ends != (boundary_nodes.count(
v) ? 2 : 0)) {
1835 if (!disconnected_links)
1836 THROW_MESSAGE(
"Disconnected preserved surface vertex link");
1837 *disconnected_links =
true;
1839 "Disconnected preserved surface vertex link at GLOBAL_ID " +
1840 std::to_string(
source.vertexIds[
v]) +
1841 "; retaining the incomplete reconstructed patch for inspection");
1844 if (!links.empty()) {
1846 std::vector<int> queue{links.begin()->first};
1847 for (
size_t i = 0;
i != queue.size(); ++
i)
1848 if (seen.insert(queue[
i]).second)
1849 for (
const auto &[neighbor, unused] : links.at(queue[
i]))
1850 queue.push_back(neighbor);
1851 if (seen.size() != links.size() &&
1852 !(disconnected_links && *disconnected_links))
1855 const auto euler =
static_cast<long long>(links.size()) -
1856 static_cast<long long>(counts.size()) +
1857 static_cast<long long>(
triangles.size());
1858 return std::make_pair(
boundary, euler);
1860 std::vector<Normal> source_normals;
1861 std::map<Edge, std::vector<int>> adjacent;
1862 for (
size_t i = 0;
i !=
source.boundary.size(); ++
i) {
1864 if (!before.count(face))
1865 THROW_MESSAGE(
"Protected triangle is not a source cell face");
1866 source_normals.push_back(normal(
source.boundary[
i]));
1867 for (
int a = 0;
a != 3; ++
a)
1868 for (
int b =
a + 1; b != 3; ++b)
1869 adjacent[{face[
a], face[b]}].push_back(
i);
1871 std::set<Edge> creases;
1872 for (
const auto &[edge, patch] : adjacent)
1873 if (patch.size() != 2 ||
1874 source.surfaceLabels[patch[0]] !=
source.surfaceLabels[patch[1]] ||
1875 before.at(
key(
source.boundary[patch[0]])) !=
1876 before.at(
key(
source.boundary[patch[1]])) ||
1877 !aligned(source_normals[patch[0]], source_normals[patch[1]]))
1878 creases.insert(edge);
1879 std::map<int, std::set<Face>> incident;
1880 std::set<Edge> result_edges;
1881 std::set<Face> exterior, covered_exterior;
1882 for (
const auto &[face, count] : after) {
1884 exterior.insert(face);
1885 for (
int i = 0;
i != 3; ++
i) {
1886 incident[face[
i]].insert(face);
1887 for (
int j =
i + 1;
j != 3; ++
j)
1888 result_edges.insert({face[
i], face[
j]});
1891 for (
auto edge : protected_edges)
1892 if (!result_edges.count(
key(edge)))
1894 "constrained recovery is required");
1895 for (
auto edge : creases)
1896 if (!result_edges.count(edge))
1897 THROW_MESSAGE(
"Reconstruction removes protected surface edge (" +
1898 std::to_string(
source.vertexIds[edge[0]]) +
"," +
1899 std::to_string(
source.vertexIds[edge[1]]) +
1900 ") at the requested surface flip angle");
1901 auto identity = [&](
int i) {
1902 auto face =
source.boundary[
i];
1903 for (
auto &
v : face)
1907 std::vector<bool> visited(
source.boundary.size(),
false);
1908 std::vector<Face> output;
1909 std::vector<int>
labels, parents;
1910 for (
size_t seed = 0; seed !=
source.boundary.size(); ++seed) {
1913 const int incidence = before.at(
key(
source.boundary[seed]));
1914 std::vector<int> patch{
static_cast<int>(seed)};
1915 visited[seed] =
true;
1916 for (
size_t i = 0;
i != patch.size(); ++
i) {
1917 const auto face =
key(
source.boundary[patch[
i]]);
1918 for (
int a = 0;
a != 3; ++
a)
1919 for (
int b =
a + 1; b != 3; ++b) {
1920 const Edge edge{face[
a], face[b]};
1921 if (!creases.count(edge))
1922 for (
int next : adjacent.at(edge))
1923 if (!visited[next]) {
1924 visited[next] =
true;
1925 patch.push_back(next);
1929 std::set<Face> original_faces,
selected;
1930 std::set<int>
vertices, selected_vertices;
1931 std::map<int, std::vector<int>> vertex_faces;
1932 for (
int i : patch) {
1933 const auto &face =
source.boundary[
i];
1934 original_faces.insert(
key(face));
1935 vertices.insert(face.begin(), face.end());
1937 vertex_faces[
v].push_back(
i);
1939 Triangles patch_triangles;
1940 for (
int i : patch) {
1941 const auto &
f =
source.boundary[
i];
1942 patch_triangles.emplace_back(point(
f[0]), point(
f[1]), point(
f[2]));
1944 const TriangleTree patch_tree(patch_triangles.cbegin(),
1945 patch_triangles.cend());
1946 std::set<Face> candidates;
1948 candidates.insert(incident[
v].begin(), incident[
v].
end());
1949 std::map<Face, Normal> normals;
1950 std::map<Face, int> carriers;
1951 for (
const auto &face : candidates) {
1952 if (after.at(face) != incidence ||
1953 !std::all_of(face.begin(), face.end(),
1954 [&](
int v) { return vertices.count(v); }))
1956 const auto n = normal(face);
1957 if (!std::all_of(face.begin(), face.end(), [&](
int v) {
1958 const auto &old = vertex_faces.at(v);
1959 return std::any_of(old.begin(), old.end(), [&](int i) {
1960 return aligned(n, source_normals[i]);
1964 const K::Point_3 center(
1965 (point(face[0]).x() / 3.) + (point(face[1]).x() / 3.) +
1966 (point(face[2]).x() / 3.),
1967 (point(face[0]).y() / 3.) + (point(face[1]).y() / 3.) +
1968 (point(face[2]).y() / 3.),
1969 (point(face[0]).z() / 3.) + (point(face[1]).z() / 3.) +
1970 (point(face[2]).z() / 3.));
1971 ClosestAlignedTriangle nearest{
1973 [&](
size_t i) {
return aligned(
n, source_normals[patch[
i]]); },
1974 [&](
size_t a,
size_t b) {
1975 return identity(patch[
a]) < identity(patch[b]);
1977 patch_tree.traversal(center, nearest);
1978 const int carrier = nearest.best == std::numeric_limits<size_t>::max()
1980 : patch[nearest.best];
1984 selected_vertices.insert(face.begin(), face.end());
1985 normals.emplace(face,
n);
1986 carriers.emplace(face, carrier);
1988 const auto original_topology =
topology(original_faces);
1989 bool disconnected_links =
false;
1991 auto check_patch = [&](
bool valid,
const std::string &message) {
1994 if (!disconnected_links)
1996 report_warning(message +
"; retaining " +
1998 " reconstructed triangles for a source patch of " +
1999 std::to_string(original_faces.size()) +
" triangles");
2001 check_patch(
vertices == selected_vertices &&
2002 original_topology == selected_topology,
2003 "Reconstruction changes protected surface nodes, boundary or "
2004 "topology at the requested flip angle");
2005 std::set<Edge> old_edges;
2006 for (
auto face : original_faces)
2007 for (
int i = 0;
i != 3; ++
i)
2008 for (
int j =
i + 1;
j != 3; ++
j)
2009 old_edges.insert({face[
i], face[
j]});
2010 std::map<Edge, std::vector<Face>> new_edges;
2012 for (
int i = 0;
i != 3; ++
i)
2013 for (
int j =
i + 1;
j != 3; ++
j)
2014 new_edges[{face[
i], face[
j]}].push_back(face);
2015 for (
const auto &edge : old_edges)
2016 check_patch(!creases.count(edge) || new_edges.count(edge),
2017 "Reconstruction removes a protected crease from its surface");
2018 for (
auto edge : protected_edges)
2019 check_patch(!old_edges.count(
key(edge)) || new_edges.count(
key(edge)),
2020 "Reconstruction removes a protected curve from its surface");
2021 for (
const auto &[edge, pair] : new_edges)
2022 if (!old_edges.count(edge) && pair.
size() == 2 &&
2023 !aligned(normals.at(pair[0]), normals.at(pair[1])))
2025 "A new surface diagonal exceeds the requested flip angle");
2028 covered_exterior.insert(face);
2029 const int carrier = carriers.at(face);
2030 if (dot(normals.at(face), source_normals[carrier]) < 0)
2031 std::swap(face[1], face[2]);
2032 output.push_back(face);
2034 parents.push_back(carrier);
2037 if (exterior != covered_exterior)
2038 THROW_MESSAGE(
"Reconstruction changes the protected domain boundary");
2039 result.boundary = std::move(output);
2044std::vector<std::uint64_t>
2045CGALTools::findVertexParents(
const std::vector<std::array<double, 3>> &
points,
2046 const std::vector<Simplex> &sources)
const {
2048 using Point = Kernel::Point_3;
2049 auto point = [](
const std::array<double, 3> &x) {
2050 if (!std::isfinite(x[0]) || !std::isfinite(x[1]) || !std::isfinite(x[2]))
2051 THROW_MESSAGE(
"Parent classification requires finite coordinates");
2052 return Point(x[0], x[1], x[2]);
2054 std::vector<std::vector<Point>>
vertices;
2055 std::set<std::uint64_t> identifiers;
2056 for (
const auto &
source : sources) {
2057 if (!
source.identifier || !identifiers.insert(
source.identifier).second ||
2058 source.vertices.size() < 2 ||
source.vertices.size() > 4)
2061 for (
const auto &
v :
source.vertices)
2062 x.push_back(point(
v));
2063 const bool degenerate =
2064 x.size() == 2 ? Kernel::Segment_3(x[0], x[1]).is_degenerate()
2066 ? Kernel::Triangle_3(x[0], x[1], x[2]).is_degenerate()
2067 : Kernel::Tetrahedron_3(x[0], x[1], x[2], x[3]).is_degenerate();
2069 THROW_MESSAGE(
"Cannot classify against a degenerate source simplex");
2072 using Box = CGAL::Box_intersection_d::Box_with_info_d<double, 3, size_t>;
2073 std::vector<Box> source_boxes, point_boxes;
2077 box = box +
v.bbox();
2078 source_boxes.emplace_back(box,
i);
2080 for (
size_t i = 0;
i !=
points.size(); ++
i)
2081 point_boxes.emplace_back(point(
points[
i]).bbox(),
i);
2082 std::vector<std::vector<size_t>> candidates(
points.size());
2083 CGAL::box_intersection_d(point_boxes.begin(), point_boxes.end(),
2084 source_boxes.begin(), source_boxes.end(),
2085 [&](
const Box &query,
const Box &
source) {
2086 candidates[query.info()].push_back(source.info());
2088 std::vector<std::uint64_t> parents;
2089 parents.reserve(
points.size());
2090 for (
size_t i = 0;
i !=
points.size(); ++
i) {
2091 const auto p = point(
points[
i]);
2092 size_t dimension = 4;
2093 std::uint64_t
parent = 0;
2094 bool ambiguous =
false;
2095 for (
size_t n : candidates[
i]) {
2097 if (x.size() - 1 > dimension)
2099 const bool contains =
2100 x.size() == 2 ? Kernel::Segment_3(x[0], x[1]).has_on(p)
2102 ? Kernel::Triangle_3(x[0], x[1], x[2]).has_on(p)
2103 : Kernel::Tetrahedron_3(x[0], x[1], x[2], x[3]).bounded_side(p) !=
2104 CGAL::ON_UNBOUNDED_SIDE;
2107 if (x.size() - 1 < dimension) {
2108 dimension = x.size() - 1;
2109 parent = sources[
n].identifier;
2115 if (!
parent || ambiguous)
2116 THROW_MESSAGE(ambiguous ?
"Ambiguous source parent for vertex"
2117 :
"Vertex lies outside the source mesh");
2118 parents.push_back(
parent);
2123void CGALTools::createDelaunay(
2125 const std::vector<std::uint64_t> &identifiers)
const {
2126 if (!identifiers.empty() && identifiers.size() !=
points.size())
2130 std::set<std::uint64_t> used_ids;
2131 for (
size_t n = 0;
n !=
points.size(); ++
n) {
2133 if (!std::isfinite(p[0]) || !std::isfinite(p[1]) || !std::isfinite(p[2]))
2135 const auto id = identifiers.empty() ? 0 : identifiers[
n];
2136 if (
id && !used_ids.insert(
id).second)
2138 const auto count =
result.tr.number_of_vertices();
2139 auto vertex =
result.tr.insert(CGALMesh::Kernel::Point_3(p[0], p[1], p[2]));
2140 if (
result.tr.number_of_vertices() == count)
2141 THROW_MESSAGE(
"Coincident CGAL points cannot retain distinct identities");
2142 vertex->moabHandle = id;
Opt-in CGAL types; not included by MoFEM.hpp.
std::map< EntityHandle, int > labels
std::map< EntityHandle, int > index
std::vector< std::array< EntityHandle, 3 > > faces
Sorted keys.
std::vector< std::array< EntityHandle, 2 > > curves
Sorted keys.
std::vector< int > source
const Settings & settings
const std::vector< Vec > * points
std::vector< int > polygon
std::vector< int > vertices
Vec t
Removal: the ring edge.
std::vector< int > parent
std::unordered_map< int, NodeConstraint > constraints
std::vector< Cell > cells
int components
Inferred from the source tag length.
std::map< EntityHandle, std::pair< bool, std::vector< double > > > previous
std::vector< double > empty
One value per component.
std::vector< std::array< double, 3 > > coordinates
SmartPetscObj< Vec > values
void simple(double P1[], double P2[], double P3[], double c[], const int N)
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
FTensor::Index< 'i', SPACE_DIM > i
const double c
speed of light (cm/ns)
const double v
phase velocity of light in medium (cm/ns)
FTensor::Index< 'j', 3 > j
implementation of Data Operators for Forces and Sources
double constraint(double eqiv, double dot_tau, double f, double sigma_y, double abs_w, double vis_H, double sigma_Y)
static constexpr double delta
CGAL::Exact_predicates_inexact_constructions_kernel Kernel
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static bool checkIfChannelExist(const std::string channel)
Check if channel exist.
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.
std::vector< int > partitions
Optional cell-to-rank assignment.
std::vector< std::array< int, 3 > > boundary
std::vector< std::array< int, 2 > > featureEdges
std::vector< int > edgeLabels
std::vector< int > cellLabels
std::vector< std::array< int, 4 > > cells
Zero-based point indices.
std::vector< std::array< double, 3 > > points
std::vector< int > vertexIds
std::vector< int > surfaceLabels
std::vector< int > fixedVertices
Point indices which cannot move or collapse.