// --------------------------------------------------------------------- // --- // --------------------------------------------------------------------- int main(int argc, char** argv) { glutInit(&argc,argv); sofa::helper::parse("This is a SOFA application.") (argc,argv); sofa::gui::GUIManager::Init(argv[0]); // The graph root node GNode::SPtr groot = sofa::core::objectmodel::New<GNode>(); groot->setName( "root" ); groot->setGravity( Coord3(0,-10,0) ); // One solver for all the graph EulerSolver::SPtr solver = sofa::core::objectmodel::New<EulerSolver>(); solver->setName("solver"); solver->f_printLog.setValue(false); groot->addObject(solver); // One node to define the particle GNode::SPtr particule_node = sofa::core::objectmodel::New<GNode>("particle_node", groot.get()); // The particule, i.e, its degrees of freedom : a point with a velocity MechanicalObject3::SPtr particle = sofa::core::objectmodel::New<MechanicalObject3>(); particle->setName("particle"); particule_node->addObject(particle); particle->resize(1); // get write access the particle positions vector WriteAccessor< Data<MechanicalObject3::VecCoord> > positions = *particle->write( VecId::position() ); positions[0] = Coord3(0,0,0); // get write access the particle velocities vector WriteAccessor< Data<MechanicalObject3::VecDeriv> > velocities = *particle->write( VecId::velocity() ); velocities[0] = Deriv3(0,0,0); // Its properties, i.e, a simple mass node UniformMass3::SPtr mass = sofa::core::objectmodel::New<UniformMass3>(); mass->setName("mass"); particule_node->addObject(mass); mass->setMass( 1 ); // Display Flags sofa::component::visualmodel::VisualStyle::SPtr style = sofa::core::objectmodel::New<sofa::component::visualmodel::VisualStyle>(); groot->addObject(style); sofa::core::visual::DisplayFlags& flags = *style->displayFlags.beginEdit(); flags.setShowBehaviorModels(true); style->displayFlags.endEdit(); sofa::simulation::tree::getSimulation()->init(groot.get()); groot->setAnimate(false); //======================================= // Run the main loop sofa::gui::GUIManager::MainLoop(groot); return 0; }
// --------------------------------------------------------------------- // --- // --------------------------------------------------------------------- int main(int argc, char** argv) { glutInit(&argc,argv); sofa::simulation::tree::init(); sofa::helper::parse("This is a SOFA application.") (argc,argv); sofa::component::initComponentBase(); sofa::component::initComponentCommon(); sofa::component::initComponentGeneral(); sofa::component::initComponentAdvanced(); sofa::component::initComponentMisc(); sofa::gui::initMain(); sofa::gui::GUIManager::Init(argv[0]); // The graph root node : gravity already exists in a GNode by default sofa::simulation::setSimulation(new sofa::simulation::tree::TreeSimulation()); sofa::simulation::Node::SPtr groot = sofa::simulation::getSimulation()->createNewGraph("root"); groot->setGravity( Coord3(0,-10,0) ); // One solver for all the graph EulerImplicitSolver::SPtr solver = sofa::core::objectmodel::New<EulerImplicitSolver>(); solver->setName("solver"); solver->f_printLog.setValue(false); groot->addObject(solver); CGLinearSolver::SPtr linearSolver = New<CGLinearSolver>(); linearSolver->setName("linearSolver"); groot->addObject(linearSolver); // Tetrahedron degrees of freedom MechanicalObject3::SPtr DOF = sofa::core::objectmodel::New<MechanicalObject3>(); groot->addObject(DOF); DOF->resize(4); DOF->setName("DOF"); //get write access to the position vector of mechanical object DOF WriteAccessor<Data<VecCoord3> > x = *DOF->write(VecId::position()); x[0] = Coord3(0,10,0); x[1] = Coord3(10,0,0); x[2] = Coord3(-10*0.5,0,10*0.866); x[3] = Coord3(-10*0.5,0,-10*0.866); DOF->showObject.setValue(true); DOF->showObjectScale.setValue(10.); // Tetrahedron uniform mass UniformMass3::SPtr mass = sofa::core::objectmodel::New<UniformMass3>(); groot->addObject(mass); mass->setMass(2); mass->setName("mass"); // Tetrahedron topology MeshTopology::SPtr topology = sofa::core::objectmodel::New<MeshTopology>(); topology->setName("mesh topology"); groot->addObject( topology ); topology->addTetra(0,1,2,3); // Tetrahedron constraints FixedConstraint3::SPtr constraints = sofa::core::objectmodel::New<FixedConstraint3>(); constraints->setName("constraints"); groot->addObject(constraints); constraints->addConstraint(0); // Tetrahedron force field TetrahedronFEMForceField3::SPtr fem = sofa::core::objectmodel::New<TetrahedronFEMForceField3>(); fem->setName("FEM"); groot->addObject(fem); fem->setMethod("polar"); fem->setUpdateStiffnessMatrix(true); fem->setYoungModulus(6); // Tetrahedron skin Node::SPtr skin = groot.get()->createChild("skin"); // The visual model OglModel::SPtr visual = sofa::core::objectmodel::New<OglModel>(); visual->setName( "visual" ); visual->load(sofa::helper::system::DataRepository.getFile("mesh/liver-smooth.obj"), "", ""); visual->setColor("red"); visual->applyScale(0.7, 0.7, 0.7); visual->applyTranslation(1.2, 0.8, 0); skin->addObject(visual); // The mapping between the tetrahedron (DOF) and the liver (visual) BarycentricMapping3_to_Ext3::SPtr mapping = sofa::core::objectmodel::New<BarycentricMapping3_to_Ext3>(); mapping->setModels(DOF.get(), visual.get()); mapping->setName( "mapping" ); skin->addObject(mapping); // Display Flags sofa::component::visualmodel::VisualStyle::SPtr style = sofa::core::objectmodel::New<sofa::component::visualmodel::VisualStyle>(); groot->addObject(style); sofa::core::visual::DisplayFlags& flags = *style->displayFlags.beginEdit(); flags.setShowNormals(false); flags.setShowInteractionForceFields(false); flags.setShowMechanicalMappings(false); flags.setShowCollisionModels(false); flags.setShowBoundingCollisionModels(false); flags.setShowMappings(false); flags.setShowForceFields(true); flags.setShowWireFrame(true); flags.setShowVisualModels(true); flags.setShowBehaviorModels(true); style->displayFlags.endEdit(); // Init the scene sofa::simulation::tree::getSimulation()->init(groot.get()); groot->setAnimate(false); //======================================= // Run the main loop sofa::gui::GUIManager::MainLoop(groot); sofa::simulation::tree::cleanup(); return 0; }
// --------------------------------------------------------------------- // --- // --------------------------------------------------------------------- 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::getSimulation()->createNewGraph("root"); groot->setGravity( Coord3(0,-10,0) ); // One solver for all the graph EulerSolver::SPtr solver = sofa::core::objectmodel::New<EulerSolver>(); solver->setName("solver"); solver->f_printLog.setValue(false); groot->addObject(solver); // One node to define the particle sofa::simulation::Node::SPtr particule_node = groot.get()->createChild("particle_node"); // The particule, i.e, its degrees of freedom : a point with a velocity MechanicalObject3::SPtr dof = sofa::core::objectmodel::New<MechanicalObject3>(); dof->setName("particle"); particule_node->addObject(dof); dof->resize(1); // get write access the particle positions vector WriteAccessor< Data<MechanicalObject3::VecCoord> > positions = *dof->write( VecId::position() ); positions[0] = Coord3(0,0,0); // get write access the particle velocities vector WriteAccessor< Data<MechanicalObject3::VecDeriv> > velocities = *dof->write( VecId::velocity() ); velocities[0] = Deriv3(0,0,0); // show the particle dof->showObject.setValue(true); dof->showObjectScale.setValue(10.); // Its properties, i.e, a simple mass node UniformMass3::SPtr mass = sofa::core::objectmodel::New<UniformMass3>(); mass->setName("mass"); particule_node->addObject(mass); mass->setMass( 1 ); // this currently reveals a bug // // attach a collision surface to the particle // SphereModel::SPtr sphere = New<SphereModel>(); // particule_node->addObject(sphere); // sphere->defaultRadius.setValue(0.1); // Display Flags sofa::component::visualmodel::VisualStyle::SPtr style = sofa::core::objectmodel::New<sofa::component::visualmodel::VisualStyle>(); groot->addObject(style); sofa::core::visual::DisplayFlags& flags = *style->displayFlags.beginEdit(); flags.setShowBehaviorModels(true); flags.setShowCollisionModels(true); style->displayFlags.endEdit(); 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; }