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

Method compute_from_mesh

src/Attributes/FaceIncircleCenterAttribute.cpp:10–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8using namespace PyMesh;
9
10void FaceIncircleCenterAttribute::compute_from_mesh(Mesh& mesh) {
11 if (!mesh.has_attribute("edge_length")) {
12 mesh.add_attribute("edge_length");
13 }
14 const VectorF& edge_length = mesh.get_attribute("edge_length");
15
16 const size_t dim = mesh.get_dim();
17 const size_t num_faces = mesh.get_num_faces();
18 const size_t num_vertex_per_face = mesh.get_vertex_per_face();
19
20 if (num_vertex_per_face != 3) {
21 throw NotImplementedError("Incircle only exists for triangles.");
22 }
23
24 VectorF& centers = m_values;
25 centers = VectorF::Zero(num_faces*dim);
26
27 const VectorF& vertices = mesh.get_vertices();
28 const VectorI& faces = mesh.get_faces();
29
30 for (size_t i=0; i<num_faces; i++) {
31 VectorI face = faces.segment(
32 i*num_vertex_per_face, num_vertex_per_face);
33 VectorF edges = edge_length.segment(
34 i*num_vertex_per_face, num_vertex_per_face);
35
36 Float circumference = edges.sum();
37 if (circumference == 0) {
38 // Triangle is so degenerate that it is a point.
39 // The incenter would be that point.
40 centers.segment(i*dim, dim) = vertices.segment(face[0]*dim, dim);
41 } else {
42 centers.segment(i*dim, dim) = (
43 vertices.segment(face[0]*dim, dim) * edges[1] +
44 vertices.segment(face[1]*dim, dim) * edges[2] +
45 vertices.segment(face[2]*dim, dim) * edges[0])
46 / circumference;
47 }
48 }
49}
50

Callers

nothing calls this directly

Calls 9

NotImplementedErrorClass · 0.85
has_attributeMethod · 0.45
add_attributeMethod · 0.45
get_attributeMethod · 0.45
get_dimMethod · 0.45
get_num_facesMethod · 0.45
get_vertex_per_faceMethod · 0.45
get_verticesMethod · 0.45
get_facesMethod · 0.45

Tested by

no test coverage detected