当前位置: 首页>>代码示例>>Python>>正文


Python vtk.vtkPolyDataReader函数代码示例

本文整理汇总了Python中vtk.vtkPolyDataReader函数的典型用法代码示例。如果您正苦于以下问题:Python vtkPolyDataReader函数的具体用法?Python vtkPolyDataReader怎么用?Python vtkPolyDataReader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了vtkPolyDataReader函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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

示例2: Merge5

def Merge5 ():
    reader = vtk.vtkPolyDataReader()
    reader.SetFileName('test10.vtk')

    reader2 = vtk.vtkPolyDataReader()
    reader2.SetFileName('test12.vtk')

    reader3 = vtk.vtkPolyDataReader()
    reader3.SetFileName('test13.vtk')

    app = vtk.vtkAppendPolyData()

    app.AddInputConnection(reader.GetOutputPort())

    tr = vtk.vtkTransform()
    tr.Translate(-50.916666, -1.083333, 0)
    tr.RotateZ(90)

    tp = vtk.vtkTransformPolyDataFilter()
    tp.SetTransform(tr)
    tp.SetInputConnection(reader2.GetOutputPort())

    app.AddInputConnection(tp.GetOutputPort())

    tr2 = vtk.vtkTransform()
    tr2.Translate(-50.916666, -1.083333, 0)

    tp2 = vtk.vtkTransformPolyDataFilter()
    tp2.SetTransform(tr2)
    tp2.SetInputConnection(reader3.GetOutputPort())

    app.AddInputConnection(tp2.GetOutputPort())

    return app
开发者ID:zippy84,项目名称:vtkbool,代码行数:34,代码来源:merge_all.py

示例3: test_airway_particles

def test_airway_particles():
  try:
    # Get the path to the this test so that we can reference the test data
    this_dir = os.path.dirname(os.path.realpath(__file__))

    # Set up the inputs to AirwayParticles
    input_ct = this_dir + '/../../../Testing/Data/Input/airwaygauss.nrrd'
    input_mask = this_dir + '/../../../Testing/Data/Input/airwaygauss_mask.nrrd'
      
    #tmp_dir = this_dir + '/../../../Testing/tmp/'
    tmp_dir = tempfile.mkdtemp()
    output_particles = os.path.join(tmp_dir,'airway_particles.vtk')
    print tmp_dir

    max_scale = 6.0
    live_th = 40.0
    seed_th = 30.0
    scale_samples = 5
    down_sample_rate = 1.0
    min_intensity = -1100
    max_intensity = -400

    # Generate the airway particles
    ap = AirwayParticles(input_ct, output_particles, tmp_dir, input_mask,
                         max_scale, live_th, seed_th, scale_samples,
                         down_sample_rate, min_intensity, max_intensity)
    ap.execute()
    
    # Read in the reference data set for comparison
    ref_reader = vtk.vtkPolyDataReader()
    ref_reader.SetFileName(this_dir +
                    '/../../../Testing/Data/Input/airway_particles.vtk')
    ref_reader.Update()

    # Now read in the output data set
    test_reader = vtk.vtkPolyDataReader()
    test_reader.SetFileName(output_particles)
    test_reader.Update()
    
    pm = ParticleMetrics(ref_reader.GetOutput(),
                         test_reader.GetOutput(), 'airway')
      
    assert pm.get_particles_dice() > 0.97, \
        "Airway particle Dice score lower than expected"

  finally:
    #Clear particles cache
    ap._clean_tmp_dir=True
    ap.clean_tmp_dir()
    shutil.rmtree(tmp_dir)
开发者ID:151706061,项目名称:ChestImagingPlatform,代码行数:50,代码来源:test_airway_particles.py

示例4: loadVtk

