X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;ds=sidebyside;f=WCudaMSE%2FTuto_Image%2Fsrc%2Fcpp%2Fcore%2F02_Damier_Zoomable%2Fb_moo%2FDamierMOO.cpp;fp=WCudaMSE%2FTuto_Image%2Fsrc%2Fcpp%2Fcore%2F02_Damier_Zoomable%2Fb_moo%2FDamierMOO.cpp;h=53cd5cf1a600a78ad6f503fddff309375ba17aa9;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Tuto_Image/src/cpp/core/02_Damier_Zoomable/b_moo/DamierMOO.cpp b/WCudaMSE/Tuto_Image/src/cpp/core/02_Damier_Zoomable/b_moo/DamierMOO.cpp new file mode 100755 index 0000000..53cd5cf --- /dev/null +++ b/WCudaMSE/Tuto_Image/src/cpp/core/02_Damier_Zoomable/b_moo/DamierMOO.cpp @@ -0,0 +1,183 @@ +#include +#include + +#include "DamierMOO.h" + +#include "OmpTools.h" +#include "MathTools.h" + +#include "IndiceTools.h" + + +using std::cout; +using std::endl; +using std::string; + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/** + * variateurT: fait varier t in [0,2pi] par increment de dt, + * d'abord de mani�re croissante jusqua 2PI, puis de maniere decroissante jusqua 0, puis en boucle a l'infini selon ce procede + */ +DamierMOO::DamierMOO(unsigned int w, unsigned int h, float dt, int n):variateurT(IntervalF(0, 2 * PI), dt) + { + // Inputs + this->n =n; + this->w=w; + this->h=h; + + //Tools + this->isEntrelacement=true; + + // OMP (facultatif) + const int NB_THREADS = OmpTools::setAndGetNaturalGranularity(); + cout << "\n[DAMIER] nbThread = " << NB_THREADS << endl;; + } + +DamierMOO::~DamierMOO(void) + { + // rien + } + +/*--------------------------------------*\ + |* Override *| + \*-------------------------------------*/ + +void DamierMOO::process(uchar4* ptrTabPixels, int w, int h, const DomaineMath& domaineMath) + { + if (isEntrelacement) + { + entrelacementOMP(ptrTabPixels,w,h,domaineMath); // Plus lent + } + else + { + forAutoOMP(ptrTabPixels,w,h,domaineMath); // Plus rapide + } + + isEntrelacement=!isEntrelacement; // Pour tester que les deux implementations fonctionnent + } + +void DamierMOO::animationStep() + { + variateurT.varierAndGet(); + } + +/*--------------*\ + |* get *| + \*-------------*/ + +int DamierMOO::getN() + { + return n; + } + +float DamierMOO::getT() + { + return variateurT.get(); + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + + +/** + * Code naturel et direct OMP + */ +void DamierMOO::forAutoOMP(uchar4* ptrTabPixels, int w, int h, const DomaineMath& domaineMath) + { + DamierMath damierMath(n); // 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[ + + workPixel(&ptrTabPixels[s],i, j,s, domaineMath,&damierMath); + } + } + } + +/** + * Code entrainement Cuda + */ +void DamierMOO::entrelacementOMP(uchar4* ptrTabPixels, int w, int h, const DomaineMath& domaineMath) + { + DamierMath damierMath(n); // 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[ + + workPixel(&ptrTabPixels[s],i, j,s, domaineMath,&damierMath); + + s += NB_THREAD; + } + } + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/** + * i in [1,h] + * j in [1,w] + * code commun � + * entrelacementOMP + * forAutoOMP + */ +void DamierMOO::workPixel(uchar4* ptrColorIJ,int i, int j,int s, const DomaineMath& domaineMath,DamierMath* ptrDamierMath) + { + DamierMath damierMath(n); // ici pour preparer cuda + + // (i,j) domaine ecran dans N2 + // (x,y) domaine math dans R2 + + double x; + double y; + + domaineMath.toXY(i, j, &x, &y); // fill (x,y) from (i,j) + + float t=variateurT.get(); + ptrDamierMath->colorXY(ptrColorIJ,x, y, domaineMath,t); // in [01] + } + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +