Main.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <iostream>
00028 #include <fstream>
00029
00030 #include <sofa/helper/ArgumentParser.h>
00031 #include <sofa/simulation/tree/Simulation.h>
00032 #include <sofa/component/contextobject/Gravity.h>
00033 #include <sofa/component/contextobject/CoordinateSystem.h>
00034 #include <sofa/core/objectmodel/Context.h>
00035 #include <sofa/component/odesolver/CGImplicitSolver.h>
00036 #include <sofa/helper/system/FileRepository.h>
00037 #include <sofa/gui/SofaGUI.h>
00038
00039 #include <sofa/component/typedef/Sofa_typedef.h>
00040
00041 #include <sofa/helper/system/glut.h>
00042
00043 using namespace sofa::simulation::tree;
00044 using sofa::component::odesolver::CGImplicitSolver;
00045 using sofa::component::topology::MeshTopology;
00046 using sofa::component::visualmodel::OglModel;
00047
00048
00049
00050 int main(int argc, char** argv)
00051 {
00052 glutInit(&argc,argv);
00053 sofa::helper::parse("This is a SOFA application.")
00054 (argc,argv);
00055
00056 sofa::gui::SofaGUI::Init(argv[0]);
00057
00058
00059 GNode* groot = new GNode;
00060 groot->setName( "root" );
00061 groot->setGravityInWorld( Coord3(0,-10,0) );
00062
00063
00064
00065 CGImplicitSolver* solver = new CGImplicitSolver;
00066 solver->f_printLog.setValue(false);
00067 groot->addObject(solver);
00068
00069
00070 MechanicalObject3* DOF = new MechanicalObject3;
00071 groot->addObject(DOF);
00072 DOF->resize(4);
00073 DOF->setName("DOF");
00074 VecCoord3& x = *DOF->getX();
00075
00076 x[0] = Coord3(0,10,0);
00077 x[1] = Coord3(10,0,0);
00078 x[2] = Coord3(-10*0.5,0,10*0.866);
00079 x[3] = Coord3(-10*0.5,0,-10*0.866);
00080
00081
00082 UniformMass3* mass = new UniformMass3;
00083 groot->addObject(mass);
00084 mass->setMass(2);
00085 mass->setName("mass");
00086
00087
00088 MeshTopology* topology = new MeshTopology;
00089 topology->setName("mesh topology");
00090 groot->addObject( topology );
00091 topology->addTetra(0,1,2,3);
00092
00093
00094 FixedConstraint3* constraints = new FixedConstraint3;
00095 constraints->setName("constraints");
00096 groot->addObject(constraints);
00097 constraints->addConstraint(0);
00098
00099
00100 TetrahedronFEMForceField3* fem = new TetrahedronFEMForceField3;
00101 fem->setName("FEM");
00102 groot->addObject(fem);
00103 fem->setMethod("polar");
00104 fem->setUpdateStiffnessMatrix(true);
00105 fem->setYoungModulus(6);
00106
00107
00108 GNode* skin = new GNode;
00109 skin->setName( "skin" );
00110 groot->addChild(skin);
00111
00112 OglModel* visual = new OglModel();
00113 visual->setName( "visual" );
00114 visual->load(sofa::helper::system::DataRepository.getFile("mesh/liver-smooth.obj"), "", "");
00115 visual->setColor("red");
00116 visual->applyScale(0.7);
00117 visual->applyTranslation(1.2, 0.8, 0);
00118 skin->addObject(visual);
00119
00120
00121 BarycentricMapping3_to_Ext3* mapping = new BarycentricMapping3_to_Ext3(DOF, visual);
00122 mapping->setName( "mapping" );
00123 skin->addObject(mapping);
00124
00125
00126 getSimulation()->init(groot);
00127 groot->setAnimate(false);
00128 groot->setShowNormals(false);
00129 groot->setShowInteractionForceFields(false);
00130 groot->setShowMechanicalMappings(false);
00131 groot->setShowCollisionModels(false);
00132 groot->setShowBoundingCollisionModels(false);
00133 groot->setShowMappings(false);
00134 groot->setShowForceFields(true);
00135 groot->setShowWireFrame(true);
00136 groot->setShowVisualModels(true);
00137
00138
00139
00140
00141
00142 sofa::gui::SofaGUI::MainLoop(groot);
00143
00144 return 0;
00145 }