API

Storage

Database

class SSD.SOFA.Storage.Database.Database(*args: Any, **kwargs: Any)[source]
__init__(root: Sofa.Core.Node, database_dir: str = '', database_name: str = 'runSofa', *args, **kwargs)[source]

Manage the creation and loading of Tables in the Database. User interface to dynamically add, get and update entries. Additional callbacks to automatically get SOFA objects Data.

Parameters:
  • root – Root node of the scene graph.

  • database_dir – Directory which contains the Database file.

  • database_name – Name of the Database file.

add_callback(table_name: str, field_name: str, record_object: str, record_field: str)[source]

Add a callback on an object Data field. If the specified Table or Field does not exist, create them.

Parameters:
  • table_name – Name of the Table.

  • field_name – Name of the Field.

  • record_object – Path to the SOFA object in the scene graph from root node (@child_node.object_name’).

  • record_field – The name of the Data field to record.

add_data(table_name: str, data: Dict[str, Any])[source]

Execute a line insert query.

Parameters:
  • table_name – Name of the Table.

  • data – New line of the Table.

onAnimateBeginEvent(_)[source]

At the beginning of a time step.

onAnimateEndEvent(_)[source]

At the end of a time step.

print_architecture()[source]

Print the content of the Database with Table(s), Field(s) and connected SOFA objects.

Rendering

UserAPI

class SSD.SOFA.Rendering.UserAPI.UserAPI(*args: Any, **kwargs: Any)[source]
__init__(root: Sofa.Core.Node, database: Database | None = None, database_dir: str = '', database_name: str | None = None, remove_existing: bool = False, non_storing: bool = False, idx_instance: int = 0, *args, **kwargs)[source]

The UserAPI is a Factory used to easily create and update visual objects in the Visualizer. This SOFA version brings additional callbacks to automatically get SOFA objects Data.

Parameters:
  • root – Root node of the sce graph.

  • database – Database to connect to.

  • database_dir – Directory which contains the Database file (used if ‘database’ is not defined).

  • database_name – Name of the Database to connect to (used if ‘database’ is not defined).

  • remove_existing – If True, overwrite a Database with the same path.

  • non_storing – If True, the Database will not be stored.

  • idx_instance – If several Factories must be created, specify the index of the Factory.

add_arrows(position_object: str, vector_object: str | None = None, dest_object: str | None = None, start_indices: ndarray | None = None, end_indices: ndarray | None = None, scale: float = 1.0, animated: bool = True, at: int = 0, alpha: float = 1.0, c: str = 'green', colormap: str = 'jet', scalar_field: ndarray = array([], dtype=float64), res: int = 12) int[source]

Add new Arrows to the Factory.

Parameters:
  • position_object – Path to an object containing start position Data.

  • vector_object – Path to an object containing vector Data. If None, vectors will be computed from ‘dest_object’ end positions.

  • dest_object – Path to an object containing end position Data.

  • start_indices – Indices of the start positions to extract.

  • end_indices – Indices of the vectors or the end positions to extract.

  • scale – Scale factor to apply to vectors.

  • animated – If True, the object will be automatically updated at each step.

  • at – Index of the window in which to Mesh will be rendered.

  • alpha – Arrows opacity.

  • c – Arrows color.

  • colormap – Colormap scheme name.

  • scalar_field – Scalar values used to color the Arrows regarding the colormap.

  • res – Circular resolution of the arrows.

add_markers(normal_to: int, indices: ndarray, animated: bool = True, at: int = 0, alpha: float = 1.0, c: str = 'green', colormap: str = 'jet', scalar_field: ndarray = array([], dtype=float64), symbol: str = 'o', size: float = 1.0, filled: bool = True) int[source]

Add new Markers to the Factory.

