def __init__(self, triangles, vertices, dtype=np.float64, atol=1e-8, assert_args=True): if isinstance(triangles, basestring): mesh_filename = triangles elif isinstance(vertices, basestring): mesh_filename = vertices else: mesh_filename = None if mesh_filename is not None: self.__polydata__ = vtk_u.load_polydata(mesh_filename) self.__polydata_is_up_to_date__ = True self.__polydata_color_is_scalars__ = None TriMesh.__init__(self, self.get_polydata_triangles(), self.get_polydata_vertices(), dtype=dtype, atol=atol, assert_args=assert_args) else: self.__polydata__ = None self.__polydata_is_up_to_date__ = False self.__polydata_color_is_scalars__ = None TriMesh.__init__(self, triangles, vertices, dtype=dtype, atol=atol, assert_args=assert_args)
def set_polydata(self, new_polydata): self.__polydata__ = new_polydata self.__polydata_is_up_to_date__ = True self.__polydata_color_is_scalars__ = None TriMesh.__init__(self, self.get_polydata_triangles(), self.get_polydata_vertices(), dtype=self.__dtype__, atol=self.__atol__)
# by Etienne St-Onge import numpy as np from trimeshpy.trimesh_class import TriMesh import trimeshpy_data triangles = np.load(trimeshpy_data.cube_triangles) vertices = np.load(trimeshpy_data.cube_vertices) tri_mesh = TriMesh(triangles, vertices) print(str(tri_mesh.get_nb_triangles()) + str(tri_mesh.get_nb_vertices())) bool_tests = True current_test = True """CONNECTIVITY MATRIX""" # test vertex connectivity vv_matrix = tri_mesh.edge_map(False) current_test = np.alltrue(vv_matrix.todense() == vv_matrix.T.todense()) print(str(current_test) + ": connectivity is symmetric") bool_tests = bool_tests and current_test # test triangles vertex connectivity tv_matrix = tri_mesh.triangle_vertex_map() nb_triangles_per_points = tri_mesh.nb_triangles_per_vertex() current_test = np.alltrue(tv_matrix.sum(1) == 3) print(str(current_test) + ": triangles have 3 vertices") bool_tests = bool_tests and current_test # test weighted vertex connectivity w_vv_matrix = tri_mesh.edge_map(True) current_test = np.alltrue(w_vv_matrix.todense() == w_vv_matrix.T.todense())
# by [email protected] import numpy as np from trimeshpy.trimesh_class import TriMesh from trimeshpy.trimesh_vtk import TriMesh_Vtk file_name = "../data/test_mesh/cube_simple.obj" #file_name = "../data/test_mesh/sphere.obj" #file_name = "../data/test_mesh/torus.obj" mesh = TriMesh_Vtk(file_name, None) triangles = mesh.get_triangles() vertices = mesh.get_vertices() tri_mesh = TriMesh(triangles, vertices) print tri_mesh.get_nb_triangles(), tri_mesh.get_nb_vertices() bool_tests = True current_test = True """CONNECTIVITY MATRIX""" # test vertex connectivity vv_matrix = tri_mesh.edge_map(False) current_test = np.alltrue(vv_matrix.todense() == vv_matrix.T.todense()) print current_test, ": connectivity is symmetric" bool_tests = bool_tests and current_test # test triangles vertex connectivity tv_matrix = tri_mesh.triangle_vertex_map() nb_triangles_per_points = tri_mesh.nb_triangles_per_vertex() current_test = np.alltrue(tv_matrix.sum(1) == 3)
def set_vertices(self, vertices): TriMesh.set_vertices(self, vertices) self.__polydata_is_up_to_date__ = False
def set_triangles(self, triangles): TriMesh.set_triangles(self, triangles) self.__polydata_is_up_to_date__ = False