Skip to content

Commit

Permalink
prerelease
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Jun 18, 2023
1 parent 602fb8c commit 2d245b3
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 163 deletions.
20 changes: 1 addition & 19 deletions docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,13 @@ examples/advanced/timer_callback3.py
examples/advanced/warp6.py
examples/pyplot/histo_1d_e.py
examples/other/tensor_grid2.py
examples/simulations/airplane1.py
examples/simulations/lorenz.py
examples/simulations/gas.py
examples/simulations/aspring2_player.py
```

### Broken Examples
```
airplane1.py
examples/simulations/trail.py
particle_simulator.py
```
align4.py
bgImage.py
colormap_list.py
mousehover3.py
cut_with_points2.py
interpolate_field.py
goniometer.py
pendulum_3d.pyq

graph_lineage.py
graph_network.py
markpoint.py
plot_stream.py

meshio_read.py


Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/cut_with_points2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

line = Line(pts, closed=True).lw(5).c("green3")

show([(mesh, line), (cmesh, line, __doc__)], N=2, axes=1)
show([(mesh, line), (cmesh, line, __doc__)], N=2).close()
24 changes: 9 additions & 15 deletions examples/advanced/interpolate_field.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
"""Interpolate a vectorial field using:
Thin Plate Spline or Radial Basis Function.
Example shows how to share the same Camera
between different Plotter windows.
"""
"""Interpolate a vectorial field using
Thin Plate Spline or Radial Basis Function"""
from scipy.interpolate import Rbf
from vedo import Plotter, Points, Arrows, show
import numpy as np
Expand All @@ -29,15 +24,15 @@

src = Points(sources, c="r", r=12)
trs = Points(sources + deltas, c="v", r=12)
arr = Arrows(sources, sources + deltas)
arr = Arrows(sources, sources + deltas).color("k8")

################################################# warp using Thin Plate Splines
warped = apos.clone().warp(sources, sources+deltas)
warped.alpha(0.4).color("lg").point_size(10)
allarr = Arrows(apos.points(), warped.points())
allarr = Arrows(apos.points(), warped.points()).color("k8")

set1 = [apos, warped, src, trs, arr, __doc__]
plt1 = show([set1, allarr], N=2, bg='bb') # returns the Plotter class
plt1 = show([set1, allarr], N=2, bg='bb', interactive=0) # returns the Plotter class


################################################# RBF
Expand All @@ -54,16 +49,15 @@
positions_rbf = np.vstack([positions_x, positions_y, positions_z])

warped_rbf = Points(positions_rbf, r=2).alpha(0.4).color("lg").point_size(10)
allarr_rbf = Arrows(apos.points(), warped_rbf.points())
allarr_rbf = Arrows(apos.points(), warped_rbf.points()).color("k8")

arr = Arrows(sources, sources + deltas)
arr = Arrows(sources, sources + deltas).color("k8")

plt2 = Plotter(N=2, pos=(200, 300), bg='bb')
plt2.camera = plt1.camera # share the same camera with previous Plotter

plt2.at(0).show("Radial Basis Function", apos, warped_rbf, src, trs, arr)
plt2.at(1).show(allarr_rbf)
plt2.interactive()

plt2.interactive().close()
plt2.close()
plt1.close()

File renamed without changes.
2 changes: 1 addition & 1 deletion examples/pyplot/graph_lineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Vertex generation is automatic,
# add a child to vertex0, so that now vertex1 exists
g.add_child(0, edge_label="Mother giving birth\nto her baby cell")
g.add_child(0, edge_label="Mother cell")
g.add_child(1); g.add_child(1)
g.add_child(2); g.add_child(2); g.add_child(2)
g.add_child(3); g.add_child(3, edge_label="daughter_38")
Expand Down
4 changes: 2 additions & 2 deletions examples/pyplot/graph_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@

# Interpolate the node value to color the edges:
graph.cmap('viridis', v2).add_scalarbar3d(c='k')
graph.scalarbar.shift(.3,0,0)
graph.scalarbar.shift(0.15,0,0).use_bounds(True)
pts.cmap('viridis', v2)

# This would colorize the edges directly with solid color based on a v3 array:
# v3 = [sin(x) for x in range(graph.ncells)]
# graph.cmap('jet', v3).add_scalarbar()

show(pts, graph, labs1, labs2, __doc__, axes=9, mode="image").close()
show(pts, graph, labs1, labs2, __doc__, zoom='tight').close()
4 changes: 2 additions & 2 deletions examples/pyplot/plot_stream.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Plot streamlines of the 2D field:
u(x,y) = -1 - x\^2 + y
v(x,y) = 1 + x - y\^2
u(x,y) = -1 - x:^2 + y
v(x,y) = 1 + x - y:^2
"""
from vedo import Points, show
from vedo.pyplot import streamplot
Expand Down
22 changes: 11 additions & 11 deletions examples/simulations/airplane1.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"""Draw the shadow and trailing line of a flying plane. Not really
a simulation.. just a way to illustrate how to move objects around!"""
"""Draw the shadow and trailing line of a moving object."""
from vedo import *

world = Box(size=(30,15,8)).wireframe()
airplane = Mesh(dataurl+"cessna.vtk").c("green")
airplane.pos(-15, 2.0, 0.15)
airplane.add_trail(n=100).add_shadow('z', -4)

plt = Plotter(axes=1, interactive=False)
plt = Plotter(interactive=False)
plt.show(world, airplane, __doc__, viewup="z")

for t in np.arange(0, 3.2, 0.02):

# make up some movement
airplane.pos(9*t-15, 2-t, sin(3-t)).rotate_x(t)
if t==0:
airplane.add_trail(n=200).add_shadow('z', -4)
plt.show(world, airplane, __doc__, viewup="z", resetcam=False)
# plt.process_events()
for t in np.arange(0, 3.2, 0.04):
pos = (9*t-15, 2-t, sin(3-t)) # make up some movement
airplane.pos(pos).rotate_x(t)
airplane.update_trail()
airplane.update_shadows()
plt.render()

plt.interactive().close()

13 changes: 8 additions & 5 deletions examples/simulations/airplane2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
world = Box([0,0,0], 30, 16, 8).wireframe()

plane1 = Mesh(dataurl+"cessna.vtk").c("green")
plane1.pos(-15, 2, 0.14).add_trail(n=200)
plane1.pos(-15, 2, 0.15).add_trail(n=100)
plane1.add_shadow('z', -4).add_shadow('y', 8)

plane2 = plane1.clone().c("tomato")
plane2.pos(-15,-2,-0.21).add_trail(n=200)
plane2.pos(-15,-2,-0.20).add_trail(n=100)
plane2.add_shadow('z', -4).add_shadow('y', 8)

# Setup the scene
plt = Plotter(axes=1, interactive=False)
plt = Plotter(interactive=False)
plt.show(world, plane1, plane2, __doc__, viewup="z")

for t in np.arange(0, 3.2, 0.02):
for t in np.arange(0, 3.2, 0.04):
plane1.pos(9*t-15, 2-t, sin(3-t)).rotate_x(0+t) # make up some movement
plane2.pos(8*t-15, t-2, sin(t-3)).rotate_x(2-t) # for the 2 planes
plt.show(world, plane1, plane2, __doc__, viewup="z")
plane1.update_trail().update_shadows()
plane2.update_trail().update_shadows()
plt.render()

plt.interactive().close()
10 changes: 7 additions & 3 deletions examples/simulations/particle_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ def simulate(self):
a.vel += ftot / a.mass * self.dt # update velocity and position of a
a.pos += a.vel * self.dt
a.vsphere.pos(a.pos)
if plt:
plt.show(resetcam=not i, azimuth=1)
a.vsphere.update_trail()
if plt:
if i==0:
plt.reset_camera()
plt.azimuth(1)
plt.render()


class Particle:
Expand All @@ -86,7 +90,7 @@ def __init__(self, pos, charge, mass, radius, color, vel, fixed, negligible):
self.negligible = negligible
self.color = color
if plt:
self.vsphere = Sphere(pos, r=radius, c=color).add_trail(lw=0.1, n=100, alpha=0.2)
self.vsphere = Sphere(pos, r=radius, c=color).add_trail(lw=1, n=75, alpha=0.5)
plt.add(self.vsphere) # Sphere representing the particle


Expand Down
17 changes: 10 additions & 7 deletions examples/simulations/pendulum_3d.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Double pendulum in 3D (press ESC to quit)"""
"""Double pendulum in 3D"""
# Original idea and solution using sympy from:
# https://www.youtube.com/watch?v=MtG9cueB548
from vedo import *
Expand All @@ -13,8 +13,8 @@
ball1.add_shadow('z', -3)
ball2.add_shadow('z', -3)

ball1.add_trail(n=20)
ball2.add_trail(n=20)
ball1.add_trail(n=10)
ball2.add_trail(n=10)
ball1.trail.add_shadow('z', -3) # make trails project a shadow too
ball2.trail.add_shadow('z', -3)

Expand All @@ -25,18 +25,21 @@

# show the solution
plt = Plotter(interactive=False)
plt.show(axes, __doc__, viewup='z')
plt.show(ball1, ball2, rod1, rod2, axes, __doc__, viewup='z')

i = 0
for b1, b2 in zip(p1,p2):
ball1.pos(b1)
ball2.pos(b2)
rod1.stretch([0,0,0], b1)
rod2.stretch(b1, b2)
# show at max frame rate of 15 Hz
plt.show(ball1, ball2, rod1, rod2, resetcam=False, rate=15)
ball1.update_shadows().update_trail()
ball2.update_shadows().update_trail()
ball1.trail.update_shadows()
ball2.trail.update_shadows()
plt.render()
i+=1
if i > 50:
if i > 150:
break

plt.interactive().close()
2 changes: 1 addition & 1 deletion examples/simulations/trail.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
plt += [s, p, __doc__]

for i in range(150):
p.pos(-2+i/100.0, sin(i/5.0)/15, 0)
p.pos(-2+i/100.0, sin(i/5.0)/15, 0).update_trail()
plt.show(azimuth=-0.2)

# stay interactive and after pressing q close
Expand Down
22 changes: 19 additions & 3 deletions vedo/addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -3926,7 +3926,7 @@ def Axes(
return asse


def add_global_axes(axtype=None, c=None):
def add_global_axes(axtype=None, c=None, bounds=()):
"""
Draw axes on scene. Available axes types are
Expand Down Expand Up @@ -3993,15 +3993,31 @@ def add_global_axes(axtype=None, c=None):
# custom grid walls
if plt.axes == 1 or plt.axes is True or isinstance(plt.axes, dict):

if len(bounds) == 6:
bnds = bounds
xrange = (bnds[0], bnds[1])
yrange = (bnds[2], bnds[3])
zrange = (bnds[4], bnds[5])
else:
xrange=None
yrange=None
zrange=None

if isinstance(plt.axes, dict):
plt.axes.update({"use_global": True})
# protect from invalid camelCase options from vedo<=2.3
for k in plt.axes:
if k.lower() != k:
return
asse = Axes(None, **plt.axes)
if "xrange" in plt.axes:
xrange = plt.axes.pop("xrange")
if "yrange" in plt.axes:
yrange = plt.axes.pop("yrange")
if "zrange" in plt.axes:
zrange = plt.axes.pop("zrange")
asse = Axes(**plt.axes, xrange=xrange, yrange=yrange, zrange=zrange)
else:
asse = Axes(None, use_global=True)
asse = Axes(xrange=xrange, yrange=yrange, zrange=zrange)

plt.renderer.AddActor(asse)
plt.axes_instances[r] = asse
Expand Down
Loading

0 comments on commit 2d245b3

Please sign in to comment.