本文整理汇总了Python中vtk.vtkUnstructuredGridReader函数的典型用法代码示例。如果您正苦于以下问题:Python vtkUnstructuredGridReader函数的具体用法?Python vtkUnstructuredGridReader怎么用?Python vtkUnstructuredGridReader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkUnstructuredGridReader函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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()
示例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
示例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()
示例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]
示例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()
示例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
示例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()
示例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)
示例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
示例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
示例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
示例13: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkUnstructuredGridReader(), 'Reading vtkUnstructuredGrid.',
(), ('vtkUnstructuredGrid',),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
示例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
示例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()