PolyFEM
Loading...
Searching...
No Matches
MeshUtils.cpp
Go to the documentation of this file.
1
2#include "MeshUtils.hpp"
3
5
11
12#include <unordered_set>
13#include <set>
14#include <tuple>
15#include <numeric>
16#include <array>
17#include <cmath>
18#include <limits>
19
20#include <igl/PI.h>
21#include <Eigen/Geometry>
23
24using namespace polyfem::utils;
25
26bool polyfem::mesh::is_planar(const Eigen::MatrixXd &V, const double tol)
27{
28 if (V.cols() == 2)
29 return true;
30
31 assert(V.cols() == 3);
32 if (V.rows() == 0)
33 return false;
34 const double diff = V.col(2).maxCoeff() - V.col(2).minCoeff();
35
36 return fabs(diff) < tol;
37}
38
40{
41 return M.point(v);
42}
43
44// -----------------------------------------------------------------------------
45
47{
48 PolygonMesh::Point p(0, 0, 0);
49 for (int lv = 0; lv < M.n_facet_vertices(f); ++lv)
50 {
51 p += polyfem::mesh::mesh_vertex(M, M.facet_vertex(f, lv));
52 }
53 return p / double(M.n_facet_vertices(f));
54}
55
56// -----------------------------------------------------------------------------
57
59{
60 return M.create_vertex(p);
61}
62
64
65void polyfem::mesh::compute_element_tags(const PolygonMesh &M, std::vector<ElementType> &element_tags)
66{
67 using index_t = int;
68
69 std::vector<ElementType> old_tags = element_tags;
70
71 element_tags.resize(M.n_facets());
72
73 // Step 0: Compute boundary vertices as true boundary + vertices incident to a polygon
74 const std::vector<bool> &is_boundary_vertex = M.boundary_vertex;
75 std::vector<bool> is_interface_vertex(M.n_vertices(), false);
76 {
77 for (index_t f = 0; f < M.n_facets(); ++f)
78 {
79 if (M.n_facet_vertices(f) != 4 || (!old_tags.empty() && old_tags[f] == ElementType::INTERIOR_POLYTOPE))
80 {
81 // Vertices incident to polygonal facets (triangles or > 4 vertices) are marked as interface
82 for (index_t lv = 0; lv < M.n_facet_vertices(f); ++lv)
83 {
84 is_interface_vertex[M.facet_vertex(f, lv)] = true;
85 }
86 }
87 }
88 }
89
90 // Step 1: Determine which vertices are regular or not
91 //
92 // Interior vertices are regular if they are incident to exactly 4 quads
93 // Boundary vertices are regular if they are incident to at most 2 quads, and no other facets
94 std::vector<int> degree(M.n_vertices(), 0);
95 std::vector<bool> is_regular_vertex(M.n_vertices());
96 for (index_t f = 0; f < M.n_facets(); ++f)
97 {
98 if (M.n_facet_vertices(f) == 4)
99 {
100 // Only count incident quads for the degree
101 for (index_t lv = 0; lv < M.n_facet_vertices(f); ++lv)
102 {
103 index_t v = M.facet_vertex(f, lv);
104 degree[v]++;
105 }
106 }
107 }
108 for (index_t v = 0; v < M.n_vertices(); ++v)
109 {
110 // assert(degree[v] > 0); // We assume there are no isolated vertices here
111 if (is_boundary_vertex[v] || is_interface_vertex[v])
112 {
113 is_regular_vertex[v] = (degree[v] <= 2);
114 }
115 else
116 {
117 is_regular_vertex[v] = (degree[v] == 4);
118 }
119 }
120
121 // Step 2: Iterate over the facets and determine the type
122 for (index_t f = 0; f < M.n_facets(); ++f)
123 {
124 assert(M.n_facet_vertices(f) > 2);
125 if (!old_tags.empty() && old_tags[f] == ElementType::INTERIOR_POLYTOPE)
126 continue;
127
128 if (M.n_facet_vertices(f) == 4)
129 {
130 // Quad facet
131
132 // a) Determine if it is on the mesh boundary
133 bool is_boundary_facet = false;
134 bool is_interface_facet = false;
135 for (index_t lv = 0; lv < M.n_facet_vertices(f); ++lv)
136 {
137 if (is_boundary_vertex[M.facet_vertex(f, lv)])
138 {
139 is_boundary_facet = true;
140 }
141 if (is_interface_vertex[M.facet_vertex(f, lv)])
142 {
143 is_interface_facet = true;
144 }
145 }
146
147 // b) Determine if it is regular or not
148 if (is_boundary_facet || is_interface_facet)
149 {
150 // A boundary quad is regular iff its boundary vertices are incident to
151 // at most 2 quads and its interior vertices to exactly 4; otherwise it
152 // is singular (still a cube, but not spline compatible).
153 bool is_singular = false;
154 for (index_t lv = 0; lv < M.n_facet_vertices(f); ++lv)
155 {
156 if (!is_regular_vertex[M.facet_vertex(f, lv)])
157 {
158 is_singular = true;
159 break;
160 }
161 }
162
163 if (is_interface_facet)
164 {
165 element_tags[f] = ElementType::INTERFACE_CUBE;
166 }
167 else if (is_singular)
168 {
169 element_tags[f] = ElementType::SIMPLE_SINGULAR_BOUNDARY_CUBE;
170 }
171 else
172 {
173 element_tags[f] = ElementType::REGULAR_BOUNDARY_CUBE;
174 }
175 }
176 else
177 {
178 // An interior quad is regular if all its vertices are singular
179 int nb_singulars = 0;
180 for (index_t lv = 0; lv < M.n_facet_vertices(f); ++lv)
181 {
182 if (!is_regular_vertex[M.facet_vertex(f, lv)])
183 {
184 ++nb_singulars;
185 }
186 }
187
188 if (nb_singulars == 0)
189 {
190 element_tags[f] = ElementType::REGULAR_INTERIOR_CUBE;
191 }
192 else if (nb_singulars == 1)
193 {
194 element_tags[f] = ElementType::SIMPLE_SINGULAR_INTERIOR_CUBE;
195 }
196 else
197 {
198 element_tags[f] = ElementType::MULTI_SINGULAR_INTERIOR_CUBE;
199 }
200 }
201 }
202 else
203 {
204 // Polygonal facet
205
206 // Note: In this function, we consider triangles as polygonal facets
207 ElementType tag = ElementType::INTERIOR_POLYTOPE;
208 const std::vector<bool> &boundary_vertices = M.boundary_vertex;
209 for (index_t lv = 0; lv < M.n_facet_vertices(f); ++lv)
210 {
211 if (boundary_vertices[M.facet_vertex(f, lv)])
212 {
213 tag = ElementType::BOUNDARY_POLYTOPE;
214 break;
215 }
216 }
217
218 element_tags[f] = tag;
219 }
220 }
221
222 // TODO what happens at the neighs?
223 // Override for simplices
224 for (index_t f = 0; f < M.n_facets(); ++f)
225 {
226 if (M.n_facet_vertices(f) == 3)
227 {
228 element_tags[f] = ElementType::SIMPLEX;
229 }
230 }
231}
232
234
235namespace
236{
237
238 // Same expression shapes as geogram's det(vec2, vec2) and
239 // Geom::triangle_signed_area(vec2, vec2, vec2).
240 inline double det_2d(const double ax, const double ay, const double bx, const double by)
241 {
242 return ax * by - ay * bx;
243 }
244
245 inline double triangle_signed_area_2d(
249 {
250 return 0.5 * det_2d(p2[0] - p1[0], p2[1] - p1[1], p3[0] - p1[0], p3[1] - p1[1]);
251 }
252
253 // Signed area of a polygonal facet
254 double signed_area(const polyfem::mesh::PolygonMesh &M, int f)
255 {
256 double result = 0;
257 int v0 = M.corner_vertex(M.corners_begin(f));
258 const polyfem::mesh::PolygonMesh::Point &p0 = M.point(v0);
259 for (int c = M.corners_begin(f) + 1; c + 1 < M.corners_end(f); c++)
260 {
261 int v1 = M.corner_vertex(c);
263 int v2 = M.corner_vertex(c + 1);
265 result += triangle_signed_area_2d(p0, p1, p2);
266 }
267 return result;
268 }
269
270} // anonymous namespace
271
273{
274 std::vector<int> component;
275 int nb_components = M.connected_components(component);
276 std::vector<double> comp_signed_volume(nb_components, 0.0);
277 for (int f = 0; f < M.n_facets(); ++f)
278 {
279 comp_signed_volume[component[f]] += signed_area(M, f);
280 }
281 for (int f = 0; f < M.n_facets(); ++f)
282 {
283 if (comp_signed_volume[component[f]] < 0.0)
284 {
285 M.flip_facet(f);
286 }
287 }
288}
289
291
292void polyfem::mesh::reorder_mesh(Eigen::MatrixXd &V, Eigen::MatrixXi &F, const Eigen::VectorXi &C, Eigen::VectorXi &R)
293{
294 assert(V.rows() == C.size());
295 int num_colors = C.maxCoeff() + 1;
296 Eigen::VectorXi count(num_colors);
297 count.setZero();
298 for (int i = 0; i < C.size(); ++i)
299 {
300 ++count[C(i)];
301 }
302 R.resize(num_colors + 1);
303 R(0) = 0;
304 for (int c = 0; c < num_colors; ++c)
305 {
306 R(c + 1) = R(c) + count(c);
307 }
308 count.setZero();
309 Eigen::VectorXi remap(C.size());
310 for (int i = 0; i < C.size(); ++i)
311 {
312 remap[i] = R(C(i)) + count[C(i)];
313 ++count[C(i)];
314 }
315 // Remap vertices
316 Eigen::MatrixXd NV(V.rows(), V.cols());
317 for (int v = 0; v < V.rows(); ++v)
318 {
319 NV.row(remap(v)) = V.row(v);
320 }
321 V = NV;
322 // Remap face indices
323 for (int f = 0; f < F.rows(); ++f)
324 {
325 for (int lv = 0; lv < F.cols(); ++lv)
326 {
327 F(f, lv) = remap(F(f, lv));
328 }
329 }
330}
331
333
334void polyfem::mesh::offset_surface_vertices(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F,
335 const Eigen::RowVector3d &interior_point, const double distance, Eigen::MatrixXd &offset)
336{
337 Eigen::MatrixXd normals = Eigen::MatrixXd::Zero(V.rows(), 3);
338 Eigen::VectorXd incident_area = Eigen::VectorXd::Zero(V.rows());
339 for (int f = 0; f < F.rows(); ++f)
340 {
341 const Eigen::RowVector3d a = V.row(F(f, 1)) - V.row(F(f, 0));
342 const Eigen::RowVector3d b = V.row(F(f, 2)) - V.row(F(f, 0));
343 const Eigen::RowVector3d normal = a.cross(b);
344 const double area = normal.norm();
345 for (int j = 0; j < 3; ++j)
346 {
347 normals.row(F(f, j)) += normal;
348 incident_area(F(f, j)) += area;
349 }
350 }
351
352 offset = V;
353 for (int v = 0; v < V.rows(); ++v)
354 {
355 Eigen::RowVector3d direction = normals.row(v);
356 // Normalizing a cancellation residual gives an arbitrary direction.
357 if (direction.norm() <= 64 * std::numeric_limits<double>::epsilon() * incident_area(v))
358 direction = V.row(v) - interior_point;
359 const double length = direction.norm();
360 if (length > 0)
361 offset.row(v) += (distance / length) * direction;
362 }
363}
364
366
367namespace
368{
369
370 // Plain 3D vector whose arithmetic mirrors geogram's vec3 operation by
371 // operation (same expression shapes), so the helpers below round exactly
372 // like the geogram code they replace.
373 struct Vec3
374 {
375 double x, y, z;
376 };
377
378 inline Vec3 vec3(const double *p) { return {p[0], p[1], p[2]}; }
379 inline Vec3 operator-(const Vec3 &a, const Vec3 &b) { return {a.x - b.x, a.y - b.y, a.z - b.z}; }
380 inline Vec3 operator+(const Vec3 &a, const Vec3 &b) { return {a.x + b.x, a.y + b.y, a.z + b.z}; }
381 inline Vec3 operator*(double s, const Vec3 &v) { return {s * v.x, s * v.y, s * v.z}; }
382 inline double dot(const Vec3 &a, const Vec3 &b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
383 inline double length2(const Vec3 &v) { return v.x * v.x + v.y * v.y + v.z * v.z; }
384 inline Vec3 cross(const Vec3 &a, const Vec3 &b)
385 {
386 return {
387 a.y * b.z - a.z * b.y,
388 a.z * b.x - a.x * b.z,
389 a.x * b.y - a.y * b.x};
390 }
391 inline double distance2(const Vec3 &a, const Vec3 &b)
392 {
393 const double dx = a.x - b.x;
394 const double dy = a.y - b.y;
395 const double dz = a.z - b.z;
396 return dx * dx + dy * dy + dz * dz;
397 }
398
399 inline double tetra_signed_volume(const Vec3 &p1, const Vec3 &p2, const Vec3 &p3, const Vec3 &p4)
400 {
401 return dot(p2 - p1, cross(p3 - p1, p4 - p1)) / 6.0;
402 }
403
404 double point_segment_squared_distance(const Vec3 &point, const Vec3 &v0, const Vec3 &v1)
405 {
406 const double l2 = distance2(v0, v1);
407 const double t = dot(point - v0, v1 - v0);
408 if (t <= 0.0 || l2 == 0.0)
409 return distance2(point, v0);
410 else if (t > l2)
411 return distance2(point, v1);
412 const double lambda1 = t / l2;
413 const double lambda0 = 1.0 - lambda1;
414 const Vec3 closest_point = lambda0 * v0 + lambda1 * v1;
415 return distance2(point, closest_point);
416 }
417
418 double cos_angle(const Vec3 &a, const Vec3 &b)
419 {
420 const double lab = std::sqrt(length2(a) * length2(b));
421 double result = (lab > 1e-50) ? (dot(a, b) / lab) : 1.0;
422 // Numerical precision problems may produce normalized dot products
423 // slightly outside [-1, 1].
424 if (result < -1.0)
425 result = -1.0;
426 else if (result > 1.0)
427 result = 1.0;
428 return result;
429 }
430
431 // calculate twice signed area of triangle (0,0)-(x1,y1)-(x2,y2)
432 // return an SOS-determined sign (-1, +1, or 0 only if it's a truly degenerate triangle)
433 int orientation(
434 double x1, double y1, double x2, double y2, double &twice_signed_area)
435 {
436 twice_signed_area = y1 * x2 - x1 * y2;
437 if (twice_signed_area > 0)
438 return 1;
439 else if (twice_signed_area < 0)
440 return -1;
441 else if (y2 > y1)
442 return 1;
443 else if (y2 < y1)
444 return -1;
445 else if (x1 > x2)
446 return 1;
447 else if (x1 < x2)
448 return -1;
449 else
450 return 0; // only true when x1==x2 and y1==y2
451 }
452
453 // robust test of (x0,y0) in the triangle (x1,y1)-(x2,y2)-(x3,y3)
454 // if true is returned, the barycentric coordinates are set in a,b,c.
455 //
456 // Note: This function comes from SDFGen by Christopher Batty.
457 // https://github.com/christopherbatty/SDFGen/blob/master/makelevelset3.cpp
458 bool point_in_triangle_2d(
459 double x0, double y0, double x1, double y1,
460 double x2, double y2, double x3, double y3,
461 double &a, double &b, double &c)
462 {
463 x1 -= x0;
464 x2 -= x0;
465 x3 -= x0;
466 y1 -= y0;
467 y2 -= y0;
468 y3 -= y0;
469 int signa = orientation(x2, y2, x3, y3, a);
470 if (signa == 0)
471 return false;
472 int signb = orientation(x3, y3, x1, y1, b);
473 if (signb != signa)
474 return false;
475 int signc = orientation(x1, y1, x2, y2, c);
476 if (signc != signa)
477 return false;
478 double sum = a + b + c;
479 assert(sum != 0); // if the SOS signs match and are nonzero, there's no way all of a, b, and c are zero.
480 a /= sum;
481 b /= sum;
482 c /= sum;
483 return true;
484 }
485
486 // -----------------------------------------------------------------------------
487
488 // Sign of the (approximate) signed area of the triangle p0, p1, p2.
489 // Originally taken from geogram/src/lib/geogram/delaunay/delaunay_2d.cpp
490 inline int orient_2d_inexact(
491 const double p0x, const double p0y,
492 const double p1x, const double p1y,
493 const double p2x, const double p2y)
494 {
495 double a11 = p1x - p0x;
496 double a12 = p1y - p0y;
497
498 double a21 = p2x - p0x;
499 double a22 = p2y - p0y;
500
501 double Delta = a11 * a22 - a12 * a21;
502
503 return (Delta > 0) ? 1 : ((Delta < 0) ? -1 : 0);
504 }
505
506 // -----------------------------------------------------------------------------
507
519 template <int X = 0, int Y = 1, int Z = 2>
520 int intersect_ray_z(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, int f, const Eigen::RowVector3d &q, double &z)
521 {
522 const auto p1 = V.row(F(f, 0));
523 const auto p2 = V.row(F(f, 1));
524 const auto p3 = V.row(F(f, 2));
525
526 double u, v, w;
527 if (point_in_triangle_2d(
528 q[X], q[Y], p1[X], p1[Y], p2[X], p2[Y], p3[X], p3[Y], u, v, w))
529 {
530 z = u * p1[Z] + v * p2[Z] + w * p3[Z];
531 return orient_2d_inexact(p1[X], p1[Y], p2[X], p2[Y], p3[X], p3[Y]);
532 }
533
534 return 0;
535 }
536
537 // -----------------------------------------------------------------------------
538
539 // Bounding volume hierarchy over the triangles of (V, F), used to cull
540 // triangles in signed_squared_distances. Culling never changes a result:
541 // distances are the exact minimum of the same per-triangle values (a box is
542 // skipped only if it is farther than the current minimum by more than any
543 // rounding error), and the ray test visits exactly the triangles whose
544 // closed xy bounding box contains the query point, which are the triangles
545 // geogram's AABB box query used to report.
546 class TriangleBVH
547 {
548 public:
549 TriangleBVH(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F)
550 : V_(V), F_(F), boxes_(F.rows()), order_(F.rows())
551 {
552 std::vector<std::array<double, 3>> centroids(F.rows());
553 for (int f = 0; f < F.rows(); ++f)
554 {
555 for (int d = 0; d < 3; ++d)
556 {
557 const double a = V(F(f, 0), d), b = V(F(f, 1), d), c = V(F(f, 2), d);
558 boxes_[f].min[d] = std::min(a, std::min(b, c));
559 boxes_[f].max[d] = std::max(a, std::max(b, c));
560 centroids[f][d] = (a + b + c) / 3;
561 }
562 }
563 std::iota(order_.begin(), order_.end(), 0);
564 nodes_.reserve(2 * F.rows());
565 if (F.rows() > 0)
566 build(0, F.rows(), centroids);
567 }
568
570 template <typename Fn>
571 void for_each_in_xy_column(const double x, const double y, Fn &&fn) const
572 {
573 if (nodes_.empty())
574 return;
575 std::vector<int> stack = {0};
576 while (!stack.empty())
577 {
578 const Node &node = nodes_[stack.back()];
579 stack.pop_back();
580 if (!contains_xy(node.box, x, y))
581 continue;
582 if (node.left < 0)
583 {
584 for (int i = node.begin; i < node.end; ++i)
585 if (contains_xy(boxes_[order_[i]], x, y))
586 fn(order_[i]);
587 }
588 else
589 {
590 stack.push_back(node.right);
591 stack.push_back(node.left);
592 }
593 }
594 }
595
597 double min_squared_distance(const Eigen::RowVector3d &p, const double margin) const
598 {
599 double best = std::numeric_limits<double>::max();
600 if (nodes_.empty())
601 return best;
602 std::vector<int> stack = {0};
603 while (!stack.empty())
604 {
605 const Node &node = nodes_[stack.back()];
606 stack.pop_back();
607 if (box_squared_distance(node.box, p) > best + margin)
608 continue;
609 if (node.left < 0)
610 {
611 for (int i = node.begin; i < node.end; ++i)
612 {
613 const int f = order_[i];
614 const Eigen::RowVector3d v0 = V_.row(F_(f, 0)), v1 = V_.row(F_(f, 1)), v2 = V_.row(F_(f, 2));
615 const double d = polyfem::mesh::point_triangle_squared_distance(p.data(), v0.data(), v1.data(), v2.data());
616 if (d < best)
617 best = d;
618 }
619 }
620 else
621 {
622 // Visit the closest child first.
623 const double dl = box_squared_distance(nodes_[node.left].box, p);
624 const double dr = box_squared_distance(nodes_[node.right].box, p);
625 if (dl < dr)
626 {
627 stack.push_back(node.right);
628 stack.push_back(node.left);
629 }
630 else
631 {
632 stack.push_back(node.left);
633 stack.push_back(node.right);
634 }
635 }
636 }
637 return best;
638 }
639
640 private:
641 struct Box
642 {
643 std::array<double, 3> min, max;
644 };
645
646 struct Node
647 {
648 Box box;
649 int begin, end;
650 int left = -1, right = -1;
651 };
652
653 static bool contains_xy(const Box &box, const double x, const double y)
654 {
655 return box.min[0] <= x && x <= box.max[0] && box.min[1] <= y && y <= box.max[1];
656 }
657
658 static double box_squared_distance(const Box &box, const Eigen::RowVector3d &p)
659 {
660 double result = 0;
661 for (int d = 0; d < 3; ++d)
662 {
663 const double delta = std::max(0.0, std::max(box.min[d] - p[d], p[d] - box.max[d]));
664 result += delta * delta;
665 }
666 return result;
667 }
668
669 int build(const int begin, const int end, const std::vector<std::array<double, 3>> &centroids)
670 {
671 const int id = nodes_.size();
672 nodes_.emplace_back();
673 Box box = boxes_[order_[begin]];
674 for (int i = begin + 1; i < end; ++i)
675 {
676 for (int d = 0; d < 3; ++d)
677 {
678 box.min[d] = std::min(box.min[d], boxes_[order_[i]].min[d]);
679 box.max[d] = std::max(box.max[d], boxes_[order_[i]].max[d]);
680 }
681 }
682 nodes_[id].box = box;
683 nodes_[id].begin = begin;
684 nodes_[id].end = end;
685 if (end - begin <= 4)
686 return id;
687
688 int axis = 0;
689 for (int d = 1; d < 3; ++d)
690 if (box.max[d] - box.min[d] > box.max[axis] - box.min[axis])
691 axis = d;
692 const int mid = begin + (end - begin) / 2;
693 std::nth_element(order_.begin() + begin, order_.begin() + mid, order_.begin() + end,
694 [&](const int a, const int b) { return centroids[a][axis] < centroids[b][axis]; });
695 const int left = build(begin, mid, centroids);
696 const int right = build(mid, end, centroids);
697 nodes_[id].left = left;
698 nodes_[id].right = right;
699 return id;
700 }
701
702 const Eigen::MatrixXd &V_;
703 const Eigen::MatrixXi &F_;
704 std::vector<Box> boxes_;
705 std::vector<int> order_;
706 std::vector<Node> nodes_;
707 };
708
709 // -----------------------------------------------------------------------------
710
711 // Flips the sign of D for every point inside the surface (V, F). The inside
712 // test casts a vertical ray from each point and counts the crossings below
713 // it, testing the triangles whose closed xy bounding box contains the point.
714 void compute_sign(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const TriangleBVH &bvh,
715 const Eigen::MatrixXd &P, Eigen::VectorXd &D)
716 {
717 assert(P.cols() == 3);
718 assert(D.size() == P.rows());
719
720 for (int k = 0; k < P.rows(); ++k)
721 {
722 const Eigen::RowVector3d center = P.row(k);
723
724 std::vector<std::pair<double, int>> inter;
725 bvh.for_each_in_xy_column(center[0], center[1], [&](const int f) {
726 double z;
727 if (int s = intersect_ray_z(V, F, f, center, z))
728 {
729 inter.emplace_back(z, s);
730 }
731 });
732 std::sort(inter.begin(), inter.end());
733
734 std::vector<double> reduced;
735 for (int i = 0, s = 0; i < (int)inter.size(); ++i)
736 {
737 const int ds = inter[i].second;
738 s += ds;
739 if ((s == -1 && ds < 0) || (s == 0 && ds > 0))
740 {
741 reduced.push_back(inter[i].first);
742 }
743 }
744
745 int num_before = 0;
746 for (double z : reduced)
747 {
748 if (z < center[2])
749 {
750 ++num_before;
751 }
752 }
753 if (num_before % 2 == 1)
754 {
755 // Point is inside
756 D(k) *= -1.0;
757 }
758 }
759 }
760
761} // anonymous namespace
762
764
765void polyfem::mesh::signed_squared_distances(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F,
766 const Eigen::MatrixXd &P, Eigen::VectorXd &D)
767{
768 assert(V.cols() == 3);
769 assert(F.cols() == 3);
770 assert(P.cols() == 3);
771 const TriangleBVH bvh(V, F);
772
773 // Pruning slack, far above the rounding error of the distances (which is
774 // of the order of 1e-15 times the squared size of the scene).
775 double scale2 = 0;
776 if (V.rows() > 0 && P.rows() > 0)
777 {
778 const Eigen::RowVector3d lo = V.colwise().minCoeff().cwiseMin(P.colwise().minCoeff());
779 const Eigen::RowVector3d hi = V.colwise().maxCoeff().cwiseMax(P.colwise().maxCoeff());
780 scale2 = (hi - lo).squaredNorm();
781 }
782 const double margin = 1e-10 * scale2;
783
784 D.resize(P.rows());
785 for (int i = 0; i < P.rows(); ++i)
786 D(i) = bvh.min_squared_distance(P.row(i), margin);
787 compute_sign(V, F, bvh, P, D);
788}
789
790// -----------------------------------------------------------------------------
791
792double polyfem::mesh::signed_volume(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F)
793{
794 assert(F.cols() == 3);
795 assert(V.cols() == 3);
796 std::array<Eigen::RowVector3d, 4> t;
797 t[3] = Eigen::RowVector3d::Zero(V.cols());
798 double volume_total = 0;
799 for (int f = 0; f < F.rows(); ++f)
800 {
801 for (int lv = 0; lv < F.cols(); ++lv)
802 {
803 t[lv] = V.row(F(f, lv));
804 }
805 double vol = tetra_signed_volume(vec3(t[0].data()), vec3(t[1].data()), vec3(t[2].data()), vec3(t[3].data()));
806 volume_total += vol;
807 }
808 return -volume_total;
809}
810
811// -----------------------------------------------------------------------------
812
813void polyfem::mesh::orient_closed_surface(const Eigen::MatrixXd &V, Eigen::MatrixXi &F, bool positive)
814{
815 if ((positive ? 1 : -1) * signed_volume(V, F) < 0)
816 {
817 for (int f = 0; f < F.rows(); ++f)
818 {
819 F.row(f) = F.row(f).reverse().eval();
820 }
821 }
822}
823
824// -----------------------------------------------------------------------------
825
826namespace
827{
828 struct EdgeInterfacePrimitive
829 {
831 Eigen::Vector2d from;
832 Eigen::Vector2d to;
833 };
834
835 struct FaceInterfacePrimitive
836 {
838 std::vector<Eigen::Vector3d> vertices;
839 };
840
841 bool same_point(const polyfem::RowVectorNd &a, const polyfem::RowVectorNd &b)
842 {
843 return a.size() == b.size() && (a - b).squaredNorm() <= 1e-24;
844 }
845
846 bool overlapping_segments(const EdgeInterfacePrimitive &first, const EdgeInterfacePrimitive &second)
847 {
848 const Eigen::Vector2d direction = first.to - first.from;
849 const double length = direction.norm();
850 const double second_length = (second.to - second.from).norm();
851 const double scale = std::max({1.0, length, second_length});
852 const double tolerance = 1e-12 * scale;
853 if (length <= tolerance || second_length <= tolerance)
854 return false;
855
856 auto cross = [](const Eigen::Vector2d &a, const Eigen::Vector2d &b) {
857 return a.x() * b.y() - a.y() * b.x();
858 };
859 if (std::abs(cross(direction, second.from - first.from)) > tolerance * length
860 || std::abs(cross(direction, second.to - first.from)) > tolerance * length)
861 return false;
862
863 const Eigen::Vector2d tangent = direction / length;
864 const double second_from = (second.from - first.from).dot(tangent);
865 const double second_to = (second.to - first.from).dot(tangent);
866 const double overlap_begin = std::max(0.0, std::min(second_from, second_to));
867 const double overlap_end = std::min(length, std::max(second_from, second_to));
868 return overlap_end - overlap_begin > tolerance;
869 }
870
871 Eigen::Vector3d face_normal(const FaceInterfacePrimitive &face)
872 {
873 Eigen::Vector3d normal = Eigen::Vector3d::Zero();
874 for (int i = 0; i < face.vertices.size(); ++i)
875 normal += face.vertices[i].cross(face.vertices[(i + 1) % face.vertices.size()]);
876 return normal;
877 }
878
879 Eigen::Vector2d project_point(const Eigen::Vector3d &point, const int dropped_axis)
880 {
881 if (dropped_axis == 0)
882 return {point.y(), point.z()};
883 if (dropped_axis == 1)
884 return {point.x(), point.z()};
885 return {point.x(), point.y()};
886 }
887
888 bool point_in_convex_polygon(
889 const Eigen::Vector2d &point,
890 const std::vector<Eigen::Vector2d> &polygon,
891 const double tolerance)
892 {
893 double sign = 0;
894 for (int i = 0; i < polygon.size(); ++i)
895 {
896 const Eigen::Vector2d edge = polygon[(i + 1) % polygon.size()] - polygon[i];
897 const Eigen::Vector2d offset = point - polygon[i];
898 const double cross = edge.x() * offset.y() - edge.y() * offset.x();
899 if (std::abs(cross) <= tolerance)
900 continue;
901 if (sign == 0)
902 sign = cross;
903 else if (sign * cross < 0)
904 return false;
905 }
906 return true;
907 }
908
909 bool overlapping_faces(const FaceInterfacePrimitive &first, const FaceInterfacePrimitive &second)
910 {
911 const Eigen::Vector3d first_normal = face_normal(first);
912 const Eigen::Vector3d second_normal = face_normal(second);
913 const double first_area_scale = first_normal.norm();
914 const double second_area_scale = second_normal.norm();
915 const double coordinate_scale = std::max({1.0,
916 first.vertices.front().norm(),
917 second.vertices.front().norm()});
918 const double tolerance = 1e-12 * coordinate_scale;
919 if (first_area_scale <= tolerance * tolerance || second_area_scale <= tolerance * tolerance)
920 return false;
921
922 const Eigen::Vector3d unit_normal = first_normal / first_area_scale;
923 if (unit_normal.cross(second_normal / second_area_scale).norm() > 1e-10)
924 return false;
925 for (const auto &point : second.vertices)
926 if (std::abs(unit_normal.dot(point - first.vertices.front())) > tolerance)
927 return false;
928
929 Eigen::Index dropped_axis;
930 unit_normal.cwiseAbs().maxCoeff(&dropped_axis);
931 std::vector<Eigen::Vector2d> first_polygon, second_polygon;
932 first_polygon.reserve(first.vertices.size());
933 second_polygon.reserve(second.vertices.size());
934 for (const auto &point : first.vertices)
935 first_polygon.push_back(project_point(point, dropped_axis));
936 for (const auto &point : second.vertices)
937 second_polygon.push_back(project_point(point, dropped_axis));
938
939 auto contains = [tolerance](const auto &container, const auto &contained) {
940 return std::all_of(contained.begin(), contained.end(), [&](const Eigen::Vector2d &point) {
941 return point_in_convex_polygon(point, container, tolerance);
942 });
943 };
944 return contains(first_polygon, second_polygon) || contains(second_polygon, first_polygon);
945 }
946} // namespace
947
948std::vector<std::pair<polyfem::mesh::Navigation::Index, polyfem::mesh::Navigation::Index>>
950{
951 using Index = Navigation::Index;
952 std::vector<EdgeInterfacePrimitive> first_edges, second_edges;
953 auto collect = [](const Mesh2D &mesh, auto &edges) {
954 for (int f = 0; f < mesh.n_faces(); ++f)
955 {
956 auto index = mesh.get_index_from_face(f);
957 for (int le = 0; le < mesh.n_face_vertices(f); ++le)
958 {
959 if (mesh.is_boundary_edge(index.edge))
960 {
961 const auto opposite = mesh.switch_vertex(index);
962 edges.push_back({index,
963 mesh.point(index.vertex).head<2>(),
964 mesh.point(opposite.vertex).head<2>()});
965 }
966 index = mesh.next_around_face(index);
967 }
968 }
969 };
970 collect(first, first_edges);
971 collect(second, second_edges);
972
973 std::vector<std::pair<Index, Index>> result;
974 std::set<std::tuple<int, int, int, int, int, int>> visited_pairs;
975 for (const auto &lhs : first_edges)
976 {
977 for (const auto &rhs : second_edges)
978 {
979 if (!overlapping_segments(lhs, rhs))
980 continue;
981 Index second_index = rhs.index;
982 if ((lhs.to - lhs.from).dot(rhs.to - rhs.from) > 0)
983 second_index = second.switch_vertex(second_index);
984 const auto key = std::make_tuple(
985 lhs.index.face, lhs.index.edge, lhs.index.vertex,
986 second_index.face, second_index.edge, second_index.vertex);
987 if (visited_pairs.insert(key).second)
988 result.emplace_back(lhs.index, second_index);
989 }
990 }
991 return result;
992}
993
994std::vector<std::pair<polyfem::mesh::Navigation3D::Index, polyfem::mesh::Navigation3D::Index>>
996{
997 using Index = Navigation3D::Index;
998 std::vector<FaceInterfacePrimitive> first_faces, second_faces;
999 auto collect = [](const Mesh3D &mesh, auto &faces) {
1000 std::unordered_set<int> visited_faces;
1001 for (int c = 0; c < mesh.n_cells(); ++c)
1002 {
1003 for (int lf = 0; lf < mesh.n_cell_faces(c); ++lf)
1004 {
1005 const int face = mesh.cell_face(c, lf);
1006 if (!mesh.is_boundary_face(face) || !visited_faces.insert(face).second)
1007 continue;
1008 auto index = mesh.get_index_from_element(c, lf, 0);
1009 std::vector<Eigen::Vector3d> vertices(mesh.n_face_vertices(face));
1010 for (int lv = 0; lv < vertices.size(); ++lv)
1011 vertices[lv] = mesh.point(mesh.face_vertex(face, lv)).head<3>();
1012 faces.push_back({index, std::move(vertices)});
1013 }
1014 }
1015 };
1016 collect(first, first_faces);
1017 collect(second, second_faces);
1018
1019 std::vector<std::pair<Index, Index>> result;
1020 for (const auto &lhs : first_faces)
1021 {
1022 for (const auto &rhs : second_faces)
1023 {
1024 if (!overlapping_faces(lhs, rhs))
1025 continue;
1026 Index second_index = rhs.index;
1027 for (int lv = 0; lv < second.n_face_vertices(second_index.face); ++lv)
1028 {
1029 if (same_point(first.point(lhs.index.vertex), second.point(second_index.vertex)))
1030 break;
1031 second_index = second.next_around_face(second_index);
1032 }
1033 result.emplace_back(lhs.index, second_index);
1034 }
1035 }
1036 return result;
1037}
1038
1040
1041namespace
1042{
1043
1044 bool approx_aligned(const double *a_, const double *b_, const double *p_, const double *q_, double tol = 1e-6)
1045 {
1046 const Vec3 a = vec3(a_), b = vec3(b_), p = vec3(p_), q = vec3(q_);
1047 double da = std::sqrt(point_segment_squared_distance(a, p, q));
1048 double db = std::sqrt(point_segment_squared_distance(b, p, q));
1049 double cos_theta = cos_angle(b - a, p - q);
1050 return (da < tol && db < tol && std::abs(std::abs(cos_theta) - 1.0) < tol);
1051 }
1052
1053} // anonymous namespace
1054
1055// -----------------------------------------------------------------------------
1056
1057void polyfem::mesh::extract_parent_edges(const Eigen::MatrixXd &IV, const Eigen::MatrixXi &IE,
1058 const Eigen::MatrixXd &BV, const Eigen::MatrixXi &BE, Eigen::MatrixXi &OE)
1059{
1060 assert(IV.cols() == 2 || IV.cols() == 3);
1061 assert(BV.cols() == 2 || BV.cols() == 3);
1062 typedef std::pair<int, int> Edge;
1063 std::vector<Edge> selected;
1064 for (int e1 = 0; e1 < IE.rows(); ++e1)
1065 {
1066 Eigen::RowVector3d a;
1067 a.setZero();
1068 a.head(IV.cols()) = IV.row(IE(e1, 0));
1069 Eigen::RowVector3d b;
1070 b.setZero();
1071 b.head(IV.cols()) = IV.row(IE(e1, 1));
1072 for (int e2 = 0; e2 < BE.rows(); ++e2)
1073 {
1074 Eigen::RowVector3d p;
1075 p.setZero();
1076 p.head(BV.cols()) = BV.row(BE(e2, 0));
1077 Eigen::RowVector3d q;
1078 q.setZero();
1079 q.head(BV.cols()) = BV.row(BE(e2, 1));
1080 if (approx_aligned(a.data(), b.data(), p.data(), q.data()))
1081 {
1082 selected.emplace_back(IE(e1, 0), IE(e1, 1));
1083 break;
1084 }
1085 }
1086 }
1087
1088 OE.resize(selected.size(), 2);
1089 for (int e = 0; e < OE.rows(); ++e)
1090 {
1091 OE.row(e) << selected[e].first, selected[e].second;
1092 }
1093}
1094
1096
1098 const Eigen::MatrixXi &tets,
1099 Eigen::MatrixXi &faces)
1100{
1101 std::unordered_set<Eigen::Vector3i, HashMatrix> tri_to_tet(4 * tets.rows());
1102 for (int i = 0; i < tets.rows(); i++)
1103 {
1104 tri_to_tet.emplace(tets(i, 0), tets(i, 2), tets(i, 1));
1105 tri_to_tet.emplace(tets(i, 0), tets(i, 3), tets(i, 2));
1106 tri_to_tet.emplace(tets(i, 0), tets(i, 1), tets(i, 3));
1107 tri_to_tet.emplace(tets(i, 1), tets(i, 2), tets(i, 3));
1108 }
1109
1110 std::vector<Eigen::RowVector3i> faces_vector;
1111 for (const auto &tri : tri_to_tet)
1112 {
1113 // find dual triangle with reversed indices:
1114 bool is_surface_triangle =
1115 tri_to_tet.find(Eigen::Vector3i(tri[2], tri[1], tri[0])) == tri_to_tet.end()
1116 && tri_to_tet.find(Eigen::Vector3i(tri[1], tri[0], tri[2])) == tri_to_tet.end()
1117 && tri_to_tet.find(Eigen::Vector3i(tri[0], tri[2], tri[1])) == tri_to_tet.end();
1118 if (is_surface_triangle)
1119 {
1120 faces_vector.emplace_back(tri[0], tri[1], tri[2]);
1121 }
1122 }
1123
1124 faces.resize(faces_vector.size(), 3);
1125 for (int i = 0; i < faces.rows(); i++)
1126 {
1127 faces.row(i) = faces_vector[i];
1128 }
1129}
1130
1132 const Eigen::MatrixXd &vertices,
1133 const Eigen::MatrixXi &tets,
1134 Eigen::MatrixXd &surface_vertices,
1135 Eigen::MatrixXi &tris)
1136{
1137 Eigen::MatrixXi full_tris;
1138 find_triangle_surface_from_tets(tets, full_tris);
1139
1140 std::unordered_map<int, int> full_to_surface;
1141 std::vector<size_t> surface_to_full;
1142 for (int i = 0; i < full_tris.rows(); i++)
1143 {
1144 for (int j = 0; j < full_tris.cols(); j++)
1145 {
1146 if (full_to_surface.find(full_tris(i, j)) == full_to_surface.end())
1147 {
1148 full_to_surface[full_tris(i, j)] = surface_to_full.size();
1149 surface_to_full.push_back(full_tris(i, j));
1150 }
1151 }
1152 }
1153
1154 surface_vertices.resize(surface_to_full.size(), 3);
1155 for (int i = 0; i < surface_to_full.size(); i++)
1156 {
1157 surface_vertices.row(i) = vertices.row(surface_to_full[i]);
1158 }
1159
1160 tris.resize(full_tris.rows(), full_tris.cols());
1161 for (int i = 0; i < tris.rows(); i++)
1162 {
1163 for (int j = 0; j < tris.cols(); j++)
1164 {
1165 tris(i, j) = full_to_surface[full_tris(i, j)];
1166 }
1167 }
1168}
1169
1170int polyfem::mesh::count_faces(const int dim, const Eigen::MatrixXi &cells)
1171{
1172 std::unordered_set<std::vector<int>, HashVector> boundaries;
1173
1174 auto insert = [&](std::vector<int> v) {
1175 std::sort(v.begin(), v.end());
1176 boundaries.insert(v);
1177 };
1178
1179 for (int i = 0; i < cells.rows(); i++)
1180 {
1181 const auto &cell = cells.row(i);
1182 if (cells.cols() == 3) // triangle
1183 {
1184 insert({{cell(0), cell(1)}});
1185 insert({{cell(1), cell(2)}});
1186 insert({{cell(2), cell(0)}});
1187 }
1188 else if (cells.cols() == 4 && dim == 2) // quadralateral
1189 {
1190 insert({{cell(0), cell(1)}});
1191 insert({{cell(1), cell(2)}});
1192 insert({{cell(2), cell(3)}});
1193 insert({{cell(3), cell(0)}});
1194 }
1195 else if (cells.cols() == 4 && dim == 3) // tetrahedron
1196 {
1197 insert({{cell(0), cell(2), cell(1)}});
1198 insert({{cell(0), cell(3), cell(2)}});
1199 insert({{cell(0), cell(1), cell(3)}});
1200 insert({{cell(1), cell(2), cell(3)}});
1201 }
1202 else if (cells.cols() == 8) // hexahedron
1203 {
1204 insert({{cell(0), cell(1), cell(2), cell(3)}});
1205 insert({{cell(1), cell(5), cell(6), cell(2)}});
1206 insert({{cell(5), cell(4), cell(7), cell(6)}});
1207 insert({{cell(0), cell(4), cell(7), cell(3)}});
1208 insert({{cell(0), cell(4), cell(5), cell(1)}});
1209 insert({{cell(2), cell(6), cell(7), cell(3)}});
1210 }
1211 else
1212 {
1213 throw std::runtime_error("count_boundary_elements not implemented for polygons");
1214 }
1215 }
1216
1217 return boundaries.size();
1218}
1219
1221{
1222 typedef std::pair<int, int> Edge;
1223
1224 if (M.n_edges() > 0)
1225 return;
1226
1227 M.connect_facets();
1228
1229 // Compute a list of all the edges
1230 std::vector<std::pair<Edge, int>> e2c; // edge to corner id
1231 for (int f = 0; f < M.n_facets(); ++f)
1232 {
1233 for (int c = M.corners_begin(f); c < M.corners_end(f); ++c)
1234 {
1235 int v = M.corner_vertex(c);
1236 int c2 = M.next_corner_around_facet(f, c);
1237 int v2 = M.corner_vertex(c2);
1238 e2c.emplace_back(std::make_pair(std::min(v, v2), std::max(v, v2)), c);
1239 }
1240 }
1241 std::sort(e2c.begin(), e2c.end());
1242
1243 // Assign unique id to edges
1244 M.clear_edges();
1245 Edge prev_e(-1, -1);
1246 for (const auto &kv : e2c)
1247 {
1248 Edge e = kv.first;
1249 if (e != prev_e)
1250 {
1251 M.create_edge(e.first, e.second);
1252 prev_e = e;
1253 }
1254 }
1255}
int V
QuadratureVector da
Eigen::RowVectorXd point
Eigen::MatrixXd F
std::vector< Eigen::VectorXi > faces
int y
int z
int x
2D mesh interface: the elements are the faces (polygons) and the boundary elements are the edges.
Definition Mesh2D.hpp:18
Navigation::Index next_around_face(Navigation::Index idx) const
Definition Mesh2D.hpp:63
virtual Navigation::Index switch_vertex(Navigation::Index idx) const =0
virtual Navigation::Index get_index_from_face(int f, int lv=0) const =0
3D mesh interface: the elements are the cells (tetrahedra, hexahedra, prisms, pyramids or general pol...
Definition Mesh3D.hpp:22
virtual Navigation3D::Index get_index_from_element(int hi, int lf, int lv) const =0
virtual int n_cell_faces(const int c_id) const =0
virtual int cell_face(const int c_id, const int lf_id) const =0
virtual Navigation3D::Index next_around_face(Navigation3D::Index idx) const =0
virtual RowVectorNd point(const int global_index) const =0
point coordinates
virtual bool is_boundary_face(const int face_global_id) const =0
is face boundary
virtual bool is_boundary_edge(const int edge_global_id) const =0
is edge boundary
virtual int n_cells() const =0
number of cells
virtual int n_faces() const =0
number of faces
virtual int n_face_vertices(const int f_id) const =0
number of vertices of a face
virtual int face_vertex(const int f_id, const int lv_id) const =0
id of the face vertex
Minimal polygonal surface mesh used as the storage of CMesh2D.
M
Definition eigs.py:94
list vertices
Definition p_bases.py:238
int norm
Definition p_bases.py:265
Eigen::Matrix< double, dim, 1 > cross(const Eigen::Matrix< double, dim, 1 > &x, const Eigen::Matrix< double, dim, 1 > &y)
Eigen::ArrayXd P(const int m, const int p, const Eigen::ArrayXd &z)
Definition p_n_bases.cpp:42
std::vector< std::pair< Navigation::Index, Navigation::Index > > compute_mesh_interface(const Mesh2D &first, const Mesh2D &second)
Pair coincident boundary edges, including nonconforming leader/follower edges.
void orient_closed_surface(const Eigen::MatrixXd &V, Eigen::MatrixXi &F, bool positive=true)
Orient a triangulated surface to have positive volume.
double signed_volume(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F)
Compute the signed volume of a surface mesh.
PolygonMesh::Point mesh_vertex(const PolygonMesh &M, int v)
Retrieve a 3D vector with the position of a given vertex.
Definition MeshUtils.cpp:39
void offset_surface_vertices(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::RowVector3d &interior_point, double distance, Eigen::MatrixXd &offset)
Offset along area-weighted surface normals, using the direction away from an interior point where inc...
void reorder_mesh(Eigen::MatrixXd &V, Eigen::MatrixXi &F, const Eigen::VectorXi &C, Eigen::VectorXi &R)
Reorder vertices of a mesh using color tags, so that vertices are ordered by increasing colors.
void find_triangle_surface_from_tets(const Eigen::MatrixXi &tets, Eigen::MatrixXi &faces)
Boundary triangles of a tet mesh, indexing the tets' vertices.
bool is_planar(const Eigen::MatrixXd &V, const double tol=1e-5)
Determine if the given V x (2|3) vertices are planar (2D or z-range below tol).
Definition MeshUtils.cpp:26
void extract_parent_edges(const Eigen::MatrixXd &IV, const Eigen::MatrixXi &IE, const Eigen::MatrixXd &BV, const Eigen::MatrixXi &BE, Eigen::MatrixXi &OE)
Extract a set of edges that are overlap with a set given set of parent edges, using vertices position...
ElementType
Type of Element, check [Poly-Spline Finite Element Method] for a complete description.
Definition Mesh.hpp:31
void extract_triangle_surface_from_tets(const Eigen::MatrixXd &vertices, const Eigen::MatrixXi &tets, Eigen::MatrixXd &surface_vertices, Eigen::MatrixXi &tris)
Extract triangular surface from a tetmesh.
double point_triangle_squared_distance(const double *p, const double *v0, const double *v1, const double *v2)
Squared distance between a point and a triangle.
void signed_squared_distances(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::MatrixXd &P, Eigen::VectorXd &D)
Computes the signed squared distance from a list of points to a triangle mesh.
PolygonMesh::Point facet_barycenter(const PolygonMesh &M, int f)
Definition MeshUtils.cpp:46
void compute_element_tags(const PolygonMesh &M, std::vector< ElementType > &element_tags)
Compute the type of each facet in a surface mesh.
Definition MeshUtils.cpp:65
int mesh_create_vertex(PolygonMesh &M, const PolygonMesh::Point &p)
Definition MeshUtils.cpp:58
void orient_normals_2d(PolygonMesh &M)
Orient facets of a 2D mesh so that each connected component has positive volume.
void generate_edges(PolygonMesh &M)
Creates the edges of M (sorted by vertex pair) if it has none yet.
int count_faces(const int dim, const Eigen::MatrixXi &cells)
Count the number of boundary elements (triangles for tetmesh and edges for triangle mesh)
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13