Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Scenes] Update and rename liver-related original scenes that have been used in the documentation #120

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions examples/organs/liver/liverFine_gravity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import Sofa
import Sofa.Core
import os

meshPath = os.path.dirname(os.path.abspath(__file__))+'/mesh/'

plugins=["SofaPython3","SoftRobots","ModelOrderReduction","STLIB",

"Sofa.Component.Visual",
"Sofa.Component.AnimationLoop",
"Sofa.GL.Component.Rendering3D",
"Sofa.Component.Constraint.Lagrangian.Solver",
'Sofa.Component.IO.Mesh',
'Sofa.Component.Playback',
'Sofa.Component.Constraint.Lagrangian.Correction', # Needed to use components [GenericConstraintCorrection]
'Sofa.Component.Engine.Select', # Needed to use components [BoxROI]
'Sofa.Component.LinearSolver.Direct', # Needed to use components [SparseLDLSolver]
'Sofa.Component.Mapping.Linear', # Needed to use components [BarycentricMapping]
'Sofa.Component.Mass', # Needed to use components [UniformMass]
'Sofa.Component.ODESolver.Backward', # Needed to use components [EulerImplicitSolver]
'Sofa.Component.SolidMechanics.FEM.Elastic', # Needed to use components [TetrahedronFEMForceField]
'Sofa.Component.SolidMechanics.Spring', # Needed to use components [RestShapeSpringsForceField]
'Sofa.Component.StateContainer', # Needed to use components [MechanicalObject]
'Sofa.Component.Topology.Container.Dynamic', # Needed to use components [TetrahedronSetTopologyContainer]
'Sofa.Component.Constraint.Projective', # Needed to use components [FixedProjectiveConstraint]
'Sofa.Component.Topology.Container.Grid'] # Needed to use components [RegularGridTopology]


def createScene(rootNode):

rootNode.addObject('RequiredPlugin', pluginName=plugins, printLog=False)
rootNode.addObject('VisualStyle', displayFlags='showCollision showVisualModels showForceFields showInteractionForceFields hideCollisionModels hideBoundingCollisionModels hideWireframe')
rootNode.findData('dt').value=0.01
rootNode.findData('gravity').value=[0, -981, 0]
surfaceColor=[0.7, 0.7, 0.7, 0.7]

liver = rootNode.addChild('liver')
liver.addObject('EulerImplicitSolver', rayleighStiffness = 0.0, rayleighMass = 0.0)
liver.addObject('SparseLDLSolver',template="CompressedRowSparseMatrixMat3x3d")
liver.addObject('MeshVTKLoader', name="loader", filename=meshPath+'liverFine.vtu')
liver.addObject('TetrahedronSetTopologyContainer', src="@loader")
liver.addObject('MechanicalObject', name="MO")
liver.addObject('BoxROI', name='ROI1', box='0 3 -1 2 5 2', drawBoxes='true')
liver.addObject('BoxROI', name='boxROIactuation', box='-5 0 -0.5 -4 0.5 0.5', drawBoxes='true')

liver.addObject('UniformMass', totalMass=0.3)
liver.addObject('TetrahedronFEMForceField', poissonRatio="0.3", youngModulus="5000")
liver.addObject('RestShapeSpringsForceField', points='@ROI1.indices', stiffness = '1e8')

# Add a visual model
visu = liver.addChild('visu')
visu.addObject( 'MeshOBJLoader', name= 'loader', filename=meshPath+'liver-smoothUV.obj')
visu.addObject('OglModel',src='@loader', color=list(surfaceColor))
visu.addObject('BarycentricMapping')

# Add an actuator node compatible with "doNothing" animation function.
actuator = rootNode.addChild('actuator')
actuator.addObject('MechanicalObject', name = 'actuatorState', position = '@liver/MO.position', template = 'Vec3d')
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,35 @@

meshPath = os.path.dirname(os.path.abspath(__file__))+'/mesh/'

