| 7 | using namespace PyMesh; |
| 8 | |
| 9 | void 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 |
nothing calls this directly
no test coverage detected