napari utilities
napari_threedee.utils.napari_utils
get_napari_visual(viewer, layer)
Get the visual class for a given layer
PARAMETER | DESCRIPTION |
---|---|
viewer
|
The napari viewer object
|
layer
|
The napari layer object for which to find the visual.
|
RETURNS | DESCRIPTION |
---|---|
visual
|
The napari visual class for the layer. |
Source code in src/napari_threedee/utils/napari_utils.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
get_vispy_layer_node(viewer: napari.Viewer, layer)
Get the vispy node associated with a layer
Source code in src/napari_threedee/utils/napari_utils.py
47 48 49 50 51 52 53 54 |
|
get_vispy_root_node(viewer: napari.Viewer, layer)
Get the vispy node at the root of the scene graph.
This is the node that layers are added to.
Source code in src/napari_threedee/utils/napari_utils.py
57 58 59 60 61 62 63 |
|
get_mouse_position_in_displayed_dimensions(event) -> np.ndarray
Get the position under the mouse in scene (displayed world) coordinates.
PARAMETER | DESCRIPTION |
---|---|
event
|
The mouse event.
|
RETURNS | DESCRIPTION |
---|---|
click_dir_data_3d
|
The click direction in displayed data coordiantes
TYPE:
|
Source code in src/napari_threedee/utils/napari_utils.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
get_view_direction_in_displayed_dimensions(event) -> np.ndarray
Get the view direction under the mouse in scene (displayed world) coordinates.
PARAMETER | DESCRIPTION |
---|---|
event
|
napari mouse event.
|
Source code in src/napari_threedee/utils/napari_utils.py
121 122 123 124 125 126 127 128 129 130 |
|
get_mouse_position_in_displayed_layer_data_coordinates(layer, event) -> Tuple[np.ndarray, np.ndarray]
Get the mouse click position and direction in layer data displayed coordinates.
PARAMETER | DESCRIPTION |
---|---|
layer
|
The layer to convert the coordinates to.
TYPE:
|
event
|
The mouse event.
|
RETURNS | DESCRIPTION |
---|---|
click_position_data_3d
|
The click position in displayed data coordinates.
TYPE:
|
click_dir_data_3d
|
The click direction in displayed data coordiantes
TYPE:
|
Source code in src/napari_threedee/utils/napari_utils.py
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 |
|
data_to_world_ray(vector, layer)
Convert a vector defining an orientation from data coordinates to world coordinates. For example, this would be used to convert the view ray.
PARAMETER | DESCRIPTION |
---|---|
vector
|
A vector in data coordinates.
TYPE:
|
layer
|
The napari layer to get the transform from.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
Transformed vector in data coordinates. |
Source code in src/napari_threedee/utils/napari_utils.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
data_to_world_normal(vector, layer)
Convert a normal vector defining an orientation from data coordinates to world coordinates. For example, this would be used to a plane normal.
https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/geometry/transforming-normals.html
PARAMETER | DESCRIPTION |
---|---|
vector
|
A vector in data coordinates.
TYPE:
|
layer
|
The napari layer to get the transform from.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
Transformed vector in data coordinates. This returns a unit vector. |
Source code in src/napari_threedee/utils/napari_utils.py
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 |
|
world_to_data_normal(vector, layer)
Convert a normal vector defining an orientation from world coordinates to data coordinates. For example, this would be used to a plane normal.
https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/geometry/transforming-normals.html
PARAMETER | DESCRIPTION |
---|---|
vector
|
A vector in world coordinates.
TYPE:
|
layer
|
The napari layer to get the transform from.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
Transformed vector in data coordinates. This returns a unit vector. |
Source code in src/napari_threedee/utils/napari_utils.py
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 |
|
point_in_layer_bounding_box(point, layer)
Determine whether an nD point is inside a layers nD bounding box.
PARAMETER | DESCRIPTION |
---|---|
point
|
(n,) array containing nD point coordinates to check.
TYPE:
|
layer
|
napari layer to get the bounding box from
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the point is in the bounding box of the layer, otherwise False |
Notes
For a more general point-in-bbox function, see:
napari_threedee.utils.geometry.point_in_bounding_box
Source code in src/napari_threedee/utils/napari_utils.py
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 |
|
clamp_point_to_layer_bounding_box(point: np.ndarray, layer)
Ensure that a point is inside of the bounding box of a given layer. If the point has a coordinate outside of the bounding box, the value is clipped to the max extent of the bounding box.
PARAMETER | DESCRIPTION |
---|---|
point
|
n-dimensional point as an (n,) ndarray. Multiple points can be passed as an (n, D) array.
TYPE:
|
layer
|
napari layer to get the bounding box from
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
clamped_point
|
TYPE:
|
Notes
This function is derived from the napari function:
napari.utils.geometry.clamp_point_to_bounding_box
Source code in src/napari_threedee/utils/napari_utils.py
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 |
|