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


Python vtk.vtkSTLWriter函数代码示例

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


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

示例1: OnExportSurface

    def OnExportSurface(self, pubsub_evt):
        filename, filetype = pubsub_evt.data
        if (filetype == const.FILETYPE_STL) or\
           (filetype == const.FILETYPE_VTP) or\
           (filetype == const.FILETYPE_PLY) or\
           (filetype == const.FILETYPE_STL_ASCII):

            # First we identify all surfaces that are selected
            # (if any)
            proj = prj.Project()
            polydata_list = []

            for index in proj.surface_dict:
                surface = proj.surface_dict[index]
                if surface.is_shown:
                    polydata_list.append(surface.polydata)

            if len(polydata_list) == 0:
                utl.debug("oops - no polydata")
                return
            elif len(polydata_list) == 1:
                polydata = polydata_list[0]
            else:
                polydata = pu.Merge(polydata_list)

            # Having a polydata that represents all surfaces
            # selected, we write it, according to filetype
            if filetype == const.FILETYPE_STL:
                writer = vtk.vtkSTLWriter()
                writer.SetFileTypeToBinary()
            elif filetype == const.FILETYPE_STL_ASCII:
                writer = vtk.vtkSTLWriter()
                writer.SetFileTypeToASCII()
            elif filetype == const.FILETYPE_VTP:
                writer = vtk.vtkXMLPolyDataWriter()
            #elif filetype == const.FILETYPE_IV:
            #    writer = vtk.vtkIVWriter()
            elif filetype == const.FILETYPE_PLY:
                writer = vtk.vtkPLYWriter()
                writer.SetFileTypeToASCII()
                writer.SetColorModeToOff()
                #writer.SetDataByteOrderToLittleEndian()
                #writer.SetColorModeToUniformCellColor()
                #writer.SetColor(255, 0, 0)

            if filetype in (const.FILETYPE_STL, const.FILETYPE_PLY):
                # Invert normals
                normals = vtk.vtkPolyDataNormals()
                normals.SetInputData(polydata)
                normals.SetFeatureAngle(80)
                normals.AutoOrientNormalsOn()
                #  normals.GetOutput().ReleaseDataFlagOn()
                normals.UpdateInformation()
                normals.Update()
                polydata = normals.GetOutput()

            filename = filename.encode(wx.GetDefaultPyEncoding())
            writer.SetFileName(filename)
            writer.SetInputData(polydata)
            writer.Write()
开发者ID:151706061,项目名称:invesalius3,代码行数:60,代码来源:surface.py

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

示例3: _save_polydata

    def _save_polydata(self, data, write_bin=False):
        """
        This private method saves into `filename` the `data`. `data` is a
        vtkPolydata. It is possible to specify format for `filename`: if
        `write_bin` is True, file is written in binary format, otherwise in
        ASCII format. This method save cached polydata to reduce number of IO
        operations.

        :param vtkPolyData data: polydatat to save.
        :param bool write_bin: for binary format file.
        """
        self._cached_data = data

        writer = vtk.vtkSTLWriter()

        if write_bin:
            writer.SetFileTypeToBinary()

        writer.SetFileName(self._filename)

        if vtk.VTK_MAJOR_VERSION <= 5:
            writer.SetInput(data)
        else:
            writer.SetInputData(data)
        writer.Write()
开发者ID:mathLab,项目名称:EZyRB,代码行数:25,代码来源:stlhandler.py

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

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

示例6: __init__

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

示例7: save

 def save(self): # writer to new file
     logger.log('Exporting temp STL of model %s...' % self.name)
     # Extract transformations done to the actor
     matrix = vtk.vtkMatrix4x4() 
     self.getActor().GetMatrix(matrix)
     # Apply transformation
     transform = vtk.vtkTransform()
     transform.SetMatrix(matrix)
     # T
     t_filter = vtk.vtkTransformPolyDataFilter()
     t_filter.SetInput(self.getPolyData())
     t_filter.SetTransform(transform)
     # Triangle filter
     #vtkTriangleFilter
     # Clean Polydata
     #vtkcleanpolydata
     # Simplify the model
     #vtk.vtkDecimate
     # Save data to a STL file
     writer = vtk.vtkSTLWriter()
     writer.SetFileName('temp.stl')
     writer.SetInputConnection(t_filter.GetOutputPort())
     writer.SetFileTypeToBinary()
     writer.Write()
     logger.log('End exporting')
开发者ID:GVallicrosa,项目名称:FabQtV2,代码行数:25,代码来源:model.py

示例8: WriteSTLSurfaceFile

 def WriteSTLSurfaceFile(self):
     if (self.OutputFileName == ''):
         self.PrintError('Error: no OutputFileName.')
     self.PrintLog('Writing STL surface file.')
     writer = vtk.vtkSTLWriter()
     writer.SetInputData(self.Surface)
     writer.SetFileName(self.OutputFileName)
     writer.Write()