def loadVtk(filename):
    if 'vtp' in filename:
        vreader = vtk.vtkXMLPolyDataReader()
    else:
        vreader = vtk.vtkPolyDataReader()

    vreader.SetFileName(filename)
    vreader.Update()
    polydata = vreader.GetOutput()
    polydata.ReleaseDataFlagOn()

    streamlines = []
    verts = vtk_to_numpy(polydata.GetPoints().GetData())
    scalars = {}

    pointdata = polydata.GetPointData()
    for si in range(pointdata.GetNumberOfArrays()):
        sname =  pointdata.GetArrayName(si)
        scalars[sname] = vtk_to_numpy(pointdata.GetArray(si))

    for i in range(polydata.GetNumberOfCells()):
        pids =  polydata.GetCell(i).GetPointIds()
        ids = [ pids.GetId(p) for p in range(pids.GetNumberOfIds())]
        streamlines.append(ids)

    res = {'points':verts, 'values':scalars, 'streamlines':streamlines}
    return res
开发者ID:sinkpoint,项目名称:fascicle,代码行数:27,代码来源:trkmanage.py

示例5: __init__

    def __init__(self):
        self._extension_map = {}
        self._all_readers = []
        self._reader = vtk.vtkPolyDataReader()

        # register file types
        self.registerFileTypes()
开发者ID:parallaxinnovations,项目名称:vtkMultiIO,代码行数:7,代码来源:vtkMultiPolyDataReader.py

示例6: readPData

def readPData(
        filename,
        verbose=1):

    myVTK.myPrint(verbose, "*** readPData: "+filename+" ***")

    assert (os.path.isfile(filename)), "Wrong filename (\""+filename+"\"). Aborting."

    if ('vtk' in filename):
        pdata_reader = vtk.vtkPolyDataReader()
    elif ('vtp' in filename):
        pdata_reader = vtk.vtkXMLPolyDataReader()
    else:
        assert 0, "File must be .vtk or .vtp. Aborting."

    pdata_reader.SetFileName(filename)
    pdata_reader.Update()
    pdata = pdata_reader.GetOutput()

    myVTK.myPrint(verbose-1, "n_points = "+str(pdata.GetNumberOfPoints()))
    myVTK.myPrint(verbose-1, "n_verts = "+str(pdata.GetNumberOfVerts()))
    myVTK.myPrint(verbose-1, "n_lines = "+str(pdata.GetNumberOfLines()))
    myVTK.myPrint(verbose-1, "n_polys = "+str(pdata.GetNumberOfPolys()))
    myVTK.myPrint(verbose-1, "n_strips = "+str(pdata.GetNumberOfStrips()))

    return pdata
开发者ID:541435721,项目名称:myVTKPythonLibrary,代码行数:26,代码来源:readPData.py

示例7: get_num_fibers

def get_num_fibers(filename):
    #reader = vtk.vtkDataSetReader()
    reader = vtk.vtkPolyDataReader()
    reader.SetFileName(filename)
    reader.Update()
    nlines = reader.GetOutput().GetNumberOfLines()
    return nlines
开发者ID:pnlbwh,项目名称:measuretracts,代码行数:7,代码来源:getTensorData.py

示例8: load_streamlines_poyldata

def load_streamlines_poyldata(file_name):
    # get file extension (type)
    reader = vtk.vtkPolyDataReader()
    reader.SetFileName(file_name)
    reader.Update()
    line_data = reader.GetOutput()
    return line_data
开发者ID:StongeEtienne,项目名称:trimeshpy,代码行数:7,代码来源:vtk_util.py

示例9: vtk2vtp

def vtk2vtp(inputfile, outputfile):
    """Read a vtk polydata and save as vtp."""
    reader = vtk.vtkPolyDataReader()
    reader.SetFileName(inputfile)
    reader.Update()
    surface = reader.GetOutput()
    writevtp(surface,outputfile)
开发者ID:catactg,项目名称:SUM,代码行数:7,代码来源:basefunctions.py

示例10: CanReadFile

    def CanReadFile(self, filename):
        '''
        Static methods for I/O
        @param filename: str 
        @rtype: unsigned int
        '''
        if self.IsMeshExtension(os.path.splitext(filename)[1]):
            return self.FILE_IS_VTK
        if self.IsOBJExtension(os.path.splitext(filename)[1]):
            reader = vtk.vtkOBJReader()
            reader.SetFileName(filename)
            try:
                reader.Update()
            except:
#                del reader
                return 0
