Skip to content

Commit

Permalink
adjust volume transfer function
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Nov 29, 2024
1 parent f7ababf commit 66406c9
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 39 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,22 @@ Check out the example galleries organized by subject here:
## ✏ Contributing

Any contributions are **greatly appreciated**!
If you have a suggestion that would make this better, please fork the repo and create a pull request.
If you have a suggestion that would make this better,
please fork the repo and create a pull request. This is how:
```bash
# 1. Fork the repository on GitHub then clone your fork locally:
git clone https://github.com/your-username/vedo.git
# 2. Create a new branch for your feature or bugfix:
git checkout -b feature/my-feature
# 3. Make your changes and commit them:
git commit -m "Description of my feature"
# 4. Push your changes to your fork:
git push origin feature/my-feature
# 5. Open a Pull Request on the main repository.
```
You can also simply open an issue with the tag "enhancement".



## 📜 References

**Scientific publications leveraging `vedo`:**
Expand Down
10 changes: 10 additions & 0 deletions docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
- changes in the scalarbar2d object.
- fix purging of nan in pyplot.plot()
- fix line trace to skip first point
- adjust volume transfer function for transparency @Poisoned



## Soft-breaking Changes
Expand Down Expand Up @@ -84,3 +86,11 @@ mesh_map2cell.py
texturecubes.py
meshquality.py
streamlines1.py

#### volume alphas look bad
erode_dilate.py
euclidian_dist.py
numpy2volume0.py
numpy_imread.py
slab_vol.py
warp_scalars.py
32 changes: 16 additions & 16 deletions tests/common/test_core1.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@
###################################### shift
cone.pos(5,6,7).shift(3,0,0)
print('shift',[8,6,7], cone.pos())
assert np.allclose([8,6,7], cone.pos())
assert np.allclose([8,6,7], cone.pos(), atol=0.001)


###################################### x y z
cone.pos(10,11,12)
cone.x(1.1)
print('x y z',[1.1,11,12], cone.pos())
assert np.allclose([1.1,11,12], cone.pos())
assert np.allclose([1.1,11,12], cone.pos(), atol=0.001)
cone.y(1.2)
print('x y z',[1.1,1.2,12], cone.pos())
assert np.allclose([1.1,1.2,12], cone.pos())
assert np.allclose([1.1,1.2,12], cone.pos(), atol=0.001)
cone.z(1.3)
print('x y z',[1.1,1.2,1.3], cone.pos())
assert np.allclose([1.1,1.2,1.3], cone.pos())
assert np.allclose([1.1,1.2,1.3], cone.pos(), atol=0.001)


###################################### rotate
Expand Down Expand Up @@ -160,7 +160,7 @@
s2.vertices = pts2
pts3 = s2.vertices
print('vertices',sum(pts3-pts2))
assert np.allclose(pts2, pts3)
assert np.allclose(pts2, pts3, atol=0.001)


###################################### cells
Expand Down Expand Up @@ -220,7 +220,7 @@
assert 3.3 < sphere.diagonal_size() < 3.5

print('center_of_mass',sphere.center_of_mass())
assert np.allclose(sphere.center_of_mass(), [0,0,0])
assert np.allclose(sphere.center_of_mass(), [0,0,0], atol=0.001)

print('volume',sphere.volume())
assert 4.1 < sphere.volume() < 4.2
Expand All @@ -233,7 +233,7 @@
pt = [12,34,52]
print('closest_point',sphere.closest_point(pt), [0.19883616, 0.48003298, 0.85441941])
assert np.allclose(sphere.closest_point(pt),
[0.19883616, 0.48003298, 0.85441941])
[0.19883616, 0.48003298, 0.85441941], atol=0.001)


###################################### find_cells_in_bounds
Expand All @@ -246,13 +246,13 @@
T = cone.clone().pos(35,67,87).transform
s3 = Sphere().apply_transform(T)
print('transformMesh',s3.center_of_mass(), (35,67,87))
assert np.allclose(s3.center_of_mass(), (35,67,87))
assert np.allclose(s3.center_of_mass(), (35,67,87), atol=0.001)


######################################normalize
s3 = sphere.clone().pos(10,20,30).scale([7,8,9]).normalize()
print('normalize',s3.center_of_mass(), (10,20,30))
assert np.allclose(s3.center_of_mass(), (10,20,30))
assert np.allclose(s3.center_of_mass(), (10,20,30), atol=0.001)
print('normalize',s3.average_size())
assert 0.9 < s3.average_size() < 1.1

Expand All @@ -276,7 +276,7 @@

###################################### vertex_normals
print('vertex_normals',sphere.vertex_normals[12], [9.97668684e-01, 1.01513637e-04, 6.82437494e-02])
assert np.allclose(sphere.vertex_normals[12], [9.97668684e-01, 1.01513637e-04, 6.82437494e-02])
assert np.allclose(sphere.vertex_normals[12], [9.97668684e-01, 1.01513637e-04, 6.82437494e-02], atol=0.001)


###################################### contains
Expand All @@ -286,9 +286,9 @@
###################################### intersectWithLine (fails vtk7..)
# pts = sphere.intersectWithLine([-2,-2,-2], [2,3,4])
# print('intersectWithLine',pts[0])
# assert np.allclose(pts[0], [-0.8179885149002075, -0.522485613822937, -0.2269827425479889])
# assert np.allclose(pts[0], [-0.8179885149002075, -0.522485613822937, -0.2269827425479889], atol=0.001)
# print('intersectWithLine',pts[1])
# assert np.allclose(pts[1], [-0.06572723388671875, 0.41784095764160156, 0.9014091491699219])
# assert np.allclose(pts[1], [-0.06572723388671875, 0.41784095764160156, 0.9014091491699219], atol=0.001)


