本文整理汇总了Python中vtk.vtkVertex函数的典型用法代码示例。如果您正苦于以下问题:Python vtkVertex函数的具体用法?Python vtkVertex怎么用?Python vtkVertex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkVertex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_ugrid_nodes_to_grid
def _add_ugrid_nodes_to_grid(self, name, diff_node_ids, nodes):
"""
based on:
_add_nastran_nodes_to_grid
"""
nnodes = nodes.shape[0]
assert nnodes > 0, nnodes
# if nnodes == 0:
# return
nnodes = len(diff_node_ids)
points = vtk.vtkPoints()
points.SetNumberOfPoints(nnodes)
for nid in diff_node_ids:
node = nodes[nid, :]
print('nid=%s node=%s' % (nid, node))
points.InsertPoint(nid, *node)
if 1:
elem = vtk.vtkVertex()
elem.GetPointIds().SetId(0, nid)
else:
elem = vtk.vtkSphere()
sphere_size = self._get_sphere_size(dim_max)
elem.SetRadius(sphere_size)
elem.SetCenter(points.GetPoint(nid))
self.alt_grids[name].InsertNextCell(elem.GetCellType(), elem.GetPointIds())
self.alt_grids[name].SetPoints(points)
示例2: __init__
def __init__(self, pointlist=[]):
points = vtk.vtkPoints()
cellArr = vtk.vtkCellArray()
Colors = vtk.vtkUnsignedCharArray()
Colors.SetNumberOfComponents(3)
Colors.SetName("Colors")
n=0
for p in pointlist:
vert = vtk.vtkVertex()
points.InsertNextPoint(p.x, p.y, p.z)
vert.GetPointIds().SetId(0,n)
cellArr.InsertNextCell( vert )
col = clColor(p.cc())
Colors.InsertNextTuple3( float(255)*col[0], float(255)*col[1], float(255)*col[2] )
n=n+1
polydata= vtk.vtkPolyData()
polydata.SetPoints(points)
polydata.SetVerts( cellArr )
polydata.GetPointData().SetScalars(Colors)
polydata.Modified()
polydata.Update()
self.src=polydata
self.mapper = vtk.vtkPolyDataMapper()
self.mapper.SetInput(self.src)
self.SetMapper(self.mapper)
示例3: addPointSet
def addPointSet(self, data):
"""Add a set of points to the UnstructuredGrid vertexGrid (the source of our calculations)
"""
logging.info("adding point set")
size = len(data)
# Create some landmarks, put them in UnstructuredGrid
# Start off with some landmarks
vertexPoints = vtk.vtkPoints()
vertexPoints.SetNumberOfPoints(size)
vertexGrid = vtk.vtkUnstructuredGrid()
vertexGrid.Allocate(size, size)
for id, (x, y, z) in enumerate(data):
vertexPoints.InsertPoint(id, x, y, z)
# Create vertices from them
vertex = vtk.vtkVertex()
vertex.GetPointIds().SetId(0, id)
#Create an unstructured grid with the landmarks added
vertexGrid.InsertNextCell(vertex.GetCellType(), vertex.GetPointIds())
vertexGrid.SetPoints(vertexPoints)
self.vertexGrids.append(vertexGrid)
logging.info("done")
示例4: geom_viz
def geom_viz(geomData, filename='sample.vtp'):
"""
DESCRIPTION
-----------
geom_viz(geomData, filename='geom.vtp')
Generate a simple point centered vtp file to visualize grain ID.
PARAMETERS
----------
geomData: numpy.array
Grain ID populated in a numpy array representing the extruded
microstructure.
filename: str
Output VTP file name.
RETURNS
-------
NOTES
----
"""
polydata = vtk.vtkPolyData()
points = vtk.vtkPoints()
vertices = vtk.vtkCellArray()
gids = vtk.vtkFloatArray()
gids.SetNumberOfComponents(1)
gids.SetName("GrainID")
# iterating through CPFFT data
cnt = 0
x, y, z = geomData.shape
for i in range(x):
for j in range(y):
for k in range(z):
# set position
points.InsertNextPoint(i, j, k)
vertex = vtk.vtkVertex()
vertex.GetPointIds().SetId(0, cnt)
cnt += 1
vertices.InsertNextCell(vertex)
# set Grain ID
gids.InsertNextTuple1(geomData[i, j, k])
# finish the vtp object
polydata.SetPoints(points)
polydata.SetVerts(vertices)
polydata.GetPointData().SetScalars(gids)
polydata.Modified()
if vtk.VTK_MAJOR_VERSION <= 5:
polydata.Update()
writer = vtk.vtkXMLPolyDataWriter()
writer.SetFileName(filename)
if vtk.VTK_MAJOR_VERSION <= 5:
writer.SetInput(polydata)
else:
writer.SetInputData(polydata)
writer.Write()
示例5: computeABPointsFromTTTSectors
def computeABPointsFromTTTSectors(
ugrid_sectors,
verbose=1):
myVTK.myPrint(verbose, "*** computeABPointsFromTTTSectors ***")
n_points = ugrid_sectors.GetNumberOfPoints()
n_cells = ugrid_sectors.GetNumberOfCells()
n_csects = 12
n_rsects = 3
n_slices = n_points / (n_rsects+1) / (n_csects+1)
myVTK.myPrint(verbose-1, "n_slices =", n_slices)
zmin = ugrid_sectors.GetPoint(0)[2]
zmax = ugrid_sectors.GetPoint(ugrid_sectors.GetNumberOfPoints()-1)[2]
dist_btw_slices = abs(zmin-zmax)/(n_slices-1)
myVTK.myPrint(verbose-1, "dist_btw_slices =", dist_btw_slices)
A = ugrid_sectors.GetPoints().GetPoint(0)
B = ugrid_sectors.GetPoints().GetPoint(6)
C = ugrid_sectors.GetPoints().GetPoint(3)
D = ugrid_sectors.GetPoints().GetPoint(9)
#print A
#print B
#print C
#print D
Px = ((A[0]*B[1]-A[1]*B[0])*(C[0]-D[0])-(A[0]-B[0])*(C[0]*D[1]-C[1]*D[0]))/((A[0]-B[0])*(C[1]-D[1])-(A[1]-B[1])*(C[0]-D[0]))
Py = ((A[0]*B[1]-A[1]*B[0])*(C[1]-D[1])-(A[1]-B[1])*(C[0]*D[1]-C[1]*D[0]))/((A[0]-B[0])*(C[1]-D[1])-(A[1]-B[1])*(C[0]-D[0]))
#print Px
#print Py
A = [Px, Py, zmin]
B = [Px, Py, zmax]
myVTK.myPrint(verbose-1, "A =", A)
myVTK.myPrint(verbose-1, "B =", B)
points_AB = vtk.vtkPoints()
points_AB.InsertNextPoint(A)
points_AB.InsertNextPoint(B)
cells_AB = vtk.vtkCellArray()
cell_AB = vtk.vtkVertex()
cell_AB.GetPointIds().SetId(0, 0)
cells_AB.InsertNextCell(cell_AB)
cell_AB.GetPointIds().SetId(0, 1)
cells_AB.InsertNextCell(cell_AB)
AB_ugrid = vtk.vtkUnstructuredGrid()
AB_ugrid.SetPoints(points_AB)
AB_ugrid.SetCells(vtk.VTK_VERTEX, cells_AB)
return points_AB
示例6: vertices
def vertices( self, points ):
assert isinstance( points, (list,tuple,numpy.ndarray) ), 'Expected list of point arrays'
import vtk
vtkPoints = vtk.vtkPoints()
vtkPoints.SetNumberOfPoints( sum(pts.shape[0] for pts in points) )
cnt = 0
for pts in points:
if pts.shape[1] < 3:
pts = numpy.concatenate([pts,numpy.zeros(shape=(pts.shape[0],3-pts.shape[1]))],axis=1)
for point in pts:
vtkPoints .SetPoint( cnt, point )
cellpoints = vtk.vtkVertex().GetPointIds()
cellpoints.SetId( 0, cnt )
self.vtkMesh.InsertNextCell( vtk.vtkVertex().GetCellType(), cellpoints )
cnt +=1
self.vtkMesh.SetPoints( vtkPoints )
示例7: addVertices
def addVertices(
ugrid,
verbose=1):
myVTK.myPrint(verbose, "*** addVertices ***")
cell = vtk.vtkVertex()
cell_array = vtk.vtkCellArray()
n_points = ugrid.GetPoints().GetNumberOfPoints()
for k_point in xrange(n_points):
cell.GetPointIds().SetId(0, k_point)
cell_array.InsertNextCell(cell)
ugrid.SetCells(vtk.VTK_VERTEX, cell_array)
n_arrays = ugrid.GetPointData().GetNumberOfArrays()
for k_array in xrange(n_arrays):
ugrid.GetCellData().AddArray(ugrid.GetPointData().GetArray(k_array))
示例8: load_surf_geometry
def load_surf_geometry(self, surf_filename, dirname, plot=True):
#skip_reading = self.remove_old_openfoam_geometry(openfoam_filename)
#if skip_reading:
# return
model = SurfReader()
self.model_type = 'surf'
print('surf_filename = %s' % surf_filename)
model.read_surf(surf_filename)
nnodes = model.nodes.shape[0]
ntris = model.tris.shape[0]
nquads = model.quads.shape[0]
nelements = ntris + nquads
nodes = model.nodes
self.nElements = nelements
self.nNodes = nnodes
print("nNodes = %s" % self.nNodes)
print("nElements = %s" % self.nElements)
assert nelements > 0, nelements
self.grid.Allocate(self.nElements, 1000)
points = vtk.vtkPoints()
points.SetNumberOfPoints(self.nNodes)
mmax = amax(nodes, axis=0)
mmin = amin(nodes, axis=0)
dim_max = (mmax - mmin).max()
self.create_global_axes(dim_max)
self.log.info('max = %s' % mmax)
self.log.info('min = %s' % mmin)
for inode, node in enumerate(nodes):
points.InsertPoint(inode, node)
tris = model.tris - 1
quads = model.quads - 1
if ntris:
for eid, element in enumerate(tris):
elem = vtkTriangle()
elem.GetPointIds().SetId(0, element[0])
elem.GetPointIds().SetId(1, element[1])
elem.GetPointIds().SetId(2, element[2])
self.grid.InsertNextCell(elem.GetCellType(),
elem.GetPointIds())
if nquads:
for eid, element in enumerate(quads):
elem = vtkQuad()
elem.GetPointIds().SetId(0, element[0])
elem.GetPointIds().SetId(1, element[1])
elem.GetPointIds().SetId(2, element[2])
elem.GetPointIds().SetId(3, element[3])
self.grid.InsertNextCell(elem.GetCellType(),
elem.GetPointIds())
model.read_surf_failnode(surf_filename)
if len(model.nodes_failed):
if 'failed_nodes' not in self.alt_grids:
yellow = (1., 1., 0.)
self.create_alternate_vtk_grid('failed_nodes', color=yellow, line_width=3, opacity=1.0)
ifailed = where(model.nodes_failed == 1)[0]
nfailed = len(ifailed)
self.alt_grids['failed_nodes'].Allocate(nfailed, 1000)
grid2 = self.alt_grids['failed_nodes']
points2 = vtk.vtkPoints()
points2.SetNumberOfPoints(nfailed)
for j, nid in enumerate(model.nodes_failed):
elem = vtk.vtkVertex()
c = nodes[nid - 1, :]
print(nid, c)
points2.InsertPoint(j, *c)
elem.GetPointIds().SetId(0, j)
self.alt_grids['failed_nodes'].InsertNextCell(elem.GetCellType(), elem.GetPointIds())
self.alt_grids['failed_nodes'].SetPoints(points2)
self._add_alt_actors(self.alt_grids)
actor = self.geometry_actors['failed_nodes']
actor.Modified()
prop = actor.GetProperty()
prop.SetRepresentationToPoints()
prop.SetPointSize(10)
# self.
self.nElements = nelements
self.grid.SetPoints(points)
self.grid.Modified()
if hasattr(self.grid, 'Update'):
self.grid.Update()
#print("updated grid")
#.........这里部分代码省略.........
示例9: serveVTKGeoJSON
def serveVTKGeoJSON(self, datasetString):
'''
Deliver a geojson encoded serialized vtkpolydata file and render it
over the canonical cpipe scene.
'''
if vtkOK == False:
return """<html><head></head><body>VTK python bindings are not loadable, be sure VTK is installed on the server and its PATHS are set appropriately.</body><html>"""
ss = vtk.vtkNetCDFCFReader() #get test data
ss.SphericalCoordinatesOff()
ss.SetOutputTypeToImage()
datadir = cherrypy.request.app.config['/data']['tools.staticdir.dir']
datadir = os.path.join(datadir, 'assets')
datafile = os.path.join(datadir, 'clt.nc')
ss.SetFileName(datafile)
sf = vtk.vtkDataSetSurfaceFilter() #convert to polydata
sf.SetInputConnection(ss.GetOutputPort())
cf = vtk.vtkContourFilter() #add some attributes
cf.SetInputConnection(sf.GetOutputPort())
cf.SetInputArrayToProcess(0,0,0,"vtkDataObject::FIELD_ASSOCIATION_POINTS", "clt")
cf.SetNumberOfContours(10)
sf.Update()
drange = sf.GetOutput().GetPointData().GetArray(0).GetRange()
for x in range(0,10):
cf.SetValue(x,x*0.1*(drange[1]-drange[0])+drange[0])
cf.ComputeScalarsOn()
ef = vtk.vtkExtractEdges() #make lines to test
ef.SetInputConnection(sf.GetOutputPort())
gf = vtk.vtkGlyph3D() #make verts to test
pts = vtk.vtkPoints()
pts.InsertNextPoint(0,0,0)
verts = vtk.vtkCellArray()
avert = vtk.vtkVertex()
avert.GetPointIds().SetId(0, 0)
verts.InsertNextCell(avert)
onevertglyph = vtk.vtkPolyData()
onevertglyph.SetPoints(pts)
onevertglyph.SetVerts(verts)
gf.SetSourceData(onevertglyph)
gf.SetInputConnection(sf.GetOutputPort())
if datasetString == "points":
toshow = gf
elif datasetString == "lines":
toshow = ef
elif datasetString == "contour":
toshow = cf
else:
toshow = sf
gw = vtk.vtkGeoJSONWriter()
gw.SetInputConnection(toshow.GetOutputPort())
gw.SetScalarFormat(2);
if True:
gw.SetFileName("/Source/CPIPES/buildogs/deploy/dataset.gj")
gw.Write()
f = file("/Source/CPIPES/buildogs/deploy/dataset.gj")
gj = str(f.readlines())
else:
gw.WriteToOutputStringOn()
gw.Write()
gj = "['"+str(gw.RegisterAndGetOutputString()).replace('\n','')+"']"
res = ("""
<html>
<head>
<script type="text/javascript" src="/common/js/gl-matrix.js"></script>
<script type="text/javascript" src="/lib/geoweb.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
function makedata() {
var datasetString = %(gjfile)s.join('\\n');
var data = new ogs.vgl.geojsonReader().getPrimitives(datasetString);
var geoms = data.geoms;
var mapper = new ogs.vgl.mapper();
mapper.setGeometryData(geoms[0]);
""" +
self.gjShader +
"""
var actor = new ogs.vgl.actor();
actor.setMapper(mapper);
actor.setMaterial(mat);
return actor;
}
</script>
<script type="text/javascript">
function main() {
var mapOptions = {
zoom : 1,
center : ogs.geo.latlng(0.0, 0.0),
source : '/data/assets/land_shallow_topo_2048.png'
};
var myMap = ogs.geo.map(document.getElementById("glcanvas"), mapOptions);
#.........这里部分代码省略.........
示例10: load_bedge_geometry
def load_bedge_geometry(self, bedge_filename, dirname, name='main', plot=True):
#skip_reading = self.remove_old_openfoam_geometry(openfoam_filename)
#if skip_reading:
# return
self.modelType = 'bedge'
model = read_bedge(bedge_filename)
print('bedge_filename = %s' % bedge_filename)
nnodes = model.nodes.shape[0]
nbars = model.bars.shape[0]
nelements = nbars
nodes = model.nodes
self.nElements = nelements
self.nNodes = nnodes
print("nNodes = %s" % self.nNodes)
print("nElements = %s" % self.nElements)
assert nelements > 0, nelements
black = (0., 0., 0.)
self.create_alternate_vtk_grid(
'nodes', color=black, line_width=5, opacity=1., point_size=3,
representation='point')
self.alt_grids['nodes'].Allocate(nnodes, 1000)
self.grid.Allocate(self.nElements, 1000)
points = vtk.vtkPoints()
points.SetNumberOfPoints(self.nNodes)
mmax = np.amax(nodes, axis=0)
mmin = np.amin(nodes, axis=0)
dim_max = (mmax - mmin).max()
self.log.info('max = %s' % mmax)
self.log.info('min = %s' % mmin)
#print('dim_max =', dim_max)
#self.update_axes_length(dim_max)
for inode, node in enumerate(nodes):
points.InsertPoint(inode, node)
elem = vtk.vtkVertex()
elem.GetPointIds().SetId(0, inode)
self.alt_grids['nodes'].InsertNextCell(elem.GetCellType(), elem.GetPointIds())
bars = model.bars
for eid, element in enumerate(bars):
elem = vtk.vtkLine()
n1, n2 = element
try:
elem.GetPointIds().SetId(0, n1)
elem.GetPointIds().SetId(1, n2)
except KeyError:
print("nodeIDs =", element)
print(str(element))
continue
self.grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds())
self.nElements = nelements
self.alt_grids['nodes'].SetPoints(points)
self.grid.SetPoints(points)
self.grid.Modified()
if hasattr(self.grid, 'Update'):
self.grid.Update()
#print("updated grid")
# loadCart3dResults - regions/loads
#self.TurnTextOn()
self.scalarBar.VisibilityOn()
self.scalarBar.Modified()
self.iSubcaseNameMap = {1: ['AFLR BEDGE', '']}
cases = {}
ID = 1
self._add_alt_actors(self.alt_grids)
form, cases = self._fill_bedge_case(bedge_filename, cases, ID, nnodes, nelements, model)
if plot:
self._finish_results_io2(form, cases)
示例11: mapElements
#.........这里部分代码省略.........
elem.GetPointIds().SetId(16, nidMap[nodeIDs[16]])
elem.GetPointIds().SetId(17, nidMap[nodeIDs[17]])
elem.GetPointIds().SetId(18, nidMap[nodeIDs[18]])
elem.GetPointIds().SetId(19, nidMap[nodeIDs[19]])
else:
elem = vtkHexahedron()
elem.GetPointIds().SetId(0, nidMap[nodeIDs[0]])
elem.GetPointIds().SetId(1, nidMap[nodeIDs[1]])
elem.GetPointIds().SetId(2, nidMap[nodeIDs[2]])
elem.GetPointIds().SetId(3, nidMap[nodeIDs[3]])
elem.GetPointIds().SetId(4, nidMap[nodeIDs[4]])
elem.GetPointIds().SetId(5, nidMap[nodeIDs[5]])
elem.GetPointIds().SetId(6, nidMap[nodeIDs[6]])
elem.GetPointIds().SetId(7, nidMap[nodeIDs[7]])
self.grid.InsertNextCell(elem.GetCellType(),
elem.GetPointIds())
elif (isinstance(element, LineElement) or
isinstance(element, SpringElement) or
element.type in ['CBUSH', 'CBUSH1D', 'CFAST', 'CROD', 'CONROD',
'CELAS1', 'CELAS2', 'CELAS3', 'CELAS4',
'CDAMP1', 'CDAMP2', 'CDAMP3', 'CDAMP4', 'CDAMP5', 'CVISC', ]):
nodeIDs = element.nodeIDs()
if None not in nodeIDs: # used to be 0...
elem = vtk.vtkLine()
try:
elem.GetPointIds().SetId(0, nidMap[nodeIDs[0]])
elem.GetPointIds().SetId(1, nidMap[nodeIDs[1]])
except KeyError:
print "nodeIDs =", nodeIDs
print str(element)
continue
self.grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds())
elif isinstance(element, CONM2): # not perfectly located
del self.eidMap[eid]
i -= 1
#nid = element.Nid()
c = element.Centroid()
elem = vtk.vtkVertex()
#elem = vtk.vtkSphere()
#elem.SetRadius(1.0)
#print str(element)
points2.InsertPoint(j, *c)
elem.GetPointIds().SetId(0, j)
#elem.SetCenter(points.GetPoint(nidMap[nid]))
self.grid2.InsertNextCell(elem.GetCellType(), elem.GetPointIds())
j += 1
else:
del self.eidMap[eid]
self.log_info("skipping %s" % element.type)
continue
i += 1
self.grid.SetPoints(points)
self.grid2.SetPoints(points2)
#self.grid.GetPointData().SetScalars(self.gridResult)
#print dir(self.grid) #.SetNumberOfComponents(0)
#self.grid.GetCellData().SetNumberOfTuples(1);
#self.grid.GetCellData().SetScalars(self.gridResult)
self.grid.Modified()
self.grid2.Modified()
self.grid.Update()
self.grid2.Update()
self.log_info("updated grid")
cases = {}
nelements = len(model.elements)
print "len(elements) =", nelements
pids = [] # zeros(nelements, 'int32')
nxs = []
nys = []
nzs = []
i = 0
for eid, element in sorted(model.elements.iteritems()):
pids.append(element.Pid())
if isinstance(element, ShellElement):
(nx, ny, nz) = element.Normal()
else:
nx = ny = nz = 0.0
nxs.append(nx)
nys.append(ny)
nzs.append(nz)
self.iSubcaseNameMap = {1: ['Nastran', '']}
# subcaseID, resultType, vectorSize, location, dataFormat
if 1:
cases[(0, 'Pid', 1, 'centroid', '%.0f')] = pids
# if not a flat plate???
#if min(nxs) == max(nxs) and min(nxs) != 0.0:
# subcaseID, resultType, vectorSize, location, dataFormat
cases[(0, 'Normal_x', 1, 'centroid', '%.1f')] = nxs
cases[(0, 'Normal_y', 1, 'centroid', '%.1f')] = nys
cases[(0, 'Normal_z', 1, 'centroid', '%.1f')] = nzs
self.log.info(cases.keys())
self.finish_io(cases)
示例12: readDynaMesh
def readDynaMesh(lsdyna_mesh_filename,
cell_type='hexahedron',
verbose=0):
myVTK.myPrint(verbose, "*** readDynaMesh: "+lsdyna_mesh_filename+" ***")
points = vtk.vtkPoints()
if (cell_type == 'vertex'):
cell_vtk_type = vtk.VTK_VERTEX
cell = vtk.vtkVertex()
cell_array = vtk.vtkCellArray()
elif (cell_type == 'hexahedron'):
cell_vtk_type = vtk.VTK_HEXAHEDRON
cell = vtk.vtkHexahedron()
cell_array = vtk.vtkCellArray()
else:
print 'Wrong cell type. Aborting.'
exit()
myVTK.myPrint(verbose-1, "Reading Dyna mesh file...")
mesh_file = open(lsdyna_mesh_filename, 'r')
context = ''
for line in mesh_file:
if (line[-1:] == '\n'): line = line[:-1]
#myVTK.myPrint(verbose-1, "line ="+line)
if line.startswith('$'): continue
if (context == 'reading nodes'):
if line.startswith('*'):
context = ''
else:
splitted_line = line.split(',')
points.InsertNextPoint([float(coord) for coord in splitted_line[1:4]])
if (cell_type == 'vertex'):
cell.GetPointIds().SetId(0, points.GetNumberOfPoints()-1)
cell_array.InsertNextCell(cell)
if (context == 'reading elems'):
if line.startswith('*'):
context = ''
else:
splitted_line = line.split(',')
if (len(splitted_line) == 3): continue
if (cell_type == 'hexahedron'):
for k_node in xrange(8):
cell.GetPointIds().SetId(k_node, int(splitted_line[2+k_node])-1)
cell_array.InsertNextCell(cell)
if line.startswith('*NODE'): context = 'reading nodes'
if line.startswith('*ELEMENT_SOLID'): context = 'reading elems'
mesh_file.close()
myVTK.myPrint(verbose-1, "Creating VTK mesh...")
ugrid = vtk.vtkUnstructuredGrid()
ugrid.SetPoints(points)
ugrid.SetCells(cell_vtk_type, cell_array)
return ugrid
示例13: mapElements
#.........这里部分代码省略.........
elem.GetPointIds().SetId(5, nidMap[nodeIDs[5]])
self.grid.InsertNextCell(
elem.GetCellType(), elem.GetPointIds())
elif isinstance(element, CPENTA15):
nodeIDs = element.nodeIDs()
if None not in nodeIDs:
elem = vtkQuadraticWedge()
elem.GetPointIds().SetId(6, nidMap[nodeIDs[6]])
elem.GetPointIds().SetId(7, nidMap[nodeIDs[7]])
elem.GetPointIds().SetId(8, nidMap[nodeIDs[8]])
elem.GetPointIds().SetId(9, nidMap[nodeIDs[9]])
elem.GetPointIds().SetId(10, nidMap[nodeIDs[10]])
elem.GetPointIds().SetId(11, nidMap[nodeIDs[11]])
elem.GetPointIds().SetId(12, nidMap[nodeIDs[12]])
elem.GetPointIds().SetId(13, nidMap[nodeIDs[13]])
elem.GetPointIds().SetId(14, nidMap[nodeIDs[14]])
else:
elem = vtkWedge()
elem.GetPointIds().SetId(0, nidMap[nodeIDs[0]])
elem.GetPointIds().SetId(1, nidMap[nodeIDs[1]])
elem.GetPointIds().SetId(2, nidMap[nodeIDs[2]])
elem.GetPointIds().SetId(3, nidMap[nodeIDs[3]])
elem.GetPointIds().SetId(4, nidMap[nodeIDs[4]])
elem.GetPointIds().SetId(5, nidMap[nodeIDs[5]])
self.grid.InsertNextCell(
elem.GetCellType(), elem.GetPointIds())
elif isinstance(element, CHEXA8):
nodeIDs = element.nodeIDs()
elem = vtkHexahedron()
elem.GetPointIds().SetId(0, nidMap[nodeIDs[0]])
elem.GetPointIds().SetId(1, nidMap[nodeIDs[1]])
elem.GetPointIds().SetId(2, nidMap[nodeIDs[2]])
elem.GetPointIds().SetId(3, nidMap[nodeIDs[3]])
elem.GetPointIds().SetId(4, nidMap[nodeIDs[4]])
elem.GetPointIds().SetId(5, nidMap[nodeIDs[5]])
elem.GetPointIds().SetId(6, nidMap[nodeIDs[6]])
elem.GetPointIds().SetId(7, nidMap[nodeIDs[7]])
self.grid.InsertNextCell(
elem.GetCellType(), elem.GetPointIds())
elif isinstance(element, CHEXA20):
nodeIDs = element.nodeIDs()
#print "nodeIDs = ",nodeIDs
if None not in nodeIDs:
elem = vtkQuadraticHexahedron()
elem.GetPointIds().SetId(8, nidMap[nodeIDs[8]])
elem.GetPointIds().SetId(9, nidMap[nodeIDs[9]])
elem.GetPointIds().SetId(10, nidMap[nodeIDs[10]])
elem.GetPointIds().SetId(11, nidMap[nodeIDs[11]])
elem.GetPointIds().SetId(12, nidMap[nodeIDs[12]])
elem.GetPointIds().SetId(13, nidMap[nodeIDs[13]])
elem.GetPointIds().SetId(14, nidMap[nodeIDs[14]])
elem.GetPointIds().SetId(15, nidMap[nodeIDs[15]])
elem.GetPointIds().SetId(16, nidMap[nodeIDs[16]])
elem.GetPointIds().SetId(17, nidMap[nodeIDs[17]])
elem.GetPointIds().SetId(18, nidMap[nodeIDs[18]])
elem.GetPointIds().SetId(19, nidMap[nodeIDs[19]])
else:
elem = vtkHexahedron()
elem.GetPointIds().SetId(0, nidMap[nodeIDs[0]])
elem.GetPointIds().SetId(1, nidMap[nodeIDs[1]])
elem.GetPointIds().SetId(2, nidMap[nodeIDs[2]])
elem.GetPointIds().SetId(3, nidMap[nodeIDs[3]])
elem.GetPointIds().SetId(4, nidMap[nodeIDs[4]])
elem.GetPointIds().SetId(5, nidMap[nodeIDs[5]])
elem.GetPointIds().SetId(6, nidMap[nodeIDs[6]])
elem.GetPointIds().SetId(7, nidMap[nodeIDs[7]])
self.grid.InsertNextCell(
elem.GetCellType(), elem.GetPointIds())
elif isinstance(element, LineElement) or isinstance(element, SpringElement):
elem = vtk.vtkLine()
nodeIDs = element.nodeIDs()
elem.GetPointIds().SetId(0, nidMap[nodeIDs[0]])
elem.GetPointIds().SetId(1, nidMap[nodeIDs[1]])
self.grid.InsertNextCell(
elem.GetCellType(), elem.GetPointIds())
###
elif isinstance(element, CONM2): # not perfectly located
nid = element.Nid()
c = element.Centroid()
elem = vtk.vtkVertex()
#elem = vtk.vtkSphere()
#elem.SetRadius(1.0)
#print str(element)
points2.InsertPoint(j, *c)
elem.GetPointIds().SetId(0, j)
#elem.SetCenter(points.GetPoint(nidMap[nid]))
self.grid2.InsertNextCell(
elem.GetCellType(), elem.GetPointIds())
j += 1
else:
print "skipping %s" % (element.type)
###
self.grid.SetPoints(points)
self.grid2.SetPoints(points2)
self.grid.Update()
self.grid2.Update()
示例14:
#!/usr/bin/env python
import vtk
points = vtk.vtkPoints()
points.InsertNextPoint(0,0,0)
vertex = vtk.vtkVertex()
vertex.GetPointIds().SetId(0, 0)
vertices = vtk.vtkCellArray()
vertices.InsertNextCell(vertex)
polydata = vtk.vtkPolyData()
polydata.SetPoints(points)
polydata.SetVerts(vertices)
# Setup actor and mapper
mapper = vtk.vtkPolyDataMapper()
if vtk.VTK_MAJOR_VERSION <= 5:
mapper.SetInputConnection(polydata.GetProducerPort())
else:
mapper.SetInputData(polydata)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetPointSize(10)
# Setup render window, renderer, and interactor
renderer = vtk.vtkRenderer()
示例15: VtkSupport
Permute VTK node ordering into default node ordering
"""
newNodes = nodes
if type.GetElementTypeId() == elements.ELEMENT_QUAD:
newNodes = copy.deepcopy(nodes)
newNodes[2] = nodes[3]
newNodes[3] = nodes[2]
return newNodes
if VtkSupport():
VTK_UNKNOWN = None
VTK_EMPTY_CELL = vtk.vtkEmptyCell().GetCellType()
VTK_VERTEX = vtk.vtkVertex().GetCellType()
VTK_LINE = vtk.vtkLine().GetCellType()
VTK_QUADRATIC_LINE = vtk.vtkQuadraticEdge().GetCellType()
VTK_TRIANGLE = vtk.vtkTriangle().GetCellType()
VTK_QUADRATIC_TRIANGLE = vtk.vtkQuadraticTriangle().GetCellType()
VTK_TETRAHEDRON = vtk.vtkTetra().GetCellType()
VTK_QUADRATIC_TETRAHEDRON = vtk.vtkQuadraticTetra().GetCellType()
VTK_QUAD = vtk.vtkQuad().GetCellType()
VTK_HEXAHEDRON = vtk.vtkHexahedron().GetCellType()
vtkTypeIds = ( \
VTK_UNKNOWN, \
VTK_EMPTY_CELL, \
VTK_VERTEX, \
VTK_LINE, VTK_QUADRATIC_LINE, \
VTK_TRIANGLE, VTK_QUADRATIC_TRIANGLE, VTK_QUAD, \