Parameters:
  • normal_to – Index of the object that defines normals of the Markers.

  • indices – Indices of the DOFs of the object where the Markers will be centered.

  • animated

  • at – Index of the window in which to Mesh will be rendered.

  • alpha – Markers opacity.

  • c – Markers color.

  • colormap – Colormap scheme name.

  • scalar_field – Scalar values used to color the Markers regarding the colormap.

  • symbol – Symbol of a Marker.

  • size – Size of a Marker.

  • filled – If True, the symbol is filled.

add_mesh(position_object: str, topology_object: str | None = None, cell_type: str = 'triangles', animated=True, at: int = 0, alpha: float = 1.0, c: str = 'green', colormap: str = 'jet', scalar_field: ndarray = array([], dtype=float64), wireframe: bool = False, line_width: float = -1.0) int[source]

Add a new Mesh to the Factory.

Parameters:
  • position_object – Path to an object containing position and eventually topology Data.

  • topology_object – Path to an object containing topology Data. If not defined, topology data will be searched in ‘position_object’.

  • cell_type – Type of the cells (‘edges’, ‘triangles’, ‘quads’, ‘tetrahedra’, ‘hexahedra’).

  • animated – If True, the object will be automatically updated at each step.

  • at – Index of the window in which to Mesh will be rendered.

  • alpha – Mesh opacity.

  • c – Mesh color.

  • colormap – Colormap scheme name.

  • scalar_field – Scalar values used to color the Mesh regarding the colormap.

  • wireframe – If True, the Mesh will be rendered as wireframe.

  • line_width – Width of the edges of the faces.

add_points(position_object: str, position_indices: ndarray | None = None, animated=True, at: int = 0, alpha: float = 1.0, c: str = 'green', colormap: str = 'jet', scalar_field: ndarray = array([], dtype=float64), point_size: int = 4) int[source]

Add a new Mesh to the Factory.

Parameters:
  • position_object – Path to an object containing position Data.

  • position_indices – Indices of the positions to extract. If None, all the positions are used.

  • animated – If True, the object will be automatically updated at each step.

  • at – Index of the window in which to Mesh will be rendered.

  • alpha – Mesh opacity.

  • c – Mesh color.

  • colormap – Colormap scheme name.

  • scalar_field – Scalar values used to color the Mesh regarding the colormap.

  • point_size – Size of the points.

add_text(content: str, at: int = 0, corner: str = 'BR', c: str = 'black', font: str = 'Arial', size: int = -1, bold: bool = False, italic: bool = False) int[source]

Add new 2D Text to the Factory.

Parameters:
  • content – Content of the Text.

  • at – Index of the window in which the Text will be rendered.

  • corner – Horizontal and vertical positions of the Text between T (top), M (middle) and B (bottom) - for instance, ‘BR’ stands for ‘bottom-right’.

  • c – Text color.

  • font – Font of the Text.

  • size – Size of the font.

  • bold – Apply bold style to the Text.

  • italic – Apply italic style to the Text.

close()[source]

Close the Visualization.

connect_visualizer(offscreen: bool = False)[source]

Connect the Factory to an existing Visualizer.

Parameters:

offscreen – If True, the visualization is done offscreen.

get_database() Database[source]

Get the Database instance.

get_database_path() Tuple[str][source]

Get the path to the Database.

launch_visualizer(backend: str = 'vedo', offscreen: bool = False, fps: int = 20) None[source]

Launch the Visualizer.

Parameters:
  • backend – The name of the Visualizer to use (either ‘vedo’ or ‘open3d’).

  • offscreen – If True, the visualization is done offscreen.

  • fps – Max frame rate.

onAnimateEndEvent(_) None[source]

Event called at the end of a time step.

update_arrows(object_id: int, positions: ndarray | None = None, vectors: ndarray | None = None, alpha: float | None = None, c: str | None = None, scalar_field: ndarray | None = None) None[source]

Update existing Arrows in the Factory.

