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 #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
00051
00052
00053 int main(int argc, char** argv) {
00054
00055 glutInit(&argc,argv);
00056
00057
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
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
00106
00107 std::cout << "Computing " << nbIter << " iterations." << std::endl;
00108 t0 = CTime::getRefTime();
00109
00110
00111
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 }