| 7 | using namespace PyMesh; |
| 8 | |
| 9 | void VoxelFaceIndexAttribute::compute_from_mesh(Mesh& mesh) { |
| 10 | const size_t num_voxels = mesh.get_num_voxels(); |
| 11 | const size_t vertex_per_voxel = mesh.get_vertex_per_voxel(); |
| 12 | if (vertex_per_voxel != 4) { |
| 13 | throw NotImplementedError("Only tet mesh is supported for voxel_face_index"); |
| 14 | } |
| 15 | |
| 16 | mesh.enable_voxel_connectivity(); |
| 17 | |
| 18 | auto& indices = m_values; |
| 19 | indices.resize(num_voxels * 4); |
| 20 | indices.setConstant(-1.0); |
| 21 | |
| 22 | const auto& faces = mesh.get_faces(); |
| 23 | const auto& voxels = mesh.get_voxels(); |
| 24 | for (size_t i=0; i<num_voxels; i++) { |
| 25 | const Vector4I voxel = voxels.segment<4>(i*4); |
| 26 | const auto& adj_faces = mesh.get_voxel_adjacent_faces(i); |
| 27 | const size_t num_adj_faces = adj_faces.size(); |
| 28 | for (size_t j=0; j<num_adj_faces; j++) { |
| 29 | const Vector3I f = faces.segment<3>(adj_faces[j]*3); |
| 30 | if (voxel[0] != f[0] && |
| 31 | voxel[0] != f[1] && |
| 32 | voxel[0] != f[2]) { |
| 33 | indices[i*4] = adj_faces[j]; |
| 34 | } else if (voxel[1] != f[0] && |
| 35 | voxel[1] != f[1] && |
| 36 | voxel[1] != f[2]) { |
| 37 | indices[i*4+1] = adj_faces[j]; |
| 38 | } else if (voxel[2] != f[0] && |
| 39 | voxel[2] != f[1] && |
| 40 | voxel[2] != f[2]) { |
| 41 | indices[i*4+2] = adj_faces[j]; |
| 42 | } else if (voxel[3] != f[0] && |
| 43 | voxel[3] != f[1] && |
| 44 | voxel[3] != f[2]) { |
| 45 | indices[i*4+3] = adj_faces[j]; |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | } |
nothing calls this directly
no test coverage detected