radioviz.models.roi_model
Module for handling Region of Interest (ROI) definitions and validations.
This module provides functionality for defining different types of regions of interest, validating their geometric properties, and calculating various attributes such as bounding boxes, centers, and dimensions. It supports rectangle, circle, ellipse, and polygon ROI types with appropriate validation schemas.
Module Attributes
Type alias for a tuple of four floats (xmin, xmax, ymin, ymax) |
|
Schema definitions for validating different ROI types. |
Functions
|
Validate the geometry of a region of interest based on its type. |
Classes
|
Data class representing a Region of Interest. |
|
Enumeration of region enclosure options. |
|
Enumeration of supported region selection types. |
- class radioviz.models.roi_model.ROI(type: ROIType, enclosure: ROIEnclosure, geometry: dict[str, Any])[source]
Bases:
objectData class representing a Region of Interest.
This class encapsulates all information about a region of interest including its type, enclosure preference, and geometric properties.
- property angle: float
Get the rotation angle of the ROI.
Returns the rotation angle for rectangle and ellipse ROIs, defaults to 0 for others.
- Returns:
The rotation angle in degrees
- Return type:
float
- property angle_rad: float
Get the rotation angle of the ROI in radians.
Converts the angle from degrees to radians for mathematical calculations.
- Returns:
The rotation angle in radians
- Return type:
float
- property bounding_box: Tuple[float, float, float, float]
Get the bounding box coordinates of the ROI.
Returns the minimum and maximum x and y coordinates that define the bounding box.
- Returns:
The bounding box coordinates (xmin, xmax, ymin, ymax)
- Return type:
tuple[float, float, float, float]
- property center: tuple[float, float]
Calculate the center point of the ROI.
For polygons, calculates the centroid by averaging vertex coordinates. For other types, calculates the midpoint of the bounding box.
- Returns:
The center coordinates of the ROI
- Return type:
tuple[float, float]
- enclosure: ROIEnclosure
The enclosure preference for the region.
- property extents: Tuple[float, float, float, float]
Get the extents of the ROI.
Returns the extent values (xmin, xmax, ymin, ymax) of the ROI.
- Returns:
The extents of the ROI
- Return type:
tuple[float, float, float, float]
- Raises:
AttributeError – if the ROI does not have extents
- geometry: dict[str, Any]
The geometric definition of the ROI.
- property height: float
Calculate the height of the ROI.
For non-polygon ROIs, returns the difference between maximum and minimum y coordinates. Raises AttributeError for polygon ROIs.
- Returns:
The height of the ROI
- Return type:
float
- Raises:
AttributeError – if the ROI is a polygon
- property radius: float
Calculate the radius of a circular ROI.
Only applicable to circle ROIs. Calculates radius from the width of the bounding box.
- Returns:
The radius of the circle ROI
- Return type:
float
- Raises:
AttributeError – if the ROI is not a circle
- property width: float
Calculate the width of the ROI.
For non-polygon ROIs, returns the difference between maximum and minimum x coordinates. Raises AttributeError for polygon ROIs.
- Returns:
The width of the ROI
- Return type:
float
- Raises:
AttributeError – if the ROI is a polygon
- property xy: tuple[float, float]
Get the x,y coordinates of the ROI.
For rectangles, returns the bottom-left corner coordinates. For circles and ellipses, returns the center coordinates. Raises AttributeError for polygon ROIs.
- Returns:
The x,y coordinates of the ROI
- Return type:
tuple[float, float]
- Raises:
AttributeError – if the ROI is a polygon
- class radioviz.models.roi_model.ROIEnclosure(*values)[source]
Bases:
StrEnumEnumeration of region enclosure options.
Defines whether a region is considered inside or outside the selection area.
- static _generate_next_value_(name, start, count, last_values)
Return the lower-cased version of the member name.
- Inside = 'Inside'
Region is inside the selection.
- Outside = 'Outside'
Region is outside the selection.
- class radioviz.models.roi_model.ROIType(*values)[source]
Bases:
StrEnumEnumeration of supported region selection types.
This enum defines the different types of regions of interest that can be created and validated within the application.
- static _generate_next_value_(name, start, count, last_values)
Return the lower-cased version of the member name.
- CIRCLE = 'Circle'
Circle selection type.
- ELLIPSE = 'Ellipse'
Ellipse selection type.
- POLYGON = 'Polygon'
Polygon selection type.
- RECTANGLE = 'Rectangle'
Rectangle selection type.
- radioviz.models.roi_model._validate_polygon_based_geometry(geom: dict[str, Any]) None[source]
Validate geometry for polygon-based ROI types.
Validates that vertices are properly formatted as a list/tuple of at least three points.
- Parameters:
geom (dict[str, Any]) – The geometry definition containing vertices
- Raises:
ValueError – if vertices are invalid
- radioviz.models.roi_model._validate_rectangle_based_geometry(geom: dict[str, Any]) None[source]
Validate geometry for rectangle-based ROI types.
Validates that extents are properly formatted as a list/tuple of four positive values and that angle is numeric.
- Parameters:
geom (dict[str, Any]) – The geometry definition containing extents and optional angle
- Raises:
ValueError – if extents are invalid or angle is not numeric
- radioviz.models.roi_model.validate_roi(roi_type: ROIType, geom: dict[str, Any]) None[source]
Validate the geometry of a region of interest based on its type.
This function checks that all required fields are present in the geometry dictionary and performs type-specific validation for different ROI types.
- Parameters:
roi_type (
ROIType) – The type of region of interest to validategeom (dict[str, Any]) – The geometry definition of the ROI
- Raises:
ValueError – if the ROI type is unsupported or required fields are missing
ValueError – if the geometry doesn’t meet type-specific requirements
- radioviz.models.roi_model.QuadFloat
Type alias for a tuple of four floats (xmin, xmax, ymin, ymax)
alias of
Tuple[float,float,float,float]
- radioviz.models.roi_model.ROI_SCHEMAS = {ROIType.CIRCLE: {'required': {'extents'}}, ROIType.ELLIPSE: {'required': {'angle', 'extents'}}, ROIType.POLYGON: {'required': {'verts'}}, ROIType.RECTANGLE: {'required': {'angle', 'extents'}}}
Schema definitions for validating different ROI types.
Each ROI type has specific required fields that must be present in the geometry dictionary for validation to pass.