| 12 | using namespace PyMesh; |
| 13 | |
| 14 | void MMGEngine::run() { |
| 15 | constexpr Float EPS = 0.1; |
| 16 | const Vector3F bbox_min = m_vertices.colwise().minCoeff().array() - EPS; |
| 17 | const Vector3F bbox_max = m_vertices.colwise().maxCoeff().array() + EPS; |
| 18 | |
| 19 | MatrixFr cube_vertices(8, 3); |
| 20 | cube_vertices << |
| 21 | bbox_min[0], bbox_min[1], bbox_min[2], |
| 22 | bbox_max[0], bbox_min[1], bbox_min[2], |
| 23 | bbox_max[0], bbox_max[1], bbox_min[2], |
| 24 | bbox_min[0], bbox_max[1], bbox_min[2], |
| 25 | bbox_min[0], bbox_min[1], bbox_max[2], |
| 26 | bbox_max[0], bbox_min[1], bbox_max[2], |
| 27 | bbox_max[0], bbox_max[1], bbox_max[2], |
| 28 | bbox_min[0], bbox_max[1], bbox_max[2]; |
| 29 | MatrixIr cube_faces(12, 3); |
| 30 | cube_faces << 0, 2, 1, |
| 31 | 0, 3, 2, |
| 32 | 4, 5, 6, |
| 33 | 4, 6, 7, |
| 34 | 1, 2, 6, |
| 35 | 1, 6, 5, |
| 36 | 0, 4, 7, |
| 37 | 0, 7, 3, |
| 38 | 0, 1, 5, |
| 39 | 0, 5, 4, |
| 40 | 2, 3, 6, |
| 41 | 6, 3, 7; |
| 42 | |
| 43 | // Use the volume of regular tetrahedron of radius m_cell_size as max |
| 44 | // volume. |
| 45 | const Float max_tet_volume = 0.1 * 8 * pow(m_cell_size, 3) / (9 * sqrt(3)); |
| 46 | |
| 47 | // Generate ambient mesh. |
| 48 | TetgenWrapper tetgen; |
| 49 | tetgen.set_points(cube_vertices); |
| 50 | tetgen.set_triangles(cube_faces); |
| 51 | tetgen.set_max_tet_volume(max_tet_volume); |
| 52 | tetgen.set_verbosity(0); |
| 53 | tetgen.run(); |
| 54 | |
| 55 | auto ambient_vertices = tetgen.get_vertices(); |
| 56 | auto ambient_tets = tetgen.get_voxels(); |
| 57 | ambient_tets.array() += 1;// Sigh... one based index. |
| 58 | const size_t num_ambient_vertices = ambient_vertices.rows(); |
| 59 | const size_t num_ambient_tets = ambient_tets.rows(); |
| 60 | const size_t num_faces = m_faces.rows(); |
| 61 | |
| 62 | VectorI vertex_refs(num_ambient_vertices); |
| 63 | VectorI tet_refs(num_ambient_tets); |
| 64 | vertex_refs.setZero(); |
| 65 | tet_refs.setZero(); |
| 66 | |
| 67 | // Compute signed distance function |
| 68 | VectorF s; |
| 69 | VectorI face_ids; |
| 70 | MatrixF closest_pts, normals; |
| 71 | igl::signed_distance(ambient_vertices, m_vertices, m_faces, |
nothing calls this directly
no test coverage detected