#            del reader
            return self.FILE_IS_OBJ
        if not self.IsVtkExtension(os.path.splitext(filename)[1]):
            return 0
        try:
            reader = vtk.vtkPolyDataReader()
            reader.SetFileName(filename)
            if reader.IsFilePolyData():
#                del reader
                return self.FILE_IS_VTK
#            del reader
        except:
            pass
        return 0
开发者ID:jackyko1991,项目名称:vtkpythonext,代码行数:30,代码来源:vtkPythonMetaSurfaceMesh.py

示例11: 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

示例12: __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.vtkPolyDataReader()

        # ctor for this specific mixin
        FilenameViewModuleMixin.__init__(
            self,
            'Select a filename',
            'VTK data (*.vtk)|*.vtk|All files (*)|*',
            {'vtkPolyDataReader': self._reader})
        
        module_utils.setup_vtk_object_progress(
            self, self._reader,
            'Reading vtk polydata')

        # set up some defaults
        self._config.filename = ''
        self.sync_module_logic_with_config()
开发者ID:fvpolpeta,项目名称:devide,代码行数:27,代码来源:vtkPolyDataRDR.py

示例13: mris2vtk

def mris2vtk(input_name, output_name):
  """
  Converts a FreeSurfer surface to VTK file format
  """
  # convert surface to VTK format
  check_call(['mris_convert', input_name, output_name])
  # get surface RAS translation
  out = check_output(["mris_info", input_name], stderr=STDOUT)
  m = re.search("c_\(ras\)\s:\s\((-?\d+\.\d+),\s(-?\d+\.\d+),\s(-?\d+\.\d+)\)", out)
  if m is None: raise RuntimeError('Could not find c_(ras) coordinates in mris_info output!')
  tx = float(m.group(1))
  ty = float(m.group(2))
  tz = float(m.group(3))
  # transform vertex positions to scanner RAS of orig.mgz
  reader = vtkPolyDataReader()
  reader.SetFileName(output_name)
  reader.Update()
  surface = reader.GetOutput()
  points = surface.GetPoints()
  for i in range(points.GetNumberOfPoints()):
    x, y, z = points.GetPoint(i)
    points.SetPoint(i, x + tx, y + ty, z + tz)
  surface.SetPoints(points)
  writer = vtkPolyDataWriter()
  writer.SetFileName(output_name)
  writer.SetInput(surface)
  writer.Write()
开发者ID:mrajchl,项目名称:IRTK,代码行数:27,代码来源:mris2vtk.py

示例14: vtk2objfcn

def vtk2objfcn(vtkfile,objfile,decimFactor):
    import vtk
    import random
    from math import *
    import numpy
    obj = open(objfile,'w')
    reader = vtk.vtkPolyDataReader()
    reader.SetFileName(vtkfile)
    reader.Update()
    out = reader.GetOutput()
    verttotal = 0
    #print out.GetNumberOfLines()
    for i in xrange(0,out.GetNumberOfLines()-1,decimFactor):
        bounds = out.GetCell(i).GetBounds()
        for j in range(out.GetCell(i).GetNumberOfPoints()):
            voutstr = "v %7.3f %7.3f %7.3f\n" % (out.GetPoint(out.GetCell(i).GetPointId(j))[0]-90.,out.GetPoint(out.GetCell(i).GetPointId(j))[1]-126.,out.GetPoint(out.GetCell(i).GetPointId(j))[2]-72.)
            obj.write(voutstr)
        loutstr = 'l'
        for k in range(out.GetCell(i).GetNumberOfPoints()-1):
            loutstr += ' %7d' % (k+1+verttotal)
        loutstr += '\n'
        obj.write(loutstr)
        verttotal += out.GetCell(i).GetNumberOfPoints()
    obj.close()
    print('Done!')
开发者ID:Neurodome,项目名称:Code,代码行数:25,代码来源:vtk2obj.py

示例15: __init__

 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkPolyDataReader(), 'Reading vtkPolyData.',
         (), ('vtkPolyData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
开发者ID:fvpolpeta,项目名称:devide,代码行数:7,代码来源:vtkPolyDataReader.py


注:本文中的vtk.vtkPolyDataReader函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。