Forum Replies Created
-
AuthorPosts
-
EricBlocked
Hi Hugo,
Thanks for your reply and suggestion.
I’ve followed the example of “python controller” as https://github.com/sofa-framework/SofaPython3/blob/master/examples/liver-scriptcontroller.py, but still fail to stream position data when I trigger the event.
My code is attached as below, aiming to print out the position of the first tissue index on pressing “ctrl + “+””
In the createScene(root) function, I create the scene with root and tissue nodetissue = root.addChild('tissue') tissue.addObject('MechanicalObject', name = "tissueDofs", src="@tissueMeshLoader") root.addObject( KeyPressedController(name="tissueController") )
In the trigger function, I define
class KeyPressedController(Sofa.Core.Controller): def __init__(self, *args, **kwargs): Sofa.Core.Controller.__init__(self, *args, **kwargs) self.iteration = 0 def onKeypressEvent(self, event): if event['key']=="+": root_now = self.getContext() tissue_now = root_now.tissue.tissueDofs with tissue_now.position.writeableArray() as wa: print(wa[0])
However, after I start the simulation and press “ctrl + “+””, I only received
[INFO] [SofaViewer] QtViewer::keyPressEvent, CONTROL pressed
but no position data was printed out. Could you help point out what might be the reason?In addition, is there other way to trigger an event than pressing a key? For example, in a tissue cutting simulation in which only when the distance between scalpel and tissue surface is closer enough could a Topology modification event be triggered.
Cheers
EricBlockedHi Hugo,
Thanks for your reply and suggestion.
I’ve followed the example of “python controller” as https://github.com/sofa-framework/SofaPython3/blob/master/examples/liver-scriptcontroller.py, but still fail to stream position data when I trigger the event.
My code is attached as below, aiming to print out the position of the first tissue index on pressing “ctrl + “+””
In the createScene(root) function, I create the scene with root and tissue nodetissue = root.addChild('tissue') tissue.addObject('MechanicalObject', name = tissueDofs, src=@tissueMeshLoader) root.addObject( KeyPressedController(name=tissueController )
In the trigger function, I define
class KeyPressedController(Sofa.Core.Controller): def __init__(self, *args, **kwargs): Sofa.Core.Controller.__init__(self, *args, **kwargs) self.iteration = 0 def onKeypressEvent(self, event): if event['key']== "+": root_now = self.getContext() tissue_now = root_now.tissue.tissueDofs with tissue_now.position.writeableArray() as wa: print(wa[0])
However, after I start the simulation and press “ctrl + “+””, I only received
[INFO] [SofaViewer] QtViewer::keyPressEvent, CONTROL pressed
but no position data was printed out. Could you help point out what might be the reason?In addition, is there other way to trigger an event than pressing a key? For example, in a tissue cutting simulation in which only when the distance between scalpel and tissue surface is closer enough could a Topology modification event be triggered.
Cheers
EricBlockedHi Hugo,
I encountered the error of “Missing attribute getObject” as I was trying to access indices within BoxROI
tissue = root.addChild('tissue') tissue.addObject('EulerImplicitSolver', name = "tissueImplicitSolver", rayleighStiffness = "0.01", printLog = "false") tissue.addObject('CGLinearSolver', name = "tissueCgLinearSolver", iterations = "25", tolerance = "1e-09", threshold="1e-09") tissue.addObject('MeshGmshLoader', name="tissueMeshLoader", filename=tissue_mesh_model) tissue.addObject('TetrahedronSetTopologyContainer', name="tissueMeshTopo", src="@tissueMeshLoader") tissue.addObject('MechanicalObject', name = "tissueDofs", src="@tissueMeshLoader") tissue.addObject('UniformMass', name = "tissueMass", totalMass = "0.001") tissue.addObject('TetrahedronFEMForceField', template = "Vec3d", name = "tissue TetrahedronFEM Forcefield", method="large", poissonRatio="0.35", youngModulus="5000", computeGlobalMatrix="0") tissue.addObject('BoxROI', name = "tissueBoxROI",box = "-999 -999 -999 0.001 0.001 0.001") tissue_fixed_indices = tissue.getObject('tissueBoxROI').findData('indices').value
However, if I define
tissue_box = tissue.addObject('BoxROI', name = "tissueBoxROI",box = "-999 -999 -999 0.001 0.001 0.001")
and after
tissue.init()
I could access object data throughtissue_box.indices
but still cannot viatissue.getObject("tissueBoxROI").findData("indices").value
The version I am running is 21.06.02. Wonder what might be the reason for this error.
Cheers
9 December 2021 at 12:29 in reply to: [SOLVED] VS code SofaRuntime.importPlugin cannot be resolved #21095EricBlockedThanks for your reply and advice. I am now aware that there is no “direct” way of writing up a sofa python script with autocompletion. In this case, I will reevaluate the workload of developing tissue cutting simulation using C++ against python3 given available online references.
Cheers
EricBlockedHi Alexandre,
Thanks for your reply. I just downgraded pybind11 from 2.8.0 to 2.6.2 and selected gcc-9 and g++-9 for compiling. Now the filesystem error is gone and I’ve successfully compiled it.
Cheers
EricBlockedHi Hugo,
Thanks for your reply and your support.
1. For one, I fail to find a well documented SOFA python API page for reference. If any, could you help point it out?
2. I was given a SOFA C++ library for tissue cutting which was written by a previous researcher in 2014. However, the code was written in a pretty hacky and horrendous manner; moreover, most of the classes used in the code are deprecated now. Therefore, I have to manually upgrade them all.I’d appreciate your opinion on the potential efforts to develop a tissue cutting simulation using python compared to C++ given the current available reference resources.
Cheers
-
AuthorPosts