Home › Forum › SOFA › Programming with SOFA › [SOLVED] Continuously Grid Topology
Tagged: 64_bits, Grid Topology, Linux_ubuntu, SOFA_other
- This topic has 8 replies, 3 voices, and was last updated 6 years, 10 months ago by Binesh.
-
AuthorPosts
-
29 October 2017 at 21:07 #10097BineshBlocked
Hi my friends
i wanna to create grid topology in animation (online)
i used regular grid topology and spatial grid container , after initialization (init function) , sofa created some grid topology , but i wanna to create same topology in run timeThanks
Behnam Binesh
30 October 2017 at 12:30 #10098mmabroukBlockedIf you’re scripting using Python, you can use the onBeginAnimationStep(self, dt) function which gets called each simulation step and create the graph objects there.
Best,
Mahmoud30 October 2017 at 14:49 #10100HugoKeymasterExactly @mmabrouk is 100% right, consider Python.
You’ll find examples in the SofaPython plugin, documentation. In the forum, I recently gave an example about Python here.HTH,
Hugo.
1 November 2017 at 15:52 #10102BineshBlocked13 November 2017 at 19:14 #10132HugoKeymasterDear @secretdevil,
I did not forget you, I am just gathering info to answer you and give you an example scene. Cheers
Hugo
15 November 2017 at 13:58 #10137HugoKeymasterDear @secretdevil,
Please find below an example with Python (Python plugin must be compiled) to dynamically create grids.
import sys import Sofa class RegularGridTopology (Sofa.PythonScriptController): def __init__(self, node, commandLineArguments) : self.commandLineArguments = commandLineArguments print "Command line arguments for python : "+str(commandLineArguments) self.createGraph(node) return None; def createGraph(self,rootNode): # rootNode self.rootNode = rootNode rootNode.createObject('VisualStyle', displayFlags='showBehaviorModels showForceFields showVisual') rootNode.createObject('CollisionPipeline', verbose='0') rootNode.createObject('BruteForceDetection', name='N2') rootNode.createObject('CollisionResponse', response='default') rootNode.createObject('DiscreteIntersection') # rootNode/LiverFFD-lowres LiverFFD_lowres = rootNode.createChild('LiverFFD-lowres') self.LiverFFD_lowres = LiverFFD_lowres LiverFFD_lowres.createObject('EulerImplicit', rayleighStiffness='0.1', rayleighMass='0.1') LiverFFD_lowres.createObject('CGLinearSolver', threshold='1e-7', tolerance='1e-7', iterations='100') LiverFFD_lowres.createObject('MechanicalObject') LiverFFD_lowres.createObject('UniformMass', totalmass='100.0') LiverFFD_lowres.createObject('RegularGrid', nx='4', ny='3', nz='3', xmin='-10.25', ymin='0.25', zmin='-2', xmax='-3.25', ymax='5.25', zmax='3') LiverFFD_lowres.createObject('BoxROI', name='myboxROI', box='-9 0 0 -4 0.9 5', drawBoxes='1') # xmin,ymin,zmin, xmax,ymax,zmax LiverFFD_lowres.createObject('FixedConstraint', indices='@myboxROI.indices') LiverFFD_lowres.createObject('RegularGridSpringForceField', name='Springs', stiffness='4000', damping='4') # rootNode/LiverFFD-lowres/Visu Visu = LiverFFD_lowres.createChild('Visu') self.Visu = Visu Visu.createObject('OglModel', color='red', translation='-5 0 0', name='Visual', fileMesh='mesh/liver-smooth.obj') Visu.createObject('BarycentricMapping', input='@..', output='@Visual') #Compute the iterations self.iteration_number=0 return 0; def onMouseButtonLeft(self, mouseX,mouseY,isPressed): ## usage e.g. #if isPressed : # print "Control+Left mouse button pressed at position "+str(mouseX)+", "+str(mouseY) return 0; def onKeyReleased(self, c): ## usage e.g. #if c=="A" : # print "You released a" return 0; def initGraph(self, node): ## Please feel free to add an example for a simple usage in /data/Softwares/sofa/src/master/applications/plugins/SofaPython/scn2python.py return 0; def onKeyPressed(self, c): ## usage e.g. if c=="A" : self.iteration_number=self.iteration_number+1 print "iteration "+str(self.iteration_number) yPositionMin = 0.25+self.iteration_number*7 yPositionMax = yPositionMin+5.25 yPositionROIMin = self.iteration_number*7 yPositionROIMax = yPositionROIMin+0.9 myGrid = self.rootNode.createChild('newGrid-'+str(self.iteration_number)) newODE = myGrid.createObject('EulerImplicit', rayleighStiffness='0.1', rayleighMass='0.1') newLSolver = myGrid.createObject('CGLinearSolver', threshold='1e-7', tolerance='1e-7', iterations='100') newMO = myGrid.createObject('MechanicalObject', showObject='1') newMass = myGrid.createObject('UniformMass', totalmass='100.0') myRegularGrid = myGrid.createObject('RegularGrid', name='myRegularGrid', nx='4', ny='3', nz='3', xmax='-3.25', xmin='-10.25', ymin=yPositionMin, ymax=yPositionMax, zmin='-2', zmax='3') newBox = myGrid.createObject('BoxROI', name='myboxROI', box='-9 '+str(yPositionROIMin)+' 0 -4 '+str(yPositionROIMax)+' 5', drawBoxes='1') newConstraint = myGrid.createObject('FixedConstraint', indices='@myboxROI.indices') newFF = myGrid.createObject('RegularGridSpringForceField', name='Springs', stiffness='4000', damping='4', drawMode="1") newODE.init() newLSolver.init() newMO.init() newMass.init() myRegularGrid.init() newBox.init() newConstraint.init() newFF.init() # rootNode/LiverFFD-lowres/Visu Visu = myGrid.createChild('Visu') self.Visu = Visu newOGL = Visu.createObject('OglModel', color='red', translation='-5 '+str(yPositionROIMin)+' 0', name='Visual', fileMesh='mesh/liver-smooth.obj') newMapping = Visu.createObject('BarycentricMapping', input='@..', output='@Visual') newOGL.init() newMapping.init() return 0; def createScene(rootNode): rootNode.findData('dt').value = '0.01' rootNode.createObject('RequiredPlugin', name='SofaPython') try : sys.argv[0] except : commandLineArguments = [] else : commandLineArguments = sys.argv myRegularGridTopology = RegularGridTopology(rootNode,commandLineArguments) return 0;
You can run this script using runSofa :
runSofa your_script.py
Let me know if it helps
Hugo
20 November 2017 at 18:02 #10163BineshBlockedThanks Dear Hugo
i try it as soon as possible8 January 2018 at 17:58 #10274HugoKeymaster21 February 2018 at 07:33 #10555 -
AuthorPosts
- You must be logged in to reply to this topic.