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 ******************************************************************************/
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     // The graph root node : gravity already exists in a GNode by default
00059     GNode* groot = new GNode;
00060     groot->setName( "root" );
00061     groot->setGravityInWorld( Coord3(0,-10,0) );
00062 
00063 
00064     // One solver for all the graph
00065     CGImplicitSolver* solver = new CGImplicitSolver;
00066     solver->f_printLog.setValue(false);
00067     groot->addObject(solver);
00068 
00069     // Tetrahedron degrees of freedom
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     // Tetrahedron uniform mass
00082     UniformMass3* mass = new UniformMass3;
00083     groot->addObject(mass);
00084     mass->setMass(2);
00085     mass->setName("mass");
00086   
00087     // Tetrahedron topology
00088     MeshTopology* topology = new MeshTopology;
00089     topology->setName("mesh topology");
00090     groot->addObject( topology );
00091     topology->addTetra(0,1,2,3);
00092 
00093     // Tetrahedron constraints
00094     FixedConstraint3* constraints = new FixedConstraint3;
00095     constraints->setName("constraints");
00096     groot->addObject(constraints);
00097     constraints->addConstraint(0);
00098 
00099     // Tetrahedron force field
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     // Tetrahedron skin
00108     GNode* skin = new GNode;
00109     skin->setName( "skin" );
00110     groot->addChild(skin);
00111     // The visual model
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     // The mapping between the tetrahedron (DOF) and the liver (visual)
00121     BarycentricMapping3_to_Ext3* mapping = new BarycentricMapping3_to_Ext3(DOF, visual);
00122     mapping->setName( "mapping" );
00123     skin->addObject(mapping);
00124 
00125     // Init the scene
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     // Run the main loop
00142     sofa::gui::SofaGUI::MainLoop(groot);
00143 
00144     return 0;
00145 }

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