Main.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This program is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU General Public License as published by the Free  *
00007 * Software Foundation; either version 2 of the License, or (at your option)   *
00008 * any later version.                                                          *
00009 *                                                                             *
00010 * This program is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for    *
00013 * more details.                                                               *
00014 *                                                                             *
00015 * You should have received a copy of the GNU General Public License along     *
00016 * with this program; if not, write to the Free Software Foundation, Inc., 51  *
00017 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.                   *
00018 *******************************************************************************
00019 *                            SOFA :: Applications                             *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00028 // scene data structure 
00029 #include <sofa/simulation/tree/Simulation.h> 
00030 #include <sofa/component/contextobject/Gravity.h>
00031 #include <sofa/component/odesolver/CGImplicitSolver.h>
00032 #include <sofa/component/odesolver/EulerSolver.h>
00033 #include <sofa/component/odesolver/StaticSolver.h>
00034 #include <sofa/component/visualmodel/OglModel.h>
00035 // gui 
00036 #include <sofa/gui/SofaGUI.h> 
00037 
00038 #include <sofa/component/typedef/Sofa_typedef.h>
00039 
00040 using namespace sofa::simulation::tree;
00041 using sofa::component::odesolver::EulerSolver;
00042    
00043 int main(int, char** argv)    
00044 {
00045     sofa::gui::SofaGUI::Init(argv[0]);
00046     //=========================== Build the scene 
00047     double endPos = 1.;  
00048     double attach = -1.;
00049     double splength = 1.;
00050 
00051     //-------------------- The graph root node
00052     GNode* groot = new GNode;
00053     groot->setName( "root" );
00054     groot->setGravityInWorld( Coord3(0,-10,0) );
00055 
00056     // One solver for all the graph
00057     EulerSolver* solver = new EulerSolver;
00058     groot->addObject(solver);
00059     solver->setName("S");
00060 
00061     //-------------------- Deformable body
00062     GNode* deformableBody = new GNode;
00063     groot->addChild(deformableBody);
00064     deformableBody->setName( "deformableBody" );
00065 
00066     // degrees of freedom
00067     MechanicalObject3* DOF = new MechanicalObject3;
00068     deformableBody->addObject(DOF);
00069     DOF->resize(2);
00070     DOF->setName("Dof1");
00071     VecCoord3& x = *DOF->getX();
00072     x[0] = Coord3(0,0,0);
00073     x[1] = Coord3(endPos,0,0);
00074 
00075     // mass
00076     //    ParticleMasses* mass = new ParticleMasses;
00077     UniformMass3* mass = new UniformMass3; 
00078     deformableBody->addObject(mass);
00079     mass->setMass(1);
00080     mass->setName("M1");
00081 
00082     // Fixed point 
00083     FixedConstraint3* constraints = new FixedConstraint3;
00084     deformableBody->addObject(constraints);
00085     constraints->setName("C");
00086     constraints->addConstraint(0);
00087 
00088     
00089     // force field
00090     StiffSpringForceField3* spring = new StiffSpringForceField3;
00091     deformableBody->addObject(spring);
00092     spring->setName("F1");
00093     spring->addSpring( 1,0, 10., 1, splength );
00094     
00095 
00096     //-------------------- Rigid body
00097     GNode* rigidBody = new GNode;
00098     groot->addChild(rigidBody);
00099     rigidBody->setName( "rigidBody" );
00100 
00101     // degrees of freedom
00102     MechanicalObjectRigid3* rigidDOF = new MechanicalObjectRigid3;
00103     rigidBody->addObject(rigidDOF);
00104     rigidDOF->resize(1);
00105     rigidDOF->setName("Dof2");
00106     VecCoordRigid3& rigid_x = *rigidDOF->getX();
00107     rigid_x[0] = CoordRigid3( Coord3(endPos-attach+splength,0,0),
00108                    Quat3::identity() );
00109 
00110     // mass
00111     UniformMassRigid3* rigidMass = new UniformMassRigid3;
00112     rigidBody->addObject(rigidMass);
00113     rigidMass->setName("M2"); 
00114     
00115  
00116     //-------------------- the particles attached to the rigid body
00117     GNode* rigidParticles = new GNode;
00118     rigidParticles->setName( "rigidParticles" );
00119     rigidBody->addChild(rigidParticles);
00120 
00121     // degrees of freedom of the skin
00122     MechanicalObject3* rigidParticleDOF = new MechanicalObject3;
00123     rigidParticles->addObject(rigidParticleDOF);
00124     rigidParticleDOF->resize(1);
00125     rigidParticleDOF->setName("Dof3");
00126     VecCoord3& rp_x = *rigidParticleDOF->getX();
00127     rp_x[0] = Coord3(attach,0,0);
00128 
00129     // mapping from the rigid body DOF to the skin DOF, to rigidly attach the skin to the body
00130     RigidMechanicalMappingRigid3_to_3* rigidMapping = new RigidMechanicalMappingRigid3_to_3(rigidDOF,rigidParticleDOF);
00131     rigidParticles->addObject( rigidMapping );
00132     rigidMapping->setName("Map23");
00133 
00134 
00135     // ---------------- Interaction force between the deformable and the rigid body
00136     StiffSpringForceField3* iff = new StiffSpringForceField3( DOF, rigidParticleDOF );
00137     groot->addObject(iff);
00138     iff->setName("F13");
00139     iff->addSpring( 1,0, 10., 1., splength );
00140 
00141 
00142 
00143 
00144     //=========================== Init the scene
00145     getSimulation()->init(groot);
00146     groot->setAnimate(false);
00147     groot->setShowNormals(false);
00148     groot->setShowInteractionForceFields(true);
00149     groot->setShowMechanicalMappings(true);
00150     groot->setShowCollisionModels(false);
00151     groot->setShowBoundingCollisionModels(false);
00152     groot->setShowMappings(false);
00153     groot->setShowForceFields(true);
00154     groot->setShowWireFrame(false);
00155     groot->setShowVisualModels(true);
00156     groot->setShowBehaviorModels(true);
00157 
00158 
00159 
00160     //=========================== Run the main loop
00161     
00162     sofa::gui::SofaGUI::MainLoop(groot);
00163 }
00164 

Generated on Sun Nov 23 02:28:34 2008 for Sofa by  doxygen 1.5.7.1