-
Notifications
You must be signed in to change notification settings - Fork 341
[SofaCarving] Add an example written in python #3457
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fb9a90b
Add example scene in python
epernod 2311cf7
Apply suggestions from code review
epernod bb9fde7
Update SimpleCarving.py
epernod d42c159
Update SimpleCarving.py
epernod 9930df7
Merge branch 'sofa-framework:master' into inf_carv_python
epernod 83a4dbc
Update SimpleCarving.py
epernod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
applications/plugins/SofaCarving/examples/SimpleCarving.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import Sofa | ||
|
|
||
|
|
||
| #Choose in your script to activate or not the GUI | ||
| USE_GUI = True | ||
|
|
||
|
|
||
| def main(): | ||
| import SofaRuntime | ||
| import Sofa.Gui | ||
|
|
||
| root = Sofa.Core.Node("root") | ||
| createScene(root) | ||
| Sofa.Simulation.init(root) | ||
|
|
||
| if not USE_GUI: | ||
| for iteration in range(10): | ||
| Sofa.Simulation.animate(root, root.dt.value) | ||
| else: | ||
| Sofa.Gui.GUIManager.Init("myscene", "qglviewer") | ||
| Sofa.Gui.GUIManager.createGUI(root, __file__) | ||
| Sofa.Gui.GUIManager.SetDimension(1080, 1080) | ||
| Sofa.Gui.GUIManager.MainLoop(root) | ||
| Sofa.Gui.GUIManager.closeGUI() | ||
|
|
||
| def createScene(root): | ||
|
|
||
| root.gravity=[0, 0, 0] | ||
| root.dt=0.05 | ||
| root.showBoundingTree = 0 | ||
| root.addObject('RequiredPlugin', name="plug1", pluginName="Sofa.Component.Collision.Detection.Algorithm Sofa.Component.Collision.Detection.Intersection Sofa.Component.Collision.Geometry Sofa.Component.Collision.Response.Contact") | ||
| root.addObject('RequiredPlugin', name="plug2", pluginName="Sofa.Component.Constraint.Projective Sofa.Component.LinearSolver.Iterative Sofa.Component.ODESolver.Backward") | ||
| root.addObject('RequiredPlugin', name="plug3", pluginName="Sofa.Component.Engine.Select Sofa.Component.IO.Mesh Sofa.Component.Mass ") | ||
| root.addObject('RequiredPlugin', name="plug4", pluginName="Sofa.Component.Mapping.Linear Sofa.Component.Mapping.NonLinear Sofa.Component.SolidMechanics.FEM.Elastic Sofa.Component.StateContainer") | ||
| root.addObject('RequiredPlugin', name="plug5", pluginName="Sofa.Component.Topology.Container.Dynamic Sofa.Component.Topology.Mapping") | ||
| root.addObject('RequiredPlugin', name="plug6", pluginName="Sofa.Component.Visual Sofa.GL.Component.Rendering3D") | ||
| root.addObject('RequiredPlugin', name="plug7", pluginName="Sofa.Component.Collision.Detection.Algorithm SofaCarving") | ||
|
|
||
| root.addObject('VisualStyle',displayFlags="") | ||
| root.addObject('DefaultAnimationLoop') | ||
| root.addObject('DefaultPipeline',verbose="0") | ||
| root.addObject('BruteForceBroadPhase') | ||
| root.addObject('BVHNarrowPhase') | ||
| root.addObject('DefaultContactManager',response="PenalityContactForceField") | ||
| root.addObject('MinProximityIntersection',name="Proximity",alarmDistance="0.08",contactDistance="0.05",useSurfaceNormals="false") | ||
| root.addObject('CarvingManager',active="true",carvingDistance="-0.01") | ||
|
|
||
|
|
||
|
|
||
| TT = root.addChild('TT') | ||
|
|
||
| TT.addObject('EulerImplicitSolver',name="cg_odesolver",printLog="false",rayleighStiffness="0.1",rayleighMass="0.1") | ||
epernod marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| TT.addObject('CGLinearSolver',iterations="25",name="linear solver",tolerance="1.0e-9",threshold="1.0e-9") | ||
| TT.addObject('MeshGmshLoader',filename="mesh/liver.msh",name="loader",scale="1") | ||
|
|
||
| TT.addObject('MechanicalObject',template="Vec3d",src="@loader",name="Volume") | ||
|
|
||
| TT.addObject('TetrahedronSetTopologyContainer', name="topo", src="@loader") | ||
epernod marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| TT.addObject('TetrahedronSetTopologyModifier', name="topoMod") | ||
| TT.addObject('TetrahedronSetGeometryAlgorithms', template="Vec3d", name="GeomAlgo") | ||
|
|
||
| TT.addObject('DiagonalMass',massDensity="0.5") | ||
| TT.addObject('FixedConstraint',indices="1 3 50") | ||
| TT.addObject('TetrahedralCorotationalFEMForceField',name="CFEM",youngModulus="160",poissonRatio="0.3",method="large") | ||
|
|
||
| T=TT.addChild('T') | ||
| T.addObject('TriangleSetTopologyContainer', name="Container") | ||
| T.addObject('TriangleSetTopologyModifier', name="Modifier") | ||
| T.addObject('TriangleSetGeometryAlgorithms',name="GeomAlgo",template="Vec3d") | ||
| T.addObject('Tetra2TriangleTopologicalMapping', input="@../topo", output="@Container") | ||
|
|
||
| T.addObject('TriangleCollisionModel', tags="CarvingSurface") | ||
|
|
||
| Visu = T.addChild('Visu') | ||
| Visu.addObject('OglModel',name="Visual",material="Default Diffuse 1 0 1 0 1 Ambient 0 1 1 1 1 Specular 1 1 1 0 1 Emissive 0 1 1 0 1 Shininess 1 100") | ||
| Visu.addObject('IdentityMapping',input="@Volume",output="@Visual") | ||
|
|
||
|
|
||
| Instrument = root.addChild('Instrument') | ||
| Instrument.addObject('EulerImplicitSolver',name="cg_odesolver",printLog="false") | ||
| Instrument.addObject('CGLinearSolver',iterations="25",name="linear solver",tolerance="1.0e-9",threshold="1.0e-9") | ||
| Instrument.addObject('MechanicalObject',template="Rigid3d",name="instrumentState",tags="Omni",rotation="90 45 0",translation="0 0 1") | ||
| Instrument.addObject('UniformMass',template="Rigid3d",name="mass",totalMass="5") | ||
| visuIns = Instrument.addChild('visuIns') | ||
| visuIns.addObject('MeshOBJLoader',name="meshLoader_0",filename="mesh/dental_instrument_light.obj",scale3d="1 1 1",translation="-0.412256 -0.067639 3.35",rotation="180 0 150",handleSeams="1") | ||
| visuIns.addObject('OglModel',template="Vec3d",name="InstrumentVisualModel",src="@meshLoader_0",material="Default Diffuse 1 1 0.2 0.2 1 Ambient 1 0.2 0.04 0.04 1 Specular 0 1 0.2 0.2 1 Emissive 0 1 0.2 0.2 1 Shininess 0 45") | ||
| visuIns.addObject('RigidMapping',template="Rigid3d,Vec3d",name="MM->VM mapping",input="@instrumentState",output="@InstrumentVisualModel") | ||
|
|
||
| colIns = Instrument.addChild('colIns') | ||
| colIns.addObject('MechanicalObject',template="Vec3d",name="Particle",position="-0.2 -0.2 -0.2") | ||
| colIns.addObject('SphereCollisionModel',name="ParticleModel",radius="0.2",tags="CarvingTool") | ||
| #colIns.addObject('SphereCollisionModel',name="ParticleModel",radius="0.2") | ||
| colIns.addObject('RigidMapping',template="Rigid3d,Vec3d",name="MM->CM mapping",input="@instrumentState",output="@Particle") | ||
|
|
||
| return root | ||
|
|
||
|
|
||
| #Function used only if this script is called from a python environment | ||
| if __name__ == '__main__': | ||
| main() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of a global variable, please do something like if __name__ == '__main__':
with_gui = False
if len(sys.args) == 2:
with_gui = sys.args[1] == "with-gui"
main(with_gui)Would be even better to use argparser https://docs.python.org/3/library/argparse.html instead of manually processing the args. |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.