Hello Stefan, Thank you very much for your answer!. The problem I have is not a null pointer, as the cast seems to work, but the translation is just not applied, nothing changes. Right now I have implemented the animate and called the rendering update
simulation->Animate(); this->RequestRenderWindowUpdate(mitk::RenderingManager::REQUEST_UPDATE_ALL); And changed the casting to be to a visualmodelImpl (and translation) sofa::component::visualmodel::VisualModelImpl* visualModel = dynamic_cast<sofa::component::visualmodel::VisualModelImpl*>(object); visualModel->applyTranslation(100, 0, 100); However, when pressing the button, it acts as a step button, just updating a delta in the direction of the force and not applying the translation. In my scene I have a MechanicalObject attached to the VtkModel and a RigidMapping, maybe I have to modify those? I don't think so, just modifying the translation of the model should do it.... Sorry for all the trouble but I am just so confused about it. Cheers, Albert 2016-11-24 13:22 GMT+01:00 Kislinskiy, Stefan < s.kislins...@dkfz-heidelberg.de>: > An addition to my mail below: You didn't specify your actual problem. Is > the cast failing with a null pointer or does it work, but you would expect > to see seomthing different on the screen? > > Also, most of the time you do not have a standalone visual model in your > scene but a simulated object with an attached visual model to get a visual > representation of the simulated object. In this case, you want to modify > the simulated object itself. Doing otherwise would result in strange > effects like you would see your simulated object at another position as it > is actually located at. For example, adding an x-translation of 10 to an > visual model of a simulated object at x-pos 100, would show your object +10 > off. When the simulation is running, the offset persists and while the > simulation object interacts with your scene at position A, it would be > rendered at position (Ax+10, Ay, Az). > ________________________________________ > Von: Kislinskiy, Stefan <s.kislins...@dkfz-heidelberg.de> > Gesendet: Donnerstag, 24. November 2016 12:57 > An: Albert Alises > Cc: mitk-users@lists.sourceforge.net > Betreff: Re: [mitk-users] [SOFA] Modify fields of a node component (such > as translation/rotation) from C++ API. > > 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 >
------------------------------------------------------------------------------
_______________________________________________ mitk-users mailing list mitk-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mitk-users