def check_duplicated_vertices(self, mesh): dim = mesh.get_dim() num_vertices = mesh.get_num_vertices() num_faces = mesh.get_num_faces() vertex_per_face = mesh.get_vertex_per_face() vertices = mesh.get_vertices().reshape((num_vertices, dim), order="C") faces = mesh.get_faces().reshape((num_faces, vertex_per_face), order="C") vertices[0, :] = vertices[1, :] expected_vertices = np.copy(vertices[1:, :]) expected_faces = np.clip(faces - 1, 0, num_faces) remover = PyMeshUtils.DuplicatedVertexRemoval(vertices, faces) remover.run(self.tol) result_vertices = remover.get_vertices() result_faces = remover.get_faces() index_map = remover.get_index_map() self.assert_matrix_eq(expected_vertices, result_vertices) self.assert_matrix_eq(expected_faces, result_faces) for i_old, i_new in enumerate(index_map): self.assertAlmostEqual( 0.0, norm(vertices[i_old] - result_vertices[i_new]), self.tol)
def _extra_info(self): try: return self.__extra_info except AttributeError: self.__extra_info = PyMeshUtils.MeshChecker( self.vertices_ref, self.faces_ref, self.voxels_ref) return self.__extra_info
def run_remover(self, vertices, faces): remover = PyMeshUtils.IsolatedVertexRemoval(vertices, faces) remover.run() result_vertices = remover.get_vertices() result_faces = remover.get_faces() # Results should be vaid after remover object is deleted. return result_vertices, result_faces
def is_colinear(v0, v1, v2): """ Return true if ``v0``, ``v1`` and ``v2`` are colinear. Colinear check is done using exact predicates. Args: v0 (``numpy.ndarray``): vector of size 2 or 3. v1 (``numpy.ndarray``): vector of size 2 or 3. v2 (``numpy.ndarray``): vector of size 2 or 3. Return: bool: whether ``v0``, ``v1`` and ``v2`` are colinear. """ dim = len(v0) if dim == 2: return PyMeshUtils.is_colinear_2D(v0, v1, v2) elif dim == 3: return PyMeshUtils.is_colinear_3D(v0, v1, v2) else: raise NotImplementedError("Supported dimention {}".format(dim))
def is_colinear(v0, v1, v2): """ Return true if ``v0``, ``v1`` and ``v2`` are colinear. Colinear check is done using exact predicates. Args: v0 (``numpy.ndarray``): vector of size 2 or 3. v1 (``numpy.ndarray``): vector of size 2 or 3. v2 (``numpy.ndarray``): vector of size 2 or 3. Return: bool: whether ``v0``, ``v1`` and ``v2`` are colinear. """ dim = len(v0); if dim == 2: return PyMeshUtils.is_colinear_2D(v0, v1, v2); elif dim == 3: return PyMeshUtils.is_colinear_3D(v0, v1, v2); else: raise NotImplementedError("Supported dimention {}".format(dim));
def test_outside(self): mesh = self.load_mesh("tet.msh"); x = np.linspace(-1.0, 1.0, 10); y = np.linspace(-1.0, 1.0, 10); z = np.linspace(-1.0, 1.0, 10); x_coord, y_coord, z_coord = np.meshgrid(x, y, z); points = np.array([x_coord.ravel(), y_coord.ravel(), z_coord.ravel()]).T; p_locator = PyMeshUtils.PointLocator(mesh); self.assertRaises(RuntimeError, p_locator.locate, points);
def get_degenerated_faces_raw(vertices, faces): """ Return indices of degenerated faces. A face is degenerated if all its 3 corners are colinear. Args: vertices (``numpy.ndarray``): Vertex matrix. faces (``numpy.ndarray``): Face matrix. Returns: ``numpy.ndarray``: List of indices of degenerated faces. """ return np.array(PyMeshUtils.get_degenerated_faces(vertices, faces))
def get_degenerated_faces_raw(vertices, faces): """ Return indices of degenerated faces. A face is degenerated if all its 3 corners are colinear. Args: vertices (``numpy.ndarray``): Vertex matrix. faces (``numpy.ndarray``): Face matrix. Returns: ``numpy.ndarray``: List of indices of degenerated faces. """ return np.array(PyMeshUtils.get_degenerated_faces(vertices, faces));
def test_2D(self): mesh = self.load_mesh("square_2D.obj"); x = np.linspace(-1.0, 1.0, 10); y = np.linspace(-1.0, 1.0, 10); x_coord, y_coord = np.meshgrid(x, y); points = np.array([x_coord.ravel(), y_coord.ravel()]).T; p_locator = PyMeshUtils.PointLocator(mesh); p_locator.locate(points); elem_indices = p_locator.get_enclosing_voxels().ravel(); barycentric_coords = p_locator.get_barycentric_coords(); self.assert_barycentric_coords_are_valid(mesh, elem_indices, barycentric_coords, points);
def convert_to_vertex_attribute_from_name(mesh, name): return PyMeshUtils.convert_to_vertex_attribute_from_name( mesh.raw_mesh, name)
def convert_to_vertex_attribute(mesh, attr): return PyMeshUtils.convert_to_vertex_attribute(mesh.raw_mesh, attr)