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

Method compute_from_mesh

src/Attributes/VoxelCircumRadiusAttribute.cpp:9–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7using namespace PyMesh;
8
9void VoxelCircumRadiusAttribute::compute_from_mesh(Mesh& mesh) {
10 const size_t dim = mesh.get_dim();
11 const size_t num_voxels = mesh.get_num_voxels();
12 const size_t vertex_per_voxel = mesh.get_vertex_per_voxel();
13
14 if (num_voxels > 0 && vertex_per_voxel != 4) {
15 throw NotImplementedError(
16 "Voxel circumradius is defined for 3D tet mesh only.");
17 }
18 if (dim != 3) {
19 throw RuntimeError("Voxel circumradius is defined for 3D tet mesh only.");
20 }
21
22 if (!mesh.has_attribute("voxel_circumcenter")) {
23 mesh.add_attribute("voxel_circumcenter");
24 }
25 const auto& circumcenter = mesh.get_attribute("voxel_circumcenter");
26
27 VectorF& circumradius = m_values;
28 circumradius.resize(num_voxels);
29 const auto& voxels = mesh.get_voxels();
30 const auto& vertices = mesh.get_vertices();
31
32 for (size_t i=0; i<num_voxels; i++) {
33 Vector4I voxel = voxels.segment<4>(i*4);
34 Vector3F v0 = vertices.segment<3>(voxel[0]*3);
35 Vector3F center = circumcenter.segment<3>(i*3);
36 circumradius[i] = (v0 - center).norm();
37 }
38}
39

Callers

nothing calls this directly

Calls 11

NotImplementedErrorClass · 0.85
RuntimeErrorClass · 0.85
normMethod · 0.80
get_dimMethod · 0.45
get_num_voxelsMethod · 0.45
get_vertex_per_voxelMethod · 0.45
has_attributeMethod · 0.45
add_attributeMethod · 0.45
get_attributeMethod · 0.45
get_voxelsMethod · 0.45
get_verticesMethod · 0.45

Tested by

no test coverage detected