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


Python vtk.vtkUnstructuredGridReader函数代码示例

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

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

示例1: __init__

    def __init__(self):
        self.files = []
        self.timestep = -1

        self.geometry = vtk.vtkUnstructuredGridReader()
        self.geometry_mapper = vtk.vtkDataSetMapper()
        self.geometry_actor = vtk.vtkActor()

        self.positions = vtk.vtkUnstructuredGridReader()
        self.positions_mapper = vtk.vtkDataSetMapper()
        self.positions_actor = vtk.vtkActor()

        self.geometry_mapper.SetInput(self.geometry.GetOutput())
        self.positions_mapper.SetInput(self.positions.GetOutput())
        self.positions_mapper.ScalarVisibilityOff()

        self.geometry_actor.SetMapper(self.geometry_mapper)
        self.geometry_actor.GetProperty().SetOpacity(0.2)

        self.positions_actor.SetMapper(self.positions_mapper)
        self.positions_actor.GetProperty().SetColor(light_grey)

        self.ren = vtk.vtkRenderer()
        self.ren_win = GtkGLExtVTKRenderWindow()
        self.ren_win.GetRenderWindow().AddRenderer(self.ren)

        self.ren.AddActor(self.geometry_actor)
        self.ren.AddActor(self.positions_actor)
        self.ren.SetBackground(0.1, 0.2, 0.4)
开发者ID:argreiner,项目名称:sympler,代码行数:29,代码来源:sympler_viewer.py


示例2: read_ugrid

def read_ugrid(filename):
    if filename.endswith(".pvtu"):
        reader = vtk.vtkXMLPUnstructuredGridReader()
    elif filename.endswith(".vtk"):
        reader = vtk.vtkUnstructuredGridReader()
    elif filename.endswith(".vtu"):
        reader = vtk.vtkUnstructuredGridReader()
    else:
        raise BaseException("Illegal filename suffix %s" % filename)

    reader.SetFileName(filename)
    reader.Update()

    return reader.GetOutput()
开发者ID:CognitionGuidedSurgery,项目名称:restflow,代码行数:14,代码来源:vtkfunctions.py


示例3: read

def read(filenames, timestep=None):
    '''Reads an unstructured mesh with added data.

    :param filenames: The files to read from.
    :type filenames: str
    :param timestep: Time step to read from, in case of an Exodus input mesh.
    :type timestep: int, optional
    :returns mesh{2,3}d: The mesh data.
    :returns point_data: Point data read from file.
    :type point_data: dict
    :returns field_data: Field data read from file.
    :type field_data: dict
    '''
    if isinstance(filenames, (list, tuple)) and len(filenames)==1:
        filenames = filenames[0]

    if isinstance(filenames, basestring):
        filename = filenames
        # serial files
        extension = os.path.splitext(filename)[1]

        import re
        # setup the reader
        # TODO Most readers have CanReadFile() -- use that.
        if extension == '.vtu':
            from vtk import vtkXMLUnstructuredGridReader
            reader = vtkXMLUnstructuredGridReader()
            vtk_mesh = _read_vtk_mesh(reader, filename)
        elif extension == '.vtk':
            from vtk import vtkUnstructuredGridReader
            reader = vtkUnstructuredGridReader()
            vtk_mesh = _read_vtk_mesh(reader, filename)
        elif extension == '.xmf':
            from vtk import vtkXdmfReader
            reader = vtkXdmfReader()
            vtk_mesh = _read_vtk_mesh(reader, filename)
        elif extension in [ '.ex2', '.exo', '.e' ]:
            from vtk import vtkExodusIIReader
            reader = vtkExodusIIReader()
            reader.SetFileName( filename )
            vtk_mesh = _read_exodusii_mesh(reader, timestep=timestep)
        elif re.match('[^\.]*\.e\.\d+\.\d+', filename):
            # Parallel Exodus files.
            # TODO handle with vtkPExodusIIReader
            from vtk import vtkExodusIIReader
            reader = vtkExodusIIReader()
            reader.SetFileName( filenames[0] )
            vtk_mesh = _read_exodusii_mesh(reader, timestep=timestep)
        else:
            raise RuntimeError( 'Unknown file type \'%s\'.' % filename )
    else:
        # Parallel files.
        # Assume Exodus format as we don't know anything else yet.
        from vtk import vtkPExodusIIReader
        # TODO Guess the file pattern or whatever.
        reader = vtkPExodusIIReader()
        reader.SetFileNames( filenames )
        vtk_mesh = _read_exodusii_mesh(reader, filename, timestep=timestep)

    return vtk_mesh
