Skip to content

Commit f4c55dd

Browse files
Sofa Rendering API inherits from Core Rendering API.
1 parent 1f7295e commit f4c55dd

File tree

9 files changed

+182
-412
lines changed

9 files changed

+182
-412
lines changed

docs/src/SOFA/rendering.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Adding callbacks is very simple, since you only have to specify:
3636
(depending on the object type).
3737
* option ``animated=True`` (by default)
3838

39+
It is also possible to create and update objects manually such as in the ``Core`` version.
40+
3941

4042
.. tabs::
4143

@@ -66,12 +68,12 @@ Adding callbacks is very simple, since you only have to specify:
6668
6769
# Create a new Factory
6870
factory = UserAPI(root=root, database_name='ball', remove_existing=True)
69-
factory.add_points(position_object='@ball.BallMO', animated=False,
70-
at=0, c='red4', point_size=8)
71-
factory.add_mesh(position_object='@ball.visual.BallOGL', cell_type='triangles', animated=True,
72-
at=0, c='green', alpha=0.8)
73-
factory.add_mesh(position_object='@ball.visual.BallOGL', cell_type='quads', animated=True,
74-
at=0, c='green', alpha=0.8)
71+
factory.add_points_callback(position_object='@ball.BallMO', animated=False,
72+
at=0, c='red4', point_size=8)
73+
factory.add_mesh_callback(position_object='@ball.visual.BallOGL', cell_type='triangles', animated=True,
74+
at=0, c='green', alpha=0.8)
75+
factory.add_mesh_callback(position_object='@ball.visual.BallOGL', cell_type='quads', animated=True,
76+
at=0, c='green', alpha=0.8)
7577
factory.launch_visualizer(backend='vedo')
7678
7779
# Init the scene graph and run some step of the simulation
@@ -104,12 +106,12 @@ Adding callbacks is very simple, since you only have to specify:
104106
105107
# Create a new Visualizer and a new Factory (pay attention to offscreen flag)
106108
factory = UserAPI(root=root, database_name='ball', remove_existing=True)
107-
factory.add_points(position_object='@ball.BallMO', animated=False,
108-
at=0, c='red4', point_size=8)
109-
factory.add_mesh(position_object='@ball.visual.BallOGL', cell_type='triangles', animated=True,
110-
at=0, c='green', alpha=0.8)
111-
factory.add_mesh(position_object='@ball.visual.BallOGL', cell_type='quads', animated=True,
112-
at=0, c='green', alpha=0.8)
109+
factory.add_points_callback(position_object='@ball.BallMO', animated=False,
110+
at=0, c='red4', point_size=8)
111+
factory.add_mesh_callback(position_object='@ball.visual.BallOGL', cell_type='triangles', animated=True,
112+
at=0, c='green', alpha=0.8)
113+
factory.add_mesh_callback(position_object='@ball.visual.BallOGL', cell_type='quads', animated=True,
114+
at=0, c='green', alpha=0.8)
113115
factory.launch_visualizer(offscreen=True)
114116
115117

examples/SOFA/rendering-offscreen/Caduceus.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,26 @@ def onSimulationInitDoneEvent(self, _):
109109
if self.factory is not None:
110110

111111
# Window 1: Snake visual meshes for body (id=0) and eyes (id=1)
112-
self.factory.add_mesh(position_object='@snake.visual.body.OglBody', cell_type='quads', animated=True,
113-
at=0, c='#93493a')
114-
self.factory.add_mesh(position_object='@snake.visual.eye.OglEye', cell_type='quads', animated=True,
115-
at=0, c='yellow5')
112+
self.factory.add_mesh_callback(position_object='@snake.visual.body.OglBody', cell_type='quads',
113+
animated=True, at=0, c='#93493a')
114+
self.factory.add_mesh_callback(position_object='@snake.visual.eye.OglEye', cell_type='quads',
115+
animated=True, at=0, c='yellow5')
116116

117117
# Window 1: Base visual meshes for quads (id=2) and triangles (id=3)
118-
self.factory.add_mesh(position_object='@base.visual.OglBase', cell_type='quads', animated=False,
119-
at=0, c='orange4')
120-
self.factory.add_mesh(position_object='@base.visual.OglBase', cell_type='triangles', animated=False,
121-
at=0, c='orange4')
118+
self.factory.add_mesh_callback(position_object='@base.visual.OglBase', cell_type='quads',
119+
animated=False, at=0, c='orange4')
120+
self.factory.add_mesh_callback(position_object='@base.visual.OglBase', cell_type='triangles',
121+
animated=False, at=0, c='orange4')
122122

123123
# Window 2: Snake collision mesh (id=4)
124-
self.factory.add_mesh(position_object='@snake.collision.SnakeCollMo', animated=True,
125-
topology_object='@snake.collision.SnakeCollTopo', cell_type='triangles',
126-
at=1, c='orange7', wireframe=True, line_width=2)
124+
self.factory.add_mesh_callback(position_object='@snake.collision.SnakeCollMo', animated=True,
125+
topology_object='@snake.collision.SnakeCollTopo', cell_type='triangles',
126+
at=1, c='orange7', wireframe=True, line_width=2)
127127

