Cleanage.
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 02_Mandelbrot_Julia / moo / device / FractalDevice.cu
1 #include "FractalDevice.h"\r
2 \r
3 #include <iostream>\r
4 \r
5 #include "Indice2D.h"\r
6 #include "IndiceTools.h"\r
7 #include "cudaTools.h"\r
8 #include "Device.h"\r
9 \r
10 #include "FractalMath.h"\r
11 \r
12 using std::cout;\r
13 using std::endl;\r
14 \r
15 __device__ void fractal(uchar4* ptrDevPixels, int w, int h, const DomaineMath& domaineMath, int n, const FractalMath& fractalMath)\r
16     {\r
17     const int TID = Indice2D::tid();\r
18     const int NB_THREAD = Indice2D::nbThread();\r
19     const int WH = w * h;\r
20 \r
21     uchar4 color;\r
22     color.z = 255; // Par défaut, l'image est opaque.\r
23 \r
24     double x, y;\r
25     int pixelI, pixelJ;\r
26 \r
27     int s = TID;\r
28     while (s < WH)\r
29         {\r
30         IndiceTools::toIJ(s, w, &pixelI, &pixelJ); // update (pixelI, pixelJ)\r
31 \r
32         // (i,j) domaine écran\r
33         // (x,y) domaine math\r
34         domaineMath.toXY(pixelI, pixelJ, &x, &y); //  (i,j) -> (x,y)\r
35 \r
36         fractalMath.colorXY(&color, x, y);\r
37 \r
38         ptrDevPixels[s] = color;\r
39 \r
40         s += NB_THREAD;\r
41         }\r
42     }\r
43 \r
44 __global__ void fractalMandelbrot(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n)\r
45     {\r
46     FractalMandelbrotMath fractalMath(n);\r
47     fractal(ptrDevPixels, w, h, domaineMath, n, fractalMath);\r
48     }\r
49 \r
50 __global__ void fractalJulia(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n, float c_r, float c_i)\r
51     {\r
52     FractalJuliaMath fractalMath(n, c_r, c_i);\r
53     fractal(ptrDevPixels, w, h, domaineMath, n, fractalMath);\r
54     }\r
55 \r