Skip to content

Commit

Permalink
4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Nov 23, 2020
1 parent 867dc3b commit e91430c
Show file tree
Hide file tree
Showing 32 changed files with 1,944 additions and 1,588 deletions.
50 changes: 31 additions & 19 deletions README.md

Large diffs are not rendered by default.

File renamed without changes.
21 changes: 21 additions & 0 deletions examples/advanced/cutWithMesh2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Cut a cube with a surface
to create a 'capping' mesh"""
from vedo import *
import numpy as np


# Equation of the "gyroid" (https://en.wikipedia.org/wiki/Gyroid)
x, y, z = np.mgrid[:30,:30,:30] * 0.4
U = sin(x)*cos(y) + sin(y)*cos(z) + sin(z)*cos(x)

# Create a Volume, take the isosurface at 0, smooth it and set mesh edges
s = Volume(U).isosurface(0).smoothLaplacian().lineWidth(1)

# Create a gridded cube
c = CubicGrid(n=(29,29,29), spacing=(1,1,1)).alpha(1)

s.cutWithMesh(c).color('silver') # take what's inside of cube
c.cutWithMesh(s).color('grey') # take what's inside of isosurface

# Show all the created objects
show(s, c, __doc__, bg='darkseagreen', bg2='lightblue', axes=5)
2 changes: 1 addition & 1 deletion examples/advanced/multi_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def onLeftClick(mesh):
pos='bottom-left', c=ishape.color(), bg='k', font='Calco')
instt = Text2D(instr, pos='bottom-right', c='dg', bg='g', font='Quikhand')

axes = addons.buildAxes(ishape, yzGrid=False)
axes = ishape.buildAxes(yzGrid=False)
acts = [ishape, axes, sname, sprop, instt]

plt1.backgroundColor('silver')
Expand Down
6 changes: 3 additions & 3 deletions examples/advanced/splitmesh.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Split a mesh by connectivity and
order the pieces by increasing area.
order the pieces by increasing area
"""
from vedo import *

em = load(datadir+"embryo.tif").isosurface(80)
em = Volume(datadir+"embryo.tif").isosurface(80)

# return the list of the largest 10 connected meshes:
splitem = em.splitByConnectivity(maxdepth=40)[0:9]

show( [(em, __doc__), splitem], N=2, axes=1 )
show(splitem, __doc__, axes=1, viewup='z')
34 changes: 23 additions & 11 deletions examples/basic/lights.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
from vedo import Plotter, Plane, datadir
"""Set custom lights to a 3D scene"""
from vedo import Plotter, load, datadir, Point, Light, show

vp = Plotter()
man = load(datadir+'man.vtk').c('white').lighting('glossy')

cow = vp.load(datadir+"cow.vtk").c("grey").scale(4).rotateX(-90)
vp += Plane(pos=[0, -3.6, 0], normal=[0, 1, 0], sx=20).texture("grass")
vp.show(viewup='y', interactive=0)
p1 = Point([1,0,1], c='y')
p2 = Point([0,0,2], c='r')
p3 = Point([-1,-0.5,-1], c='b')
p4 = Point([0,1,0], c='k')

# vp.light() returns a vtkLight object with focal Point, fp, to mesh cow
# fp can also be explicitly set as fp=[x,y,z]
l = vp.addLight(pos=[-6, 6, 6], focalPoint=cow, deg=12, showsource=1)
# Add light sources at the given positions
l1 = Light(p1, c='y') # p1 can simply be [1,0,1]
l2 = Light(p2, c='r')
l3 = Light(p3, c='b')
l4 = Light(p4, c='w', intensity=0.5)

# can be switched on/off this way
#l.SwitchOff()
show(man, l1, l2, l3, l4, p1, p2, p3, p4,
__doc__, axes=1, viewup='z')

vp.show(interactive=1)


