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 #include <stdarg.h>
00030 #include <stdio.h>
00031 
00032 #include <sofa/gpu/cuda/mycuda.h>
00033 
00034 #include <sofa/simulation/tree/Simulation.h>
00035 #include <sofa/component/init.h>
00036 #include <sofa/helper/Factory.h>
00037 #include <sofa/helper/BackTrace.h>
00038 #include <sofa/helper/system/thread/CTime.h>
00039 #include <sofa/helper/system/FileRepository.h>
00040 #include <sofa/gui/SofaGUI.h>
00041 #include <sofa/helper/system/glut.h>
00042 
00043 using sofa::helper::system::thread::CTime;
00044 using sofa::helper::system::thread::ctime_t;
00045 
00046 using namespace sofa::simulation::tree;
00047 using namespace sofa::gpu::cuda;
00048 
00049 // ---------------------------------------------------------------------
00050 // --- MAIN
00051 // ---------------------------------------------------------------------
00052 
00053 int main(int argc, char** argv) {
00054 
00055     glutInit(&argc,argv);
00056     
00057     //std::string fileName = "CUDA/beam10x10x46-spring-rk4-CUDA.scn";
00058 
00059     std::string fileName = "CUDA/quadSpringSphereCUDA.scn";
00060     
00061     int nbIter = 0;
00062     if (argc < 2 || argc > 3)
00063     {
00064         std::cerr << "Usage: "<<argv[0]<<" filename.scn [niterations]\n";
00065         //return 1;
00066     }
00067     else
00068     {
00069         fileName = argv[1];
00070         if (argc >=3) nbIter = atoi(argv[2]);
00071     }
00072 
00073     sofa::component::init();
00074 
00075     sofa::gui::SofaGUI::Init(argv[0]);
00076 
00077     sofa::helper::system::DataRepository.findFile(fileName);
00078 
00079     mycudaInit();
00080 
00081     GNode* groot = NULL; 
00082     ctime_t t0, t1;
00083     CTime::getRefTime();
00084 
00085     if (!fileName.empty())
00086     {
00087       groot = dynamic_cast< GNode* >(getSimulation()->load(fileName.c_str()));
00088     }
00089 
00090     if (groot==NULL)
00091     {
00092         groot = new GNode;
00093     }
00094 
00095     if (nbIter > 0)
00096     {
00097 
00098         groot->setAnimate(true);
00099 
00100         std::cout << "Computing first iteration." << std::endl;
00101 
00102         getSimulation()->animate(groot);
00103 
00104         //=======================================
00105         // Run the main loop
00106 
00107         std::cout << "Computing " << nbIter << " iterations." << std::endl;
00108         t0 = CTime::getRefTime();
00109 
00110         //=======================================
00111         // SEQUENTIAL MODE
00112         int n = 0;
00113         for (int i=0;i<nbIter;i++)
00114         {
00115             int n2 = i*80/(nbIter-1);
00116             while(n2>n)
00117             {
00118                 std::cout << '.' << std::flush;
00119                 ++n;
00120             }
00121             getSimulation()->animate(groot);
00122         }
00123 
00124         t1 = CTime::getRefTime();
00125         std::cout << std::endl;
00126         std::cout << nbIter << " iterations done." << std::endl;
00127         std::cout << "Time: " << ((t1-t0)/(CTime::getRefTicksPerSec()/1000))*0.001 << " seconds, " << ((t1-t0)/(CTime::getRefTicksPerSec()/1000))/(double)nbIter <<" ms/it." << std::endl;
00128         std::string logname = fileName.substr(0,fileName.length()-4)+"-log.txt";
00129         std::ofstream flog(logname.c_str());
00130         flog << "Time: " << ((t1-t0)/(CTime::getRefTicksPerSec()/1000))*0.001 << " seconds, " << ((t1-t0)/(CTime::getRefTicksPerSec()/1000))/(double)nbIter <<" ms/it." << std::endl;
00131         flog.close();
00132         std::string objname = fileName.substr(0,fileName.length()-4)+"-scene.obj";
00133         std::cout << "Exporting to OBJ " << objname << std::endl;
00134         getSimulation()->exportOBJ(groot, objname.c_str());
00135         std::string xmlname = fileName.substr(0,fileName.length()-4)+"-scene.scn";
00136         std::cout << "Exporting to XML " << xmlname << std::endl;
00137         getSimulation()->exportXML(groot, xmlname.c_str());
00138 
00139     }
00140     else
00141     {
00142         sofa::gui::SofaGUI::MainLoop(groot,fileName.c_str());
00143     }
00144 
00145     return 0;
00146 }

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