本文整理汇总了Python中vtk.vtkPolygon函数的典型用法代码示例。如果您正苦于以下问题:Python vtkPolygon函数的具体用法?Python vtkPolygon怎么用?Python vtkPolygon使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkPolygon函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getCell2vtp
def getCell2vtp(vtkObj,ind):
"""
Function gets a cell by ind and constructs a polydata from it.
"""
# Get the cell
cE = vtkObj.GetCell(ind)
# Make the polygon
if cE.GetCellType() == 11:
# Use a cubeSource, much faster
cube = vtk.vtkCubeSource()
cube.SetBounds(cE.GetBounds())
cube.Update()
vtpObj = cube.GetOutput()
else:
polygons = vtk.vtkCellArray()
for iF in range(cE.GetNumberOfFaces()):
f = cE.GetFace(iF)
poly = vtk.vtkPolygon()
poly.GetPointIds().SetNumberOfIds(f.GetNumberOfPoints())
for nr in range(f.GetNumberOfPoints()):
poly.GetPointIds().SetId(nr,f.GetPointId(nr))
polygons.InsertNextCell(poly)
# Build the polydata
vtpObj = vtk.vtkPolyData()
vtpObj.SetPoints(obj.GetPoints())
vtpObj.SetPolys(polygons)
return polydata.normFilter(polydata.triangulatePolyData(vtpObj))
示例2: polygons
def polygons(indices):
"""
Maps a numpy ndarray to an vtkCellArray of vtkPolygons
Args:
indices (numpy.ndarray<int>): A numpy.ndarray of shape (n,m) of indices that define n polygons with m points each
Returns:
vtk_polygons (vtk.vtkCellArray): VTK representation of the polygons
"""
if not isinstance(indices, numpy.ndarray):
raise Numpy2VtkFormatException(
'polygons needs numpy array as input'
)
if len(indices.shape) != 2:
raise Numpy2VtkFormatException(
'polygons needs a nxm ndarray as input'
)
if indices.dtype != numpy.int:
raise Numpy2VtkFormatException(
'polygons needs to be numpy array of type numpy.int'
)
number_of_polygons = indices.shape[0]
poly_shape = indices.shape[1]
vtk_polygons = vtk.vtkCellArray()
for j in range(0, number_of_polygons):
polygon = vtk.vtkPolygon()
polygon.GetPointIds().SetNumberOfIds(poly_shape)
for i in range(0, poly_shape):
polygon.GetPointIds().SetId(i, indices[j, i])
vtk_polygons.InsertNextCell(polygon)
return vtk_polygons
示例3: _update_vtk_objects
def _update_vtk_objects(self):
"""When n is changed the thus the number of coordinates this function is needed
to update the vtk objects with the new number of points."""
# self._vtk_points.SetNumberOfPoints(len(self._points))
# for i, c in enumerate(self._points):
# self._vtk_points.InsertPoint(i, c[0], c[1], c[2])
self._vtk_points = _vtk.vtkPoints()
for coordinates in self._points:
self._vtk_points.InsertNextPoint(coordinates[0], coordinates[1], coordinates[2])
self._vtk_polygons = _vtk.vtkCellArray()
for polygon in self._polygons:
vtk_polygon = _vtk.vtkPolygon()
vtk_polygon.GetPointIds().SetNumberOfIds(3)
for local_index, global_index in enumerate(polygon):
vtk_polygon.GetPointIds().SetId(local_index, global_index)
self._vtk_polygons.InsertNextCell(vtk_polygon)
self._vtk_poly_data.SetPoints(self._vtk_points)
self._vtk_poly_data.SetPolys(self._vtk_polygons)
self._vtk_scalars = _vtk.vtkFloatArray()
self._vtk_scalars.SetNumberOfValues(self._vtk_poly_data.GetPoints().GetNumberOfPoints())
for i in range(self._vtk_scalars.GetNumberOfTuples()):
self._vtk_scalars.SetValue(i, 0.)
self._vtk_poly_data.GetPointData().SetScalars(self._vtk_scalars)
self._vtk_poly_data.Modified()
示例4: gen_outline
def gen_outline(pts,color,size):
'''
Returns an outline actor with specified pts, color and size. Incoming pnts should be ordered.
'''
if color[0]<=1 and color != None:
color=(int(color[0]*255),int(color[1]*255),int(color[2]*255))
if color[0]>=1 and color != None:
color=(color[0]/float(255),color[1]/float(255),color[2]/float(255))
points=vtk.vtkPoints()
for i in pts:
points.InsertNextPoint(i)
lineseg=vtk.vtkPolygon()
lineseg.GetPointIds().SetNumberOfIds(len(pts))
for i in range(len(pts)):
lineseg.GetPointIds().SetId(i,i)
linesegcells=vtk.vtkCellArray()
linesegcells.InsertNextCell(lineseg)
outline=vtk.vtkPolyData()
outline.SetPoints(points)
outline.SetVerts(linesegcells)
outline.SetLines(linesegcells)
Omapper=vtk.vtkPolyDataMapper()
Omapper.SetInputData(outline)
outlineActor=vtk.vtkActor()
outlineActor.SetMapper(Omapper)
outlineActor.GetProperty().SetColor(color)
outlineActor.GetProperty().SetPointSize(size)
return outlineActor,outline #actor/polydata
示例5: gocad2vtp
def gocad2vtp(gcFile):
""""
Function to read gocad polystructure file and makes VTK Polydata object (vtp).
Input:
gcFile: gocadFile with polysturcture
"""
print "Reading GOCAD ts file..."
vrtx, trgl = read_GOCAD_ts(gcFile)
# Adjust the index
trgl = trgl - 1
# Make vtk pts
ptsvtk = vtk.vtkPoints()
ptsvtk.SetData(npsup.numpy_to_vtk(vrtx,deep=1))
# Make the polygon connection
polys = vtk.vtkCellArray()
for face in trgl:
poly = vtk.vtkPolygon()
poly.GetPointIds().SetNumberOfIds(len(face))
for nrv, vert in enumerate(face):
poly.GetPointIds().SetId(nrv,vert)
polys.InsertNextCell(poly)
# Make the polydata, structure of connections and vrtx
polyData = vtk.vtkPolyData()
polyData.SetPoints(ptsvtk)
polyData.SetPolys(polys)
return polyData
示例6: draw
def draw(self, graphics):
cell, pointnums = super(Polygon, self).draw(graphics)
polygon = vtk.vtkPolygon()
polygon.GetPointIds().SetNumberOfIds(len(pointnums))
for i, p in enumerate(pointnums):
polygon.GetPointIds().SetId(i, p)
cell.InsertNextCell(polygon)
graphics.data.SetPolys(cell)
示例7: _createpolygon
def _createpolygon(self, pointnumbers):
if depth(pointnumbers) >= 3:
for p in pointnumbers:
self._createpolygon(p)
else:
polygon = vtk.vtkPolygon()
polygon.GetPointIds().SetNumberOfIds(len(pointnumbers))
i = 0
for p in pointnumbers:
polygon.GetPointIds().SetId(i, p)
i += 1
self.polygons.InsertNextCell(polygon)
示例8: generateVolumetricLine
def generateVolumetricLine(self):
""" Generates volumetric lines. """
if self.centroid is None:
return
points = vtk.vtkPoints()
poly_s = vtk.vtkPolygon()
tangent_dir = self.calculateElectrodePolygon(points, poly_s)
self.polygonActor = self.prepareActorWithShadersAndMapper(points, poly_s, tangent_dir)
示例9: arrayToPolydata
def arrayToPolydata(verts, faces):
pts = vtk.vtkPoints()
tris = vtk.vtkCellArray()
for v in verts:
pts.InsertNextPoint( [v[0], v[1], v[2]] )
for f in faces:
poly = vtk.vtkPolygon()
poly.GetPointIds().InsertId(0,f[0])
poly.GetPointIds().InsertId(1,f[1])
poly.GetPointIds().InsertId(2,f[2])
tris.InsertNextCell(poly.GetPointIds())
return pts, tris
示例10: prepFillarea
def prepFillarea(renWin,ren,farea,cmap=None):
n = prepPrimitive(farea)
if n==0:
return
for i in range(n):
x = farea.x[i]
y = farea.y[i]
c = farea.color[i]
st = farea.style[i]
idx = farea.index[i]
N = max(len(x),len(y))
for a in [x,y]:
while len(a)<n:
a.append(a[-1])
#Create points
pts = vtk.vtkPoints()
for j in range(N):
pts.InsertNextPoint(x[j],y[j],0.)
#Create polygon out of these points
polygon = vtk.vtkPolygon()
pid = polygon.GetPointIds()
pid.SetNumberOfIds(N)
for j in range(N):
pid.SetId(j,j)
polygons = vtk.vtkCellArray()
polygons.InsertNextCell(polygon)
polygonPolyData = vtk.vtkPolyData()
geo,pts = project(pts,farea.projection,farea.worldcoordinate)
polygonPolyData.SetPoints(pts)
polygonPolyData.SetPolys(polygons)
a = vtk.vtkActor()
m = vtk.vtkPolyDataMapper()
m.SetInputData(polygonPolyData)
a.SetMapper(m)
p = a.GetProperty()
if cmap is None:
if farea.colormap is not None:
cmap = farea.colormap
else:
cmap = 'default'
if isinstance(cmap,str):
cmap = vcs.elements["colormap"][cmap]
color = cmap.index[c]
p.SetColor([C/100. for C in color])
ren.AddActor(a)
fitToViewport(a,ren,farea.viewport,wc=farea.worldcoordinate,geo=geo)
return
示例11: genPoly
def genPoly(coords,pts,filled=True):
N = pts.GetNumberOfPoints()
if filled:
poly = vtk.vtkPolygon()
else:
poly = vtk.vtkPolyLine()
pid = poly.GetPointIds()
n = len(coords)
pid.SetNumberOfIds(n)
for j in range(n):
c = list(coords[j])
if len(c)==2:
c.append(0)
pts.InsertNextPoint(*c)
pid.SetId(j,j+N)
return poly
示例12: _square_slice
def _square_slice(self):
"""Return a polydata of a square slice."""
polygons = vtk.vtkCellArray()
for i in range(self._side-1):
for j in range(self._side-1):
corners = [(i, j), (i+1, j), (i+1, j+1), (i, j+1)]
polygon = vtk.vtkPolygon()
polygon.GetPointIds().SetNumberOfIds(4)
for index, corner in enumerate(corners):
polygon.GetPointIds().SetId(index, corner[0]*self._side+corner[1])
polygons.InsertNextCell(polygon)
template_poly_data = vtk.vtkPolyData()
template_poly_data.SetPoints(self._points)
template_poly_data.GetPointData().SetScalars(self._image_values)
template_poly_data.SetPolys(polygons)
return template_poly_data
示例13: _square_slice
def _square_slice(self):
"""Call in the beginning. Precalculates the polydata object
without rotation."""
self._polygons.Initialize()
for i in range(self._side-1):
for j in range(self._side-1):
corners = [(i, j), (i+1, j), (i+1, j+1), (i, j+1)]
polygon = _vtk.vtkPolygon()
polygon.GetPointIds().SetNumberOfIds(4)
for index, corner in enumerate(corners):
polygon.GetPointIds().SetId(index,
corner[0]*self._side+corner[1])
self._polygons.InsertNextCell(polygon)
self._template_poly_data = _vtk.vtkPolyData()
self._template_poly_data.SetPoints(self._points)
self._template_poly_data.GetPointData().SetScalars(self._image_values)
self._template_poly_data.SetPolys(self._polygons)
示例14: _generate_vtk_objects
def _generate_vtk_objects(self):
"""Generate vtk_points, vtk_polygons, vtk_poly_data, vtk_scalars,
vtk_mapper and vtk_actor.
This function must be called after _generate_points_and_polys()"""
self._vtk_points = _vtk.vtkPoints()
for coordinates in self._points:
self._vtk_points.InsertNextPoint(coordinates[0], coordinates[1], coordinates[2])
self._vtk_polygons = _vtk.vtkCellArray()
for polygon in self._polygons:
vtk_polygon = _vtk.vtkPolygon()
vtk_polygon.GetPointIds().SetNumberOfIds(3)
for local_index, global_index in enumerate(polygon):
vtk_polygon.GetPointIds().SetId(local_index, global_index)
self._vtk_polygons.InsertNextCell(vtk_polygon)
self._vtk_poly_data = _vtk.vtkPolyData()
self._vtk_poly_data.SetPoints(self._vtk_points)
self._vtk_poly_data.SetPolys(self._vtk_polygons)
self._vtk_scalars = _vtk.vtkFloatArray()
self._vtk_scalars.SetNumberOfValues(self._vtk_poly_data.GetPoints().GetNumberOfPoints())
for i in range(self._vtk_scalars.GetNumberOfTuples()):
self._vtk_scalars.SetValue(i, 0.)
self._vtk_poly_data.GetPointData().SetScalars(self._vtk_scalars)
self._vtk_poly_data.Modified()
self._vtk_mapper = _vtk.vtkPolyDataMapper()
if VTK_VERSION < 6:
self._vtk_mapper.SetInput(self._vtk_poly_data)
else:
self._vtk_mapper.SetInputData(self._vtk_poly_data)
self._vtk_mapper.InterpolateScalarsBeforeMappingOn()
self._vtk_mapper.UseLookupTableScalarRangeOn()
self._vtk_actor = _vtk.vtkActor()
self._vtk_actor.SetMapper(self._vtk_mapper)
normals = _vtk.vtkFloatArray()
normals.SetNumberOfComponents(3)
for point in self._points:
normals.InsertNextTuple(point)
self._vtk_poly_data.GetPointData().SetNormals(normals)
示例15: _circular_slice
def _circular_slice(self):
"""Return a cellarray of a square slice."""
polygons = vtk.vtkCellArray()
for i in range(self._side-1):
for j in range(self._side-1):
corners = [(i, j), (i+1, j), (i+1, j+1), (i, j+1)]
radius = max([numpy.sqrt((c[0] - self._side/2. + 0.5)**2 + (c[1] - self._side/2. + 0.5)**2)
for c in corners])
if radius < self._side/2.:
polygon = vtk.vtkPolygon()
polygon.GetPointIds().SetNumberOfIds(4)
for index, corner in enumerate(corners):
polygon.GetPointIds().SetId(index, corner[0]*self._side+corner[1])
polygons.InsertNextCell(polygon)
template_poly_data = vtk.vtkPolyData()
template_poly_data.SetPoints(self._points)
template_poly_data.GetPointData().SetScalars(self._image_values)
template_poly_data.SetPolys(polygons)
return template_poly_data