开发者ID:nschloe,项目名称:nosh,代码行数:60,代码来源:mesh_io.py


示例4: __init__

    def __init__(self, vtk_filename=None, vtk_data=None):
        """
        Initiate Viwer

        Parameters
        ----------
        vtk_filename : str
            Input VTK filename
        """

        QDialog.__init__(self)
        self.initUI()

        ren = vtk.vtkRenderer()
        self.vtkWidget.GetRenderWindow().AddRenderer(ren)
        iren = self.vtkWidget.GetRenderWindow().GetInteractor()

        if vtk_filename is not None:
            # VTK file
            reader = vtk.vtkUnstructuredGridReader()
            reader.SetFileName(vtk_filename)
            reader.Update()
            vtkdata = reader.GetOutput()

        if vtk_data is not None:
            vtkdata = vtk_data

        # VTK surface
        surface = vtk.vtkDataSetSurfaceFilter()
        surface.SetInput(vtkdata)
        surface.Update()

        mapper = vtk.vtkDataSetMapper()
        mapper.SetInput(surface.GetOutput())

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().EdgeVisibilityOff()
        # actor.GetProperty().SetEdgeColor(1,1,1)
        # actor.GetProperty().SetLineWidth(0.1)
        ren.AddActor(actor)

        # annot. cube
        axesActor = vtk.vtkAnnotatedCubeActor()
        axesActor.SetXPlusFaceText('R')
        axesActor.SetXMinusFaceText('L')
        axesActor.SetYMinusFaceText('H')
        axesActor.SetYPlusFaceText('F')
        axesActor.SetZMinusFaceText('A')
        axesActor.SetZPlusFaceText('P')
        axesActor.GetTextEdgesProperty().SetColor(1, 1, 0)
        axesActor.GetCubeProperty().SetColor(0, 0, 1)
        self.axes = vtk.vtkOrientationMarkerWidget()
        self.axes.SetOrientationMarker(axesActor)
        self.axes.SetInteractor(iren)
        self.axes.EnabledOn()
        self.axes.InteractiveOn()

        ren.ResetCamera()
        iren.Initialize()
开发者ID:andrlikjirka,项目名称:lisa,代码行数:60,代码来源:viewer.py


示例5: read_data_and_build_snapshot_matrix

def read_data_and_build_snapshot_matrix(x_min,x_max,y_min,y_max,z_min,z_max,snapshot_dir,file_list,\
						num_snapshots,num_points,num_components,var_name, A):
	reader = vtk.vtkUnstructuredGridReader()
	reader.ReadAllScalarsOn()
	reader.ReadAllVectorsOn()
	extract_region = "false"
	if ( (x_min<x_max) and (y_min<y_max) and (z_min<z_max) ):
		extract_region = "true"
		extract = vtk.vtkExtractUnstructuredGrid()
		extract.SetExtent(x_min, x_max, y_min, y_max, z_min, z_max)
		extract.MergingOn()
	u_temp_read = np.array(np.zeros((num_points,3), dtype=np.float64))
	print '\n   Reading data ...'
	for j in range(0,num_snapshots+1):
		print '      Reading file ', file_list[j].strip(), 'file number ', j, ' of ', num_snapshots
		reader.SetFileName(snapshot_dir + file_list[j].strip())
		reader.Update()
		if (extract_region=="true"):
			extract.SetInput(reader.GetOutput())
			extract.Update()
			u_temp_read = VN.vtk_to_numpy(extract.GetOutput().GetPointData().GetVectors(var_name))
		else:
			u_temp_read = VN.vtk_to_numpy(reader.GetOutput().GetPointData().GetVectors(var_name))
		for k in range(0,num_components):
			A[k*num_points:(k+1)*num_points,j] = u_temp_read[:,k]
开发者ID:vassilikitsios,项目名称:snapshot_pod_rom_py,代码行数:25,代码来源:io_vtk_m.py


示例6: unstructered_grid_reader

    def unstructered_grid_reader(filename):
        # Read the source file.
        reader = vtk.vtkUnstructuredGridReader()
        reader.SetFileName(filename)
        reader.Update() # Needed because of GetScalarRange
        output = reader.GetOutput()
        scalar_range = output.GetScalarRange()

        # Create the mapper that corresponds the objects of the vtk file
        # into graphics elements
        mapper =vtk.vtkDataSetMapper()
        mapper.SetInputData(output)
        mapper.SetScalarRange(scalar_range)

        # Create the Actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)

        # Create the Renderer
        renderer = vtk.vtkRenderer()
        renderer.AddActor(actor)
        renderer.SetBackground(1, 1, 1) # Set background to white

        # Create the RendererWindow
        renderer_window = vtk.vtkRenderWindow()
        renderer_window.AddRenderer(renderer)

        # Create the RendererWindowInteractor and display the vtk_file
        interactor = vtk.vtkRenderWindowInteractor()
        interactor.SetRenderWindow(renderer_window)
        interactor.Initialize()
        interactor.Start()
