One of the greatest things about MITK Simulation is, that it is transparent to 
SOFA, which means, that it kind of *is* SOFA, with additional functionality on 
top. There's (nearly) nothing special you need to know and if it doesn't work 
in MITK SImulation, that usually means that it doesn't work in plane SOFA 
either. From another view: You don't have to care about MITK's reinit stuff or 
anything like that when writing your simulations.*


The SOFA guys used (and are using) C++ for many years, until they switched to 
Python rather recently as it seems. So they have lots of experience even with 
the C++-API. Trust them. :-) Did you try the suggestion of Hugo? Of course you 
need to update the SOFA scene after your modifications, which is an intrinsic 
requirement of any simulation software. But beware, other than for 
initialization before the very first simulation step, it's not a good idea to 
manually transform any simulated object in the scene. This way you completely 
bypass the simulation and you may introduce infinite forces to your scene as it 
appears to the simulation that you moved the object infinitely fast. If you 
want to know how to update your simulation in C++, just have a look at the code 
behind the step button of the simulation plugin.


* There's this one exception: To get SOFA visuals working and behaving nicely 
in the context of VTK, we had to use SOFA's factory mechanism to inject our own 
VisualModel/OglModel replacement class instead of the standard SOFA ones (see 
[1]). They are kind of identical, but it might be necessary to know the 
difference when it comes to casting of course. In contrast to Hugo's 
suggestion, you want to cast to VtkModel instead of VisualModel/OglModel. So 
remember, every VisualModel/OglModel in your scene will be instantiated in MITK 
Simulation as a VtkModel instead. All of these classes derive from 
VisualModelImpl so if this superclass provides everything you need, you can 
also just cast to VisualModelImpl to stay super compatible with standalone 
SOFA. If I remember correctly, you can also check the type of objects in your 
scene in the scene graph of the MITK Simulation plugin.


BTW there's also a great hidden feature in the scene graph of the MITK 
Simulation plugin. You can right-click a "visual model" to open a context menu, 
which allows you to indirectly render into a mitk::Surface instead (it even 
shows up in the Data Manager). This way you have a great bridge between a MITK 
scene and the contained SOFA scene.


[1] 
https://github.com/MITK/MITK/blob/v2016.03.0/Modules/Simulation/mitkSimulationObjectFactory.cpp#L51-L52


________________________________
Von: Albert Alises <ironicpsy...@gmail.com>
Gesendet: Donnerstag, 24. November 2016 11:56
An: Kislinskiy, Stefan
Cc: mitk-users@lists.sourceforge.net
Betreff: Re: [mitk-users] [SOFA] Modify fields of a node component (such as 
translation/rotation) from C++ API.

Hello Stefan,

I already asked on the SOFA Forum

https://www.sofa-framework.org/community/forum/topic/modify-fields-of-a-node-components-such-as-translationrotation-from-c-api/#post-7972

However, I am still stuck with the question, as seemingly the C++ API of SOFA 
is not used a lot, and also I do not know how the integration with MITK works 
(e.g do i have to reinit the scene node for any modification to happen?). I 
believe it is a problem with the references or casting, but I get quite lost on 
the API of SOFA with C++....

Best Regards,
Albert.


2016-11-24 8:26 GMT+01:00 Kislinskiy, Stefan 
<s.kislins...@dkfz-heidelberg.de<mailto:s.kislins...@dkfz-heidelberg.de>>:
Hi Albert,


for questions related to pure SOFA, I highly recommend to ask in the official 
SOFA forum instead:

https://www.sofa-framework.org/community/forum/section/user-forum/developing-in-sofa/


Best,
Stefan?


________________________________
Von: Albert Alises <ironicpsy...@gmail.com<mailto:ironicpsy...@gmail.com>>
Gesendet: Mittwoch, 23. November 2016 10:56
An: mitk-users@lists.sourceforge.net<mailto:mitk-users@lists.sourceforge.net>
Betreff: [mitk-users] [SOFA] Modify fields of a node component (such as 
translation/rotation) from C++ API.


Hello,

I have a problem related to the way we access the scene and nodes information 
via the C++ API of SOFA (from MITK). 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 get to the point where I get the SOFASimulation object from the 
mitk::Simulation one.


SOFASimulation = simulation->GetSOFASimulation();


Then I get a child node and try to get the mesh object and cast it to a 
VisualModel which has an applyTranslation method. However this does not seem to 
work, what I want to do is setup the scene moving the mesh (not on simulation 
runtime)

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::VisualObject*>(object);

visualModel->applyTranslation(100,0,100);


Is it a casting problem, reference ... I do not know how to modify the initial 
placement of the objects of the scene, and the SOFA C++ API does not provide 
any examples that I have seen.


Thank You,

Albert.



Thank you very much,
Cordially,
Albert.


------------------------------------------------------------------------------
_______________________________________________
mitk-users mailing list
mitk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to