• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python vtk.vtkPolyDataWriter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: save_polydata

def save_polydata(polydata, file_name, binary=False, color_array_name=None):
    # get file extension (type)
    file_extension = file_name.split(".")[-1].lower()

    # todo better generic load
    # todo test all
    if file_extension == "vtk":
        writer = vtk.vtkPolyDataWriter()
    elif file_extension == "vtp":
        writer = vtk.vtkPolyDataWriter()
    elif file_extension == "fib":
        writer = vtk.vtkPolyDataWriter()
    elif file_extension == "ply":
        writer = vtk.vtkPLYWriter()
    elif file_extension == "stl":
        writer = vtk.vtkSTLWriter()
    elif file_extension == "xml":
        writer = vtk.vtkXMLPolyDataWriter()
    elif file_extension == "obj":
        raise "mni obj or Wavefront obj ?"
    #    writer = set_input(vtk.vtkMNIObjectWriter(), polydata)

    writer.SetFileName(file_name)
    writer = set_input(writer, polydata)
    if color_array_name is not None:
        writer.SetArrayName(color_array_name);
    
    if binary :
        writer.SetFileTypeToBinary()
    writer.Update()
    writer.Write()
开发者ID:StongeEtienne,项目名称:trimeshpy,代码行数:31,代码来源:vtk_util.py


示例2: __init__

    def __init__(self, module_manager):

        # call parent constructor
        ModuleBase.__init__(self, module_manager)

        self._writer = vtk.vtkPolyDataWriter()
        # sorry about this, but the files get REALLY big if we write them
        # in ASCII - I'll make this a gui option later.
        self._writer.SetFileTypeToBinary()

        module_utils.setup_vtk_object_progress(
            self, self._writer,
            'Writing VTK Polygonal data')

        
        # ctor for this specific mixin
        FilenameViewModuleMixin.__init__(
            self,
            'Select a filename',
            'VTK data (*.vtk)|*.vtk|All files (*)|*',
            {'vtkPolyDataWriter': self._writer},
            fileOpen=False)

        # set up some defaults
        self._config.filename = ''

        self.sync_module_logic_with_config()
开发者ID:fvpolpeta,项目名称:devide,代码行数:27,代码来源:vtkPolyDataWRT.py


示例3: write_polydata

def write_polydata(polydata, filename):
    """Write polydata as vtkPolyData format, according to extension."""

    if VERBOSE:
        print "Writing ", filename, "..."

    basename, extension = os.path.splitext(filename)

    if   (extension == '.vtk'):
        writer = vtk.vtkPolyDataWriter()
        writer.SetFileTypeToBinary()
    elif (extension == '.vtp'):
        writer = vtk.vtkXMLPolyDataWriter()
        writer.SetDataModeToBinary()
    else:
        print 'Cannot recognize model file format'
        return None

    writer.SetFileName(filename)
    if (vtk.vtkVersion().GetVTKMajorVersion() >= 6.0):
        writer.SetInputData(polydata)
    else:
        writer.SetInput(polydata)
    writer.Update()

    del writer

    if VERBOSE:
        print "Done writing ", filename
        print "Number of lines found:", outpd.GetNumberOfLines()
开发者ID:RuizhiLiao,项目名称:whitematteranalysis,代码行数:30,代码来源:io.py


示例4: chooseWriter

 def chooseWriter(self, file_format, vtk_dataset_type):
     """
     Return a writer based on file_format and possibly vtk_dataset_type.
     @param vtk_dataset_type, None or one of the VTK_DATASET_TYPES
     """
     if file_format == 'ply':
         return vtk.vtkPLYWriter()
     # For now we'll just return the POLYDATA writer since methods work
     # only with that vtk_dataset_type.
     return vtk.vtkPolyDataWriter()
     if vtk_dataset_type == 'STRUCTURED_GRID':
         return vtk.vtkStructuredGridWriter()
     elif vtk_dataset_type == 'POLYDATA':
         return vtk.vtkPolyDataWriter()
     elif vtk_dataset_type == 'UNSTRUCTURED_GRID':
         return vtk.vtkUnstructuredGridWriter()
开发者ID:gregvonkuster,项目名称:icqsol,代码行数:16,代码来源:icqShapeManager.py


示例5: main

def main():
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    infile = sys.argv[1]
    if len(sys.argv) >= 3:
        outfile = sys.argv[2]

    else:
        outfile = 'output.vtk'

    yaml_file = open(infile, 'r')
    tree_raw_data = yaml.load(yaml_file)

    tree_data = process_tree(tree_raw_data['graph']['porta'])
    try:
        tree_data = process_tree(tree_raw_data['graph']['porta'])
    except:
        tree_data = process_tree(tree_raw_data['Graph']['porta'])
    polyData = gen_tree(tree_data)

    writer = vtk.vtkPolyDataWriter()
    writer.SetFileName(outfile)
    writer.SetInput(polyData)
    writer.Write()
开发者ID:Trineon,项目名称:lisa,代码行数:25,代码来源:gen_vtk_tree.py