开发者ID:CognitionGuidedSurgery,项目名称:msml,代码行数:32,代码来源:msmlvtk.py


示例7: get_number_of_points_and_boundary_faces

def get_number_of_points_and_boundary_faces(pod_mode_dir,calibrate_coefficients):
	filename = pod_mode_dir+"/spatial_meanfield.vtk"
	reader = vtk.vtkUnstructuredGridReader()
	reader.ReadAllScalarsOn()
	reader.ReadAllVectorsOn()
	reader.ReadAllTensorsOn()
	reader.SetFileName(filename)
	reader.Update()
	num_points = reader.GetOutput().GetNumberOfPoints()

	if( (calibrate_coefficients=="none") or (calibrate_coefficients=="constant") ):
		geom_filter = vtk.vtkDataSetSurfaceFilter()
		geom_filter.SetInput(reader.GetOutput())
		geom_filter.Update()
		boundary_faces = vtk.vtkPolyData()
		boundary_faces = geom_filter.GetOutput()

		point_to_cell_data = vtk.vtkPointDataToCellData()
		point_to_cell_data.SetInput(geom_filter.GetOutput())
		point_to_cell_data.Update()
		num_boundary_faces = point_to_cell_data.GetOutput().GetNumberOfCells()
	else:
		num_boundary_faces = 1

	return num_points, num_boundary_faces
开发者ID:vassilikitsios,项目名称:snapshot_pod_rom_py,代码行数:25,代码来源:rom_coefficients_m.py


示例8: loadVtk

    def loadVtk(self, fname):
        """ Load a given VTK file into a vtkPolyData object """

        reader = vtk.vtkUnstructuredGridReader()
        reader.SetFileName(filename)
        reader.Update()
        self._vtk = reader.GetOutput()
开发者ID:Andrew-AbiMansour,项目名称:PyDEM,代码行数:7,代码来源:visualize.py


示例9: read_vtk

    def read_vtk(self, data_dir='./data', file_name='separatrices.vtk'):
        """
        Read the separatrices from a vtk file.

        call signature:

            read_vtk(data_dir='./data', file_name='separatrices.vtk')

        Arguments:

        *data_dir*:
            Origin data directory.

        *file_name*:
            Origin file name.
        """

        reader = vtk.vtkUnstructuredGridReader()
        reader.SetFileName(os.path.join(data_dir, file_name))
        reader.Update()
        output = reader.GetOutput()

        # Read the separatrices.
        points = output.GetPoints()
        cells = output.GetCells()
        self.separatrices = []
        self.connectivity = []
        for separatrix in range(points.GetNumberOfPoints()):
            self.separatrices.append(points.GetPoint(separatrix))
        self.separatrices = np.array(self.separatrices)
        self.connectivity = np.array([VN.vtk_to_numpy(cells.GetData())[1::3],
                                      VN.vtk_to_numpy(cells.GetData())[2::3]])
        self.connectivity = self.connectivity.swapaxes(0, 1)
开发者ID:debanjan0811,项目名称:pencil-code,代码行数:33,代码来源:field_skeleton.py


示例10: read

def read(filetype, filename):
    if filetype == 'vtk':
        reader = vtk.vtkUnstructuredGridReader()
        reader.SetFileName(filename)
        reader.Update()
        vtk_mesh = reader.GetOutput()
    elif filetype == 'vtu':
        reader = vtk.vtkXMLUnstructuredGridReader()
        reader.SetFileName(filename)
        reader.Update()
        vtk_mesh = reader.GetOutput()
    elif filetype == 'exodus':
        reader = vtk.vtkExodusIIReader()
        reader.SetFileName(filename)
        vtk_mesh = _read_exodusii_mesh(reader)
    else:
        raise RuntimeError('Unknown file type \'%s\'.' % filename)

    # Explicitly extract points, cells, point data, field data
    points = vtk.util.numpy_support.vtk_to_numpy(
        vtk_mesh.GetPoints().GetData())
    cells = _read_cells(vtk_mesh)
    point_data = _read_data(vtk_mesh.GetPointData())
    cell_data = _read_data(vtk_mesh.GetCellData())
    field_data = _read_data(vtk_mesh.GetFieldData())

    return points, cells, point_data, cell_data, field_data
