Home › Forum › SOFA › Using SOFA › [SOLVED] How to use the XML API?
- This topic has 6 replies, 3 voices, and was last updated 3 years, 3 months ago by eaparra.
-
AuthorPosts
-
28 November 2016 at 06:30 #8001CocoBlocked
Hello!
I want to load a XML scene file in C++,but meet some problems.
here is my project.
#include <sofa/helper/ArgumentParser.h> #include <SofaSimulationGraph/init.h> #include <SofaSimulationGraph/DAGSimulation.h> #include <SofaSimulationCommon/SceneLoaderXML.h> #include <sofa/simulation/Node.h> #include <SofaGraphComponent/Gravity.h> #include <SofaExplicitOdeSolver/EulerSolver.h> #include <SofaBaseVisual/VisualStyle.h> #include <sofa/core/objectmodel/Context.h> #include <SofaBaseCollision/SphereModel.h> #include <sofa/core/VecId.h> #include <sofa/gui/GUIManager.h> #include <sofa/gui/Main.h> #include <sofa/helper/system/glut.h> #include <sofa/helper/accessor.h> #include <SofaComponentCommon/initComponentCommon.h> #include <SofaComponentBase/initComponentBase.h> #include <SofaComponentGeneral/initComponentGeneral.h> #include <SofaComponentAdvanced/initComponentAdvanced.h> #include <SofaComponentMisc/initComponentMisc.h> using sofa::component::odesolver::EulerSolver; using namespace sofa::component::collision; using sofa::core::objectmodel::Data; using sofa::helper::ReadAccessor; using sofa::helper::WriteAccessor; using sofa::core::VecId; using sofa::core::objectmodel::New; //Using double by default, if you have SOFA_FLOAT in use in you sofa-default.cfg, then it will be FLOAT. #include <sofa/component/typedef/Sofa_typedef.h> // --------------------------------------------------------------------- // --- // --------------------------------------------------------------------- int main(int argc, char** argv) { glutInit(&argc,argv); sofa::simulation::graph::init(); sofa::component::initComponentBase(); sofa::component::initComponentCommon(); sofa::component::initComponentGeneral(); sofa::component::initComponentAdvanced(); sofa::component::initComponentMisc(); sofa::gui::initMain(); sofa::helper::parse("This is a SOFA application.") (argc,argv); // The graph root node sofa::simulation::setSimulation(new sofa::simulation::graph::DAGSimulation()); sofa::simulation::Node::SPtr groot =sofa::simulation::SceneLoaderXML().load("D:/workfile/sofa/v16.08/src/share/XMLfile/ball.xml"); sofa::simulation::graph::getSimulation()->init(groot.get()); groot->setAnimate(false); //====================================== // Set up the GUI sofa::gui::GUIManager::Init(argv[0]); sofa::gui::GUIManager::createGUI(groot); sofa::gui::GUIManager::SetDimension(800,700); // sofa::gui::GUIManager::SetFullScreen(); // why does this not work ? //======================================= // Run the main loop sofa::gui::GUIManager::MainLoop(groot); sofa::simulation::graph::cleanup(); return 0; }
Here is my XML file
<Node> <MechanicalObject template="Vec3" position="0 0 0" name="dofs" /> <UniformMass /> <FixedConstraint indices="0" /> <SphereModel radius="0.5" /> </Node>
When I run my project in debug, I found an error at line
sofa::gui::GUIManager::createGUI(groot);
and the detail display Unhandled exception at 0x000007FED8774362 (SofaGuiQt_d.dll) in XMLLoaderTest.exe: 0xC0000005: Access violation reading location 0x0000000000000000.Can someone help me?
30 November 2016 at 19:17 #8031HugoKeymasterHi Coco,
I would advise to use a backtracer to check where does this crash come from.
Moreover, for the writing of such a main() I would advise to stay close and compare with the one from runSofa.Cheers,
Hugo
1 December 2016 at 02:58 #8032CocoBlockedHi Hugo,
I have solved the problem.
Thanks a lot!
2 December 2016 at 08:55 #8037HugoKeymasterNice ! well done Coco !
What was the issue ?Cheers,
Hugo
2 December 2016 at 15:46 #8039CocoBlockedHi Hugo,
As you said, I refer to the runSofa and change the
sofa::simulation::Node::SPtr groot =sofa::simulation::SceneLoaderXML().load("D:/workfile/sofa/v16.08/src/share/XMLfile/ball.xml");
tosofa::simulation::Node::SPtr groot = sofa::simulation::getSimulation()->load(fileName.c_str());
.It works well.2 December 2016 at 17:09 #8040HugoKeymasterPerfect.
Thank you for sharing,Best,
Hugo
26 August 2021 at 20:06 #20255eaparraBlockedHi @Coco and @Hugo.
I would like to know if it is possible using C++ or pyhton that controls de variables of the xml scene?
I have been making a scene in xml “.scn” but I want to change some variables, for instance in ConstantForceField <ConstantForceField indices=”0″ forces=”0 0 0 0 X 0 0″ printLog=”true”/> and I would like to change X in the simulation.Thanks for the help.
-
AuthorPosts
- You must be logged in to reply to this topic.