utils¶
Brayns utilities.
This subpackage contains all functionalities that are commonly used inside and outside the main package and are not directly related to the Web API.
It includes helpers for algebra, imaging or coloring and the base exception.
vector¶
- class Axis¶
Bases:
object
Helper class to store the principal axes of Brayns coordinate system.
- class property back: Vector3¶
3D vector with XYZ components.
Provides dot and cross product in addition to Vector operators.
- Parameters:
x (float) – X component.
y (float) – Y component.
z (float) – Z component.
- class property down: Vector3¶
3D vector with XYZ components.
Provides dot and cross product in addition to Vector operators.
- Parameters:
x (float) – X component.
y (float) – Y component.
z (float) – Z component.
- class property front: Vector3¶
3D vector with XYZ components.
Provides dot and cross product in addition to Vector operators.
- Parameters:
x (float) – X component.
y (float) – Y component.
z (float) – Z component.
- class property left: Vector3¶
3D vector with XYZ components.
Provides dot and cross product in addition to Vector operators.
- Parameters:
x (float) – X component.
y (float) – Y component.
z (float) – Z component.
- class property right: Vector3¶
3D vector with XYZ components.
Provides dot and cross product in addition to Vector operators.
- Parameters:
x (float) – X component.
y (float) – Y component.
z (float) – Z component.
- class property up: Vector3¶
3D vector with XYZ components.
Provides dot and cross product in addition to Vector operators.
- Parameters:
x (float) – X component.
y (float) – Y component.
z (float) – Z component.
- class property x: Vector3¶
3D vector with XYZ components.
Provides dot and cross product in addition to Vector operators.
- Parameters:
x (float) – X component.
y (float) – Y component.
z (float) – Z component.
- class Vector2(x: float = 0.0, y: float = 0.0)¶
Bases:
Vector
[float
]2D vector with XY components.
Provides dot product in addition to Vector operators.
- Parameters:
x (float) – X component.
y (float) – Y component.
- property x: float¶
- property y: float¶
- class Vector3(x: float = 0.0, y: float = 0.0, z: float = 0.0)¶
Bases:
Vector2
3D vector with XYZ components.
Provides dot and cross product in addition to Vector operators.
- Parameters:
x (float) – X component.
y (float) – Y component.
z (float) – Z component.
- class property one: Vector3¶
3D vector with XYZ components.
Provides dot and cross product in addition to Vector operators.
- Parameters:
x (float) – X component.
y (float) – Y component.
z (float) – Z component.
- property x: float¶
- property y: float¶
- property z: float¶
bounds¶
- class Bounds(min: Vector3, max: Vector3)¶
Bases:
object
Axis aligned bounding box.
- property center: Vector3¶
Compute the center point of the bounds.
- Returns:
3D point of the center.
- Return type:
- property corners: list[Vector3]¶
List the 8 corners of the box.
- Returns:
List of corner points.
- Return type:
list[Vector3]
- property depth: float¶
Compute the depth of the bounds.
- Returns:
size.z.
- Return type:
float
- property height: float¶
Compute the height of the bounds.
- Returns:
size.y.
- Return type:
float
- rotate(rotation: Rotation, center: Vector3 = (0.0, 0.0, 0.0)) Bounds ¶
Rotate bounds by given value around optional center.
- property size: Vector3¶
Compute the size of the bounds.
- Returns:
Size XYZ (width, height, depth).
- Return type:
- class property unit: Bounds¶
Create unit bounds (size = [1, 1, 1]).
- Returns:
Unit bounds centered in [0, 0, 0].
- Return type:
- property width: float¶
Compute the width of the bounds.
- Returns:
size.x.
- Return type:
float
rotation¶
- class CameraRotation¶
Bases:
object
Helper class to store camera rotations to reach different views.
All rotations are relative to front view (X-right, Y-up, Z-front).
- class ModelRotation¶
Bases:
object
Helper class to store model rotations to reach different views.
All rotations are relative to front view (X-right, Y-up, Z-front).
- class Rotation(quaternion: Quaternion)¶
Bases:
object
Arbitrary 3D rotation using normalized quaternion internally.
Direct construction, prefer from_quaternion.
- property angle_degrees: float¶
Get rotation angle in degrees.
- Returns:
Rotation angle.
- Return type:
- property angle_radians: float¶
Get rotation angle in radians.
- Returns:
Rotation angle.
- Return type:
- apply(value: Vector3, center: Vector3 = (0.0, 0.0, 0.0)) Vector3 ¶
Apply rotation on value around center.
- static between(source: Vector3, destination: Vector3) Rotation ¶
Compute the minimal arc rotation between two vectors.
Vectors must not be zero.
- property euler_degrees: Vector3¶
Get rotation as euler angles XYZ in degrees.
- Returns:
Euler angles.
- Return type:
- property euler_radians: Vector3¶
Get rotation as euler angles XYZ in radians.
- Returns:
Euler angles.
- Return type:
- static from_axis_angle(axis: Vector3, angle: float, degrees: bool = False) Rotation ¶
Construct a rotation of angle around axis.
Axis must not be zero.
- static from_euler(euler: Vector3, degrees: bool = False) Rotation ¶
Construct a rotation from euler angle in XYZ order.
- static from_quaternion(quaternion: Quaternion) Rotation ¶
Construct a rotation using a quaternion (will be normalized).
- Parameters:
quaternion (Quaternion) – Quaternion representing rotation.
- Returns:
Rotation object.
- Return type:
- class property identity: Rotation¶
Construct a rotation with no effects.
- Returns:
Identity rotation.
- Return type:
- property inverse: Rotation¶
Get rotation such as self * self.inverse == Rotation.identity.
- Returns:
Inverse rotation.
- Return type:
- property quaternion: Quaternion¶
Get rotation as normalized quaternion.
- Returns:
Normalized quaternion.
- Return type:
- euler(x: float, y: float, z: float, degrees: bool = False) Rotation ¶
Shortcut to build a rotation from euler angles.
- Parameters:
x (float) – X rotation.
y (float) – Y rotation.
z (float) – Z rotation.
degrees (bool, optional) – Wether given angles are in degrees, defaults to False
- Returns:
Rotation corresponding to angles.
- Return type:
color¶
- class Color3(r: float = 0.0, g: float = 0.0, b: float = 0.0)¶
Bases:
Vector
[float
]Color with RGB normalized components.
Color3 are vectors and can be manipulated as such.
- Parameters:
r (float) – Red component 0-1.
g (float) – Green component 0-1.
b (float) – Blue component 0-1.
- property b: float¶
- class property bbp_background: T¶
Create a color of the BBP standard background (~blue).
- Returns:
BBP background color [0.004, 0.016, 0.102].
- Return type:
- property g: float¶
- property r: float¶
- class Color4(r: float = 0.0, g: float = 0.0, b: float = 0.0, a: float = 1.0)¶
Bases:
Color3
Color with RGBA normalized components.
Color4 are Color3 and can be manipulated as such but with alpha channel.
Opaque is alpha = 1 and fully transparent is alpha = 0.
Color3 standard colors, if used from Color4, will have an alpha of 1.
- Parameters:
a (float, optional) – Alpha component, defaults to 1.0.
- property a: float¶
- static from_color3(color: Color3, alpha: float = 1.0) Color4 ¶
Helper to build a Color4 from a Color3.
- property opaque: Color4¶
Create an identical color but with alpha = 1.
- Returns:
Color but fully opaque.
- Return type:
json_schema¶
- class JsonSchema(title: str = '', description: str = '', type: JsonType = JsonType.UNDEFINED, read_only: bool = False, write_only: bool = False, default: Any = None, minimum: float | None = None, maximum: float | None = None, items: JsonSchema | None = None, min_items: int | None = None, max_items: int | None = None, properties: dict[str, JsonSchema] = <factory>, required: list[str] = <factory>, additional_properties: bool | JsonSchema | None = None, one_of: list[JsonSchema] = <factory>, enum: list[Any] = <factory>)¶
Bases:
object
JSON schema describing JSON-RPC message format.
- Parameters:
title (str) – Title (class name).
description (str) – Human readable description.
type (JsonType) – JSON type (null, boolean, number, string, object, …).
read_only (bool) – If true, this field cannot be assigned.
write_only (bool) – If true, this field cannot get retreived.
default (Any) – Optional default value.
minimum (float | None) – Optional minimum value for numbers.
maximum (float | None) – Optional maximum value for numbers.
items (JsonSchema | None) – Optional item schema value for arrays.
min_items (int | None) – Optional minimum item count for arrays.
max_items (int | None) – Optional maximum item count for arrays.
properties (dict[str, JsonSchema]) – Optional fixed properties schema for objects.
required (list[str]) – Optional list of required properties for objects.
additional_properties (bool | JsonSchema | None) – Schema of additional properties for objects. If False then no additional properties are allowed (only fixed). If None then any additional properties are allowed (usually ignored).
one_of (list[JsonSchema]) – If not empty, the schema is a union of several schemas.
enum (list[Any]) – If not empty, the message must be in these values.
- additional_properties: bool | JsonSchema | None = None¶
- default: Any = None¶
- description: str = ''¶
- enum: list[Any]¶
- items: JsonSchema | None = None¶
- max_items: int | None = None¶
- maximum: float | None = None¶
- min_items: int | None = None¶
- minimum: float | None = None¶
- one_of: list[JsonSchema]¶
- properties: dict[str, JsonSchema]¶
- read_only: bool = False¶
- required: list[str]¶
- title: str = ''¶
- write_only: bool = False¶
- class JsonType(value)¶
Bases:
Enum
Enumeration of available JSON types.
The value is the string from the JSON schema standard.
- Parameters:
UNDEFINED – Any type is allowed.
NULL – No types are allowed.
BOOLEAN – Boolean.
INTEGER – Integral number.
NUMBER – Any number.
STRING – String.
ARRAY – Array.
OBJECT – Object.
- ARRAY = 'array'¶
- BOOLEAN = 'boolean'¶
- INTEGER = 'integer'¶
- NULL = 'null'¶
- NUMBER = 'number'¶
- OBJECT = 'object'¶
- STRING = 'string'¶
- UNDEFINED = 'undefined'¶
- deserialize_schema(message: dict[str, Any]) JsonSchema ¶
Deserialize dictionary to JSON schema.
- Parameters:
message (dict[str, Any]) – Parsed JSON object.
- Returns:
JSON schema with supported fields.
- Return type:
- serialize_schema(schema: JsonSchema) dict[str, Any] ¶
Serialize JSON schema to dictionary.
- Parameters:
schema (JsonSchema) – JSON schema.
- Returns:
Dictionary that can be stringified to raw JSON.
- Return type:
dict[str, Any]
error¶
- exception Error¶
Bases:
Exception
Base class of all Brayns exceptions.
Can be used to catch only brayns specific errors.
image¶
- class ImageFormat(value)¶
Bases:
Enum
Enumeration of all supported image format.
Values are the image format file extension without the dot.
- Parameters:
JPEG – JPEG format, smaller but lose quality.
PNG – PNG format, bigger but lossless.
- JPEG = 'jpg'¶
- PNG = 'png'¶
- class Resolution(width: int, height: int)¶
Bases:
Vector
[int
]Image resolution.
Resolution is a Vector of integers and can be handled as such.
- Parameters:
width (int) – Image width in pixels.
height (int) – Image height in pixels.
- property aspect_ratio: float¶
Get aspect ratio.
- Returns:
Width / height.
- Return type:
float
- class property full_hd: Resolution¶
Create a full HD (1920x1080) resolution.
- Returns:
Full HD resolution.
- Return type:
- property height: int¶
- class property production: Resolution¶
Create a production (15360x8640) resolution.
- Returns:
Production resolution.
- Return type:
- class property ultra_hd: Resolution¶
Create a 4K (3840x2160) resolution.
- Returns:
Ultra HD resolution.
- Return type:
- property width: int¶
- parse_image_format(filename: str | Path) ImageFormat ¶
Parse the image format from a file path using its extension.
Supports both string and Path input.
- Parameters:
filename (str | Path) – Image file path.
- Returns:
Image format.
- Return type:
plane_equation¶
- class PlaneEquation(a: float, b: float, c: float, d: float = 0.0)¶
Bases:
Vector
[float
]Plane equation satisfying ax + by + cz + d = 0.
Normal and direction point to the upper side of the plane.
- Parameters:
a (float) – A component.
b (float) – B component.
c (float) – C component.
d (float) – D component.
- property a: float¶
- property b: float¶
- property c: float¶
- property d: float¶
- static of(normal: Vector3, point: Vector3) PlaneEquation ¶
Compute the equation of a plane from its normal and a point.
- Parameters:
- Returns:
Plane equation.
- Return type:
quaternion¶
- class Quaternion(x: float = 0.0, y: float = 0.0, z: float = 0.0, w: float = 1.0)¶
Bases:
Vector
[float
]Quaternion with XYZW components.
Provides vector operations (componentwise) and quaternion special operators (multiplication, conjugate, etc).
- Parameters:
x (float, optional) – X component, defaults to 0.
y (float, optional) – Y component, defaults to 0.
z (float, optional) – Z component, defaults to 0.
w (float, optional) – W component, defaults to 1.
- property angle_degrees: float¶
- property angle_radians: float¶
- property conjugate: Quaternion¶
- class property identity: Quaternion¶
Quaternion with XYZW components.
Provides vector operations (componentwise) and quaternion special operators (multiplication, conjugate, etc).
- Parameters:
x (float, optional) – X component, defaults to 0.
y (float, optional) – Y component, defaults to 0.
z (float, optional) – Z component, defaults to 0.
w (float, optional) – W component, defaults to 1.
- property inverse: Quaternion¶
- property w: float¶
- property x: float¶
- property y: float¶
- property z: float¶
transform¶
- class Transform(translation: ~brayns.utils.vector.Vector3 = (0.0, 0.0, 0.0), rotation: ~brayns.utils.rotation.Rotation = <brayns.utils.rotation.Rotation object>, scale: ~brayns.utils.vector.Vector3 = (1.0, 1.0, 1.0))¶
Bases:
object
3D transformation.
Used to move models in 3D space.
It is equivalent to a TRS matrix multiplication.
It means we first scale the point at the origin, then rotate around the same origin and finally we translate it to its position.
- Parameters:
- class property identity: Transform¶
Create an identity transform (doesn’t do anything).
- Returns:
Identity transform.
- Return type: