def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkFacetReader(), 'Reading vtkFacet.', (), ('vtkFacet',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def _load_file(filename, c, alpha, threshold, spacing, unpack): fl = filename.lower() ################################################################# other formats: if fl.endswith(".xml") or fl.endswith(".xml.gz") or fl.endswith(".xdmf"): # Fenics tetrahedral file actor = loadDolfin(filename) elif fl.endswith(".neutral") or fl.endswith(".neu"): # neutral tetrahedral file actor = loadNeutral(filename) elif fl.endswith(".gmsh"): # gmesh file actor = loadGmesh(filename) elif fl.endswith(".pcd"): # PCL point-cloud format actor = loadPCD(filename) actor.GetProperty().SetPointSize(2) elif fl.endswith(".off"): actor = loadOFF(filename) elif fl.endswith(".3ds"): # 3ds format actor = load3DS(filename) elif fl.endswith(".wrl"): importer = vtk.vtkVRMLImporter() importer.SetFileName(filename) importer.Read() importer.Update() actors = importer.GetRenderer().GetActors() #vtkActorCollection actors.InitTraversal() wacts = [] for i in range(actors.GetNumberOfItems()): act = actors.GetNextActor() wacts.append(act) actor = Assembly(wacts) ################################################################# volumetric: elif fl.endswith(".tif") or fl.endswith(".slc") or fl.endswith(".vti") \ or fl.endswith(".mhd") or fl.endswith(".nrrd") or fl.endswith(".nii") \ or fl.endswith(".dem"): img = loadImageData(filename, spacing) if threshold is False: if c is None and alpha == 1: c = ['b','lb','lg','y','r'] # good for blackboard background alpha = (0.0, 0.0, 0.2, 0.4, 0.8, 1) actor = Volume(img, c, alpha) else: actor = Volume(img).isosurface(threshold=threshold) actor.color(c).alpha(alpha) ################################################################# 2D images: elif fl.endswith(".png") or fl.endswith(".jpg") or fl.endswith(".bmp") or fl.endswith(".jpeg"): if ".png" in fl: picr = vtk.vtkPNGReader() elif ".jpg" in fl or ".jpeg" in fl: picr = vtk.vtkJPEGReader() elif ".bmp" in fl: picr = vtk.vtkBMPReader() picr.SetFileName(filename) picr.Update() actor = Picture() # object derived from vtk.vtkImageActor() actor.SetInputData(picr.GetOutput()) if alpha is None: alpha = 1 actor.SetOpacity(alpha) ################################################################# multiblock: elif fl.endswith(".vtm") or fl.endswith(".vtmb"): read = vtk.vtkXMLMultiBlockDataReader() read.SetFileName(filename) read.Update() mb = read.GetOutput() if unpack: acts = [] for i in range(mb.GetNumberOfBlocks()): b = mb.GetBlock(i) if isinstance(b, (vtk.vtkPolyData, vtk.vtkImageData, vtk.vtkUnstructuredGrid, vtk.vtkStructuredGrid, vtk.vtkRectilinearGrid)): acts.append(b) return acts else: return mb ################################################################# numpy: elif fl.endswith(".npy"): acts = loadNumpy(filename) if unpack == False: return Assembly(acts) return acts elif fl.endswith(".geojson") or fl.endswith(".geojson.gz"): return loadGeoJSON(fl) ################################################################# polygonal mesh: else: if fl.endswith(".vtk"): # read all legacy vtk types #output can be: # PolyData, StructuredGrid, StructuredPoints, UnstructuredGrid, RectilinearGrid reader = vtk.vtkDataSetReader() reader.ReadAllScalarsOn() reader.ReadAllVectorsOn() reader.ReadAllTensorsOn() reader.ReadAllFieldsOn() reader.ReadAllNormalsOn() reader.ReadAllColorScalarsOn() elif fl.endswith(".ply"): reader = vtk.vtkPLYReader() elif fl.endswith(".obj"): reader = vtk.vtkOBJReader() elif fl.endswith(".stl"): reader = vtk.vtkSTLReader() elif fl.endswith(".byu") or fl.endswith(".g"): reader = vtk.vtkBYUReader() elif fl.endswith(".foam"): # OpenFoam reader = vtk.vtkOpenFOAMReader() elif fl.endswith(".pvd"): reader = vtk.vtkXMLGenericDataObjectReader() elif fl.endswith(".vtp"): reader = vtk.vtkXMLPolyDataReader() elif fl.endswith(".vts"): reader = vtk.vtkXMLStructuredGridReader() elif fl.endswith(".vtu"): reader = vtk.vtkXMLUnstructuredGridReader() elif fl.endswith(".vtr"): reader = vtk.vtkXMLRectilinearGridReader() elif fl.endswith(".pvtk"): reader = vtk.vtkPDataSetReader() elif fl.endswith(".pvtr"): reader = vtk.vtkXMLPRectilinearGridReader() elif fl.endswith("pvtu"): reader = vtk.vtkXMLPUnstructuredGridReader() elif fl.endswith(".txt") or fl.endswith(".xyz"): reader = vtk.vtkParticleReader() # (format is x, y, z, scalar) elif fl.endswith(".facet"): reader = vtk.vtkFacetReader() else: return None reader.SetFileName(filename) reader.Update() routput = reader.GetOutput() if not routput: colors.printc("~noentry Unable to load", filename, c=1) return None actor = Actor(routput, c, alpha) if fl.endswith(".txt") or fl.endswith(".xyz"): actor.GetProperty().SetPointSize(4) actor.filename = filename return actor
import vtk import sys, os from math import * reader = vtk.vtkFacetReader() reader.SetFileName("edges") edges = reader.GetOutput() edges.Update() edgesmapper = vtk.vtkDataSetMapper() edgesmapper.SetInput(edges) edgesactor = vtk.vtkActor() edgesactor.SetMapper(edgesmapper) edgesactor.GetProperty().SetRepresentationToWireframe() #edgesactor.GetProperty().SetColor(0,0,0) edgesactor.GetProperty().SetLineWidth(3) reader2 = vtk.vtkFacetReader() reader2.SetFileName("tri") poly = reader2.GetOutput() poly.Update() polymapper = vtk.vtkDataSetMapper() polymapper.SetInput(poly) polyactor = vtk.vtkActor() polyactor.SetMapper(polymapper) polyactor.GetProperty().SetRepresentationToWireframe() #polyactor.GetProperty().SetColor(0,0,0) polyactor.GetProperty().SetLineWidth(3) # axes actor
def lazy_vtkFacetReader(): """Lazy import of the vtkFacetReader.""" return vtk.vtkFacetReader()
#!/usr/bin/env python import vtk from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() ren1 = vtk.vtkRenderer() ren1.SetBackground(0,0,0) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) renWin.SetSize(300,300) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) facet0 = vtk.vtkFacetReader() facet0.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/clown.facet") Mapper5 = vtk.vtkPolyDataMapper() Mapper5.SetInputConnection(facet0.GetOutputPort()) Mapper5.UseLookupTableScalarRangeOff() Mapper5.SetScalarVisibility(1) Mapper5.SetScalarModeToDefault() Actor5 = vtk.vtkLODActor() Actor5.SetMapper(Mapper5) Actor5.GetProperty().SetRepresentationToSurface() Actor5.GetProperty().SetInterpolationToGouraud() Actor5.GetProperty().SetAmbient(0.15) Actor5.GetProperty().SetDiffuse(0.85) Actor5.GetProperty().SetSpecular(0.1) Actor5.GetProperty().SetSpecularPower(100) Actor5.GetProperty().SetSpecularColor(1,1,1) Actor5.GetProperty().SetColor(1,1,1) Actor5.SetNumberOfCloudPoints(30000) ren1.AddActor(Actor5)
#!/usr/bin/env python import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() ren1 = vtk.vtkRenderer() ren1.SetBackground(0,0,0) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) renWin.SetSize(300,300) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) facet0 = vtk.vtkFacetReader() facet0.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/clown.facet") Mapper5 = vtk.vtkPolyDataMapper() Mapper5.SetInputConnection(facet0.GetOutputPort()) Mapper5.SetImmediateModeRendering(1) Mapper5.UseLookupTableScalarRangeOff() Mapper5.SetScalarVisibility(1) Mapper5.SetScalarModeToDefault() Actor5 = vtk.vtkLODActor() Actor5.SetMapper(Mapper5) Actor5.GetProperty().SetRepresentationToSurface() Actor5.GetProperty().SetInterpolationToGouraud() Actor5.GetProperty().SetAmbient(0.15) Actor5.GetProperty().SetDiffuse(0.85) Actor5.GetProperty().SetSpecular(0.1) Actor5.GetProperty().SetSpecularPower(100) Actor5.GetProperty().SetSpecularColor(1,1,1) Actor5.GetProperty().SetColor(1,1,1)
import vtk import sys, os from math import * reader = vtk.vtkFacetReader() reader.SetFileName("edges") edges = reader.GetOutput() edges.Update() edgesmapper = vtk.vtkDataSetMapper() edgesmapper.SetInput(edges) edgesactor = vtk.vtkActor() edgesactor.SetMapper(edgesmapper) edgesactor.GetProperty().SetRepresentationToWireframe() #edgesactor.GetProperty().SetColor(0,0,0) edgesactor.GetProperty().SetLineWidth(3) reader2 = vtk.vtkFacetReader() reader2.SetFileName("tri") poly = reader2.GetOutput() poly.Update() polymapper = vtk.vtkDataSetMapper() polymapper.SetInput(poly) polyactor = vtk.vtkActor() polyactor.SetMapper(polymapper) polyactor.GetProperty().SetRepresentationToWireframe() #polyactor.GetProperty().SetColor(0,0,0) polyactor.GetProperty().SetLineWidth(3)