# analysis¶

Defines methods useful to analyse 3D meshes.

## alignICP¶

vedo.analysis.alignICP(source, target, iters=100, rigid=False)[source]

Return a copy of source mesh which is aligned to target mesh through the Iterative Closest Point algorithm.

The core of the algorithm is to match each vertex in one surface with the closest surface point on the other, then apply the transformation that modify one surface to best match the other (in the least-square sense).

Hint

## alignLandmarks¶

vedo.analysis.alignLandmarks(source, target, rigid=False)[source]

Find best matching of source points towards target in the mean least square sense, in one single step.

## alignProcrustes¶

vedo.analysis.alignProcrustes(sources, rigid=False)[source]

Return an Assembly of aligned source meshes with the Procrustes algorithm. The output Assembly is normalized in size.

Procrustes algorithm takes N set of points and aligns them in a least-squares sense to their mutual mean. The algorithm is iterated until convergence, as the mean must be recomputed after each alignment.

The set of average points generated by the algorithm can be accessed with algoutput.info['mean'] as a numpy array.

Parameters

rigid (bool) – if True scaling is disabled.

## booleanOperation¶

vedo.analysis.booleanOperation(mesh1, operation, mesh2)[source]

Volumetric union, intersection and subtraction of surfaces.

Parameters

operation (str) – allowed operations: 'plus', 'intersect', 'minus'.

## cluster¶

vedo.analysis.cluster(points, radius)[source]

Clustering of points in space.

radius is the radius of local search. Individual subsets can be accessed through mesh.clusters.

## connectedPoints¶

vedo.analysis.connectedPoints(mesh, radius, mode=0, regions=(), vrange=0, 1, seeds=(), angle=0)[source]

Extracts and/or segments points from a point cloud based on geometric distance measures (e.g., proximity, normal alignments, etc.) and optional measures such as scalar range. The default operation is to segment the points into “connected” regions where the connection is determined by an appropriate distance measure. Each region is given a region id.

Optionally, the filter can output the largest connected region of points; a particular region (via id specification); those regions that are seeded using a list of input point ids; or the region of points closest to a specified position.

The key parameter of this filter is the radius defining a sphere around each point which defines a local neighborhood: any other points in the local neighborhood are assumed connected to the point. Note that the radius is defined in absolute terms.

Other parameters are used to further qualify what it means to be a neighboring point. For example, scalar range and/or point normals can be used to further constrain the neighborhood. Also the extraction mode defines how the filter operates. By default, all regions are extracted but it is possible to extract particular regions; the region closest to a seed point; seeded regions; or the largest region found while processing. By default, all regions are extracted.

On output, all points are labeled with a region number. However note that the number of input and output points may not be the same: if not extracting all regions then the output size may be less than the input size.

Parameters
• radius (float) – radius variable specifying a local sphere used to define local point neighborhood

• mode (int) –

• 0, Extract all regions

• 1, Extract point seeded regions

• 2, Extract largest region

• 3, Test specified regions

• 4, Extract all regions with scalar connectivity

• 5, Extract point seeded regions

• regions (list) – a list of non-negative regions id to extract

• vrange (list) – scalar range to use to extract points based on scalar connectivity

• seeds (list) – a list of non-negative point seed ids

• angle (list) – points are connected if the angle between their normals is within this angle threshold (expressed in degrees).

## delaunay2D¶

vedo.analysis.delaunay2D(plist, mode='scipy', tol=None)[source]

Create a mesh from points in the XY plane. If mode=’fit’ then the filter computes a best fitting plane and projects the points onto it.

## densifyCloud¶

vedo.analysis.densifyCloud(mesh, targetDistance, closestN=6, radius=0, maxIter=None, maxN=None)[source]

Adds new points to an input point cloud. The new points are created in such a way that all points in any local neighborhood are within a target distance of one another.

The algorithm works as follows. For each input point, the distance to all points in its neighborhood is computed. If any of its neighbors is further than the target distance, the edge connecting the point and its neighbor is bisected and a new point is inserted at the bisection point. A single pass is completed once all the input points are visited. Then the process repeats to the limit of the maximum number of iterations.

Note

