本文整理汇总了Python中vtk.vtkPoints函数的典型用法代码示例。如果您正苦于以下问题:Python vtkPoints函数的具体用法?Python vtkPoints怎么用?Python vtkPoints使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkPoints函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: computeSphericalPoints
def computeSphericalPoints( self, **args ):
lon_data = self.np_points_data[0::3]
lat_data = self.np_points_data[1::3]
z_data = self.np_points_data[2::3]
radian_scaling = math.pi / 180.0
theta = ( 90.0 - lat_data ) * radian_scaling
phi = lon_data * radian_scaling
r = z_data * self.spherical_scaling + self.earth_radius
self.np_sp_grid_data = numpy.dstack( ( r, theta, phi ) ).flatten()
vtk_sp_grid_data = numpy_support.numpy_to_vtk( self.np_sp_grid_data )
# if self.grid == PlotType.List:
# # r = numpy.empty( lon_data.shape, lon_data.dtype )
# # r.fill( self.earth_radius )
# r = z_data * self.spherical_scaling + self.earth_radius
# self.np_sp_grid_data = numpy.dstack( ( r, theta, phi ) ).flatten()
# vtk_sp_grid_data = numpy_support.numpy_to_vtk( self.np_sp_grid_data )
# elif self.grid == PlotType.Grid:
# thetaB = theta.reshape( [ theta.shape[0], 1 ] )
# phiB = phi.reshape( [ 1, phi.shape[0] ] )
# grid_data = numpy.array( [ ( self.earth_radius, t, p ) for (t,p) in numpy.broadcast(thetaB,phiB) ] )
# self.np_sp_grid_data = grid_data.flatten()
# vtk_sp_grid_data = numpy_support.numpy_to_vtk( self.np_sp_grid_data )
# else:
# print>>sys.stderr, "Unrecognized grid type: %s " % str( self.grid )
# return
size = vtk_sp_grid_data.GetSize()
vtk_sp_grid_data.SetNumberOfComponents( 3 )
vtk_sp_grid_data.SetNumberOfTuples( size/3 )
vtk_sp_grid_points = vtk.vtkPoints()
vtk_sp_grid_points.SetData( vtk_sp_grid_data )
self.vtk_spherical_points = vtk.vtkPoints()
self.shperical_to_xyz_trans.TransformPoints( vtk_sp_grid_points, self.vtk_spherical_points )
示例2: DeleteCallback
def DeleteCallback(self, obj):
delId = -1
sourceValid = False
if self.CurrentSourcePointId != -1:
delId = self.CurrentSourcePointId
sourceValid = True
elif self.CurrentTargetPointId != -1:
delId = self.CurrentTargetPointId
else:
return
savedSources = vtk.vtkPoints()
savedSources.DeepCopy(self.SourcePoints)
savedTargets = vtk.vtkPoints()
savedTargets.DeepCopy(self.TargetPoints)
self.InitializeSpheres()
for i in range(savedSources.GetNumberOfPoints()):
if i != delId:
self.AddDisplacement(savedSources.GetPoint(i), savedTargets.GetPoint(i))
nPoints = self.SourcePoints.GetNumberOfPoints()
if nPoints == 0:
self.SelectSource(-1)
elif sourceValid:
self.SelectSource((delId - 1) % nPoints)
else:
self.SelectTarget((delId - 1) % nPoints)
self.SourceSpheres.Modified()
self.TargetSpheres.Modified()
self.vmtkRenderer.RenderWindow.Render()
示例3: latitude_create
def latitude_create(
arg_lat,
arg_projection):
if arg_projection == 'linear' :
n_polypoints=2
polygonpoints=vtk.vtkPoints()
polygonpoints.SetNumberOfPoints(n_polypoints)
polygonpoints.InsertPoint(0,-180,arg_lat,0)
polygonpoints.InsertPoint(1,540,arg_lat,0)
else:
n_polypoints=360
polygonpoints=vtk.vtkPoints()
polygonpoints.SetNumberOfPoints(n_polypoints)
deg2rad=numpy.pi/180.
for n in range(n_polypoints) :
theta=2*numpy.pi*n/(n_polypoints-1)
x=numpy.cos(arg_lat*deg2rad)*numpy.cos(theta)
y=numpy.cos(arg_lat*deg2rad)*numpy.sin(theta)
z=numpy.sin(arg_lat*deg2rad)
polygonpoints.InsertPoint(n,x,y,z)
polygonlines=vtk.vtkCellArray()
polygonlines.InsertNextCell(n_polypoints)
for n in range(n_polypoints) :
polygonlines.InsertCellPoint(n)
latpolydata=vtk.vtkPolyData()
latpolydata.SetPoints(polygonpoints)
latpolydata.SetLines(polygonlines)
return latpolydata
示例4: setPointHeights
def setPointHeights( self, ptheights ):
try:
if self.topo == PlotType.Planar:
self.np_points_data[2::3] = ptheights
vtk_points_data = numpy_support.numpy_to_vtk( self.np_points_data )
vtk_points_data.SetNumberOfComponents( 3 )
vtk_points_data.SetNumberOfTuples( len( self.np_points_data ) / 3 )
self.vtk_planar_points.SetData( vtk_points_data )
self.polydata.SetPoints( self.vtk_planar_points )
self.vtk_planar_points.Modified()
elif self.topo == PlotType.Spherical:
self.np_sp_grid_data[0::3] = self.spherical_scaling * ptheights + self.earth_radius
vtk_sp_grid_data = numpy_support.numpy_to_vtk( self.np_sp_grid_data )
size = vtk_sp_grid_data.GetSize()
vtk_sp_grid_data.SetNumberOfComponents( 3 )
vtk_sp_grid_data.SetNumberOfTuples( size/3 )
vtk_sp_grid_points = vtk.vtkPoints()
vtk_sp_grid_points.SetData( vtk_sp_grid_data )
self.vtk_spherical_points = vtk.vtkPoints()
self.shperical_to_xyz_trans.TransformPoints( vtk_sp_grid_points, self.vtk_spherical_points )
# pt0 = self.vtk_spherical_points.GetPoint(0)
# print "VTK Set point Heights, samples: %s %s %s " % ( str( ptheights[0] ), str( self.np_sp_grid_data[0] ), str( pt0 ) )
self.polydata.SetPoints( self.vtk_spherical_points )
self.vtk_spherical_points.Modified()
self.polydata.Modified()
except Exception, err:
self.printLogMessage( "Processing point heights: %s " % str( err ), error=True )
示例5: __init__
def __init__(self, sliceWidget):
# keep a flag since events such as sliceNode modified
# may come during superclass construction, which will
# invoke our processEvents method
self.initialized = False
super(DrawEffectTool,self).__init__(sliceWidget)
# create a logic instance to do the non-gui work
self.logic = DrawEffectLogic(self.sliceWidget.sliceLogic())
# interaction state variables
self.activeSlice = None
self.lastInsertSLiceNodeMTime = None
self.actionState = None
# initialization
self.xyPoints = vtk.vtkPoints()
self.rasPoints = vtk.vtkPoints()
self.polyData = self.createPolyData()
self.mapper = vtk.vtkPolyDataMapper2D()
self.actor = vtk.vtkActor2D()
self.mapper.SetInputData(self.polyData)
self.actor.SetMapper(self.mapper)
property_ = self.actor.GetProperty()
property_.SetColor(1,1,0)
property_.SetLineWidth(1)
self.renderer.AddActor2D( self.actor )
self.actors.append( self.actor )
self.initialized = True
示例6: genTextActor
def genTextActor(renderer,string=None,x=None,y=None,to='default',tt='default',cmap=None):
if isinstance(to,str):
to = vcs.elements["textorientation"][to]
if isinstance(tt,str):
tt = vcs.elements["texttable"][tt]
if tt.priority==0:
return []
if string is None:
string = tt.string
if x is None:
x = tt.x
if y is None:
y = tt.y
if x is None or y is None or string in [['',],[]]:
return []
n = max(len(x),len(y),len(string))
for a in [x,y,string]:
while len(a)<n:
a.append(a[-1])
sz = renderer.GetRenderWindow().GetSize()
actors=[]
pts = vtk.vtkPoints()
geo = None
if vcs.elements["projection"][tt.projection].type!="linear":
# Need to figure out new WC
Npts = 20
for i in range(Npts+1):
X = tt.worldcoordinate[0]+float(i)/Npts*(tt.worldcoordinate[1]-tt.worldcoordinate[0])
for j in range(Npts+1):
Y = tt.worldcoordinate[2]+float(j)/Npts*(tt.worldcoordinate[3]-tt.worldcoordinate[2])
pts.InsertNextPoint(X,Y,0.)
geo,pts = project(pts,tt.projection,tt.worldcoordinate,geo=None)
wc = pts.GetBounds()[:4]
#renderer.SetViewport(tt.viewport[0],tt.viewport[2],tt.viewport[1],tt.viewport[3])
renderer.SetWorldPoint(wc)
for i in range(n):
t = vtk.vtkTextActor()
p=t.GetTextProperty()
prepTextProperty(p,sz,to,tt,cmap)
pts = vtk.vtkPoints()
pts.InsertNextPoint(x[i],y[i],0.)
if geo is not None:
geo,pts = project(pts,tt.projection,tt.worldcoordinate,geo=geo)
X,Y,tz=pts.GetPoint(0)
X,Y = world2Renderer(renderer,X,Y,tt.viewport,wc)
else:
X,Y = world2Renderer(renderer,x[i],y[i],tt.viewport,tt.worldcoordinate)
t.SetPosition(X,Y)
t.SetInput(string[i])
#T=vtk.vtkTransform()
#T.Scale(1.,sz[1]/606.,1.)
#T.RotateY(to.angle)
#t.SetUserTransform(T)
renderer.AddActor(t)
actors.append(t)
return actors
示例7: __init__
def __init__(self, sliceWidget):
super(LevelTracingEffectTool,self).__init__(sliceWidget)
# create a logic instance to do the non-gui work
self.logic = LevelTracingEffectLogic(self.sliceWidget.sliceLogic())
# instance variables
self.actionState = ''
# initialization
self.xyPoints = vtk.vtkPoints()
self.rasPoints = vtk.vtkPoints()
self.polyData = vtk.vtkPolyData()
self.tracingFilter = vtkITK.vtkITKLevelTracingImageFilter()
self.ijkToXY = vtk.vtkGeneralTransform()
self.mapper = vtk.vtkPolyDataMapper2D()
self.actor = vtk.vtkActor2D()
property_ = self.actor.GetProperty()
property_.SetColor( 107/255., 190/255., 99/255. )
property_.SetLineWidth( 1 )
if vtk.VTK_MAJOR_VERSION <= 5:
self.mapper.SetInput(self.polyData)
else:
self.mapper.SetInputData(self.polyData)
self.actor.SetMapper(self.mapper)
property_ = self.actor.GetProperty()
property_.SetColor(1,1,0)
property_.SetLineWidth(1)
self.renderer.AddActor2D( self.actor )
self.actors.append( self.actor )
示例8: getRigidTransform
def getRigidTransform(fix, mov): # In real resolution
LandmarkTransform = vtk.vtkLandmarkTransform()
LandmarkTransform.SetModeToRigidBody()
n = fix.shape[0]
fix_point = vtk.vtkPoints()
fix_point.SetNumberOfPoints(n)
mov_point = vtk.vtkPoints()
mov_point.SetNumberOfPoints(n)
for i in range(n):
fix_point.SetPoint(i, fix[i, 0], fix[i, 1], fix[i, 2])
mov_point.SetPoint(i, mov[i, 0], mov[i, 1], mov[i, 2])
LandmarkTransform.SetSourceLandmarks(mov_point)
LandmarkTransform.SetTargetLandmarks(fix_point)
LandmarkTransform.Update()
matrix = LandmarkTransform.GetMatrix()
T = ml.zeros([4, 4], dtype = npy.float32)
for i in range(4):
for j in range(4):
T[i, j] = matrix.GetElement(j, i)
p1 = mov[0, :].tolist()
p2 = [0.0, 0, 0]
LandmarkTransform.InternalTransformPoint(p1, p2)
return T, npy.array(p2)
示例9: display
def display(data, data2=None, data3=None):
# Generate some random points
math = vtk.vtkMath()
points = vtk.vtkPoints()
[data, scalefactor]=scaledata(data)
for i in range(len(data)):
points.InsertNextPoint( data[i,0],data[i,1], data[i,2]);
ballActor = vtksetup(points, color=red, radius=.001)
[ren,renWin,iren]=vtkwindow()
ren.AddActor(ballActor) # Add the actors to the renderer, set the background and size
if data2 != None:
data=data2*scalefactor
points = vtk.vtkPoints()
for i in range(len(data)):
points.InsertNextPoint( data[i,0],data[i,1], data[i,2]);
ballActor = vtksetup(points, color=blue)
ren.AddActor(ballActor)
if data3 != None:
data=data3*scalefactor
points = vtk.vtkPoints()
for i in range(len(data)):
points.InsertNextPoint( data[i,0],data[i,1], data[i,2]);
ballActor = vtksetup(points, color=green, radius=.007)
ren.AddActor(ballActor)
# Interact with the data.
iren.Initialize()
renWin.Render()
iren.Start()
示例10: __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"]])
示例11: KeyPressCallback
def KeyPressCallback(self, obj, event):
ch = self.window_interactor.GetKeySym()
if ch == 'Return':
trans = loadTransform()
num = 0
for transform in trans:
self.point_data_result = applyTransform(self.tmp_data_move, transform)
self.point_data_result[:, :3] /= self.tmp_space
for cnt in range(3, 6):
point_result = self.point_data_result[npy.where(npy.round(self.point_data_result[:, -1]) == cnt - 3)]
point_move = self.point_data_move[npy.where(npy.round(self.point_data_move[:, -1]) == cnt - 3)]
if not point_result.shape[0]:
continue
self.cells = vtk.vtkCellArray()
self.points = vtk.vtkPoints()
l = 0
for i in range(self.zmin, self.zmax + 1):
data = point_result[npy.where(npy.round(point_move[:, 2]) == i)]
if data is not None:
if data.shape[0] == 0:
continue
count = data.shape[0]
points = vtk.vtkPoints()
for j in range(count):
points.InsertPoint(j, data[j, 0], data[j, 1], data[j, 2])
para_spline = vtk.vtkParametricSpline()
para_spline.SetXSpline(vtk.vtkKochanekSpline())
para_spline.SetYSpline(vtk.vtkKochanekSpline())
para_spline.SetZSpline(vtk.vtkKochanekSpline())
para_spline.SetPoints(points)
para_spline.ClosedOn()
# The number of output points set to 10 times of input points
numberOfOutputPoints = count * 10
self.cells.InsertNextCell(numberOfOutputPoints)
for k in range(0, numberOfOutputPoints):
t = k * 1.0 / numberOfOutputPoints
pt = [0.0, 0.0, 0.0]
para_spline.Evaluate([t, t, t], pt, [0] * 9)
if pt[0] != pt[0]:
print pt
continue
self.points.InsertPoint(l, pt[0], pt[1], pt[2])
self.cells.InsertCellPoint(l)
l += 1
self.contours[cnt].SetPoints(self.points)
self.contours[cnt].SetPolys(self.cells)
self.contours[cnt].Update()
self.render_window.Render()
saveGif(self.render_window, num)
num += 1
示例12: method
def method(self):
# multiblock += contact points
output_a = self._contact_source_a.GetPolyDataOutput()
output_b = self._contact_source_b.GetPolyDataOutput()
id_f = numpy.where(
abs(self._data[:, 0] - self._time) < 1e-15)[0]
self.cpa_export = self._data[
id_f, 2:5].copy()
self.cpb_export = self._data[
id_f, 5:8].copy()
self.cn_export = self._data[
id_f, 8:11].copy()
self.cf_export = self._data[
id_f, 11:14].copy()
self.cpa_ = numpy_support.numpy_to_vtk(
self.cpa_export)
self.cpa_.SetName('contact_positions_A')
self.cpb_ = numpy_support.numpy_to_vtk(
self.cpb_export)
self.cpb_.SetName('contact_positions_B')
self.cn_ = numpy_support.numpy_to_vtk(
self.cn_export)
self.cn_.SetName('contact_normals')
self.cf_ = numpy_support.numpy_to_vtk(
self.cf_export)
self.cf_.SetName('contact_forces')
output_a.Allocate(len(self.cpa_export), 1)
cpa_points = vtk.vtkPoints()
cpa_points.SetNumberOfPoints(len(self.cpa_export))
cpa_points.SetData(self.cpa_)
output_a.SetPoints(cpa_points)
# normal and forces are attached to A points
output_a.GetPointData().AddArray(self.cn_)
output_a.GetPointData().AddArray(self.cf_)
output_b.Allocate(len(self.cpb_export), 1)
cpb_points = vtk.vtkPoints()
cpb_points.SetNumberOfPoints(len(self.cpb_export))
cpb_points.SetData(self.cpb_)
output_b.SetPoints(cpb_points)
示例13: vtk_ellipsoid_topomesh
def vtk_ellipsoid_topomesh(ellipsoid_radius=50.0, ellipsoid_scales=[1,1,1], ellipsoid_axes=np.diag(np.ones(3)), ellipsoid_center=np.zeros(3)):
"""
"""
import vtk
from openalea.cellcomplex.property_topomesh.utils.image_tools import vtk_polydata_to_triangular_mesh
ico = vtk.vtkPlatonicSolidSource()
ico.SetSolidTypeToIcosahedron()
ico.Update()
subdivide = vtk.vtkLoopSubdivisionFilter()
subdivide.SetNumberOfSubdivisions(3)
subdivide.SetInputConnection(ico.GetOutputPort())
subdivide.Update()
scale_transform = vtk.vtkTransform()
scale_factor = ellipsoid_radius/(np.sqrt(2)/2.)
scale_transform.Scale(scale_factor,scale_factor,scale_factor)
ellipsoid_sphere = vtk.vtkTransformPolyDataFilter()
ellipsoid_sphere.SetInput(subdivide.GetOutput())
ellipsoid_sphere.SetTransform(scale_transform)
ellipsoid_sphere.Update()
ellipsoid_transform = vtk.vtkTransform()
axes_transform = vtk.vtkLandmarkTransform()
source_points = vtk.vtkPoints()
source_points.InsertNextPoint([1,0,0])
source_points.InsertNextPoint([0,1,0])
source_points.InsertNextPoint([0,0,1])
target_points = vtk.vtkPoints()
target_points.InsertNextPoint(ellipsoid_axes[0])
target_points.InsertNextPoint(ellipsoid_axes[1])
target_points.InsertNextPoint(ellipsoid_axes[2])
axes_transform.SetSourceLandmarks(source_points)
axes_transform.SetTargetLandmarks(target_points)
axes_transform.SetModeToRigidBody()
axes_transform.Update()
ellipsoid_transform.SetMatrix(axes_transform.GetMatrix())
ellipsoid_transform.Scale(ellipsoid_scales[0],ellipsoid_scales[1],ellipsoid_scales[2])
center_transform = vtk.vtkTransform()
center_transform.Translate(ellipsoid_center[0],ellipsoid_center[1],ellipsoid_center[2])
center_transform.Concatenate(ellipsoid_transform)
ellipsoid_ellipsoid = vtk.vtkTransformPolyDataFilter()
ellipsoid_ellipsoid.SetInput(ellipsoid_sphere.GetOutput())
ellipsoid_ellipsoid.SetTransform(center_transform)
ellipsoid_ellipsoid.Update()
ellipsoid_mesh = vtk_polydata_to_triangular_mesh(ellipsoid_ellipsoid.GetOutput())
topomesh = triangle_topomesh(ellipsoid_mesh.triangles.values(),ellipsoid_mesh.points)
return topomesh
示例14: draw_lines
def draw_lines(nodes, color):
colors = vtk.vtkUnsignedCharArray()
colors.SetNumberOfComponents(3)
colors.SetName("Colors")
cnt = 0
noderange = 100
mod = 1
edges = nodes[0].getedges()
points = vtk.vtkPoints()
lines = vtk.vtkCellArray()
nodecnt = 0
while cnt < len(nodes):
node = nodes[cnt]
cnt += 1
edges = node.getedges()
for edge in edges:
x0,y0,z0 = edge[0]
x1,y1,z1 = edge[1]
points.InsertNextPoint(edge[0])
points.InsertNextPoint(edge[1])
line = vtk.vtkLine()
line.GetPointIds().SetId(0,nodecnt)
line.GetPointIds().SetId(1,nodecnt+1)
lines.InsertNextCell(line)
nodecnt += 2
colors.InsertNextTupleValue(color)
if cnt % mod == 0:
print "noderange", noderange, "cnt", cnt, "mod",mod
# Create a polydata to store everything in
linesPolyData = vtk.vtkPolyData()
# Add the points to the dataset
linesPolyData.SetPoints(points)
# Add the lines to the dataset
linesPolyData.SetLines(lines)
linesPolyData.GetCellData().SetScalars(colors)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(linesPolyData)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
renderer.AddActor(actor)
points = vtk.vtkPoints()
lines = vtk.vtkCellArray()
nodecnt = 0
renderWindow.Render()
camera = renderer.GetActiveCamera()
camera.Azimuth(0.1)
print "done!"
示例15: InitializeSeeds
def InitializeSeeds(self):
if (self.InteractionMode==0):
self.SeedIds.Initialize()
self.SeedPoints.Initialize()
seedPoints = vtk.vtkPoints()
self.SeedPoints.SetPoints(seedPoints)
else:
self.ExamineSpheres.Initialize()
spherePoints = vtk.vtkPoints()
self.ExamineSpheres.SetPoints(spherePoints)
self.ExamineSpheres.GetPointData().Initialize()
sphereRadii = vtk.vtkDoubleArray()
self.ExamineSpheres.GetPointData().SetScalars(sphereRadii)