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)
332 if (c == (
int)M.cells.adjacent(c2, lf))
334 return (
int)M.cells.facet(c2, lf);
341 std::vector<int> cell_facet_to_facet(M.cell_facets.nb(), -1);
344 int facet_counter = 0;
347 for (
int c = 0; c < (int)M.cells.nb(); ++c)
351 cell.
hex = (M.cells.type(c) == GEO::MESH_HEX);
353 is_hex = is_hex && cell.
hex;
355 int nf = M.cells.nb_facets(c);
358 for (
int lf = 0; lf < nf; ++lf)
360 int cf = M.cells.facet(c, lf);
361 int cf2 = opposite_cell_facet(c, cf);
364 if (cf2 < 0 || cell_facet_to_facet[cf2] < 0)
369 assert(face.
vs.empty());
370 face.
vs.resize(M.cells.facet_nb_vertices(c, lf));
371 for (
int lv = 0; lv < (int)M.cells.facet_nb_vertices(c, lf); ++lv)
373 face.
vs[lv] = M.cells.facet_vertex(c, lf, lv);
376 cell.
fs[lf] = face.
id = facet_counter;
377 cell_facet_to_facet[cf] = facet_counter;
382 cell.
fs[lf] = cell_facet_to_facet[cf2];
387 for (
auto fid : cell.
fs)
391 sort(cell.
vs.begin(), cell.
vs.end());
392 cell.
vs.erase(unique(cell.
vs.begin(), cell.
vs.end()), cell.
vs.end());
395 Eigen::RowVector3d p(0, 0, 0);
396 for (
int v : cell.
vs)
524 const auto attach_p2 = [&](
const Navigation3D::Index &index,
const std::vector<int> &nodes_ids) {
527 if (n.nodes.size() > 0)
533 const int n_v1 = index.
vertex;
538 if ((n_v1 == nodes_ids[0] && n_v2 == nodes_ids[1]) || (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[1]))
540 else if ((n_v1 == nodes_ids[1] && n_v2 == nodes_ids[2]) || (n_v2 == nodes_ids[1] && n_v1 == nodes_ids[2]))
542 else if ((n_v1 == nodes_ids[2] && n_v2 == nodes_ids[3]) || (n_v2 == nodes_ids[2] && n_v1 == nodes_ids[3]))
545 else if ((n_v1 == nodes_ids[0] && n_v2 == nodes_ids[3]) || (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[3]))
547 else if ((n_v1 == nodes_ids[0] && n_v2 == nodes_ids[2]) || (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[2]))
552 n.nodes.resize(1, 3);
553 n.nodes <<
V(nodes_ids[node_index], 0),
V(nodes_ids[node_index], 1),
V(nodes_ids[node_index], 2);
554 n.nodes_ids.push_back(nodes_ids[node_index]);
557 const auto attach_p3 = [&](
const Navigation3D::Index &index,
const std::vector<int> &nodes_ids) {
560 if (n.nodes.size() > 0)
566 const int n_v1 = index.
vertex;
571 if (n_v1 == nodes_ids[0] && n_v2 == nodes_ids[1])
576 else if (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[1])
581 else if (n_v1 == nodes_ids[1] && n_v2 == nodes_ids[2])
586 else if (n_v2 == nodes_ids[1] && n_v1 == nodes_ids[2])
591 else if (n_v1 == nodes_ids[2] && n_v2 == nodes_ids[3])
596 else if (n_v2 == nodes_ids[2] && n_v1 == nodes_ids[3])
602 else if (n_v1 == nodes_ids[0] && n_v2 == nodes_ids[3])
607 else if (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[3])
612 else if (n_v1 == nodes_ids[0] && n_v2 == nodes_ids[2])
617 else if (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[2])
623 else if (n_v2 == nodes_ids[1] && n_v1 == nodes_ids[3])
634 n.nodes.resize(2, 3);
635 n.nodes.row(0) <<
V(nodes_ids[node_index1], 0),
V(nodes_ids[node_index1], 1),
V(nodes_ids[node_index1], 2);
636 n.nodes.row(1) <<
V(nodes_ids[node_index2], 0),
V(nodes_ids[node_index2], 1),
V(nodes_ids[node_index2], 2);
637 n.nodes_ids.push_back(nodes_ids[node_index1]);
638 n.nodes_ids.push_back(nodes_ids[node_index2]);
641 const auto attach_p3_face = [&](
const Navigation3D::Index &index,
const std::vector<int> &nodes_ids,
int id) {
643 if (n.nodes.size() <= 0)
648 n.nodes.resize(1, 3);
649 n.nodes <<
V(nodes_ids[
id], 0),
V(nodes_ids[
id], 1),
V(nodes_ids[
id], 2);
650 n.nodes_ids.push_back(nodes_ids[
id]);
654 const auto attach_p4 = [&](
const Navigation3D::Index &index,
const std::vector<int> &nodes_ids) {
657 if (n.nodes.size() > 0)
663 const int n_v1 = index.
vertex;
669 if (n_v1 == nodes_ids[0] && n_v2 == nodes_ids[1])
675 else if (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[1])
682 else if (n_v1 == nodes_ids[1] && n_v2 == nodes_ids[2])
688 else if (n_v2 == nodes_ids[1] && n_v1 == nodes_ids[2])
695 else if (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[2])
701 else if (n_v1 == nodes_ids[0] && n_v2 == nodes_ids[2])
708 else if (n_v2 == nodes_ids[0] && n_v1 == nodes_ids[3])
714 else if (n_v1 == nodes_ids[0] && n_v2 == nodes_ids[3])
721 else if (n_v2 == nodes_ids[2] && n_v1 == nodes_ids[3])
727 else if (n_v1 == nodes_ids[2] && n_v2 == nodes_ids[3])
734 else if (n_v2 == nodes_ids[1] && n_v1 == nodes_ids[3])
740 else if (n_v1 == nodes_ids[1] && n_v2 == nodes_ids[3])
751 n.nodes.resize(3, 3);
752 n.nodes.row(0) <<
V(nodes_ids[node_index1], 0),
V(nodes_ids[node_index1], 1),
V(nodes_ids[node_index1], 2);
753 n.nodes.row(1) <<
V(nodes_ids[node_index2], 0),
V(nodes_ids[node_index2], 1),
V(nodes_ids[node_index2], 2);
754 n.nodes.row(2) <<
V(nodes_ids[node_index3], 0),
V(nodes_ids[node_index3], 1),
V(nodes_ids[node_index3], 2);
755 n.nodes_ids.push_back(nodes_ids[node_index1]);
756 n.nodes_ids.push_back(nodes_ids[node_index2]);
757 n.nodes_ids.push_back(nodes_ids[node_index3]);
760 const auto attach_p4_face = [&](
const Navigation3D::Index &index,
const std::vector<int> &nodes_ids) {
762 if (n.nodes.size() <= 0)
768 std::array<int, 3> vid = {{n.v1, n.v2, n.v3}};
769 std::sort(vid.begin(), vid.end());
771 std::array<int, 3> c1 = {{nodes_ids[0], nodes_ids[1], nodes_ids[2]}};
772 std::array<int, 3> c2 = {{nodes_ids[0], nodes_ids[1], nodes_ids[3]}};
773 std::array<int, 3> c3 = {{nodes_ids[0], nodes_ids[2], nodes_ids[3]}};
774 std::array<int, 3> c4 = {{nodes_ids[1], nodes_ids[2], nodes_ids[3]}};
776 std::sort(c1.begin(), c1.end());
777 std::sort(c2.begin(), c2.end());
778 std::sort(c3.begin(), c3.end());
779 std::sort(c4.begin(), c4.end());
835 n.nodes.resize(3, 3);
836 assert(
id + index0 < nodes_ids.size());
837 assert(
id + index1 < nodes_ids.size());
838 assert(
id + index2 < nodes_ids.size());
839 n.nodes.row(0) <<
V(nodes_ids[
id + index0], 0),
V(nodes_ids[
id + index0], 1),
V(nodes_ids[
id + index0], 2);
840 n.nodes.row(1) <<
V(nodes_ids[
id + index1], 0),
V(nodes_ids[
id + index1], 1),
V(nodes_ids[
id + index1], 2);
841 n.nodes.row(2) <<
V(nodes_ids[
id + index2], 0),
V(nodes_ids[
id + index2], 1),
V(nodes_ids[
id + index2], 2);
842 n.nodes_ids.push_back(nodes_ids[
id + index0]);
843 n.nodes_ids.push_back(nodes_ids[
id + index1]);
844 n.nodes_ids.push_back(nodes_ids[
id + index2]);
848 const auto attach_p4_cell = [&](
const Navigation3D::Index &index,
const std::vector<int> &nodes_ids) {
850 assert(nodes_ids.size() == 35);
851 assert(n.nodes.size() == 0);
853 if (n.nodes.size() <= 0)
859 n.nodes.resize(1, 3);
861 n.nodes <<
V(nodes_ids[34], 0),
V(nodes_ids[34], 1),
V(nodes_ids[34], 2);
862 n.nodes_ids.push_back(nodes_ids[34]);
866 assert(nodes.size() ==
n_cells());
868 for (
int c = 0; c <
n_cells(); ++c)
872 const auto &nodes_ids = nodes[c];
874 if (nodes_ids.size() == 4)
880 else if (nodes_ids.size() == 10)
884 for (
int le = 0; le < 3; ++le)
886 attach_p2(index, nodes_ids);
891 attach_p2(index, nodes_ids);
894 attach_p2(index, nodes_ids);
897 attach_p2(index, nodes_ids);
900 else if (nodes_ids.size() == 20)
904 for (
int le = 0; le < 3; ++le)
906 attach_p3(index, nodes_ids);
912 attach_p3(index, nodes_ids);
915 attach_p3(index, nodes_ids);
918 attach_p3(index, nodes_ids);
923 std::array<int, 4> indices;
926 std::array<int, 3> f16 = {{nodes_ids[0], nodes_ids[1], nodes_ids[2]}};
927 std::array<int, 3> f17 = {{nodes_ids[3], nodes_ids[1], nodes_ids[0]}};
928 std::array<int, 3> f18 = {{nodes_ids[0], nodes_ids[2], nodes_ids[3]}};
929 std::array<int, 3> f19 = {{nodes_ids[1], nodes_ids[2], nodes_ids[3]}};
930 std::sort(f16.begin(), f16.end());
931 std::sort(f17.begin(), f17.end());
932 std::sort(f18.begin(), f18.end());
933 std::sort(f19.begin(), f19.end());
944 std::sort(f0.begin(), f0.end());
945 std::sort(f1.begin(), f1.end());
946 std::sort(f2.begin(), f2.end());
947 std::sort(f3.begin(), f3.end());
949 const std::array<std::array<int, 3>, 4>
faces = {{f0, f1, f2, f3}};
950 const std::array<std::array<int, 3>, 4> nodes = {{f16, f17, f18, f19}};
951 for (
int i = 0; i < 4; ++i)
953 const auto &f =
faces[i];
955 for (
int j = 0; j < 4; ++j)
969 attach_p3_face(index, nodes_ids, indices[0]);
970 attach_p3_face(
switch_face(index), nodes_ids, indices[1]);
976 else if (nodes_ids.size() == 35)
979 for (
int le = 0; le < 3; ++le)
981 attach_p4(index, nodes_ids);
987 attach_p4(index, nodes_ids);
990 attach_p4(index, nodes_ids);
993 attach_p4(index, nodes_ids);
999 attach_p4_face(index, nodes_ids);