Wildmeshing Toolkit
Loading...
Searching...
No Matches
BoundaryEnvelope.hpp
1#pragma once
2
3#include <wmtk/TriMesh.h>
4#include <wmtk/envelope/Envelope.hpp>
5
6#include <Eigen/Core>
7
8#include <array>
9#include <cstddef>
10#include <vector>
11
12namespace wmtk {
13
43{
44public:
58 template <typename VertexAttributes>
59 bool init(const TriMesh& m, VertexAttributes& vertex_attrs, double eps, bool use_exact)
60 {
61 std::vector<Eigen::Vector2i> E;
62 for (const TriMesh::Tuple& e : m.get_edges()) {
63 if (!m.is_boundary_edge(e)) continue;
64 const size_t a = e.vid(m), b = e.switch_vertex(m).vid(m);
65 E.emplace_back(int(a), int(b));
66 vertex_attrs[a].input_boundary = true;
67 vertex_attrs[b].input_boundary = true;
68 }
69 if (E.empty()) {
70 m_initialized = false;
71 return false;
72 }
73 std::vector<Eigen::Vector3d> V(m.vert_capacity());
74 for (size_t i = 0; i < V.size(); ++i) {
75 V[i] = vertex_attrs[i].pos;
76 }
77 build(V, E, eps, use_exact);
78 return true;
79 }
80
82 bool initialized() const { return m_initialized; }
83
89 void set_use_exact(bool use_exact) { m_envelope.use_exact = use_exact; }
90
100 template <typename VertexAttributes>
102 const TriMesh& m,
103 const VertexAttributes& vertex_attrs,
104 const std::vector<TriMesh::Tuple>& tris) const
105 {
106 if (!m_initialized) return true;
107 for (const TriMesh::Tuple& t : tris) {
108 for (int j = 0; j < 3; ++j) {
109 const TriMesh::Tuple e = m.tuple_from_edge(t.fid(m), j);
110 const size_t a = e.vid(m), b = e.switch_vertex(m).vid(m);
111 if (!vertex_attrs[a].input_boundary && !vertex_attrs[b].input_boundary) continue;
112 if (!m.is_boundary_edge(e)) continue;
113 const std::array<Eigen::Vector3d, 2> seg{
114 {vertex_attrs[a].pos, vertex_attrs[b].pos}};
115 if (m_envelope.is_outside(seg)) return false;
116 }
117 }
118 return true;
119 }
120
132 template <typename VertexAttributes>
133 static bool on_input_boundary(
134 const TriMesh& m,
135 const VertexAttributes& vertex_attrs,
136 const TriMesh::Tuple& v)
137 {
138 return vertex_attrs[v.vid(m)].input_boundary && m.is_boundary_vertex(v);
139 }
140
141private:
142 void build(
143 const std::vector<Eigen::Vector3d>& V,
144 const std::vector<Eigen::Vector2i>& E,
145 double eps,
146 bool use_exact);
147
148 Envelope m_envelope;
149 bool m_initialized = false;
150};
151
152} // namespace wmtk
A tube around the open boundary of a triangle mesh, for operations allowed to move it.
Definition BoundaryEnvelope.hpp:43
bool initialized() const
Whether init() found a boundary to build the tube around.
Definition BoundaryEnvelope.hpp:82
bool init(const TriMesh &m, VertexAttributes &vertex_attrs, double eps, bool use_exact)
Build the tube around the boundary edges of m and flag their vertices.
Definition BoundaryEnvelope.hpp:59
static bool on_input_boundary(const TriMesh &m, const VertexAttributes &vertex_attrs, const TriMesh::Tuple &v)
v is an input_boundary vertex that is still on the boundary.
Definition BoundaryEnvelope.hpp:133
bool boundary_edges_inside(const TriMesh &m, const VertexAttributes &vertex_attrs, const std::vector< TriMesh::Tuple > &tris) const
Every boundary edge of tris that touches an input_boundary vertex lies in the tube.
Definition BoundaryEnvelope.hpp:101
void set_use_exact(bool use_exact)
Definition BoundaryEnvelope.hpp:89
Definition Envelope.hpp:19
virtual bool is_outside(const std::array< Eigen::Vector3d, 3 > &tris) const
Definition Envelope.cpp:434
Definition TriMesh.h:36
Tuple switch_vertex(const TriMesh &m) const
Definition TriMesh.cpp:161
size_t vid(const TriMesh &) const
Definition TriMesh.h:76
Definition TriMesh.h:32