utils¶
Utilities submodule.
ProgressBar¶
-
class
vedo.utils.
ProgressBar
(start, stop, step=1, c=None, bold=True, italic=False, title='', ETA=True, width=25, char='━', char_back='─')[source]¶ Bases:
object
Class to print a progress bar with optional text message.
- Example
import time pb = ProgressBar(0,400, c='red') for i in pb.range(): time.sleep(.1) pb.print('some message')
cameraFromNeuroglancer¶
cameraFromQuaternion¶
-
vedo.utils.
cameraFromQuaternion
(pos, quaternion, distance=10000, ngl_correct=True)[source]¶ Define a
vtkCamera
with a particular orientation.- Parameters
pos (np.array, list, tuple) – an iterator of length 3 containing the focus point of the camera
quaternion (np.array, list, tuple) – a len(4) quaternion (x,y,z,w) describing the rotation of the camera such as returned by neuroglancer x,y,z,w all in [0,1] range
distance (float) – the desired distance from pos to the camera (default = 10000 nm)
- Returns
a vtk camera setup according to these rules.
- Return type
vtk.vtkCamera
dotdict¶
-
class
vedo.utils.
dotdict
(*args, **kwargs)[source]¶ Bases:
dict
A dictionary supporting dot notation.
Example
dd = dotdict({"a": 1, "b": {"c": "hello", "d": [1, 2, {"e": 123}]} } ) dd.update({'k':3}) dd.g = 7 print("k=", dd.k) # k= 3 print(dd.b.c) # hello print(isinstance(dd, dict)) # True print(dd.lookup("b.d")) # [1, 2, {"e": 123}]
fitCircle2D¶
-
vedo.utils.
fitCircle2D
(points)[source]¶ Fits a circle through points in the plane, with a very fast non-iterative method.
Returns the tuple (center_x, center_y, radius).
Reference: J.F. Crawford, Nucl. Instr. Meth. 211, 1983, 223-225.
Note
E.g.:
from vedo import * x = arange(0, 3, 0.1) y = sin(x) cx, cy, R = fitCircle2D([x,y]) Points([x, y]) Point([cx, cy]) Circle([cx, cy], r=R) show(..., axes=8)
geometry¶
-
vedo.utils.
geometry
(obj, extent=None)[source]¶ Apply the
vtkGeometryFilter
. This is a general-purpose filter to extract geometry (and associated data) from any type of dataset. This filter also may be used to convert any type of data to polygonal type. The conversion process may be less than satisfactory for some 3D datasets. For example, this filter will extract the outer surface of a volume or structured grid dataset.Returns a
Mesh
object.- Parameters
extent (list) – set a [xmin,xmax, ymin,ymax, zmin,zmax] bounding box to clip data.
grep¶
humansort¶
linInterpolate¶
-
vedo.utils.
linInterpolate
(x, rangeX, rangeY)[source]¶ Interpolate linearly variable x in rangeX onto rangeY. If x is a 3D vector the linear weight is the distance to the two 3D rangeX vectors.
E.g. if x runs in rangeX=[x0,x1] and I want it to run in rangeY=[y0,y1] then y = linInterpolate(x, rangeX, rangeY) will interpolate x onto rangeY.
makeBands¶
orientedCamera¶
pointIsInTriangle¶
pointToLineDistance¶
precision¶
-
vedo.utils.
precision
(x, p, vrange=None, delimiter='e')[source]¶ Returns a string representation of x formatted with precision p.
- Parameters
vrange (float) – range in which x exists (to snap it to ‘0’ if below precision).
Based on the webkit javascript implementation taken from here, and implemented by randlet.
printHistogram¶
-
vedo.utils.
printHistogram
(data, bins=10, height=10, logscale=False, minbin=0, horizontal=False, char='▉', c=None, bold=True, title='Histogram')[source]¶ Ascii histogram printing. Input can also be
Volume
orMesh
. Returns the raw data before binning (useful when passing vtk objects).- Parameters
bins (int) – number of histogram bins
height (int) – height of the histogram in character units
logscale (bool) – use logscale for frequencies
minbin (int) – ignore bins before minbin
horizontal (bool) – show histogram horizontally
char (bool) – character to be used
char – use boldface
title (str) – histogram title
- Example
from vedo import printHistogram import np as np d = np.random.normal(size=1000) data = printHistogram(d, c='blue', logscale=True, title='my scalars') data = printHistogram(d, c=1, horizontal=1) print(np.mean(data)) # data here is same as d
resampleArrays¶
-
vedo.utils.
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.