napari utilities
clamp_point_to_layer_bounding_box(point, 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.
Parameters
point : np.ndarray n-dimensional point as an (n,) ndarray. Multiple points can be passed as an (n, D) array. layer : napari.layers.Layer napari layer to get the bounding box from
Returns
clamped_point : np.ndarray
point
clamped to the limits of the layer bounding box
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
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 |
|
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
Parameters
vector : tuple, list, 1D array A vector in data coordinates. layer : napari.layers.BaseLayer The napari layer to get the transform from.
Returns
np.ndarray Transformed vector in data coordinates. This returns a unit vector.
Source code in src/napari_threedee/utils/napari_utils.py
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 |
|
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.
Parameters
vector : tuple, list, 1D array A vector in data coordinates. layer : napari.layers.BaseLayer The napari layer to get the transform from.
Returns
np.ndarray Transformed vector in data coordinates.
Source code in src/napari_threedee/utils/napari_utils.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
get_mouse_position_in_displayed_dimensions(event)
Get the position under the mouse in scene (displayed world) coordinates.
Parameters
event The mouse event.
Returns
click_dir_data_3d : np.ndarray The click direction in displayed data coordiantes
Source code in src/napari_threedee/utils/napari_utils.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
get_mouse_position_in_displayed_layer_data_coordinates(layer, event)
Get the mouse click position and direction in layer data displayed coordinates.
Parameters
layer : napari.layers.Layer The layer to convert the coordinates to. event The mouse event.
Returns
click_position_data_3d : np.ndarray The click position in displayed data coordinates. click_dir_data_3d : np.ndarray The click direction in displayed data coordiantes
Source code in src/napari_threedee/utils/napari_utils.py
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 |
|
get_napari_visual(viewer, layer)
Get the visual class for a given layer
Parameters
viewer The napari viewer object layer The napari layer object for which to find the visual.
Returns
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_view_direction_in_displayed_dimensions(event)
Get the view direction under the mouse in scene (displayed world) coordinates.
Parameters
event: Event napari mouse event.
Source code in src/napari_threedee/utils/napari_utils.py
123 124 125 126 127 128 129 130 131 132 |
|
get_vispy_layer_node(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, 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 64 65 |
|
point_in_layer_bounding_box(point, layer)
Determine whether an nD point is inside a layers nD bounding box.
Parameters
point : np.ndarray (n,) array containing nD point coordinates to check. layer : napari.layers.Layer napari layer to get the bounding box from
Returns
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
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 |
|
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
Parameters
vector : tuple, list, 1D array A vector in world coordinates. layer : napari.layers.BaseLayer The napari layer to get the transform from.
Returns
np.ndarray Transformed vector in data coordinates. This returns a unit vector.
Source code in src/napari_threedee/utils/napari_utils.py
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 |
|