plugins=["SofaPython3","SoftRobots","ModelOrderReduction","STLIB",

"Sofa.Component.Visual",
"Sofa.Component.AnimationLoop",
"Sofa.GL.Component.Rendering3D",
"Sofa.Component.Constraint.Lagrangian.Solver",
'Sofa.Component.IO.Mesh',
'Sofa.Component.Playback',
'Sofa.Component.Constraint.Lagrangian.Correction', # Needed to use components [GenericConstraintCorrection]
'Sofa.Component.Engine.Select', # Needed to use components [BoxROI]
'Sofa.Component.LinearSolver.Direct', # Needed to use components [SparseLDLSolver]
'Sofa.Component.Mapping.Linear', # Needed to use components [BarycentricMapping]
'Sofa.Component.Mass', # Needed to use components [UniformMass]
'Sofa.Component.ODESolver.Backward', # Needed to use components [EulerImplicitSolver]
'Sofa.Component.SolidMechanics.FEM.Elastic', # Needed to use components [TetrahedronFEMForceField]
'Sofa.Component.SolidMechanics.Spring', # Needed to use components [RestShapeSpringsForceField]
'Sofa.Component.StateContainer', # Needed to use components [MechanicalObject]
'Sofa.Component.Topology.Container.Dynamic', # Needed to use components [TetrahedronSetTopologyContainer]
'Sofa.Component.Constraint.Projective', # Needed to use components [FixedProjectiveConstraint]
'Sofa.Component.Topology.Container.Grid'] # Needed to use components [RegularGridTopology]


def createScene(rootNode):

rootNode.addObject('RequiredPlugin', name='ModelOrderReduction', pluginName='ModelOrderReduction')
rootNode.addObject('RequiredPlugin', name='SofaPython3', pluginName='SofaPython3')
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Engine.Select') # Needed to use components [BoxROI]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.IO.Mesh') # Needed to use components [MeshOBJLoader,MeshVTKLoader]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.LinearSolver.Direct') # Needed to use components [SparseLDLSolver]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Mapping.Linear') # Needed to use components [BarycentricMapping]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Mass') # Needed to use components [UniformMass]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.ODESolver.Backward') # Needed to use components [EulerImplicitSolver]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.SolidMechanics.FEM.Elastic') # Needed to use components [TetrahedronFEMForceField]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.SolidMechanics.Spring') # Needed to use components [RestShapeSpringsForceField]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.StateContainer') # Needed to use components [MechanicalObject]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Topology.Container.Dynamic') # Needed to use components [TetrahedronSetTopologyContainer]
rootNode.addObject('RequiredPlugin', name='Sofa.Component.Visual') # Needed to use components [VisualStyle]
rootNode.addObject('RequiredPlugin', name='Sofa.GL.Component.Rendering3D') # Needed to use components [OglModel]


rootNode.addObject('RequiredPlugin', pluginName=plugins, printLog=False)
rootNode.addObject('VisualStyle', displayFlags='showCollision showVisualModels showForceFields showInteractionForceFields hideCollisionModels hideBoundingCollisionModels hideWireframe')
rootNode.findData('dt').value=0.01
rootNode.findData('gravity').value=[0, -981, 0]
surfaceColor=[0.7, 0.7, 0.7, 0.7]

rootNode.addObject('DefaultAnimationLoop')

Expand All @@ -44,10 +52,10 @@ def createScene(rootNode):

visu = liver.addChild('visu')
visu.addObject( 'MeshOBJLoader', name= 'loader', filename=meshPath+'liver-smoothUV.obj')
visu.addObject('OglModel',src='@loader')
visu.addObject('OglModel',src='@loader', color=list(surfaceColor))
visu.addObject('BarycentricMapping')



# Add an actuator node compatible with "shakingLiver" animation function.
actuator = rootNode.addChild('actuator')
actuator.addObject('MechanicalObject', name = 'actuatorState', position = '@../liver/boxROIactuation.pointsInROI', template = 'Vec3d')
Loading