API

Core

class SimRender.core.local.viewer.Viewer(sync: bool = False)[source]
__init__(sync: bool = False)[source]

This class manages a single remote viewer to render visual objects.

Parameters:

sync – If True, the rendering step will block the python code execution. Otherwise, the viewer will only render the current status of the simulation. Use it if you want to make sure that all your simulation steps are rendered.

launch(batch_key: int | None = None) None[source]

Launch the rendering window in its own python process.

render() None[source]

Render the current step of the simulation.

shutdown() None[source]

Close the rendering window.

class SimRender.core.local.player.Player[source]
__init__()[source]

This class manages a single remote viewer to render visual objects.

launch(batch_key: int | None = None) None

Launch the rendering window in its own python process.

render() None

Render the current step of the simulation.

shutdown() None

Close the rendering window.

class SimRender.core.local.viewer_batch.ViewerBatch[source]
start(nb_view: int) List[int][source]

Launch the rendering window in its own python process.

Parameters:

nb_view – Number of simulations sources to render.

stop() None[source]

Close the rendering window.

class SimRender.core.local.factory.Objects(factory: Factory)[source]
add_arrows(positions: ndarray, vectors: ndarray, color: str = 'green', alpha: float = 1.0, colormap: str = 'jet', colormap_field: ndarray = array(nan), colormap_range: ndarray = array(nan)) int[source]

Add a new point cloud in the viewer.

Parameters:
  • positions – Positions of the arrows bases.

  • vectors – Vectors of the arrows.

  • color – Color of the arrows.

  • alpha – Opacity of the arrows.

  • colormap – Color map scheme name.

  • colormap_field – Scalar values to color the point cloud regarding the colormap.

  • colormap_range – Range of the color map.

Returns:

ID of the object in the viewer.

add_lines(start_positions: ndarray, end_positions: ndarray, color: str = 'green', alpha: float = 1.0, line_width: float = 1.0) int[source]

Add line segments to the viewer.

Parameters:
  • start_positions – Start position of each line segment.

  • end_positions – End position of each line segment.

  • color – Color of the lines.

  • alpha – Opacity of the lines.

  • line_width – Width of the lines.

Returns:

ID of the object in the viewer.

add_mesh(positions: ndarray, cells: List[int], color: str = 'green', alpha: float = 1.0, wireframe: bool = False, line_width: float = 1.0, colormap: str = 'jet', colormap_field: ndarray = array(nan), colormap_range: ndarray = array(nan), texture_name: str = '', texture_coords: ndarray = array(nan)) int[source]

Add a new mesh in the viewer.

Parameters:
  • positions – Positions of the mesh.

  • cells – Faces of the mesh.

  • color – Color of the mesh.

  • alpha – Opacity of the mesh.

  • wireframe – If True, the mesh has a wireframe representation.

  • line_width – Width of the mesh edges.

  • colormap – Color map scheme name.

  • colormap_field – Scalar values to color the mesh regarding the colormap.

  • colormap_range – Range of the color map.

  • texture_name – Name of the texture file.

  • texture_coords – Texture coordinates.

Returns:

ID of the object in the viewer.

add_points(positions: ndarray, color: str = 'green', alpha: float = 1.0, point_size: int = 4, colormap: str = 'jet', colormap_field: ndarray = array(nan), colormap_range: ndarray = array(nan)) int[source]

Add a new point cloud in the viewer.

Parameters:
  • positions – Positions of the point cloud.

  • color – Color of the point cloud.

  • alpha – Opacity of the point cloud.

  • point_size – Size of points.

  • colormap – Color map scheme name.

  • colormap_field – Scalar values to color the point cloud regarding the colormap.

  • colormap_range – Range of the color map.

Returns:

ID of the object in the viewer.

add_text(content: str, corner: str = 'BR', color: str = 'black', font: str = '', size: int = 1, bold: bool = False, italic: bool = False) int[source]

Add 2D text in the viewer.

Parameters:
  • content – Text content (max 100 car.).

  • corner – Vertical (Top, Middle, Bottom) and horizontal (Left, Middle, Right) positions of the Text - for instance, ‘BR’ stands for ‘bottom-right’.

  • color – Text color.

  • font – Text font name.

  • size – Text size.

  • bold – If True, apply bold style to the text.

  • italic – If True, apply italic style to the text.

Returns:

ID of the object in the viewer.

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

Update an existing point cloud in the viewer.

Parameters:
  • object_id – ID of the object as returned when created.

  • positions – Positions of the point cloud.

  • vectors – Vectors of the arrows.

  • color – Color of the point cloud.

  • alpha – Opacity of the point cloud.

  • colormap_field – Scalar values to color the point cloud regarding the colormap.

update_lines(object_id: int, start_positions: ndarray | None = None, end_positions: ndarray | None = None, color: str | None = None, alpha: float | None = None, line_width: float | None = None) None[source]

Update existing line segments in the viewer.