Points will be created in an iterative fashion until all points in their local neighborhood are the target distance apart or less. Note that the process may terminate early due to the limit on the maximum number of iterations. By default the target distance is set to 0.5. Note that the TargetDistance should be less than the Radius or nothing will change on output.

Warning

This class can generate a lot of points very quickly. The maximum number of iterations is by default set to =1.0 for this reason. Increase the number of iterations very carefully. Also, maxN can be set to limit the explosion of points. It is also recommended that a N closest neighborhood is used.

## fitLine¶

vedo.analysis.fitLine(points)[source]

Fits a line through points.

Extra info is stored in Line.slope, Line.center, Line.variances.

## fitPlane¶

vedo.analysis.fitPlane(points)[source]

Fits a plane to a set of points.

Extra info is stored in Plane.normal, Plane.center, Plane.variance.

Hint

Example: fitplanes.py

## fitSphere¶

vedo.analysis.fitSphere(coords)[source]

Fits a sphere to a set of points.

Extra info is stored in Sphere.radius, Sphere.center, Sphere.residue.

Hint

Example: fitspheres1.py

## geodesic¶

vedo.analysis.geodesic(mesh, start, end)[source]

Dijkstra algorithm to compute the graph geodesic. Takes as input a polygonal mesh and performs a single source shortest path calculation.

Parameters
• start (int, list) – start vertex index or close point [x,y,z]

• end – end vertex index or close point [x,y,z]

## implicitModeller¶

vedo.analysis.implicitModeller(mesh, distance=0.05, res=110, 40, 20, bounds=(), maxdist=None, outer=True)[source]

Finds the surface at the specified distance from the input one

## interpolateToStructuredGrid¶

vedo.analysis.interpolateToStructuredGrid(mesh, kernel=None, radius=None, bounds=None, nullValue=None, dims=None)[source]

Generate a volumetric dataset (vtkStructuredData) by interpolating a scalar or vector field which is only known on a scattered set of points or mesh. Available interpolation kernels are: shepard, gaussian, voronoi, linear.

Parameters
• kernel (str) – interpolation kernel type [shepard]

• bounds (list) – bounding box of the output vtkStructuredGrid object

• dims (list) – dimensions of the output vtkStructuredGrid object

• nullValue (float) – value to be assigned to invalid points

## interpolateToVolume¶

vedo.analysis.interpolateToVolume(mesh, kernel='shepard', radius=None, bounds=None, nullValue=None, dims=20, 20, 20)[source]

Generate a Volume by interpolating a scalar or vector field which is only known on a scattered set of points or mesh. Available interpolation kernels are: shepard, gaussian, voronoi, linear.

Parameters
• kernel (str) – interpolation kernel type [shepard]

• bounds (list) – bounding box of the output Volume object

• dims (list) – dimensions of the output Volume object

• nullValue (float) – value to be assigned to invalid points

## mesh2Volume¶

vedo.analysis.mesh2Volume(mesh, spacing=1, 1, 1)[source]

Convert a mesh it into a Volume where the foreground (exterior) voxels value is 1 and the background (interior) voxels value is 0. Internally the vtkPolyDataToImageStencil class is used.

## normalLines¶

vedo.analysis.normalLines(mesh, ratio=1, atCells=True, scale=1)[source]

Build an Mesh made of the normals at cells shown as lines.

if atCells is False normals are shown at vertices.

## pcaEllipsoid¶

vedo.analysis.pcaEllipsoid(points, pvalue=0.95)[source]

Show the oriented PCA ellipsoid that contains fraction pvalue of points.

Parameters

pvalue (float) – ellypsoid will contain the specified fraction of points.

Extra can be calculated with mesh.asphericity(), mesh.asphericity_error() (asphericity is equal to 0 for a perfect sphere).

Axes can be accessed in mesh.va, mesh.vb, mesh.vc. End point of the axes are stored in mesh.axis1, mesh.axis12 and mesh.axis3.

Hint

Examples: pca.py cell_colony.py

## pointCloudFrom¶

vedo.analysis.pointCloudFrom(obj, useCellData=False)[source]

Build a Mesh object from any VTK dataset as a point cloud.

Parameters

