Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Oct 25, 2024
1 parent 03c6610 commit e04ed8c
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 21 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
.DS_Store

docs/pdoc/html
develop/
dist/
vtk_data

vedo.egg-info
build
Expand All @@ -19,12 +22,10 @@ examples/notebooks/.ipynb_checkpoints

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

dev_*.py
z?.py
x?.py
v?.py
6 changes: 5 additions & 1 deletion docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ Changes that will break existing code and need active thinking and work to adapt

## New/Revised Examples
```
tests/issues/issue_1146.py
examples/advanced/spline_draw2.py
examples/volumetric/isosurfaces2.py
examples/pyplot/fit_curve2.py
tests/issues/issue_1146.py
tests/issues/discussion_1190.py
tests/snippets/test_interactive_plotxy.py
```

## To Do
- improve 4/5 keys to show a scalarbar
- add interpolate_scalar5 to webpage
- fix draw_spline1,2 in webpage
- fix trasform in image.tomesh() is not transmitted to mesh


### Broken Examples
Expand Down
6 changes: 3 additions & 3 deletions docs/documentation.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://en.wikipedia.org/wiki/MIT_License)
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/vedo/badges/version.svg)](https://anaconda.org/conda-forge/vedo)
[![Ubuntu 23.10 package](https://repology.org/badge/version-for-repo/ubuntu_23_10/vedo.svg)](https://repology.org/project/vedo/versions)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5842090.svg)](https://doi.org/10.5281/zenodo.5842090)
[![Ubuntu 24.10 package](https://repology.org/badge/version-for-repo/ubuntu_24_10/vedo.svg)](https://repology.org/project/vedo/versions)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4587871.svg)](https://doi.org/10.5281/zenodo.4587871)

![](https://vedo.embl.es/images/feats/teapot_banner.png)


A python module for scientific analysis of 3D objects and
point clouds based on [VTK](https://www.vtk.org/) and [numpy](http://www.numpy.org/).
point clouds based on [VTK](https://www.vtk.org/) and [Numpy](http://www.numpy.org/).

Check out the [**GitHub repository**](https://github.com/marcomusy/vedo)
and the [**vedo main page here**](https://vedo.embl.es).
Expand Down
21 changes: 9 additions & 12 deletions examples/other/make_video.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""Make a video file with or without graphic window"""
from vedo import dataurl, Plotter, Mesh, Video
from vedo import dataurl, Plotter, Mesh, Axes, Video


msh = Mesh(dataurl+"spider.ply").rotate_x(-90)
msh.texture(dataurl+"textures/leather.jpg")
msh = Mesh(dataurl+"data/teapot.vtk").normalize()#.rotate_x(-90)
msh.shift(-msh.center_of_mass())

plt = Plotter(bg="beige", bg2="lb", axes=10, offscreen=False)
plt += [msh, __doc__]
plt = Plotter(bg="beige", bg2="lb", offscreen=False)
plt += [msh, Axes(msh), __doc__]

##############################################################
# Open a video file and force it to last 3 seconds in total
video = Video("spider.mp4", duration=3) # or gif
video = Video("vedo_video.mp4", duration=3) # or gif

##############################################################
# Any rendering loop goes here, e.g.:
Expand All @@ -29,22 +29,19 @@
# OR set a sequence of camera positions, e.g.:
cam1 = dict(
position=(5.805, 17.34, -0.8418),
focal_point=(3.133, 1.506, -3.132),
focal_point=(0.133, 0.506, -0.132),
viewup=(-0.3099, 0.1871, -0.9322),
distance=16.22,
clipping_range=(12.35, 21.13),
)
cam2 = dict(
position=(-1.167, 3.356, -18.66),
focal_point=(3.133, 1.506, -3.132),
distance=16.22,
focal_point=(0.133, 0.506, -0.132),
clipping_range=(8.820, 25.58),
)
cam3 = dict(
position=(-4.119, 0.9889, -0.8867),
focal_point=(2.948, 1.048, -3.592),
focal_point=(0.948, 0.048, -0.592),
viewup=(-0.01864, 0.9995, -0.02682),
distance=7.567,
clipping_range=(0.07978, 17.04),
)

Expand Down
37 changes: 37 additions & 0 deletions tests/issues/discussion_1190.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from vedo import *
import matplotlib.colors as colors
import matplotlib.pyplot as plt

settings.default_font = "Antares"

man = Mesh(dataurl + "man.vtk")
h_knees = -0.5
over_limit = 1.5
under_limit = -1.4

# let the scalar be the z coordinate of the mesh vertices
scals = man.vertices[:, 2]

# build a complicated colour map
c1 = plt.cm.viridis(np.linspace(0.0, 0.7, 128))
c2 = plt.cm.terrain(np.linspace(0.5, 0.8, 128))
c = np.vstack((c1, c2))
cmap = colors.LinearSegmentedColormap.from_list("heights", c)
cmap.set_over(color="red")
cmap.set_under(color="orange")
norm = colors.TwoSlopeNorm(h_knees, vmin=under_limit, vmax=over_limit)
mapper = plt.cm.ScalarMappable(norm=norm, cmap=cmap)

# build look up table
lut = build_lut(
[(v, mapper.to_rgba(v)[:3]) for v in np.linspace(under_limit, over_limit, 128)],
above_color=cmap.get_over()[:3],
below_color=cmap.get_under()[:3],
vmin=under_limit,
vmax=over_limit,
)

man.cmap(lut, scals)
man.add_scalarbar3d(above_text="Above Eyes", below_text="Below Heels")
man.scalarbar = man.scalarbar.clone2d("center-left", size=0.3) # make it 2D
show(man, axes=1, viewup="z")
60 changes: 60 additions & 0 deletions tests/snippets/test_interactive_plotxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import numpy as np
from scipy.optimize import fsolve
from vedo import Plotter, settings
from vedo.pyplot import plot


# Initial values
C_init = 0
xdata = np.linspace(-3, 3, 50)


# Function to solve for y given x and C (from your first script)
def solve_for_y(x, C):
y_vals = []
for sign in [1, -1]: # Solve for positive and negative y

def equation(y):
return 0.5 * y**2 + np.log(np.abs(y)) - 0.5 * x**2 - C

y_initial_guess = sign * np.exp(-0.5 * x**2 - C)

root = fsolve(equation, y_initial_guess)[0]
if equation(root) < 1e-5: # Only accept the root if it's a valid solution
y_vals.append(root)
return y_vals


# Generate the y values for plotting (positive and negative y)
def generate_y_values(x_values, C):
y_positive = []
y_negative = []
for x in x_values:
y_vals = solve_for_y(x, C)
if len(y_vals) > 0:
y_positive.append(max(y_vals)) # Choose the largest root as positive
y_negative.append(min(y_vals)) # Choose the smallest root as negative
else:
y_positive.append(np.nan) # Use NaN for missing values
y_negative.append(np.nan)
return y_positive, y_negative


# Function to update the plot when the slider changes
def update_plot(widget=None, event=""):
C_value = C_init if widget is None else widget.value
y_positive, y_negative = generate_y_values(xdata, C_value)
m = max(max(y_positive), abs(min(y_negative)))
p = plot(xdata, y_positive, c='red5', lw=4, ylim=(-m, m))
p += plot(xdata, y_negative, c='blue5', lw=4, like=p)
plt.remove("PlotXY").add(p)


# Create Plotter and the slider to control the value of C
settings.default_font = "Brachium"

plt = Plotter(size=(900, 650), title="Exercise")
slider = plt.add_slider(update_plot, -10.0, 10.0, value=C_init, title="C value", c="green3")
update_plot() # Initial plot

plt.show(mode="2d", zoom=1.35)
1 change: 0 additions & 1 deletion vedo/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3151,7 +3151,6 @@ def _histogram_polar(
ct, st = np.cos(t), np.sin(t)

if show_errors:
show_lines = False
err = np.sqrt(histodata[i]) / vmax * r2
errl = shapes.Line(
((r1 + r - err) * ct, (r1 + r - err) * st, 0.01),
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+dev12'
_version = '2024.5.2+dev14'

0 comments on commit e04ed8c

Please sign in to comment.