Skip to content

Commit

Permalink
1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Apr 24, 2019
1 parent 1fa08f9 commit 692c339
Show file tree
Hide file tree
Showing 85 changed files with 1,727 additions and 661 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ git clone https://github.com/marcomusy/vtkplotter.git
cd vtkplotter/examples
python tutorial.py
```
**More than 100 examples can be found in directories** _(scroll down to see the screenshots):_ <br>
**More than 150 examples can be found in directories** _(scroll down to see the screenshots):_ <br>
[**examples/basic**](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic)<br>
[**examples/advanced**](https://github.com/marcomusy/vtkplotter/blob/master/examples/advanced)<br>
[**examples/volumetric**](https://github.com/marcomusy/vtkplotter/blob/master/examples/volumetric)<br>
[**examples/simulations**](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations)<br>
[**examples/other**](https://github.com/marcomusy/vtkplotter/blob/master/examples/other).<br>
[**examples/other**](https://github.com/marcomusy/vtkplotter/blob/master/examples/other)<br>
[**examples/other/dolfin**](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin).<br>

| | |
|:-----------------------------------------------------------------------------------------------------------------:|:-----|
Expand Down
11 changes: 9 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@
copyright = '2019, M. Musy'
author = 'Marco Musy'

# The short X.Y version
version = '2019.1.4'
# package version
try:
VERSIONFILE = "../../vtkplotter/version.py"
verstrline = open(VERSIONFILE, "rt").read()
verstr = verstrline.split('=')[1].replace('\n','').replace("'","")
except:
verstr='unknown_version'

version = verstr


# -- General configuration ---------------------------------------------------
Expand Down
43 changes: 24 additions & 19 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ vp = Plotter(title='first example')
# (The actual mesh corresponds to the outer shape of
# an embryonic mouse limb at about 11 days of gestation).
# Choose a tomato color for the internal surface of the mesh, and no transparency.
vp.load('data/270.vtk', c='b', bc='tomato') # c=(R,G,B), letter or color name, b=blue
vp.load(datadir+'270.vtk', c='b', bc='tomato') # c=(R,G,B), letter or color name, b=blue
vp.show() # picks what was stored in python list vp.actors
# Press Esc to close the window and exit python session, or q to continue

# The same result can be achieved in an even simpler way:
from vtkplotter import *
mesh = load(datadir+'270.vtk', c='b', bc='tomato')
# a Plotter instance is automatically generated
mesh.show()
```
![tut1](https://user-images.githubusercontent.com/32848391/50738980-d9227400-11d9-11e9-8a7c-14b2abc4d41f.jpg)

Expand All @@ -33,9 +39,9 @@ vp.show() # picks what was stored in python list vp.actors
# by default use their file names as legend entries.
# No need to use any variables, as actors are stored internally in vp.actors:
vp = Plotter(title='3 shapes')
vp.load('data/250.vtk', c=(1,0.4,0), alpha=0.3) # set opacity to 30%
vp.load('data/270.vtk', c=(1,0.6,0), alpha=0.3)
vp.load('data/290.vtk', c=(1,0.8,0), alpha=0.3)
vp.load(datadir+'250.vtk', c=(1,0.4,0), alpha=0.3) # set opacity to 30%
vp.load(datadir+'270.vtk', c=(1,0.6,0), alpha=0.3)
vp.load(datadir+'290.vtk', c=(1,0.8,0), alpha=0.3)
print('Loaded vtkActors: ', len(vp.actors))
vp.show()
```
Expand Down Expand Up @@ -88,15 +94,15 @@ vp.show(Cylinder(), at=8, legend='cylinder', interactive=1)
# Draw a bunch of objects from various mesh formats. Loading is automatic.
vp = Plotter(shape=(3,3), title='mesh formats') # split window in 3 rows and 3 columns
vp.sharecam = False # each object can be moved independently
vp.show('data/beethoven.ply', at=0, c=0, axes=0) # dont show axes
vp.show('data/cow.byu', at=1, c=1, zoom=1.15) # make it 15% bigger
vp.show('data/limb.pcd', at=2, c=2)
vp.show('data/ring.gmsh', at=3, c=3, wire=1) # show mesh as wireframe
vp.show('data/images/dog.jpg',at=4) # 2d images can be loaded the same way
vp.show('data/shuttle.obj', at=5, c=5)
vp.show('data/shapes/man.vtk',at=6, c=6, axes=2) # show negative axes segments
vp.show('data/teapot.xyz', at=7, c=7, axes=3) # hide negative axes
vp.show('data/pulley.vtu', at=8, c=8, interactive=1) # try to click object and press k
vp.show(datadir+'beethoven.ply', at=0, c=0, axes=0) # dont show axes
vp.show(datadir+'cow.byu', at=1, c=1, zoom=1.15) # make it 15% bigger
vp.show(datadir+'limb.pcd', at=2, c=2)
vp.show(datadir+'ring.gmsh', at=3, c=3, wire=1) # show mesh as wireframe
vp.show(datadir+'images/dog.jpg',at=4) # 2d images can be loaded the same way
vp.show(datadir+'shuttle.obj', at=5, c=5)
vp.show(datadir+'shapes/man.vtk',at=6, c=6, axes=2) # show negative axes segments
vp.show(datadir+'teapot.xyz', at=7, c=7, axes=3) # hide negative axes
vp.show(datadir+'pulley.vtu', at=8, c=8, interactive=1) # try to click object and press k
```
![tut7](https://user-images.githubusercontent.com/32848391/50738975-d889dd80-11d9-11e9-97a1-647a9a044718.jpg)

Expand All @@ -105,7 +111,7 @@ vp.show('data/pulley.vtu', at=8, c=8, interactive=1) # try to click object an
# Increase the number of vertices of a mesh using subdivide().
# Show the mesh before and after in two separate renderers defined by shape=(1,2)
vp = Plotter(shape=(1,2), axes=0) # dont show axes
a1 = vp.load('data/beethoven.ply')
a1 = vp.load(datadir+'beethoven.ply')

coords1 = a1.coordinates() # get coordinates of mesh vertices
pts1 = vp.points(coords1, r=4, c='g', legend='#points = '+str(len(coords1)))
Expand All @@ -125,7 +131,7 @@ vp.show([a2, pts2], at=1, interactive=True)
# point at x=500 and has normal (0, 0.3, -1).
# Wildcards can be used to load multiple files or entire directories:
vp = Plotter(title='Cut a surface with a plane')
vp.load('data/2*0.vtk', c='orange', bc='aqua')
vp.load(datadir+'2*0.vtk', c='orange', bc='aqua')
for a in vp.actors:
a.cutWithPlane(origin=(500,0,0), normal=(0,0.3,-1), showcut=True)
vp.show()
Expand All @@ -143,7 +149,7 @@ vp.renderer # holds the current vtkRenderer
vp.renderers # holds the list of renderers
vp.interactor # holds the vtkWindowInteractor object
vp.interactive # (True) allows to interact with renderer after show()
vp.camera # holds the current vtkCamera
vp.camera # holds the current vtkCamera object
vp.sharecam # (True) share the same camera in multiple renderers
```
Expand All @@ -159,10 +165,9 @@ actor.rotate(angle, axis) # rotate actor around axis
actor.color(name) # sets/gets color
actor.alpha(value) # sets/gets opacity
actor.N() # get number of vertex points defining the actor's mesh
actor.polydata() # get the actor's mesh polydata in its current transformation
actor.polydata() # get the actor's mesh vtkPolyData in its current transformation
actor.coordinates() # get a copy of vertex points coordinates (copy=False to get references)
actor.normals() # get the list of normals at the vertices of the surface
actor.clone() # get a copy of actor
actor.clone() # generate a copy of actor
...
```

Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/geodesic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

doc = Text(__doc__, c="w")

show(s, Earth(lw=1), doc, paths, viewup="z", verbose=0)
show(s, Earth(lw=1), doc, paths, viewup="z")
2 changes: 1 addition & 1 deletion examples/advanced/mesh_smoothers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Mesh smoothing with two different VTK methods.
See also analogous Plotter method smoothMLS2D()
in exammples/advanced/moving_least_squares2D.py
in exammples/advanced/moving_least_squares2D.py
"""
print(__doc__)
from vtkplotter import Plotter, datadir
Expand Down
4 changes: 2 additions & 2 deletions examples/advanced/moving_least_squares1D.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
This example shows how to use a variant of a 1 dimensional
Moving Least Squares (MLS) algorithm to project a cloud
Moving Least Squares (MLS) algorithm to project a cloud
of unordered points to become a smooth line.
The parameter f controls the size of the local regression.
The input actor's polydata is modified by the method
so more than one pass is possible.
If showNLines>0 an actor is built demonstrating the
If showNLines>0 an actor is built demonstrating the
details of the regression for some random points
"""
from __future__ import division, print_function
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/recosurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
vp.show(act_pts1, at=2)

# reconstructed surface from point cloud
act_reco = recoSurface(act_pts1, bins=128).legend("surf reco")
act_reco = recoSurface(act_pts1, bins=128).legend("surf reco")
vp.show(act_reco, at=3, axes=7, interactive=1)
2 changes: 1 addition & 1 deletion examples/advanced/splitmesh.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Split a mesh by connectivity and order the pieces
Split a mesh by connectivity and order the pieces
by increasing area.
"""
print(__doc__)
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/thinplate_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
apts = Points(ptsource, r=5, c="r")
arrs = Arrows(ptsource, pttarget)

show(warped, apts, arrs, Text(__doc__), axes=9, viewup="z", verbose=0, bg="w")
show(warped, apts, arrs, Text(__doc__), axes=9, viewup="z", bg="w")
2 changes: 2 additions & 0 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ python example.py
| | |
| [![mesh_custom](https://user-images.githubusercontent.com/32848391/51390972-20d9c180-1b31-11e9-955d-025f1ef24cb7.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/mesh_custom.py)<br/> `mesh_custom.py` | Build a custom color map to specify the color for each vertex of a mesh. |
| | |
| [![mesh_map2cell](https://user-images.githubusercontent.com/32848391/56600859-0153a880-65fa-11e9-88be-34fd96b18e9a.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/mesh_map2cell.py)<br/> `mesh_map2cell.py` | Map a scalar which is defined on the vertices to the mesh cells. |
| | |
| [![mesh_threshold](https://user-images.githubusercontent.com/32848391/51807663-4762cf80-228a-11e9-9d0c-184bb11a97bf.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/mesh_threshold.py)<br/> `mesh_threshold.py` | Extracts the cells where scalar value satisfies a threshold criterion. |
| | |
| [![mirror](https://user-images.githubusercontent.com/32848391/50738855-bf346180-11d8-11e9-97a0-c9aaae6ce052.jpg)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/mirror.py)<br/> `mirror.py` | Mirror-reflect a mesh with respect to one of the cartesian axes. |
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/buildpolydata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Load a mesh, extract the vertex coordinates,
and build a new vtkPolyData object.
Load a mesh, extract the vertex coordinates,
and build a new vtkPolyData object.
Faces (vertex connectivity) can be specified too.
(press p to increase point size)
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/buttons.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Add a square button with N possible internal states
Add a square button with N possible internal states
to a rendering window that calls an external function.
Available fonts: arial, courier, times
"""
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/connCells.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
show(pactor, d, piece, Point(p, c='r'), interactive=0)

tomerge.append(piece)

show(mergeActors(tomerge).clean(), interactive=1)

4 changes: 2 additions & 2 deletions examples/basic/distance2mesh.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Computes the (signed) distance
Computes the (signed) distance
from one mesh to another.
"""
from vtkplotter import Sphere, Cube, show, Text
Expand All @@ -13,4 +13,4 @@

#print(s1.scalars("Distance"))

show(s1, s2, Text(__doc__))
show(s1, s2, Text(__doc__))
2 changes: 1 addition & 1 deletion examples/basic/flatarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
l2 = [[sin(x)+c+0.1, -cos(x)+s + x/15, x] for x in arange(0,3, 0.1)]

FlatArrow(l1, l2, c=i, tipSize=1, tipWidth=1)

show(collection(), viewup="z", axes=1, bg="w")
2 changes: 1 addition & 1 deletion examples/basic/glyphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
scaleByVectorSize=True,
)

show(s, gsphere1, t, at=0, N=2, verbose=0)
show(s, gsphere1, t, at=0, N=2)


#######################################
Expand Down
29 changes: 29 additions & 0 deletions examples/basic/glyphs_arrows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Draw color arrows.
"""
from vtkplotter import *
import numpy as np

s1 = Sphere(r=10, res=8).c('white').wire()
s2 = Sphere(r=20, res=8).c('white').wire().alpha(0.1).pos(0,4,0)

coords1 = s1.coordinates() # get the vertices coords
coords2 = s2.coordinates()

# color can be a colormap which maps arrrow sizes
a1 = Arrows(coords1, coords2, c='coolwarm', alpha=0.4)
a1.addScalarBar()


# get a list of random rgb colors
nrs = np.random.randint(0, 10, len(coords1))
cols = getColor(nrs)

a2 = Arrows(coords1, coords2, c=cols, scale=0.5)

t1 = Text('color arrows by size\nusing a color map')
t2 = Text('color arrows by an array\nand scale them')

# draw 2 group of actors on two renderers
show([[s1, s2, a1, t1], [s1, s2, a2, t2]], N=2)

2 changes: 1 addition & 1 deletion examples/basic/keypress.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
This example shows how to implement a custom function that is triggered by
pressing a keyboard button when the rendering window is in interactive mode.
Every time a key is pressed the picked point of the mesh is used
Every time a key is pressed the picked point of the mesh is used
to add a sphere and some info is printed.
"""
from vtkplotter import Plotter, printc, Sphere, Text, datadir
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/largestregion.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Extract the mesh region that
Extract the mesh region that
has the largest connected surface
"""
from vtkplotter import *
Expand Down
16 changes: 9 additions & 7 deletions examples/basic/latex.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from vtkplotter import Latex, Cube, Point, show
from vtkplotter import Latex, Point, show

# https://matplotlib.org/tutorials/text/mathtext.html

latex1 = r'x= \frac{ - b \pm \sqrt {b^2 - 4ac} }{2a}'
latex2 = r'$\mathcal{A}\mathrm{sin}(2 \omega t)$'
latex2 = r'\mathcal{A}\mathrm{sin}(2 \omega t)'
latex3 = r'I(Y | X)=\sum_{x \in \mathcal{X}, y \in \mathcal{Y}} p(x, y) \log \left(\frac{p(x)}{p(x, y)}\right)'
latex4 = r'\Gamma_{\epsilon}(x)=\left[1-e^{-2 \pi \epsilon}\right]^{1-x} \prod_{n=0}^{\infty} \frac{1-\exp (-2 \pi \epsilon(n+1))}{1-\exp (-2 \pi \epsilon(x+n))}'
latex5 = r'\left( \begin{array}{l}{c t^{\prime}} \\ {x^{\prime}} \\ {y^{\prime}} \\ {z^{\prime}}\end{array}\right)=\left( \begin{array}{cccc}{\gamma} & {-\gamma \beta} & {0} & {0} \\ {-\gamma \beta} & {\gamma} & {0} & {0} \\ {0} & {0} & {1} & {0} \\ {0} & {0} & {0} & {1}\end{array}\right) \left( \begin{array}{l}{c t} \\ {x} \\ {y} \\ {z}\end{array}\right)'
latex6 = r'\mathrm{CO}_{2}+6 \mathrm{H}_{2} \mathrm{O} \rightarrow \mathrm{C}_{6} \mathrm{H}_{12} \mathrm{O}_{6}+6 \mathrm{O}_{2}'
latex7 = r'x~\mathrm{(arb. units)}'
latex7 = r'x \mathrm{(arb. units)}'

p = Point()
c = Cube().wire()
l = Latex(latex4, s=1, c='white', bg='', alpha=0.9, usetex=False, fromweb=False)
l.crop(0.3, 0.3) # crop top and bottom 30%
l.pos(2,0,0)

l = Latex(latex5, s=1, c='white', bg='', alpha=0.9, fromweb=False).addPos(4,0,-1)
p = Point()
box = l.box() # return the bounding box of an actor

show(p, c, l, axes=8)
show(p, l, box, axes=8)
3 changes: 2 additions & 1 deletion examples/basic/markpoint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Mark a specific point on a mesh with some text.
Mark a specific point
on a mesh with some text.
"""
from vtkplotter import Sphere, Point, show, Text

Expand Down
4 changes: 2 additions & 2 deletions examples/basic/mesh_bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from vtkplotter import show, Hyperboloid, Torus, Text
from numpy import linspace

doc = Text(__doc__, c="w", bg="lg")
doc = Text(__doc__, c="k", bg="lg")


hyp = Hyperboloid()
Expand All @@ -18,4 +18,4 @@
transp = linspace(1, 0.5, len(scalars)) # set transparencies from 1 -> .5
tor.pointColors(scalars, alpha=transp, bands=3, cmap="winter")

show(hyp, tor, doc, viewup="z", depthpeeling=1, axes=2, verbose=0)
show(hyp, tor, doc, viewup="z", depthpeeling=1, axes=2)
2 changes: 1 addition & 1 deletion examples/basic/mesh_coloring.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
print(__doc__)

from vtkplotter import Plotter, Text, datadir
from vtkplotter import *
import numpy as np

vp = Plotter(N=3)
Expand Down
19 changes: 11 additions & 8 deletions examples/basic/mesh_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
individual cell or point of an actor's mesh.
Keyword depthpeeling may improve the rendering of transparent objects.
"""
from vtkplotter import load, Text, show, datadir
from vtkplotter import *

doc = Text(__doc__, pos=1, c="w")

Expand All @@ -13,16 +13,19 @@
# let the scalar be the z coordinate of the mesh vertices
scals = man.coordinates()[:, 2]

# custom color map with optional opacity (here: 1, 0.2 and 0.8)
mymap = ["darkblue", "cyan 0.2", (1, 0, 0, 0.8)]
# custom color map with specified opacities
#mymap = ["darkblue", "cyan", (1, 0, 0)]
#alphas = [0.8, 0.4, 0.2]

# - or by predefined color numbers:
# mymap = [i for i in range(10)]
# - OR by predefined color numbers:
mymap = [i for i in range(10)]
alphas = [i/10. for i in range(10)]

# - or by generating a palette betwwen 2 colors:
# - OR by generating a palette betwwen 2 colors:
# from vtkplotter.colors import makePalette
# mymap = makePalette('pink', 'green', N=500, hsv=True)
#mymap = makePalette('pink', 'green', N=500, hsv=True)
#alphas = 1

man.pointColors(scals, cmap=mymap).addScalarBar()
man.pointColors(scals, cmap=mymap, alpha=alphas).addScalarBar()

show(man, doc, viewup="z", axes=8, depthpeeling=1)
Loading

0 comments on commit 692c339

Please sign in to comment.