本文整理汇总了Python中vtk.vtkSTLReader函数的典型用法代码示例。如果您正苦于以下问题:Python vtkSTLReader函数的具体用法?Python vtkSTLReader怎么用?Python vtkSTLReader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkSTLReader函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LerSTL
def LerSTL(self, path):
mesh= vtk.vtkSTLReader()
mesh.SetFileName(path)
mesh.Update()
#self.pd = mesh.GetOutput()
self.polydata = mesh.GetOutput()
normals = vtk.vtkPolyDataNormals()
#normals.SetInput(polydata)
normals.SetInputData(mesh.GetOutput())
normals.ComputeCellNormalsOn()
normals.Update()
#mudanças para aumentar a normal
self.vertices =pontos(normals.GetOutput())
self.normalsp = get_normals(normals.GetOutput())
stlMapper = vtk.vtkPolyDataMapper()
stlMapper.SetInputConnection(normals.GetOutputPort())
stlActor = vtk.vtkLODActor()
stlActor.SetMapper(stlMapper)
self.renderer.AddActor(stlActor)
self.Interactor.Render()
示例2: __init__
def __init__(self, module_manager):
"""Constructor (initialiser) for the PD reader.
This is almost standard code for most of the modules making use of
the FilenameViewModuleMixin mixin.
"""
# call the constructor in the "base"
ModuleBase.__init__(self, module_manager)
# setup necessary VTK objects
self._reader = vtk.vtkSTLReader()
# ctor for this specific mixin
FilenameViewModuleMixin.__init__(
self,
'Select a filename',
'STL data (*.stl)|*.stl|All files (*)|*',
{'vtkSTLReader': self._reader})
module_utils.setup_vtk_object_progress(self, self._reader,
'Reading STL data')
# set up some defaults
self._config.filename = ''
self.sync_module_logic_with_config()
示例3: _read_polydata
def _read_polydata(self):
"""
This private method reads the given `filename` and return a vtkPolyData
object containing all informations about file; to avoid useless IO
operation on the same file, it stores polydata of the last file parsed
and if user ask for this file, the polydata previously stored is
returned.
:return: polydata containing information about file.
:rtype: vtkPolyData
"""
# Polydata from `filename` is already loaded; return it
if self._cached_data is not None:
return self._cached_polydata
if not os.path.isfile(self._filename):
raise RuntimeError("{0!s} doesn't exist".format(
os.path.abspath(self._filename)))
reader = vtk.vtkSTLReader()
reader.SetFileName(self._filename)
reader.Update()
data = reader.GetOutput()
self._cached_data = data
return data
示例4: __init__
def __init__(self):
"""Setup the pipeline.
"""
self.reader = vtkSTLReader()
self.cutter = vtkCutter()
self.cutter.SetInputConnection(self.reader.GetOutputPort())
self.regionPicker = vtkPolyDataConnectivityFilter()
self.regionPicker.SetInputConnection(self.cutter.GetOutputPort())
self.regionPicker.SetExtractionModeToClosestPointRegion()
self.scaler = vtkTransformPolyDataFilter()
self.scaler.SetInputConnection(self.regionPicker.GetOutputPort())
self.GetFileName = self.reader.GetFileName
self.SetFileName = self.reader.SetFileName
self.GetOutputPort = self.scaler.GetOutputPort
self.GetOutput = self.scaler.GetOutput
self.Update = self.scaler.Update
self.iolet = None
self.fileUnitLength = None
return
示例5: Read
def Read(self, m_forceRead=False):
"""
Initial step, should be performed before everything else starts, considering to add
this into the class constructor so that it is read automatically.
:return:
"""
# Skip redundant read if it is already done
if self._IS_READ_FLAG and not m_forceRead:
return
if self.filename.split(".")[-1] == "vtp" or self.filename.split(".")[-1] == "vtk":
m_reader = vtk.vtkXMLPolyDataReader()
elif self.filename.split(".")[-1] == "stl":
m_reader = vtk.vtkSTLReader()
else:
raise IOError("Input file for arm surface is of incorrect format")
m_reader.SetFileName(self.filename)
m_reader.Update()
m_mapper = vtk.vtkPolyDataMapper()
m_mapper.SetInputConnection(m_reader.GetOutputPort())
m_actor = vtk.vtkActor()
m_actor.SetMapper(m_mapper)
self._reader = m_reader
self._renderer.AddActor(m_actor)
self._data = m_reader.GetOutput()
self._IS_READ_FLAG = True
pass
示例6: readPData
def readPData(
filename,
verbose=0):
mypy.my_print(verbose, "*** readPData: "+filename+" ***")
assert (os.path.isfile(filename)), "Wrong filename (\""+filename+"\"). Aborting."
if (filename.endswith('vtk')):
pdata_reader = vtk.vtkPolyDataReader()
elif (filename.endswith('vtp')):
pdata_reader = vtk.vtkXMLPolyDataReader()
elif (filename.endswith('stl')):
pdata_reader = vtk.vtkSTLReader()
else:
assert 0, "File must be .vtk, .vtp or .stl. Aborting."
pdata_reader.SetFileName(filename)
pdata_reader.Update()
pdata = pdata_reader.GetOutput()
mypy.my_print(verbose-1, "n_points = "+str(pdata.GetNumberOfPoints()))
mypy.my_print(verbose-1, "n_verts = "+str(pdata.GetNumberOfVerts()))
mypy.my_print(verbose-1, "n_lines = "+str(pdata.GetNumberOfLines()))
mypy.my_print(verbose-1, "n_polys = "+str(pdata.GetNumberOfPolys()))
mypy.my_print(verbose-1, "n_strips = "+str(pdata.GetNumberOfStrips()))
return pdata
示例7: SetObjective
def SetObjective(self, ApplicatorObjetiveInOpticalCoordinates):
if self.calibrated:
# Save the Transformation Goal
self.ApplicatorObjetiveAxis = ApplicatorObjetiveInOpticalCoordinates.copy()
self.ApplicatorObjetiveAxis = numpy.dot(self.TWorldToOptical,self.ApplicatorObjetiveAxis)
self.ApplicatorObjetive = vtk.vtkTransform()
self.ApplicatorObjetive.SetMatrix([self.ApplicatorObjetiveAxis[0,0],self.ApplicatorObjetiveAxis[0,1],self.ApplicatorObjetiveAxis[0,2],self.ApplicatorObjetiveAxis[0,3],
self.ApplicatorObjetiveAxis[1,0],self.ApplicatorObjetiveAxis[1,1],self.ApplicatorObjetiveAxis[1,2],self.ApplicatorObjetiveAxis[1,3],
self.ApplicatorObjetiveAxis[2,0],self.ApplicatorObjetiveAxis[2,1],self.ApplicatorObjetiveAxis[2,2],self.ApplicatorObjetiveAxis[2,3],
self.ApplicatorObjetiveAxis[3,0],self.ApplicatorObjetiveAxis[3,1],self.ApplicatorObjetiveAxis[3,2],self.ApplicatorObjetiveAxis[3,3]])
self.ApplicatorObjetiveaxes = vtk.vtkAxesActor()
self.ApplicatorObjetiveaxes.SetUserTransform(self.ApplicatorObjetive)
self.ApplicatorObjetiveaxes.SetXAxisLabelText('X App')
self.ApplicatorObjetiveaxes.SetYAxisLabelText('Y App')
self.ApplicatorObjetiveaxes.SetZAxisLabelText('Z App')
self.ApplicatorObjetiveaxes.SetTotalLength(0.2,0.2,0.2)
self.STLReaderApplicator = vtk.vtkSTLReader()
self.STLReaderApplicator.SetFileName(self.pathToModelApplicator)
self.STLReaderApplicator.Update()
self.mapperApplicator = vtk.vtkPolyDataMapper()
self.mapperApplicator.SetInputConnection(self.STLReaderApplicator.GetOutputPort())
self.modelActorApplicator = vtk.vtkActor()
self.modelActorApplicator.SetMapper(self.mapperApplicator)
self.modelActorApplicator.SetUserTransform(self.ApplicatorObjetive)
self.modelActorApplicator.GetProperty().SetColor(0,1,0)
self.modelActorApplicator.GetProperty().SetOpacity(0.5)
self.objetiveFixed = True
示例8: __init__
def __init__(self, renderers, isRightHand):
'''
Initialize the user model.
'''
# Call the parent constructor
super(Hand,self).__init__(renderers)
filename = "../scene/media/rhand.stl"
reader = vtk.vtkSTLReader()
reader.SetFileName(filename)
# Do the internal transforms to make it look along unit-z, do it with a quick transform
trans = vtk.vtkTransform()
trans.RotateZ(180)
if isRightHand == False: #Flip with a horizontal flip using a -1 scale
trans.Scale([-1, 1, 1])
transF = vtk.vtkTransformPolyDataFilter()
transF.SetInputConnection(reader.GetOutputPort())
transF.SetTransform(trans)
self.__mapper = vtk.vtkPolyDataMapper()
#if vtk.VTK_MAJOR_VERSION <= 5:
# self.__mapper.SetInput(reader.GetOutput())
#else:
self.__mapper.SetInputConnection(transF.GetOutputPort())
self.vtkActor.SetMapper(self.__mapper)
示例9: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkSTLReader(), 'Reading vtkSTL.',
(), ('vtkSTL',),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
示例10: Decimate_mesh
def Decimate_mesh(meshvtk,name_vtkmesh,nvertices=2000):
print 'test'
stlWriter = vtk.vtkSTLWriter()
stlWriter.SetFileName('meshdecimated.stl')
stlWriter.SetInputData(meshvtk)
stlWriter.Write()
mesh_om = om.PolyMesh()
Result=om.read_mesh(mesh_om, "meshdecimated.stl")
print Result
deci_om=om.PolyMeshDecimater(mesh_om)
mh=om.PolyMeshModQuadricHandle()
deci_om.add(mh)
deci_om.initialize()
deci_om.decimate_to(nvertices)
mesh_om.garbage_collection()
assert mesh_om.n_vertices()==nvertices, 'vertices goal not acomplished; nvertices={0:d}'.format(mesh_om.n_vertices())
print "Decimation to {0} vertices Sucessful".format(nvertices)
om.write_mesh(mesh_om,'meshdecimated.stl')
stlReader = vtk.vtkSTLReader()
stlReader.SetFileName('meshdecimated.stl')
stlReader.Update()
vtkwrite=vtk.vtkPolyDataWriter()
vtkwrite.SetInputData(stlReader.GetOutput())
vtkwrite.SetFileName(name_vtkmesh)
vtkwrite.Write()
print "enters"
示例11: __init__
def __init__(self,InputImageFileName ):
print " class constructor called \n\n"
# damage paramters
# open stl and extract VOI for a reference
stlReader = vtk.vtkSTLReader()
stlReader.SetFileName( InputImageFileName )
stlReader.Update()
self.stlData = stlReader.GetOutput()
stlpoints = self.stlData.GetPoints()
# VOI Origin should be at the lower bound
VOIBounds = self.stlData.GetBounds()
self.origin = (VOIBounds[0]-1.,VOIBounds[2]-1.,VOIBounds[4]-1.)
self.dimensions = (256,256,100,1)
self.spacing = ((VOIBounds[1]+1. - self.origin[0])/self.dimensions[0],
(VOIBounds[3]+1. - self.origin[1])/self.dimensions[1],
(VOIBounds[5]+1. - self.origin[2])/self.dimensions[2])
numpyimagesize = self.dimensions[0]*self.dimensions[1]*self.dimensions[2]
# store as double precision
self.ImageFile = numpy.zeros( numpyimagesize, dtype=numpy.float32 )
for ipoint in range(stlpoints.GetNumberOfPoints() ):
CurrentPoint = stlpoints.GetPoint(ipoint)
XIndex = int( ( CurrentPoint[0]-self.origin[0])/ self.spacing[0] )
YIndex = int( ( CurrentPoint[1]-self.origin[1])/ self.spacing[1] )
ZIndex = int( ( CurrentPoint[2]-self.origin[2])/ self.spacing[2] )
CurrentIndex = XIndex \
+ YIndex * self.dimensions[0] \
+ ZIndex * self.dimensions[0] * self.dimensions[1]
self.ImageFile[CurrentIndex ] = 1.
示例12: load_polydata
def load_polydata(file_name):
# get file extension (type)
file_extension = file_name.split(".")[-1].lower()
# todo better generic load
if file_extension == "vtk":
reader = vtk.vtkPolyDataReader()
elif file_extension == "vtp":
reader = vtk.vtkPolyDataReader()
elif file_extension == "fib":
reader = vtk.vtkPolyDataReader()
elif file_extension == "ply":
reader = vtk.vtkPLYReader()
elif file_extension == "stl":
reader = vtk.vtkSTLReader()
elif file_extension == "xml":
reader = vtk.vtkXMLPolyDataReader()
elif file_extension == "obj":
reader = vtk.vtkOBJReader()
#try: # try to read as a normal obj
# reader = vtk.vtkOBJReader()
#except: # than try load a MNI obj format
# reader = vtk.vtkMNIObjectReader()
else:
raise "polydata " + file_extension + " is not suported"
reader.SetFileName(file_name)
reader.Update()
print file_name, " Mesh ", file_extension, "Loaded"
return reader.GetOutput()
示例13: attach_stl
def attach_stl(self, fname, scale=None):
"""Load a given STL file into a vtkPolyData object"""
reader = vtk.vtkSTLReader()
reader.SetFileName(fname)
reader.Update() # polydata
if scale is not None:
trans = vtk.vtkTransform()
trans.Scale(scale)
filt = vtk.vtkTransformFilter()
if vtk.VTK_MAJOR_VERSION <= 5:
filt.SetInputConnection(reader.GetOutputPort)
else:
filt.SetInputConnection(reader.GetOutputPort())
filt.SetTransform(trans)
mapper = vtk.vtkPolyDataMapper()
if vtk.VTK_MAJOR_VERSION <= 5:
mapper.SetInput(filt.GetOutput())
else:
mapper.SetInputConnection(filt.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
self._ren.AddActor(actor)
示例14: view_stl
def view_stl(filename):
"""
http://www.vtk.org/Wiki/VTK/Examples/Python/STLReader
"""
reader = vtk.vtkSTLReader()
reader.SetFileName(filename)
mapper = vtk.vtkPolyDataMapper()
if vtk.VTK_MAJOR_VERSION <= 5:
mapper.SetInput(reader.GetOutput())
else:
mapper.SetInputConnection(reader.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# Create a rendering window and renderer
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
# Create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Assign actor to the renderer
ren.AddActor(actor)
# Enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()
示例15: __init__
def __init__(self, parent = None):
QtGui.QMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ren = vtk.vtkRenderer()
self.ui.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
self.iren = self.ui.vtkWidget.GetRenderWindow().GetInteractor()
filename = "organ.stl"
# Create a reader
reader = vtk.vtkSTLReader()
reader.SetFileName(filename)
# Create a mapper
mapper = vtk.vtkPolyDataMapper()
if vtk.VTK_MAJOR_VERSION <= 5:
mapper.SetInput(reader.GetOutput())
else:
mapper.SetInputConnection(reader.GetOutputPort())
# Create an actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.RotateX(-90)
self.ren.AddActor(actor)