TP fractalTP fractal..
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 02_Mandelbrot_Julia / moo / device / FractalDevice.cu
1 #include <iostream>\r
2 \r
3 #include "Indice2D.h"\r
4 #include "IndiceTools.h"\r
5 #include "DomaineMath.h"\r
6 #include "cudaTools.h"\r
7 #include "Device.h"\r
8 \r
9 #include "FractalMath.h"\r
10 \r
11 using std::cout;\r
12 using std::endl;\r
13 \r
14 /*----------------------------------------------------------------------*\\r
15  |*                     Declaration                                     *|\r
16  \*---------------------------------------------------------------------*/\r
17 \r
18 /*--------------------------------------*\\r
19  |*             Imported                *|\r
20  \*-------------------------------------*/\r
21 \r
22 /*--------------------------------------*\\r
23  |*             Public                  *|\r
24  \*-------------------------------------*/\r
25 \r
26 __global__ void fractalMandelbrot(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n);\r
27 __global__ void fractalJulia(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n, float c_r, float c_i);\r
28 __device__ void fractal(uchar4* ptrDevPixels, int w, int h, const DomaineMath& domaineMath, int n, const FractalMath& fractalMath);\r
29 \r
30 /*--------------------------------------*\\r
31  |*             Private                 *|\r
32  \*-------------------------------------*/\r
33 \r
34 /*----------------------------------------------------------------------*\\r
35  |*                     Implementation                                  *|\r
36  \*---------------------------------------------------------------------*/\r
37 \r
38 /*--------------------------------------*\\r
39  |*             Public                  *|\r
40  \*-------------------------------------*/\r
41 \r
42 /*--------------------------------------*\\r
43  |*             Private                 *|\r
44  \*-------------------------------------*/\r
45 \r
46 \r
47 __global__ void fractalMandelbrot(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n)\r
48     {\r
49     FractalMandelbrotMath fractalMath(n);\r
50     fractal(ptrDevPixels, w, h, domaineMath, n, fractalMath);\r
51     }\r
52 \r
53 __global__ void fractalJulia(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n, float c_r, float c_i)\r
54     {\r
55     FractalJuliaMath fractalMath(n, c_r, c_i);\r
56     fractal(ptrDevPixels, w, h, domaineMath, n, fractalMath);\r
57     }\r
58 \r
59 __device__ void fractal(uchar4* ptrDevPixels, int w, int h, const DomaineMath& domaineMath, int n, const FractalMath& fractalMath)\r
60     {\r
61     const int TID = Indice2D::tid();\r
62     const int NB_THREAD = Indice2D::nbThread();\r
63     const int WH = w * h;\r
64 \r
65     uchar4 color;\r
66     color.z = 255; // Par défaut, l'image est opaque.\r
67 \r
68     double x, y;\r
69     int pixelI, pixelJ;\r
70 \r
71     int s = TID;\r
72     while (s < WH)\r
73         {\r
74         IndiceTools::toIJ(s, w, &pixelI, &pixelJ); // update (pixelI, pixelJ)\r
75 \r
76         // (i,j) domaine ecran\r
77         // (x,y) domaine math\r
78         domaineMath.toXY(pixelI, pixelJ, &x, &y); //  (i,j) -> (x,y)\r
79 \r
80         fractalMath.colorXY(&color, x, y);\r
81 \r
82         ptrDevPixels[s] = color;\r
83 \r
84         s += NB_THREAD;\r
85         }\r
86     }\r
87 \r
88 /*----------------------------------------------------------------------*\\r
89  |*                     End                                             *|\r
90  \*---------------------------------------------------------------------*/\r
91 \r