def test01(): s = tvtk.STLReader(file_name="python.stl") m = tvtk.PolyDataMapper(input_connection=s.output_port) a = tvtk.Actor(mapper = m) win = ivtk_scene(a) win.scene.isometric_view() event_loop()
def __reader_dict_default(self): """Default value for reader dict.""" rd = {'stl':tvtk.STLReader(), 'stla':tvtk.STLReader(), 'stlb':tvtk.STLReader(), 'txt':tvtk.SimplePointsReader(), 'raw':tvtk.ParticleReader(), 'ply':tvtk.PLYReader(), 'pdb':tvtk.PDBReader(), 'slc':tvtk.SLCReader(), 'xyz':tvtk.XYZMolReader(), 'obj':tvtk.OBJReader(), 'facet':tvtk.FacetReader(), 'cube':tvtk.GaussianCubeReader(), 'g':tvtk.BYUReader(), } return rd
def View(self): if self.bouton_OK["fg"] == 'green': reader = tvtk.STLReader() reader.file_name = self.STL reader.update() surf = reader.output mlab.pipeline.surface(surf) mlab.show() k = 0 else: self.bouton_OK["fg"] = 'red'
def test7(self): s = tvtk.STLReader(file_name="E:/mesh.stl") # 调用stl文件 m = tvtk.PolyDataMapper(input_connection=s.output_port) a = tvtk.Actor(mapper=m) # win=ivtk.IVTKWithCrust() # win=ivtk.IVTK() win = ivtk.IVTKWithCrustAndBrowser() win.open() win.scene.add_actor(a) win.scene.isometric_view() dialog = win.control.centralWidget().widget(0).widget(0) from pyface.qt import QtCore dialog.setWindowFlags(QtCore.Qt.WindowFlags(0x00000000)) dialog.show() gui = GUI() gui.start_event_loop()
from tvtk.api import tvtk from tvtkfunc import ivtk_scene, event_loop s = tvtk.STLReader(file_name="python.stl") m = tvtk.PolyDataMapper(input_connection=s.output_port) a = tvtk.Actor(mapper=m) win = ivtk_scene(a) win.scene.isometric_view() event_loop()
def flip_normals(stl_fname): # reading the stl file and getting the triangle data reader = tvtk.STLReader() reader.file_name = stl_fname reader.update() ordering = [] polydata = reader.output points = polydata.points.to_array() x, y, z = points.T data = polydata.polys.to_array() data.shape = data.size // 4, 4 ordering = np.delete(data, 0, 1) # getting normal data of the stl file normals = tvtk.PolyDataNormals() configure_input(normals, polydata) normals.compute_point_normals = 0 normals.compute_cell_normals = 1 normals.update() polydata_normals = normals.output u, v, w = polydata_normals.cell_data.normals.to_array().T fig = mlab.figure(bgcolor=(0, 0, 0)) # renders the given stl file triangles = mlab.triangular_mesh(x, y, z, ordering, figure=fig, opacity=0.6) # coordinates of centroids of the trianlges centroids = np.sum(points[ordering], axis=1) / 3 centroids_x, centroids_y, centroids_z = centroids.T # renders normals at centroids normals = mlab.quiver3d(centroids_x, centroids_y, centroids_z, u, v, w, figure=fig) centroids = mlab.points3d(centroids_x, centroids_y, centroids_z, color=(0.2, 0.6, 0.1), resolution=15) outline = mlab.outline(line_width=3) outline.outline_mode = "cornered" outline_size = centroids.glyph.glyph_source.glyph_source.radius * 0.3 outline.bounds = (centroids_x[0] - outline_size, centroids_x[0] + outline_size, centroids_y[0] - outline_size, centroids_y[0] + outline_size, centroids_z[0] - outline_size, centroids_z[0] + outline_size) ########################################################################### # refer to examples/mayavi/data_interaction/select_red_balls.py for # detailed information on using the callback glyph_normals = centroids.glyph.glyph_source.glyph_source.output.points.\ to_array() def picker_callback(picker): if picker.actor in centroids.actor.actors: centroid_id = picker.point_id // glyph_normals.shape[0] if centroid_id != -1: x, y, z = centroids_x[centroid_id], centroids_y[centroid_id], \ centroids_z[centroid_id] u[centroid_id], v[centroid_id], w[centroid_id] = \ -1*u[centroid_id], -1*v[centroid_id], -1*w[centroid_id] normals.mlab_source.set(u=u, v=v, w=w) outline.bounds = (x - outline_size, x + outline_size, y - outline_size, y + outline_size, z - outline_size, z + outline_size) picker = fig.on_mouse_pick(picker_callback) picker.tolerance = 0.01 mlab.title("Click on centroid to invert normal", color=(1, 1, 1), figure=fig)
import sys from tvtk.api import tvtk from bem.triangulation import Mesh from bem.formats.stl import read_stl, stl_to_mesh, check_normals from bem.formats.cpy import split_by_normal s = tvtk.STLReader(file_name=sys.argv[1]) s.update() m, d = Mesh.from_polydata(s.output) #print m, d #print m.points #print m.triangles #print m.points[m.triangles, :] r = read_stl(open(sys.argv[1], "rb")) check_normals(*r[:2]) r = stl_to_mesh(*r) del r["stl_0"] print r.keys() r = split_by_normal(r) m = Mesh.from_mesh(r) m.triangulate("qQ") m.to_vtk("test") #print m