Home › Forum › SOFA › Using SOFA › [SOLVED] indices of ROI in python scene
Tagged: +
- This topic has 7 replies, 4 voices, and was last updated 3 years, 5 months ago by chiarasapo.
-
AuthorPosts
-
7 April 2020 at 08:33 #15657SimonMember
Hi,
in my .pyscn I want to get the list of indices found in my ROI. In the sofa gui everything works perfectly fine. Doubleclicking on my boxROI, I can see the ROI is working and the found points/indices are listed. Also the following
FixedConstraint
with@box_roi_fix.indices
is working fine.But I want to get the list of indices by using
findData('indices').value
to further work on those indices in my python code. printing stuff out shows me I don’t get the indices.
What am I doing wrong?findData('name').value
works? Accessing viabox.indices
is giving me the same problemdef createScene(rootNode): rootNode.createObject('VisualStyle', displayFlags = "showBehavior") print dir(rootNode.VisualStyle.displayFlags) rootNode.createObject('MechanicalObject', name="dofs", position="0 0 0 0 0 1 0 10 10 10 10 10", showObject="true", showObjectScale="5") box = rootNode.createObject('BoxROI',template="Vec3d", name='box_roi_fix',box=[-1, -16, -11, 1, 16, 11], drawBoxes='True', drawSize="1") # print type(rootNode.getObject('box_roi_fix').findData('indices')) # print dir(rootNode.getObject('box_roi_fix').findData('indices')) print (rootNode.getObject('box_roi_fix').findData('name').value) print (rootNode.getObject('box_roi_fix').findData('indices').value) print (rootNode.getObject('box_roi_fix').findData('nbIndices').value) print box.name print box.indices rootNode.createObject('FixedConstraint', template="Vec3d" ,name="testROIindices", indices="@box_roi_fix.indices", showObject="True", drawSize="0.3") return rootNode
Thanks in advance
Simon7 April 2020 at 08:40 #15659HugoKeymasterHi @simon
This is due to the fact you are calling the data before it is actually initialized.
The createScene() function is called before initialization to define what components are inside the graph. Then, initialization occurs and the simulation can be run.
If you call the same
findData('indices').value
orbox.indices
in the function onBeginAnimationStep() it will work fine.Best wishes,
Hugo
7 April 2020 at 08:52 #15660SimonMemberThanks @Hugo,
I understand. But if I need the the list of indices in the creation of my scene how can I do this?
Is there something possible like:
– createScene() (until I need initialization)
– initialize()
– continue with createScene() ?7 April 2020 at 09:04 #15661SimonMemberI could think off 2 .pyscn files:
1st .pyscn
-create part of my scne with the roi
-initialize it
-animate for on time step
-get my indices, save them somehow2nd .pyscn
-import indices somehow
-continue/finish my createscene processOr is there already some more clever approach to this?
7 April 2020 at 09:05 #15662HugoKeymasterHi @simon
Do it in the bwdInitGraph() Python function within the same file.
FYI all Python functions are displayed in the applications/plugins/SofaPython/examples/EmptyController.py exampleBest wishes,
Hugo
7 April 2020 at 09:20 #156635 May 2021 at 12:32 #19359AryaBlockedHey @hugo, I am having an issue with using boxROI indices in the Rigidify function of STLIB/physics/mixedmaterial. I am trying to rigidify a certain part of my deformable body using this rigidify function and I am using boxROI to insert indices into groupIndices of the rigidify function. Although I am not able to extract indices values from boxROI, I am doing this in python and have tried to get indices using the following forms and all of them give seperate errors :
groupIndices = [“@boxROI.indices”]
groupIndices = [eobject.getObject(‘boxROI’).findData(‘indices’).value]
groupIndices = [“@”+BoxROI2.getPathName()+’.indices’]
groupIndices = [np.array(eobject.getObject(‘boxROI’).findData(‘indices’).value)]I tried to print the values of the indices in the onBeginAnimationStep() but I don’t get any output and when I print them in my deformable body class, I get an output of : [[0]]
Also on using the rigidify function with the groupIndices as the above I get errors like :
“TypeError: ‘in <string>’ requires string as left operand, not int
File “rigidifywakrabot.pyscn”, line 92, in createScene
Wakraedge(rootNode, translation=[1.0, 0.0, 0.0])
File “rigidifywakrabot.pyscn”, line 73, in Wakraedge
Rigidify(wakraedge, eobject, groupIndices = [“@”+BoxROI2.getPathName()+’.indices’], frames=None, name=”rigidbody”, frameOrientation=None)
File “/home/aryak/Downloads/SOFA_v19.06.99_custom_Linux_v5.1/plugins/STLIB/python/stlib/physics/mixedmaterial/rigidification.py”, line 86, in Rigidify
selectedPoints = mfilter(groupIndices[i], allIndices, sourcePoints)
File “/home/aryak/Downloads/SOFA_v19.06.99_custom_Linux_v5.1/plugins/STLIB/python/stlib/physics/mixedmaterial/rigidification.py”, line 78, in mfilter
if i in si:
” ;“TypeError: unhashable type: ‘list’
File “rigidifywakrabot.pyscn”, line 91, in createScene
Wakraedge(rootNode, translation=[1.0, 0.0, 0.0])
File “rigidifywakrabot.pyscn”, line 73, in Wakraedge
Rigidify(wakraedge, eobject, groupIndices = [eobject.getObject(‘boxROI2’).findData(‘indices’).value], frames=None, name=”rigidbody”, frameOrientation=None)
File “/home/aryak/Downloads/SOFA_v19.06.99_custom_Linux_v5.1/plugins/STLIB/python/stlib/physics/mixedmaterial/rigidification.py”, line 111, in Rigidify
Kd.update({v: [1, k] for k, v in enumerate(selectedIndices)})
File “/home/aryak/Downloads/SOFA_v19.06.99_custom_Linux_v5.1/plugins/STLIB/python/stlib/physics/mixedmaterial/rigidification.py”, line 111, in <dictcomp>
Kd.update({v: [1, k] for k, v in enumerate(selectedIndices)})
“;“TypeError: unhashable type: ‘numpy.ndarray’
File “rigidifywakrabot.pyscn”, line 92, in createScene
Wakraedge(rootNode, translation=[1.0, 0.0, 0.0])
File “rigidifywakrabot.pyscn”, line 74, in Wakraedge
Rigidify(wakraedge, eobject, groupIndices = np.array([np.array(eobject.getObject(‘boxROI2’).findData(‘indices’).value)]), frames=None, name=”rigidbody”, frameOrientation=None)
File “/home/aryak/Downloads/SOFA_v19.06.99_custom_Linux_v5.1/plugins/STLIB/python/stlib/physics/mixedmaterial/rigidification.py”, line 111, in Rigidify
Kd.update({v: [1, k] for k, v in enumerate(selectedIndices)})
File “/home/aryak/Downloads/SOFA_v19.06.99_custom_Linux_v5.1/plugins/STLIB/python/stlib/physics/mixedmaterial/rigidification.py”, line 111, in <dictcomp>
Kd.update({v: [1, k] for k, v in enumerate(selectedIndices)})
“17 June 2021 at 16:48 #19745chiarasapoBlockedHi @aryakarani, I have the same problem: I obtain an empty array when trying to retrieve the boxROI indices from the onBeginAnimationStep function. Did you find a solution? If so, I’d be glad to hear it! Thank you in advance,
Chiara -
AuthorPosts
- You must be logged in to reply to this topic.