useCellData (bool) – if True cell data is interpolated at point positions.

## pointDensity¶

vedo.analysis.pointDensity(mesh, dims=40, 40, 40, bounds=None, radius=None, computeGradient=False)[source]

Generate a density field from a point cloud. Output is a Volume. The local neighborhood is specified as a radius around each sample position (each voxel). The density is normalized to the upper value of the scalar range.

See example script: pointDensity.py

## pointSampler¶

vedo.analysis.pointSampler(mesh, distance=None)[source]

Generate a cloud of points the specified distance apart from the input.

## probeLine¶

vedo.analysis.probeLine(vol, p1, p2, res=100)[source]

Takes a Volume (or any other vtk data set) and probes its scalars along a line defined by 2 points p1 and p2.

Note that a mask is also output with valid/invalid points which can be accessed with mesh.getPointArray(‘vtkValidPointMask’).

Parameters

res (int) – nr of points along the line

## probePlane¶

vedo.analysis.probePlane(vol, origin=0, 0, 0, normal=1, 0, 0)[source]

Takes a Volume (or any other vtk data set) and probes its scalars on a plane defined by a point and a normal.

## probePoints¶

vedo.analysis.probePoints(vol, pts)[source]

Takes a Volume (or any other vtk data set) and probes its scalars at the specified points in space.

Note that a mask is also output with valid/invalid points which can be accessed with mesh.getPointArray(‘vtkValidPointMask’).

## projectSphereToPlane¶

vedo.analysis.projectSphereToPlane(mesh)[source]

Project a spherical-like object onto a plane.

## recoSurface¶

vedo.analysis.recoSurface(pts, dims=250, 250, 250, radius=None, sampleSize=None, holeFilling=True, bounds=(), pad=0.1)[source]

Surface reconstruction from a scattered cloud of points.

Parameters
• dims (int) – number of voxels in x, y and z to control precision.

• radius (float) – radius of influence of each point. Smaller values generally improve performance markedly. Note that after the signed distance function is computed, any voxel taking on the value >= radius is presumed to be “unseen” or uninitialized.

• sampleSize (int) – if normals are not present they will be calculated using this sample size per point.

• holeFilling (bool) – enables hole filling, this generates separating surfaces between the empty and unseen portions of the volume.

• bounds (list) – region in space in which to perform the sampling in format (xmin,xmax, ymin,ymax, zim, zmax)

• pad (float) – increase by this fraction the bounding box

## removeOutliers¶

vedo.analysis.removeOutliers(points, radius)[source]

Remove outliers from a cloud of points within the specified radius search.

## resampleArrays¶

vedo.analysis.resampleArrays(source, target, tol=None)[source]

Resample point and cell data of a dataset on points from another dataset. It takes two inputs - source and target, and samples the point and cell values of target onto the point locations of source. The output has the same structure as the source but its point data have the resampled values from target.

Parameters

tol (float) – set the tolerance used to compute whether a point in the target is in a cell of the source. Points without resampled values, and their cells, are be marked as blank.

## signedDistanceFromPointCloud¶

vedo.analysis.signedDistanceFromPointCloud(mesh, maxradius=None, bounds=None, dims=20, 20, 20)[source]

Compute signed distances over a volume from an input point cloud. The output is a Volume object whose voxels contains the signed distance from the cloud.

Parameters
• maxradius (float) – how far out to propagate distance calculation

• bounds (list) – volume bounds.

• dims (list) – dimensions (nr. of voxels) of the output volume.

## smoothMLS3D¶

vedo.analysis.smoothMLS3D(meshs, neighbours=10)[source]

A time sequence of point clouds (Mesh) is being smoothed in 4D (3D + time) using a MLS (Moving Least Squares) algorithm variant. The time associated to an mesh must be specified in advance with mesh.time() method. Data itself can suggest a meaningful time separation based on the spatial distribution of points.

Parameters

neighbours (int) – fixed nr. of neighbours in space-time to take into account in the fit.

## streamLines¶

vedo.analysis.streamLines(domain, probe, activeVectors='', integrator='rk4', direction='forward', initialStepSize=None, maxPropagation=None, maxSteps=10000, stepLength=None, extrapolateToBoundingBox=(), surfaceConstrain=False, computeVorticity=True, ribbons=None, tubes={}, scalarRange=None, lw=None)[source]

