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

Method compute_from_mesh

src/Attributes/FaceCentroidAttribute.cpp:8–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6using namespace PyMesh;
7
8void FaceCentroidAttribute::compute_from_mesh(Mesh& mesh) {
9 const size_t dim = mesh.get_dim();
10 const size_t num_faces = mesh.get_num_faces();
11 const size_t vertex_per_face = mesh.get_vertex_per_face();
12
13 VectorF& centroids = m_values;
14 centroids.resize(num_faces * dim);
15
16 for (size_t i=0; i<num_faces; i++) {
17 VectorI face = mesh.get_face(i);
18 VectorF centroid = VectorF::Zero(dim);
19 for (size_t j=0; j<vertex_per_face; j++) {
20 centroid += mesh.get_vertex(face[j]);
21 }
22 centroid /= vertex_per_face;
23
24 centroids.segment(i*dim, dim) = centroid;
25 }
26}

Callers

nothing calls this directly

Calls 5

get_faceMethod · 0.80
get_dimMethod · 0.45
get_num_facesMethod · 0.45
get_vertex_per_faceMethod · 0.45
get_vertexMethod · 0.45

Tested by

no test coverage detected