GSP Extra API Reference¶
The GSP Extra package provides additional utilities, helpers, and high-level components that extend the core GSP functionality, including animation, 3D object management, camera controls, and viewport event handling.
Overview¶
gsp_extra
¶
Bufferx Module¶
Extended buffer utilities with numpy integration.
gsp_extra.bufferx
¶
Bufferx extra module re-exporting Bufferx from gsp_matplotlib.extra.bufferx.
Object3D Module¶
3D object management with transformations, visuals, and cameras.
gsp_extra.object3d
¶
Object3D class for managing 3D objects, their transformations, visuals, and cameras.
Object3D
¶
Class representing a 3D object with transformation, visuals, and cameras.
Source code in src/gsp_extra/object3d.py
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 147 148 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 242 243 244 245 246 247 248 249 | |
cameras: list[Camera] = []
instance-attribute
¶
list of cameras attached to this Object3D.
children: list[Object3D] = []
instance-attribute
¶
list of children Object3D.
dont_update_matrix_local: bool = False
instance-attribute
¶
if True, the local matrix won't be updated.
dont_update_matrix_world: bool = False
instance-attribute
¶
if True, the world matrix won't be updated.
euler: np.ndarray = np.zeros(3, dtype=(np.float32))
instance-attribute
¶
euler angles in radians of this Object3D.
matrix_local: np.ndarray = np.eye(4, dtype=(np.float32))
instance-attribute
¶
matrix local of this Object3D
matrix_world: np.ndarray = np.eye(4, dtype=(np.float32))
instance-attribute
¶
matrix world of this Object3D
name: str = name if name is not None else f'a {self.__class__.__name__} - {self.uuid}'
instance-attribute
¶
name of this Object3D.
position: np.ndarray = np.zeros(3, dtype=(np.float32))
instance-attribute
¶
position of this Object3D.
rotation_order: str = 'XYZ'
instance-attribute
¶
rotation order for euler angles.
scale: np.ndarray = np.ones(3, dtype=(np.float32))
instance-attribute
¶
scale of this Object3D.
uuid = UuidUtils.generate_uuid()
instance-attribute
¶
uuid of the visual being wrapped.
visuals: list[VisualBase] = []
instance-attribute
¶
list of visuals attached to this Object3D.
__init__(name: str | None = None)
¶
Initialize the Object3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Optional name for the Object3D. If None, a default name is generated. |
None
|
Source code in src/gsp_extra/object3d.py
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 | |
__repr__() -> str
¶
String representation of the Object3D.
Source code in src/gsp_extra/object3d.py
62 63 64 | |
add(child: Object3D)
¶
Add a child Object3D to this Object3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
child
|
gsp_extra.object3d.Object3D
|
child to add. |
required |
Source code in src/gsp_extra/object3d.py
70 71 72 73 74 75 76 | |
attach_camera(camera: Camera)
¶
Add a camera to this Object3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera
|
gsp.core.camera.Camera
|
camera to add. |
required |
Source code in src/gsp_extra/object3d.py
110 111 112 113 114 115 116 | |
attach_visual(visual: VisualBase)
¶
Add a visual to this Object3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
visual
|
gsp.types.visual_base.VisualBase
|
visual to add. |
required |
Source code in src/gsp_extra/object3d.py
90 91 92 93 94 95 96 | |
detach_camera(camera: Camera)
¶
Remove a camera from this Object3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
camera
|
gsp.core.camera.Camera
|
camera to remove. |
required |
Source code in src/gsp_extra/object3d.py
118 119 120 121 122 123 124 | |
detach_visual(visual: VisualBase)
¶
Remove a visual from this Object3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
visual
|
gsp.types.visual_base.VisualBase
|
visual to remove. |
required |
Source code in src/gsp_extra/object3d.py
98 99 100 101 102 103 104 | |
pre_render(viewport: Viewport, scene: Object3D, camera: Camera) -> tuple[list[Viewport], list[VisualBase], list[TransBuf], list[Camera]]
staticmethod
¶
Prepare the scene for rendering by updating matrices and gathering render arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewport
|
gsp.core.Viewport
|
viewport to render to. |
required |
scene
|
gsp_extra.object3d.Object3D
|
root Object3D of the scene. |
required |
camera
|
gsp.core.camera.Camera
|
camera to use for rendering. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list[gsp.core.Viewport], list[gsp.types.visual_base.VisualBase], list[gsp.types.transbuf.TransBuf], list[gsp.core.camera.Camera]]
|
tuple[list[Viewport], list[VisualBase], list[TransBuf], list[Camera]]: viewports, visuals, model matrices and cameras. |
Source code in src/gsp_extra/object3d.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
remove(child: Object3D)
¶
Remove a child Object3D from this Object3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
child
|
gsp_extra.object3d.Object3D
|
child to remove. |
required |
Source code in src/gsp_extra/object3d.py
78 79 80 81 82 83 84 | |
to_render_args(viewport: Viewport, scene: Object3D, camera: Camera) -> tuple[list[Viewport], list[VisualBase], list[TransBuf], list[Camera]]
staticmethod
¶
Render the scene using the provided renderer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewport
|
gsp.core.Viewport
|
viewport to render to. |
required |
scene
|
gsp_extra.object3d.Object3D
|
root Object3D of the scene. |
required |
camera
|
gsp.core.camera.Camera
|
camera to use for rendering. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list[gsp.core.Viewport], list[gsp.types.visual_base.VisualBase], list[gsp.types.transbuf.TransBuf], list[gsp.core.camera.Camera]]
|
tuple[list[Viewport], list[VisualBase], list[TransBuf], list[Camera]]: viewports, visuals, model matrices and cameras. |
Source code in src/gsp_extra/object3d.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
traverse()
¶
Generator to traverse the Object3D hierarchy.
Source code in src/gsp_extra/object3d.py
130 131 132 133 134 | |
update_camera_view_matrices(scene: Object3D) -> None
staticmethod
¶
Update the view matrices of all cameras attached to the Object3D hierarchy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scene
|
gsp_extra.object3d.Object3D
|
root Object3D of the scene. |
required |
Source code in src/gsp_extra/object3d.py
193 194 195 196 197 198 199 200 201 202 203 204 | |
update_matrix_local(force_update: bool = False) -> None
¶
Upload the local matrix from position, euler and scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force_update
|
bool
|
if True, forces the update even if dont_update_matrix_local is True. Defaults to False. |
False
|
Source code in src/gsp_extra/object3d.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
update_matrix_world(parent_matrix_world: np.ndarray | None = None, force_update: bool = False) -> None
¶
Compute the world matrix from the local matrix and the parent's world matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_matrix_world
|
numpy.ndarray | None
|
parent's world matrix. Defaults to None. |
None
|
force_update
|
bool
|
if True, forces the update even if dont_update_matrix_world is True. Defaults to False. |
False
|
Source code in src/gsp_extra/object3d.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
Animator Module¶
Animation utilities for different rendering backends.
gsp_extra.animator
¶
"Animator module for GSP visualizations.
Animator Base¶
gsp_extra.animator.animator_base
¶
Abstract base class for GSP scene animators.
AnimatorBase
¶
Bases: abc.ABC
Abstract base class for GSP scene animators.
Defines the interface for animator implementations that handle frame-by-frame updates of GSP visualizations. Concrete implementations should provide renderer-specific animation loop mechanisms.
Source code in src/gsp_extra/animator/animator_base.py
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 | |
on_video_saved: Event[VideoSavedCalledback]
instance-attribute
¶
Event triggered when the video is saved.
add_callback(func: AnimatorFunc) -> None
abstractmethod
¶
Add a callback to the animation loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
gsp_extra.animator.animator_types.AnimatorFunc
|
The callback function to add. It should accept a delta_time float and return a sequence of VisualBase objects that were modified. |
required |
Source code in src/gsp_extra/animator/animator_base.py
29 30 31 32 33 34 35 36 37 | |
event_listener(func: AnimatorFunc) -> AnimatorFunc
abstractmethod
¶
Decorator to register a callback function to the animation loop.
This method should be implemented to allow decorator-style registration of animation callbacks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
gsp_extra.animator.animator_types.AnimatorFunc
|
The callback function to decorate and add to the animation loop. Should accept delta_time (float) and return a sequence of modified VisualBase objects. |
required |
Returns:
| Type | Description |
|---|---|
gsp_extra.animator.animator_types.AnimatorFunc
|
The wrapper function that will be called on each animation frame. |
Source code in src/gsp_extra/animator/animator_base.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
remove_callback(func: AnimatorFunc) -> None
abstractmethod
¶
Remove a callback from the animation loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
gsp_extra.animator.animator_types.AnimatorFunc
|
The callback function to remove. Must be the same function object that was previously added. |
required |
Source code in src/gsp_extra/animator/animator_base.py
39 40 41 42 43 44 45 46 47 | |
start(viewports: Sequence[Viewport], visuals: Sequence[VisualBase], model_matrices: Sequence[TransBuf], cameras: Sequence[Camera]) -> None
abstractmethod
¶
Start the animation loop.
Begins animating the scene using the provided viewports, visuals, model matrices, and cameras. The registered callbacks will be invoked on each frame to update the scene.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewports
|
typing.Sequence[gsp.core.viewport.Viewport]
|
Sequence of viewports to render. |
required |
visuals
|
typing.Sequence[gsp.types.visual_base.VisualBase]
|
Sequence of visual objects to animate. |
required |
model_matrices
|
typing.Sequence[gsp.types.transbuf.TransBuf]
|
Sequence of transformation buffers for the visuals. |
required |
cameras
|
typing.Sequence[gsp.core.camera.Camera]
|
Sequence of cameras for each viewport. |
required |
Source code in src/gsp_extra/animator/animator_base.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
stop() -> None
abstractmethod
¶
Stop the animation loop.
Cleans up animation state and stops any ongoing animation.
Source code in src/gsp_extra/animator/animator_base.py
81 82 83 84 85 86 87 | |
Animator Matplotlib¶
gsp_extra.animator.animator_matplotlib
¶
Matplotlib-based animator for GSP scenes.
Provides animation capabilities using a MatplotlibRenderer backend with support for real-time animation display and video export.
AnimatorMatplotlib
¶
Bases: gsp_extra.animator.animator_base.AnimatorBase
Animator for GSP scenes using a Matplotlib renderer.
Manages animation loops with callback functions that update visuals each frame. Supports real-time display and video export in various formats. Uses Matplotlib's FuncAnimation for efficient rendering updates.
Source code in src/gsp_extra/animator/animator_matplotlib.py
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 147 148 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 242 243 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 334 335 336 337 338 339 340 | |
on_video_saved = Event[VideoSavedCalledback]()
instance-attribute
¶
Event triggered when the video has been successfully saved to disk.
__init__(matplotlib_renderer: MatplotlibRenderer, fps: int = 50, video_duration: float = 10.0, video_path: str | None = None, video_writer: str | None = None)
¶
Initialize the Matplotlib animator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matplotlib_renderer
|
gsp_matplotlib.renderer.MatplotlibRenderer
|
The Matplotlib renderer to use for rendering frames. |
required |
fps
|
int
|
Target frames per second for the animation. |
50
|
video_duration
|
float
|
Total duration of the animation in seconds. |
10.0
|
video_path
|
str | None
|
Path where the video should be saved. If None, no video is saved. |
None
|
video_writer
|
str | None
|
Video writer to use ("ffmpeg" or "pillow"). If None, auto-detected from extension. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the video format is not supported. |
Source code in src/gsp_extra/animator/animator_matplotlib.py
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 | |
add_callback(func: AnimatorFunc) -> None
¶
Add a callback to the animation loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
gsp_extra.animator.animator_types.AnimatorFunc
|
The animator function to call on each frame. |
required |
Source code in src/gsp_extra/animator/animator_matplotlib.py
101 102 103 104 105 106 107 | |
event_listener(func: AnimatorFunc) -> AnimatorFunc
¶
Decorator to add a callback to the animation loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
gsp_extra.animator.animator_types.AnimatorFunc
|
The animator function to register as a callback. |
required |
Returns:
| Type | Description |
|---|---|
gsp_extra.animator.animator_types.AnimatorFunc
|
The wrapped animator function. |
Usage
@animation_loop.event_listener
def my_callback(delta_time: float) -> Sequence[VisualBase]:
...
# later, if needed
animation_loop.remove_callback(my_callback)
Source code in src/gsp_extra/animator/animator_matplotlib.py
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 | |
remove_callback(func: AnimatorFunc) -> None
¶
Remove a callback from the animation loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
gsp_extra.animator.animator_types.AnimatorFunc
|
The animator function to remove. |
required |
Source code in src/gsp_extra/animator/animator_matplotlib.py
109 110 111 112 113 114 115 | |
start(viewports: Sequence[Viewport], visuals: Sequence[VisualBase], model_matrices: Sequence[TransBuf], cameras: Sequence[Camera]) -> None
¶
Start the animation loop.
Begins rendering frames using registered callbacks to update visuals. In test mode (GSP_TEST=True), saves a single preview image instead of animating.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewports
|
typing.Sequence[gsp.core.viewport.Viewport]
|
Sequence of viewport regions to render into. |
required |
visuals
|
typing.Sequence[gsp.types.visual_base.VisualBase]
|
Sequence of visual elements to render and animate. |
required |
model_matrices
|
typing.Sequence[gsp.types.transbuf.TransBuf]
|
Sequence of model transformation matrices. |
required |
cameras
|
typing.Sequence[gsp.core.camera.Camera]
|
Sequence of cameras defining view and projection. |
required |
Source code in src/gsp_extra/animator/animator_matplotlib.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 | |
stop()
¶
Stop the animation loop.
Stops the Matplotlib animation timer and clears internal state.
Source code in src/gsp_extra/animator/animator_matplotlib.py
230 231 232 233 234 235 236 237 238 239 240 241 242 | |
Animator Datoviz¶
gsp_extra.animator.animator_datoviz
¶
Animator for GSP scenes using a matplotlib renderer.
AnimatorDatoviz
¶
Bases: gsp_extra.animator.animator_base.AnimatorBase
Animator for GSP scenes using a matplotlib renderer.
Source code in src/gsp_extra/animator/animator_datoviz.py
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 147 148 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 | |
on_video_saved = Event[VideoSavedCalledback]()
instance-attribute
¶
Event triggered when the video is saved.
__init__(datoviz_renderer: DatovizRenderer, fps: int = 50, video_duration: float | None = None, video_path: str | None = None)
¶
Initialize the animator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datoviz_renderer
|
gsp_datoviz.renderer.datoviz_renderer.DatovizRenderer
|
The datoviz renderer to use for rendering. |
required |
fps
|
int
|
Frames per second. Defaults to 50. |
50
|
video_duration
|
float | None
|
Duration of the video to save. Defaults to None. |
None
|
video_path
|
str | None
|
Path to save the video. Defaults to None. |
None
|
Source code in src/gsp_extra/animator/animator_datoviz.py
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 | |
add_callback(func: AnimatorFunc) -> None
¶
Add a callback to the animation loop.
Source code in src/gsp_extra/animator/animator_datoviz.py
63 64 65 | |
event_listener(func: AnimatorFunc) -> AnimatorFunc
¶
A decorator to add a callback to the animation loop.
Usage
@animation_loop.event_listener
def my_callback(delta_time: float) -> Sequence[Object3D]:
...
# later, if needed
animation_loop.remove_callback(my_callback)
Source code in src/gsp_extra/animator/animator_datoviz.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
remove_callback(func: AnimatorFunc) -> None
¶
Remove a callback from the animation loop.
Source code in src/gsp_extra/animator/animator_datoviz.py
67 68 69 | |
start(viewports: Sequence[Viewport], visuals: Sequence[VisualBase], model_matrices: Sequence[TransBuf], cameras: Sequence[Camera]) -> None
¶
Animate the given canvas and camera using the provided callbacks to update visuals.
Source code in src/gsp_extra/animator/animator_datoviz.py
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 147 148 149 150 151 152 153 154 155 156 157 158 | |
stop()
¶
Stop the animation.
Source code in src/gsp_extra/animator/animator_datoviz.py
163 164 165 166 167 168 169 | |
Animator Network¶
gsp_extra.animator.animator_network
¶
Network-based animator for GSP scenes.
Provides animation capabilities using a NetworkRenderer backend with support for real-time animation display and video export.
AnimatorNetwork
¶
Bases: gsp_extra.animator.animator_base.AnimatorBase
Animator for GSP scenes using a network renderer.
Manages animation loops with callback functions that update visuals each frame. Supports real-time display and video export in various formats.
Source code in src/gsp_extra/animator/animator_network.py
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 147 148 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 242 243 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 | |
on_video_saved = Event[VideoSavedCalledback]()
instance-attribute
¶
Event triggered when the video has been successfully saved to disk.
__init__(network_renderer: NetworkRenderer, fps: int = 50, video_duration: float = 10.0, video_path: str | None = None, video_writer: str | None = None)
¶
Initialize the network animator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_renderer
|
gsp_network.renderer.NetworkRenderer
|
The network renderer to use for rendering frames. |
required |
fps
|
int
|
Target frames per second for the animation. |
50
|
video_duration
|
float
|
Total duration of the animation in seconds. |
10.0
|
video_path
|
str | None
|
Path where the video should be saved. If None, no video is saved. |
None
|
video_writer
|
str | None
|
Video writer to use ("ffmpeg" or "pillow"). If None, auto-detected from extension. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the video format is not supported. |
Source code in src/gsp_extra/animator/animator_network.py
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 | |
add_callback(func: AnimatorFunc) -> None
¶
Add a callback to the animation loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
gsp_extra.animator.animator_types.AnimatorFunc
|
The animator function to call on each frame. |
required |
Source code in src/gsp_extra/animator/animator_network.py
94 95 96 97 98 99 100 | |
event_listener(func: AnimatorFunc) -> AnimatorFunc
¶
Decorator to add a callback to the animation loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
gsp_extra.animator.animator_types.AnimatorFunc
|
The animator function to register as a callback. |
required |
Returns:
| Type | Description |
|---|---|
gsp_extra.animator.animator_types.AnimatorFunc
|
The wrapped animator function. |
Usage
@animation_loop.event_listener
def my_callback(delta_time: float) -> Sequence[VisualBase]:
...
# later, if needed
animation_loop.remove_callback(my_callback)
Source code in src/gsp_extra/animator/animator_network.py
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 | |
remove_callback(func: AnimatorFunc) -> None
¶
Remove a callback from the animation loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
gsp_extra.animator.animator_types.AnimatorFunc
|
The animator function to remove. |
required |
Source code in src/gsp_extra/animator/animator_network.py
102 103 104 105 106 107 108 | |
start(viewports: Sequence[Viewport], visuals: Sequence[VisualBase], model_matrices: Sequence[TransBuf], cameras: Sequence[Camera]) -> None
¶
Start the animation loop.
Begins rendering frames using registered callbacks to update visuals. In test mode (GSP_TEST=True), saves a single preview image instead of animating.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
viewports
|
typing.Sequence[gsp.core.viewport.Viewport]
|
Sequence of viewport regions to render into. |
required |
visuals
|
typing.Sequence[gsp.types.visual_base.VisualBase]
|
Sequence of visual elements to render and animate. |
required |
model_matrices
|
typing.Sequence[gsp.types.transbuf.TransBuf]
|
Sequence of model transformation matrices. |
required |
cameras
|
typing.Sequence[gsp.core.camera.Camera]
|
Sequence of cameras defining view and projection. |
required |
Source code in src/gsp_extra/animator/animator_network.py
142 143 144 145 146 147 148 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 | |
stop()
¶
Stop the animation loop.
Stops the Matplotlib animation timer and clears internal state.
Source code in src/gsp_extra/animator/animator_network.py
223 224 225 226 227 228 229 230 231 232 233 234 235 | |
Animator Types¶
gsp_extra.animator.animator_types
¶
Type definitions for the animator module.
This module defines callback protocols and type aliases used by the animator for managing animation loops and video saving operations.
AnimatorFunc = Callable[[float], Sequence[VisualBase]]
module-attribute
¶
Type alias for animation callback functions.
An animator function is called on each frame of the animation with the elapsed time since the last frame in milliseconds, and returns a sequence of VisualBase objects to render in the current frame.
VideoSavedCalledback
¶
Bases: typing.Protocol
Callback protocol for video saved event.
Source code in src/gsp_extra/animator/animator_types.py
24 25 26 27 28 29 | |
__call__() -> None
¶
Called when the video has been successfully saved.
Source code in src/gsp_extra/animator/animator_types.py
27 28 29 | |
Camera Controls Module¶
Camera control utilities for interactive 3D navigation.
Object Controls AWSD¶
gsp_extra.camera_controls.object_controls_awsd
¶
Implements camera controls using AWSD keys for movement and mouse for orientation.
ObjectControlAwsd
¶
Implements camera controls using AWSD keys for movement and mouse for orientation.
Source code in src/gsp_extra/camera_controls/object_controls_awsd.py
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 | |
__init__(model_matrix_buffer: Buffer, viewport_events: ViewportEventsBase)
¶
Initialize the ObjectControlAwsd.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_matrix_buffer
|
gsp.types.buffer.Buffer
|
The buffer containing the model matrix to control. |
required |
viewport_events
|
gsp_extra.viewport_events.viewport_events_base.ViewportEventsBase
|
The viewport events to subscribe to for keyboard input. |
required |
Source code in src/gsp_extra/camera_controls/object_controls_awsd.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
close()
¶
Unsubscribe from events.
Source code in src/gsp_extra/camera_controls/object_controls_awsd.py
41 42 43 44 | |
Object Controls Trackball¶
gsp_extra.camera_controls.object_controls_trackball
¶
Implements camera controls using AWSD keys for movement and mouse for orientation.
ObjectControlsTrackball
¶
Implements camera controls using AWSD keys for movement and mouse for orientation.
Source code in src/gsp_extra/camera_controls/object_controls_trackball.py
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 | |
__init__(model_matrix_buffer: Buffer, viewport_events: ViewportEventsBase)
¶
Initialize the ObjectControlsTrackball.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_matrix_buffer
|
gsp.types.buffer.Buffer
|
The buffer containing the model matrix to control. |
required |
viewport_events
|
gsp_extra.viewport_events.viewport_events_base.ViewportEventsBase
|
The viewport events to subscribe to for mouse input. |
required |
Source code in src/gsp_extra/camera_controls/object_controls_trackball.py
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 | |
close()
¶
Unsubscribe from events.
Source code in src/gsp_extra/camera_controls/object_controls_trackball.py
44 45 46 47 48 | |
Miscellaneous Module¶
Various utility helpers and render item definitions.
Render Item¶
gsp_extra.misc.render_item
¶
Render item definition.
RenderItem
dataclass
¶
Render item is a dataclasss containing all necessary information for rendering a visual in a viewport.
Source code in src/gsp_extra/misc/render_item.py
13 14 15 16 17 18 19 20 21 22 23 24 | |
camera: Camera
instance-attribute
¶
Camera used for rendering the visual.
model_matrix: Buffer
instance-attribute
¶
Model matrix for transforming the visual.
viewport: Viewport
instance-attribute
¶
Viewport where the visual will be rendered.
visual_base: VisualBase
instance-attribute
¶
Visual to be rendered.
Colorama Utils¶
gsp_extra.misc.colorama_utils
¶
Colorama utility functions.
text_cyan(text: str) -> str
¶
Return the given text string colored in cyan.
Source code in src/gsp_extra/misc/colorama_utils.py
10 11 12 | |
text_magenta(text: str) -> str
¶
Return the given text string colored in magenta.
Source code in src/gsp_extra/misc/colorama_utils.py
15 16 17 | |
MPL3D Module¶
3D mathematics utilities for graphics operations.
GLM¶
gsp_extra.mpl3d.glm
¶
OpenGL Mathematics (GLM) utilities for numpy.
This module provides mathematical functions commonly used in 3D graphics, including matrix transformations, projections, rotations, and vector operations. All operations are implemented using numpy for efficient computation.
align(U: np.ndarray, V: np.ndarray, dtype: np.dtype = np.dtype(np.float32)) -> np.ndarray
¶
Return the rotation matrix that aligns vector U to vector V.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
U
|
numpy.ndarray
|
First vector |
required |
V
|
numpy.ndarray
|
Second vector |
required |
dtype
|
numpy.dtype
|
dtype of the resulting array |
numpy.dtype(numpy.float32)
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: Rotation matrix |
Source code in src/gsp_extra/mpl3d/glm.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
camera(xrotation: float = 25.0, yrotation: float = 45.0, zoom: float = 1.0, mode: Literal['perspective', 'ortho'] = 'perspective') -> np.ndarray
¶
Create a camera transformation matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xrotation
|
float
|
Rotation around the X axis in degrees. |
25.0
|
yrotation
|
float
|
Rotation around the Y axis in degrees. |
45.0
|
zoom
|
float
|
Zoom factor. |
1.0
|
mode
|
typing.Literal['perspective', 'ortho']
|
Camera mode. |
'perspective'
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: Camera matrix |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unknown camera mode is provided. |
Source code in src/gsp_extra/mpl3d/glm.py
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 | |
center(vertices: np.ndarray) -> np.ndarray
¶
Center vertices around the origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
numpy.ndarray
|
Vertices to center |
required |
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: vertices centered |
Source code in src/gsp_extra/mpl3d/glm.py
245 246 247 248 249 250 251 252 253 254 255 256 | |
clamp(V: np.ndarray, vmin: float = 0, vmax: float = 1) -> np.ndarray
¶
Clamp values between minimum and maximum bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
V
|
numpy.ndarray
|
Array of values to clamp. |
required |
vmin
|
float
|
Minimum value (default: 0). |
0
|
vmax
|
float
|
Maximum value (default: 1). |
1
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
Array with values clamped to [vmin, vmax]. |
Source code in src/gsp_extra/mpl3d/glm.py
27 28 29 30 31 32 33 34 35 36 37 38 | |
fit(vertices: np.ndarray) -> np.ndarray
¶
Fit vertices to the normalized cube.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
numpy.ndarray
|
Vertices to fit |
required |
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: vertices contained in the normalize cube |
Source code in src/gsp_extra/mpl3d/glm.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
frontback(triangles: np.ndarray) -> tuple[np.ndarray, np.ndarray]
¶
Sort front and back facing triangles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
triangles
|
numpy.ndarray
|
Triangles to sort |
required |
Returns:
| Type | Description |
|---|---|
tuple[numpy.ndarray, numpy.ndarray]
|
tuple[np.ndarray, np.ndarray]: front and back facing triangles as (n1,3) and (n2,3) arrays (n1+n2=n) |
Source code in src/gsp_extra/mpl3d/glm.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
frustum(left: float, right: float, bottom: float, top: float, znear: float, zfar: float, dtype: np.dtype = np.dtype(np.float32)) -> np.ndarray
¶
Create a view frustum projection matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
float
|
Left coordinate of the field of view. |
required |
right
|
float
|
Right coordinate of the field of view. |
required |
bottom
|
float
|
Bottom coordinate of the field of view. |
required |
top
|
float
|
Top coordinate of the field of view. |
required |
znear
|
float
|
Near coordinate of the field of view. |
required |
zfar
|
float
|
Far coordinate of the field of view. |
required |
dtype
|
numpy.dtype
|
dtype of the resulting array |
numpy.dtype(numpy.float32)
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: View frustum matrix |
Source code in src/gsp_extra/mpl3d/glm.py
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 | |
lookat(eye: tuple[float, float, float] = (0, 0, 4.5), center: tuple[float, float, float] = (0, 0, 0), up: tuple[float, float, float] = (0, 0, 1), dtype: np.dtype = np.dtype(np.float32)) -> np.ndarray
¶
Create a viewing matrix derived from an eye point, reference point, and up vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eye
|
tuple[float, float, float]
|
Eye point |
(0, 0, 4.5)
|
center
|
tuple[float, float, float]
|
Reference point |
(0, 0, 0)
|
up
|
tuple[float, float, float]
|
Up vector |
(0, 0, 1)
|
dtype
|
numpy.dtype
|
dtype of the resulting array |
numpy.dtype(numpy.float32)
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: View matrix |
Source code in src/gsp_extra/mpl3d/glm.py
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 | |
normalize(V: np.ndarray) -> np.ndarray
¶
Normalize a vector or array of vectors to unit length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
V
|
numpy.ndarray
|
Vector or array of vectors to normalize. |
required |
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
Normalized vector(s) with unit length. |
Source code in src/gsp_extra/mpl3d/glm.py
15 16 17 18 19 20 21 22 23 24 | |
ortho(left: float, right: float, bottom: float, top: float, znear: float, zfar: float, dtype: np.dtype = np.dtype(np.float32)) -> np.ndarray
¶
Create an orthographic projection matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
float
|
Left coordinate of the field of view. |
required |
right
|
float
|
Right coordinate of the field of view. |
required |
bottom
|
float
|
Bottom coordinate of the field of view. |
required |
top
|
float
|
Top coordinate of the field of view. |
required |
znear
|
float
|
Near coordinate of the field of view. |
required |
zfar
|
float
|
Far coordinate of the field of view. |
required |
dtype
|
numpy.dtype
|
dtype of the resulting array |
numpy.dtype(numpy.float32)
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: Orthographic projection matrix |
Source code in src/gsp_extra/mpl3d/glm.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
perspective(fovy: float, aspect: float, znear: float, zfar: float, dtype: np.dtype = np.dtype(np.float32)) -> np.ndarray
¶
Create a perspective projection matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fovy
|
float
|
The field of view along the y axis. |
required |
aspect
|
float
|
Aspect ratio of the view. |
required |
znear
|
float
|
Near coordinate of the field of view. |
required |
zfar
|
float
|
Far coordinate of the field of view. |
required |
dtype
|
numpy.dtype
|
dtype of the resulting array |
numpy.dtype(numpy.float32)
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: Perspective projection matrix |
Source code in src/gsp_extra/mpl3d/glm.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
rotate(angle: float, axis: np.ndarray, dtype: np.dtype = np.dtype(np.float32)) -> np.ndarray
¶
Create a rotation matrix around an arbitrary axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angle
|
float
|
Specifies the angle of rotation, in degrees. |
required |
axis
|
numpy.ndarray
|
Axis of rotation |
required |
dtype
|
numpy.dtype
|
dtype of the resulting array |
numpy.dtype(numpy.float32)
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: Rotation matrix |
Source code in src/gsp_extra/mpl3d/glm.py
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 | |
scale(scale: np.ndarray, dtype: np.dtype = np.dtype(np.float32)) -> np.ndarray
¶
Create a non-uniform scaling matrix along the x, y, and z axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
numpy.ndarray
|
Scaling vector |
required |
dtype
|
numpy.dtype
|
dtype of the resulting array |
numpy.dtype(numpy.float32)
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: Scaling matrix |
Source code in src/gsp_extra/mpl3d/glm.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
translate(translate: np.ndarray, dtype: np.dtype = np.dtype(np.float32)) -> np.ndarray
¶
Create a translation matrix by a given vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
translate
|
numpy.ndarray
|
Translation vector. |
required |
dtype
|
numpy.dtype
|
dtype of the resulting array |
numpy.dtype(numpy.float32)
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: Translation matrix |
Source code in src/gsp_extra/mpl3d/glm.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
viewport(x: int, y: int, w: int, h: int, d: float, dtype: np.dtype = np.dtype(np.float32)) -> np.ndarray
¶
Create a viewport transformation matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
X origin (pixels) of the viewport (lower left) |
required |
y
|
int
|
Y origin (pixels) of the viewport (lower left) |
required |
w
|
int
|
Width (pixels) of the viewport |
required |
h
|
int
|
Height (pixels) of the viewport |
required |
d
|
float
|
Depth of the viewport. |
required |
dtype
|
numpy.dtype
|
dtype of the resulting array |
numpy.dtype(numpy.float32)
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: Viewport matrix |
Source code in src/gsp_extra/mpl3d/glm.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
xrotate(angle_x: float = 0.0, dtype: np.dtype = np.dtype(np.float32)) -> np.ndarray
¶
Create a rotation matrix about the X axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angle_x
|
float
|
Specifies the angle of rotation, in degrees. |
0.0
|
dtype
|
numpy.dtype
|
dtype of the resulting array |
numpy.dtype(numpy.float32)
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: Rotation matrix |
Source code in src/gsp_extra/mpl3d/glm.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
yrotate(angle_y: float = 0.0, dtype: np.dtype = np.dtype(np.float32)) -> np.ndarray
¶
Create a rotation matrix about the Y axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angle_y
|
float
|
Specifies the angle of rotation, in degrees. |
0.0
|
dtype
|
numpy.dtype
|
dtype of the resulting array |
numpy.dtype(numpy.float32)
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: Rotation matrix |
Source code in src/gsp_extra/mpl3d/glm.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
zrotate(angle_z: float = 0.0, dtype: np.dtype = np.dtype(np.float32)) -> np.ndarray
¶
Create a rotation matrix about the Z axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angle_z
|
float
|
Specifies the angle of rotation, in degrees. |
0.0
|
dtype
|
numpy.dtype
|
dtype of the resulting array |
numpy.dtype(numpy.float32)
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
np.ndarray: Rotation matrix |
Source code in src/gsp_extra/mpl3d/glm.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
Trackball¶
gsp_extra.mpl3d.trackball
¶
Provides a virtual trackball for 3D scene viewing.
Example usage:
trackball = Trackball(45,30)
@window.event def on_mouse_drag(x, y, dx, dy, button): trackball.drag(x,y,dx,dy)
@window.event def on_resize(width,height): glViewport(0, 0, window.width, window.height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45, window.width / float(window.height), .1, 1000) glMatrixMode (GL_MODELVIEW) glLoadIdentity () glTranslatef (0, 0, -3) glMultMatrixf(trackball.model)
You can also set trackball orientation directly by setting theta and phi value expressed in degrees. Theta relates to the rotation angle around X axis while phi relates to the rotation angle around Z axis.
Trackball
¶
Bases: object
Virtual trackball for 3D scene viewing.
Source code in src/gsp_extra/mpl3d/trackball.py
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 341 342 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 | |
model: np.ndarray
property
¶
Model transformation (read-only).
Returns:
| Type | Description |
|---|---|
numpy.ndarray
|
The current model transformation matrix as a 4x4 numpy array. |
phi
property
writable
¶
Angle (in degrees) around the x axis.
theta
property
writable
¶
Angle (in degrees) around the z axis.
__init__(theta: float = 0, phi: float = 0)
¶
Build a new trackball with specified view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta
|
float
|
Initial rotation angle around the X axis in degrees. |
0
|
phi
|
float
|
Initial rotation angle around the Z axis in degrees. |
0
|
Source code in src/gsp_extra/mpl3d/trackball.py
289 290 291 292 293 294 295 296 297 298 299 300 301 | |
drag_to(x: float, y: float, dx: float, dy: float)
¶
Move trackball view from x,y to x+dx,y+dy.
Updates the trackball rotation based on mouse drag movement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Current x position in normalized coordinates [-1, 1]. |
required |
y
|
float
|
Current y position in normalized coordinates [-1, 1]. |
required |
dx
|
float
|
Change in x position. |
required |
dy
|
float
|
Change in y position. |
required |
Source code in src/gsp_extra/mpl3d/trackball.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
Transform Links Module¶
Transform link utilities for loading and network operations.
gsp_extra.transform_links
¶
"TransformLink that loads data from a URI into a Buffer.
Transform Load¶
gsp_extra.transform_links.transform_load
¶
TransformLink that loads data from a URI into a Buffer.
TransformLoad
¶
Bases: gsp.transforms.transform_link_base.TransformLinkBase
Load data from a URI into a Buffer. previous buffer is ignored.
Source code in src/gsp_extra/transform_links/transform_load.py
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 | |
__init__(uri: str, buffer_type: BufferType) -> None
¶
Initialize the TransformLoad.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
The URI to load data from. |
required |
buffer_type
|
gsp.types.buffer_type.BufferType
|
The type of buffer to create. |
required |
Source code in src/gsp_extra/transform_links/transform_load.py
25 26 27 28 29 30 31 32 33 | |
apply(buffer_src: Buffer | None) -> Buffer
¶
Load data from the URI into a new Buffer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buffer_src
|
gsp.types.buffer.Buffer | None
|
Ignored. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Buffer |
gsp.types.buffer.Buffer
|
The loaded buffer. |
Source code in src/gsp_extra/transform_links/transform_load.py
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 | |
deserialize(data: dict[str, Any]) -> TransformLoad
staticmethod
¶
Deserialize a TransformLoad from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, typing.Any]
|
The serialized TransformLoad. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TransformLoad |
gsp_extra.transform_links.transform_load.TransformLoad
|
The deserialized TransformLoad instance. |
Source code in src/gsp_extra/transform_links/transform_load.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
serialize() -> dict[str, Any]
¶
Serialize the TransformLoad to a dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, typing.Any]
|
dict[str, Any]: The serialized TransformLoad. |
Source code in src/gsp_extra/transform_links/transform_load.py
102 103 104 105 106 107 108 109 110 111 112 113 114 | |
Transform Network Server¶
gsp_extra.transform_links.transform_network_server
¶
Starts a network server with user-space transforms registered.
Viewport Events Module¶
Viewport event handling for user interactions.
Viewport Events Base¶
gsp_extra.viewport_events.viewport_events_base
¶
Base class for viewport event handlers.
ViewportEventsBase
¶
Bases: abc.ABC
Base class for window event handlers for camera controls.
Source code in src/gsp_extra/viewport_events/viewport_events_base.py
10 11 12 13 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 | |
button_press_event: Event[MouseEventCallback]
instance-attribute
¶
Event triggered on mouse button press
button_release_event: Event[MouseEventCallback]
instance-attribute
¶
Event triggered on mouse button release
canvas_resize_event: Event[CanvasResizeEventCallback]
instance-attribute
¶
Event triggered on canvas resize
key_press_event: Event[KeyboardEventCallback]
instance-attribute
¶
Event triggered on key press
key_release_event: Event[KeyboardEventCallback]
instance-attribute
¶
Event triggered on key release
mouse_move_event: Event[MouseEventCallback]
instance-attribute
¶
Event triggered on mouse move
mouse_scroll_event: Event[MouseEventCallback]
instance-attribute
¶
Event triggered on mouse scroll
Viewport Events Matplotlib¶
gsp_extra.viewport_events.viewport_events_matplotlib
¶
MatplotlibRenderer event handler for viewport events.
ViewportEventsMatplotlib
¶
Bases: gsp_extra.viewport_events.viewport_events_base.ViewportEventsBase
MatplotlibRenderer event handler for viewport.
Source code in src/gsp_extra/viewport_events/viewport_events_matplotlib.py
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 147 148 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 | |
__init__(renderer: MatplotlibRenderer, viewport: Viewport) -> None
¶
Initialize the Matplotlib viewport event handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
renderer
|
gsp_matplotlib.renderer.MatplotlibRenderer
|
MatplotlibRenderer associated with this event handler. |
required |
viewport
|
gsp.core.Viewport
|
Viewport associated with this event handler. |
required |
Source code in src/gsp_extra/viewport_events/viewport_events_matplotlib.py
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 | |
close()
¶
Close the event handler and release resources.
Source code in src/gsp_extra/viewport_events/viewport_events_matplotlib.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
Viewport Events Datoviz¶
gsp_extra.viewport_events.viewport_events_datoviz
¶
DatovizRenderer event handler for viewport events.
ViewportEventsDatoviz
¶
Bases: gsp_extra.viewport_events.viewport_events_base.ViewportEventsBase
DatovizRenderer event handler for viewport.
Source code in src/gsp_extra/viewport_events/viewport_events_datoviz.py
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 147 148 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 | |
__init__(renderer: DatovizRenderer, viewport: Viewport) -> None
¶
Initialize the Datoviz viewport event handler.
Source code in src/gsp_extra/viewport_events/viewport_events_datoviz.py
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 147 148 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 | |
close()
¶
Close the event handler and release resources.
Source code in src/gsp_extra/viewport_events/viewport_events_datoviz.py
179 180 181 182 | |
Viewport Events Network¶
gsp_extra.viewport_events.viewport_events_network
¶
"NetworkRenderer event handler for viewport events.
ViewportEventsNetwork
¶
Bases: gsp_extra.viewport_events.viewport_events_base.ViewportEventsBase
NetworkRenderer event handler for viewport.
Code heavily inspired from ViewportEventsMatplotlib
Source code in src/gsp_extra/viewport_events/viewport_events_network.py
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 147 148 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 | |
__init__(renderer: NetworkRenderer, viewport: Viewport) -> None
¶
Initialize the event handler with a renderer and viewport.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
renderer
|
gsp_network.renderer.NetworkRenderer
|
NetworkRenderer associated with this event handler. |
required |
viewport
|
gsp.core.Viewport
|
Viewport associated with this event handler. |
required |
Source code in src/gsp_extra/viewport_events/viewport_events_network.py
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 | |
close()
¶
Close the event handler and release resources.
Source code in src/gsp_extra/viewport_events/viewport_events_network.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
Viewport Events Types¶
gsp_extra.viewport_events.viewport_events_types
¶
Viewport Event Types and Callback Protocols.
CanvasResizeEvent
dataclass
¶
Represents a canvas resize event.
Attributes:
| Name | Type | Description |
|---|---|---|
viewport_uuid |
str
|
The unique identifier of the viewport affected by the resize. |
event_type |
gsp_extra.viewport_events.viewport_events_types.EventType
|
The type of event (CANVAS_RESIZE). |
canvas_width_px |
int
|
The new width of the canvas in pixels. |
canvas_height_px |
int
|
The new height of the canvas in pixels. |
Source code in src/gsp_extra/viewport_events/viewport_events_types.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
CanvasResizeEventCallback
¶
Bases: typing.Protocol
Protocol for canvas resize event callback functions.
Defines the signature for functions that handle canvas resize events.
Source code in src/gsp_extra/viewport_events/viewport_events_types.py
101 102 103 104 105 106 107 108 109 | |
__call__(canvas_resize_event: CanvasResizeEvent) -> None
¶
Handle a canvas resize event.
Source code in src/gsp_extra/viewport_events/viewport_events_types.py
107 108 109 | |
EventType
¶
Bases: enum.StrEnum
Enumeration of viewport event types.
Defines the different types of user interaction events that can occur in a viewport, including keyboard, mouse, and canvas events.
Source code in src/gsp_extra/viewport_events/viewport_events_types.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
KeyEvent
dataclass
¶
Represents a keyboard event in a viewport.
Attributes:
| Name | Type | Description |
|---|---|---|
viewport_uuid |
str
|
The unique identifier of the viewport where the event occurred. |
event_type |
gsp_extra.viewport_events.viewport_events_types.EventType
|
The type of keyboard event (KEY_PRESS or KEY_RELEASE). |
key_name |
str
|
The name of the key that was pressed or released. |
Source code in src/gsp_extra/viewport_events/viewport_events_types.py
25 26 27 28 29 30 31 32 33 34 35 36 37 | |
KeyboardEventCallback
¶
Bases: typing.Protocol
Protocol for keyboard event callback functions.
Defines the signature for functions that handle keyboard events.
Source code in src/gsp_extra/viewport_events/viewport_events_types.py
80 81 82 83 84 85 86 87 | |
__call__(key_event: KeyEvent) -> None
¶
Handle a keyboard event.
Source code in src/gsp_extra/viewport_events/viewport_events_types.py
86 87 | |
MouseEvent
dataclass
¶
Represents a mouse event in a viewport.
Source code in src/gsp_extra/viewport_events/viewport_events_types.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
event_type: EventType
instance-attribute
¶
The type of mouse event (BUTTON_PRESS, BUTTON_RELEASE, MOUSE_MOVE, or MOUSE_SCROLL)
left_button: bool = False
class-attribute
instance-attribute
¶
Whether the left mouse button is pressed.
middle_button: bool = False
class-attribute
instance-attribute
¶
Whether the middle mouse button is pressed.
right_button: bool = False
class-attribute
instance-attribute
¶
Whether the right mouse button is pressed.
scroll_steps: float = 0.0
class-attribute
instance-attribute
¶
The number of scroll steps (positive for up, negative for down).
viewport_uuid: str
instance-attribute
¶
The unique identifier of the viewport where the event occurred.
x_ndc: float
instance-attribute
¶
The x-coordinate of the mouse position in the viewport in NDC units.
y_ndc: float
instance-attribute
¶
The y-coordinate of the mouse position in the viewport in NDC units.
MouseEventCallback
¶
Bases: typing.Protocol
Protocol for mouse event callback functions.
Defines the signature for functions that handle mouse events.
Source code in src/gsp_extra/viewport_events/viewport_events_types.py
90 91 92 93 94 95 96 97 98 | |
__call__(mouse_event: MouseEvent) -> None
¶
Handle a mouse event.
Source code in src/gsp_extra/viewport_events/viewport_events_types.py
96 97 98 | |