Integrate a vector field on a domain (a Mesh or other vtk datasets types) to generate streamlines.

The integration is performed using a specified integrator (Runge-Kutta). The length of a streamline is governed by specifying a maximum value either in physical arc length or in (local) cell length. Otherwise, the integration terminates upon exiting the field domain.

Parameters
• domain – the vtk object that contains the vector field

• activeVectors (str) – name of the vector array

• probe (Mesh,list) – the Mesh that probes the domain. Its coordinates will be the seeds for the streamlines, can also be an array of positions.

• integrator (str) – Runge-Kutta integrator, either ‘rk2’, ‘rk4’ of ‘rk45’

• initialStepSize (float) – initial step size of integration

• maxPropagation (float) – maximum physical length of the streamline

• maxSteps (int) – maximum nr of steps allowed

• stepLength (float) – length of step integration.

• extrapolateToBoundingBox (dict) –

Vectors defined on a surface are extrapolated to the entire volume defined by its bounding box

• kernel, (str) - interpolation kernel type [shepard]

• bounds, (list) - bounding box of the output Volume

• dims, (list) - dimensions of the output Volume object

• nullValue, (float) - value to be assigned to invalid points

• surfaceConstrain (bool) – force streamlines to be computed on a surface

• computeVorticity (bool) – Turn on/off vorticity computation at streamline points (necessary for generating proper stream-ribbons)

• ribbons (int) – render lines as ribbons by joining them. An integer value represent the ratio of joining (e.g.: ribbons=2 groups lines 2 by 2)

• tubes (dict) –

dictionary containing the parameters for the tube representation:

• ratio, (int) - draws tube as longitudinal stripes

• res, (int) - tube resolution (nr. of sides, 12 by default)

• varyRadius, (int) - radius varies based on the scalar or vector magnitude:

• 0 - do not vary radius

• 1 - vary radius by scalar

• 2 - vary radius by vector

• 3 - vary radius by absolute value of scalar

• scalarRange (list) – specify the scalar range for coloring

Hint

## surfaceIntersection¶

vedo.analysis.surfaceIntersection(mesh1, mesh2, tol=1e-06)[source]

Intersect 2 surfaces and return a line mesh.

## visiblePoints¶

vedo.analysis.visiblePoints(mesh, area=(), tol=None, invert=False)[source]

Extract points based on whether they are visible or not. Visibility is determined by accessing the z-buffer of a rendering window. The position of each input point is converted into display coordinates, and then the z-value at that point is obtained. If within the user-specified tolerance, the point is considered visible. Associated data attributes are passed to the output as well.

This filter also allows you to specify a rectangular window in display (pixel) coordinates in which the visible points must lie.

Parameters
• area (list) – specify a rectangular region as (xmin,xmax,ymin,ymax)

• tol (float) – a tolerance in normalized display coordinate system

• invert (bool) – select invisible points instead.

Example
from vedo import Ellipsoid, show, visiblePoints

s = Ellipsoid().rotateY(30)

#Camera options: pos, focalPoint, viewup, distance,
# clippingRange, parallelScale, thickness, viewAngle
camopts = dict(pos=(0,0,25), focalPoint=(0,0,0))
show(s, camera=camopts, offscreen=True)

m = visiblePoints(s)
#print('visible pts:', m.points()) # numpy array
show(m, newPlotter=True, axes=1)   # optionally draw result


## volumeFromMesh¶

vedo.analysis.volumeFromMesh(mesh, bounds=None, dims=20, 20, 20, signed=True, negate=False)[source]

Compute signed distances over a volume from an input mesh. The output is a Volume object whose voxels contains the signed distance from the mesh.

Parameters
• bounds (list) – bounds of the output volume.

• dims (list) – dimensions (nr. of voxels) of the output volume.

See example script: volumeFromMesh.py

## voronoi3D¶

vedo.analysis.voronoi3D(nuclei, bbfactor=1, tol=None)[source]

Generate 3D Voronio tasselization with the Voro++ package.