A python module for scientific visualization, analysis of 3D objects and point clouds.
Interactive widgets and UI elements including sliders, buttons, scalar bars, legends, and measurement tools for creating interactive 3D applications. These components enable users to build sophisticated interactive visualizations with custom controls and feedback.
Slider widgets for real-time parameter adjustment and interactive control of visualization properties.
class Slider2D:
"""
2D slider widget for interactive parameter control.
Parameters:
- func: callable
Function to call when slider value changes
- xmin: float
Minimum slider value
- xmax: float
Maximum slider value
- value: float, optional
Initial slider value
- pos: int or tuple, default 4
Slider position (corner index or (x,y) coordinates)
- title: str, default ""
Slider title text
- font: str, default "Calco"
Font name for text
- titleSize: float, default 1
Title text size
- c: str or tuple, optional
Slider color
- alpha: float, default 1
Slider transparency
- showValue: bool, default True
Display current value
- delayed: bool, default False
Delay callback until mouse release
- **options: keyword arguments
Additional slider options
"""
def __init__(
self,
func,
xmin,
xmax,
value=None,
pos=4,
title="",
font="Calco",
titleSize=1,
c=None,
alpha=1,
showValue=True,
delayed=False,
**options
): ...
class Slider3D:
"""
3D slider widget embedded in the 3D scene.
Parameters:
- func: callable
Function to call when slider value changes
- xmin: float
Minimum slider value
- xmax: float
Maximum slider value
- value: float, optional
Initial slider value
- pos: tuple, default (0, 0, 0)
3D position in scene
- normal: tuple, default (0, 0, 1)
Slider orientation normal
- length: float, default 1
Slider track length
- width: float, default 0.1
Slider track width
- c: str or tuple, default "red"
Slider color
- alpha: float, default 1
Slider transparency
"""
def __init__(
self,
func,
xmin,
xmax,
value=None,
pos=(0, 0, 0),
normal=(0, 0, 1),
length=1,
width=0.1,
c="red",
alpha=1
): ...
class Button:
"""
Interactive button widget.
Parameters:
- func: callable
Function to call when button is pressed
- states: list, default ["On", "Off"]
Button state labels
- c: list or str, default ["white", "gray"]
Button colors for each state
- bc: list or str, default ["green", "red"]
Border colors for each state
- pos: tuple, default (0.7, 0.1)
Button position (normalized coordinates)
- size: int, default 24
Button size
- font: str, default ""
Font name for button text
- bold: bool, default False
Use bold text
- italic: bool, default False
Use italic text
"""
def __init__(
self,
func,
states=["On", "Off"],
c=["white", "gray"],
bc=["green", "red"],
pos=(0.7, 0.1),
size=24,
font="",
bold=False,
italic=False
): ...
class CheckBox:
"""
Checkbox widget for boolean input.
Parameters:
- label: str
Checkbox label text
- value: bool, default False
Initial checkbox state
- pos: tuple, default (0.8, 0.1)
Checkbox position (normalized coordinates)
- c: str or tuple, default "white"
Checkbox color
- bc: str or tuple, default "black"
Border color
- size: int, default 24
Checkbox size
- font: str, default ""
Font name for label
"""
def __init__(
self,
label,
value=False,
pos=(0.8, 0.1),
c="white",
bc="black",
size=24,
font=""
): ...Components for displaying legends, scalar bars, and informational overlays.
class ScalarBar:
"""
2D scalar bar for displaying color mapping scales.
Parameters:
- obj: vedo object
Object to create scalar bar for
- title: str, default ""
Scalar bar title
- pos: tuple, default (0.775, 0.05)
Position (normalized coordinates)
- titleYOffset: int, default 15
Title vertical offset
- titleFontSize: int, default 12
Title font size
- size: tuple, default (None, None)
Scalar bar size
- nlabels: int, optional
Number of labels
- c: str or tuple, optional
Text color
- horizontal: bool, default False
Horizontal orientation
- useAlpha: bool, default True
Include transparency in bar
"""
def __init__(
self,
obj,
title="",
pos=(0.775, 0.05),
titleYOffset=15,
titleFontSize=12,
size=(None, None),
nlabels=None,
c=None,
horizontal=False,
useAlpha=True
): ...
class ScalarBar3D:
"""
3D scalar bar embedded in the scene.
Parameters:
- obj: vedo object
Object to create scalar bar for
- title: str, default ""
Scalar bar title
- pos: tuple, optional
3D position in scene
- normal: tuple, default (0, 0, 1)
Bar orientation normal
- sx: float, default 1
Bar width
- sy: float, default 8
Bar height
- nlabels: int, default 9
Number of labels
- c: str or tuple, default "black"
Text color
- italic: bool, default False
Use italic text
"""
def __init__(
self,
obj,
title="",
pos=None,
normal=(0, 0, 1),
sx=1,
sy=8,
nlabels=9,
c="black",
italic=False
): ...
class LegendBox:
"""
Legend box for displaying object labels and colors.
Parameters:
- entries: list
List of (label, color) tuples
- markers: list, optional
Custom markers for each entry
- c: str or tuple, default "black"
Text color
- font: str, default ""
Font name
- width: float, default 0.18
Legend box width
- height: float, optional
Legend box height
- pos: tuple, default "top-right"
Legend position
"""
def __init__(
self,
entries,
markers=None,
c="black",
font="",
width=0.18,
height=None,
pos="top-right"
): ...
class Icon:
"""
Display icon images in the scene.
Parameters:
- name: str
Icon name or file path
- pos: tuple, default (0.1, 0.1)
Icon position (normalized coordinates)
- size: float, default 0.06
Icon size
"""
def __init__(self, name, pos=(0.1, 0.1), size=0.06): ...Lighting controls and visualization aids for scene illumination.
class Light:
"""
Light source for scene illumination.
Parameters:
- pos: tuple, default (1, 1, 1)
Light position coordinates
- focalPoint: tuple, default (0, 0, 0)
Point the light is focused on
- deg: float, default 180
Light cone angle in degrees
- c: str or tuple, default "white"
Light color
- intensity: float, default 1
Light intensity
"""
def __init__(
self,
pos=(1, 1, 1),
focalPoint=(0, 0, 0),
deg=180,
c="white",
intensity=1
): ...Components for displaying coordinate systems, axes, and reference frames.
class Axes:
"""
Coordinate axes display.
Parameters:
- obj: vedo object, optional
Object to create axes for
- xtitle: str, default "x"
X-axis label
- ytitle: str, default "y"
Y-axis label
- ztitle: str, default "z"
Z-axis label
- xrange: tuple, optional
X-axis range
- yrange: tuple, optional
Y-axis range
- zrange: tuple, optional
Z-axis range
- c: str or tuple, default "black"
Axes color
- alpha: float, default 1
Axes transparency
- tips: bool, default True
Show arrow tips
- labels: bool, default True
Show axis labels
"""
def __init__(
self,
obj=None,
xtitle="x",
ytitle="y",
ztitle="z",
xrange=None,
yrange=None,
zrange=None,
c="black",
alpha=1,
tips=True,
labels=True
): ...
class RendererFrame:
"""
Frame around the renderer viewport.
Parameters:
- c: str or tuple, default "black"
Frame color
- alpha: float, default 1
Frame transparency
- lw: float, default 1
Frame line width
- padding: float, default 0
Frame padding
"""
def __init__(self, c="black", alpha=1, lw=1, padding=0): ...Interactive tools for measuring distances, angles, and other geometric properties.
class Ruler2D:
"""
2D ruler for measuring distances on screen.
Parameters:
- p1: tuple
First point (screen coordinates)
- p2: tuple
Second point (screen coordinates)
- units: str, default ""
Measurement units label
- c: str or tuple, default "black"
Ruler color
- alpha: float, default 1
Ruler transparency
- lw: float, default 1
Line width
"""
def __init__(self, p1, p2, units="", c="black", alpha=1, lw=1): ...
class Ruler3D:
"""
3D ruler for measuring distances in world coordinates.
Parameters:
- p1: tuple
First 3D point
- p2: tuple
Second 3D point
- units: str, default ""
Measurement units label
- c: str or tuple, default "black"
Ruler color
- alpha: float, default 1
Ruler transparency
- lw: float, default 2
Line width
"""
def __init__(self, p1, p2, units="", c="black", alpha=1, lw=2): ...
class DistanceTool:
"""
Interactive distance measurement tool.
Parameters:
- c: str or tuple, default "red"
Tool color
- lw: float, default 2
Line width
- units: str, default ""
Measurement units
"""
def __init__(self, c="red", lw=2, units=""): ...
class SplineTool:
"""
Interactive spline creation and editing tool.
Parameters:
- points: list, optional
Initial control points
- pc: str or tuple, default "red"
Point color
- lc: str or tuple, default "blue"
Line color
- alpha: float, default 1
Tool transparency
"""
def __init__(self, points=None, pc="red", lc="blue", alpha=1): ...Tools for displaying contextual information and interactive annotations.
class Hover:
"""
Display information when hovering over objects.
Parameters:
- obj: vedo object
Object to attach hover information to
- c: str or tuple, default "black"
Text color
- bc: str or tuple, default "yellow"
Background color
- alpha: float, default 1
Information box transparency
- font: str, default ""
Font name
"""
def __init__(self, obj, c="black", bc="yellow", alpha=1, font=""): ...
class Flagpost:
"""
Flag-style annotation pointing to specific locations.
Parameters:
- txt: str
Flag text
- pos: tuple
3D position to point to
- height: float, default 1
Flag pole height
- s: float, default 1
Flag size
- c: str or tuple, default "red"
Flag color
- bc: str or tuple, default "white"
Background color
- alpha: float, default 1
Flag transparency
"""
def __init__(
self,
txt,
pos,
height=1,
s=1,
c="red",
bc="white",
alpha=1
): ...import vedo
import numpy as np
# Create interactive visualization with UI components
plt = vedo.Plotter(title="Interactive 3D Scene")
# Add main 3D objects
sphere = vedo.Sphere(pos=(0, 0, 0), r=1, c='red')
box = vedo.Box(pos=(2, 0, 0), c='blue')
plt.add(sphere, box)
# Add interactive sliders
def update_sphere_radius(widget, event):
r = widget.GetRepresentation().GetValue()
sphere.scale(r)
def update_box_position(widget, event):
x = widget.GetRepresentation().GetValue()
box.pos(x, 0, 0)
radius_slider = vedo.Slider2D(
update_sphere_radius,
xmin=0.5, xmax=2.0, value=1.0,
pos=4, title="Sphere Radius",
showValue=True
)
position_slider = vedo.Slider2D(
update_box_position,
xmin=-3, xmax=3, value=2.0,
pos=3, title="Box X Position",
c='blue'
)
# Add 3D slider embedded in scene
def rotate_objects(widget, event):
angle = widget.GetRepresentation().GetValue()
sphere.rotate_z(angle - sphere.info.get('last_angle', 0))
sphere.info['last_angle'] = angle
rotation_slider = vedo.Slider3D(
rotate_objects,
xmin=0, xmax=360, value=0,
pos=(0, -3, 0), length=4,
c='green', title="Rotation"
)
# Add control buttons
def toggle_visibility(obj, state):
if state:
sphere.alpha(1)
box.alpha(1)
else:
sphere.alpha(0.3)
box.alpha(0.3)
visibility_button = vedo.Button(
toggle_visibility,
states=["Visible", "Faded"],
c=["white", "gray"],
pos=(0.1, 0.9)
)
# Add checkbox for wireframe mode
def toggle_wireframe(obj, state):
if state:
sphere.wireframe()
box.wireframe()
else:
sphere.wireframe(False)
box.wireframe(False)
wireframe_checkbox = vedo.CheckBox(
"Wireframe Mode",
value=False,
pos=(0.1, 0.8)
)
# Add scalar bar (requires scalar data)
# Generate some scalar data for demonstration
points = sphere.points()
distances = np.linalg.norm(points, axis=1)
sphere.pointdata['distance'] = distances
scalar_bar = vedo.ScalarBar(
sphere,
title="Distance from Origin",
pos=(0.85, 0.1),
titleFontSize=14
)
# Add 3D scalar bar
scalar_bar_3d = vedo.ScalarBar3D(
sphere,
title="3D Scale",
pos=(4, 0, 0),
sy=2
)
# Create legend for objects
legend_entries = [
("Red Sphere", "red"),
("Blue Box", "blue"),
("Green Slider", "green")
]
legend = vedo.LegendBox(
legend_entries,
width=0.15,
pos="top-left"
)
# Add coordinate axes
axes = vedo.Axes(
sphere,
xtitle="X axis",
ytitle="Y axis",
ztitle="Z axis",
c='black'
)
# Add lighting
key_light = vedo.Light(
pos=(5, 5, 5),
focalPoint=(0, 0, 0),
intensity=1.2,
c='white'
)
fill_light = vedo.Light(
pos=(-3, 2, 3),
focalPoint=(0, 0, 0),
intensity=0.6,
c='lightblue'
)
# Add measurement tools
ruler = vedo.Ruler3D(
sphere.center(), box.center(),
units="units",
c='yellow',
lw=3
)
# Add information display
hover_info = vedo.Hover(
sphere,
c='black',
bc='lightyellow'
)
# Add flag annotation
flag = vedo.Flagpost(
"Important Point",
pos=(0, 0, 1),
height=1.5,
c='orange'
)
# Measurement and analysis tools
distance_tool = vedo.DistanceTool(c='purple', units='cm')
# Create spline editing tool
control_points = [(0, -2, 0), (1, -2, 1), (2, -2, 0), (3, -2, -1)]
spline_tool = vedo.SplineTool(
points=control_points,
pc='red',
lc='blue'
)
# Add all components to the plotter
plt.add([
radius_slider, position_slider, rotation_slider,
visibility_button, wireframe_checkbox,
scalar_bar, scalar_bar_3d, legend, axes,
key_light, fill_light, ruler, hover_info, flag,
distance_tool, spline_tool
])
# Add renderer frame
frame = vedo.RendererFrame(c='black', lw=2)
plt.add(frame)
# Add icon
icon = vedo.Icon("home", pos=(0.95, 0.95), size=0.04)
plt.add(icon)
# Show interactive scene
plt.show()
# Example of programmatic UI updates
def animate_scene():
"""Demonstrate programmatic control of UI elements."""
for i in range(100):
# Update slider values programmatically
radius_slider.SetValue(1 + 0.5 * np.sin(i * 0.1))
position_slider.SetValue(2 * np.cos(i * 0.05))
# Update object properties
sphere.color(i % 10) # Cycle through colors
# Update measurements
new_ruler = vedo.Ruler3D(
sphere.center(), box.center(),
units="dynamic",
c='red'
)
plt.render()
animate_scene()Install with Tessl CLI
npx tessl i tessl/pypi-vedo