############################################################################
Expand Down Expand Up @@ -333,21 +333,21 @@
q = transformations.cart2spher(*q)
q = transformations.spher2cart(*q)
print("cart2spher spher2cart", q)
assert np.allclose(q, [5,2,3])
assert np.allclose(q, [5,2,3], atol=0.001)
q = transformations.cart2cyl(*q)
q = transformations.cyl2cart(*q)
print("cart2cyl cyl2cart", q)
assert np.allclose(q, [5,2,3])
assert np.allclose(q, [5,2,3], atol=0.001)
q = transformations.cart2cyl(*q)
q = transformations.cyl2spher(*q)
q = transformations.spher2cart(*q)
print("cart2cyl cyl2spher spher2cart", q)
assert np.allclose(q, [5,2,3])
assert np.allclose(q, [5,2,3], atol=0.001)
q = transformations.cart2spher(*q)
q = transformations.spher2cyl(*q)
q = transformations.cyl2cart(*q)
print("cart2spher spher2cyl cyl2cart", q)
assert np.allclose(q, [5,2,3])
assert np.allclose(q, [5,2,3], atol=0.001)

######################################
print("OK with test_actors")
Expand Down
46 changes: 27 additions & 19 deletions tests/snippets/test_elastic_pendulum.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Simulate an elastic pendulum.
The trail is colored according to the velocity."""
import numpy as np
from scipy.integrate import solve_ivp
import matplotlib.pyplot as plt
from vedo import Plotter, Axes, Sphere, Spring, Image
from vedo import Plotter, Axes, Sphere, Spring, Image, mag, sin, cos
from vedo.addons import ProgressBarWidget


Expand All @@ -12,19 +14,17 @@

# Define the system of ODEs
def system(t, z):
x, x_dot, y, y_dot = z # z = [x, x', y, y']
dx_dt = x_dot
dy_dt = y_dot
dx_dot_dt = (a + x) * y_dot ** 2 - k / m * x + g * np.cos(y)
dy_dot_dt = -2 / (a + x) * x_dot * y_dot - g / (a + x) * np.sin(y)
return [dx_dt, dx_dot_dt, dy_dt, dy_dot_dt]
x, dx_dt, y, dy_dt = z # z = [x, x', y, y']
dxdot_dt = (a+x) * dy_dt**2 - k/m * x + g * cos(y)
dydot_dt = -2/(a+x) * dx_dt * dy_dt - g/(a+x) * sin(y)
return [dx_dt, dxdot_dt, dy_dt, dydot_dt]


# Initial conditions: x(0), x'(0), y(0), y'(0)
initial_conditions = [0.0, 0.0, 0.4, 0.0]
initial_conditions = [0.0, 0.0, 0.4, 0.0]

# Time span for the solution
t_span = (0, 10)
t_span = (0, 12)
t_eval = np.linspace(t_span[0], t_span[1], 500) # range to evaluate solution

# Solve the system numerically
Expand All @@ -33,28 +33,36 @@ def system(t, z):
elong_values = solution.y[0]
theta_values = solution.y[2]

# Plot the results
# Plot the results using matplotlib as a graph
fig = plt.figure()
plt.plot(t_values, elong_values, label="elongation(t)")
plt.plot(t_values, theta_values, label="angle(t)")
plt.xlabel("Time")
plt.legend()

# Use vedo to animate the system
# Animate the system using the solution of the ODE
plotter = Plotter(bg="blackboard", bg2="blue1", interactive=False)
pbw = ProgressBarWidget(len(t_values))
pbw = ProgressBarWidget(len(t_values))
axes = Axes(xrange=[-2, 2], yrange=[-a*2, 1], xygrid=0, xyframe_line=0, c="w")
img = Image(fig).clone2d("top-right", size=0.5)
img = Image(fig).clone2d("top-right", size=0.5)
sphere = Sphere(r=0.3, c="red5").add_trail(c="k5", lw=4)
plotter.show(axes, sphere, img, pbw)
plotter.show(axes, sphere, img, pbw, __doc__)

for el, theta in zip(elong_values, theta_values):
x = (a + el) * np.sin(theta)
y = -(a + el) * np.cos(theta)
for elong, theta in zip(elong_values, theta_values):
x = (a + elong) * sin(theta)
y = -(a + elong) * cos(theta)
spring = Spring([0, 0], [x, y])
sphere.pos([x, y]).update_trail()
plotter.remove("Spring").add(spring)

# color the trail according to the lenght of each segment
v = sphere.trail.vertices
lenghts1 = np.array(v[1:])
lenghts2 = np.array(v[:-1])
lenghts = mag(lenghts1 - lenghts2) # lenght of each segment
lenghts = np.append(lenghts, lenghts[-1])
sphere.trail.cmap("Blues_r", lenghts, vmin=0, vmax=0.1)

plotter.remove("Spring").add(spring).render()
pbw.update() # update progress bar
plotter.render()

plotter.interactive()
2 changes: 1 addition & 1 deletion vedo/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3398,7 +3398,7 @@ def __init__(

super().__init__(tuf.GetOutput(), c, alpha)

self.phong()
self.phong().lighting("metallic")
self.base = np.array(start_pt, dtype=float)
self.top = np.array(end_pt, dtype=float)
self.name = "Spring"
Expand Down
2 changes: 1 addition & 1 deletion vedo/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
_version = '2024.5.2+dev15'
_version = '2024.5.2+dev17'

0 comments on commit 66406c9

Please sign in to comment.