Skip to content

Commit

Permalink
4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Aug 4, 2019
1 parent 9eefe27 commit 953e2d9
Show file tree
Hide file tree
Showing 56 changed files with 1,348 additions and 752 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = []
exclude_patterns = ['../../vtkplotter/docs.py']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
Expand Down
12 changes: 0 additions & 12 deletions examples/basic/ids.py

This file was deleted.

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

cow = vp.load(datadir+"cow.byu", c="grey", alpha=0.7)
vp += Plane(pos=[0, -3.6, 0], normal=[0, 1, 0], sx=20, texture="grass")
vp.show(viewup='y')
vp += Plane(pos=[0, -3.6, 0], normal=[0, 1, 0], sx=20).texture("grass")
vp.show(viewup='y', interactive=0)

# vp.light() returns a vtkLight object with focal Point, fp, to actor cow
# fp can also be explicitly set as fp=[x,y,z]
Expand All @@ -13,4 +13,4 @@
# can be switched on/off this way
#l.SwitchOff()

vp.show()
vp.show(interactive=1)
27 changes: 16 additions & 11 deletions examples/basic/lorenz.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
from vtkplotter import Plotter, mag, Points, Point
import numpy as np


dt = 0.002
y = [25.0, -10.0, -7.0] # Starting point (initial condition)
y = (25.0, -10.0, -7.0) # Starting point (initial condition)
pts, cols = [], []


for t in np.linspace(0, 20, int(20 / dt)):
# Integrate a funny differential equation
dydt = np.array(
[-8 / 3.0 * y[0] + y[1] * y[2], -10.0 * (y[1] - y[2]), -y[1] * y[0] + 28.0 * y[1] - y[2]]
[-8 / 3.0 * y[0] + y[1] * y[2],
-10.0 * (y[1] - y[2]),
-y[1] * y[0] + 28.0 * y[1] - y[2]]
)
y = y + dydt * dt

c = np.clip([mag(dydt) * 0.005], 0, 1)[0] # color by speed
c = np.clip([np.linalg.norm(dydt) * 0.005], 0, 1)[0] # color by speed
cols.append([c, 0, 1-c])
pts.append(y)
cols.append([c, 0, 1 - c])

scene = Plotter(title="Lorenz attractor", axes=2, verbose=0, bg="w")
scene += Point(y, r=20, c="g")
scene += Points(pts, r=5, c=cols)
scene.show()

from vtkplotter import Plotter, Line, Point, Points, settings
settings.renderPointsAsSpheres = False # render points as squares

scene = Plotter(title="Lorenz attractor", axes=1, verbose=0, bg="w")
scene += Point(y, r=10, c="g") # end point
scene += Points(pts, r=3, c=cols)
scene += Line(pts).off().addShadow(x=3) # only show shadow, not line
scene += Line(pts).off().addShadow(z=-30)
scene.show(viewup='z')
4 changes: 2 additions & 2 deletions examples/basic/manypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
RGBA = np.c_[RGB, Alpha] # concatenate

print("clock starts")
t0 = time.clock()
t0 = time.time()

# passing c in format (R,G,B,A) is ~50x faster
pts = Points(pts, r=2, c=RGBA) #fast
#pts = Points(pts, r=2, c=pts, alpha=pts[:, 2]) #slow

t1 = time.clock()
t1 = time.time()
print("----> elapsed time:", t1-t0, "seconds for N:", N)

pts.show(bg="white", axes=True)
8 changes: 5 additions & 3 deletions examples/basic/mesh_bands.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""
Use a scalar to paint colored bands on a mesh,
this can be combined with opacities values for each vertex of the mesh.
Keyword depthpeeling improves the rendering of translucent objects.
useDepthPeeling improves the rendering of translucent objects.
"""
from vtkplotter import show, Hyperboloid, Torus, Text
from vtkplotter import *
from numpy import linspace

settings.useDepthPeeling = True

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


Expand All @@ -18,4 +20,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)
show(hyp, tor, doc, viewup="z", axes=2)
6 changes: 4 additions & 2 deletions examples/basic/mesh_custom.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""
Example on how to specify a color for each
individual cell or point of an actor's mesh.
Keyword depthpeeling may improve the rendering of transparent objects.
useDepthPeeling may improve the rendering of transparent objects.
"""
from vtkplotter import *

settings.useDepthPeeling = True

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


Expand All @@ -28,4 +30,4 @@

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

