18 November 2016 at 16 h 00 min #7787
The problem I have is related to the way we access the scene and nodes information via the C++ API of SOFA. I have a simulation node,
Based on that object, I want to access a specific node component of this simulation, that is an OglModel (a mesh loaded from an stl). What I want to do is modify the translation and rotation properties of this node. That can be done on the xml file defining the scene as:
<OglModel template=”ExtVec3f” name=”oglModel6″ translation=”100 0 100″ ..
However, as I am using MITK integrated with sofa, I need a way to access and modify the scene using the C++ API, not the xml. Is there a way I can get the OglModel object and add/modify fields to it from the sofa::simulation::Simulation class? (I have seen that you can get the root node, and from there you can get a children node, but from there I cannot seem to find how to modify the properties of the nodes such as the transformations)
Thank you very much,
Albert.24 November 2016 at 0 h 19 min #7954
We are not that much writing scene in Cpp now, we all rather use Python.
But, to answer your question, we you have your simulation:
sofa::simulation::Node::SPtr childNode = rootNode->getChild("name_of_the_child_node")
OglModel< ExtVec3f >* my_OglModel = childNode->get< OglModel < ExtVec3f > >(); my_OglModel->translation.setValue(set_here_a_Vec3_translation);
I am writing from memory, so take is as a hint,
my two cents.
Hugo24 November 2016 at 11 h 40 min #7972
Thank you very much for your answer!. I have tried something very similar to your code but I haven’t had success so far. The problem is that I cannot access the OglModel directly (does not find the sofa::component). What I do is then create a BaseObject using the getObject method of the node. Then I get the visual model by casting and apply a translation (Visual Model has a method for that).
However, nothing changes in the simulation when doing that. Maybe it is a reference problem or casting issues. Please find the code attached here:
sofa::simulation::Node::SPtr ImplantNode = SOFASimulation->GetRoot()->getChild("Implant"); sofa::core::objectmodel::BaseObject *object = ImplantNode->getObject("oglModel6"); sofa::core::visual::VisualModel* visualModel = dynamic_cast<sofa::core::visual::VisualModel*>(object); visualModel->applyTranslation(100, 0, 100);28 November 2016 at 22 h 59 min #8002
What do you mean exactly by “I cannot access the OglModel directly” ?
OglModel hierarchy is :
sofa::component::visualmodel::OglModel< ExtVec3f > ...
Hugo1 December 2016 at 11 h 20 min #8035
Thank you very much for your answer. The problem is that maybe I have to access the MechanicalObject rather than the mesh itself. However, I tackled the problem differently by changing the parameters via parsing the scene file. Not that clean and elegant but it works wonders.
Now I’m having issues by finding the translation (I want to align the mesh in a given direction). Will open another thread commenting the issue should it interest other users.
Albert.2 December 2016 at 8 h 56 min #8038
Ok I close this topic then.
- You must be logged in to reply to this topic.