开发者ID:nilswagner,项目名称:meshio,代码行数:27,代码来源:vtk_io.py


示例11: get_node_data_n

	def get_node_data_n(self, file_name):
		"""
		Reads mesh information. Returns a numpy arrays of nodes & elements in 'abaqus' format.
		"""
		meshSource=vtk.vtkUnstructuredGridReader()
		meshSource.SetFileName(file_name)
		meshSource.Update()

		#get nodes & elements returned to numpy arrays
		nread=v2n(meshSource.GetOutput().GetPoints().GetData())
		#allocate for extra node numbers to be input
		node_data=np.zeros((np.shape(nread)[0],np.shape(nread)[1]+1))
		#reshape according to 'abaqus' standards (node num, coord1, 2 ...)
		node_data[:,0]=np.arange(np.shape(nread)[0])+1
		node_data[:,1:]=nread
		# print([np.shape(np.arange(np.shape(n)[0])].transpose()))
		e=v2n(meshSource.GetOutput().GetCells().GetData())

		#get cell types & reshape element array as needed.
		tcs=vtk.vtkCellTypes()
		meshSource.GetOutput().GetCellTypes(tcs)

		#reshape according to 'abaqus' standards (elem number, connectivity1 2 ...)
		if tcs.IsType(12)==1:
			self.mainCellType=12 #1st order quad
			element_data=np.resize(e,(int(len(e)/float(9)),9))
			element_data[:,0]=np.arange(np.shape(element_data)[0])+1
		elif tcs.IsType(24)==1:
			self.mainCellType=24 #2nd order tet
			element_data=np.resize(e,(int(len(e)/float(11)),11))
			element_data[:,0]=np.arange(np.shape(element_data)[0])+1
		# print(np.shape(node_data),np.shape(element_data)) #debug
		return node_data, element_data+1 #add one to the element number to match abaqus format
开发者ID:majroy,项目名称:pyCM,代码行数:33,代码来源:postprocess.py


示例12: Create_Topo

def Create_Topo(Slope,Plane):
	ugrid = vtk.vtkUnstructuredGrid()
	gridreader=vtk.vtkUnstructuredGridReader()
	gridreader.SetFileName(Slope)
	gridreader.Update()
	ugrid = gridreader.GetOutput()
	GeomFilt1 = vtk.vtkGeometryFilter()
	GeomFilt1.SetInput(ugrid)
	GeomFilt1.Update()
	x = GeomFilt1.GetOutput()

	u = vtk.vtkUnstructuredGrid()
	bgridreader=vtk.vtkXMLUnstructuredGridReader()
	bgridreader.SetFileName(Plane)
	bgridreader.Update()
	u = bgridreader.GetOutput() 
	GeomFilt2 = vtk.vtkGeometryFilter()
	GeomFilt2.SetInput(u)
	GeomFilt2.Update()
	y = GeomFilt2.GetOutput()

	append = vtk.vtkAppendPolyData()
	append.AddInput(x)
	append.AddInput(y)
	data = append.GetOutput()

	d = vtk.vtkDelaunay3D()
	d.SetInput(data)
	d.Update
	d.BoundingTriangulationOff()  
	d.SetTolerance(0.00001)
	d.SetAlpha(0)
	d.Update()
	z = d.GetOutput()
	return z
开发者ID:Norrisa,项目名称:open-stratigraphy-model,代码行数:35,代码来源:Geom.py


示例13: __init__

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


示例14: readUGrid

def readUGrid(
        filename,
        verbose=1):

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

    if ('vtk' in filename):
        ugrid_reader = vtk.vtkUnstructuredGridReader()
    elif ('vtu' in filename):
        ugrid_reader = vtk.vtkXMLUnstructuredGridReader()
    else:
        assert 0, "File must be .vtk or .vtu. Aborting."

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

    ugrid_reader.SetFileName(filename)
    ugrid_reader.Update()
    ugrid = ugrid_reader.GetOutput()

    if (verbose):
        n_points = ugrid.GetNumberOfPoints()
        print 'n_points =', n_points

        n_cells = ugrid.GetNumberOfCells()
        print 'n_cells =', n_cells

    return ugrid
开发者ID:gacevedobolton,项目名称:myVTKPythonLibrary,代码行数:27,代码来源:readUGrid.py


