MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / cut_along_edges

Method cut_along_edges

tools/MeshUtils/MeshCutter.cpp:176–299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176Mesh::Ptr MeshCutter::cut_along_edges(
177 const std::vector<std::vector<int>>& edge_chains) const {
178 std::unordered_set<Duplet, MultipletHashFunc<Duplet>> cut_edges;
179 for (const auto& chain : edge_chains) {
180 const auto chain_size = chain.size();
181 assert(chain_size >= 2);
182 for (size_t i=0; i < chain_size-1; i++) {
183 cut_edges.insert(Duplet(
184 static_cast<int>(chain[i]),
185 static_cast<int>(chain[i+1]) ));
186 }
187 }
188 auto is_cut_edge = [&cut_edges](const Duplet& e) {
189 return cut_edges.find(e) != cut_edges.end();
190 };
191
192 const size_t dim = m_mesh->get_dim();
193 const size_t vertex_per_face = m_mesh->get_vertex_per_face();
194 const size_t num_existing_vertices = m_mesh->get_num_vertices();
195 auto faces = m_mesh->get_faces(); // Intentional copy
196 const auto& vertices = m_mesh->get_vertices();
197 std::vector<size_t> new_vertices;
198
199 const size_t num_vertices = m_mesh->get_num_vertices();
200 for (size_t i=0; i<num_vertices; i++) {
201 const auto& adj_faces = m_mesh->get_vertex_adjacent_faces(i);
202 const auto num_adj_faces = adj_faces.size();
203 if (num_adj_faces == 0) continue;
204 DupletMap<int> edge_face_map;
205 std::unordered_map<int, std::array<Duplet, 2>> spokes;
206 for (size_t j=0; j<num_adj_faces; j++) {
207 std::array<Duplet, 2> es;
208 const auto fid = adj_faces[j];
209 const auto& f = faces.segment<3>(fid*3);
210 if (f[0] == i) {
211 es[0] = {f[0], f[1]};
212 es[1] = {f[0], f[2]};
213 } else if (f[1] == i) {
214 es[0] = {f[1], f[2]};
215 es[1] = {f[1], f[0]};
216 } else {
217 assert(f[2] == i);
218 es[0] = {f[2], f[0]};
219 es[1] = {f[2], f[1]};
220 }
221 spokes.insert({fid, es});
222 edge_face_map.insert(es[0], fid);
223 edge_face_map.insert(es[1], fid);
224 }
225
226 std::unordered_set<int> visited;
227 auto has_visited = [&visited](int fid) {
228 return visited.find(fid) != visited.end();
229 };
230 std::vector<std::list<int>> comps;
231
232 auto flood_across_edge = [
233 &is_cut_edge,

Callers 4

cut_to_manifoldMethod · 0.80
runMethod · 0.80
TEST_FFunction · 0.80
MeshCutterTest.hFile · 0.80

Calls 15

DupletClass · 0.85
RuntimeErrorClass · 0.85
findMethod · 0.80
pushMethod · 0.80
popMethod · 0.80
MeshFactoryClass · 0.50
sizeMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
get_dimMethod · 0.45
get_vertex_per_faceMethod · 0.45
get_num_verticesMethod · 0.45

Tested by 1

TEST_FFunction · 0.64