示例6: save_vtk

    def save_vtk(self, outfile, inflated=False):
        """ Export a mesh in '.vtk' format.

        This code uses vtk.

        Parameters
        ----------
        outfile: str (mandatory)
            the location where the mesh will be written.
        inflated: bool (optional, default False)
            if True write the inflated volume.
        """
        # Import here since vtk is not required by the package
        import vtk

        # Check that the inflated vertices are specified if requested
        if inflated and self.inflated_vertices is None:
            raise ValueError("Can't save inflated volume '{0}' since it has "
                             "not been specified.".format(outfile))

        # Create the desired polydata
        polydata = self._polydata(inflated=inflated)

        # Write the polydata
        writer = vtk.vtkPolyDataWriter()
        writer.SetDataModeToAscii()
        writer.SetFileName(outfile)
        if vtk.VTK_MAJOR_VERSION <= 5:
            writer.SetInput(polydata)
        else:
            writer.SetInputData(polydata)
        writer.Write()
开发者ID:dgoyard,项目名称:pyfreesurfer,代码行数:32,代码来源:surftools.py


示例7: writeMeshFile

def writeMeshFile(triangles, filename, binary=True, verbose=False):
    """Write mesh file.
    The output format is determined by file name extension. Files can be written
    in binary (default) and ASCII format."""

    outformat = path.splitext(options.outfilename)[1].strip('.')
    # set writer based on filename extension
    if outformat=='stl':
        write = vtk.vtkSTLWriter()
    elif outformat=='vtk':
        write = vtk.vtkPolyDataWriter()
    elif outformat=='obj':
        write = vtk.vtkMNIObjectWriter()
    elif outformat=='tag':
        write = vtk.vtkMNITagPointWriter()
    else:
        raise ValueError('cannot write outpur format' + outformat)
    write.SetInputConnection(triangles.GetOutputPort())

    if outformat!='tag':
        if binary:
            if verbose: print 'setting ouptut to binary'
            write.SetFileTypeToBinary()
        else:
            if verbose: print 'setting ouptut to ascii'
            write.SetFileTypeToASCII()

    write.SetFileName(filename)
    err = write.Write()
    if err != 1:
        raise IOError('failed to write')

    if verbose:
        print "wrote", filename
    pass
开发者ID:steelec,项目名称:minc-scripts,代码行数:35,代码来源:vtk_meshconvert.py


示例8: writevtk

def writevtk(surface,filename):
    """Write vtk polydata file."""
    writer = vtk.vtkPolyDataWriter()
    writer.SetInputData(surface)
    writer.SetFileTypeToASCII()
    writer.SetFileName(filename)
    writer.Write()
开发者ID:catactg,项目名称:SUM,代码行数:7,代码来源:basefunctions.py


示例9: filter_step

    def filter_step(self, unfiltered_file, include_file, exclude_file):
        import shutil

        fiber_basename = self.get_unique_name()
        filtered_temp_file = '%s_filtered.vtp' % fiber_basename
        shutil.copy2(unfiltered_file, filtered_temp_file)        

        if include_file: 
            cmd='slicerFilterFibers.sh --pass 1 %s %s %s' % (include_file, filtered_temp_file, filtered_temp_file)
            exec_cmd(cmd)

        if exclude_file:
            cmd='slicerFilterFibers.sh --nopass 1 %s %s %s' % (exclude_file, filtered_temp_file, filtered_temp_file)
            exec_cmd(cmd)

        vreader = vtkXMLPolyDataReader()
        vreader.SetFileName(filtered_temp_file)
        vreader.Update()
        polydata = vreader.GetOutput()

        vwriter = vtkPolyDataWriter()
        output_file = '%s_filtered.vtk' % fiber_basename
        vwriter.SetFileName(output_file)
        vwriter.SetInput(polydata)
        vwriter.Write()

        return output_file 
开发者ID:sinkpoint,项目名称:sagit,代码行数:27,代码来源:slicer.py


示例10: convert_mris

