210 assert(M.vertices.dimension() == 3);
213 const int nv = M.vertices.nb();
216 for (
int i = 0; i < nv; ++i)
227 if (M.cells.nb() == 0)
230 bool last_isolated =
true;
234 for (
int i = 0; i < (int)M.facets.nb(); ++i)
239 face.
vs.resize(M.facets.nb_vertices(i));
240 for (
int j = 0; j < (int)M.facets.nb_vertices(i); ++j)
242 face.
vs[j] = M.facets.vertex(i, j);
243 if ((
int)face.
vs[j] == nv - 1)
245 last_isolated =
false;
252 for (
int i = 0; i < 1; ++i)
257 int nf = M.facets.nb();
260 for (
int j = 0; j < nf; ++j)
265 for (
auto fid : cell.
fs)
269 sort(cell.
vs.begin(), cell.
vs.end());
270 cell.
vs.erase(unique(cell.
vs.begin(), cell.
vs.end()), cell.
vs.end());
272 for (
int j = 0; j < nf; ++j)
279 cell.
v_in_Kernel.push_back(M.vertices.point(nv - 1)[0]);
280 cell.
v_in_Kernel.push_back(M.vertices.point(nv - 1)[1]);
281 cell.
v_in_Kernel.push_back(M.vertices.point(nv - 1)[2]);
286 Eigen::RowVector3d p(0, 0, 0);
287 for (
int v : cell.
vs)
298 for (
int i = 0; i < 1; ++i)
322 auto opposite_cell_facet = [&M](
int c,
int cf) {
323 GEO::index_t c2 = M.cell_facets.adjacent_cell(cf);
324 if (c2 == GEO::NO_FACET)
328 for (
int lf = 0; lf < (int)M.cells.nb_facets(c2); ++lf)
330 if (c == (
int)M.cells.adjacent(c2, lf))
332 return (
int)M.cells.facet(c2, lf);
339 std::vector<int> cell_facet_to_facet(M.cell_facets.nb(), -1);
342 int facet_counter = 0;
345 for (
int c = 0; c < (int)M.cells.nb(); ++c)
349 cell.
hex = (M.cells.type(c) == GEO::MESH_HEX);
351 is_hex = is_hex && cell.
hex;
353 int nf = M.cells.nb_facets(c);
356 for (
int lf = 0; lf < nf; ++lf)
358 int cf = M.cells.facet(c, lf);
359 int cf2 = opposite_cell_facet(c, cf);
360 if (cf2 < 0 || cell_facet_to_facet[cf2] < 0)
364 assert(face.
vs.empty());
365 face.
vs.resize(M.cells.facet_nb_vertices(c, lf));
366 for (
int lv = 0; lv < (int)M.cells.facet_nb_vertices(c, lf); ++lv)
368 face.
vs[lv] = M.cells.facet_vertex(c, lf, lv);
371 cell.
fs[lf] = face.
id = facet_counter;
372 cell_facet_to_facet[cf] = facet_counter;
377 cell.
fs[lf] = cell_facet_to_facet[cf2];
382 for (
auto fid : cell.
fs)
386 sort(cell.
vs.begin(), cell.
vs.end());
387 cell.
vs.erase(unique(cell.
vs.begin(), cell.
vs.end()), cell.
vs.end());
390 Eigen::RowVector3d p(0, 0, 0);
391 for (
int v : cell.
vs)
522 const auto attach_p2 = [&](
const Navigation3D::Index &index,
const std::vector<int> &nodes_ids) {
525 if (n.nodes.size() > 0)
531 const int n_v1 = index.
vertex;
536 if ((n_v1 == nodes_ids[0] && n_v2 == nodes_ids[1]) || (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[1]))
538 else if ((n_v1 == nodes_ids[1] && n_v2 == nodes_ids[2]) || (n_v2 == nodes_ids[1] && n_v1 == nodes_ids[2]))
540 else if ((n_v1 == nodes_ids[2] && n_v2 == nodes_ids[3]) || (n_v2 == nodes_ids[2] && n_v1 == nodes_ids[3]))
543 else if ((n_v1 == nodes_ids[0] && n_v2 == nodes_ids[3]) || (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[3]))
545 else if ((n_v1 == nodes_ids[0] && n_v2 == nodes_ids[2]) || (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[2]))
550 n.nodes.resize(1, 3);
551 n.nodes <<
V(nodes_ids[node_index], 0),
V(nodes_ids[node_index], 1),
V(nodes_ids[node_index], 2);
552 n.nodes_ids.push_back(nodes_ids[node_index]);
555 const auto attach_p3 = [&](
const Navigation3D::Index &index,
const std::vector<int> &nodes_ids) {
558 if (n.nodes.size() > 0)
564 const int n_v1 = index.
vertex;
569 if (n_v1 == nodes_ids[0] && n_v2 == nodes_ids[1])
574 else if (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[1])
579 else if (n_v1 == nodes_ids[1] && n_v2 == nodes_ids[2])
584 else if (n_v2 == nodes_ids[1] && n_v1 == nodes_ids[2])
589 else if (n_v1 == nodes_ids[2] && n_v2 == nodes_ids[3])
594 else if (n_v2 == nodes_ids[2] && n_v1 == nodes_ids[3])
600 else if (n_v1 == nodes_ids[0] && n_v2 == nodes_ids[3])
605 else if (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[3])
610 else if (n_v1 == nodes_ids[0] && n_v2 == nodes_ids[2])
615 else if (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[2])
621 else if (n_v2 == nodes_ids[1] && n_v1 == nodes_ids[3])
632 n.nodes.resize(2, 3);
633 n.nodes.row(0) <<
V(nodes_ids[node_index1], 0),
V(nodes_ids[node_index1], 1),
V(nodes_ids[node_index1], 2);
634 n.nodes.row(1) <<
V(nodes_ids[node_index2], 0),
V(nodes_ids[node_index2], 1),
V(nodes_ids[node_index2], 2);
635 n.nodes_ids.push_back(nodes_ids[node_index1]);
636 n.nodes_ids.push_back(nodes_ids[node_index2]);
639 const auto attach_p3_face = [&](
const Navigation3D::Index &index,
const std::vector<int> &nodes_ids,
int id) {
641 if (n.nodes.size() <= 0)
646 n.nodes.resize(1, 3);
647 n.nodes <<
V(nodes_ids[
id], 0),
V(nodes_ids[
id], 1),
V(nodes_ids[
id], 2);
648 n.nodes_ids.push_back(nodes_ids[
id]);
652 const auto attach_p4 = [&](
const Navigation3D::Index &index,
const std::vector<int> &nodes_ids) {
655 if (n.nodes.size() > 0)
661 const int n_v1 = index.
vertex;
667 if (n_v1 == nodes_ids[0] && n_v2 == nodes_ids[1])
673 else if (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[1])
680 else if (n_v1 == nodes_ids[1] && n_v2 == nodes_ids[2])
686 else if (n_v2 == nodes_ids[1] && n_v1 == nodes_ids[2])
693 else if (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[2])
699 else if (n_v1 == nodes_ids[0] && n_v2 == nodes_ids[2])
706 else if (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[3])
712 else if (n_v1 == nodes_ids[0] && n_v2 == nodes_ids[3])
719 else if (n_v2 == nodes_ids[2] && n_v1 == nodes_ids[3])
725 else if (n_v1 == nodes_ids[2] && n_v2 == nodes_ids[3])
732 else if (n_v2 == nodes_ids[1] && n_v1 == nodes_ids[3])
738 else if (n_v1 == nodes_ids[1] && n_v2 == nodes_ids[3])
749 n.nodes.resize(3, 3);
750 n.nodes.row(0) <<
V(nodes_ids[node_index1], 0),
V(nodes_ids[node_index1], 1),
V(nodes_ids[node_index1], 2);
751 n.nodes.row(1) <<
V(nodes_ids[node_index2], 0),
V(nodes_ids[node_index2], 1),
V(nodes_ids[node_index2], 2);
752 n.nodes.row(2) <<
V(nodes_ids[node_index3], 0),
V(nodes_ids[node_index3], 1),
V(nodes_ids[node_index3], 2);
753 n.nodes_ids.push_back(nodes_ids[node_index1]);
754 n.nodes_ids.push_back(nodes_ids[node_index2]);
755 n.nodes_ids.push_back(nodes_ids[node_index3]);
758 const auto attach_p4_face = [&](
const Navigation3D::Index &index,
const std::vector<int> &nodes_ids) {
760 if (n.nodes.size() <= 0)
766 std::array<int, 3> vid = {{n.v1, n.v2, n.v3}};
767 std::sort(vid.begin(), vid.end());
769 std::array<int, 3> c1 = {{nodes_ids[0], nodes_ids[1], nodes_ids[2]}};
770 std::array<int, 3> c2 = {{nodes_ids[0], nodes_ids[1], nodes_ids[3]}};
771 std::array<int, 3> c3 = {{nodes_ids[0], nodes_ids[2], nodes_ids[3]}};
772 std::array<int, 3> c4 = {{nodes_ids[1], nodes_ids[2], nodes_ids[3]}};
774 std::sort(c1.begin(), c1.end());
775 std::sort(c2.begin(), c2.end());
776 std::sort(c3.begin(), c3.end());
777 std::sort(c4.begin(), c4.end());
833 n.nodes.resize(3, 3);
834 assert(
id + index0 < nodes_ids.size());
835 assert(
id + index1 < nodes_ids.size());
836 assert(
id + index2 < nodes_ids.size());
837 n.nodes.row(0) <<
V(nodes_ids[
id + index0], 0),
V(nodes_ids[
id + index0], 1),
V(nodes_ids[
id + index0], 2);
838 n.nodes.row(1) <<
V(nodes_ids[
id + index1], 0),
V(nodes_ids[
id + index1], 1),
V(nodes_ids[
id + index1], 2);
839 n.nodes.row(2) <<
V(nodes_ids[
id + index2], 0),
V(nodes_ids[
id + index2], 1),
V(nodes_ids[
id + index2], 2);
840 n.nodes_ids.push_back(nodes_ids[
id + index0]);
841 n.nodes_ids.push_back(nodes_ids[
id + index1]);
842 n.nodes_ids.push_back(nodes_ids[
id + index2]);
846 const auto attach_p4_cell = [&](
const Navigation3D::Index &index,
const std::vector<int> &nodes_ids) {
848 assert(nodes_ids.size() == 35);
849 assert(n.nodes.size() == 0);
851 if (n.nodes.size() <= 0)
857 n.nodes.resize(1, 3);
859 n.nodes <<
V(nodes_ids[34], 0),
V(nodes_ids[34], 1),
V(nodes_ids[34], 2);
860 n.nodes_ids.push_back(nodes_ids[34]);
864 assert(nodes.size() ==
n_cells());
866 for (
int c = 0; c <
n_cells(); ++c)
870 const auto &nodes_ids = nodes[c];
872 if (nodes_ids.size() == 4)
878 else if (nodes_ids.size() == 10)
882 for (
int le = 0; le < 3; ++le)
884 attach_p2(index, nodes_ids);
889 attach_p2(index, nodes_ids);
892 attach_p2(index, nodes_ids);
895 attach_p2(index, nodes_ids);
898 else if (nodes_ids.size() == 20)
902 for (
int le = 0; le < 3; ++le)
904 attach_p3(index, nodes_ids);
910 attach_p3(index, nodes_ids);
913 attach_p3(index, nodes_ids);
916 attach_p3(index, nodes_ids);
921 std::array<int, 4> indices;
924 std::array<int, 3> f16 = {{nodes_ids[0], nodes_ids[1], nodes_ids[2]}};
925 std::array<int, 3> f17 = {{nodes_ids[3], nodes_ids[1], nodes_ids[0]}};
926 std::array<int, 3> f18 = {{nodes_ids[0], nodes_ids[2], nodes_ids[3]}};
927 std::array<int, 3> f19 = {{nodes_ids[1], nodes_ids[2], nodes_ids[3]}};
928 std::sort(f16.begin(), f16.end());
929 std::sort(f17.begin(), f17.end());
930 std::sort(f18.begin(), f18.end());
931 std::sort(f19.begin(), f19.end());
942 std::sort(f0.begin(), f0.end());
943 std::sort(f1.begin(), f1.end());
944 std::sort(f2.begin(), f2.end());
945 std::sort(f3.begin(), f3.end());
947 const std::array<std::array<int, 3>, 4>
faces = {{f0, f1, f2, f3}};
948 const std::array<std::array<int, 3>, 4> nodes = {{f16, f17, f18, f19}};
949 for (
int i = 0; i < 4; ++i)
951 const auto &f =
faces[i];
953 for (
int j = 0; j < 4; ++j)
967 attach_p3_face(index, nodes_ids, indices[0]);
968 attach_p3_face(
switch_face(index), nodes_ids, indices[1]);
974 else if (nodes_ids.size() == 35)
977 for (
int le = 0; le < 3; ++le)
979 attach_p4(index, nodes_ids);
985 attach_p4(index, nodes_ids);
988 attach_p4(index, nodes_ids);
991 attach_p4(index, nodes_ids);
997 attach_p4_face(index, nodes_ids);