code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
r = options.pop("r", 5)
c = options.pop("c", "gray")
alpha = options.pop("alpha", 1)
mesh, u = _inputsort(inputobj)
plist = mesh.coordinates()
if u:
u_values = np.array([u(p) for p in plist])
if len(plist[0]) == 2: # coords are 2d.. not good..
plist = np.insert(plist, ... | def MeshPoints(*inputobj, **options) | Build a point ``Actor`` for a list of points.
:param float r: point radius.
:param c: color name, number, or list of [R,G,B] colors of same length as plist.
:type c: int, str, list
:param float alpha: transparency in range [0,1]. | 3.050233 | 3.036834 | 1.004412 |
scale = options.pop("scale", 1)
lw = options.pop("lw", 1)
c = options.pop("c", None)
alpha = options.pop("alpha", 1)
mesh, u = _inputsort(inputobj)
startPoints = mesh.coordinates()
u_values = np.array([u(p) for p in mesh.coordinates()])
if not utils.isSequence(u_values[0]):
... | def MeshLines(*inputobj, **options) | Build the line segments between two lists of points `startPoints` and `endPoints`.
`startPoints` can be also passed in the form ``[[point1, point2], ...]``.
A dolfin ``Mesh`` that was deformed/modified by a function can be
passed together as inputs.
:param float scale: apply a rescaling factor to the ... | 3.204378 | 3.294575 | 0.972622 |
s = options.pop("s", None)
scale = options.pop("scale", 1)
c = options.pop("c", "gray")
alpha = options.pop("alpha", 1)
res = options.pop("res", 12)
mesh, u = _inputsort(inputobj)
startPoints = mesh.coordinates()
u_values = np.array([u(p) for p in mesh.coordinates()])
if not ut... | def MeshArrows(*inputobj, **options) | Build arrows representing displacements.
:param float s: cross-section size of the arrow
:param float rescale: apply a rescaling factor to the length | 3.145078 | 3.329178 | 0.944701 |
polylns = vtk.vtkAppendPolyData()
for a in actors:
polylns.AddInputData(a.polydata())
polylns.Update()
pd = polylns.GetOutput()
return Actor(pd) | def mergeActors(actors, tol=0) | Build a new actor formed by the fusion of the polydatas of input objects.
Similar to Assembly, but in this case the input objects become a single mesh.
.. hint:: |thinplate_grid| |thinplate_grid.py|_ | 4.044907 | 3.630575 | 1.114123 |
if smoothing:
smImg = vtk.vtkImageGaussianSmooth()
smImg.SetDimensionality(3)
smImg.SetInputData(image)
smImg.SetStandardDeviations(smoothing, smoothing, smoothing)
smImg.Update()
image = smImg.GetOutput()
scrange = image.GetScalarRange()
if scrange[1] >... | def isosurface(image, smoothing=0, threshold=None, connectivity=False) | Return a ``vtkActor`` isosurface extracted from a ``vtkImageData`` object.
:param float smoothing: gaussian filter to smooth vtkImageData, in units of sigmas
:param threshold: value or list of values to draw the isosurface(s)
:type threshold: float, list
:param bool connectivity: if True only keeps ... | 2.369048 | 2.382949 | 0.994166 |
from vtkplotter.plotter import show
return show(
self,
at=at,
shape=shape,
N=N,
pos=pos,
size=size,
screensize=screensize,
title=title,
bg=bg,
bg2=bg2,
axes=axes,... | def show(
self,
at=None,
shape=(1, 1),
N=None,
pos=(0, 0),
size="auto",
screensize="auto",
title="",
bg="blackboard",
bg2=None,
axes=4,
infinity=False,
verbose=True,
interactive=None,
offscreen=False,... | Create on the fly an instance of class ``Plotter`` or use the last existing one to
show one single object.
Allowed input objects are: ``Actor`` or ``Volume``.
This is meant as a shortcut. If more than one object needs to be visualised
please use the syntax `show([actor1, actor2,...], o... | 1.298239 | 1.535663 | 0.845393 |
if txt:
self._legend = txt
else:
return self._legend
return self | def legend(self, txt=None) | Set/get ``Actor`` legend text.
:param str txt: legend text.
Size and positions can be modified by setting attributes
``Plotter.legendSize``, ``Plotter.legendBC`` and ``Plotter.legendPos``.
.. hint:: |fillholes.py|_ | 4.220074 | 10.289161 | 0.410148 |
if p_x is None:
return np.array(self.GetPosition())
if z is None: # assume p_x is of the form (x,y,z)
self.SetPosition(p_x)
else:
self.SetPosition(p_x, y, z)
if self.trail:
self.updateTrail()
return self | def pos(self, p_x=None, y=None, z=None) | Set/Get actor position. | 3.048671 | 2.880237 | 1.058479 |
p = np.array(self.GetPosition())
if dz is None: # assume dp_x is of the form (x,y,z)
self.SetPosition(p + dp_x)
else:
self.SetPosition(p + [dp_x, dy, dz])
if self.trail:
self.updateTrail()
return self | def addPos(self, dp_x=None, dy=None, dz=None) | Add vector to current actor position. | 3.701828 | 3.495644 | 1.058983 |
p = self.GetPosition()
if position is None:
return p[0]
self.SetPosition(position, p[1], p[2])
if self.trail:
self.updateTrail()
return self | def x(self, position=None) | Set/Get actor position along x axis. | 4.733654 | 3.274829 | 1.445466 |
p = self.GetPosition()
if position is None:
return p[1]
self.SetPosition(p[0], position, p[2])
if self.trail:
self.updateTrail()
return self | def y(self, position=None) | Set/Get actor position along y axis. | 4.586287 | 3.487122 | 1.315207 |
p = self.GetPosition()
if position is None:
return p[2]
self.SetPosition(p[0], p[1], position)
if self.trail:
self.updateTrail()
return self | def z(self, position=None) | Set/Get actor position along z axis. | 3.883549 | 2.939328 | 1.321237 |
if rad:
anglerad = angle
else:
anglerad = angle / 57.29578
axis = utils.versor(axis)
a = np.cos(anglerad / 2)
b, c, d = -axis * np.sin(anglerad / 2)
aa, bb, cc, dd = a * a, b * b, c * c, d * d
bc, ad, ac, ab, bd, cd = b * c, a * d,... | def rotate(self, angle, axis=(1, 0, 0), axis_point=(0, 0, 0), rad=False) | Rotate ``Actor`` around an arbitrary `axis` passing through `axis_point`. | 2.066454 | 1.990106 | 1.038363 |
if rad:
angle *= 57.29578
self.RotateX(angle)
if self.trail:
self.updateTrail()
return self | def rotateX(self, angle, axis_point=(0, 0, 0), rad=False) | Rotate around x-axis. If angle is in radians set ``rad=True``. | 5.082226 | 5.034401 | 1.0095 |
if rad:
angle *= 57.29578
self.RotateY(angle)
if self.trail:
self.updateTrail()
return self | def rotateY(self, angle, axis_point=(0, 0, 0), rad=False) | Rotate around y-axis. If angle is in radians set ``rad=True``. | 5.078891 | 4.973938 | 1.021101 |
if rad:
angle *= 57.29578
self.RotateZ(angle)
if self.trail:
self.updateTrail()
return self | def rotateZ(self, angle, axis_point=(0, 0, 0), rad=False) | Rotate around z-axis. If angle is in radians set ``rad=True``. | 5.361144 | 5.264298 | 1.018397 |
if rad:
rotation *= 57.29578
initaxis = utils.versor(self.top - self.base)
if newaxis is None:
return initaxis
newaxis = utils.versor(newaxis)
pos = np.array(self.GetPosition())
crossvec = np.cross(initaxis, newaxis)
angle = np.arc... | def orientation(self, newaxis=None, rotation=0, rad=False) | Set/Get actor orientation.
:param rotation: If != 0 rotate actor around newaxis.
:param rad: set to True if angle is in radians.
.. hint:: |gyroscope2| |gyroscope2.py|_ | 2.907297 | 3.133717 | 0.927747 |
if s is None:
return np.array(self.GetScale())
self.SetScale(s)
return self | def scale(self, s=None) | Set/get actor's scaling factor.
:param s: scaling factor(s).
:type s: float, list
.. note:: if `s==(sx,sy,sz)` scale differently in the three coordinates. | 4.045838 | 5.759607 | 0.70245 |
if t is None:
return self._time
self._time = t
return self | def time(self, t=None) | Set/get actor's absolute time. | 3.426804 | 3.11907 | 1.098662 |
if maxlength is None:
maxlength = self.diagonalSize() * 20
if maxlength == 0:
maxlength = 1
if self.trail is None:
pos = self.GetPosition()
self.trailPoints = [None] * n
self.trailSegmentSize = maxlength / n
... | def addTrail(self, offset=None, maxlength=None, n=25, c=None, alpha=None, lw=1) | Add a trailing line to actor.
:param offset: set an offset vector from the object center.
:param maxlength: length of trailing line in absolute units
:param n: number of segments to control precision
:param lw: line width of the trail
.. hint:: |trail| |trail.py|_ | 2.53595 | 2.501163 | 1.013908 |
b = self.GetBounds()
from vtkplotter.shapes import Box
pos = (b[0]+b[1])/2, (b[3]+b[2])/2, (b[5]+b[4])/2
length, width, height = b[1]-b[0], b[3]-b[2], b[5]-b[4]
oa = Box(pos, length, width, height, c='gray').wire()
if isinstance(self.GetProperty(), vtk.vtkPropert... | def box(self) | Return the bounding box as a new ``Actor``.
.. hint:: |latex.py|_ | 2.846173 | 2.667309 | 1.067058 |
if value is None:
return self.GetPickable()
else:
self.SetPickable(value)
return self | def pickable(self, value=None) | Set/get pickable property of actor. | 2.774459 | 2.42556 | 1.143843 |
self.poly = polydata
self.mapper.SetInputData(polydata)
self.mapper.Modified()
return self | def updateMesh(self, polydata) | Overwrite the polygonal mesh of the actor with a new one. | 4.128012 | 3.891191 | 1.060861 |
# book it, it will be created by Plotter.show() later
self.scalarbar = [c, title, horizontal, vmin, vmax]
return self | def addScalarBar(self, c=None, title="", horizontal=False, vmin=None, vmax=None) | Add a 2D scalar bar to actor.
.. hint:: |mesh_bands| |mesh_bands.py|_ | 11.618496 | 16.775118 | 0.692603 |
# book it, it will be created by Plotter.show() later
self.scalarbar = [pos, normal, sx, sy, nlabels, ncols, cmap, c, alpha]
return self | def addScalarBar3D(
self,
pos=(0, 0, 0),
normal=(0, 0, 1),
sx=0.1,
sy=2,
nlabels=9,
ncols=256,
cmap=None,
c="k",
alpha=1,
) | Draw a 3D scalar bar to actor.
.. hint:: |mesh_coloring| |mesh_coloring.py|_ | 7.78863 | 9.582685 | 0.812782 |
import os
if mapTo == 1:
tmapper = vtk.vtkTextureMapToCylinder()
elif mapTo == 2:
tmapper = vtk.vtkTextureMapToSphere()
elif mapTo == 3:
tmapper = vtk.vtkTextureMapToPlane()
tmapper.SetInputData(self.polydata(False))
if mapTo... | def texture(self, name, scale=1, falsecolors=False, mapTo=1) | Assign a texture to actor from image file or predefined texture name. | 3.230663 | 3.156462 | 1.023508 |
poly = self.polydata(True)
p = [0, 0, 0]
poly.GetPoints().GetPoint(i, p)
return np.array(p) | def getPoint(self, i) | Retrieve specific `i-th` point coordinates in mesh.
Actor transformation is reset to its mesh position/orientation.
:param int i: index of vertex point.
.. warning:: if used in a loop this can slow down the execution by a lot.
.. seealso:: ``actor.Points()`` | 4.040284 | 3.88862 | 1.039002 |
poly = self.polydata(False)
poly.GetPoints().SetPoint(i, p)
poly.GetPoints().Modified()
# reset actor to identity matrix position/rotation:
self.PokeMatrix(vtk.vtkMatrix4x4())
return self | def setPoint(self, i, p) | Set specific `i-th` point coordinates in mesh.
Actor transformation is reset to its original mesh position/orientation.
:param int i: index of vertex point.
:param list p: new coordinates of mesh point.
.. warning:: if used in a loop this can slow down the execution by a lot.
... | 9.324184 | 8.630125 | 1.080423 |
return self.coordinates(transformed, copy) | def getPoints(self, transformed=True, copy=True) | Return the list of vertex coordinates of the input mesh.
Same as `actor.coordinates()`.
:param bool transformed: if `False` ignore any previous trasformation
applied to the mesh.
:param bool copy: if `False` return the reference to the points
so that they can be modified... | 16.744749 | 25.837952 | 0.648068 |
vpts = vtk.vtkPoints()
vpts.SetData(numpy_to_vtk(pts, deep=True))
self.poly.SetPoints(vpts)
self.poly.GetPoints().Modified()
# reset actor to identity matrix position/rotation:
self.PokeMatrix(vtk.vtkMatrix4x4())
return self | def setPoints(self, pts) | Set specific points coordinates in mesh. Input is a python list.
Actor transformation is reset to its mesh position/orientation.
:param list pts: new coordinates of mesh vertices. | 5.32771 | 5.231297 | 1.01843 |
poly = self.polydata(False)
pnormals = poly.GetPointData().GetNormals()
cnormals = poly.GetCellData().GetNormals()
if pnormals and cnormals:
return self
pdnorm = vtk.vtkPolyDataNormals()
pdnorm.SetInputData(poly)
pdnorm.ComputePointNormalsOn(... | def computeNormals(self) | Compute cell and vertex normals for the actor's mesh.
.. warning:: Mesh gets modified, can have a different nr. of vertices. | 3.025167 | 2.937882 | 1.02971 |
if opacity is None:
return self.GetProperty().GetOpacity()
self.GetProperty().SetOpacity(opacity)
bfp = self.GetBackfaceProperty()
if bfp:
if opacity < 1:
self._bfprop = bfp
self.SetBackfaceProperty(None)
else:... | def alpha(self, opacity=None) | Set/get actor's transparency. Same as `actor.opacity()`. | 3.158733 | 3.009527 | 1.049578 |
if wireframe:
self.GetProperty().SetRepresentationToWireframe()
else:
self.GetProperty().SetRepresentationToSurface()
return self | def wire(self, wireframe=True) | Set actor's representation as wireframe or solid surface. Same as `wireframe()`. | 2.860051 | 2.164218 | 1.321517 |
if s is not None:
if isinstance(self, vtk.vtkAssembly):
cl = vtk.vtkPropCollection()
self.GetActors(cl)
cl.InitTraversal()
a = vtk.vtkActor.SafeDownCast(cl.GetNextProp())
a.GetProperty().SetRepresentationToPoint... | def pointSize(self, s=None) | Set/get actor's point size of vertices. | 2.341219 | 2.245087 | 1.042819 |
if c is False:
return np.array(self.GetProperty().GetColor())
elif c is None:
self.GetMapper().ScalarVisibilityOn()
return self
else:
self.GetMapper().ScalarVisibilityOff()
self.GetProperty().SetColor(colors.getColor(c))
... | def color(self, c=False) | Set/get actor's color.
If None is passed as input, will use colors from active scalars.
Same as `c()`. | 3.399304 | 2.875539 | 1.182145 |
backProp = self.GetBackfaceProperty()
if bc is None:
if backProp:
return backProp.GetDiffuseColor()
return None
if self.GetProperty().GetOpacity() < 1:
colors.printc("~noentry backColor(): only active for alpha=1", c="y")
... | def backColor(self, bc=None) | Set/get actor's backface color. | 5.102052 | 4.483806 | 1.137884 |
if lw is not None:
if lw == 0:
self.GetProperty().EdgeVisibilityOff()
return
self.GetProperty().EdgeVisibilityOn()
self.GetProperty().SetLineWidth(lw)
else:
return self.GetProperty().GetLineWidth()
return se... | def lineWidth(self, lw=None) | Set/get width of mesh edges. Same as `lw()`. | 2.932758 | 2.675778 | 1.096039 |
poly = self.polydata(False)
cleanPolyData = vtk.vtkCleanPolyData()
cleanPolyData.PointMergingOn()
cleanPolyData.ConvertLinesToPointsOn()
cleanPolyData.ConvertPolysToLinesOn()
cleanPolyData.SetInputData(poly)
if tol:
cleanPolyData.SetTolerance(... | def clean(self, tol=None) | Clean actor's polydata. Can also be used to decimate a mesh if ``tol`` is large.
If ``tol=None`` only removes coincident points.
:param tol: defines how far should be the points from each other in terms of fraction
of the bounding box length.
.. hint:: |moving_least_squares1D| |mov... | 2.780669 | 3.137037 | 0.8864 |
cm = self.centerOfMass()
coords = self.coordinates(copy=False)
if not len(coords):
return 0
s, c = 0.0, 0.0
n = len(coords)
step = int(n / 10000.0) + 1
for i in np.arange(0, n, step):
s += utils.mag(coords[i] - cm)
c +=... | def averageSize(self) | Calculate the average size of a mesh.
This is the mean of the vertex distances from the center of mass. | 3.389187 | 3.097042 | 1.09433 |
b = self.polydata().GetBounds()
return np.sqrt((b[1] - b[0]) ** 2 + (b[3] - b[2]) ** 2 + (b[5] - b[4]) ** 2) | def diagonalSize(self) | Get the length of the diagonal of actor bounding box. | 2.900842 | 2.503685 | 1.158629 |
b = self.polydata(True).GetBounds()
return max(abs(b[1] - b[0]), abs(b[3] - b[2]), abs(b[5] - b[4])) | def maxBoundSize(self) | Get the maximum dimension in x, y or z of the actor bounding box. | 2.93734 | 2.707113 | 1.085045 |
cmf = vtk.vtkCenterOfMass()
cmf.SetInputData(self.polydata(True))
cmf.Update()
c = cmf.GetCenter()
return np.array(c) | def centerOfMass(self) | Get the center of mass of actor.
.. hint:: |fatlimb| |fatlimb.py|_ | 3.28179 | 3.856387 | 0.851001 |
mass = vtk.vtkMassProperties()
mass.SetGlobalWarningDisplay(0)
mass.SetInputData(self.polydata())
mass.Update()
v = mass.GetVolume()
if value is not None:
if not v:
colors.printc("~bomb Volume is zero: cannot rescale.", c=1, end="")
... | def volume(self, value=None) | Get/set the volume occupied by actor. | 7.565558 | 6.981075 | 1.083724 |
mass = vtk.vtkMassProperties()
mass.SetGlobalWarningDisplay(0)
mass.SetInputData(self.polydata())
mass.Update()
ar = mass.GetSurfaceArea()
if value is not None:
if not ar:
colors.printc("~bomb Area is zero: cannot rescale.", c=1, end="... | def area(self, value=None) | Get/set the surface area of actor.
.. hint:: |largestregion.py|_ | 8.009285 | 7.575819 | 1.057217 |
poly = self.polydata(True)
if N > 1 or radius:
plocexists = self.point_locator
if not plocexists or (plocexists and self.point_locator is None):
point_locator = vtk.vtkPointLocator()
point_locator.SetDataSet(poly)
point_lo... | def closestPoint(self, pt, N=1, radius=None, returnIds=False) | Find the closest point on a mesh given from the input point `pt`.
:param int N: if greater than 1, return a list of N ordered closest points.
:param float radius: if given, get all points within that radius.
:param bool returnIds: return points IDs instead of point coordinates.
.. hint... | 2.089164 | 2.079755 | 1.004524 |
'''
Computes the (signed) distance from one mesh to another.
.. hint:: |distance2mesh| |distance2mesh.py|_
'''
poly1 = self.polydata()
poly2 = actor.polydata()
df = vtk.vtkDistancePolyDataFilter()
df.SetInputData(0, poly1)
df.SetInputData(... | def distanceToMesh(self, actor, signed=False, negate=False) | Computes the (signed) distance from one mesh to another.
.. hint:: |distance2mesh| |distance2mesh.py|_ | 2.994825 | 2.411276 | 1.242009 |
poly = self.polydata(transformed=transformed)
polyCopy = vtk.vtkPolyData()
polyCopy.DeepCopy(poly)
cloned = Actor()
cloned.poly = polyCopy
cloned.mapper.SetInputData(polyCopy)
cloned.mapper.SetScalarVisibility(self.mapper.GetScalarVisibility())
p... | def clone(self, transformed=True) | Clone a ``Actor(vtkActor)`` and make an exact copy of it.
:param transformed: if `False` ignore any previous trasformation applied to the mesh.
.. hint:: |carcrash| |carcrash.py|_ | 2.977253 | 3.226698 | 0.922693 |
if isinstance(transformation, vtk.vtkMatrix4x4):
tr = vtk.vtkTransform()
tr.SetMatrix(transformation)
transformation = tr
tf = vtk.vtkTransformPolyDataFilter()
tf.SetTransform(transformation)
tf.SetInputData(self.polydata())
tf.Updat... | def transformMesh(self, transformation) | Apply this transformation to the polygonal `mesh`,
not to the actor's transformation, which is reset.
:param transformation: ``vtkTransform`` or ``vtkMatrix4x4`` object. | 3.72909 | 3.962373 | 0.941125 |
cm = self.centerOfMass()
coords = self.coordinates()
if not len(coords):
return
pts = coords - cm
xyz2 = np.sum(pts * pts, axis=0)
scale = 1 / np.sqrt(np.sum(xyz2) / len(pts))
t = vtk.vtkTransform()
t.Scale(scale, scale, scale)
... | def normalize(self) | Shift actor's center of mass at origin and scale its average size to unit. | 3.14173 | 2.816015 | 1.115665 |
poly = self.polydata(transformed=True)
polyCopy = vtk.vtkPolyData()
polyCopy.DeepCopy(poly)
sx, sy, sz = 1, 1, 1
dx, dy, dz = self.GetPosition()
if axis.lower() == "x":
sx = -1
elif axis.lower() == "y":
sy = -1
elif axis.l... | def mirror(self, axis="x") | Mirror the actor polydata along one of the cartesian axes.
.. note:: ``axis='n'``, will flip only mesh normals.
.. hint:: |mirror| |mirror.py|_ | 2.435459 | 2.471879 | 0.985266 |
poly = self.polydata(True)
shrink = vtk.vtkShrinkPolyData()
shrink.SetInputData(poly)
shrink.SetShrinkFactor(fraction)
shrink.Update()
return self.updateMesh(shrink.GetOutput()) | def shrink(self, fraction=0.85) | Shrink the triangle polydata in the representation of the input mesh.
Example:
.. code-block:: python
from vtkplotter import *
pot = load(datadir + 'shapes/teapot.vtk').shrink(0.75)
s = Sphere(r=0.2).pos(0,0,-0.5)
show(pot, s)
... | 3.146864 | 3.525358 | 0.892637 |
if self.base is None:
colors.printc('~times Error in stretch(): Please define vectors \
actor.base and actor.top at creation. Exit.', c='r')
exit(0)
p1, p2 = self.base, self.top
q1, q2, z = np.array(q1), np.array(q2), np.array([0, 0, 1]... | def stretch(self, q1, q2) | Stretch actor between points `q1` and `q2`. Mesh is not affected.
.. hint:: |aspring| |aspring.py|_
.. note:: for ``Actors`` like helices, Line, cylinders, cones etc.,
two attributes ``actor.base``, and ``actor.top`` are already defined. | 3.041115 | 2.804017 | 1.084557 |
if normal is "x":
normal = (1,0,0)
elif normal is "y":
normal = (0,1,0)
elif normal is "z":
normal = (0,0,1)
plane = vtk.vtkPlane()
plane.SetOrigin(origin)
plane.SetNormal(normal)
self.computeNormals()
poly = s... | def cutWithPlane(self, origin=(0, 0, 0), normal=(1, 0, 0), showcut=False) | Takes a ``vtkActor`` and cuts it with the plane defined by a point and a normal.
:param origin: the cutting plane goes through this point
:param normal: normal of the cutting plane
:param showcut: if `True` show the cut off part of the mesh as thin wireframe.
:Example:
... | 2.590514 | 2.686089 | 0.964418 |
if isinstance(mesh, vtk.vtkPolyData):
polymesh = mesh
if isinstance(mesh, Actor):
polymesh = mesh.polydata()
else:
polymesh = mesh.GetMapper().GetInput()
poly = self.polydata()
# Create an array to hold distance information
si... | def cutWithMesh(self, mesh, invert=False) | Cut an ``Actor`` mesh with another ``vtkPolyData`` or ``Actor``.
:param bool invert: if True return cut off part of actor.
.. hint:: |cutWithMesh| |cutWithMesh.py|_
|cutAndCap| |cutAndCap.py|_ | 2.912987 | 2.948014 | 0.988118 |
poly = self.polydata(True)
fe = vtk.vtkFeatureEdges()
fe.SetInputData(poly)
fe.BoundaryEdgesOn()
fe.FeatureEdgesOff()
fe.NonManifoldEdgesOff()
fe.ManifoldEdgesOff()
fe.Update()
stripper = vtk.vtkStripper()
stripper.SetInputData(f... | def cap(self, returnCap=False) | Generate a "cap" on a clipped actor, or caps sharp edges.
.. hint:: |cutAndCap| |cutAndCap.py|_ | 2.170698 | 2.15777 | 1.005991 |
if utils.isSequence(scalars):
self.addPointScalars(scalars, "threshold")
scalars = "threshold"
elif self.scalars(scalars) is None:
colors.printc("~times No scalars found with name", scalars, c=1)
exit()
thres = vtk.vtkThreshold()
... | def threshold(self, scalars, vmin=None, vmax=None, useCells=False) | Extracts cells where scalar value satisfies threshold criterion.
:param scalars: name of the scalars array.
:type scalars: str, list
:param float vmin: minimum value of the scalar
:param float vmax: maximum value of the scalar
:param bool useCells: if `True`, assume array scalar... | 2.641859 | 2.658458 | 0.993756 |
tf = vtk.vtkTriangleFilter()
tf.SetPassLines(lines)
tf.SetPassVerts(verts)
tf.SetInputData(self.poly)
tf.Update()
return self.updateMesh(tf.GetOutput()) | def triangle(self, verts=True, lines=True) | Converts actor polygons and strips to triangles. | 3.498082 | 3.228751 | 1.083417 |
c2p = vtk.vtkCellDataToPointData()
c2p.SetInputData(self.polydata(False))
c2p.Update()
return self.updateMesh(c2p.GetOutput()) | def mapCellsToPoints(self) | Transform cell data (i.e., data specified per cell)
into point data (i.e., data specified at cell points).
The method of transformation is based on averaging the data values
of all cells using a particular point. | 3.590915 | 3.907882 | 0.91889 |
p2c = vtk.vtkPointDataToCellData()
p2c.SetInputData(self.polydata(False))
p2c.Update()
return self.updateMesh(p2c.GetOutput()) | def mapPointsToCells(self) | Transform point data (i.e., data specified per point)
into cell data (i.e., data specified per cell).
The method of transformation is based on averaging the data values
of all points defining a particular cell.
.. hint:: |mesh_map2cell| |mesh_map2cell.py|_ | 3.653798 | 3.99096 | 0.915518 |
poly = self.polydata(False)
if isinstance(scalars, str): # if a name is passed
scalars = vtk_to_numpy(poly.GetPointData().GetArray(scalars))
n = len(scalars)
useAlpha = False
if n != poly.GetNumberOfPoints():
colors.printc('~times pointColors E... | def pointColors(self, scalars, cmap="jet", alpha=1, bands=None, vmin=None, vmax=None) | Set individual point colors by providing a list of scalar values and a color map.
`scalars` can be a string name of the ``vtkArray``.
:param cmap: color map scheme to transform a real number into a color.
:type cmap: str, list, vtkLookupTable, matplotlib.colors.LinearSegmentedColormap
:... | 2.302277 | 2.291695 | 1.004618 |
poly = self.polydata(False)
if len(scalars) != poly.GetNumberOfPoints():
colors.printc('~times pointScalars Error: Number of scalars != nr. of points',
len(scalars), poly.GetNumberOfPoints(), c=1)
exit()
arr = numpy_to_vtk(np.ascontiguou... | def addPointScalars(self, scalars, name) | Add point scalars to the actor's polydata assigning it a name.
.. hint:: |mesh_coloring| |mesh_coloring.py|_ | 3.483557 | 3.58151 | 0.97265 |
poly = self.polydata(False)
if isinstance(scalars, str):
scalars = vtk_to_numpy(poly.GetPointData().GetArray(scalars))
if len(scalars) != poly.GetNumberOfCells():
colors.printc("~times Number of scalars != nr. of cells", c=1)
exit()
arr = num... | def addCellScalars(self, scalars, name) | Add cell scalars to the actor's polydata assigning it a name. | 3.035046 | 2.861159 | 1.060775 |
poly = self.polydata(False)
if len(vectors) != poly.GetNumberOfPoints():
colors.printc('~times addPointVectors Error: Number of vectors != nr. of points',
len(vectors), poly.GetNumberOfPoints(), c=1)
exit()
arr = vtk.vtkDoubleArray()
... | def addPointVectors(self, vectors, name) | Add a point vector field to the actor's polydata assigning it a name. | 3.379597 | 3.091759 | 1.093098 |
ids = vtk.vtkIdFilter()
ids.SetInputData(self.poly)
ids.PointIdsOn()
ids.CellIdsOn()
if asfield:
ids.FieldDataOn()
else:
ids.FieldDataOff()
ids.Update()
return self.updateMesh(ids.GetOutput()) | def addIDs(self, asfield=False) | Generate point and cell ids.
:param bool asfield: flag to control whether to generate scalar or field data. | 2.885589 | 3.049126 | 0.946366 |
curve = vtk.vtkCurvatures()
curve.SetInputData(self.poly)
curve.SetCurvatureType(method)
curve.Update()
self.poly = curve.GetOutput()
scls = self.poly.GetPointData().GetScalars().GetRange()
print("curvature(): scalar range is", scls)
self.mapper... | def addCurvatureScalars(self, method=0, lut=None) | Build an ``Actor`` that contains the color coded surface
curvature calculated in three different ways.
:param int method: 0-gaussian, 1-mean, 2-max, 3-min curvature.
:param float lut: optional look up table.
:Example:
.. code-block:: python
from... | 3.238569 | 3.934819 | 0.823054 |
poly = self.polydata(False)
if name_or_idx is None: # get mode behaviour
ncd = poly.GetCellData().GetNumberOfArrays()
npd = poly.GetPointData().GetNumberOfArrays()
nfd = poly.GetFieldData().GetNumberOfArrays()
arrs = []
for i in rang... | def scalars(self, name_or_idx=None, datatype="point") | Retrieve point or cell scalars using array name or index number.
If no ``name`` is given return the list of names of existing arrays.
.. hint:: |mesh_coloring.py|_ | 2.088225 | 2.095483 | 0.996537 |
triangles = vtk.vtkTriangleFilter()
triangles.SetInputData(self.polydata())
triangles.Update()
originalMesh = triangles.GetOutput()
if method == 0:
sdf = vtk.vtkLoopSubdivisionFilter()
elif method == 1:
sdf = vtk.vtkLinearSubdivisionFilter... | def subdivide(self, N=1, method=0) | Increase the number of vertices of a surface mesh.
:param int N: number of subdivisions.
:param int method: Loop(0), Linear(1), Adaptive(2), Butterfly(3)
.. hint:: |tutorial_subdivide| |tutorial.py|_ | 2.776326 | 2.75216 | 1.008781 |
poly = self.polydata(True)
if N: # N = desired number of points
Np = poly.GetNumberOfPoints()
fraction = float(N) / Np
if fraction >= 1:
return self
decimate = vtk.vtkDecimatePro()
decimate.SetInputData(poly)
decimate... | def decimate(self, fraction=0.5, N=None, boundaries=False, verbose=True) | Downsample the number of vertices in a mesh.
:param float fraction: the desired target of reduction.
:param int N: the desired number of final points (**fraction** is recalculated based on it).
:param bool boundaries: (True), decide whether to leave boundaries untouched or not.
.. note... | 3.137936 | 3.279479 | 0.95684 |
sz = self.diagonalSize()
pts = self.coordinates()
n = len(pts)
ns = np.random.randn(n, 3) * sigma * sz / 100
vpts = vtk.vtkPoints()
vpts.SetNumberOfPoints(n)
vpts.SetData(numpy_to_vtk(pts + ns, deep=True))
self.poly.SetPoints(vpts)
self.po... | def addGaussNoise(self, sigma) | Add gaussian noise.
:param float sigma: sigma is expressed in percent of the diagonal size of actor.
:Example:
.. code-block:: python
from vtkplotter import Sphere
Sphere().addGaussNoise(1.0).show() | 3.778306 | 3.423523 | 1.103631 |
poly = self.poly
cl = vtk.vtkCleanPolyData()
cl.SetInputData(poly)
cl.Update()
smoothFilter = vtk.vtkSmoothPolyDataFilter()
smoothFilter.SetInputData(cl.GetOutput())
smoothFilter.SetNumberOfIterations(niter)
smoothFilter.SetRelaxationFactor(relaxf... | def smoothLaplacian(self, niter=15, relaxfact=0.1, edgeAngle=15, featureAngle=60) | Adjust mesh point positions using `Laplacian` smoothing.
:param int niter: number of iterations.
:param float relaxfact: relaxation factor. Small `relaxfact` and large `niter` are more stable.
:param float edgeAngle: edge angle to control smoothing along edges (either interior or boundary).
... | 1.994207 | 2.166718 | 0.920382 |
poly = self.poly
cl = vtk.vtkCleanPolyData()
cl.SetInputData(poly)
cl.Update()
smoothFilter = vtk.vtkWindowedSincPolyDataFilter()
smoothFilter.SetInputData(cl.GetOutput())
smoothFilter.SetNumberOfIterations(niter)
smoothFilter.SetEdgeAngle(edgeAng... | def smoothWSinc(self, niter=15, passBand=0.1, edgeAngle=15, featureAngle=60) | Adjust mesh point positions using the `Windowed Sinc` function interpolation kernel.
:param int niter: number of iterations.
:param float passBand: set the passband value for the windowed sinc filter.
:param float edgeAngle: edge angle to control smoothing along edges (either interior or bounda... | 1.997367 | 2.103082 | 0.949733 |
fh = vtk.vtkFillHolesFilter()
if not size:
mb = self.maxBoundSize()
size = mb / 10
fh.SetHoleSize(size)
fh.SetInputData(self.poly)
fh.Update()
return self.updateMesh(fh.GetOutput()) | def fillHoles(self, size=None) | Identifies and fills holes in input mesh.
Holes are identified by locating boundary edges, linking them together into loops,
and then triangulating the resulting loops.
:param float size: approximate limit to the size of the hole that can be filled.
Example: |fillholes.py|_ | 4.184962 | 4.751398 | 0.880785 |
import vtkplotter.vtkio as vtkio
return vtkio.write(self, filename, binary) | def write(self, filename="mesh.vtk", binary=True) | Write actor's polydata in its current transformation to file. | 5.869294 | 5.167311 | 1.135851 |
normals = self.polydata(True).GetPointData().GetNormals()
return np.array(normals.GetTuple(i)) | def normalAt(self, i) | Return the normal vector at vertex point `i`. | 5.432325 | 4.127098 | 1.316258 |
if cells:
vtknormals = self.polydata(True).GetCellData().GetNormals()
else:
vtknormals = self.polydata(True).GetPointData().GetNormals()
return vtk_to_numpy(vtknormals) | def normals(self, cells=False) | Retrieve vertex normals as a numpy array.
:params bool cells: if `True` return cell normals. | 3.103056 | 3.898894 | 0.795881 |
if not transformed:
if not self.poly:
self.poly = self.GetMapper().GetInput() # cache it for speed
return self.poly
M = self.GetMatrix()
if utils.isIdentity(M):
if not self.poly:
self.poly = self.GetMapper().GetInput()... | def polydata(self, transformed=True) | Returns the ``vtkPolyData`` of an ``Actor``.
.. note:: If ``transformed=True`` returns a copy of polydata that corresponds
to the current actor's position in space.
.. hint:: |quadratic_morphing| |quadratic_morphing.py|_ | 3.393977 | 3.025921 | 1.121635 |
poly = self.polydata(transformed)
if copy:
return np.array(vtk_to_numpy(poly.GetPoints().GetData()))
else:
return vtk_to_numpy(poly.GetPoints().GetData()) | def coordinates(self, transformed=True, copy=True) | Return the list of vertex coordinates of the input mesh. Same as `actor.getPoints()`.
:param bool transformed: if `False` ignore any previous trasformation applied to the mesh.
:param bool copy: if `False` return the reference to the points
so that they can be modified in place.
..... | 3.057783 | 4.123446 | 0.74156 |
if self.mesh:
self.u = u_function
delta = [u_function(p) for p in self.mesh.coordinates()]
movedpts = self.mesh.coordinates() + delta
self.polydata(False).GetPoints().SetData(numpy_to_vtk(movedpts))
self.poly.GetPoints().Modified()
... | def move(self, u_function) | Move a mesh by using an external function which prescribes the displacement
at any point in space.
Useful for manipulating ``dolfin`` meshes. | 6.490774 | 5.7068 | 1.137375 |
if "transform" in self.info.keys():
T = self.info["transform"]
return T
else:
T = self.GetMatrix()
tr = vtk.vtkTransform()
tr.SetMatrix(T)
return tr | def getTransform(self) | Check if ``info['transform']`` exists and returns it.
Otherwise return current user transformation
(where the actor is currently placed). | 3.766895 | 3.033833 | 1.241629 |
if isinstance(T, vtk.vtkMatrix4x4):
self.SetUserMatrix(T)
else:
try:
self.SetUserTransform(T)
except TypeError:
colors.printc('~time Error in setTransform(): consider transformPolydata() instead.', c=1)
return self | def setTransform(self, T) | Transform actor position and orientation wrt to its polygonal mesh,
which remains unmodified. | 7.573641 | 7.305657 | 1.036682 |
poly = self.polydata(True)
points = vtk.vtkPoints()
points.InsertNextPoint(point)
pointsPolydata = vtk.vtkPolyData()
pointsPolydata.SetPoints(points)
sep = vtk.vtkSelectEnclosedPoints()
sep.SetTolerance(tol)
sep.CheckSurfaceOff()
sep.SetIn... | def isInside(self, point, tol=0.0001) | Return True if point is inside a polydata closed surface. | 2.790418 | 2.541472 | 1.097953 |
poly = self.polydata(True)
# check if the stl file is closed
#featureEdge = vtk.vtkFeatureEdges()
#featureEdge.FeatureEdgesOff()
#featureEdge.BoundaryEdgesOn()
#featureEdge.NonManifoldEdgesOn()
#featureEdge.SetInputData(poly)
#featureEdge... | def insidePoints(self, points, invert=False, tol=1e-05) | Return the sublist of points that are inside a polydata closed surface.
.. hint:: |pca| |pca.py|_ | 3.077083 | 2.999316 | 1.025928 |
vcen = vtk.vtkCellCenters()
vcen.SetInputData(self.polydata(True))
vcen.Update()
return vtk_to_numpy(vcen.GetOutput().GetPoints().GetData()) | def cellCenters(self) | Get the list of cell centers of the mesh surface.
.. hint:: |delaunay2d| |delaunay2d.py|_ | 3.623252 | 3.908126 | 0.927107 |
fe = vtk.vtkFeatureEdges()
fe.SetInputData(self.polydata())
fe.SetBoundaryEdges(boundaryEdges)
if featureAngle:
fe.FeatureEdgesOn()
fe.SetFeatureAngle(featureAngle)
else:
fe.FeatureEdgesOff()
fe.SetNonManifold... | def boundaries(self, boundaryEdges=True, featureAngle=65, nonManifoldEdges=True) | Return an ``Actor`` that shows the boundary lines of an input mesh.
:param bool boundaryEdges: Turn on/off the extraction of boundary edges.
:param float featureAngle: Specify the feature angle for extracting feature edges.
:param bool nonManifoldEdges: Turn on/off the extraction of non... | 3.280364 | 3.297949 | 0.994668 |
mesh = self.polydata()
cellIdList = vtk.vtkIdList()
mesh.GetPointCells(index, cellIdList)
idxs = []
for i in range(cellIdList.GetNumberOfIds()):
pointIdList = vtk.vtkIdList()
mesh.GetCellPoints(cellIdList.GetId(i), pointIdList)
for j... | def connectedVertices(self, index, returnIds=False) | Find all vertices connected to an input vertex specified by its index.
:param bool returnIds: return vertex IDs instead of vertex coordinates.
.. hint:: |connVtx| |connVtx.py|_ | 2.229573 | 2.482302 | 0.898187 |
# Find all cells connected to point index
dpoly = self.polydata()
cellPointIds = vtk.vtkIdList()
dpoly.GetPointCells(index, cellPointIds)
ids = vtk.vtkIdTypeArray()
ids.SetNumberOfComponents(1)
rids = []
for k in range(cellPointIds.G... | def connectedCells(self, index, returnIds=False) | Find all cellls connected to an input vertex specified by its index. | 2.211861 | 2.211938 | 0.999965 |
if not self.line_locator:
line_locator = vtk.vtkOBBTree()
line_locator.SetDataSet(self.polydata(True))
line_locator.BuildLocator()
self.line_locator = line_locator
intersectPoints = vtk.vtkPoints()
intersection = [0, 0, 0]
self.li... | def intersectWithLine(self, p0, p1) | Return the list of points intersecting the actor
along the segment defined by two points `p0` and `p1`.
:Example:
.. code-block:: python
from vtkplotter import *
s = Spring(alpha=0.2)
pts = s.intersectWithLine([0,0,0], [1,0.1,0])
... | 2.660407 | 2.617684 | 1.016321 |
cl = vtk.vtkPropCollection()
self.GetActors(cl)
self.actors = []
cl.InitTraversal()
for i in range(self.GetNumberOfPaths()):
act = vtk.vtkActor.SafeDownCast(cl.GetNextProp())
if act.GetPickable():
self.actors.append(act)
re... | def getActors(self) | Unpack a list of ``vtkActor`` objects from a ``vtkAssembly``. | 3.96967 | 3.508545 | 1.131429 |
szs = [a.diagonalSize() for a in self.actors]
return np.max(szs) | def diagonalSize(self) | Return the maximum diagonal size of the ``Actors`` of the ``Assembly``. | 7.39836 | 5.644559 | 1.310707 |
if a is not None:
self.GetProperty().SetOpacity(a)
return self
else:
return self.GetProperty().GetOpacity() | def alpha(self, a=None) | Set/get actor's transparency. | 3.202204 | 2.568054 | 1.246938 |
extractVOI = vtk.vtkExtractVOI()
extractVOI.SetInputData(self.GetInput())
extractVOI.IncludeBoundaryOn()
d = self.GetInput().GetDimensions()
bx0, bx1, by0, by1 = 0, d[0]-1, 0, d[1]-1
if left is not None: bx0 = int((d[0]-1)*left)
if right is not None: ... | def crop(self, top=None, bottom=None, right=None, left=None) | Crop image.
:param float top: fraction to crop from the top margin
:param float bottom: fraction to crop from the bottom margin
:param float left: fraction to crop from the left margin
:param float right: fraction to crop from the right margin | 2.117687 | 2.161066 | 0.979927 |
th = vtk.vtkImageThreshold()
th.SetInputData(self.image)
if vmin is not None and vmax is not None:
th.ThresholdBetween(vmin, vmax)
elif vmin is not None:
th.ThresholdByUpper(vmin)
elif vmax is not None:
th.ThresholdByLower(vma... | def threshold(self, vmin=None, vmax=None, replaceWith=None) | Binary or continuous volume thresholding. | 1.963953 | 1.925027 | 1.020221 |
nx, ny, nz = self.image.GetDimensions()
voxdata = np.zeros([nx, ny, nz])
lsx = range(nx)
lsy = range(ny)
lsz = range(nz)
renorm = vmin is not None and vmax is not None
for i in lsx:
for j in lsy:
for k in lsz:
... | def getVoxelsScalar(self, vmin=None, vmax=None) | Return voxel content as a ``numpy.array``.
:param float vmin: rescale scalar content to match `vmin` and `vmax` range.
:param float vmax: rescale scalar content to match `vmin` and `vmax` range. | 2.140247 | 2.133753 | 1.003044 |
if alpha is None:
alpha = 1
if isinstance(inputobj, vtk.vtkPolyData):
a = Actor(inputobj, c, alpha, wire, bc, texture)
if inputobj and inputobj.GetNumberOfPoints() == 0:
colors.printc("~lightning Warning: actor has zero points.", c=5)
return a
acts = []
... | def load(
inputobj,
c="gold",
alpha=None,
wire=False,
bc=None,
texture=None,
smoothing=None,
threshold=None,
connectivity=False,
) | Returns a ``vtkActor`` from reading a file, directory or ``vtkPolyData``.
:param c: color in RGB format, hex, symbol or name
:param alpha: transparency (0=invisible)
:param wire: show surface as wireframe
:param bc: backface color of internal surface
:param texture: any png/jpg file can b... | 3.294412 | 3.440145 | 0.957638 |
if not os.path.exists(filename):
colors.printc("~noentry Error in loadPolyData: Cannot find", filename, c=1)
return None
fl = filename.lower()
if fl.endswith(".vtk"):
reader = vtk.vtkPolyDataReader()
elif fl.endswith(".ply"):
reader = vtk.vtkPLYReader()
elif fl... | def loadPolyData(filename) | Load a file and return a ``vtkPolyData`` object (not a ``vtkActor``). | 2.232692 | 2.227237 | 1.002449 |
def loadXMLGenericData(filename): # not tested
reader = vtk.vtkXMLGenericDataObjectReader()
reader.SetFileName(filename)
reader.Update()
return Actor(reader.GetOutput()) | Read any type of vtk data object encoded in XML format. Return an ``Actor(vtkActor)`` object. | null | null | null | |
reader = vtk.vtkStructuredPointsReader()
reader.SetFileName(filename)
reader.Update()
gf = vtk.vtkImageDataGeometryFilter()
gf.SetInputConnection(reader.GetOutputPort())
gf.Update()
return Actor(gf.GetOutput()) | def loadStructuredPoints(filename) | Load a ``vtkStructuredPoints`` object from file and return an ``Actor(vtkActor)`` object.
.. hint:: |readStructuredPoints| |readStructuredPoints.py|_ | 2.439809 | 2.519096 | 0.968526 |
def loadStructuredGrid(filename): # not tested
reader = vtk.vtkStructuredGridReader()
reader.SetFileName(filename)
reader.Update()
gf = vtk.vtkStructuredGridGeometryFilter()
gf.SetInputConnection(reader.GetOutputPort())
gf.Update()
return Actor(gf.GetOutput()) | Load a ``vtkStructuredGrid`` object from file and return a ``Actor(vtkActor)`` object. | null | null | null | |
def loadUnStructuredGrid(filename): # not tested
reader = vtk.vtkUnstructuredGridReader()
reader.SetFileName(filename)
reader.Update()
gf = vtk.vtkUnstructuredGridGeometryFilter()
gf.SetInputConnection(reader.GetOutputPort())
gf.Update()
return Actor(gf.GetOutput()) | Load a ``vtkunStructuredGrid`` object from file and return a ``Actor(vtkActor)`` object. | null | null | null | |
def loadRectilinearGrid(filename): # not tested
reader = vtk.vtkRectilinearGridReader()
reader.SetFileName(filename)
reader.Update()
gf = vtk.vtkRectilinearGridGeometryFilter()
gf.SetInputConnection(reader.GetOutputPort())
gf.Update()
return Actor(gf.GetOutput()) | Load a ``vtkRectilinearGrid`` object from file and return a ``Actor(vtkActor)`` object. | null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.