code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def orientation(p: np.ndarray, q: np.ndarray, r: np.ndarray) -> np.ndarray: """Determines oritentation of ordered triplet (p, q, r) Parameters ---------- p : (2,) array Array of first point of triplet q : (2,) array Array of second point of triplet r : (2,) array Array o...
Determines oritentation of ordered triplet (p, q, r) Parameters ---------- p : (2,) array Array of first point of triplet q : (2,) array Array of second point of triplet r : (2,) array Array of third point of triplet Returns ------- val : int One of (-1,...
orientation
python
napari/napari
src/napari/layers/shapes/_accelerated_triangulate_python.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_python.py
BSD-3-Clause
def _common_orientation(poly: npt.NDArray) -> int | None: """Check whether a polygon has the same orientation for all its angles. and return the orientation. Parameters ---------- poly: numpy array of floats, shape (N, 3) Polygon vertices, in order. Returns ------- int or None ...
Check whether a polygon has the same orientation for all its angles. and return the orientation. Parameters ---------- poly: numpy array of floats, shape (N, 3) Polygon vertices, in order. Returns ------- int or None if all angles have same orientation return it, otherwise ...
_common_orientation
python
napari/napari
src/napari/layers/shapes/_accelerated_triangulate_python.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_python.py
BSD-3-Clause
def is_convex_py(poly: npt.NDArray) -> bool: """Check whether a polygon is convex. Parameters ---------- poly: numpy array of floats, shape (N, 3) Polygon vertices, in order. Returns ------- bool True if the given polygon is convex. """ orientation_ = _common_orient...
Check whether a polygon is convex. Parameters ---------- poly: numpy array of floats, shape (N, 3) Polygon vertices, in order. Returns ------- bool True if the given polygon is convex.
is_convex_py
python
napari/napari
src/napari/layers/shapes/_accelerated_triangulate_python.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_accelerated_triangulate_python.py
BSD-3-Clause
def hold_to_lock_aspect_ratio(layer: Shapes) -> Generator[None, None, None]: """Hold to lock aspect ratio when resizing a shape.""" # on key press layer._fixed_aspect = True box = layer._selected_box if box is not None: size = box[Box.BOTTOM_RIGHT] - box[Box.TOP_LEFT] if not np.any(s...
Hold to lock aspect ratio when resizing a shape.
hold_to_lock_aspect_ratio
python
napari/napari
src/napari/layers/shapes/_shapes_key_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_key_bindings.py
BSD-3-Clause
def select_all_shapes(layer: Shapes) -> None: """Select all shapes in the current view slice.""" if layer._mode in (Mode.DIRECT, Mode.SELECT): layer.selected_data = set(np.nonzero(layer._data_view._displayed)[0]) layer._set_highlight()
Select all shapes in the current view slice.
select_all_shapes
python
napari/napari
src/napari/layers/shapes/_shapes_key_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_key_bindings.py
BSD-3-Clause
def select(layer: Shapes, event: MouseEvent) -> Generator[None, None, None]: """Select shapes or vertices either in select or direct select mode. Once selected shapes can be moved or resized, and vertices can be moved depending on the mode. Holding shift when resizing a shape will preserve the aspect r...
Select shapes or vertices either in select or direct select mode. Once selected shapes can be moved or resized, and vertices can be moved depending on the mode. Holding shift when resizing a shape will preserve the aspect ratio. Parameters ---------- layer : Shapes Napari shapes layer ...
select
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def add_line(layer: Shapes, event: MouseEvent) -> Generator[None, None, None]: """Add a line. Adds a line by connecting 2 ndim points. On press one point is set under the mouse cursor and a second point is created with a very minor offset to the first point. If moving mouse while mouse is pressed the secon...
Add a line. Adds a line by connecting 2 ndim points. On press one point is set under the mouse cursor and a second point is created with a very minor offset to the first point. If moving mouse while mouse is pressed the second point will track the cursor. The second point it set upon mouse release. Pa...
add_line
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def add_ellipse( layer: Shapes, event: MouseEvent ) -> Generator[None, None, None]: """ Add an ellipse to the shapes layer. Parameters ---------- layer : Shapes Napari shapes layer event : MouseEvent A proxy read only wrapper around a vispy mouse event. """ size = la...
Add an ellipse to the shapes layer. Parameters ---------- layer : Shapes Napari shapes layer event : MouseEvent A proxy read only wrapper around a vispy mouse event.
add_ellipse
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def add_rectangle( layer: Shapes, event: NapariMouseEvent ) -> Generator[None, None, None]: """Add a rectangle to the shapes layer. Parameters ---------- layer : Shapes Napari shapes layer event : NapariMouseEvent A proxy read only wrapper around a vispy mouse event. """ ...
Add a rectangle to the shapes layer. Parameters ---------- layer : Shapes Napari shapes layer event : NapariMouseEvent A proxy read only wrapper around a vispy mouse event.
add_rectangle
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def _add_line_rectangle_ellipse( layer: Shapes, event: NapariMouseEvent, data: npt.NDArray, shape_type: str ) -> Generator[None, None, None]: """Helper function for adding a line, rectangle or ellipse. Parameters ---------- layer : Shapes Napari shapes layer event : NapariMouseEvent ...
Helper function for adding a line, rectangle or ellipse. Parameters ---------- layer : Shapes Napari shapes layer event : NapariMouseEvent A proxy read only wrapper around a vispy mouse event. data : np.ndarray Array containing the initial datapoints of the shape in image da...
_add_line_rectangle_ellipse
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def initiate_polygon_draw( layer: Shapes, coordinates: tuple[float, ...] ) -> None: """Start drawing of polygon. Creates the polygon shape when initializing the draw, adding to layer and selecting the initiatlized shape and setting required layer attributes for drawing. Parameters ---------- ...
Start drawing of polygon. Creates the polygon shape when initializing the draw, adding to layer and selecting the initiatlized shape and setting required layer attributes for drawing. Parameters ---------- layer : Shapes Napari shapes layer coordinates : Tuple[float, ...] A tup...
initiate_polygon_draw
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def add_path_polygon_lasso( layer: Shapes, event: MouseEvent ) -> Generator[None, None, None]: """Add, draw and finish drawing of polygon. Initiates, draws and finishes the lasso polygon in drag mode (tablet) or initiates and finishes the lasso polygon when drawing with the mouse. Parameters -...
Add, draw and finish drawing of polygon. Initiates, draws and finishes the lasso polygon in drag mode (tablet) or initiates and finishes the lasso polygon when drawing with the mouse. Parameters ---------- layer : Shapes Napari shapes layer event : MouseEvent A proxy read only ...
add_path_polygon_lasso
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def add_vertex_to_path( layer: Shapes, event: MouseEvent, index: int, coordinates: tuple[float, ...], new_type: str | None, ) -> None: """Add a vertex to an existing path or polygon and edit the layer view. Parameters ---------- layer : Shapes Napari shapes layer event :...
Add a vertex to an existing path or polygon and edit the layer view. Parameters ---------- layer : Shapes Napari shapes layer event : MouseEvent A proxy read only wrapper around a vispy mouse event. index : int The index of the shape being added, e.g. first shape in the laye...
add_vertex_to_path
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def polygon_creating(layer: Shapes, event: MouseEvent) -> None: """Let active vertex follow cursor while drawing polygon, adding it to polygon after a certain distance. When drawing a polygon in lasso mode or adding a path, a vertex follows the cursor, creating a polygon visually that is *not* the final po...
Let active vertex follow cursor while drawing polygon, adding it to polygon after a certain distance. When drawing a polygon in lasso mode or adding a path, a vertex follows the cursor, creating a polygon visually that is *not* the final polygon to be created: it is the polygon if the current mouse positio...
polygon_creating
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def add_path_polygon(layer: Shapes, event: MouseEvent) -> None: """Add a path or polygon or add vertex to an existing one. When shape is not yet being created, initiates the drawing of a polygon on mouse press. Else, on subsequent mouse presses, add vertex to polygon being created. Parameters ----...
Add a path or polygon or add vertex to an existing one. When shape is not yet being created, initiates the drawing of a polygon on mouse press. Else, on subsequent mouse presses, add vertex to polygon being created. Parameters ---------- layer : Shapes Napari shapes layer event : Mouse...
add_path_polygon
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def move_active_vertex_under_cursor( layer: Shapes, coordinates: tuple[float, ...] ) -> None: """While a path or polygon is being created, move next vertex to be added. Parameters ---------- layer : Shapes Napari shapes layer coordinates : Tuple[float, ...] The coordinates in da...
While a path or polygon is being created, move next vertex to be added. Parameters ---------- layer : Shapes Napari shapes layer coordinates : Tuple[float, ...] The coordinates in data space of the vertex to be potentially added, e.g. vertex tracks the mouse cursor position. ...
move_active_vertex_under_cursor
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def vertex_insert(layer: Shapes, event: MouseEvent) -> None: """Insert a vertex into a selected shape. The vertex will get inserted in between the vertices of the closest edge from all the edges in selected shapes. Vertices cannot be inserted into Ellipses. Parameters ---------- layer : Sh...
Insert a vertex into a selected shape. The vertex will get inserted in between the vertices of the closest edge from all the edges in selected shapes. Vertices cannot be inserted into Ellipses. Parameters ---------- layer : Shapes Napari shapes layer event : MouseEvent A pr...
vertex_insert
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def vertex_remove(layer: Shapes, event: MouseEvent) -> None: """Remove a vertex from a selected shape. If a vertex is clicked on remove it from the shape it is in. If this cause the shape to shrink to a size that no longer is valid remove the whole shape. Parameters ---------- layer : Shap...
Remove a vertex from a selected shape. If a vertex is clicked on remove it from the shape it is in. If this cause the shape to shrink to a size that no longer is valid remove the whole shape. Parameters ---------- layer : Shapes Napari shapes layer event : MouseEvent A prox...
vertex_remove
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def _drag_selection_box(layer: Shapes, coordinates: tuple[float, ...]) -> None: """Drag a selection box. Parameters ---------- layer : napari.layers.Shapes Shapes layer. coordinates : Tuple[float, ...] The current position of the cursor during the mouse move event in image data spac...
Drag a selection box. Parameters ---------- layer : napari.layers.Shapes Shapes layer. coordinates : Tuple[float, ...] The current position of the cursor during the mouse move event in image data space.
_drag_selection_box
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def _set_drag_start( layer: Shapes, coordinates: tuple[float, ...] ) -> list[float]: """Indicate where in data space a drag event started. Sets the coordinates relative to the center of the bounding box of a shape and returns the position of where a drag event of a shape started. Parameters --...
Indicate where in data space a drag event started. Sets the coordinates relative to the center of the bounding box of a shape and returns the position of where a drag event of a shape started. Parameters ---------- layer : Shapes The napari layer shape coordinates : Tuple[float, ...] ...
_set_drag_start
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def _move_active_element_under_cursor( layer: Shapes, coordinates: tuple[float, ...] ) -> None: """Moves object at given mouse position and set of indices. Parameters ---------- layer : napari.layers.Shapes Shapes layer. coordinates : Tuple[float, ...] Position of mouse cursor i...
Moves object at given mouse position and set of indices. Parameters ---------- layer : napari.layers.Shapes Shapes layer. coordinates : Tuple[float, ...] Position of mouse cursor in data coordinates.
_move_active_element_under_cursor
python
napari/napari
src/napari/layers/shapes/_shapes_mouse_bindings.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_mouse_bindings.py
BSD-3-Clause
def find_planar_axis( points: CoordinateArray, ) -> tuple[CoordinateArray2D, int | None, float | None]: """Find an axis along which the input points are planar. If points are 2D, they are returned unchanged. If there is a planar axis, return the corresponding 2D points, the axis position, and the ...
Find an axis along which the input points are planar. If points are 2D, they are returned unchanged. If there is a planar axis, return the corresponding 2D points, the axis position, and the coordinate of the plane. If there is *no* planar axis, return an empty dataset. Parameters ----------...
find_planar_axis
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def _fan_triangulation( poly: CoordinateArray, ) -> tuple[CoordinateArray, TriangleArray]: """Return a fan triangulation of a given polygon. https://en.wikipedia.org/wiki/Fan_triangulation Parameters ---------- poly: numpy array of float, shape (N, 3) or (N, 2) Polygon vertices, in ord...
Return a fan triangulation of a given polygon. https://en.wikipedia.org/wiki/Fan_triangulation Parameters ---------- poly: numpy array of float, shape (N, 3) or (N, 2) Polygon vertices, in order. Returns ------- vertices : numpy array of float, shape (N, 3) or (N, 2) The v...
_fan_triangulation
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def inside_boxes(boxes): """Checks which boxes contain the origin. Boxes need not be axis aligned Parameters ---------- boxes : (N, 8, 2) array Array of N boxes that should be checked Returns ------- inside : (N,) array of bool True if corresponding box contains the origin....
Checks which boxes contain the origin. Boxes need not be axis aligned Parameters ---------- boxes : (N, 8, 2) array Array of N boxes that should be checked Returns ------- inside : (N,) array of bool True if corresponding box contains the origin.
inside_boxes
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def triangles_intersect_box(triangles, corners): """Determines which triangles intersect an axis aligned box. Parameters ---------- triangles : (N, 3, 2) array Array of vertices of triangles to be tested corners : (2, 2) array Array specifying corners of a box Returns -----...
Determines which triangles intersect an axis aligned box. Parameters ---------- triangles : (N, 3, 2) array Array of vertices of triangles to be tested corners : (2, 2) array Array specifying corners of a box Returns ------- intersects : (N,) array of bool Array wit...
triangles_intersect_box
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def triangle_vertices_inside_box(triangles, corners): """Determines which triangles have vertices inside an axis aligned box. Parameters ---------- triangles : (N, 3, 2) array Array of vertices of triangles to be tested corners : (2, 2) array Array specifying corners of a box R...
Determines which triangles have vertices inside an axis aligned box. Parameters ---------- triangles : (N, 3, 2) array Array of vertices of triangles to be tested corners : (2, 2) array Array specifying corners of a box Returns ------- inside : (N,) array of bool Ar...
triangle_vertices_inside_box
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def triangle_edges_intersect_box(triangles, corners): """Determines which triangles have edges that intersect the edges of an axis aligned box. Parameters ---------- triangles : (N, 3, 2) array Array of vertices of triangles to be tested corners : (2, 2) array Array specifying c...
Determines which triangles have edges that intersect the edges of an axis aligned box. Parameters ---------- triangles : (N, 3, 2) array Array of vertices of triangles to be tested corners : (2, 2) array Array specifying corners of a box Returns ------- intersects : (N,...
triangle_edges_intersect_box
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def lines_intersect(p1, q1, p2, q2): """Determines if line segment p1q1 intersects line segment p2q2 Parameters ---------- p1 : (2,) array Array of first point of first line segment q1 : (2,) array Array of second point of first line segment p2 : (2,) array Array of firs...
Determines if line segment p1q1 intersects line segment p2q2 Parameters ---------- p1 : (2,) array Array of first point of first line segment q1 : (2,) array Array of second point of first line segment p2 : (2,) array Array of first point of second line segment q2 : (2,)...
lines_intersect
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def on_segment(p, q, r): """Checks if q is on the segment from p to r Parameters ---------- p : (2,) array Array of first point of segment q : (2,) array Array of point to check if on segment r : (2,) array Array of second point of segment Returns ------- on...
Checks if q is on the segment from p to r Parameters ---------- p : (2,) array Array of first point of segment q : (2,) array Array of point to check if on segment r : (2,) array Array of second point of segment Returns ------- on : bool Bool indicating ...
on_segment
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def is_collinear(points: npt.NDArray) -> bool: """Determines if a list of 2D points are collinear. Parameters ---------- points : (N, 2) array Points to be tested for collinearity Returns ------- val : bool True is all points are collinear, False otherwise. """ if l...
Determines if a list of 2D points are collinear. Parameters ---------- points : (N, 2) array Points to be tested for collinearity Returns ------- val : bool True is all points are collinear, False otherwise.
is_collinear
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def point_to_lines(point, lines): """Calculate the distance between a point and line segments and returns the index of the closest line. First calculates the distance to the infinite line, then checks if the projected point lies between the line segment endpoints. If not, calculates distance to the endp...
Calculate the distance between a point and line segments and returns the index of the closest line. First calculates the distance to the infinite line, then checks if the projected point lies between the line segment endpoints. If not, calculates distance to the endpoints Parameters ---------- ...
point_to_lines
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def create_box(data: CoordinateArray2D) -> BoxArray: """Creates the axis aligned interaction box of a list of points Parameters ---------- data : np.ndarray Nx2 array of points whose interaction box is to be found Returns ------- box : np.ndarray 9x2 array of vertices of th...
Creates the axis aligned interaction box of a list of points Parameters ---------- data : np.ndarray Nx2 array of points whose interaction box is to be found Returns ------- box : np.ndarray 9x2 array of vertices of the interaction box. The first 8 points are the corner...
create_box
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def rectangle_to_box( data: np.ndarray[tuple[typing.Literal[4], int], np.dtype[np.float32]], ) -> BoxArray: """Converts the four corners of a rectangle into a interaction box like representation. If the rectangle is not axis aligned the resulting box representation will not be axis aligned either P...
Converts the four corners of a rectangle into a interaction box like representation. If the rectangle is not axis aligned the resulting box representation will not be axis aligned either Parameters ---------- data : np.ndarray 4xD array of corner points to be converted to a box like represe...
rectangle_to_box
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def find_corners(data: npt.NDArray) -> npt.NDArray: """Finds the four corners of the interaction box defined by an array of points Parameters ---------- data : np.ndarray Nx2 array of points whose interaction box is to be found Returns ------- corners : np.ndarray 4x2 a...
Finds the four corners of the interaction box defined by an array of points Parameters ---------- data : np.ndarray Nx2 array of points whose interaction box is to be found Returns ------- corners : np.ndarray 4x2 array of corners of the bounding box
find_corners
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def center_radii_to_corners( center: npt.NDArray, radii: npt.NDArray ) -> npt.NDArray: """Expands a center and radii into a four corner rectangle Parameters ---------- center : np.ndarray Length 2 array of the center coordinates. radii : np.ndarray Length 2 array of the two radi...
Expands a center and radii into a four corner rectangle Parameters ---------- center : np.ndarray Length 2 array of the center coordinates. radii : np.ndarray Length 2 array of the two radii. Returns ------- corners : np.ndarray 4x2 array of corners of the bounding ...
center_radii_to_corners
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def triangulate_ellipse( corners: CoordinateArray, num_segments: int = 100 ) -> tuple[CoordinateArray, TriangleArray]: """Determines the triangulation of a path. The resulting `offsets` can multiplied by a `width` scalar and be added to the resulting `centers` to generate the vertices of the triangles f...
Determines the triangulation of a path. The resulting `offsets` can multiplied by a `width` scalar and be added to the resulting `centers` to generate the vertices of the triangles for the triangulation, i.e. `vertices = centers + width*offsets`. Using the `centers` and `offsets` representation thus all...
triangulate_ellipse
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def _fix_vertices_if_needed( vertices: CoordinateArray2D, axis: int | None, value: float | None ) -> CoordinateArray: """Ensure vertices are planar along a given axis. If an axis and value are provided, this function inserts the value as a new coordinate along the given axis. Used to convert 2D ver...
Ensure vertices are planar along a given axis. If an axis and value are provided, this function inserts the value as a new coordinate along the given axis. Used to convert 2D vertices in 3D vertices along the plane. Parameters ---------- vertices: np.ndarray[np.floating], shape (N, 2) ...
_fix_vertices_if_needed
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def triangulate_face_and_edges( polygon_vertices: CoordinateArray, triangulate_face_: typing.Callable, ) -> tuple[ tuple[CoordinateArray, TriangleArray], tuple[CoordinateArray, CoordinateArray, TriangleArray], ]: """Determines the triangulation of the face and edges of a shape. Parameters -...
Determines the triangulation of the face and edges of a shape. Parameters ---------- polygon_vertices : np.ndarray Nx2 array of vertices of shape to be triangulated Returns ------- face_tri : tuple[np.ndarray, np.ndarray] Tuple of vertices and triangles of the face. edge_tr...
triangulate_face_and_edges
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def reconstruct_and_triangulate_edge( vertices: CoordinateArray, edges: EdgeArray ) -> tuple[CoordinateArray, CoordinateArray, TriangleArray]: """Triangulate edges when vertices form multiple disjoint polygons. Parameters ---------- vertices: np.ndarray Nx2 or Nx3 array of vertices of shape...
Triangulate edges when vertices form multiple disjoint polygons. Parameters ---------- vertices: np.ndarray Nx2 or Nx3 array of vertices of shape to be triangulated. Cannot contain duplicated vertices. edges: np.ndarray list of edges encoded as vertices indices. Cannot c...
reconstruct_and_triangulate_edge
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def triangulate_face( polygon_vertices: CoordinateArray2D, triangulate_face_: typing.Callable, ) -> tuple[CoordinateArray2D, TriangleArray]: """Determines the triangulation of the face of a shape. Parameters ---------- polygon_vertices : np.ndarray Nx2 array of vertices of shape to be t...
Determines the triangulation of the face of a shape. Parameters ---------- polygon_vertices : np.ndarray Nx2 array of vertices of shape to be triangulated Returns ------- vertices : np.ndarray Mx2 array vertices of the triangles. triangles : np.ndarray Px3 array of ...
triangulate_face
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def triangulate_edge( path: CoordinateArray, closed: bool = False ) -> tuple[CoordinateArray, CoordinateArray, TriangleArray]: """Determines the triangulation of a path. The resulting `offsets` can multiplied by a `width` scalar and be added to the resulting `centers` to generate the vertices of the tr...
Determines the triangulation of a path. The resulting `offsets` can multiplied by a `width` scalar and be added to the resulting `centers` to generate the vertices of the triangles for the triangulation, i.e. `vertices = centers + width*offsets`. Using the `centers` and `offsets` representation thus al...
triangulate_edge
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def generate_tube_meshes(path, closed=False, tube_points=10): """Generates list of mesh vertices and triangles from a path Adapted from vispy.visuals.TubeVisual https://github.com/vispy/vispy/blob/main/vispy/visuals/tube.py Parameters ---------- path : (N, 3) array Vertices specifying ...
Generates list of mesh vertices and triangles from a path Adapted from vispy.visuals.TubeVisual https://github.com/vispy/vispy/blob/main/vispy/visuals/tube.py Parameters ---------- path : (N, 3) array Vertices specifying the path. closed : bool Bool which determines if the path...
generate_tube_meshes
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def path_to_mask( mask_shape: npt.NDArray, vertices: npt.NDArray ) -> npt.NDArray[np.bool_]: """Converts a path to a boolean mask with `True` for points lying along each edge. Parameters ---------- mask_shape : array (2,) Shape of mask to be generated. vertices : array (N, 2) ...
Converts a path to a boolean mask with `True` for points lying along each edge. Parameters ---------- mask_shape : array (2,) Shape of mask to be generated. vertices : array (N, 2) Vertices of the path. Returns ------- mask : np.ndarray Boolean array with `True`...
path_to_mask
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def poly_to_mask( mask_shape: npt.ArrayLike, vertices: npt.ArrayLike ) -> npt.NDArray[np.bool_]: """Converts a polygon to a boolean mask with `True` for points lying inside the shape. Uses the bounding box of the vertices to reduce computation time. Parameters ---------- mask_shape : np.nda...
Converts a polygon to a boolean mask with `True` for points lying inside the shape. Uses the bounding box of the vertices to reduce computation time. Parameters ---------- mask_shape : np.ndarray | tuple 1x2 array of shape of mask to be generated. vertices : np.ndarray Nx2 array...
poly_to_mask
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def grid_points_in_poly(shape, vertices): """Converts a polygon to a boolean mask with `True` for points lying inside the shape. Loops through all indices in the grid Parameters ---------- shape : np.ndarray | tuple 1x2 array of shape of mask to be generated. vertices : np.ndarray ...
Converts a polygon to a boolean mask with `True` for points lying inside the shape. Loops through all indices in the grid Parameters ---------- shape : np.ndarray | tuple 1x2 array of shape of mask to be generated. vertices : np.ndarray Nx2 array of the vertices of the polygon. ...
grid_points_in_poly
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def points_in_poly(points, vertices): """Tests points for being inside a polygon using the ray casting algorithm Parameters ---------- points : np.ndarray Mx2 array of points to be tested vertices : np.ndarray Nx2 array of the vertices of the polygon. Returns ------- in...
Tests points for being inside a polygon using the ray casting algorithm Parameters ---------- points : np.ndarray Mx2 array of points to be tested vertices : np.ndarray Nx2 array of the vertices of the polygon. Returns ------- inside : np.ndarray Length M boolean ar...
points_in_poly
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def extract_shape_type(data, shape_type=None): """Separates shape_type from data if present, and returns both. Parameters ---------- data : Array | Tuple(Array,str) | List[Array | Tuple(Array, str)] | Tuple(List[Array], str) list or array of vertices belonging to each shape, optionally containi...
Separates shape_type from data if present, and returns both. Parameters ---------- data : Array | Tuple(Array,str) | List[Array | Tuple(Array, str)] | Tuple(List[Array], str) list or array of vertices belonging to each shape, optionally containing shape type strings shape_type : str | None ...
extract_shape_type
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def get_default_shape_type(current_type): """If all shapes in current_type are of identical shape type, return this shape type, else "polygon" as lowest common denominator type. Parameters ---------- current_type : list of str list of current shape types Returns ------- ...
If all shapes in current_type are of identical shape type, return this shape type, else "polygon" as lowest common denominator type. Parameters ---------- current_type : list of str list of current shape types Returns ------- default_type : str default shape type ...
get_default_shape_type
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def get_shape_ndim(data): """Checks whether data is a list of the same type of shape, one shape, or a list of different shapes and returns the dimensionality of the shape/s. Parameters ---------- data : (N, ) list of array List of shape data, where each element is an (N, D) array of the ...
Checks whether data is a list of the same type of shape, one shape, or a list of different shapes and returns the dimensionality of the shape/s. Parameters ---------- data : (N, ) list of array List of shape data, where each element is an (N, D) array of the N vertices of a shape in D d...
get_shape_ndim
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def number_of_shapes(data): """Determine number of shapes in the data. Parameters ---------- data : list or np.ndarray Can either be no shapes, if empty, a single shape or a list of shapes. Returns ------- n_shapes : int Number of new shapes """ if len(data)...
Determine number of shapes in the data. Parameters ---------- data : list or np.ndarray Can either be no shapes, if empty, a single shape or a list of shapes. Returns ------- n_shapes : int Number of new shapes
number_of_shapes
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def validate_num_vertices( data, shape_type, min_vertices=None, valid_vertices=None ): """Raises error if a shape in data has invalid number of vertices. Checks whether all shapes in data have a valid number of vertices for the given shape type and vertex information. Rectangles and ellipses can ha...
Raises error if a shape in data has invalid number of vertices. Checks whether all shapes in data have a valid number of vertices for the given shape type and vertex information. Rectangles and ellipses can have either 2 or 4 vertices per shape, lines can have only 2, while paths and polygons have a mi...
validate_num_vertices
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def perpendicular_distance( point: npt.NDArray, line_start: npt.NDArray, line_end: npt.NDArray ) -> float: """Calculate the perpendicular distance of a point to a given euclidean line. Calculates the shortest distance of a point to a euclidean line defined by a line_start point and a line_end point. Wo...
Calculate the perpendicular distance of a point to a given euclidean line. Calculates the shortest distance of a point to a euclidean line defined by a line_start point and a line_end point. Works up to any dimension. Parameters --------- point : np.ndarray A point defined by a numpy array...
perpendicular_distance
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def rdp(vertices: npt.NDArray, epsilon: float) -> npt.NDArray: """Reduce the number of vertices that make up a polygon. Implementation of the Ramer-Douglas-Peucker algorithm based on: https://github.com/fhirschmann/rdp/blob/master/rdp. This algorithm reduces the amounts of points in a polyline or in th...
Reduce the number of vertices that make up a polygon. Implementation of the Ramer-Douglas-Peucker algorithm based on: https://github.com/fhirschmann/rdp/blob/master/rdp. This algorithm reduces the amounts of points in a polyline or in this case reduces the number of vertices in a polygon shape. Parame...
rdp
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def _save_failed_triangulation( data: np.ndarray, target_dir: str | None = None, backend: str = '' ) -> tuple[str, str]: """Save data to temporary files for debugging. This function saves input data when triangulation fails. It saves the same data to both a .npz file and a .txt file within the temp...
Save data to temporary files for debugging. This function saves input data when triangulation fails. It saves the same data to both a .npz file and a .txt file within the temporary directory, and returns the paths to the saved files. Parameters ---------- data : np.ndarray The data to ...
_save_failed_triangulation
python
napari/napari
src/napari/layers/shapes/_shapes_utils.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_utils.py
BSD-3-Clause
def _ensure_color_arrays(shapes, face_colors=None, edge_colors=None): """Return as many face and edge colors as there are shapes in the input. Parameters ---------- shapes : iterable of Shape Each Shape must be a subclass of Shape face_colors : iterable of face_color or None If None...
Return as many face and edge colors as there are shapes in the input. Parameters ---------- shapes : iterable of Shape Each Shape must be a subclass of Shape face_colors : iterable of face_color or None If None, default face colors will be used edge_colors : iterable of edge_color o...
_ensure_color_arrays
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _calculate_array_sizes(shapes): """Calculate sizes needed for array preallocation. Parameters ---------- shapes : iterable of Shape Each Shape must be a subclass of Shape Returns ------- n_vertices : int Total number of vertices n_indices : int Total number ...
Calculate sizes needed for array preallocation. Parameters ---------- shapes : iterable of Shape Each Shape must be a subclass of Shape Returns ------- n_vertices : int Total number of vertices n_indices : int Total number of indices n_mesh_vertices : int ...
_calculate_array_sizes
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _preallocate_arrays(shapes, sizes): """Preallocate arrays for storing shape data. Parameters ---------- shapes : iterable of Shape Each Shape must be a subclass of Shape sizes : tuple Tuple containing sizes for preallocation: (n_vertices, n_indices, n_mesh_vertices, ...
Preallocate arrays for storing shape data. Parameters ---------- shapes : iterable of Shape Each Shape must be a subclass of Shape sizes : tuple Tuple containing sizes for preallocation: (n_vertices, n_indices, n_mesh_vertices, n_face_tri, n_edge_tri) Returns --...
_preallocate_arrays
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _fill_arrays( start_shape_index, start_mesh_index, shapes, face_colors, edge_colors, arrays, ): """Fill preallocated arrays with shape data. Parameters ---------- start_shape_index : int The number of starting shapes already present before we start filling th...
Fill preallocated arrays with shape data. Parameters ---------- start_shape_index : int The number of starting shapes already present before we start filling the arrays. start_mesh_index : int The number of mesh vertices in the shape list before adding these shapes. ...
_fill_arrays
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _batch_dec(meth): """ Decorator to apply `self.batched_updates` to the current method. """ @wraps(meth) def _wrapped(self, *args, **kwargs): with self.batched_updates(): return meth(self, *args, **kwargs) return _wrapped
Decorator to apply `self.batched_updates` to the current method.
_batch_dec
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def batched_updates(self) -> Generator[None, None, None]: """ Reentrant context manager to batch the display update `_update_displayed()` is called at _most_ once on exit of the context manager. There are two reason for this: 1. Some updates are triggered by events, b...
Reentrant context manager to batch the display update `_update_displayed()` is called at _most_ once on exit of the context manager. There are two reason for this: 1. Some updates are triggered by events, but sometimes multiple pieces of data that trigger events ...
batched_updates
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _set_color( self, colors: npt.NDArray, attribute: Literal['edge', 'face'] ) -> None: """Set the face_color or edge_color property Parameters ---------- colors : (N, 4) np.ndarray The value for setting edge or face_color. There must be one color fo...
Set the face_color or edge_color property Parameters ---------- colors : (N, 4) np.ndarray The value for setting edge or face_color. There must be one color for each shape attribute : str in {'edge', 'face'} The name of the attribute to set the color ...
_set_color
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _update_displayed(self) -> None: """Update the displayed data based on the slice key. This method must be called from within the `batched_updates` context manager: """ assert self.__batched_level >= 1, ( 'call _update_displayed from within self.batched_updates co...
Update the displayed data based on the slice key. This method must be called from within the `batched_updates` context manager:
_update_displayed
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def add( self, shape: Shape | Sequence[Shape], face_color=None, edge_color=None, shape_index=None, z_refresh=True, ): """Adds a single Shape object (single add mode) or multiple Shapes (multiple shape mode, which is much faster) If shape is a single i...
Adds a single Shape object (single add mode) or multiple Shapes (multiple shape mode, which is much faster) If shape is a single instance of subclass Shape then single add mode will be used, otherwise multiple add mode Parameters ---------- shape : single Shape or iterable of Shape ...
add
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _add_single_shape( self, shape, face_color=None, edge_color=None, shape_index=None, z_refresh=True, ): """Adds a single Shape object Parameters ---------- shape : subclass Shape Must be a subclass of Shape, one of "{'Li...
Adds a single Shape object Parameters ---------- shape : subclass Shape Must be a subclass of Shape, one of "{'Line', 'Rectangle', 'Ellipse', 'Path', 'Polygon'}" shape_index : None | int If int then edits the shape date at current index. To be used in...
_add_single_shape
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _extend_meshes(self, face_colors, edge_colors, arrays): """Assemble mesh properties from filled arrays. Parameters ---------- face_colors : np.ndarray Array of face colors edge_colors : np.ndarray Array of edge colors arrays : dict ...
Assemble mesh properties from filled arrays. Parameters ---------- face_colors : np.ndarray Array of face colors edge_colors : np.ndarray Array of edge colors arrays : dict Dictionary containing filled arrays
_extend_meshes
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _add_multiple_shapes( self, shapes, face_colors=None, edge_colors=None, z_refresh=True, ): """Add multiple shapes at once (faster than adding them one by one) Parameters ---------- shapes : iterable of Shape Each Shape must be ...
Add multiple shapes at once (faster than adding them one by one) Parameters ---------- shapes : iterable of Shape Each Shape must be a subclass of Shape, one of "{'Line', 'Rectangle', 'Ellipse', 'Path', 'Polygon'}" face_colors : iterable of face_color edg...
_add_multiple_shapes
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def remove(self, index, renumber=True): """Removes a single shape located at index. Parameters ---------- index : int Location in list of the shape to be removed. renumber : bool Bool to indicate whether to renumber all shapes or not. If not the ...
Removes a single shape located at index. Parameters ---------- index : int Location in list of the shape to be removed. renumber : bool Bool to indicate whether to renumber all shapes or not. If not the expectation is that this shape is being immediat...
remove
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _update_mesh_vertices(self, index, edge=False, face=False): """Updates the mesh vertex data and vertex data for a single shape located at index. Parameters ---------- index : int Location in list of the shape to be changed. edge : bool Bool to...
Updates the mesh vertex data and vertex data for a single shape located at index. Parameters ---------- index : int Location in list of the shape to be changed. edge : bool Bool to indicate whether to update mesh vertices corresponding to edge...
_update_mesh_vertices
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _update_z_order(self): """Updates the z order of the triangles given the z_index list""" self._z_order = np.argsort(self._z_index) # type: ignore[assignment] if len(self._z_order) == 0: self._mesh.triangles_z_order = np.empty((0), dtype=int) else: _, idx, cou...
Updates the z order of the triangles given the z_index list
_update_z_order
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def edit( self, index, data, face_color=None, edge_color=None, new_type=None ): """Updates the data of a single shape located at index. If `new_type` is not None then converts the shape type to the new type Parameters ---------- index : int Location in li...
Updates the data of a single shape located at index. If `new_type` is not None then converts the shape type to the new type Parameters ---------- index : int Location in list of the shape to be changed. data : np.ndarray NxD array of vertices. new...
edit
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def update_edge_color(self, index, edge_color, update=True): """Updates the edge color of a single shape located at index. Parameters ---------- index : int Location in list of the shape to be changed. edge_color : str | tuple If string can be any color n...
Updates the edge color of a single shape located at index. Parameters ---------- index : int Location in list of the shape to be changed. edge_color : str | tuple If string can be any color name recognized by vispy or hex value if starting with `#`. I...
update_edge_color
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def update_edge_colors(self, indices, edge_colors, update=True): """same as update_edge_color() but for multiple indices/edgecolors at once""" self._edge_color[indices] = edge_colors all_indices = np.bitwise_and( np.isin(self._mesh.triangles_index[:, 0], indices), self._m...
same as update_edge_color() but for multiple indices/edgecolors at once
update_edge_colors
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def update_face_color(self, index, face_color, update=True): """Updates the face color of a single shape located at index. Parameters ---------- index : int Location in list of the shape to be changed. face_color : str | tuple If string can be any color n...
Updates the face color of a single shape located at index. Parameters ---------- index : int Location in list of the shape to be changed. face_color : str | tuple If string can be any color name recognized by vispy or hex value if starting with `#`. I...
update_face_color
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def update_face_colors(self, indices, face_colors, update=True): """same as update_face_color() but for multiple indices/facecolors at once""" self._face_color[indices] = face_colors all_indices = np.bitwise_and( np.isin(self._mesh.triangles_index[:, 0], indices), self._m...
same as update_face_color() but for multiple indices/facecolors at once
update_face_colors
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def update_dims_order(self, dims_order): """Updates dimensions order for all shapes. Parameters ---------- dims_order : (D,) list Order that the dimensions are rendered in. """ for index in range(len(self.shapes)): if self.shapes[index].dims_order...
Updates dimensions order for all shapes. Parameters ---------- dims_order : (D,) list Order that the dimensions are rendered in.
update_dims_order
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def update_z_index(self, index, z_index): """Updates the z order of a single shape located at index. Parameters ---------- index : int Location in list of the shape to be changed. z_index : int Specifier of z order priority. Shapes with higher z order are...
Updates the z order of a single shape located at index. Parameters ---------- index : int Location in list of the shape to be changed. z_index : int Specifier of z order priority. Shapes with higher z order are displayed ontop of others.
update_z_index
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def shift(self, index, shift): """Performs a 2D shift on a single shape located at index Parameters ---------- index : int Location in list of the shape to be changed. shift : np.ndarray length 2 array specifying shift of shapes. """ self....
Performs a 2D shift on a single shape located at index Parameters ---------- index : int Location in list of the shape to be changed. shift : np.ndarray length 2 array specifying shift of shapes.
shift
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def scale(self, index, scale, center=None): """Performs a scaling on a single shape located at index Parameters ---------- index : int Location in list of the shape to be changed. scale : float, list scalar or list specifying rescaling of shape. c...
Performs a scaling on a single shape located at index Parameters ---------- index : int Location in list of the shape to be changed. scale : float, list scalar or list specifying rescaling of shape. center : list length 2 list specifying coord...
scale
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def rotate(self, index, angle, center=None): """Performs a rotation on a single shape located at index Parameters ---------- index : int Location in list of the shape to be changed. angle : float angle specifying rotation of shape in degrees. cent...
Performs a rotation on a single shape located at index Parameters ---------- index : int Location in list of the shape to be changed. angle : float angle specifying rotation of shape in degrees. center : list length 2 list specifying coordinat...
rotate
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def flip(self, index, axis, center=None): """Performs an vertical flip on a single shape located at index Parameters ---------- index : int Location in list of the shape to be changed. axis : int integer specifying axis of flip. `0` flips horizontal, `1` ...
Performs an vertical flip on a single shape located at index Parameters ---------- index : int Location in list of the shape to be changed. axis : int integer specifying axis of flip. `0` flips horizontal, `1` flips vertical. center : list ...
flip
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def transform(self, index, transform): """Performs a linear transform on a single shape located at index Parameters ---------- index : int Location in list of the shape to be changed. transform : np.ndarray 2x2 array specifying linear transform. "...
Performs a linear transform on a single shape located at index Parameters ---------- index : int Location in list of the shape to be changed. transform : np.ndarray 2x2 array specifying linear transform.
transform
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def outline( self, indices: int | Sequence[int] ) -> tuple[np.ndarray, np.ndarray, np.ndarray]: """Finds outlines of shapes listed in indices Parameters ---------- indices : int | Sequence[int] Location in list of the shapes to be outline. If sequence...
Finds outlines of shapes listed in indices Parameters ---------- indices : int | Sequence[int] Location in list of the shapes to be outline. If sequence, all elements should be ints Returns ------- centers : np.ndarray Nx2 array of ce...
outline
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def outlines( self, indices: Sequence[int] ) -> tuple[np.ndarray, np.ndarray, np.ndarray]: """Finds outlines of shapes listed in indices Parameters ---------- indices : Sequence[int] Location in list of the shapes to be outline. Returns ------- ...
Finds outlines of shapes listed in indices Parameters ---------- indices : Sequence[int] Location in list of the shapes to be outline. Returns ------- centers : np.ndarray Nx2 array of centers of outline offsets : np.ndarray N...
outlines
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def shapes_in_box(self, corners): """Determines which shapes, if any, are inside an axis aligned box. Looks only at displayed shapes Parameters ---------- corners : np.ndarray 2x2 array of two corners that will be used to create an axis aligned box. ...
Determines which shapes, if any, are inside an axis aligned box. Looks only at displayed shapes Parameters ---------- corners : np.ndarray 2x2 array of two corners that will be used to create an axis aligned box. Returns ------- shapes :...
shapes_in_box
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def inside(self, coord): """Determines if any shape at given coord by looking inside triangle meshes. Looks only at displayed shapes Parameters ---------- coord : sequence of float Image coordinates to check if any shapes are at. Returns ------- ...
Determines if any shape at given coord by looking inside triangle meshes. Looks only at displayed shapes Parameters ---------- coord : sequence of float Image coordinates to check if any shapes are at. Returns ------- shape : int | None I...
inside
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _inside_3d(self, ray_position: np.ndarray, ray_direction: np.ndarray): """Determines if any shape is intersected by a ray by looking inside triangle meshes. Looks only at displayed shapes. Parameters ---------- ray_position : np.ndarray (3,) array containing the ...
Determines if any shape is intersected by a ray by looking inside triangle meshes. Looks only at displayed shapes. Parameters ---------- ray_position : np.ndarray (3,) array containing the location that was clicked. This should be in the same coordinate system as...
_inside_3d
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _triangle_intersection( self, triangle_indices: np.ndarray, ray_position: np.ndarray, ray_direction: np.ndarray, ): """Find the intersection of a ray with specified triangles. Parameters ---------- triangle_indices : np.ndarray (n,) ar...
Find the intersection of a ray with specified triangles. Parameters ---------- triangle_indices : np.ndarray (n,) array of shape indices to find the intersection with the ray. The indices should correspond with self._mesh.displayed_triangles. ray_position : np.nd...
_triangle_intersection
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def to_masks(self, mask_shape=None, zoom_factor=1, offset=(0, 0)): """Returns N binary masks, one for each shape, embedded in an array of shape `mask_shape`. Parameters ---------- mask_shape : np.ndarray | tuple | None 2-tuple defining shape of mask to be generated. ...
Returns N binary masks, one for each shape, embedded in an array of shape `mask_shape`. Parameters ---------- mask_shape : np.ndarray | tuple | None 2-tuple defining shape of mask to be generated. If non specified, takes the max of all the vertices zoom_f...
to_masks
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def to_labels(self, labels_shape=None, zoom_factor=1, offset=(0, 0)): """Returns a integer labels image, where each shape is embedded in an array of shape labels_shape with the value of the index + 1 corresponding to it, and 0 for background. For overlapping shapes z-ordering will be res...
Returns a integer labels image, where each shape is embedded in an array of shape labels_shape with the value of the index + 1 corresponding to it, and 0 for background. For overlapping shapes z-ordering will be respected. Parameters ---------- labels_shape : np.ndarray ...
to_labels
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def to_colors( self, colors_shape=None, zoom_factor=1, offset=(0, 0), max_shapes=None ): """Rasterize shapes to an RGBA image array. Each shape is embedded in an array of shape `colors_shape` with the RGBA value of the shape, and 0 for background. For overlapping shapes z-or...
Rasterize shapes to an RGBA image array. Each shape is embedded in an array of shape `colors_shape` with the RGBA value of the shape, and 0 for background. For overlapping shapes z-ordering will be respected. Parameters ---------- colors_shape : np.ndarray | tuple | Non...
to_colors
python
napari/napari
src/napari/layers/shapes/_shape_list.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shape_list.py
BSD-3-Clause
def _update_displayed_data(self) -> None: """Update the data that is to be displayed.""" # Build boundary vertices with num_segments self._clean_cache() vertices, triangles = triangulate_ellipse(self.data_displayed) self._set_meshes(vertices[1:-1], face=False) # type: ignore[arg...
Update the data that is to be displayed.
_update_displayed_data
python
napari/napari
src/napari/layers/shapes/_shapes_models/ellipse.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/ellipse.py
BSD-3-Clause
def transform(self, transform): """Performs a linear transform on the shape Parameters ---------- transform : np.ndarray 2x2 array specifying linear transform. """ self._box = self._box @ transform.T self._data[:, self.dims_displayed] = ( ...
Performs a linear transform on the shape Parameters ---------- transform : np.ndarray 2x2 array specifying linear transform.
transform
python
napari/napari
src/napari/layers/shapes/_shapes_models/ellipse.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/ellipse.py
BSD-3-Clause
def bounding_box(self) -> np.ndarray: """(2, N) array, bounding box of the object.""" # We add +-0.5 to handle edge width return self._bounding_box[:, self.dims_displayed] + [ [-0.5 * self.edge_width], [0.5 * self.edge_width], ]
(2, N) array, bounding box of the object.
bounding_box
python
napari/napari
src/napari/layers/shapes/_shapes_models/shape.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/shape.py
BSD-3-Clause
def _set_meshes_compiled_bermuda( self, data: CoordinateArray, closed: bool = True, face: bool = True, edge: bool = True, ) -> None: """Sets the face and edge meshes from a set of points. Uses bermuda compiled backend for triangulation. Parameters ...
Sets the face and edge meshes from a set of points. Uses bermuda compiled backend for triangulation. Parameters ---------- data : np.ndarray Nx2 or Nx3 array specifying the shape to be triangulated closed : bool Bool which determines if the edge is close...
_set_meshes_compiled_bermuda
python
napari/napari
src/napari/layers/shapes/_shapes_models/shape.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/shape.py
BSD-3-Clause
def _set_meshes_compiled_partseg( self, data: CoordinateArray, closed: bool = True, face: bool = True, edge: bool = True, ) -> None: """Sets the face and edge meshes from a set of points. Uses PartSegCore compiled backend for triangulation. Parameter...
Sets the face and edge meshes from a set of points. Uses PartSegCore compiled backend for triangulation. Parameters ---------- data : np.ndarray Nx2 or Nx3 array specifying the shape to be triangulated closed : bool Bool which determines if the edge is c...
_set_meshes_compiled_partseg
python
napari/napari
src/napari/layers/shapes/_shapes_models/shape.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/shape.py
BSD-3-Clause
def _set_meshes_triangle( self, data: CoordinateArray, closed: bool = True, face: bool = True, edge: bool = True, ) -> None: """Sets the face and edge meshes from a set of points. Uses the triangle package to triangulate the polygon face Parameters ...
Sets the face and edge meshes from a set of points. Uses the triangle package to triangulate the polygon face Parameters ---------- data : np.ndarray Nx2 or Nx3 array specifying the shape to be triangulated closed : bool Bool which determines if the edge...
_set_meshes_triangle
python
napari/napari
src/napari/layers/shapes/_shapes_models/shape.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/shape.py
BSD-3-Clause
def _set_meshes_py( self, data: CoordinateArray, closed: bool = True, face: bool = True, edge: bool = True, ) -> None: """Sets the face and edge meshes from a set of points. Parameters ---------- data : np.ndarray Nx2 or Nx3 array ...
Sets the face and edge meshes from a set of points. Parameters ---------- data : np.ndarray Nx2 or Nx3 array specifying the shape to be triangulated closed : bool Bool which determines if the edge is closed or not face : bool Bool which determ...
_set_meshes_py
python
napari/napari
src/napari/layers/shapes/_shapes_models/shape.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/shape.py
BSD-3-Clause
def _triangulate_edge( self, data: CoordinateArray, closed: bool ) -> tuple[CoordinateArray, CoordinateArray, TriangleArray]: """Triangulate the edge of the shape. Parameters ---------- data : np.ndarray Nx2 or Nx3 array specifying the shape to be triangulated ...
Triangulate the edge of the shape. Parameters ---------- data : np.ndarray Nx2 or Nx3 array specifying the shape to be triangulated closed : bool Bool which determines if the edge is closed or not Returns ------- tuple Tuple o...
_triangulate_edge
python
napari/napari
src/napari/layers/shapes/_shapes_models/shape.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/shape.py
BSD-3-Clause
def _all_triangles(self): """Return all triangles for the shape Returns ------- np.ndarray Nx3 array of vertex indices that form the triangles for the shape """ return np.vstack( [ self._face_vertices[self._face_triangles], ...
Return all triangles for the shape Returns ------- np.ndarray Nx3 array of vertex indices that form the triangles for the shape
_all_triangles
python
napari/napari
src/napari/layers/shapes/_shapes_models/shape.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/shape.py
BSD-3-Clause
def shift(self, shift: npt.NDArray) -> None: """Performs a 2D shift on the shape Parameters ---------- shift : np.ndarray length 2 array specifying shift of shapes. """ shift = np.array(shift) self._face_vertices = self._face_vertices + shift ...
Performs a 2D shift on the shape Parameters ---------- shift : np.ndarray length 2 array specifying shift of shapes.
shift
python
napari/napari
src/napari/layers/shapes/_shapes_models/shape.py
https://github.com/napari/napari/blob/master/src/napari/layers/shapes/_shapes_models/shape.py
BSD-3-Clause