def convert_mris(input_name, output_name):
  """
  Converts a FreeSurfer surface to VTK file format
  """
  # convert surface to VTK format
  if output_name.endswith('.vtp'): temp_name = output_name[0:-1] + 'k'
  else:                            temp_name = output_name
  if not temp_name.endswith('.vtk'):
    raise RuntimeError('Output file name extension must be either .vtk or .vtp')
  check_call(['mris_convert', input_name, temp_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(temp_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)
  if output_name.endswith('.vtp'): writer = vtkXMLPolyDataWriter()
  else:                            writer = vtkPolyDataWriter()
  writer.SetFileName(output_name)
  writer.SetInput(surface)
  writer.Write()
  if temp_name != output_name:
    remove(temp_name)
开发者ID:151706061,项目名称:MIRTK,代码行数:34,代码来源:convert-mris.py


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


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


示例13: onMeshesComplete

def onMeshesComplete(dlg, obj_filepath):
    """
    Called when mesh extraction is complete.
    Writes the extracted mesh to an .obj file
    """
    print "Mesh generation complete."
    mesh_count = len( dlg.extractor.meshes )

    # Mesh count can sometimes be 0 for the '<not saved yet>' object...
    if mesh_count > 0:
        assert mesh_count == 1, \
            "Found {} meshes. (Only expected 1)".format( mesh_count )
        mesh = dlg.extractor.meshes.values()[0]

        # Use VTK to write to a temporary .vtk file
        tmpdir = tempfile.mkdtemp()
        vtkpoly_path = os.path.join(tmpdir, 'meshes.vtk')
        w = vtkPolyDataWriter()
        w.SetFileTypeToASCII()
        w.SetInput(mesh)
        w.SetFileName(vtkpoly_path)
        w.Write()
        
        # Now convert the file to .obj format.
        print "Saving meshes to {}".format( obj_filepath )
        convertVTPtoOBJ(vtkpoly_path, obj_filepath)

        shutil.rmtree( tmpdir )
开发者ID:JaimeIvanCervantes,项目名称:ilastik,代码行数:28,代码来源:hdf5-to-mesh.py


示例14: onMeshesComplete

        def onMeshesComplete():
            """
            Called when mesh extraction is complete.
            Writes the extracted mesh to an .obj file
            """
            logger.info( "Mesh generation complete." )
            mesh_count = len( window.extractor.meshes )

            # Mesh count can sometimes be 0 for the '<not saved yet>' object...
            if mesh_count > 0:
                assert mesh_count == 1, \
                    "Found {} meshes processing object '{}',"\
                    "(only expected 1)".format( mesh_count, object_name )
                mesh = window.extractor.meshes.values()[0]
                logger.info( "Saving meshes to {}".format( obj_filepath ) )
    
                # Use VTK to write to a temporary .vtk file
                tmpdir = tempfile.mkdtemp()
                vtkpoly_path = os.path.join(tmpdir, 'meshes.vtk')
                w = vtkPolyDataWriter()
                w.SetFileTypeToASCII()
                w.SetInput(mesh)
                w.SetFileName(vtkpoly_path)
                w.Write()
                
                # Now convert the file to .obj format.
                convertVTPtoOBJ(vtkpoly_path, obj_filepath)
    
            # Cleanup: We don't need the window anymore.
            window.setParent(None)

            # If there are still objects left to process,
            #   start again with the remainder of the list.
            if object_names:
                self._exportMeshes(object_names, obj_filepaths)
开发者ID:JaimeIvanCervantes,项目名称:ilastik,代码行数:35,代码来源:carvingGui.py


示例15: trim_vtp

def trim_vtp(fn = "c.vtp", fnout = "t.vtk", s = (1.0,1.0,1.0)):
    if not os.path.exists(fn):
        print "%s does not exists, skip" % (fn,)
        return
    
    # Read vtp
    rd = vtk.vtkXMLPolyDataReader()
    rd.SetFileName(fn)
    rd.Update()

    # the poly data
    pd = vtk.vtkPolyData()
    pd = rd.GetOutput()

    # times by 10.0 (CM -> MM)
    MM = [10.0 for each in range(0,len(s))]
    pd = scale_vtkPolyData(pd, MM)
    # then divides the spacing
    ss = [1/each for each in s]
    pd = scale_vtkPolyData(pd, ss)

    # Write vtk
    wt = vtk.vtkPolyDataWriter()
    wt.SetInputData(pd)
    wt.SetFileName(fnout)
    wt.Write()    
开发者ID:pengsun,项目名称:CatVSDog,代码行数:26,代码来源:defactoSeg.py


示例16: __init__

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


示例17: __init__

    def __init__(self):
        self._extension_map = {}
        self._scalars_name = 'scalars'
        self._writer = vtk.vtkPolyDataWriter()

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


示例18: WriteVTKSurfaceFile

 def WriteVTKSurfaceFile(self):
     if (self.OutputFileName == ''):
         self.PrintError('Error: no OutputFileName.')
     self.PrintLog('Writing VTK surface file.')
     writer = vtk.vtkPolyDataWriter()
     writer.SetInput(self.Surface)
     writer.SetFileName(self.OutputFileName)
     writer.Write()
开发者ID:SaraZanchi,项目名称:vmtk,代码行数:8,代码来源:vmtksurfacewriter.py


示例19: WriteVTKNetworkFile

 def WriteVTKNetworkFile(self):
     if self.OutputFileName == '':
         self.PrintError('Error: no OutputFileName.')
     self.PrintLog('Writing VTK network file.')
     writer = vtk.vtkPolyDataWriter()
     writer.SetInput(self.Network)
     writer.SetFileName(self.OutputFileName)
     writer.Write()
开发者ID:ChaliZhg,项目名称:vmtk,代码行数:8,代码来源:vmtknetworkwriter.py


示例20: exportToVTKPolydata

    def exportToVTKPolydata(self, filename):
        """
        Export the reconstructed mesh to a VTKpolyMesh file.

        @param filename: the name of the file
        @type filename: str
        """
        self.__exportToVtkDataExporter(vtk.vtkPolyDataWriter(),
                                       self.vtkMesh.GetOutput(),
                                       filename)
开发者ID:baishi,项目名称:3dbar,代码行数:10,代码来源:barreconstructor.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python vtk.vtkPolygon函数代码示例发布时间:2022-05-26
下一篇:
Python vtk.vtkPolyDataReader函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap