Skip to content

Commit 4b774ef

Browse files
Update Sofa package.
1 parent aee7e46 commit 4b774ef

File tree

17 files changed

+139
-78
lines changed

17 files changed

+139
-78
lines changed

examples/SOFA/rendering-offscreen/Caduceus.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Optional
22
import Sofa
33

4-
from SSD.SOFA import UserAPI
4+
from SSD.SOFA.Rendering import UserAPI
55

66

77
class Caduceus(Sofa.Core.Controller):
@@ -17,37 +17,43 @@ def __init__(self, root, factory: Optional[UserAPI] = None, *args, **kwargs):
1717
# Root
1818
self.root.gravity.value = [0, -1000, 0]
1919
self.root.dt.value = 0.04
20-
required_plugins = ['Sofa.Component', 'Sofa.GL.Component']
20+
with open('plugins.txt', 'r') as file:
21+
required_plugins = [plugin[:-1] if plugin.endswith('\n') else plugin for plugin in file.readlines()
22+
if plugin != '\n']
2123
self.root.addObject('RequiredPlugin', pluginName=required_plugins)
2224
self.root.addObject('VisualStyle', displayFlags='showVisual')
2325
self.root.addObject('FreeMotionAnimationLoop', parallelCollisionDetectionAndFreeMotion=True)
24-
self.root.addObject('DefaultPipeline', depth=15, verbose=0, draw=0)
26+
self.root.addObject('CollisionPipeline', depth=15, verbose=0, draw=0)
2527
self.root.addObject('BruteForceBroadPhase')
2628
self.root.addObject('BVHNarrowPhase')
2729
self.root.addObject('MinProximityIntersection', alarmDistance=1.5, contactDistance=1)
28-
self.root.addObject('DefaultContactManager', response='FrictionContactConstraint')
30+
self.root.addObject('CollisionResponse', response='FrictionContactConstraint')
2931
self.root.addObject('LCPConstraintSolver', tolerance=1e-3, maxIt=1000, initial_guess=False, build_lcp=False,
3032
printLog=0, mu=0.2)
3133

3234
# Camera
3335
self.root.addObject('InteractiveCamera', position=[0, 30, 90], lookAt=[0, 30, 0])
3436
self.root.addObject('LightManager')
35-
self.root.addObject('SpotLight', position=[0, 80, 25], direction=[0, -1, -0.8], cutoff=30, exponent=1)
36-
self.root.addObject('SpotLight', position=[0, 40, 100], direction=[0, 0, -1], cutoff=30, exponent=1)
37+
self.root.addObject('SpotLight', name='light1', position=[0, 80, 25], direction=[0, -1, -0.8], cutoff=30,
38+
exponent=1)
39+
self.root.addObject('SpotLight', name='light2', position=[0, 40, 100], direction=[0, 0, -1], cutoff=30,
40+
exponent=1)
3741

3842
# Snake.Physics
3943
self.root.addChild('snake')
4044
self.root.snake.addObject('MeshOBJLoader', name='Snake', filename='mesh/snake_body.obj')
4145
self.root.snake.addObject('EulerImplicitSolver', rayleighMass=1, rayleighStiffness=0.03)
46+
self.root.snake.addObject('MatrixLinearSystem', name='LinearSystem', template='CompressedRowSparseMatrixMat3x3')
4247
self.root.snake.addObject('CGLinearSolver', iterations=20, tolerance=1e-12, threshold=1e-18,
43-
template='CompressedRowSparseMatrixMat3x3d')
48+
template='CompressedRowSparseMatrixMat3x3d', linearSystem='@LinearSystem')
4449
self.root.snake.addObject('SparseGridRamificationTopology', name='Grid', src='@Snake', n=[4, 12, 3],
4550
nbVirtualFinerLevels=3, finestConnectivity=0)
46-
self.root.snake.addObject('MechanicalObject', src='@Grid', scale=1, dy=2)
51+
self.root.snake.addObject('MechanicalObject', name='GridMO', src='@Grid', scale=1, dy=2)
4752
self.root.snake.addObject('UniformMass', totalMass=1.)
4853
self.root.snake.addObject('HexahedronFEMForceField', youngModulus=30000, poissonRatio=0.3, method='large',
4954
updateStiffnessMatrix=False)
50-
self.root.snake.addObject('UncoupledConstraintCorrection', useOdeSolverIntegrationFactors=False)
55+
self.root.snake.addObject('UncoupledConstraintCorrection', defaultCompliance=184,
56+
useOdeSolverIntegrationFactors=False)
5157

5258
# Snake.Collision
5359
self.root.snake.addChild('collision')
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Sofa.Component.AnimationLoop
2+
Sofa.Component.Collision.Detection.Algorithm
3+
Sofa.Component.Collision.Detection.Intersection
4+
Sofa.Component.Collision.Geometry
5+
Sofa.Component.Collision.Response.Contact
6+
Sofa.Component.Constraint.Lagrangian.Correction
7+
Sofa.Component.Constraint.Lagrangian.Solver
8+
Sofa.Component.IO.Mesh
9+
Sofa.Component.LinearSolver.Iterative
10+
Sofa.Component.LinearSystem
11+
Sofa.Component.Mapping.Linear
12+
Sofa.Component.Mass
13+
Sofa.Component.ODESolver.Backward
14+
Sofa.Component.SolidMechanics.FEM.Elastic
15+
Sofa.Component.StateContainer
16+
Sofa.Component.Topology.Container.Constant
17+
Sofa.Component.Topology.Container.Grid
18+
Sofa.Component.Visual
19+
Sofa.GL.Component.Rendering3D
20+
Sofa.GL.Component.Shader

examples/SOFA/rendering-offscreen/record.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Sofa
22

3-
from SSD.SOFA import UserAPI
3+
from SSD.SOFA.Rendering import UserAPI
44
from Caduceus import Caduceus
55

66
USE_GUI = True
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from os.path import exists
2+
from os import system
23

3-
from SSD.SOFA import Replay
4+
from SSD.SOFA.Rendering import Replay
45

56

67
# Check Database existence
78
if not exists('caduceus.db'):
8-
raise FileNotFoundError("You must create the Database using `python3 record.py` before to replay it.")
9+
system('python3 record.py')
910

1011
# Launch Visualizer
1112
Replay(database_name='caduceus', fps=50).launch()

examples/SOFA/rendering/Liver.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from numpy import zeros, array
55
import Sofa
66

7-
from SSD.SOFA import UserAPI
7+
from SSD.SOFA.Rendering import UserAPI
88

99

1010
class Liver(Sofa.Core.Controller):
@@ -20,14 +20,12 @@ def __init__(self, root, factory: Optional[UserAPI] = None, *args, **kwargs):
2020

2121
# Root
2222
self.root.dt.value = 0.02
23-
required_plugins = ['Sofa.Component', 'Sofa.GL.Component']
23+
with open('plugins.txt', 'r') as file:
24+
required_plugins = [plugin[:-1] if plugin.endswith('\n') else plugin for plugin in file.readlines()
25+
if plugin != '\n']
2426
self.root.addObject('RequiredPlugin', pluginName=required_plugins)
2527
self.root.addObject('VisualStyle', displayFlags='showVisual')
26-
self.root.addObject('DefaultPipeline', verbose=0)
27-
self.root.addObject('BruteForceBroadPhase')
28-
self.root.addObject('BVHNarrowPhase')
29-
self.root.addObject('DiscreteIntersection')
30-
self.root.addObject('DefaultContactManager')
28+
self.root.addObject('DefaultAnimationLoop')
3129

3230
# Liver.Physics
3331
self.root.addChild('liver')
@@ -37,19 +35,18 @@ def __init__(self, root, factory: Optional[UserAPI] = None, *args, **kwargs):
3735
self.root.liver.addObject('TetrahedronSetTopologyContainer', name='Grid', src='@Liver')
3836
self.root.liver.addObject('TetrahedronSetGeometryAlgorithms', template='Vec3d')
3937
self.root.liver.addObject('MechanicalObject', name='GridMO', src='@Liver')
40-
self.root.liver.addObject('DiagonalMass', massDensity=1.)
38+
self.root.liver.addObject('DiagonalMass', massDensity=0.1)
4139
self.root.liver.addObject('TetrahedralCorotationalFEMForceField', template='Vec3d', method='large',
4240
youngModulus=50000, poissonRatio=0.4, computeGlobalMatrix=False)
43-
self.root.liver.addObject('FixedConstraint', indices=[3, 39, 64])
41+
self.root.liver.addObject('FixedProjectiveConstraint', indices=[3, 39, 64])
4442

4543
# Liver.Surface
4644
self.root.liver.addChild('surface')
4745
self.root.liver.surface.addObject('SphereLoader', name='Spheres', filename='mesh/liver.sph')
4846
self.root.liver.surface.addObject('MechanicalObject', name='SurfaceMO', position='@Spheres.position')
49-
self.root.liver.surface.addObject('SphereCollisionModel', listRadius='@Spheres.listRadius')
5047
self.root.liver.surface.addObject('BarycentricMapping', input='@..', output='@.')
5148
self.cff = self.root.liver.surface.addObject('ConstantForceField', name='CFF', indices=[33],
52-
force=[0., 0., 0.], showArrowSize=5e-4)
49+
forces=[[0., 0., 0.]], showArrowSize=5e-4)
5350

5451
# Liver.Visual
5552
self.root.liver.addChild('visual')
@@ -91,10 +88,9 @@ def onAnimateBeginEvent(self, _):
9188

9289
# Change the force value every 50 time steps
9390
if self.step % 50 == 0:
94-
f = uniform(-1, 1, (3,))
91+
f = uniform(-1, 1, (1, 3))
9592
f = (f / norm(f)) * 5e3
96-
self.cff.force.value = f
97-
93+
self.cff.forces.value = f
9894
self.step += 1
9995

10096
def onAnimateEndEvent(self, _):
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Sofa.Component.Collision.Geometry
2+
Sofa.Component.Constraint.Projective
3+
Sofa.Component.IO.Mesh
4+
Sofa.Component.LinearSolver.Iterative
5+
Sofa.Component.Mapping.Linear
6+
Sofa.Component.Mass
7+
Sofa.Component.MechanicalLoad
8+
Sofa.Component.ODESolver.Backward
9+
Sofa.Component.SolidMechanics.FEM.Elastic
10+
Sofa.Component.StateContainer
11+
Sofa.Component.Topology.Container.Dynamic
12+
Sofa.Component.Visual
13+
Sofa.GL.Component.Rendering3D

examples/SOFA/rendering/record.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Sofa
22

3-
from SSD.SOFA import UserAPI
3+
from SSD.SOFA.Rendering import UserAPI
44
from Liver import Liver
55

66
USE_GUI = True

examples/SOFA/rendering/replay.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from os.path import exists
2+
from os import system
23

3-
from SSD.SOFA import Replay
4+
from SSD.SOFA.Rendering import Replay
45

56

67
# Check Database existence
78
if not exists('liver.db'):
8-
raise FileNotFoundError("You must create the Database using `python3 record.py` before to replay it.")
9+
system('python3 record.py')
910

1011
# Launch Visualizer
1112
Replay(database_name='liver').launch()

examples/SOFA/storage/Caduceus.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from numpy import ndarray
22
import Sofa
33

4-
from SSD.SOFA import Database
4+
from SSD.SOFA.Storage import Database
55

66

77
class Caduceus(Sofa.Core.Controller):
@@ -17,37 +17,43 @@ def __init__(self, root, database=False, *args, **kwargs):
1717
# Root
1818
self.root.gravity.value = [0, -1000, 0]
1919
self.root.dt.value = 0.04
20-
required_plugins = ['Sofa.Component', 'Sofa.GL.Component']
20+
with open('plugins.txt', 'r') as file:
21+
required_plugins = [plugin[:-1] if plugin.endswith('\n') else plugin for plugin in file.readlines()
22+
if plugin != '\n']
2123
self.root.addObject('RequiredPlugin', pluginName=required_plugins)
2224
self.root.addObject('VisualStyle', displayFlags='showVisual')
2325
self.root.addObject('FreeMotionAnimationLoop', parallelCollisionDetectionAndFreeMotion=True)
24-
self.root.addObject('DefaultPipeline', depth=15, verbose=0, draw=0)
26+
self.root.addObject('CollisionPipeline', depth=15, verbose=0, draw=0)
2527
self.root.addObject('BruteForceBroadPhase')
2628
self.root.addObject('BVHNarrowPhase')
2729
self.root.addObject('MinProximityIntersection', alarmDistance=1.5, contactDistance=1)
28-
self.root.addObject('DefaultContactManager', response='FrictionContactConstraint')
30+
self.root.addObject('CollisionResponse', response='FrictionContactConstraint')
2931
self.root.addObject('LCPConstraintSolver', tolerance=1e-3, maxIt=1000, initial_guess=False, build_lcp=False,
3032
printLog=0, mu=0.2)
3133

3234
# Camera
3335
self.root.addObject('InteractiveCamera', position=[0, 30, 90], lookAt=[0, 30, 0])
3436
self.root.addObject('LightManager')
35-
self.root.addObject('SpotLight', position=[0, 80, 25], direction=[0, -1, -0.8], cutoff=30, exponent=1)
36-
self.root.addObject('SpotLight', position=[0, 40, 100], direction=[0, 0, -1], cutoff=30, exponent=1)
37+
self.root.addObject('SpotLight', name='light1', position=[0, 80, 25], direction=[0, -1, -0.8], cutoff=30,
38+
exponent=1)
39+
self.root.addObject('SpotLight', name='light2', position=[0, 40, 100], direction=[0, 0, -1], cutoff=30,
40+
exponent=1)
3741

3842
# Snake.Physics
3943
self.root.addChild('snake')
4044
self.root.snake.addObject('MeshOBJLoader', name='Snake', filename='mesh/snake_body.obj')
4145
self.root.snake.addObject('EulerImplicitSolver', rayleighMass=1, rayleighStiffness=0.03)
46+
self.root.snake.addObject('MatrixLinearSystem', name='LinearSystem', template='CompressedRowSparseMatrixMat3x3')
4247
self.root.snake.addObject('CGLinearSolver', iterations=20, tolerance=1e-12, threshold=1e-18,
43-
template='CompressedRowSparseMatrixMat3x3d')
48+
template='CompressedRowSparseMatrixMat3x3d', linearSystem='@LinearSystem')
4449
self.root.snake.addObject('SparseGridRamificationTopology', name='Grid', src='@Snake', n=[4, 12, 3],
4550
nbVirtualFinerLevels=3, finestConnectivity=0)
4651
self.root.snake.addObject('MechanicalObject', name='GridMO', src='@Grid', scale=1, dy=2)
4752
self.root.snake.addObject('UniformMass', totalMass=1.)
4853
self.root.snake.addObject('HexahedronFEMForceField', youngModulus=30000, poissonRatio=0.3, method='large',
4954
updateStiffnessMatrix=False)
50-
self.root.snake.addObject('UncoupledConstraintCorrection', useOdeSolverIntegrationFactors=False)
55+
self.root.snake.addObject('UncoupledConstraintCorrection', defaultCompliance=184,
56+
useOdeSolverIntegrationFactors=False)
5157

5258
# Snake.Collision
5359
self.root.snake.addChild('collision')

examples/SOFA/storage/plugins.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Sofa.Component.AnimationLoop
2+
Sofa.Component.Collision.Detection.Algorithm
3+
Sofa.Component.Collision.Detection.Intersection
4+
Sofa.Component.Collision.Geometry
5+
Sofa.Component.Collision.Response.Contact
6+
Sofa.Component.Constraint.Lagrangian.Correction
7+
Sofa.Component.Constraint.Lagrangian.Solver
8+
Sofa.Component.IO.Mesh
9+
Sofa.Component.LinearSolver.Iterative
10+
Sofa.Component.LinearSystem
11+
Sofa.Component.Mapping.Linear
12+
Sofa.Component.Mass
13+
Sofa.Component.ODESolver.Backward
14+
Sofa.Component.SolidMechanics.FEM.Elastic
15+
Sofa.Component.StateContainer
16+
Sofa.Component.Topology.Container.Constant
17+
Sofa.Component.Topology.Container.Grid
18+
Sofa.Component.Visual
19+
Sofa.GL.Component.Rendering3D
20+
Sofa.GL.Component.Shader

0 commit comments

Comments
 (0)