#####################################################
##### Equivalent code using a Plotter instance: #####
#####################################################
# plt = Plotter(axes=1)
# plt += [man, p1, p2, p3, p4, l1, l2, l3, l4]
# plt.show(viewup='z')
#####################################################
5 changes: 2 additions & 3 deletions examples/basic/specular.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
specular, specularPower, specularColor.
"""
#https://lorensen.github.io/VTKExamples/site/Python/Rendering/SpecularSpheres
from vedo import Plotter, Arrow, datadir
from vedo import Plotter, Arrow, Light, datadir


vp = Plotter(axes=1)
Expand All @@ -30,6 +30,5 @@
print('Adding a light source..')
p = (3, 1.5, 3)
f = (3, 1.5, 0)
vp.addLight(pos=p, focalPoint=f)
vp += Arrow(p,f, s=0.01, c='gray', alpha=0.2)
vp += [Arrow(p,f, s=0.01, c='gray', alpha=0.2), Light(pos=p, focalPoint=f)]
vp.show()
10 changes: 0 additions & 10 deletions examples/notebooks/notebooks_index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"- <a href='advanced/gray_scott.ipynb' target='_blank'>advanced/gray_scott.ipynb</a>\n",
"- <a href='advanced/sierpinski.ipynb' target='_blank'>advanced/sierpinski.ipynb</a>\n",
"- <a href='advanced/thinplate_grid.ipynb' target='_blank'>advanced/thinplate_grid.ipynb</a>\n",
"- <a href='advanced/value-iteration.ipynb' target='_blank'>advanced/value-iteration.ipynb</a>\n",
"- <a href='advanced/volterra.ipynb' target='_blank'>advanced/volterra.ipynb</a>\n",
"- <a href='basic/align1.ipynb' target='_blank'>basic/align1.ipynb</a>\n",
"- <a href='basic/align2.ipynb' target='_blank'>basic/align2.ipynb</a>\n",
Expand All @@ -31,9 +30,7 @@
"- <a href='basic/distance2mesh.ipynb' target='_blank'>basic/distance2mesh.ipynb</a>\n",
"- <a href='basic/manipulate_camera.ipynb' target='_blank'>basic/manipulate_camera.ipynb</a>\n",
"- <a href='basic/mirror.ipynb' target='_blank'>basic/mirror.ipynb</a>\n",
"- <a href='basic/noname.ipynb' target='_blank'>basic/noname.ipynb</a>\n",
"- <a href='basic/pca.ipynb' target='_blank'>basic/pca.ipynb</a>\n",
"- <a href='basic/shadow.ipynb' target='_blank'>basic/shadow.ipynb</a>\n",
"- <a href='basic/shrink.ipynb' target='_blank'>basic/shrink.ipynb</a>\n",
"- <a href='basic/sphere.ipynb' target='_blank'>basic/sphere.ipynb</a>\n",
"- <a href='dolfin/demo_cahn-hilliard.ipynb' target='_blank'>dolfin/demo_cahn-hilliard.ipynb</a>\n",
Expand Down Expand Up @@ -92,13 +89,6 @@
"Markdown(l1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
8 changes: 4 additions & 4 deletions examples/other/makeVideo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
Make a video (needs ffmpeg or opencv)
Set offscreen=True to only produce the video
without any graphical window showing
without any graphic window showing
"""
print(__doc__)
from vedo import *

# settings.screeshotScale = 2 # to get higher resolution
# settings.screeshotScale = 2 # to get higher resolution

# declare the class instance
vp = Plotter(bg='beige', axes=10, offscreen=True)
Expand All @@ -26,6 +26,6 @@
#Options are: elevation_range=(0,80),
# azimuth_range=(0,359),
# zoom=None,
# cam1=None, cam2=None # initial and final camera positions
# cam1=None, cam2=None # initial and final camera positions

video.close() # merge all the recorded frames
video.close() # merge all the recorded frames
2 changes: 1 addition & 1 deletion examples/other/nevergrad_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def callbk(optimizer, v, value):
res = optimizer.minimize(func) # best value
printc('Minimum at:', res.value)

ln = Line(pts, lw=3)
ln = Line(pts, lw=3, c='r')
fu = plot(f, xlim=[-3,4], ylim=[-3,4], alpha=0.5)

show(fu, ln, __doc__)
35 changes: 35 additions & 0 deletions examples/pyplot/plot_density4d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Plot a volume evolution in time
# Credits: https://github.com/edmontz
import numpy as np
from scipy.fftpack import fftn, fftshift
from vedo import Volume, ProgressBar, show, interactive

def f(x, y, z, t):
r = np.sqrt(x*x + y*y + z*z + 2*t*t) + 0.1
return np.sin(9*np.pi * r)/r

n = 64
qn = 50
vol = np.zeros((n, n, n))
n1 = int(n/2)

pb = ProgressBar(0, qn, c="r")
for q in pb.range():
pb.print()

t = 2 * q / qn - 1
for k in range(n1):
z = 2 * k / n1 - 1
for j in range(n1):
y = 2 * j / n1 - 1
for i in range(n1):
x = 2 * i / n1 - 1
vol[i, j, k] = f(x, y, z, t)
volf = fftn(vol)
volf = fftshift(abs(volf))
volf = np.log(12*volf/volf.max()+ 1) / 2.5

vb = Volume(volf).mode(1).c("rainbow").alpha([0, 0.8, 1])
show(vb, bg="black", axes=1, viewup='z', interactive=False)

interactive()
26 changes: 12 additions & 14 deletions examples/pyplot/scatter3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,28 @@
from vedo import *
from numpy.random import randn


### first scatter plot in blue
### first cloud in blue, place it at z=0:
x = randn(2000) * 3
y = randn(2000) * 2

# scatter cloud, place it at z=0:
pts1 = Points([x,y], c="blue", alpha=0.5).z(0.0)
bra1 = Brace([-7,-7], [7,-7], thickness=0.75,
comment='whole population', s=0.5, c='b')


### second scatter plot in red
### second cloud in red
x = randn(1200) + 4
y = randn(1200) + 2
pts2 = Points([x,y], c="red", alpha=0.5).z(0.1)
bra2 = Brace([8,2], [6,5], comment='red zone', c='r').z(0.3)


### third scatter plot with marker in black
### third cloud with a black marker
x = randn(20) + 4
y = randn(20) - 4
mark = Marker('*', s=0.2, filled=True)
mark = Marker('*', s=0.25)
pts3 = Glyph([x,y], mark, c='k').z(0.2)
bra3 = Brace([8,-6], [8,-2], comment='my stars').z(0.3)

# some text message
msg = Text("preliminary\nresults!", font='Quikhand', s=1.5)
msg.c('black').rotateZ(20).pos(-10,3,.2)

label = Text("preliminary\nresults!", font='Quikhand', s=1.5, pos=(-8,4,.2))
label.c('black').rotateZ(20)

show(pts1, pts2, pts3, label, __doc__,
title='A simple scatter plot', axes=1, viewup='2d')
show(pts1, pts2, pts3, msg, bra1, bra2, bra3, __doc__, axes=1, zoom=1.2)
43 changes: 27 additions & 16 deletions examples/pyplot/whiskers.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
"""Whisker plot with quantiles indication
(horizontal line shows the mean value)"""
from vedo import Axes, Brace, Line, Ribbon, show
from vedo.pyplot import whisker
from vedo import show, buildAxes
import numpy as np

# create 5 whisker bars with some random data
ws = []
for i in range(5):
xval = i*2
data = np.random.randn(25) + i/2
xval = i*2 # position along x axis
data = xval/4 + np.random.randn(25)
w = whisker(data, bc=i, s=0.5).x(xval)
ws.append(w)
# print(i, 'whisker:\n', w.info)

# build some theoretical expectation to be shown as a grey band
x = np.linspace(-1, 9, 100)
y = x/5 + 0.2*np.sin(x)
ye= y**2/5 + 0.1 # error on y
line = Line(np.c_[x, y])
band = Ribbon(np.c_[x, y-ye], np.c_[x, y+ye]).c('black').alpha(0.1)

# build braces to inndicate stats significance and dosage
bra1 = Brace([0, 3],[2, 3], comment='*~*', s=0.7, style='[')
bra2 = Brace([4,-1],[8,-1], comment='dose > 3~\mug/kg', s=0.7)

# build custom axes
ax = buildAxes(xrange=[-1,9],
yrange=[-3,5],
htitle='\beta_c -expression: change in time',
xtitle=' ',
ytitle='Level of \beta_c protein in \muM/l',
xValuesAndLabels=[(0,'experiment^A\nat t=1h'),
(4,'experiment^B\nat t=2h'),
(8,'experiment^C\nat t=4h'),
],
xLabelSize=0.02,
)
axes = Axes(xrange=[-1,9],
yrange=[-3,5],
htitle='\beta_c -expression: change in time',
xtitle=' ',
ytitle='Level of \beta_c protein in \muM/l',
xValuesAndLabels=[(0,'Experiment^A\nat t=1h'),
(4,'Experiment^B\nat t=2h'),
(8,'Experiment^C\nat t=4h'),
],
xLabelSize=0.02,
)

show(ws, ax, __doc__)
# print('whisker0:', ws[0].info)
show(ws, bra1, bra2, line, band, __doc__, axes, zoom=1.1)


Loading

0 comments on commit e91430c

Please sign in to comment.