9 #include "IndiceTools.h"
16 /*----------------------------------------------------------------------*\
18 \*---------------------------------------------------------------------*/
20 /*--------------------------------------*\
22 \*-------------------------------------*/
24 /*--------------------------------------*\
26 \*-------------------------------------*/
28 /*----------------------------------------------------------------------*\
30 \*---------------------------------------------------------------------*/
32 /*--------------------------------------*\
34 \*-------------------------------------*/
37 * variateurT: fait varier t in [0,2pi] par increment de dt,
38 * d'abord de mani�re croissante jusqua 2PI, puis de maniere decroissante jusqua 0, puis en boucle a l'infini selon ce procede
40 DamierMOO::DamierMOO(unsigned int w
, unsigned int h
, float dt
, int n
):variateurT(IntervalF(0, 2 * PI
), dt
)
48 this->isEntrelacement
=true;
51 const int NB_THREADS
= OmpTools::setAndGetNaturalGranularity();
52 cout
<< "\n[DAMIER] nbThread = " << NB_THREADS
<< endl
;;
55 DamierMOO::~DamierMOO(void)
60 /*--------------------------------------*\
62 \*-------------------------------------*/
64 void DamierMOO::process(uchar4
* ptrTabPixels
, int w
, int h
, const DomaineMath
& domaineMath
)
68 entrelacementOMP(ptrTabPixels
,w
,h
,domaineMath
); // Plus lent
72 forAutoOMP(ptrTabPixels
,w
,h
,domaineMath
); // Plus rapide
75 isEntrelacement
=!isEntrelacement
; // Pour tester que les deux implementations fonctionnent
78 void DamierMOO::animationStep()
80 variateurT
.varierAndGet();
92 float DamierMOO::getT()
94 return variateurT
.get();
97 /*--------------------------------------*\
99 \*-------------------------------------*/
103 * Code naturel et direct OMP
105 void DamierMOO::forAutoOMP(uchar4
* ptrTabPixels
, int w
, int h
, const DomaineMath
& domaineMath
)
107 DamierMath
damierMath(n
); // ici pour preparer cuda
109 #pragma omp parallel for
110 for (int i
= 0; i
< h
; i
++)
112 for (int j
= 0; j
< w
; j
++)
115 int s
=IndiceTools::toS(w
,i
,j
);// i[0,H[ j[0,W[ --> s[0,W*H[
117 workPixel(&ptrTabPixels
[s
],i
, j
,s
, domaineMath
,&damierMath
);
123 * Code entrainement Cuda
125 void DamierMOO::entrelacementOMP(uchar4
* ptrTabPixels
, int w
, int h
, const DomaineMath
& domaineMath
)
127 DamierMath
damierMath(n
); // ici pour preparer cuda
135 const int NB_THREAD
= OmpTools::getNbThread(); // dans region parallel
137 const int TID
= OmpTools::getTid();
138 int s
= TID
; // in [0,...
144 IndiceTools::toIJ(s
,w
,&i
,&j
); // s[0,W*H[ --> i[0,H[ j[0,W[
146 workPixel(&ptrTabPixels
[s
],i
, j
,s
, domaineMath
,&damierMath
);
153 /*--------------------------------------*\
155 \*-------------------------------------*/
164 void DamierMOO::workPixel(uchar4
* ptrColorIJ
,int i
, int j
,int s
, const DomaineMath
& domaineMath
,DamierMath
* ptrDamierMath
)
166 DamierMath
damierMath(n
); // ici pour preparer cuda
168 // (i,j) domaine ecran dans N2
169 // (x,y) domaine math dans R2
174 domaineMath
.toXY(i
, j
, &x
, &y
); // fill (x,y) from (i,j)
176 float t
=variateurT
.get();
177 ptrDamierMath
->colorXY(ptrColorIJ
,x
, y
, domaineMath
,t
); // in [01]
180 /*----------------------------------------------------------------------*\
182 \*---------------------------------------------------------------------*/