show(man, doc, viewup="z", axes=1, depthpeeling=1)
show(man, doc, viewup="z", axes=1)
33 changes: 33 additions & 0 deletions examples/basic/slider_browser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Mouse hind limb growth from day 10 9h to day 15 21h
"""
from vtkplotter import *

objs = load(datadir+'timecourse1d.npy') # list of vtkActors

# show the biggest and continue (return a Plotter instance)
vp = show(objs[-1], axes=True, interactive=False)
vp.actors = objs # set Plotter internal list of objs to be shown

# switch off all the others
[objs[i].c('gold').lw(2.0).off() for i in range(1, len(objs))]

k = 0 # visible actor index
def sliderfunc(widget, event):
global k
vp.actors[k].off() #switch off
k = int(widget.GetRepresentation().GetValue())
vp.actors[k].on() #switch on
days = int((k+249)/24)
hours = ' %2sh (' % (k+249 -days*24)
limbage = str(days)+ "d"+ hours + str(k+249)+"h)"
widget.GetRepresentation().SetTitleText(limbage)

vp.addSlider2D(sliderfunc, 0, len(objs)-1,
pos=[(0.4,0.1), (0.9,0.1)], showValue=False)

vp += Text(__doc__, font='SpecialElite', s=1.2)
vp += load(datadir+'images/limbs_tc.jpg').scale(0.0154).y(10.0)
vp += Line([(0,8), (0,10), (28.6,10), (4.5,8)], c='gray')

vp.show(zoom=1.2, interactive=True)
95 changes: 95 additions & 0 deletions examples/notebooks/manipulate_camera.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7811126ce93c494bb80ce84c8003236d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, camera=[4.5, 4.5, 4.5, 0.0, 0.0, 0.0, 1.0, …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from vtkplotter import *\n",
"\n",
"bu = load(datadir+'bunny.obj')\n",
"\n",
"bu.show()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Manually set the k3d camera. Syntax is:\n",
"# [posx,posy,posz, targetx,targety,targetz, upx,upy,upz]\n",
"settings.notebook_plotter.camera = [0., 0. ,1.,\n",
" 0., 0., 0.,\n",
" 0., 1., 0.]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1mk3dcam is [-0.0068 0.044 0.192 -0.017 0.11 0.08 0. 1. 0. ]\u001b[0m\n"
]
}
],
"source": [
"# Convert a vtkCamera object into the appropiate K3D list\n",
"import vtk\n",
"vcam = vtk.vtkCamera()\n",
"vcam.SetPosition( [-0.017, 0.11, 0.48] )\n",
"vcam.SetFocalPoint( [-0.017, 0.11, -0.001] )\n",
"vcam.SetViewUp( [0.0, 1.0, 0.0] )\n",
"vcam.SetDistance( 0.4 )\n",
"k3dcam = vtkCameraToK3D(vcam)\n",
"printc('k3dcam is', k3dcam)\n",
"\n",
"settings.notebook_plotter.camera = k3dcam"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1 change: 1 addition & 0 deletions examples/other/dolfin/demo_cahn-hilliard.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def J(self, A, x): assemble(self.a, tensor=A)
elevation=-3, # move camera a bit
azimuth=1,
text='time: '+str(t*2e4),
lighting='plastic',
interactive=0 )

plot()
28 changes: 25 additions & 3 deletions examples/other/dolfin/demo_submesh.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ba0959304b784ebab287f15f4d2dac67",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, camera=[4.5, 4.5, 4.5, 0.0, 0.0, 0.0, 1.0, …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\"\"\"\n",
"How to extract matching sub meshes from a common mesh.\n",
Expand Down Expand Up @@ -44,6 +59,13 @@
"plot(fluid_mesh)\n",
"plot(structure_mesh, c='tomato', add=True)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -62,7 +84,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down
1 change: 1 addition & 0 deletions examples/other/dolfin/navier-stokes_lshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Solve the incompressible Navier-Stokes equations
on an L-shaped domain using Chorin's splitting method.
"""
from __future__ import print_function
from dolfin import *
from vtkplotter.dolfin import ProgressBar, plot, datadir

Expand Down
4 changes: 2 additions & 2 deletions examples/other/dolfin/noplot/ex05_non-matching-meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
######################################### vtkplotter
from vtkplotter.dolfin import *

s1 = MeshActor(v1).lineWidth(0.5).wire(False)
s3 = MeshActor(v3).lineWidth(0.5).wire(False)
s1 = MeshActor(v1).lineWidth(0.5).wireframe(False)
s3 = MeshActor(v3).lineWidth(0.5).wireframe(False)

show(s1, s3, N=2) # distribute s1 and s3 on 2 synced renderers
9 changes: 5 additions & 4 deletions examples/other/dolfin/stokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
L = inner(f, v)*dx
w = Function(W)

solve(a == L, w, bcs, solver_parameters={'linear_solver' : 'mumps'})
solve(a == L, w, bcs)

# Split the mixed solution using a shallow copy
(u, p) = w.split()
Expand All @@ -45,6 +45,7 @@
f = r'-\nabla \cdot(\nabla u+p I)=f ~\mathrm{in}~\Omega'
formula = Latex(f, pos=(0.55,0.45,-.05), s=0.1)

plot(u, formula, at=0, N=2, text="velocity", mode='mesh and arrows',
scale=.03, wire=1, scalarbar=False, style=1)
plot(p, at=1, text="pressure", cmap='jet')
plot(u, formula, at=0, N=2,
mode='mesh and arrows', scale=.03,
wireframe=True, scalarbar=False, style=1)
plot(p, at=1, text="pressure", cmap='rainbow')
Loading

0 comments on commit 953e2d9

Please sign in to comment.