本文整理汇总了Python中vtk.vtkDoubleArray函数的典型用法代码示例。如果您正苦于以下问题:Python vtkDoubleArray函数的具体用法?Python vtkDoubleArray怎么用?Python vtkDoubleArray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkDoubleArray函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, pdata):
"""
Constructor
@param pdata vtkPolyData instance
"""
self.polydata = pdata
# save the points and point data as separate class members
# so as not to pollute pdata
self.points = vtk.vtkPoints()
self.points.DeepCopy(pdata.GetPoints())
self.pointData = {}
pd = pdata.GetPointData()
for i in range(pd.GetNumberOfArrays()):
arr = pd.GetArray(i)
name = arr.GetName()
self.pointData[name] = vtk.vtkDoubleArray()
self.pointData[name].DeepCopy(arr)
self.cellData = {}
cd = pdata.GetCellData()
for i in range(cd.GetNumberOfArrays()):
name = cd.GetArray(i).GetName()
self.cellData[name] = vtk.vtkDoubleArray()
self.cellData[name].SetName(name)
示例2: initVTK
def initVTK(self, key):
print "initializing VTK objects"
self.__setMinMaxRange(key)
self.__normalize(key)
# Create our Data object
vtk.vtkStructuredGrid()
self.vtkStructuredGrid = vtk.vtkStructuredGrid()
self.vtkStructuredGrid.SetDimensions([128]*3)
# Set up Points
self.vtkPoints = vtk.vtkPoints()
self.vtkPoints.Allocate(128*3)
# Set up Cells
# self.vtkCells = vtk.vtkCellArray()
# Setup the velocity vectors
self.vtkVectors = vtk.vtkDoubleArray()
self.vtkVectors.SetNumberOfComponents(3)
self.vtkVectors.SetNumberOfTuples(self.sdfIdent.size)
# Setup the Scalars
self.vtkScalars = vtk.vtkDoubleArray()
self.vtkScalars.SetName(key)
# Allocate points, cells, scalars, and vector fields
self.AllocateData(self.sdfIdent.size, key)
# Now attach newly allocated objects to the grid
self.vtkStructuredGrid.SetPoints(self.vtkPoints)
# self.vtkStructuredGrid.SetVerts(self.vtkCells)
self.vtkStructuredGrid.GetPointData().SetVectors(self.vtkVectors)
self.vtkStructuredGrid.GetPointData().SetScalars(self.vtkScalars)
self.vtkStructuredGrid.GetPointData().SetActiveScalars(key)
示例3: SetVtkGrid
def SetVtkGrid(x,y,z):
"""Set up the vtk rectilinear grid using x, y, z data.
Parameters:
x, y, z -- the points in the x, y and z directions respectively
Returns:
grid -- a vtkRectilinearGrid object
"""
grid = vtkRectilinearGrid();
grid.SetDimensions(len(x),len(y),len(z));
xArray = vtkDoubleArray();
for xCoord in x: xArray.InsertNextValue(xCoord)
yArray = vtkDoubleArray();
for yCoord in y: yArray.InsertNextValue(yCoord)
zArray = vtkDoubleArray();
for zCoord in z: zArray.InsertNextValue(zCoord)
grid.SetXCoordinates(xArray);
grid.SetYCoordinates(yArray);
grid.SetZCoordinates(zArray);
print "There are " + str(grid.GetNumberOfPoints()) + " points.";
print "There are " + str(grid.GetNumberOfCells()) + " cells.";
return grid
示例4: cell_average
def cell_average(model, bucket):
""" Calculate a volume fraction estimate at the level of the grid."""
ugrid = vtk.vtkUnstructuredGrid()
ugrid.DeepCopy(model)
locator = vtk.vtkCellLocator()
locator.SetDataSet(ugrid)
locator.BuildLocator()
volfrac = numpy.zeros(ugrid.GetNumberOfCells())
volume = numpy.zeros(ugrid.GetNumberOfCells())
temperature = numpy.zeros(ugrid.GetNumberOfCells())
velocity = numpy.zeros((ugrid.GetNumberOfCells(),3))
for particle in bucket.particles:
cell_id = locator.FindCell(particle.pos)
volume[cell_id] += particle.volume
velocity[cell_id, :] += particle.volume*particle.vel
for _ in range(ugrid.GetNumberOfCells()):
if volume[_] >1.0e-12:
velocity[_, :] /= volume[_]
volfrac[_] = volume[_] / get_measure(ugrid.GetCell(_))
for particle in bucket.particles:
cell_id = locator.FindCell(particle.pos)
temperature[cell_id] += particle.volume*distance2(particle.vel,velocity[cell_id, :])
for _ in range(ugrid.GetNumberOfCells()):
if volume[_] >1.0e-12:
temperature[_] /= volume[_]
data = [vtk.vtkDoubleArray()]
data[0].SetName('SolidVolumeFraction')
data.append(vtk.vtkDoubleArray())
data[1].SetName('SolidVolumeVelocity')
data[1].SetNumberOfComponents(3)
data.append(vtk.vtkDoubleArray())
data[2].SetName('GranularTemperature')
# data.append(vtk.vtkDoubleArray())
# data[3].SetName('SolidPressure')
for _ in range(ugrid.GetNumberOfCells()):
data[0].InsertNextValue(volume[_])
data[1].InsertNextTuple3(*(velocity[_]))
data[2].InsertNextValue(temperature[_])
# data[3].InsertNextValue(solid_pressure[_])
pdata = vtk.vtkDoubleArray()
pdata.SetName('Time')
for _ in range(ugrid.GetNumberOfPoints()):
pdata.InsertNextValue(bucket.time)
for _ in data:
ugrid.GetCellData().AddArray(_)
ugrid.GetPointData().AddArray(pdata)
return ugrid
示例5: initializearray
def initializearray(polydata, arrayname, isscalar=True, ispointdata=True):
"""Initialize a data array. Choose pointdata or celldata and scalar or
vector. Array values are initialized with 0.0 or [0.0, 0.0, 0.0]."""
if ispointdata: # add array to pointdata
numberofpoints = polydata.GetNumberOfPoints()
array = vtk.vtkDoubleArray()
array.SetName(arrayname)
if isscalar: # array holds scalars
array.SetNumberOfValues(numberofpoints)
array.FillComponent(0, 0.0)
polydata.GetPointData().AddArray(array)
else: # array holds vectors
array.SetNumberOfComponents(3)
array.SetNumberOfTuples(numberofpoints)
for j in range(3):
array.FillComponent(j, 0.0)
polydata.GetPointData().AddArray(array)
else: # add array to celldata
numberofcells = polydata.GetNumberOfCells()
array = vtk.vtkDoubleArray()
array.SetName(arrayname)
if isscalar: # array holds scalars
array.SetNumberOfValues(numberofcells)
array.FillComponent(0, 0.0)
polydata.GetCellData().AddArray(array)
else: # array holds vectors
array.SetNumberOfComponents(3)
array.SetNumberOfTuples(numberofcells)
for j in range(3):
array.FillComponent(j, 0.0)
polydata.GetCellData().AddArray(array)
return array
示例6: __init__
def __init__(self):
pypes.pypeScript.__init__(self)
self.Surface = None
self.DeformedSurface = None
self.SourcePoints = vtk.vtkPoints()
self.TargetPoints = vtk.vtkPoints()
self.DisplacementNorms = vtk.vtkDoubleArray()
self.Displacements = vtk.vtkDoubleArray()
self.Displacements.SetNumberOfComponents(3)
self.SourceSpheres = vtk.vtkPolyData()
self.TargetSpheres = vtk.vtkPolyData()
self.SourceSpheres.SetPoints(self.SourcePoints)
self.TargetSpheres.SetPoints(self.TargetPoints)
self.SourceSpheres.GetPointData().SetScalars(self.DisplacementNorms)
self.SourceSpheres.GetPointData().SetVectors(self.Displacements)
self.vmtkRenderer = None
self.OwnRenderer = 0
self.DisplayDeformed = False
self.SurfaceMapper = None
self.Opacity = 1.0
self.SourceSpheresActor = None
self.TargetSpheresActor = None
self.SetScriptName("vmtkthinplatesplinedeformation")
self.SetInputMembers(
[
["Surface", "i", "vtkPolyData", 1, "", "the input surface", "vmtksurfacereader"],
["Opacity", "opacity", "float", 1, "(0.0,1.0)", "object opacities in the scene"],
["vmtkRenderer", "renderer", "vmtkRenderer", 1, "", "external renderer"],
]
)
self.SetOutputMembers([["DeformedSurface", "o", "vtkPolyData", 1, "", "", "vmtksurfacewriter"]])
示例7: make_unstructured_grid
def make_unstructured_grid(mesh, velocity, pressure, time, outfile=None):
"""Given a mesh (in Gmsh format), velocity and pressure fields, and a
time level, store the data in a vtkUnstructuredGridFormat."""
pnts = vtk.vtkPoints()
pnts.Allocate(len(mesh.nodes))
node2id = {}
for k, point in mesh.nodes.items():
node2id[k] = pnts.InsertNextPoint(point)
ugrid = vtk.vtkUnstructuredGrid()
ugrid.SetPoints(pnts)
for element in mesh.elements.values():
id_list = vtk.vtkIdList()
for node in element[2]:
id_list.InsertNextId(node2id[node])
ugrid.InsertNextCell(TYPE_DICT[element[0]], id_list)
data = []
data.append(vtk.vtkDoubleArray())
data[0].SetNumberOfComponents(3)
data[0].Allocate(3*pnts.GetNumberOfPoints())
data[0].SetName('Velocity')
data.append(vtk.vtkDoubleArray())
data[1].Allocate(pnts.GetNumberOfPoints())
data[1].SetName('Pressure')
data.append(vtk.vtkDoubleArray())
data[2].Allocate(pnts.GetNumberOfPoints())
data[2].SetName('Time')
for k in range(len(mesh.nodes)):
if hasattr(velocity, '__call__'):
data[0].InsertNextTuple3(*velocity(ugrid.GetPoints().GetPoint(k)))
else:
data[0].InsertNextTuple3(*velocity[k, :])
if hasattr(pressure, '__call__'):
data[1].InsertNextValue(pressure(ugrid.GetPoints().GetPoint(k)))
else:
data[1].InsertNextValue(pressure[k])
data[2].InsertNextValue(time)
for _ in data:
ugrid.GetPointData().AddArray(_)
if outfile:
write_to_file(ugrid, outfile)
return ugrid
示例8: Gather
def Gather(c, arr, root):
vtkArr = vtk.vtkDoubleArray()
count = len(arr)
vtkArr.SetNumberOfTuples(count)
for i in range(count):
vtkArr.SetValue(i, arr[i])
vtkResult = vtk.vtkDoubleArray()
c.Gather(vtkArr, vtkResult, root)
result = [vtkResult.GetValue(i) for i in range(vtkResult.GetNumberOfTuples())]
return [ tuple(result[i : i + count]) \
for i in range(0, vtkResult.GetNumberOfTuples(), count) ]
示例9: CreateParentArteryPatches
def CreateParentArteryPatches(parentCenterlines, clipPoints):
numberOfDaughterPatches = parentCenterlines.GetNumberOfCells()
patchedCenterlines = vtk.vtkPolyData()
patchedCenterlinesPoints = vtk.vtkPoints()
patchedCenterlinesCellArray = vtk.vtkCellArray()
patchedRadiusArray = vtk.vtkDoubleArray()
clipIds, numberOfPatchedCenterlinesPoints = ExtractPatchesIds(parentCenterlines, clipPoints)
print "Clipping Point Ids ", clipIds
radiusArray = vtk.vtkDoubleArray()
radiusArray.SetNumberOfComponents(1)
radiusArray.SetName(radiusArrayName)
radiusArray.SetNumberOfTuples(numberOfPatchedCenterlinesPoints)
radiusArray.FillComponent(0, 0.0)
numberOfCommonPatch = clipIds[0] + 1
patchedCenterlinesCellArray.InsertNextCell(numberOfCommonPatch)
count = 0
for i in range(0, numberOfCommonPatch):
patchedCenterlinesPoints.InsertNextPoint(parentCenterlines.GetPoint(i))
patchedCenterlinesCellArray.InsertCellPoint(i)
radiusArray.SetTuple1(i, parentCenterlines.GetPointData().GetArray(radiusArrayName).GetTuple1(i))
count += 1
for j in range(numberOfDaughterPatches):
cell = vtk.vtkGenericCell()
parentCenterlines.GetCell(j, cell)
numberOfCellPoints = cell.GetNumberOfPoints()
startId = clipIds[j + 1]
patchNumberOfPoints = numberOfCellPoints - startId
patchedCenterlinesCellArray.InsertNextCell(patchNumberOfPoints)
for i in range(startId, cell.GetNumberOfPoints()):
point = cell.GetPoints().GetPoint(i)
patchedCenterlinesPoints.InsertNextPoint(point)
patchedCenterlinesCellArray.InsertCellPoint(count)
radiusArray.SetTuple1(
count, parentCenterlines.GetPointData().GetArray(radiusArrayName).GetTuple1(cell.GetPointId(i))
)
count += 1
patchedCenterlines.SetPoints(patchedCenterlinesPoints)
patchedCenterlines.SetLines(patchedCenterlinesCellArray)
patchedCenterlines.GetPointData().AddArray(radiusArray)
return patchedCenterlines
示例10: vtkbasis
def vtkbasis(mesh, etob, fname, coeffs):
''' Find the directions from a (non-uniform) plane wave basis and output a VTK-compatible file
It's possible that this needs to be updated to work with recent changes to ElementToBasis
'''
try:
import vtk
points = vtk.vtkPoints()
vectors = vtk.vtkDoubleArray()
vectors.SetNumberOfComponents(3)
scalars = vtk.vtkDoubleArray()
nc = 0
for e in range(mesh.nelements):
c = paa.origin(mesh, e)
bs = etob[e]
cc = np.zeros(3)
cc[:len(c)] = c
nondir = 0
ndir = 0
for b in bs:
if hasattr(b, "directions"):
for d in b.directions.transpose():
dd = np.zeros(3)
dd[:len(d)] = d
if coeffs is not None: dd *= abs(coeffs[nc])
points.InsertNextPoint(*cc)
vectors.InsertNextTuple3(*dd)
ndir+=1
nc+=1
else:
nondir += np.sqrt(np.sum(coeffs[nc:nc+b.n]**2))
nc += b.n
for _ in range(ndir): scalars.InsertNextValue(nondir)
g = vtk.vtkUnstructuredGrid()
g.SetPoints(points)
gpd = g.GetPointData()
gpd.SetVectors(vectors)
gpd.SetScalars(scalars)
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetFileName(fname)
writer.SetInput(g)
writer.Write()
except ImportError as e:
print "Unable to write basis to file: ",e
示例11: ReadTetrIniFile
def ReadTetrIniFile(self,filename,arrayname):
self.PrintLog('Reading '+filename+'.')
if (self.Compressed == 1):
f=gzip.open(filename, 'r')
else:
f=open(filename, 'r')
line = f.readline()
while (line!='$vel_old1'):
line = f.readline()
line = f.readline()
line = f.readline()
numberOfTuples = int(line)
outputArray = vtk.vtkDoubleArray()
outputArray.SetName(arrayname)
outputArray.SetNumberOfComponents(3)
outputArray.SetNumberOfTuples(numberOfTuples)
for i in range(numberOfTuples):
line = f.readline()
splitline = line.split(' ')
value0 = float(splitline[0])
value1 = float(splitline[1])
value2 = float(splitline[2])
outputArray.SetComponent(i,0,value0)
outputArray.SetComponent(i,1,value1)
outputArray.SetComponent(i,2,value2)
self.Mesh.GetPointData().AddArray(outputArray)
示例12: ReadTetrVelFile
def ReadTetrVelFile(self,filename,arrayname):
self.PrintLog('Reading '+filename+'.')
if self.UnNormalize == 1:
self.ReadTetrInDimensionalParameters()
if (self.Compressed == 1):
f=gzip.open(filename, 'r')
else:
f=open(filename, 'r')
lines = f.readlines()
line = lines[0]
lineoffset = 1
splitline = line.split(' ')
numberOfTuples = int(splitline[0])
iteration = float(splitline[1])
outputArray = vtk.vtkDoubleArray()
outputArray.SetName(arrayname)
outputArray.SetNumberOfComponents(3)
outputArray.SetNumberOfTuples(numberOfTuples)
velocityUnNormalizationFactor = self.ReD / (2.0 * self.Radius) * self.Viscosity / self.Density
for i in range(numberOfTuples):
line = lines[i+lineoffset]
splitline = line.split(' ')
value0 = float(splitline[0])
value1 = float(splitline[1])
value2 = float(splitline[2])
if self.UnNormalize ==1:
value0 *= velocityUnNormalizationFactor
value1 *= velocityUnNormalizationFactor
value2 *= velocityUnNormalizationFactor
outputArray.SetComponent(i,0,value0)
outputArray.SetComponent(i,1,value1)
outputArray.SetComponent(i,2,value2)
self.Mesh.GetPointData().AddArray(outputArray)
示例13: addVectorToNode
def addVectorToNode(self,fieldValues,name):
datas = vtk.vtkDoubleArray()
datas.SetNumberOfComponents(3)
datas.SetName(name)
for value in fieldValues:
datas.InsertNextTuple3(value[0],value[1],value[2])
self._hexs.GetPointData().AddArray(datas)
示例14: convertArray2vtkImage
def convertArray2vtkImage(self, nparray, t_ImagedataVTK, npImagesandMask):
""" Takes a numpy.ndarray and converts it to a vtkimageData. require npImagesandMask to pass on image info """
# Create vtk object
size_array = npImagesandMask['dims'][0]*npImagesandMask['dims'][1]*npImagesandMask['dims'][2]
flatim = nparray.transpose(2,1,0)
flatim = flatim.flatten()
# create vtk image
vtk_image = vtk.vtkImageData()
vtk_image.DeepCopy(t_ImagedataVTK)
vtk_image.SetNumberOfScalarComponents(1)
vtk_image.SetScalarTypeToDouble()
vtk_image.AllocateScalars()
# Get scalars from numpy
image_array = vtk.vtkDoubleArray()
image_array.SetNumberOfValues(size_array)
image_array.SetNumberOfComponents(1)
# not too efficient convertion of np.array to vtk. Far from ideal
for k in range(size_array):
image_array.InsertTuple1(k,flatim[k])
vtk_image.GetPointData().SetScalars(image_array)
vtk_image.Update()
return vtk_image
示例15: buildATPMesh
def buildATPMesh(polydata, filename):
centroidFilter = vtk.vtkCellCenters()
centroidFilter.VertexCellsOn()
centroidFilter.SetInputData(polydata)
newPolydata = vtk.vtkPolyData()
newPolydata = centroidFilter.GetOutput()
centroidFilter.Update()
ATPValues = vtk.vtkDoubleArray()
ATPValues.SetName("initialATP")
_, _, yMin, yMax, _, _ = polydata.GetBounds()
yRange = yMax - yMin
for pointId in range(0, newPolydata.GetNumberOfPoints()):
_, y, _ = newPolydata.GetPoint(pointId)
ATPValue = y / (yRange * 1.0)
ATPValues.InsertNextValue(ATPValue)
newPolydata.GetCellData().SetScalars(ATPValues)
polyDataWriter = vtk.vtkXMLPolyDataWriter()
polyDataWriter.SetFileName(filename)
polyDataWriter.SetInputData(newPolydata)
polyDataWriter.Write()