Home › Forum › SOFA › Programming with SOFA › [SOLVED] Modify fields of a node components (such as translation/rotation) from C++ API.
Tagged: 64_bits, Linux_other, SOFA_1608
- This topic has 5 replies, 2 voices, and was last updated 8 years ago by Hugo.
-
AuthorPosts
-
18 November 2016 at 16:00 #7787ArcadiaBlurBlocked
Hello,
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,
sofa::simulation::Simulation simnode;
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,
Cordially,
Albert.24 November 2016 at 00:19 #7954HugoKeymasterCiao Albert,
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.Hugo
24 November 2016 at 11:40 #7972ArcadiaBlurBlockedHello Hugo,
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:59 #8002HugoKeymasterDear Albert,
What do you mean exactly by “I cannot access the OglModel directly” ?
OglModel hierarchy is :
sofa::component::visualmodel::OglModel< ExtVec3f > ...
Best,
Hugo
1 December 2016 at 11:20 #8035ArcadiaBlurBlockedHello,
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.
Best,
Albert.2 December 2016 at 08:56 #8038HugoKeymasterOk I close this topic then.
Cheers,Hugo
-
AuthorPosts
- You must be logged in to reply to this topic.