X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=WCudaMSE%2FTuto_Image%2Fsrc%2Fcpp%2Fcore%2F01_Vague%2Fb_moo%2FVagueMOO.cpp;fp=WCudaMSE%2FTuto_Image%2Fsrc%2Fcpp%2Fcore%2F01_Vague%2Fb_moo%2FVagueMOO.cpp;h=7a1e633495d558cb9f78b310913d8e56d50d24d7;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.cpp b/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.cpp new file mode 100755 index 0000000..7a1e633 --- /dev/null +++ b/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.cpp @@ -0,0 +1,150 @@ +#include +#include +#include + +#include "VagueMOO.h" +#include "VagueMath.h" + +#include "OmpTools.h" +#include "IndiceTools.h" + +using std::cout; +using std::endl; + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +VagueMOO::VagueMOO(unsigned int w, unsigned int h, float dt) + { + // Input + this->dt = dt; + this->w=w; + + + // Tools + this->t = 0; + this->isEntrelacement=true; + + + // OMP (facultatif) + const int NB_THREADS = OmpTools::setAndGetNaturalGranularity(); + cout << "\n[VAGUE] nbThread = " << NB_THREADS << endl; + } + +VagueMOO::~VagueMOO(void) + { + // rien + } + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +void VagueMOO::process(uchar4* ptrTabPixels, int w, int h) + { + if (isEntrelacement) + { + entrelacementOMP(ptrTabPixels, w, h); // Plus lent + } + else + { + forAutoOMP(ptrTabPixels, w, h); // Plus rapide + } + + isEntrelacement = !isEntrelacement; // Pour tester que les deux implementations fonctionnent + } + +void VagueMOO::animationStep() + { + t+=dt; + } + +/*--------------*\ + |* get *| + \*-------------*/ + +float VagueMOO::getT() + { + return t; + } + +float VagueMOO::getDT() + { + return dt; + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/** + * Code naturel et direct OMP + */ +void VagueMOO::forAutoOMP(uchar4* ptrTabPixels, int w, int h) + { + VagueMath vagueMath(w,h); // ici pour preparer cuda + +#pragma omp parallel for + for (int i = 0; i < h; i++) + { + for (int j = 0; j < w; j++) + { + // int s = i * W + j; + int s = IndiceTools::toS(w, i, j); // i[0,H[ j[0,W[ --> s[0,W*H[ + + vagueMath.colorIJ(&ptrTabPixels[s], i, j,t); + } + } + } + +/** + * Code entrainement Cuda + */ +void VagueMOO::entrelacementOMP(uchar4* ptrTabPixels, int w, int h) + { + VagueMath vagueMath(w,h); // ici pour preparer cuda + + const int WH = w * h; + + +#pragma omp parallel + { + const int NB_THREAD = OmpTools::getNbThread();// dans region parallel + const int TID = OmpTools::getTid(); + int s = TID; // in [0,... + + int i; + int j; + while (s < WH) + { + IndiceTools::toIJ(s, w, &i, &j); // s[0,W*H[ --> i[0,H[ j[0,W[ + + vagueMath.colorIJ(&ptrTabPixels[s], i, j,t); + + s += NB_THREAD; + } + } + } + + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +