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

Method compute_from_mesh

src/Attributes/VoxelDihedralAngleAttribute.cpp:28–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26using namespace VoxelDihedralAngleAttributeHelper;
27
28void VoxelDihedralAngleAttribute::compute_from_mesh(Mesh& mesh) {
29 const size_t dim = mesh.get_dim();
30 const size_t num_voxels = mesh.get_num_voxels();
31 const size_t vertex_per_voxel = mesh.get_vertex_per_voxel();
32 if (dim != 3) {
33 throw RuntimeError("Voxel dihedral anlge computation is for 3D only.");
34 }
35 if (num_voxels > 0 && vertex_per_voxel != 4) {
36 throw NotImplementedError(
37 "Voxel dihedral angle computation only support tet for now.");
38 }
39
40 const auto& vertices = mesh.get_vertices();
41 const auto& voxels = mesh.get_voxels();
42 VectorF& dihedral_angles = m_values;
43 dihedral_angles.resize(num_voxels * 6);
44
45 for (size_t i=0; i<num_voxels; i++) {
46 Vector4I v = voxels.segment<4>(i*4);
47 Vector3F v0 = vertices.segment<3>(v[0]*3);
48 Vector3F v1 = vertices.segment<3>(v[1]*3);
49 Vector3F v2 = vertices.segment<3>(v[2]*3);
50 Vector3F v3 = vertices.segment<3>(v[3]*3);
51
52 Vector3F n0 = compute_normal(v1, v2, v3);
53 Vector3F n1 = compute_normal(v0, v3, v2);
54 Vector3F n2 = compute_normal(v0, v1, v3);
55 Vector3F n3 = compute_normal(v0, v2, v1);
56
57 dihedral_angles[i*6 ] = M_PI - angle(n2, n3);
58 dihedral_angles[i*6+1] = M_PI - angle(n0, n3);
59 dihedral_angles[i*6+2] = M_PI - angle(n1, n3);
60 dihedral_angles[i*6+3] = M_PI - angle(n1, n2);
61 dihedral_angles[i*6+4] = M_PI - angle(n0, n1);
62 dihedral_angles[i*6+5] = M_PI - angle(n0, n2);
63 }
64}
65

Callers

nothing calls this directly

Calls 9

RuntimeErrorClass · 0.85
NotImplementedErrorClass · 0.85
compute_normalFunction · 0.85
angleFunction · 0.70
get_dimMethod · 0.45
get_num_voxelsMethod · 0.45
get_vertex_per_voxelMethod · 0.45
get_verticesMethod · 0.45
get_voxelsMethod · 0.45

Tested by

no test coverage detected