genepy3d_gpl.util package#
Module contents#
Submodules#
genepy3d_gpl.util.mayavi module#
Plot objects using Mayavi.
This module plot the basic objects in GeNePy3D using Mayavi–VTK based library for 3D visualization.
Functions:
|
Plot a curve in 3D. |
|
Plot points in 3D. |
|
Plot tree in 3D. |
|
Plot surface in 3D. |
- genepy3d_gpl.util.mayavi.plot_curve(mlab, crv, r=1.0, clc=(1.0, 0.0, 0.0), opacity=1.0, ntheta=18, npnt=200)[source]#
Plot a curve in 3D.
- Parameters:
mlab (Mayavi object) – Mayavi plot object.
crv (Curve) – 3D curve.
r (float or array of float) – radius.
clc (tuple of float) – color.
opacity (float) – transparency.
ntheta (int) – number of angles for sampling the points from the given radii.
npnt (int) – number of points that used to be displayed (see mask_points in mlab.mesh()).
- Returns:
mlab mesh object.
Examples
from mayavi import mlab from genepy3d.util import mayavi as mvi from genepy3d.obj.curves import Curve # 3D curve from a helix t = np.arange(50) a = 1. b = 1. x = a * np.cos(t/5) y = a * np.sin(t/5) z = b * t crv = Curve((x,y,z)) # Random radius r = np.abs(np.sin(t)*0.2) + 0.1 # Plot curve mlab.figure(1, bgcolor=(0, 0, 0), fgcolor=(1, 1, 1), size=(800, 600)) mlab.clf() mvi.plot_curve(mlab,crv,r=r,clc=(0.,1.,0.)) mlab.show()
- genepy3d_gpl.util.mayavi.plot_points(mlab, pnt, r=1.0, clc=(1.0, 0.0, 0.0), opacity=1.0)[source]#
Plot points in 3D.
- Parameters:
mlab (Mayavi object) – Mayavi plot object.
pnt (Point) – 3D point cloud.
r (float or array of float) – radius.
clc (tuple of float) – color.
opacity (float) – transparency.
- Returns:
mlab mesh object.
Examples
from mayavi import mlab from genepy3d.util import mayavi as mvi from genepy3d.obj.points import Points # 3D points from a helix t = np.arange(50) a = 1. b = 1. x = a * np.cos(t/5) y = a * np.sin(t/5) z = b * t pnt = Points((x,y,z)) # Random radius r = np.abs(np.sin(t)*0.2) + 0.1 # Plot points mlab.figure(1, bgcolor=(0, 0, 0), fgcolor=(1, 1, 1), size=(800, 600)) mlab.clf() mvi.plot_points(mlab,pnt,r=r,clc=(1.,0.,1.)) mlab.show()
- genepy3d_gpl.util.mayavi.plot_tree(mlab, tr, r=None, clc=(0.5, 0.5, 0.5), opacity=1.0, show_branchings=False, br_clc=(0.0, 0.0, 1.0), br_r=None, show_leaves=False, lf_clc=(1.0, 1.0, 0.0), lf_r=None, show_connectors=False, cn_clc=(0.0, 1.0, 0.0), cn_r=None, show_root=False, ro_clc=(1.0, 0.0, 0.0), ro_r=None)[source]#
Plot tree in 3D.
- Parameters:
mlab (Mayavi object) – Mayavi plot object.
tr (Tree) – 3D tree.
r (None, float, int) – if None then plot the radius stored in tree, otherwise plot a constant radius.
clc (tuple or dict) – if tuple then entire tree has one color, if dict then colors are assigned for each structure_id.
opacity (float) – transparence.
show_branchings (bool) – if True plot branching points.
br_clc (tuple) – color of branching points.
br_r (None, float, int, array) – radius of branching points. if None then plot the real radius, otherwise plot a constant radius.
show_leaves (bool) – if True plot leaf points.
lf_clc (tuple) – color of leaf points.
lf_r (None, float, int, array) – radius of leaf points. if None then plot the real radius, otherwise plot a constant radius.
show_connectors (bool) – if True plot connectors.
cn_clc (tuple) – color of connectors.
cn_r (None, float, int, array) – radius of connector points. if None then plot the real radius, otherwise plot a constant radius.
show_root (bool) – if True plot the root points.
ro_clc (tuple) – color of root points.
ro_r (None, float, int, array) – radius of root points. if None then plot the real radius, otherwise plot a constant radius.
Examples
from mayavi import mlab from genepy3d.util import mayavi as mvi from genepy3d.obj.trees import Tree # Import a neuronal tree from swc file filepath = 'path/to/swc/file' neu = Tree.from_swc(filepath) # Plot tree clcdic = {1:(1.,0.,0.),3:(0.,1.,0.),4:(1.,0.,1.)} # assign color for a specific structure id mlab.figure(1, bgcolor=(0, 0, 0), fgcolor=(1, 1, 1), size=(800, 600)) mlab.clf() mvi.plot_tree( mlab,neu,clc=clcdic, show_leaves=True,lf_r=1.5, show_branchings=True,br_r=1.5, show_root=True,ro_r=5.) mlab.show()
- genepy3d_gpl.util.mayavi.plot_surface(mlab, surf, clc=(0.5, 0.5, 0.5), opacity=0.5)[source]#
Plot surface in 3D.
- Parameters:
mlab (Mayavi object) – Mayavi plot object.
surf (Surface) – 3D surface.
clc (tuple of float) – color.
opacity (float) – transparency.
- Returns:
mlab object.
Examples
from mayavi import mlab from genepy3d.util import mayavi as mvi from genepy3d.obj.surfaces import Surface # Get 3D coordinates from a csv file outlinepath = "outline.csv" tbl = pd.read_csv(outlinepath) coors = tbl[['x','y','z']].values # Plot 3D surface from the coordinates by QHull surf = Surface.from_points_qhull(coors) mlab.figure(1, bgcolor=(0, 0, 0), fgcolor=(1, 1, 1), size=(800, 600)) mlab.clf() mvi.plot_surface(mlab,surf) mlab.show()