Parameters:
  • object_id – Index of the object (follows the global order of creation).

  • positions – Positions of the Arrows DOFs.

  • vectors – Vectors of the Arrows.

  • alpha – Arrows opacity.

  • c – Arrows color.

  • scalar_field – Scalar values used to color the Arrows regarding the colormap.

update_markers(object_id: int, normal_to: int | None = None, indices: ndarray | None = None, alpha: float | None = None, c: str | None = None, scalar_field: ndarray | None = None, symbol: str | None = None, size: float | None = None, filled: bool | None = None) None[source]

Update existing Markers in the Factory.

Parameters:
  • object_id – Index of the object (follows the global order of creation).

  • normal_to – Index of the object that defines normals of the Markers.

  • indices – Indices of the DOFs of the object where the Markers will be centered.

  • alpha – Markers opacity.

  • c – Markers color.

  • scalar_field – Scalar values used to color the Markers regarding the colormap.

  • symbol – Symbol of a Marker.

  • size – Size of a Marker.

  • filled – If True, the symbol is filled.

update_mesh(object_id: int, positions: ndarray | None = None, alpha: float | None = None, c: str | None = None, scalar_field: ndarray | None = None, wireframe: bool | None = None) None[source]

Update an existing Mesh in the Factory.

Parameters:
  • object_id – Index of the object (follows the global order of creation).

  • positions – Positions of the Mesh DOFs.

  • alpha – Mesh opacity.

  • c – Mesh color.

  • scalar_field – Scalar values used to color the Mesh regarding the colormap.

  • wireframe – If True, the Mesh will be rendered as wireframe.

update_points(object_id: int, positions: ndarray | None = None, alpha: float | None = None, c: str | None = None, scalar_field: ndarray | None = None, point_size: int | None = None) None[source]

Update an existing Point Cloud in the Factory.

Parameters:
  • object_id – Index of the object (follows the global order of creation).

  • positions – Positions of the Point Cloud DOFs.

  • alpha – Point Cloud opacity.

  • c – Point Cloud color.

  • scalar_field – Scalar values used to color the Point Cloud regarding the colormap.

  • point_size – Size of the points.

update_text(object_id: int, content: str | None = None, c: str | None = None, bold: bool | None = None, italic: bool | None = None) None[source]

Update existing Text in the Factory.

Parameters:
  • object_id – Index of the object (follows the global order of creation).

  • content – Content of the Text.

  • c – Text color.

  • bold – Apply bold style to the Text.

  • italic – Apply italic style to the Text.

Visualizer

class SSD.SOFA.Rendering.Visualizer.Visualizer(backend: str = 'vedo', database: Database | None = None, database_dir: str = '', database_name: str | None = None, remove_existing: bool = False, fps: int = 20, nb_clients: int = 1)[source]
__init__(backend: str = 'vedo', database: Database | None = None, database_dir: str = '', database_name: str | None = None, remove_existing: bool = False, fps: int = 20, nb_clients: int = 1)[source]

The Visualizer is used to launch either the VedoVisualizer either the Open3dVisualizer. It is recommended to launch the visualizer with UserAPI.launch_visualizer() method.

Parameters:
  • backend – The name of the Visualizer to use (either ‘vedo’ or ‘open3d’).

  • database – Database to connect to.

  • database_dir – Directory which contains the Database file (used if ‘database’ is not defined).

  • database_name – Name of the Database (used if ‘database’ is not defined).

  • remove_existing – If True, overwrite a Database with the same path.

  • fps – Max frame rate.

Replay

class SSD.SOFA.Rendering.Replay.Replay(database_name: str, database_dir: str = '', backend: str = 'vedo', fps: int = 20)[source]
__init__(database_name: str, database_dir: str = '', backend: str = 'vedo', fps: int = 20)[source]

Replay a simulation from saved visual data.

Parameters:
  • database_name – Name of the Database.

  • database_dir – Directory of the Database.

  • backend – The name of the Visualizer to use (either ‘vedo’ or ‘open3d’).

  • fps – Max frame rate.