Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Mar 16, 2021
1 parent ed67abb commit bd7c79d
Show file tree
Hide file tree
Showing 50 changed files with 303 additions and 2,213 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ notebooks/.ipynb_checkpoints/
docs/build/
docs/source/content
docs/source/index.rst

untitled*.py
bug_*.py
prove
speed_tester.py
data

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Type `vedo -h` for the complete list of options.<br>
| [![cubecut](https://user-images.githubusercontent.com/32848391/99916179-e763d580-2d08-11eb-9044-b647115167ed.jpg)](https://github.com/marcomusy/vedo/tree/master/examples/advanced/cutWithMesh2.py) | [![greyscott](https://user-images.githubusercontent.com/32848391/80291855-87e11f80-8751-11ea-9428-12e193a2a66e.gif)](https://github.com/marcomusy/vedo/tree/master/examples/simulations/grayscott.py)| [![quatumsine](https://user-images.githubusercontent.com/32848391/47751431-06aae880-dc92-11e8-9fcf-6659123edbfa.gif)](https://github.com/marcomusy/vedo/tree/master/examples/simulations/tunnelling2.py) |
| *Easily work with volumes, tetrahedral and polygonal meshes.* | *Turing system of reaction-diffusion between two molecules.* | *Quantum-tunnelling of a particle in a box hitting a sinusoidal potential.* |
| [![trimesh](https://user-images.githubusercontent.com/32848391/91164151-e8b44080-e6ce-11ea-8213-cf5b12aa4d16.png)](https://github.com/marcomusy/vedo/blob/master/examples/other/trimesh) | [![dolf](https://user-images.githubusercontent.com/32848391/58368591-8b3fab80-7eef-11e9-882f-8b8eaef43567.gif)](https://vedo.embl.es/content/vedo/dolfin.html)| [![whisker](https://user-images.githubusercontent.com/32848391/99916183-e8950280-2d08-11eb-8070-8bb1146c7c62.png)](https://github.com/marcomusy/vedo/tree/master/examples/pyplot/whiskers.py) |
| *Interoperability with external libraries like [trimesh](https://trimsh.org/), [pymeshlab](https://github.com/cnr-isti-vclab/PyMeshLab).* | *Support for the [FEniCS/Dolfin](https://fenicsproject.org/) library for PDE and finite element solutions.* | *Advanced 2D/3D histogramming and plotting capablities.* |
| *Interoperability with external libraries like [trimesh](https://trimsh.org/), [pymeshlab](https://github.com/cnr-isti-vclab/PyMeshLab), and [pyvista](https://github.com/pyvista/pyvista).* | *Support for the [FEniCS/Dolfin](https://fenicsproject.org/) library for PDE and finite element solutions.* | *Advanced 2D/3D histogramming and plotting capablities.* |


### Galleries
Expand Down
5 changes: 4 additions & 1 deletion docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Added interfaces and examples to libraries [iminuit](https://github.com/scikit-hep/iminuit)
and [pymeshlab](https://github.com/cnr-isti-vclab/PyMeshLab)
- variable `datadir` changed to `dataurl`
- added `ipyvtk_simple` for notebooks


---
Expand Down Expand Up @@ -59,7 +60,7 @@ Lower index means darker.
### `picture.py`
- attribute `picture.shape` holds the shape of the picture in pixels
- added `gif` file reader to return a list of `Picture` objs.

- added `clone()` method.

---
### `pointcloud.py`
Expand Down Expand Up @@ -123,7 +124,9 @@ Lower index means darker.
- `vedo -r fitPolynomial1`
- `vedo -r fitPolynomial2`
- `vedo -r histo_gauss`
- `vedo -r plot_polar`
- `vedo -r densifycloud`
- `vedo -r interpolateVolume`



Expand Down
20 changes: 10 additions & 10 deletions examples/advanced/mesh_smoother1.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
"""Mesh smoothing with two different methods"""
from vedo import Plotter, dataurl

vp = Plotter(N=3)
plt = Plotter(N=3)

# Load a mesh and show it
vol = vp.load(dataurl+"embryo.tif")
vol = plt.load(dataurl+"embryo.tif")
m0 = vol.isosurface().normalize().lw(0.1).c("violet")
vp.show(m0, __doc__, at=0)
plt.show(m0, __doc__+"\nOriginal Mesh:", at=0)

# Adjust mesh using Laplacian smoothing
m1 = m0.clone().smoothLaplacian(niter=20, relaxfact=0.1, edgeAngle=15, featureAngle=60)
m1.color("pink").legend("laplacian")
vp.show(m1, at=1)
m1.color("pink")
plt.show(m1, "Laplacian smoothing", at=1, viewup='z')

# Adjust mesh using a windowed sinc function interpolation kernel
m2 = m0.clone().smoothWSinc(niter=15, passBand=0.1, edgeAngle=15, featureAngle=60)
m2.color("lg").legend("window sinc")
vp.show(m2, at=2)
m2 = m0.clone().smoothWSinc(niter=20, passBand=0.1, edgeAngle=15, featureAngle=60)
m2.color("lg")
plt.show(m2, "WindowSinc smoothing", at=2)

vp.backgroundColor([0.8, 1, 1], at=0) # set first renderer color
plt.backgroundColor([0.8, 1, 1], at=0) # set first renderer color

vp.show(zoom=1.4, interactive=True)
plt.show(zoom=1.4, interactive=True)
15 changes: 11 additions & 4 deletions examples/basic/mousehighlight.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
"""Click a sphere to highlight it"""
from vedo import Sphere, Plotter
from vedo import Text2D, Sphere, Plotter
import numpy as np

pts = np.random.rand(30,2)*20
spheres = [Sphere().pos(p).color('k5') for p in pts]
spheres = []
for i in range(25):
p = np.random.rand(2)
s = Sphere(r=0.05).pos(p).color('k5')
s.name = f"sphere nr.{i} at {p}"
spheres.append(s)

def func(evt):
if not evt.actor: return
sil = evt.actor.silhouette().lineWidth(6).c('red5')
msg.text("You clicked: "+evt.actor.name)
plt.remove(silcont.pop()).add(sil)
silcont.append(sil)

silcont = [None]
msg = Text2D("", pos="bottom-center", c='k', bg='r9', alpha=0.8)

plt = Plotter(axes=1, bg='black')
plt.addCallback('mouse click', func)
plt.show(spheres, __doc__, zoom=1.2)
plt.show(spheres, msg, __doc__, zoom=1.2)
29 changes: 16 additions & 13 deletions examples/basic/mousehover.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
"""Visualize scalar values interactively
by hovering the mouse on a mesh
Press c to clear"""
Press c to clear the path"""
from vedo import *

def func(evt): ### called every time the mouse moves!
if not evt.actor: return # no hits, return. (NB: evt is a dictionary)
pt = evt.picked3d # 3d coords of picked point under mouse
def func(evt): ### called every time the mouse moves!
if not evt.actor: return # no hits, return. (NB: evt is a dictionary)
pt = evt.picked3d # 3d coords of picked point under mouse

pid = evt.actor.closestPoint(pt, returnPointId=True)
txt = f"Point: {precision(pt[:2],2)}\n" \
f"Height: {precision(arr[pid],3)}\n"\
txt = f"Point: {precision(pt[:2] ,2)}\n" \
f"Height: {precision(arr[pid],3)}\n" \
f"Ground speed: {precision(evt.speed3d*100,2)}"
arw = Arrow(pt - evt.delta3d, pt, s=0.001, c='orange5')
vig = evt.actor.vignette(txt, point=pt, offset=(0.4,0.6),
s=0.04, c='k', font="VictorMono").followCamera()
msg = Text2D(txt, pos='bottom-left', font="VictorMono")
if len(plt.actors) > 3:
plt.remove(plt.actors[-2:]) # remove the old vig and msg
plt.add([arw, vig, msg]) # add Arrow and the new vig and msg
msg.text(txt) # update text message
if len(plt.actors)>3:
plt.pop() # remove the old vignette
plt.add([arw, vig]) # add Arrow and the new vig

hil = ParametricShape('RandomHills').cmap('terrain').addScalarBar()
arr = hil.getPointArray("Scalars")

plt = Plotter(axes=1, bg2='lightblue')
plt.addCallback('MouseMove', func) # the callback function
plt.addCallback('KeyPress', lambda e: plt.remove(plt.actors[2:], render=True))
plt.show(hil, __doc__, viewup='z')
plt.addCallback('mouse moving', func) # the callback function
plt.addCallback('keyboard', lambda e: plt.remove(plt.actors[3:], render=True))

msg = Text2D("", pos='bottom-left', font="VictorMono")

plt.show(hil, msg, __doc__, viewup='z')
22 changes: 12 additions & 10 deletions examples/basic/rotateImage.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
"""Normal jpg/png pictures can be loaded,
cropped, rotated and positioned in 3D
"""
from vedo import Plotter, dataurl
cropped, rotated and positioned in 3D."""
from vedo import Plotter, Picture, dataurl

vp = Plotter(axes=3)
plt = Plotter(axes=7)

pic = Picture(dataurl+"images/dog.jpg")

for i in range(5):
p = vp.load(dataurl+"images/dog.jpg") # returns Picture
p.crop(bottom=0.2) # crop 20%
p.scale(1-i/10.0).alpha(0.8) # picture can be scaled in size
p.rotateX(20*i).pos(0,0,30*i) # (can concatenate methods)
p = pic.clone()
p.crop(bottom=0.20) # crop 20% from bottom
p.scale(1-i/10.0).rotateX(20*i).z(30*i)
p.alpha(0.8)
plt += p

vp += __doc__
vp.show()
plt += __doc__
plt.show()
12 changes: 7 additions & 5 deletions examples/notebooks/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Jupyter Notebooks

Here you will find a set of notebooks.
It allows to embed a redering window into a jupyter notebook via
Here you will find a set of notebooks.
It allows to embed a redering window into a jupyter notebook via
[K3D](https://github.com/K3D-tools/K3D-jupyter)
(or optionally with `itkwidgets` or [panel](https://github.com/pyviz/panel)).
(or optionally with `itkwidgets`, `ipyvtk` or [panel](https://github.com/pyviz/panel)).

On top of this `K3D` allows to export an interactive
[snapshot](https://vedo.embl.es/examples/K3D_snapshot.html)
of the rendered scene.

`jupyter notebook examples/notebooks/basic/embryo.ipynb`
### note that notebook support (except for `ipyvtk`) is rather limited and not all functionalities are available, in particular:

![embed](https://user-images.githubusercontent.com/32848391/58486800-d6172880-8166-11e9-9a43-ed20b8fed19c.jpg)
- axes are very basic
- text2d is not available
- limited possibilities for scene interaction
13 changes: 4 additions & 9 deletions examples/notebooks/basic/align1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"\"\"\"\n",
Expand All @@ -14,7 +16,7 @@
"\"\"\"\n",
"from vedo import *\n",
"\n",
"embedWindow('k3d') # or panel, k3d, itk, ipyvtk, or False\n",
"embedWindow(\"k3d\") # or panel, k3d, itk, ipyvtk, or False\n",
"\n",
"plt = Plotter()\n",
"\n",
Expand All @@ -34,13 +36,6 @@
"printc([arim.getTransform()], invert=True)\n",
"plt.show(axes=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
26 changes: 2 additions & 24 deletions examples/notebooks/basic/align2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,9 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0a54c302d3a04861854eea7ad62f5bc1",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Plot(antialias=3, axes=['x', 'y', 'z'], axes_helper=1.0, background_color=16777215, camera=[2, -3, 0.2, 0.0, 0…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"\"\"\"Example usage of align() method:\n",
"generate two random sets of points and align them using\n",
Expand Down Expand Up @@ -54,13 +39,6 @@
"vp.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
79 changes: 10 additions & 69 deletions examples/notebooks/basic/sphere.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,98 +2,39 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1c3612b7f22e457685d803362ca4b53a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"ViewInteractiveWidget(height=960, layout=Layout(height='auto', width='100%'), width=960)"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"from vedo import *\n",
"\n",
"embedWindow('ipyvtk') #uncomment to pop an ext. window\n",
"\n",
"embedWindow('ipyvtk') \n",
"\n",
"s = Sphere().cutWithPlane(normal=(1,1,1))\n",
"scals = s.points()[:,2] # use z-coords to color vertices\n",
"\n",
"# NB, actions can be concatenated into a pipeline:\n",
"# add point scalars with a choice of color map, use flat shading, print infos and then show\n",
"s.cmap('Set3', scals)\n",
"plt = s.show(axes=1, viewup='z')\n",
"plt"
"s.show(axes=1, viewup='z')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<vedo.plotter.Plotter at 0x7eff901428d0>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"closeWindow()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<vedo.plotter.Plotter at 0x7f6c4cba9790>"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"settings.plotter_instance.backgroundColor('g','y')"
"settings.plotter_instance.backgroundColor('lg','lb')"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<vedo.plotter.Plotter at 0x7f6c4cba9790>"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"settings.plotter_instance.add(\"gggg\")"
"settings.plotter_instance.add(\"some message\")"
]
},
{
Expand Down
Loading

0 comments on commit bd7c79d

Please sign in to comment.