示例15: __init__

    def __init__(self,delta,wing):

        self.arrowColor = vtk.vtkColorTransferFunction()

        self.update_look_up_table()

        self.print_counter=0
        self.ren = vtk.vtkRenderer()

        self.geo_reader = vtk.vtkUnstructuredGridReader()
        self.geo_reader.SetFileName(wing)


        self.vec_reader = vtk.vtkStructuredPointsReader()
        self.vec_reader.SetFileName(delta)

        """ This is for drawing the wing,"""
        geo_Mapper=vtk.vtkDataSetMapper()
        geo_Mapper.SetInputConnection(self.geo_reader.GetOutputPort())

        geo_actor = vtk.vtkActor()
        geo_actor.SetMapper(geo_Mapper)

        self.ren.AddActor(geo_actor)

        """End of adding the wing """


        self.ren.AddActor(self.create_stream_line(25,150,0,0.5))


        #Add renderer to renderwindow and render
        self.renWin = vtk.vtkRenderWindow()
        self.renWin.AddRenderer(self.ren)
        self.renWin.SetSize(1920, 1080)

        iren = vtk.vtkRenderWindowInteractor()
        iren.SetRenderWindow(self.renWin)

        iren.AddObserver('RightButtonPressEvent', self.capture_image, 1.0)

        # Scalar Bar actor
        scalar_bar = vtk.vtkScalarBarActor()
        scalar_bar.SetOrientationToHorizontal()
        scalar_bar.SetLookupTable(self.arrowColor)
        scalar_bar.SetTitle("Color map")
        scalar_bar.SetLabelFormat("%5.2f")
        scalar_bar.SetMaximumHeightInPixels(300)
        scalar_bar.SetMaximumWidthInPixels(60)

        # Scalar Bar Widget
        scalar_bar_widget = vtk.vtkScalarBarWidget()
        scalar_bar_widget.SetInteractor(iren)
        scalar_bar_widget.SetScalarBarActor(scalar_bar)
        scalar_bar_widget.On()

        self.ren.SetBackground(0,0,0)
        self.renWin.Render()
        iren.Start()
开发者ID:svelezsaffon,项目名称:vector_field_visualization_vtk,代码行数:59,代码来源:streamsurfaces.py


示例16: getReader

 def getReader(self, model_type=None):
     self.model_type = model_type
     if self.model_type == 'UnstructuredGrid':
         return vtk.vtkUnstructuredGridReader()
     elif self.model_type == 'PolyData':
         return vtk.vtkPolyDataReader()
     else:
         raise ValueError("model type informed is unknow...")
开发者ID:aabdulwahed,项目名称:vtk2webgl,代码行数:8,代码来源:vtk_reader.py


示例17: getData_2

def getData_2(filename):
    # Read CELL_DATA from vtk file
    reader = vtk.vtkUnstructuredGridReader()
    reader.SetFileName(filename)
    reader.Update()
    vtk_points_arrays= reader.GetOutput().GetPointData()
    vtk_cell_arrays  = reader.GetOutput().GetCellData()
    return vtk_points_arrays, vtk_cell_arrays
开发者ID:pyotr777,项目名称:kportal,代码行数:8,代码来源:make_cell_images.py


示例18: ReadVTKMeshFile

 def ReadVTKMeshFile(self):
     if (self.InputFileName == ''):
         self.PrintError('Error: no InputFileName.')
     self.PrintLog('Reading VTK mesh file.')
     reader = vtk.vtkUnstructuredGridReader()
     reader.SetFileName(self.InputFileName)
     reader.Update()
     self.Mesh = reader.GetOutput()
开发者ID:151706061,项目名称:vmtk,代码行数:8,代码来源:vmtkmeshreader.py


示例19: getData

def getData(filename):
    # load a vtk file as input
    reader = vtk.vtkUnstructuredGridReader()
    reader.SetFileName(filename)
    reader.Update()
    vtk_arrays= reader.GetOutput().GetPointData()
    #print vtk_nodes
    #print vtk_arrays
    return vtk_arrays
开发者ID:pyotr777,项目名称:kportal,代码行数:9,代码来源:make_points_images.py


示例20: readVTK

 def readVTK(self,verbose=False):
     self.reader=vtk.vtkUnstructuredGridReader()
     try:
         self.reader.SetFileName(self.filename)
         self.reader.ReadAllScalarsOn()
         self.reader.ReadAllVectorsOn()
     except:
         print 'Could not find file: ',self.filename
         return
开发者ID:pawelaw,项目名称:phd,代码行数:9,代码来源:vtkextract.py



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