Skip to content

Commit

Permalink
2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed May 8, 2019
1 parent c1624ba commit b9341d6
Show file tree
Hide file tree
Showing 27 changed files with 419 additions and 173 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Intuitive and straightforward API which can be combined with VTK seamlessly
in a program, whilst mantaining access to the full range of VTK native classes.

It includes a [**large set of working examples**](https://github.com/marcomusy/vtkplotter/tree/master/examples)
for the all following functionalities:
for all the following functionalities:

- Import meshes from VTK format, STL, Wavefront OBJ, 3DS, XML, Neutral, GMSH, OFF, PCD (PointCloud), volumetric TIFF stacks, DICOM, SLC, MHD, 2D images PNG, JPEG.
- Export meshes as ASCII or binary to VTK, STL, OBJ, PLY formats.
Expand All @@ -39,7 +39,7 @@ for the all following functionalities:
- Point-surface operations: find nearest points, determine if a point lies inside or outside a mesh.
- Create primitive objects like: spheres, arrows, cubes, torus, ellipsoids...
- Generate *glyphs* (associating a mesh to each vertex of a source mesh).
- Create animations easily by just defining the position of the displayed objects in the 3D scene. Add trailing lines to moving objects automatically.
- Create animations easily by just defining the position of the displayed objects in the 3D scene. Add trailing lines and shadows to moving objects is also supported.
- Straightforward support for multiple *sync-ed* or independent renderers in the same window.
- Registration (alignment) of meshes with different techniques.
- Mesh smoothing with *Laplacian* and *WindowedSinc* algorithms.
Expand Down Expand Up @@ -97,7 +97,7 @@ git clone https://github.com/marcomusy/vtkplotter.git
cd vtkplotter/examples
python tutorial.py
```
**More than 160 working examples can be found in directories** _(scroll down to see the screenshots):_ <br>
**More than 170 working 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>
Expand All @@ -109,6 +109,8 @@ python tutorial.py
|:--------:|:-----|
| ![rabbit](https://user-images.githubusercontent.com/32848391/50738808-5816ad00-11d8-11e9-9854-c952be6fb941.jpg) | Apply a *Moving Least Squares* algorithm to obtain a smooth surface from a to a large cloud of scattered points in space ([script](https://github.com/marcomusy/vtkplotter/blob/master/examples/advanced/moving_least_squares2D.py)) <br /> `python advanced/moving_least_squares2D.py` |
| | |
| ![airplanes](https://user-images.githubusercontent.com/32848391/57341963-b8910900-713c-11e9-898a-84b6d3712bce.gif)| Create 3D animations in just a few lines of code.<br>Trails and shadows can be added to moving objects easily. ([script](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/airplanes.py)) <br /> `python simulations/airplanes.py`|
| | |
| ![gyro](https://user-images.githubusercontent.com/32848391/39766016-85c1c1d6-52e3-11e8-8575-d167b7ce5217.gif) | Simulation of a gyroscope hanging from a spring ([script](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/gyroscope1.py)) <br /> `python simulations/gyroscope1.py`|
| | |
| ![qsine2](https://user-images.githubusercontent.com/32848391/47751431-06aae880-dc92-11e8-9fcf-6659123edbfa.gif) | Quantum-tunnelling effect integrating the Schroedinger equation with 4th order Runge-Kutta method. The animation shows the evolution of a particle in a box hitting a sinusoidal potential barrier. ([script](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/tunnelling2.py)) <br /> `python simulations/tunnelling2.py` |
Expand All @@ -119,6 +121,7 @@ python tutorial.py
<br />



## References
Scientific publications using `vtkplotter` so far:

Expand Down
20 changes: 20 additions & 0 deletions examples/advanced/densifycloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""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.
"""
from vtkplotter import *
import numpy as np
np.random.seed(3)

npts = 200 # nr. of points
coords = np.random.rand(npts, 3) # range is [0, 1]
scals = np.abs(coords[:, 2]) # let the scalar be the z of point itself

apts = Points(coords, r=9).addPointScalars(scals, name='scals')

densecloud = densifyCloud(apts, .05, closestN=10, maxIter=1)
print(apts.N(), '->', densecloud.N())

ppp = Points(densecloud.coordinates())
show(apts, densecloud, Text(__doc__), axes=8)
4 changes: 3 additions & 1 deletion examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ python example.py
| | |
| [![sliders3d](https://user-images.githubusercontent.com/32848391/52859555-4efcf200-312d-11e9-9290-6988c8295163.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/sliders3d.py)<br/> `sliders3d.py` | Use a 3D sliders to modify interactively the position of a mesh.|
| | |
| [![silhouette](https://user-images.githubusercontent.com/32848391/57179369-8e5df380-6e7d-11e9-99b4-3b1a120dd375.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/silhouette.py)<br/> `silhouette.py` |Show the silhouette of a mesh as seen along a specified direction. |
| [![silhouette](https://user-images.githubusercontent.com/32848391/57179369-8e5df380-6e7d-11e9-99b4-3b1a120dd375.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/silhouette.py)<br/> `silhouette.py` |Show the silhouette of a mesh as seen along a specified direction. |
| | |
| [![shadow](https://user-images.githubusercontent.com/32848391/57312574-1d714280-70ee-11e9-8741-04fc5386d692.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/shadow.py)<br/> `shadow.py` | Draw the shadow of a set of meshes on one of the Cartesian planes. |
| | |
| [![texturecubes](https://user-images.githubusercontent.com/32848391/50738847-be033480-11d8-11e9-8087-8ba949dbf228.jpg)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/texturecubes.py)<br/> `texturecubes.py` | Show a cube for each available texture name. Any jpg file can be used as texture. <br/>Built in textures: `['aqua', 'blue', 'bricks', 'gold1', 'gold2', 'grass', 'greenfloor', 'greentiles', 'ivy', 'leather1', 'leather2', 'marble', 'masonry', 'metal1', 'metal2', 'metalfloor1', 'metalfloor2', 'paper', 'water', 'white1', 'white2', 'white3', 'white4', 'wood1', 'wood2', 'wood3', 'wood4', 'wood5', 'wood6', 'wood7', 'wood8', 'wood9']` |
| | |
Expand Down
9 changes: 9 additions & 0 deletions examples/basic/shadow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Make a shadow of 2 meshes on the wall."""
from vtkplotter import *

a = load(datadir + "spider.ply").normalize().rotateZ(-90)
s = Sphere(pos=[-0.4, 1.5, 0.3], r=0.3)

shad = Shadow(a, s, direction="x").x(-4)

show(a, s, shad, Text(__doc__), axes=1, viewup="z", bg="w")
6 changes: 3 additions & 3 deletions examples/basic/silhouette.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

s = Hyperboloid().rotateX(20)

sx = s.clone().projectOnPlane('yz').addPos(-2,0,0).c('r')
sy = s.clone().projectOnPlane('zx').addPos(0,-2,0).c('g')
sz = s.clone().projectOnPlane('xy').addPos(0,0,-2).c('b')
sx = s.clone().projectOnPlane('x').c('r').x(-3)
sy = s.clone().projectOnPlane('y').c('g').y(-3)
sz = s.clone().projectOnPlane('z').c('b').z(-3)

show(s, sx, sy, sz,
sx.silhouette(),
Expand Down
2 changes: 2 additions & 0 deletions examples/other/dolfin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ python example.py # on mac OSX try 'pythonw' instead
| | |
| [![submesh](https://user-images.githubusercontent.com/32848391/56675428-4e984e80-66bc-11e9-90b0-43dde7e4cc29.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin/demo_submesh.py)<br/> `demo_submesh.py` | How to extract matching sub meshes from a common mesh. |
| | |
| [![scalemesh](https://user-images.githubusercontent.com/32848391/57393382-431c4b80-71c3-11e9-9a2c-8abb172f5468.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin/scalemesh.py)<br/> `scalemesh.py` | Scale a 2D mesh asymmetrically in one coordinate and elevate it along the z-axis with the solution. |
| | |
| [![pi_estimate](https://user-images.githubusercontent.com/32848391/56675429-4e984e80-66bc-11e9-9217-a0652a8e74fe.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin/pi_estimate.py)<br/> `pi_estimate.py` | Estimate _pi_ by integrating a circle surface. Latex formulas can be added to the renderer directly. |
| | |
| [![tet_mesh](https://user-images.githubusercontent.com/32848391/53026244-d2d31900-3462-11e9-835a-1fa9d66d3dae.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin/ex02_tetralize-mesh.py)<br/> `ex02_tetralize-mesh.py` | Tetrahedral meshes generation with package _mshr_. |
Expand Down
4 changes: 2 additions & 2 deletions examples/other/dolfin/ex06_elasticity1.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

# ps = point size, only mesh vertices are shown
plot(u, mode='mesh', ps=10)
clear()

# plot displacements as white arrows, lw controls the mesh visibility
plot(u, mode='arrows', color='w', alpha=0.5, cmap='gist_earth', lw=1)
plot(u, mode='arrows', add=True,
color='w', alpha=0.5, cmap='gist_earth', lw=1)
3 changes: 3 additions & 0 deletions examples/other/dolfin/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ python calc_surface_area.py
echo Running markmesh.py
python markmesh.py

echo Running scalemesh.py
python scalemesh.py

echo Running pi_estimate.py
python pi_estimate.py

Expand Down
25 changes: 25 additions & 0 deletions examples/other/dolfin/scalemesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Scale a mesh asymmetrically in one coordinate
"""
from dolfin import *
from mshr import *

domain = Rectangle(Point(0.0, 0.0), Point(5.0, 0.01))
mesh = generate_mesh(domain, 20)
V = FunctionSpace(mesh, "CG", 2)

e = Expression("sin(2*pi*(x[0]*x[0]+x[1]*x[1]))", degree=2)
f = interpolate(e, V)

####################################################
from vtkplotter.dolfin import plot

plt = plot(f,
warpZfactor=0.05, # add z elevation proportional to expression
style=1,
lw=0,
xtitle = 'y-coord is scaled by factor 100',
text=__doc__,
interactive=False)
plt.actors[0].scale([1,100,1]) # retrieve actor object and scale y
plt.show(interactive=True) # refresh scene
2 changes: 1 addition & 1 deletion examples/other/dolfin/stokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from vtkplotter.dolfin import plot, datadir, Latex

t0 = time()
print("calculating... please wait...")
print("calculating... please wait... this takes time!")

# Load mesh and subdomains
mesh = Mesh(datadir+"dolfin_fine.xml")
Expand Down
6 changes: 3 additions & 3 deletions examples/other/self_org_maps2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# -----------------------------------------------------------------------------
import numpy as np
import scipy.spatial
from vtkplotter import Points, Sphere, Grid, ProgressBar, Text, show
from vtkplotter import *


class SOM:
Expand Down Expand Up @@ -52,7 +52,8 @@ def learn(self, n_epoch=10000, sigma=(0.25,0.01), lrate=(0.5,0.01)):
for j in range(n):
grd.setPoint(i*n+j, (x[i,j], y[i,j], z[i,j]))
show(doc, pts, grd, axes=6, bg='w', azimuth=2, interactive=False)


interactive()
return [self.codebook[:,i].reshape(n,n) for i in range(3)]

# -------------------------------------------------------------------------------
Expand All @@ -69,4 +70,3 @@ def learn(self, n_epoch=10000, sigma=(0.25,0.01), lrate=(0.5,0.01)):
som.samples = s.coordinates()
som.learn(n_epoch=7000, sigma=(1, 0.01), lrate=(1, 0.01))

show(interactive=True)
79 changes: 23 additions & 56 deletions examples/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ python basic/glyphs.py
echo Running basic/glyphs_arrows.py
python basic/glyphs_arrows.py

echo Running basic/shadow.py
python basic/shadow.py


#################################### advanced
echo Running advanced/fatlimb.py
Expand Down Expand Up @@ -248,50 +251,8 @@ python advanced/projectsphere.py
echo Running advanced/convexHull.py
python advanced/convexHull.py


################################### simulations
echo Running simulations/aspring.py
python simulations/aspring.py

echo Running simulations/cell_main.py
python simulations/cell_main.py

echo Running simulations/brownian2D.py
python simulations/brownian2D.py

echo Running simulations/gas.py
python simulations/gas.py

echo Running simulations/gyroscope1.py
python simulations/gyroscope1.py

echo Running simulations/gyroscope2.py
python simulations/gyroscope2.py

echo Running simulations/multiple_pendulum.py
python simulations/multiple_pendulum.py

echo Running simulations/hanoi3d.py
python simulations/hanoi3d.py

echo Running simulations/pendulum.py
python simulations/pendulum.py

echo Running simulations/wave_equation.py
python simulations/wave_equation.py

echo Running simulations/turing.py
python simulations/turing.py

echo Running simulations/particle_simulator.py
python simulations/particle_simulator.py

echo Running simulations/doubleslit.py
python simulations/doubleslit.py

echo Running simulations/tunnelling2.py
python simulations/tunnelling2.py

echo Running advanced/densifycloud.py
python advanced/densifycloud.py

################################### volumetric
echo Running volumetric/readVolumeAsIsoSurface.py
Expand Down Expand Up @@ -384,18 +345,6 @@ echo Running other/export_x3d.py
python other/export_x3d.py


##################################### not ran/ignored:
#basic/annotations.py
#basic/text_just.py
#basic/lights.py
#basic/ids.py
#basic/surfIntersect.py
#other/makeVideo.py
#other/spherical_harmonics2.py
#other/remesh_ACVD.py
#other/tf_learn_embryo.py
#other/self_org_maps2d.py

####################################
echo
echo
Expand Down Expand Up @@ -427,4 +376,22 @@ echo '----------------------------'
echo vtkplotter -s "data/2??.vtk"
vtkplotter -s data/2??.vtk

echo '\n----------------------------'
echo '----------------------------'
echo 'cd simulations; ./run_all.sh'
echo 'cd other/dolfin; ./run_all.sh'
echo '----------------------------'
echo '----------------------------'


##################################### not ran/ignored:
#basic/annotations.py
#basic/text_just.py
#basic/lights.py
#basic/ids.py
#basic/surfIntersect.py
#other/makeVideo.py
#other/spherical_harmonics2.py
#other/remesh_ACVD.py
#other/tf_learn_embryo.py
#other/self_org_maps2d.py
5 changes: 5 additions & 0 deletions examples/simulations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ python example.py # on mac OSX try 'pythonw' instead
| | |
| [![hanoi](https://user-images.githubusercontent.com/32848391/56989284-58c1bd80-6b92-11e9-8f82-1ce95813f846.gif)](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/hanoi3d.py)<br/> `hanoi3d.py` | Solve the Tower of Hanoi puzzle (contributed by [G. Jacquenot](https://github.com/Gjacquenot)). |
| | |
| [![airplanes](https://user-images.githubusercontent.com/32848391/57341963-b8910900-713c-11e9-898a-84b6d3712bce.gif)](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/airplanes.py)<br/> `airplanes.py` | Two acrobatic planes casting shadows and leaving a trail. |
| | |
| [![ruth](https://user-images.githubusercontent.com/32848391/50738891-db380300-11d8-11e9-84c2-0f55be7228f1.gif)](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/particle_simulator.py)<br/> `particle_simulator.py` | Simulates interacting charged particles in 3D space. |
| | |
| [![tunneling1](https://vtkplotter.embl.es/gifs/tunnelling2.gif)](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/tunnelling1.py)<br/> `tunnelling1.py` | Quantum Tunnelling effect using 4th order Runge-Kutta method with arbitrary potential shape. <br>The animation shows the evolution of a particle of relatively well defined momentum (hence undefined position) in a box hitting a potential barrier. The wave function is forced to be zero at the box walls. |
Expand All @@ -40,3 +42,6 @@ python example.py # on mac OSX try 'pythonw' instead
| [![wave](https://user-images.githubusercontent.com/32848391/50738956-7e891800-11d9-11e9-92d7-fa109b1b8551.gif)](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/wave_equation.py)<br/> `wave_equation.py` | Simulate a collection of discrete coupled oscillators. We use this as a model of a vibrating string and compare two methods of integration: Euler and Runge-Kutta4.|
| | |
| [![](https://user-images.githubusercontent.com/32848391/44957809-b2c09500-aed6-11e8-9dc5-c2e52b632f94.gif)](https://github.com/marcomusy/pianoplayer) | Finding and animating the optimal fingering to play a piano score with<br />[`pianoplayer 2.0`](https://github.com/marcomusy/pianoplayer)|



20 changes: 20 additions & 0 deletions examples/simulations/airplanes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Draw the shadow and trailing lines of 2 planes. This is not really
# a simulation.. just a way to illustrate how to move objects around!
from vtkplotter import *

world = Box([0,0,0], 30, 15, 8).wire()

p1 = load(datadir+"cessna.vtk").c("green").addTrail(lw=2, n=50)
p2 = p1.clone().c("tomato").addTrail(lw=2, n=50) # make a copy

# Setup the scene, creating the Plotter object is automatic
show(world, p1, p2, axes=1, bg="white", viewup="z", resetcam=0, interactive=0)

for x in arange(0, 3.5, 0.01):
p1.pos(9*x-15, 2-x, sin( 3-x)).rotateX(0+x) # make up some fancy movement
p2.pos(8*x-15, -2+x, sin(-3+x)).rotateX(2-x)

shad = Shadow(p1, p2, direction='z').z(-4) # fix z position of the shadow
show(world, p1, p2, shad)

interactive()
2 changes: 1 addition & 1 deletion examples/simulations/multiple_pendulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
Dt2 = Dt / 2 # Midpoint time step
DiaSq = (2 * R) ** 2 # Diameter of bob squared

printc("Press Esc to exit.", c="red")
printc("Press F1 to exit.", c="red")

while True:
bob_x_m = list(map((lambda x, dx: x + Dt2 * dx), bob_x, x_dot)) # midpoint variables
Expand Down
58 changes: 58 additions & 0 deletions examples/simulations/run_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
# source run_all.sh
#
printf "\033c"

echo #############################################
echo Press F1 at anytime to skip example
echo #############################################
echo
echo
echo


################################### simulations
echo Running aspring.py
python aspring.py

echo Running cell_main.py
python cell_main.py

echo Running brownian2D.py
python brownian2D.py

echo Running gas.py
python gas.py

echo Running gyroscope1.py
python gyroscope1.py

echo Running gyroscope2.py
python gyroscope2.py

echo Running multiple_pendulum.py
python multiple_pendulum.py

echo Running hanoi3d.py
python hanoi3d.py

echo Running airplanes.py
python airplanes.py

echo Running pendulum.py
python pendulum.py

echo Running wave_equation.py
python wave_equation.py

echo Running turing.py
python turing.py

echo Running particle_simulator.py
python particle_simulator.py

echo Running doubleslit.py
python doubleslit.py

echo Running tunnelling2.py
python tunnelling2.py
Loading

0 comments on commit b9341d6

Please sign in to comment.