本文整理汇总了Python中vtk.vtkSTLReader函数的典型用法代码示例。如果您正苦于以下问题:Python vtkSTLReader函数的具体用法?Python vtkSTLReader怎么用?Python vtkSTLReader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkSTLReader函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:jcdinis,项目名称:POMES,代码行数:31,代码来源:app.py
示例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()
开发者ID:fvpolpeta,项目名称:devide,代码行数:26,代码来源:stlRDR.py
示例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
开发者ID:mathLab,项目名称:EZyRB,代码行数:27,代码来源:stlhandler.py
示例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
开发者ID:uschille,项目名称:hemelb,代码行数:26,代码来源:SurfaceIntersectionFinder.py
示例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
开发者ID:teracamo,项目名称:vtkSemiUniformGridding,代码行数:31,代码来源:PolyDataHandler.py
示例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
开发者ID:mgenet,项目名称:myVTKPythonLibrary,代码行数:28,代码来源:readPData.py
示例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
开发者ID:dgmato,项目名称:LIAC-Guidance,代码行数:35,代码来源:SordinaLIAC.py
示例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)
开发者ID:GearsAD,项目名称:semisorted_arnerve,代码行数:29,代码来源:Hand.py
示例9: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkSTLReader(), 'Reading vtkSTL.',
(), ('vtkSTL',),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
开发者ID:fvpolpeta,项目名称:devide,代码行数:7,代码来源:vtkSTLReader.py
示例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"
开发者ID:rogertrullo,项目名称:Surface_Segmentation,代码行数:33,代码来源:Surface_Utilities.py
示例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.
开发者ID:ImageGuidedTherapyLab,项目名称:FileConversionScripts,代码行数:30,代码来源:convertSTLVTKImage.py
示例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()
开发者ID:StongeEtienne,项目名称:trimeshpy,代码行数:30,代码来源:vtk_util.py
示例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)
开发者ID:Andrew-AbiMansour,项目名称:PyDEM,代码行数:31,代码来源:visualize.py
示例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()
开发者ID:CognitionGuidedSurgery,项目名称:msml,代码行数:32,代码来源:msmlvtk.py
示例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)
开发者ID:Aaronhuu,项目名称:VTK-A-Medical-CAD-System,代码行数:29,代码来源:gui.py
示例16: readMeshFile
def readMeshFile(filename, verbose=False):
"""Read mesh file.
The input format is determined by file name extension. Degenerate data gets
removed and polygons get split into triangles to support varios restrictive
output formats."""
informat = path.splitext(options.infilename)[1].strip('.')
# set reader based on filename extension
if informat=='stl':
reader = vtk.vtkSTLReader()
elif informat=='vtk':
reader = vtk.vtkPolyDataReader()
elif informat=='obj':
reader = vtk.vtkMNIObjectReader()
#elif informat=='tag':
# reader = vtk.vtkMNITagPointReader()
else:
raise ValueError('cannot read input format' + informat)
reader.SetFileName(filename)
# merge duplicate points, and/or remove unused points and/or remove degenerate cells
clean = vtk.vtkCleanPolyData()
clean.SetInputConnection(reader.GetOutputPort())
# convert input polygons and strips to triangles
triangles = vtk.vtkTriangleFilter()
triangles.SetInputConnection(clean.GetOutputPort())
#triangles = reader.GetOutputPort() # skipping above 'cleaning' doesn't work
if verbose:
print "read", filename
return triangles
开发者ID:steelec,项目名称:minc-scripts,代码行数:33,代码来源:vtk_meshconvert.py
示例17: parse
def parse(self, filename):
"""
Method to parse the `filename`. It returns a matrix with all the
coordinates.
:param string filename: name of the input file.
:return: mesh_points: it is a `n_points`-by-3 matrix containing the
coordinates of the points of the mesh
:rtype: numpy.ndarray
"""
self._check_filename_type(filename)
self._check_extension(filename)
self.infile = filename
reader = vtk.vtkSTLReader()
reader.SetFileName(self.infile)
reader.Update()
data = reader.GetOutput()
n_points = data.GetNumberOfPoints()
mesh_points = np.zeros([n_points, 3])
for i in range(n_points):
mesh_points[i][0], mesh_points[i][1], mesh_points[i][
2] = data.GetPoint(i)
return mesh_points
开发者ID:mathLab,项目名称:PyGeM,代码行数:29,代码来源:stlhandler.py
示例18: readSTL
def readSTL(filename):
''' Returns a VTK Reader instance for the file type. '''
reader = vtk.vtkSTLReader()
reader.SetFileName(filename)
reader.Update()
return reader
开发者ID:behollis,项目名称:DBSViewer,代码行数:7,代码来源:dbsUtils.py
示例19: CreateSurfaceFromFile
def CreateSurfaceFromFile(self, filename):
scalar = False
if filename.lower().endswith('.stl'):
reader = vtk.vtkSTLReader()
elif filename.lower().endswith('.ply'):
reader = vtk.vtkPLYReader()
elif filename.lower().endswith('.obj'):
reader = vtk.vtkOBJReader()
elif filename.lower().endswith('.vtp'):
reader = vtk.vtkXMLPolyDataReader()
scalar = True
else:
wx.MessageBox(_("File format not reconized by InVesalius"), _("Import surface error"))
return
if _has_win32api:
reader.SetFileName(win32api.GetShortPathName(filename).encode(const.FS_ENCODE))
else:
reader.SetFileName(filename.encode(const.FS_ENCODE))
reader.Update()
polydata = reader.GetOutput()
if polydata.GetNumberOfPoints() == 0:
wx.MessageBox(_("InVesalius was not able to import this surface"), _("Import surface error"))
else:
name = os.path.splitext(os.path.split(filename)[-1])[0]
self.CreateSurfaceFromPolydata(polydata, name=name, scalar=scalar)
开发者ID:invesalius,项目名称:invesalius3,代码行数:28,代码来源:surface.py
示例20: __init__
def __init__(self, renderers, name):
'''
Initialize the bot model.
'''
# Call the parent constructor
super(RoverBot,self).__init__(renderers)
filename = "../scene/media/rover.stl"
self.__name = name
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.Scale(0.05, 0.05, 0.05)
trans.RotateX(-90)
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)
# Set up all the children for this model
self.__setupChildren(renderers)
# Set it to [0,0,0] so that it updates all the children
self.SetSceneObjectPosition([0, 0, 0])
开发者ID:GearsAD,项目名称:semisorted_arnerve,代码行数:34,代码来源:RoverBot.py
注:本文中的vtk.vtkSTLReader函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论