viser
Composable 3D visualization primitives using viser.
This module provides building blocks for creating interactive 3D trajectory visualizations. The design philosophy is to give you useful primitives that you can mix and match - not a monolithic plotting function that tries to handle every case.
Basic Pattern:
1. Create a viser.ViserServer (use our helper, or make your own!)
2. Add static scene elements (obstacles, gates, ground planes, etc.)
3. Add animated elements - each returns (handle, update_callback)
4. Wire up animation controls with your list of update callbacks
5. Call server.sleep_forever() to keep the visualization running
Example - Building Your Own Visualization::
from openscvx.plotting import viser
# Step 1: Create server (or just use viser.ViserServer() directly!)
server = viser.create_server(positions)
# Step 2: Add static elements
viser.add_gates(server, gate_vertices)
viser.add_ellipsoid_obstacles(server, centers, radii)
viser.add_ghost_trajectory(server, positions, colors)
# Step 3: Add animated elements (collect the update callbacks)
_, update_trail = viser.add_animated_trail(server, positions, colors)
_, update_marker = viser.add_position_marker(server, positions)
_, update_thrust = viser.add_thrust_vector(server, positions, thrust)
# Step 4: Wire up animation controls
viser.add_animation_controls(
server, time_array,
[update_trail, update_marker, update_thrust]
)
# Step 5: Keep server running
server.sleep_forever()
Available Primitives:
- Server: create_server, compute_velocity_colors, compute_grid_size
- Static: add_gates, add_ellipsoid_obstacles, add_glideslope_cone,
add_ghost_trajectory
- Animated: add_animated_trail, add_position_marker, add_thrust_vector,
add_attitude_frame, add_viewcone, add_target_marker(s)
- Plotly: add_animated_plotly_marker, add_animated_vector_norm_plot
- SCP iteration: add_scp_animation_controls, add_scp_iteration_nodes, etc.
For problem-specific examples (drones with viewcones, rockets with glideslope
constraints, etc.), see examples/plotting_viser.py.
add_animated_plotly_marker(server: viser.ViserServer, fig: go.Figure, time_array: np.ndarray, marker_x_data: np.ndarray, marker_y_data: np.ndarray, use_trajectory_indexing: bool = True, marker_name: str = 'Current', marker_color: str = 'red', marker_size: int = 12, folder_name: str | None = None, aspect: float = 1.5) -> tuple
¶
Add a plotly figure to viser GUI with an animated time marker.
This function takes any plotly figure and adds an animated marker that synchronizes with viser's 3D animation timeline. The marker shows the current position on the plot as the animation plays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
fig
|
Figure
|
Plotly figure to display |
required |
time_array
|
ndarray
|
Time values corresponding to animation frames (N,). This should match the time array passed to add_animation_controls(). |
required |
marker_x_data
|
ndarray
|
X-axis values for marker position (N,) |
required |
marker_y_data
|
ndarray
|
Y-axis values for marker position (N,) |
required |
use_trajectory_indexing
|
bool
|
If True, frame_idx maps directly to data indices. If False, searches for nearest time value (use for node-only data). |
True
|
marker_name
|
str
|
Legend name for the marker trace |
'Current'
|
marker_color
|
str
|
Color of the animated marker |
'red'
|
marker_size
|
int
|
Size of the animated marker in points |
12
|
folder_name
|
str | None
|
Optional GUI folder name to organize plots |
None
|
aspect
|
float
|
Aspect ratio for plot display (width/height) |
1.5
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (plot_handle, update_callback) |
Example::
from openscvx.plotting import plot_vector_norm, viser
# Create any plotly figure
fig = plot_vector_norm(results, "thrust")
thrust_norms = np.linalg.norm(results.trajectory["thrust"], axis=1)
# Add to viser with animated marker
_, update_plot = viser.add_animated_plotly_marker(
server, fig,
time_array=results.trajectory["time"].flatten(),
marker_x_data=results.trajectory["time"].flatten(),
marker_y_data=thrust_norms,
)
# Add to animation callbacks
update_callbacks.append(update_plot)
Source code in openscvx/plotting/viser/plotly_integration.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
add_animated_plotly_vline(server: viser.ViserServer, fig: go.Figure, time_array: np.ndarray, use_trajectory_indexing: bool = True, line_color: str = 'red', line_width: int = 2, line_dash: str = 'dash', annotation_text: str = 'Current', annotation_position: str = 'top', folder_name: str | None = None, aspect: float = 1.5) -> tuple
¶
Add a plotly figure to viser GUI with an animated vertical line.
This function takes any plotly figure and adds an animated vertical line that synchronizes with viser's 3D animation timeline. The line shows the current time position as the animation plays.
This is more generic than add_animated_plotly_marker() as it works for any number of traces without needing to specify y-data for each.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
fig
|
Figure
|
Plotly figure to display |
required |
time_array
|
ndarray
|
Time values corresponding to animation frames (N,). This should match the time array passed to add_animation_controls(). |
required |
use_trajectory_indexing
|
bool
|
If True, frame_idx maps directly to time indices. If False, searches for nearest time value (use for node-only data). |
True
|
line_color
|
str
|
Color of the vertical line |
'red'
|
line_width
|
int
|
Width of the vertical line in pixels |
2
|
line_dash
|
str
|
Dash style - "solid", "dash", "dot", "dashdot" |
'dash'
|
annotation_text
|
str
|
Text to show on the line |
'Current'
|
annotation_position
|
str
|
Position of annotation - "top", "bottom", "top left", etc. |
'top'
|
folder_name
|
str | None
|
Optional GUI folder name to organize plots |
None
|
aspect
|
float
|
Aspect ratio for plot display (width/height) |
1.5
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (plot_handle, update_callback) |
Example::
from openscvx.plotting import plot_control, viser
# Create any plotly figure
fig = plot_control(results, "thrust_force")
# Add to viser with animated vertical line
_, update_plot = viser.add_animated_plotly_vline(
server, fig,
time_array=results.trajectory["time"].flatten(),
)
# Add to animation callbacks
update_callbacks.append(update_plot)
Source code in openscvx/plotting/viser/plotly_integration.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
add_animated_trail(server: viser.ViserServer, pos: np.ndarray, colors: np.ndarray, point_size: float = 0.15) -> tuple[viser.PointCloudHandle, UpdateCallback]
¶
Add an animated trail that grows with the animation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
pos
|
ndarray
|
Position array of shape (N, 3) |
required |
colors
|
ndarray
|
RGB color array of shape (N, 3) |
required |
point_size
|
float
|
Size of trail points |
0.15
|
Returns:
| Type | Description |
|---|---|
tuple[PointCloudHandle, UpdateCallback]
|
Tuple of (handle, update_callback) |
Source code in openscvx/plotting/viser/animated.py
add_animated_vector_norm_plot(server: viser.ViserServer, results: OptimizationResults, var_name: str, bounds: tuple[float, float] | None = None, title: str | None = None, folder_name: str | None = None, aspect: float = 1.5, marker_color: str = 'red', marker_size: int = 12) -> tuple
¶
Add animated norm plot for a state or control variable.
Convenience wrapper around add_animated_plotly_marker() that uses the existing plot_vector_norm() function to create the base plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
results
|
OptimizationResults
|
Optimization results containing variable data |
required |
var_name
|
str
|
Name of the state or control variable to plot |
required |
bounds
|
tuple[float, float] | None
|
Optional (min, max) bounds to display on plot |
None
|
title
|
str | None
|
Optional custom title for the plot (defaults to "‖{var_name}‖₂") |
None
|
folder_name
|
str | None
|
Optional GUI folder name to organize plots |
None
|
aspect
|
float
|
Aspect ratio for plot display (width/height) |
1.5
|
marker_color
|
str
|
Color of the animated marker |
'red'
|
marker_size
|
int
|
Size of the animated marker in points |
12
|
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple of (plot_handle, update_callback), or (None, None) if variable not found |
Example::
from openscvx.plotting import viser
# Add animated thrust norm plot
_, update_thrust = viser.add_animated_vector_norm_plot(
server, results, "thrust",
title="Thrust Magnitude",
bounds=(0.0, max_thrust),
folder_name="Control Plots"
)
if update_thrust is not None:
update_callbacks.append(update_thrust)
Source code in openscvx/plotting/viser/plotly_integration.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
add_animation_controls(server: viser.ViserServer, traj_time: np.ndarray, update_callbacks: list[UpdateCallback], loop: bool = True, folder_name: str = 'Animation') -> None
¶
Add animation GUI controls and start the animation loop.
Creates play/pause button, reset button, time slider, speed slider, and loop checkbox. Runs animation in a background daemon thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
traj_time
|
ndarray
|
Time array of shape (N,) with timestamps for each frame |
required |
update_callbacks
|
list[UpdateCallback]
|
List of update functions to call each frame |
required |
loop
|
bool
|
Whether to loop animation by default |
True
|
folder_name
|
str
|
Name for the GUI folder |
'Animation'
|
Source code in openscvx/plotting/viser/animated.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
add_attitude_frame(server: viser.ViserServer, pos: np.ndarray, attitude: np.ndarray | None, axes_length: float = 2.0, axes_radius: float = 0.05) -> tuple[viser.FrameHandle | None, UpdateCallback | None]
¶
Add an animated body coordinate frame showing attitude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
pos
|
ndarray
|
Position array of shape (N, 3) |
required |
attitude
|
ndarray | None
|
Quaternion array of shape (N, 4) in [w, x, y, z] format, or None to skip |
required |
axes_length
|
float
|
Length of the coordinate axes |
2.0
|
axes_radius
|
float
|
Radius of the axes cylinders |
0.05
|
Returns:
| Type | Description |
|---|---|
tuple[FrameHandle | None, UpdateCallback | None]
|
Tuple of (handle, update_callback), or (None, None) if attitude is None |
Source code in openscvx/plotting/viser/animated.py
add_ellipsoid_obstacles(server: viser.ViserServer, centers: list[np.ndarray], radii: list[np.ndarray], axes: list[np.ndarray] | None = None, color: tuple[int, int, int] = (255, 100, 100), opacity: float = 0.6, wireframe: bool = False, subdivisions: int = 2) -> list
¶
Add ellipsoidal obstacles to the scene.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
centers
|
list[ndarray]
|
List of center positions, each shape (3,) |
required |
radii
|
list[ndarray]
|
List of radii along principal axes, each shape (3,) |
required |
axes
|
list[ndarray] | None
|
List of rotation matrices (3, 3) defining principal axes. If None, ellipsoids are axis-aligned. |
None
|
color
|
tuple[int, int, int]
|
RGB color tuple |
(255, 100, 100)
|
opacity
|
float
|
Opacity (0-1), only used when wireframe=False |
0.6
|
wireframe
|
bool
|
If True, render as wireframe instead of solid |
False
|
subdivisions
|
int
|
Icosphere subdivisions (higher = smoother, 2 is usually good) |
2
|
Returns:
| Type | Description |
|---|---|
list
|
List of mesh handles |
Source code in openscvx/plotting/viser/primitives.py
add_gates(server: viser.ViserServer, vertices: list, color: tuple[int, int, int] = (255, 165, 0), line_width: float = 3.0) -> None
¶
Add gate/obstacle wireframes to the scene.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
vertices
|
list
|
List of vertex arrays (4 vertices for planar gate, 8 for box) |
required |
color
|
tuple[int, int, int]
|
RGB color tuple |
(255, 165, 0)
|
line_width
|
float
|
Line width for wireframe |
3.0
|
Source code in openscvx/plotting/viser/primitives.py
add_ghost_trajectory(server: viser.ViserServer, pos: np.ndarray, colors: np.ndarray, opacity: float = 0.3, point_size: float = 0.05) -> None
¶
Add a faint ghost trajectory showing the full path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
pos
|
ndarray
|
Position array of shape (N, 3) |
required |
colors
|
ndarray
|
RGB color array of shape (N, 3) |
required |
opacity
|
float
|
Opacity factor (0-1) applied to colors |
0.3
|
point_size
|
float
|
Size of trajectory points |
0.05
|
Source code in openscvx/plotting/viser/primitives.py
add_glideslope_cone(server: viser.ViserServer, apex: np.ndarray | tuple = (0.0, 0.0, 0.0), height: float = 2000.0, glideslope_angle_deg: float = 86.0, axis: np.ndarray | tuple = (0.0, 0.0, 1.0), color: tuple[int, int, int] = (100, 200, 100), opacity: float = 0.2, wireframe: bool = False, n_segments: int = 32) -> viser.MeshHandle
¶
Add a glideslope/approach constraint cone to the scene.
The glideslope constraint typically has the form
||position_perp|| <= tan(angle) * position_along_axis
This creates a cone with apex at the target, opening along the specified axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
apex
|
ndarray | tuple
|
Apex position (docking/landing site), default is origin |
(0.0, 0.0, 0.0)
|
height
|
float
|
Height of the cone visualization |
2000.0
|
glideslope_angle_deg
|
float
|
Glideslope angle in degrees (measured from axis). For constraint ||r_perp|| <= tan(theta) * r_axis, pass theta here. Common values: 86 deg (very wide), 70 deg (moderate), 45 deg (steep) |
86.0
|
axis
|
ndarray | tuple
|
Unit vector direction the cone opens toward. Default (0,0,1) for +Z. Use (-1,0,0) for R-bar approach (from below in radial direction). |
(0.0, 0.0, 1.0)
|
color
|
tuple[int, int, int]
|
RGB color tuple |
(100, 200, 100)
|
opacity
|
float
|
Opacity (0-1) |
0.2
|
wireframe
|
bool
|
If True, render as wireframe |
False
|
n_segments
|
int
|
Number of segments for cone smoothness |
32
|
Returns:
| Type | Description |
|---|---|
MeshHandle
|
Mesh handle for the cone |
Source code in openscvx/plotting/viser/primitives.py
add_position_marker(server: viser.ViserServer, pos: np.ndarray, radius: float = 0.5, color: tuple[int, int, int] = (100, 200, 255)) -> tuple[viser.IcosphereHandle, UpdateCallback]
¶
Add an animated position marker (sphere at current position).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
pos
|
ndarray
|
Position array of shape (N, 3) |
required |
radius
|
float
|
Marker radius |
0.5
|
color
|
tuple[int, int, int]
|
RGB color tuple |
(100, 200, 255)
|
Returns:
| Type | Description |
|---|---|
tuple[IcosphereHandle, UpdateCallback]
|
Tuple of (handle, update_callback) |
Source code in openscvx/plotting/viser/animated.py
add_scp_animation_controls(server: viser.ViserServer, n_iterations: int, update_callbacks: list[UpdateCallback], autoplay: bool = False, frame_duration_ms: int = 500, folder_name: str = 'SCP Animation') -> None
¶
Add GUI controls for stepping through SCP iterations.
Creates play/pause button, step buttons, iteration slider, and speed control.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
n_iterations
|
int
|
Total number of SCP iterations |
required |
update_callbacks
|
list[UpdateCallback]
|
List of update functions to call each iteration |
required |
autoplay
|
bool
|
Whether to start playing automatically |
False
|
frame_duration_ms
|
int
|
Default milliseconds per iteration frame |
500
|
folder_name
|
str
|
Name for the GUI folder |
'SCP Animation'
|
Source code in openscvx/plotting/viser/scp.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
add_scp_ghost_iterations(server: viser.ViserServer, positions: list[np.ndarray], point_size: float = 0.15, cmap_name: str = 'viridis') -> tuple[list[viser.PointCloudHandle], UpdateCallback]
¶
Add ghost trails showing all previous SCP iterations.
Pre-buffers point clouds for all iterations and toggles visibility for performance. Shows all previous iterations with viridis coloring to visualize convergence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
positions
|
list[ndarray]
|
List of position arrays per iteration, each shape (N, 3) |
required |
point_size
|
float
|
Size of ghost points |
0.15
|
cmap_name
|
str
|
Matplotlib colormap name for ghost colors |
'viridis'
|
Returns:
| Type | Description |
|---|---|
tuple[list[PointCloudHandle], UpdateCallback]
|
Tuple of (list of handles, update_callback) |
Source code in openscvx/plotting/viser/scp.py
add_scp_iteration_attitudes(server: viser.ViserServer, positions: list[np.ndarray], attitudes: list[np.ndarray] | None, axes_length: float = 1.5, axes_radius: float = 0.03, stride: int = 1) -> tuple[list[viser.FrameHandle], UpdateCallback | None]
¶
Add animated attitude frames at each node that update per SCP iteration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
positions
|
list[ndarray]
|
List of position arrays per iteration, each shape (N, 3) |
required |
attitudes
|
list[ndarray] | None
|
List of quaternion arrays per iteration, each shape (N, 4) in wxyz format. If None, returns empty list and None callback. |
required |
axes_length
|
float
|
Length of coordinate frame axes |
1.5
|
axes_radius
|
float
|
Radius of axes cylinders |
0.03
|
stride
|
int
|
Show attitude frame every |
1
|
Returns:
| Type | Description |
|---|---|
tuple[list[FrameHandle], UpdateCallback | None]
|
Tuple of (list of frame handles, update_callback) |
Source code in openscvx/plotting/viser/scp.py
add_scp_iteration_nodes(server: viser.ViserServer, positions: list[np.ndarray], colors: list[tuple[int, int, int]] | None = None, point_size: float = 0.3, cmap_name: str = 'viridis') -> tuple[list[viser.PointCloudHandle], UpdateCallback]
¶
Add animated optimization nodes that update per SCP iteration.
Pre-buffers point clouds for all iterations and toggles visibility for performance. This avoids transmitting point data on every frame update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
positions
|
list[ndarray]
|
List of position arrays per iteration, each shape (N, 3) |
required |
colors
|
list[tuple[int, int, int]] | None
|
Optional list of RGB colors per iteration. If None, uses viridis colormap. |
None
|
point_size
|
float
|
Size of node markers |
0.3
|
cmap_name
|
str
|
Matplotlib colormap name (default: "viridis") |
'viridis'
|
Returns:
| Type | Description |
|---|---|
tuple[list[PointCloudHandle], UpdateCallback]
|
Tuple of (list of point_handles, update_callback) |
Source code in openscvx/plotting/viser/scp.py
add_scp_propagation_lines(server: viser.ViserServer, propagations: list[list[np.ndarray]], line_width: float = 2.0, cmap_name: str = 'viridis') -> tuple[list, UpdateCallback]
¶
Add animated nonlinear propagation lines that update per SCP iteration.
Shows the actual integrated trajectory between optimization nodes, revealing defects (gaps) in early iterations that close as SCP converges. All iterations up to the current one are shown with viridis coloring, similar to ghost iterations for nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
propagations
|
list[list[ndarray]]
|
List of propagation trajectories per iteration from extract_propagation_positions(). Each iteration contains a list of (n_substeps, 3) position arrays, one per segment. |
required |
line_width
|
float
|
Width of propagation lines |
2.0
|
cmap_name
|
str
|
Matplotlib colormap name (default: "viridis") |
'viridis'
|
Returns:
| Type | Description |
|---|---|
tuple[list, UpdateCallback]
|
Tuple of (list of line handles, update_callback) |
Source code in openscvx/plotting/viser/scp.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
add_target_marker(server: viser.ViserServer, target_pos: np.ndarray, name: str = 'target', radius: float = 0.8, color: tuple[int, int, int] = (255, 50, 50), show_trail: bool = True, trail_color: tuple[int, int, int] | None = None) -> tuple[viser.IcosphereHandle, UpdateCallback | None]
¶
Add a viewplanning target marker (static or moving).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
target_pos
|
ndarray
|
Target position - either shape (3,) for static or (N, 3) for moving |
required |
name
|
str
|
Unique name for this target (used in scene path) |
'target'
|
radius
|
float
|
Marker radius |
0.8
|
color
|
tuple[int, int, int]
|
RGB color tuple for marker |
(255, 50, 50)
|
show_trail
|
bool
|
If True and target is moving, show trajectory trail |
True
|
trail_color
|
tuple[int, int, int] | None
|
RGB color for trail (defaults to dimmed marker color) |
None
|
Returns:
| Type | Description |
|---|---|
tuple[IcosphereHandle, UpdateCallback | None]
|
Tuple of (handle, update_callback). update_callback is None for static targets. |
Source code in openscvx/plotting/viser/animated.py
add_target_markers(server: viser.ViserServer, target_positions: list[np.ndarray], colors: list[tuple[int, int, int]] | None = None, radius: float = 0.8, show_trails: bool = True) -> list[tuple[viser.IcosphereHandle, UpdateCallback | None]]
¶
Add multiple viewplanning target markers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
target_positions
|
list[ndarray]
|
List of target positions, each either (3,) or (N, 3) |
required |
colors
|
list[tuple[int, int, int]] | None
|
List of RGB colors, one per target. Defaults to distinct colors. |
None
|
radius
|
float
|
Marker radius |
0.8
|
show_trails
|
bool
|
If True, show trails for moving targets |
True
|
Returns:
| Type | Description |
|---|---|
list[tuple[IcosphereHandle, UpdateCallback | None]]
|
List of (handle, update_callback) tuples |
Source code in openscvx/plotting/viser/animated.py
add_thrust_vector(server: viser.ViserServer, pos: np.ndarray, thrust: np.ndarray | None, attitude: np.ndarray | None = None, scale: float = 0.3, color: tuple[int, int, int] = (255, 100, 100), line_width: float = 4.0) -> tuple[viser.LineSegmentsHandle | None, UpdateCallback | None]
¶
Add an animated thrust/force vector visualization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
pos
|
ndarray
|
Position array of shape (N, 3) |
required |
thrust
|
ndarray | None
|
Thrust/force array of shape (N, 3), or None to skip |
required |
attitude
|
ndarray | None
|
Quaternion array of shape (N, 4) in [w, x, y, z] format. If provided, thrust is assumed to be in body frame and will be rotated to world frame using the attitude. |
None
|
scale
|
float
|
Scale factor for thrust vector length |
0.3
|
color
|
tuple[int, int, int]
|
RGB color tuple |
(255, 100, 100)
|
line_width
|
float
|
Line width |
4.0
|
Returns:
| Type | Description |
|---|---|
tuple[LineSegmentsHandle | None, UpdateCallback | None]
|
Tuple of (handle, update_callback), or (None, None) if thrust is None |
Source code in openscvx/plotting/viser/animated.py
add_viewcone(server: viser.ViserServer, pos: np.ndarray, attitude: np.ndarray | None, half_angle_x: float, half_angle_y: float | None = None, scale: float = 10.0, norm_type: float | str = 2, R_sb: np.ndarray | None = None, color: tuple[int, int, int] = (35, 138, 141), opacity: float = 0.4, wireframe: bool = False, n_segments: int = 32) -> tuple[viser.MeshHandle | None, UpdateCallback | None]
¶
Add an animated viewcone mesh that matches p-norm constraints.
The sensor is assumed to look along +Z in its own frame (boresight = [0,0,1]). The viewcone represents the constraint ||[x,y]||_p <= tan(alpha) * z.
Cross-section shapes by norm
- p=1: diamond
- p=2: circle/ellipse
- p>2: rounded square (superellipse)
- p=inf: square/rectangle
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
pos
|
ndarray
|
Position array of shape (N, 3) |
required |
attitude
|
ndarray | None
|
Quaternion array of shape (N, 4) in [w, x, y, z] format, or None to skip |
required |
half_angle_x
|
float
|
Half-angle of the cone in x direction (radians). For symmetric cones, this is pi/alpha_x where alpha_x is the constraint parameter. |
required |
half_angle_y
|
float | None
|
Half-angle in y direction (radians). If None, uses half_angle_x. For asymmetric constraints, this is pi/alpha_y. |
None
|
scale
|
float
|
Depth/length of the cone visualization |
10.0
|
norm_type
|
float | str
|
p-norm value (1, 2, 3, ..., or "inf" for infinity norm) |
2
|
R_sb
|
ndarray | None
|
Body-to-sensor rotation matrix (3x3). If None, sensor is aligned with body z-axis. |
None
|
color
|
tuple[int, int, int]
|
RGB color tuple |
(35, 138, 141)
|
opacity
|
float
|
Mesh opacity (0-1), ignored if wireframe=True |
0.4
|
wireframe
|
bool
|
If True, render as wireframe instead of solid |
False
|
n_segments
|
int
|
Number of segments for cone smoothness |
32
|
Returns:
| Type | Description |
|---|---|
tuple[MeshHandle | None, UpdateCallback | None]
|
Tuple of (handle, update_callback), or (None, None) if attitude is None |
Source code in openscvx/plotting/viser/animated.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
compute_grid_size(pos: np.ndarray, padding: float = 1.2) -> float
¶
Compute grid size based on trajectory extent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
ndarray
|
Position array of shape (N, 3) |
required |
padding
|
float
|
Padding factor (1.2 = 20% padding) |
1.2
|
Returns:
| Type | Description |
|---|---|
float
|
Grid size (width and height) |
Source code in openscvx/plotting/viser/server.py
compute_velocity_colors(vel: np.ndarray, cmap_name: str = 'viridis') -> np.ndarray
¶
Compute RGB colors based on velocity magnitude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vel
|
ndarray
|
Velocity array of shape (N, 3) |
required |
cmap_name
|
str
|
Matplotlib colormap name |
'viridis'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of RGB colors with shape (N, 3), values in [0, 255] |
Source code in openscvx/plotting/viser/server.py
create_server(pos: np.ndarray, dark_mode: bool = True, show_grid: bool = True) -> viser.ViserServer
¶
Create a viser server with basic scene setup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
ndarray
|
Position array for computing grid size |
required |
dark_mode
|
bool
|
Whether to use dark theme |
True
|
show_grid
|
bool
|
Whether to show the grid (default True) |
True
|
Returns:
| Type | Description |
|---|---|
ViserServer
|
ViserServer instance with grid and origin frame |
Source code in openscvx/plotting/viser/server.py
extract_propagation_positions(discretization_history: list[np.ndarray], n_x: int, n_u: int, position_slice: slice, scene_scale: float = 1.0) -> list[list[np.ndarray]]
¶
Extract 3D position trajectories from discretization history.
The discretization history contains the multi-shot integration results. Each V matrix has shape (flattened_size, n_timesteps) where: - flattened_size = (N-1) * i4 - i4 = n_x + n_x*n_x + 2*n_x*n_u (state + STM + control influence matrices) - n_timesteps = number of integration substeps
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
discretization_history
|
list[ndarray]
|
List of V matrices from each SCP iteration |
required |
n_x
|
int
|
Number of states |
required |
n_u
|
int
|
Number of controls |
required |
position_slice
|
slice
|
Slice for extracting position from state vector |
required |
scene_scale
|
float
|
Divide positions by this factor for visualization |
1.0
|
Returns:
| Type | Description |
|---|---|
list[list[ndarray]]
|
List of propagation trajectories per iteration. |
list[list[ndarray]]
|
Each iteration contains a list of (n_substeps, 3) arrays, one per segment. |