Parameters:
  • object_id – ID of the object as returned when created.

  • start_positions – Start position of each line segment.

  • end_positions – End position of each line segment.

  • color – Color of the lines.

  • alpha – Opacity of the lines.

  • line_width – Width of the lines.

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

Update an existing mesh in the viewer.

Parameters:
  • object_id – ID of the object as returned when created.

  • positions – Positions of the mesh.

  • color – Color of the mesh.

  • alpha – Opacity of the mesh.

  • wireframe – If True, the mesh has a wireframe representation.

  • line_width – Width of the mesh edges.

  • colormap_field – Scalar values to color the mesh regarding the colormap.

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

Update an existing point cloud in the viewer.

Parameters:
  • object_id – ID of the object as returned when created.

  • positions – Positions of the point cloud.

  • color – Color of the point cloud.

  • alpha – Opacity of the point cloud.

  • point_size – Size of points.

  • colormap_field – Scalar values to color the point cloud regarding the colormap.

update_text(object_id: int, content: str, color: str = 'black', bold: bool = False, italic: bool = False) None[source]

Update an existing text in the viewer.

Parameters:
  • object_id – ID of the object as returned when created.

  • content – Text content (max 100 car.).

  • color – Text color.

  • bold – If True, apply bold style to the text.

  • italic – If True, apply italic style to the text.

SOFA

class SimRender.sofa.local.viewer.Viewer(root_node: Sofa.Core.Node, sync: bool = False)[source]
__init__(root_node: Sofa.Core.Node, sync: bool = False)[source]

This class manages a single remote viewer to render SOFA objects.

Parameters:
  • root_node – Root node of the SOFA scene graph.

  • sync – If True, the rendering step will block the python code execution. Otherwise, the viewer will only render the current status of the simulation. Use it if you want to make sure that all your simulation steps are rendered.

launch(batch_key: int | None = None) None[source]

Launch the rendering window in its own python process.

render() None[source]

Render the current step of the simulation.

shutdown() None[source]

Close the rendering window.

class SimRender.sofa.local.factory.Objects(root_node: Sofa.Core.Node, factory: Factory)[source]
add_scene_graph(visual_models: bool = True, behavior_models: bool = False, force_fields: bool = False, collision_models: bool = False) None[source]

The whole SOFA scene graph is explored to create visual objects automatically.

Parameters:
  • visual_models – If True, display each detected visual model in the scene graph.

  • behavior_models – If True, display each detected behavior model in the scene graph.

  • force_fields – If True, display each detected force field in the scene graph.

  • collision_models – If True, display each detected collision model in the scene graph.

add_sofa_arrows(positions_data: Sofa.Core.Data, vectors_data: Sofa.Core.Data, color: str = 'green', alpha: float = 1.0, colormap: str = 'jet', colormap_range: ndarray = array(nan), colormap_function: Callable | None = None) int[source]

Add a new point cloud in the viewer.

Parameters:
  • positions_data – SOFA Data field containing the positions of the arrows bases.

  • vectors_data – SOFA Data field containing the vectors of the arrows.

  • color – Color of the arrows.

  • alpha – Opacity of the arrows.

  • colormap – Color map scheme name.

  • colormap_range – Range of the color map.

  • colormap_function – Function to compute at each time step the scalar values to color the arrows regarding the color map.

Returns:

ID of the object in the viewer.

add_sofa_mesh(positions_data: Sofa.Core.Data, cells_data: Sofa.Core.Data | List[Sofa.Core.Data], color: str = 'green', alpha: float = 1.0, wireframe: bool = False, line_width: float = 1.0, colormap: str = 'jet', colormap_range: ndarray = array(nan), colormap_function: Callable | None = None) int[source]

Add a new mesh object in the viewer and record it automatically using the SOFA Data fields.

Parameters:
  • positions_data – SOFA Data field containing the positions of the mesh.

  • cells_data – SOFA Data field(s) containing the faces of the mesh.

  • color – Color of the mesh.

  • alpha – Opacity of the mesh.

  • wireframe – If True, the mesh has a wireframe representation.

  • line_width – Width of the mesh edges.

  • colormap – Color map scheme name.

  • colormap_range – Range of the color map.

  • colormap_function – Function to compute at each time step the scalar values to color the mesh regarding the color map.

Returns:

ID of the object in the viewer.

add_sofa_points(positions_data: Sofa.Core.Data, color: str = 'green', alpha: float = 1.0, point_size: int = 4, colormap: str = 'jet', colormap_range: ndarray = array(nan), colormap_function: Callable | None = None) int[source]

Add a new point cloud in the viewer and record it automatically using the SOFA Data fields.

Parameters:
  • positions_data – SOFA Data field containing the positions of the points.

  • color – Color of the point cloud.

  • alpha – Opacity of the point cloud.

  • point_size – Size of points.

  • colormap – Color map scheme name.

  • colormap_range – Range of the color map.

  • colormap_function – Function to compute at each time step the scalar values to color the points regarding the color map.

Returns:

ID of the object in the viewer.