开发者ID:151706061,项目名称:vmtk,代码行数:8,代码来源:vmtksurfacewriter2.py

示例9: WriteSTLSurfaceFile

 def WriteSTLSurfaceFile(self):
     if self.OutputFileName == "":
         self.PrintError("Error: no OutputFileName.")
     self.PrintLog("Writing STL surface file.")
     writer = vtk.vtkSTLWriter()
     writer.SetInput(self.Surface)
     writer.SetFileName(self.OutputFileName)
     writer.Write()
开发者ID:abhishek101hi,项目名称:vmtk,代码行数:8,代码来源:vmtksurfacewriter2.py

示例10: ConvertMSH

def ConvertMSH(file_name):
	out_name = file_name.split('.')[0]+'.stl'
	print 'Out file:'+out_name
	# read file head
	file = open(file_name,'r')
	line = file.readline().split('=')
	while(line[0].strip() != 'Points'):
		line = file.readline().split('=')
		print 'Processing ', line[0]
		if(line[0].strip() == 'NPoints'):
			num_Points = int(line[1].strip())
			print 'Number of Points is ' + str(num_Points)
			
	# put in to vtkPoints
	print 'Writing Points'
	points = vtk.vtkPoints()
	points.SetNumberOfPoints(num_Points)
	for i in range(0,num_Points):
		line = file.readline()
		nums = line.split( )
		x = float(nums[1])
		y = float(nums[2])
		z = float(nums[3])
		points.SetPoint(i,x,y,z)

	# create cells
	print 'Writing Cells'
	line = file.readline().split('=')
	while(line[0].strip() != 'Cells'):
		line = file.readline().split('=')
		print 'Processing ', line[0]
		if(line[0].strip() == 'NCells'):
			num_Triangles = int(line[1].strip())
			print 'Number of num_Triangles: '+str(num_Triangles)
		
	polys = vtk.vtkCellArray()
	for i in range(1,num_Triangles):
		line = file.readline()
		nums = line.split( )
		a = int(nums[1])
		b = int(nums[2])
		c = int(nums[3])
		polys.InsertNextCell(3)
		polys.InsertCellPoint(a)
		polys.InsertCellPoint(b)
		polys.InsertCellPoint(c)
	
	polyData = vtk.vtkPolyData()
	polyData.SetPoints(points)
	polyData.SetPolys(polys)
	
	print 'Writing to STL file'
	writer = vtk.vtkSTLWriter()
	writer.SetFileName(out_name)
	writer.SetInputData(polyData)
	writer.Update()
开发者ID:Beastmaster,项目名称:itk-python-example,代码行数:56,代码来源:vtkReadmsh.py

示例11: exportToSTL

    def exportToSTL(self, filename):
        """
        Export the rendered scene to a Wavefront .obj file.

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

示例12: main

def main():
    poly = load_file(sys.argv[1])
    steps = int(sys.argv[3])
    
    new_poly = taubin_smooth(poly, 0.5, -0.53, steps)

    w = vtk.vtkSTLWriter()
    w.SetFileName(sys.argv[2])
    w.SetInput(new_poly)
    w.SetFileTypeToBinary()
    w.Write()
开发者ID:tfmoraes,项目名称:diffgeom,代码行数:11,代码来源:taubin.py

示例13: write_stl

def write_stl(ugrid, filename):
    surface_filter = vtk.vtkDataSetSurfaceFilter()
    surface_filter.SetInputData(ugrid)

    triangle_filter = vtk.vtkTriangleFilter()
    triangle_filter.SetInputConnection(surface_filter.GetOutputPort())

    writer = vtk.vtkSTLWriter()
    writer.SetFileName(filename)
    writer.SetInputConnection(triangle_filter.GetOutputPort())
    writer.Write()
开发者ID:CognitionGuidedSurgery,项目名称:restflow,代码行数:11,代码来源:vtkfunctions.py

示例14: WriteSTLSurfaceFile

 def WriteSTLSurfaceFile(self):
     if (self.OutputFileName == ''):
         self.PrintError('Error: no OutputFileName.')
     self.PrintLog('Writing STL surface file.')
     writer = vtk.vtkSTLWriter()
     writer.SetInputData(self.Surface)
     writer.SetFileName(self.OutputFileName)
     if self.Mode == "binary":
         writer.SetFileTypeToBinary()
     elif self.Mode == "ascii":
         writer.SetFileTypeToASCII()
     writer.Write()
开发者ID:samsmu,项目名称:vmtk,代码行数:12,代码来源:vmtksurfacewriter.py

示例15: writeSTL

def writeSTL(
        pdata,
        filename,
        verbose=1):

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

    stl_writer = vtk.vtkSTLWriter()
    stl_writer.SetFileName(filename)
    stl_writer.SetInputData(pdata)
    stl_writer.Update()
    stl_writer.Write()
开发者ID:gacevedobolton,项目名称:myVTKPythonLibrary,代码行数:12,代码来源:writeSTL.py


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