128128
# Window 2: Base Collision meshes for stick (id=5), blobs (id=6) and foot (id=7)
129-
self.factory.add_mesh(position_object='@base.stick.StickCollTopo', cell_type='edges', animated=False,
130-
at=1, c='orange7', wireframe=True, line_width=2)
131-
self.factory.add_mesh(position_object='@base.blobs.BlobsCollTopo', cell_type='triangles', animated=False,
132-
at=1, c='orange7', wireframe=True, line_width=2)
133-
self.factory.add_mesh(position_object='@base.foot.FootCollTopo', cell_type='triangles', animated=False,
134-
at=1, c='orange7', wireframe=True, line_width=2)
129+
self.factory.add_mesh_callback(position_object='@base.stick.StickCollTopo', cell_type='edges',
130+
animated=False, at=1, c='orange7', wireframe=True, line_width=2)
131+
self.factory.add_mesh_callback(position_object='@base.blobs.BlobsCollTopo', cell_type='triangles',
132+
animated=False, at=1, c='orange7', wireframe=True, line_width=2)
133+
self.factory.add_mesh_callback(position_object='@base.foot.FootCollTopo', cell_type='triangles',
134+
animated=False, at=1, c='orange7', wireframe=True, line_width=2)

examples/SOFA/rendering-offscreen/replay.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
raise FileNotFoundError("You must create the Database using `python3 record.py` before to replay it.")
99

1010
# Launch Visualizer
11-
Replay(database_name='caduceus').launch()
12-
11+
Replay(database_name='caduceus', fps=50).launch()

examples/SOFA/rendering/Liver.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,30 @@ def onSimulationInitDoneEvent(self, _):
6262
# Add object to the factory
6363
if self.factory is not None:
6464
# Window 1: Liver only (id=0)
65-
self.factory.add_mesh(position_object='@liver.visual.LiverOgl',
66-
cell_type='triangles', animated=True,
67-
at=0, c='red5')
65+
self.factory.add_mesh_callback(position_object='@liver.visual.LiverOgl', cell_type='triangles',
66+
animated=True, at=0, c='red5')
6867

6968
# Window 2: Liver (id=1) + Force (id=2)
70-
self.factory.add_mesh(position_object='@liver.visual.LiverOgl',
71-
cell_type='triangles', animated=True,
72-
at=1, c='green8', wireframe=True, line_width=1)
73-
self.factory.add_arrows(position_object='@liver.surface.SurfaceMO', vector_object='@liver.surface.CFF',
74-
animated=True, start_indices=array([33]),
75-
at=1, scale=0.5e-3, c='green3', res=20)
69+
self.factory.add_mesh_callback(position_object='@liver.visual.LiverOgl', cell_type='triangles',
70+
animated=True, at=1, c='green8', wireframe=True, line_width=1)
71+
self.factory.add_arrows_callback(position_object='@liver.surface.SurfaceMO',
72+
vector_object='@liver.surface.CFF', start_indices=array([33]),
73+
animated=True, at=1, scale=0.5e-3, c='green3', res=20)
7674

7775
# Window 3: Grid (id=3 & id=4) + Constraint (id=5)
78-
self.factory.add_points(position_object='@liver.GridMO', animated=True,
79-
at=2, c='grey3', point_size=8)
80-
self.factory.add_mesh(position_object='@liver.GridMO', topology_object='@liver.Grid',
81-
cell_type='tetrahedra', animated=True,
82-
at=2, c='grey3', wireframe=True, line_width=1)
76+
self.factory.add_points_callback(position_object='@liver.GridMO', animated=True,
77+
at=2, c='grey3', point_size=8)
78+
self.factory.add_mesh_callback(position_object='@liver.GridMO', topology_object='@liver.Grid',
79+
cell_type='tetrahedra', animated=True,
80+
at=2, c='grey3', wireframe=True, line_width=1)
8381
self.factory.add_markers(normal_to=4, indices=array([3, 39, 64]),
8482
at=2, c='red3', size=0.5, symbol='0', filled=False)
8583

8684
# Window 4: Liver Displacement (id=6)
8785
nb_points = len(self.root.liver.visual.getObject('LiverOgl').position.value)
88-
self.factory.add_mesh(position_object='@liver.visual.LiverOgl',
89-
cell_type='triangles', animated=True,
90-
at=3, alpha=0.6, colormap='coolwarm', scalar_field=zeros((nb_points,)))
86+
self.factory.add_mesh_callback(position_object='@liver.visual.LiverOgl', cell_type='triangles',
87+
animated=True, at=3, alpha=0.6, colormap='coolwarm',
88+
scalar_field=zeros((nb_points,)))
9189

9290
def onAnimateBeginEvent(self, _):
9391

examples/SOFA/storage/Caduceus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,6 @@ def onAnimateEndEvent(self, _):
148148
data={'U': coll_mo.position.array() - coll_mo.rest_position.array()})
149149

150150
# Shape Data
151-
X = self.root.snake.visual.body.getObject('OglBody').position.array()
151+
shape = self.root.snake.visual.body.getObject('OglBody').position.array()
152152
self.database.add_data(table_name='SnakeShape',
153-
data={'height': X.max(), 'size': X.max() - X.min()})
153+
data={'height': shape.max(), 'size': shape.max() - shape.min()})

src/Core/Rendering/UserAPI.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ def render(self) -> None:
140140
self.__socket.close()
141141
self.__socket = None
142142
except ConnectionResetError:
143-
self.kill()
143+
self.__kill()
144144
except BrokenPipeError:
145-
self.kill()
145+
self.__kill()
146146
else:
147-
self.kill()
147+
self.__kill()
148148

149-
def kill(self):
149+
def __kill(self):
150150
"""
151151
Kill the program on Visualizer close.
152152
"""

src/Core/Rendering/backend/BaseReplay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self,
2020
self.database = database
2121

2222
# Visualization parameters
23-
self.fps: float = 1 / min(max(1, abs(fps)), 50)
23+
self.fps: float = 1 / min(max(1, abs(fps)), 100)
2424
self.nb_sample: Dict[str, int] = {}
2525
self.step: int = 1
2626

0 commit comments

Comments
 (0)