Submodule to manage polygonal meshes.
Mesh(inputobj=None, c=None, alpha=1, computeNormals=False)¶
Build an instance of object
Input can be
vtkActor, or a python list of [vertices, faces].
If input is any of
vtkRectilinearGridthe geometry is extracted. In this case the original VTK data structures can be accessed with:
Finally input can be a list of vertices and their connectivity (faces of the polygonal mesh). For point clouds - e.i. no faces - just substitute the faces list with
E.g.: Mesh( [ [[x1,y1,z1],[x2,y2,z2], …], [[0,1,2], [1,2,3], …] ] )
A mesh can be built from vertices and their connectivity. See e.g.:
Add scalars to
Meshthat contains the curvature calculated in three different ways.
method (int) – 0-gaussian, 1-mean, 2-max, 3-min curvature.
lut – optional vtkLookUpTable up table.
from vedo import Torus Torus().addCurvatureScalars().show()
addElevationScalars(lowPoint=(), highPoint=(), vrange=(), lut=None)¶
Mesha scalar array that contains distance along a specified direction.
from vedo import Sphere s = Sphere().addElevationScalars(lowPoint=(0,0,0), highPoint=(1,1,1)) s.addScalarBar().show(axes=1) |elevation|
addShadow(x=None, y=None, z=None, c=0.5, 0.5, 0.5, alpha=1, culling=1)¶
Generate a shadow out of an
Meshon one of the three Cartesian planes. The output is a new
Meshrepresenting the shadow. This new mesh is accessible through mesh.shadow. By default the shadow mesh is placed on the bottom/back wall of the bounding box.
Set/get mesh’s backface color.
Set culling of polygons based on orientation of normal with respect to camera.
Shortcut for mesh.backColor().
Volumetric union, intersection and subtraction of surfaces.
operation (str) – allowed operations:
boundaries(boundaryEdges=True, featureAngle=65, nonManifoldEdges=True, returnPointIds=False, returnCellIds=False)¶
Meshthat shows the boundary lines of an input mesh.
boundaryEdges (bool) – Turn on/off the extraction of boundary edges.
featureAngle (float) – Specify the feature angle for extracting feature edges.
nonManifoldEdges (bool) – Turn on/off the extraction of non-manifold edges.
returnPointIds (bool) – return a numpy array of point indices
returnCellIds (bool) – return a numpy array of cell indices
Compute cell and vertex normals for the mesh.
Mesh gets modified, output can have a different nr. of vertices.
Find all cellls connected to an input vertex specified by its index.
Find all vertices connected to an input vertex specified by its index.
returnIds (bool) – return vertex IDs instead of vertex coordinates.
crop(top=None, bottom=None, right=None, left=None, front=None, back=None, bounds=None)¶
top (float) – fraction to crop from the top plane (positive z)
bottom (float) – fraction to crop from the bottom plane (negative z)
front (float) – fraction to crop from the front plane (positive y)
back (float) – fraction to crop from the back plane (negative y)
right (float) – fraction to crop from the right plane (positive x)
left (float) – fraction to crop from the left plane (negative x)
bounds (list) – direct list of bounds passed as [x0,x1, y0,y1, z0,z1]
from vedo import Sphere Sphere().crop(right=0.3, left=0.1).show()
Meshmesh with another
invert (bool) – if True return cut off part of Mesh.
cutWithPlane(origin=0, 0, 0, normal=1, 0, 0, returnCut=False)¶
Cut the mesh with the plane defined by a point and a normal.
origin – the cutting plane goes through this point
normal – normal of the cutting plane
from vedo import Cube cube = Cube().cutWithPlane(normal=(1,1,1)) cube.bc('pink').show()
Meshobject with a set of points forming a closed loop.
decimate(fraction=0.5, N=None, method='quadric', boundaries=False)¶
Downsample the number of vertices in a mesh to fraction.
fraction (float) – the desired target of reduction.
N (int) – the desired number of final points (fraction is recalculated based on it).
method (str) – can be either ‘quadric’ or ‘pro’. In the first case triagulation will look like more regular, irrespective of the mesh origianl curvature. In the second case triangles are more irregular but mesh is more precise on more curved regions.
boundaries (bool) – (True), in pro mode decide whether to leave boundaries untouched or not.
fraction=0.1leaves 10% of the original nr of vertices.
distanceToMesh(mesh, signed=False, negate=False)¶
Computes the (signed) distance from one mesh to another.
Extract the largest connected part of a mesh and discard all the smaller pieces.
extrude(zshift=1, rotation=0, dR=0, cap=True, res=1)¶
Sweep a polygonal data creating a “skirt” from free edges and lines, and lines from vertices. The input dataset is swept around the z-axis to create new polygonal primitives. For example, sweeping a line results in a cylindrical shell, and sweeping a circle creates a torus.
You can control whether the sweep of a 2D object (i.e., polygon or triangle strip) is capped with the generating geometry. Also, you can control the angle of rotation, and whether translation along the z-axis is performed along with the rotation. (Translation is useful for creating “springs”). You also can adjust the radius of the generating geometry using the “dR” keyword.
The skirt is generated by locating certain topological features. Free edges (edges of polygons or triangle strips only used by one polygon or triangle strips) generate surfaces. This is true also of lines or polylines. Vertices generate lines.
This filter can be used to model axisymmetric objects like cylinders, bottles, and wine glasses; or translational/rotational symmetric objects like springs or corkscrews.
Some polygonal objects have no free edges (e.g., sphere). When swept, this will result in two separate surfaces if capping is on, or no surface if capping is off.
Get cell polygonal connectivity ids as a python
list. The output format is: [[id0 … idn], [id0 … idm], etc].
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.
size (float) – approximate limit to the size of the hole that can be filled.
Set surface interpolation to Flat.
Mesh object will follow camera movements and stay locked to it. Use
mesh.followCamera(False)to disable it.
cam (vtkCamera) – if None the text will auto-orient itself to the active camera. A
vtkCameraobject can also be passed.
Set culling of polygons based on orientation of normal with respect to camera.
Dijkstra algorithm to compute the geodesic line. Takes as input a polygonal mesh and performs a single source shortest path calculation.
implicitModeller(distance=0.05, res=50, 50, 50, bounds=(), maxdist=None, outer=True)¶
Find the surface which sits at the specified distance from the input one.
insidePoints(pts, invert=False, tol=1e-05, returnIds=False)¶
Return the point cloud that is inside mesh surface.
Intersect this Mesh with the input surface to return a line.
Return the list of points intersecting the mesh along the segment defined by two points p0 and p1.
Return True if point is inside a polydata closed surface.
isobands(n=10, vmin=None, vmax=None)¶
Return a new
Meshrepresenting the isobands of the active scalars. This is a new mesh where the scalar is now associated to cell faces and used to colorize the mesh.
isolines(n=10, vmin=None, vmax=None)¶
Return a new
Meshrepresenting the isolines of the active scalars.
Generate triangle strips and/or polylines from input polygons, triangle strips, and lines.
Input polygons are assembled into triangle strips only if they are triangles; other types of polygons are passed through to the output and not stripped. Use mesh.triangulate() to triangulate non-triangular polygons prior to running this filter if you need to strip all the data.
Also note that if triangle strips or polylines are present in the input they are passed through and not joined nor extended. If you wish to strip these use mesh.triangulate() to fragment the input into triangles and lines prior to applying strip().
polys (bool) – polygonal segments will be joined if they are contiguous
If triangle strips or polylines exist in the input data they will be passed through to the output data. This filter will only construct triangle strips if triangle polygons are available; and will only construct polylines if lines are available.
Set/get color of mesh edges. Same as lineColor().
Set/get color of mesh edges. Same as lc().
Set/get width of mesh edges. Same as lw().
Get lines connectivity ids as a numpy array. Default format is [[id0,id1], [id3,id4], …]
flat (bool) – 1D numpy array as [2, 10,20, 3, 10,11,12, 2, 70,80, …]
Set/get width of mesh edges. Same as lineWidth().
Set surface interpolation to Phong.
Calculate functions of quality of the elements of a triangular mesh. See class vtkMeshQuality for explanation.
measure (int) –
type of estimator
EDGE RATIO, 0
ASPECT RATIO, 1
RADIUS RATIO, 2
ASPECT FROBENIUS, 3
MED ASPECT_FROBENIUS, 4
MAX ASPECT FROBENIUS, 5
COLLAPSE RATIO, 7
MAX ANGLE, 8
SCALED JACOBIAN, 10
RELATIVE SIZE SQUARED, 12
SHAPE AND SIZE, 14
MAX EDGE RATIO, 16
SHEAR AND SIZE, 24
ASPECT GAMMA, 27
ASPECT BETA, 29
Reverse the order of polygonal cells and/or reverse the direction of point and cell normals. Two flags are used to control these operations:
cells=True reverses the order of the indices in the cell connectivity list.
- normals=True reverses the normals by multiplying the normal vector by -1
(both point and cell normals, if present).
Shrink the triangle polydata in the representation of the input mesh.
from vedo import * pot = load(datadir + 'teapot.vtk').shrink(0.75) s = Sphere(r=0.2).pos(0,0,-0.5) show(pot, s)
silhouette(direction=None, borderEdges=True, featureAngle=False)¶
Return a new line
Meshwhich corresponds to the outer silhouette of the input as seen along a specified direction, this can also be a
direction (list) – viewpoint direction vector. If None this is guessed by looking at the minimum of the sides of the bounding box.
borderEdges (bool) – enable or disable generation of border edges
featureAngle (float) – minimal angle for sharp edges detection. If set to False the functionality is disabled.
smoothLaplacian(niter=15, relaxfact=0.1, edgeAngle=15, featureAngle=60)¶
Adjust mesh point positions using Laplacian smoothing.
niter (int) – number of iterations.
relaxfact (float) – relaxation factor. Small relaxfact and large niter are more stable.
edgeAngle (float) – edge angle to control smoothing along edges (either interior or boundary).
featureAngle (float) – specifies the feature angle for sharp edge identification.
smoothWSinc(niter=15, passBand=0.1, edgeAngle=15, featureAngle=60)¶
Adjust mesh point positions using the Windowed Sinc function interpolation kernel.
Split a mesh by connectivity and order the pieces by increasing area.
maxdepth (int) – only consider this number of mesh parts.
Stretch mesh between points q1 and q2. Mesh is not affected.
Meshobjects like helices, Line, cylinders, cones etc., two attributes
mesh.topare already defined.
Increase the number of vertices of a surface mesh.
texture(tname, tcoords=None, interpolate=True, repeat=True, edgeClamp=False, scale=None, ushift=None, vshift=None)¶
Assign a texture to mesh from image file or predefined texture tname. If tname is
Nonetexture is disabled. Input tname can also be an array of shape (n,m,3).
interpolate (bool) – turn on/off linear interpolation of the texture map when rendering.
repeat (bool) – repeat of the texture when tcoords extend beyond the [0,1] range.
edgeClamp (bool) – turn on/off the clamping of the texture map when the texture coords extend beyond the [0,1] range. Only used when repeat is False, and edge clamping is supported by the graphics card.
scale (bool) – scale the texture image by this factor
ushift (bool) – shift u-coordinates of texture by this amaount
vshift (bool) – shift v-coordinates of texture by this amaount
threshold(scalars, above=None, below=None, useCells=False)¶
Extracts cells where scalar value satisfies threshold criterion.
Converts mesh polygons into triangles.
If the input mesh is only made of 2D lines (no faces) the output will be a triangulation that fills the internal area. The contours may be concave, and may even contain holes, i.e. a contour may contain an internal contour winding in the opposite direction to indicate that it is a hole.
Get/set the volume occupied by mesh.
Set mesh’s representation as wireframe or solid surface. Same as mesh.wireframe().