Skip to content

Commit

Permalink
2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed May 13, 2019
1 parent b9341d6 commit 91defa4
Show file tree
Hide file tree
Showing 74 changed files with 1,641 additions and 399 deletions.
5 changes: 3 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include vtkplotter/*
include vtkplotter/textures/*
include vtkplotter/icons/*
include vtkplotter/fonts/*
include vtkplotter/fonts/licenses/*
include vtkplotter/data/*
include vtkplotter/data/images/*
include vtkplotter/data/shapes/*
include vtkplotter/data/timecourse1d/*
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ git clone https://github.com/marcomusy/vtkplotter.git
cd vtkplotter/examples
python tutorial.py
```
**More than 170 working examples can be found in directories** _(scroll down to see the screenshots):_ <br>
**More than 180 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,15 +109,15 @@ 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`|
| ![airplanes](https://user-images.githubusercontent.com/32848391/57341963-b8910900-713c-11e9-898a-84b6d3712bce.gif)| Create a 3D animation in exactly 10 lines of code. ([script](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/airplanes.py))<br>Trails and shadows can be added to moving objects easily. <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` |
| | |
| ![turing](https://user-images.githubusercontent.com/32848391/40665257-1412a30e-635d-11e8-9536-4c73bf6bdd92.gif) | Visualizing a Turing system of reaction-diffusion between two molecules<sup>1</sup> ([script](https://github.com/marcomusy/vtkplotter/blob/master/examples/simulations/turing.py)) <br /> `python simulations/turing.py` |
| | |
| ![elastodyn](https://user-images.githubusercontent.com/32848391/54932788-bd4a8680-4f1b-11e9-9326-33645171a45e.gif) | Support for the [FEniCS/dolfin](https://fenicsproject.org/) platform for visualization of finite element solutions ([see here](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin)). <br /> ![dolf](https://user-images.githubusercontent.com/32848391/56671156-6bc91f00-66b4-11e9-8c58-e6b71e2ad1d0.gif) |
| ![elastodyn](https://user-images.githubusercontent.com/32848391/54932788-bd4a8680-4f1b-11e9-9326-33645171a45e.gif) | Support for the [FEniCS/dolfin](https://fenicsproject.org/) platform for visualization of PDE and finite element solutions ([see here](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin)). <br /> ![dolf](https://user-images.githubusercontent.com/32848391/56671156-6bc91f00-66b4-11e9-8c58-e6b71e2ad1d0.gif) |
<br />


Expand Down
4 changes: 2 additions & 2 deletions bin/vtkplotter
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ else:

vp.show(actors[0], interactive=False, zoom=args.zoom)

if isinstance(vp.axes_exist[0], vtk.vtkCubeAxesActor):
vp.axes_exist[0].SetBounds(vbb)
if isinstance(vp.axes_instances[0], vtk.vtkCubeAxesActor):
vp.axes_instances[0].SetBounds(vbb)

cb = (1, 1, 1)
if numpy.sum(vp.renderer.GetBackground()) > 1.5:
Expand Down
12 changes: 12 additions & 0 deletions examples/basic/fonts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from vtkplotter import Cube, Text, show, collection
from vtkplotter.settings import fonts

Text("List of available fonts:")

Cube().c('white').rotateX(20).rotateZ(20)

for i, f in enumerate(fonts):
Text(f+': The quick fox jumps over the lazy dog.',
pos=(5,i*40+20), font=f, c=i%3)

show(collection(), axes=False)
15 changes: 8 additions & 7 deletions examples/basic/histo2D.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""
2D histogram with hexagonal binning.
"""
print(__doc__)
from vtkplotter import Plotter, histogram2D, Points, Latex
from vtkplotter import *
import numpy as np

vp = Plotter(axes=1, verbose=0, bg="w")
Expand All @@ -14,12 +13,14 @@
x = np.random.randn(N) * 1.0
y = np.random.randn(N) * 1.5

histo = histogram2D(x, y, c="dr", bins=15, fill=False)
histo = histogram2D(x, y, bins=10, fill=True)

pts = Points([x, y, np.zeros(N)], c="black", alpha=0.1)
pts = Points([x, y, np.zeros(N)+6], c="black", alpha=0.01)

f = r'f(x, y)=A \exp \left(-\left(\frac{\left(x-x_{o}\right)^{2}}{2 \sigma_{x}^{2}}+\frac{\left(y-y_{o}\right)^{2}}{2 \sigma_{y}^{2}}\right)\right)'
f = r'f(x, y)=A \exp \left(-\left(\frac{\left(x-x_{o}\right)^{2}}'
f+= r'{2 \sigma_{x}^{2}}+\frac{\left(y-y_{o}\right)^{2}}'
f+= r'{2 \sigma_{y}^{2}}\right)\right)'

formula = Latex(f, c='k', s=2).rotateZ(90).pos(5,-2,1)
formula = Latex(f, c='k', s=1.5).rotateZ(90).rotateX(90).pos(1,-1,1)

vp.show(histo, pts, formula, viewup="z")
vp.show(histo, pts, formula, Text(__doc__), viewup="z")
10 changes: 10 additions & 0 deletions examples/basic/lightings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from vtkplotter import *

styles = ['default', 'metallic', 'plastic', 'shiny', 'reflective']

a = load(datadir+"beethoven.ply").subdivide()

for i,s in enumerate(styles):
show(a.clone().lighting(s), Text(s), at=i, N=len(styles))

interactive()
6 changes: 3 additions & 3 deletions examples/basic/lights.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
vp = Plotter()

cow = vp.load(datadir+"cow.byu", c="grey", alpha=0.7)

vp.add(Plane(pos=[0, -3.6, 0], normal=[0, 1, 0], sx=20, texture="grass"))
vp.show(viewup='y')

# vp.light() returns a vtkLight object with focal Point, fp, to actor cow
# fp can also be explicitly set as fp=[x,y,z]
l = vp.light(pos=[-6, 6, 6], fp=cow, deg=12, showsource=1)
l = vp.addLight(pos=[-6, 6, 6], focalPoint=cow, deg=12, showsource=1)

# can be switched on/off this way
# l.SwitchOff()
#l.SwitchOff()

vp.show()
23 changes: 7 additions & 16 deletions examples/basic/mesh_modify.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
"""
Modify mesh vertex positions.
(vtkActor transformation matrix is reset when mesh is modified)
"""
from vtkplotter import Plotter, Disc, Text
import numpy as np


vp = Plotter(axes=4, interactive=0)

dsc = Disc()
from vtkplotter import *

dsc = Disc().lineWidth(0.1)
coords = dsc.coordinates()
t = Text(__doc__)

for i in range(50):
noise = np.random.randn(len(coords), 3) * 0.02
noise[:, 0] = 0 # only perturb z
noise[:, 1] = 0
dsc.setPoints(coords + noise) # modify mesh
vp.show(dsc, elevation=-1)

vp.add(Text(__doc__))
coords[:,2] = sin(i/10.*coords[:,0])/2 # move vertices in z
dsc.setPoints(coords) # modify mesh
show(dsc, t, axes=8, resetcam=0, interactive=0)

vp.show(interactive=1)
interactive()
8 changes: 4 additions & 4 deletions examples/basic/shadow.py
Original file line number Diff line number Diff line change
@@ -1,9 +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)
a = load(datadir + "spider.ply")
a.normalize().rotateZ(-90).addShadow(x=-4, alpha=0.5)

shad = Shadow(a, s, direction="x").x(-4)
s = Sphere(pos=[-0.4, 1.4, 0.3], r=0.3).addShadow(x=-4)

show(a, s, shad, Text(__doc__), axes=1, viewup="z", bg="w")
show(a, s, Text(__doc__), axes=1, viewup="z", bg="w")
37 changes: 37 additions & 0 deletions examples/basic/specular.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Setting illumination properties:
ambient, diffuse
specular, specularPower, specularColor.
"""
#https://lorensen.github.io/VTKExamples/site/Python/Rendering/SpecularSpheres
from vtkplotter import Plotter, Text, Arrow, datadir


vp = Plotter(axes=8, bg="w")

ambient, diffuse, specular = 0.1, 0., 0.
specularPower, specularColor= 20, 'white'

for i in range(8):
s = vp.load(datadir+'pumpkin.vtk')#.color(i)
s.normalize().pos((i%4)*2.2, int(i<4)*3, 0)

#s.phong()
#s.gouraud()
s.flat()

# modify the default with specific values
s.lighting('default', ambient, diffuse, specular, specularPower, specularColor)
#ambient += 0.125
diffuse += 0.125
specular += 0.125

vp.add(Text(__doc__))
vp.show()

print('Adding a light source..')
p = (3, 1.5, 3)
f = (3, 1.5, 0)
vp.addLight(pos=p, focalPoint=f)
vp.add(Arrow(p,f, s=0.01, c='gray', alpha=0.2))
vp.show()
7 changes: 5 additions & 2 deletions examples/other/dolfin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@ python example.py # on mac OSX try 'pythonw' instead
| | |
| [![turing_pattern](https://user-images.githubusercontent.com/32848391/56056437-77cfeb00-5d5c-11e9-9887-828e5745d547.gif)](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin/turing_pattern.py)<br/> `turing_pattern.py` | Solve a reaction-diffusion problem on a 2D domain. |
| | |
| [![elasticbeam](https://user-images.githubusercontent.com/32848391/57185890-eecc4f80-6ed4-11e9-866e-ae353735d966.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin/elasticbeam.py)<br/> `elasticbeam.py` | A clamped beam deformed under its own weight. The whole 3D scene is exported and visualized on a [web page](https://vtkplotter.embl.es/examples/fenics_elasticity.html). |

| [![elasticbeam](https://user-images.githubusercontent.com/32848391/57185890-eecc4f80-6ed4-11e9-866e-ae353735d966.png)](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin/elasticbeam.py)<br/> `elasticbeam.py` | A clamped beam deformed under its own weight. The whole 3D scene is exported and visualized on a [web page](https://vtkplotter.embl.es/examples/fenics_elasticity.html). |
| | |
| [![heatconv](https://user-images.githubusercontent.com/32848391/57455107-b200af80-726a-11e9-897d-9c7bcb9854ac.gif)](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin/heatconv.py)<br/> `heatconv.py` | Heat equation in moving media. (by [J. Blechta](https://github.com/blechta/fenics-handson/blob/master/heatconv)).|
| | |
| [![wavy](https://user-images.githubusercontent.com/32848391/57570898-70593b80-7407-11e9-87cf-ce498f499c09.gif)](https://github.com/marcomusy/vtkplotter/blob/master/examples/other/dolfin/wavy_1d.py)<br/> `wavy_1d.py` | 1-dimensional time integration of the wave equation with the Crank-Nicolson method. |
39 changes: 17 additions & 22 deletions examples/other/dolfin/elasticbeam.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,45 @@
"""
A clamped beam deforming
under its own weight.
A beam deforming under its own weight.
"""
from dolfin import *

# Scaled variables
L = 1
W = 0.1
mu = 1
rho = 1
delta = W / L
gamma = 1.2 * delta ** 2
beta = 1.25
lambda_ = beta
g = gamma
l, w = 1, 0.1
mu_, lambda_ = 1, 1
rho = 10
gamma = (w/l)**2
wind = (0, 0.0, 0)

# Create mesh and define function space
mesh = BoxMesh(Point(0, 0, 0), Point(L, W, W), 15, 3, 3)
mesh = BoxMesh(Point(0, 0, 0), Point(l, w, w), 50, 5, 5)
V = VectorFunctionSpace(mesh, "P", 1)

# Define boundary condition
tol = 1e-14
def clamped_boundary(x, on_boundary):
return on_boundary and x[0] < tol
return on_boundary and (near(x[0], 0) or near(x[0], l))
bc = DirichletBC(V, Constant((0, 0, 0)), clamped_boundary)

# Define strain and stress
def epsilon(u):
return 0.5 * (nabla_grad(u) + nabla_grad(u).T)

def sigma(u):
return lambda_ * nabla_grad(u) * Identity(d) + 2 * mu * epsilon(u)
return lambda_ * nabla_grad(u) * Identity(3) + 2 * mu_ * epsilon(u)


# Define variational problem
u = TrialFunction(V)
d = u.geometric_dimension() # space dimension
v = TestFunction(V)
f = Constant((0, 0, -rho * g))
T = Constant((0, 0, 0))
f = Constant((0, 0, -rho * gamma))
T = Constant(wind)
a = inner(sigma(u), epsilon(v)) * dx
L = dot(f, v) * dx + dot(T, v) * ds

# Compute solution
u = Function(V)
solve(a == L, u, bc)

s = sigma(u) - (1.0 / 3) * tr(sigma(u)) * Identity(d) # deviatoric stress
s = sigma(u) - (1.0 / 3) * tr(sigma(u)) * Identity(3) # deviatoric stress
von_Mises = sqrt(3.0 / 2 * inner(s, s))
V = FunctionSpace(mesh, "P", 1)
von_Mises = project(von_Mises, V)
Expand All @@ -60,13 +53,15 @@ def sigma(u):
text=__doc__,
scalarbar=False,
axes=1,
bg='white',
viewup='z')
exportWindow('elasticbeam1.x3d') # generate a html test page
#exportWindow('elasticbeam1.x3d') # generate a html test page

txt = Text("Von Mises stress intensity", pos=(0.1,.12,0), s=0.03, c='white')
plot(von_Mises, txt, cmap='plasma', scalarbar=False, newPlotter=True)
exportWindow('elasticbeam2.x3d')
#exportWindow('elasticbeam2.x3d') # generate a html test page

txt = Text("Magnitude of displacement", pos=(0.1,.12,0), s=0.03, c='white')
plot(u_magnitude, txt, scalarbar=False, newPlotter=True)
exportWindow('elasticbeam3.x3d')
#exportWindow('elasticbeam3.x3d') # generate a html test page

20 changes: 12 additions & 8 deletions examples/other/dolfin/ft07_navier_stokes_channel.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""
Incompressible Navier-Stokes equations
"""Incompressible Navier-Stokes equations
for channel flow (Poisseuille) on the unit square using
the Incremental Pressure Correction Scheme (IPCS).
u' + u . nabla(u)) - div(sigma(u, p)) = f
div(u) = 0
u' + u . nabla(u)) - div(sigma(u, p)) = f
div(u) = 0
"""
from fenics import *

Expand Down Expand Up @@ -110,12 +109,17 @@ def sigma(u, p):

# Plot solution
plot(u_,
cmap='plasma',
scalarbar=False,
bg='w',
cmap='tab10',
lw=0,
isolines={"n": 12, "lw":1, "c":'black', "alpha":0.1},
warpZfactor=0.8,
# scalarbar=False,
bg='white',
text=__doc__,
axes=7, # bottom ruler
axes=7, #bottom ruler
ztitle='',
interactive=False)

print('done.')
plot()

4 changes: 2 additions & 2 deletions examples/other/dolfin/ft08_navier_stokes_cylinder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Incompressible Navier-Stokes equations
for flow around a cylinder using the Incremental Pressure Correction
Scheme (IPCS).
for flow around a cylinder using the
Incremental Pressure Correction Scheme.
u' + u . nabla(u)) - div(sigma(u, p)) = f
div(u) = 0
Expand Down
1 change: 1 addition & 0 deletions examples/other/dolfin/ft09_reaction_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
u_3' + w . nabla(u_3) - div(eps*grad(u_3)) = f_3 + K*u_1*u_2 - K*u_3
"""
from __future__ import print_function
print(__doc__)
from fenics import *
set_log_level(30)
Expand Down
Loading

0 comments on commit 91defa4

Please sign in to comment.