Rippling CUDA Warmup et Smart.
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 01_Rippling / moo / device / math / RipplingMath.h
1 #ifndef RIPPLING_MATH_H_
2 #define RIPPLING_MATH_H_
3
4 #include <math.h>
5
6 /*----------------------------------------------------------------------*\
7 |* Declaration *|
8 \*---------------------------------------------------------------------*/
9
10 /*--------------------------------------*\
11 |* Public *|
12 \*-------------------------------------*/
13
14 class RipplingMath
15 {
16
17 /*--------------------------------------*\
18 |* Constructor *|
19 \*-------------------------------------*/
20
21 public:
22
23 __device__
24 RipplingMath(int w, int h)
25 : dim2(w / 2.0)
26 {
27 }
28
29 /*--------------------------------------*\
30 |* Methodes *|
31 \*-------------------------------------*/
32
33 public:
34
35 /**
36 * x=pixelI
37 * y=pixelJ
38 */
39 __device__
40 void color(int i, int j, float t, uchar4& color)
41 {
42 const double dxy10 = dxy(j, i) / 10.0;
43 const double grayLevelFloat = 128.0 + 127.0 * cos(dxy10 - t / 7.0 / 10.0) / (dxy10 + 1);
44 const uchar grayLevel = (uchar)(long(grayLevelFloat) % 256);
45
46 color.x = grayLevel;
47 color.y = grayLevel;
48 color.z = grayLevel;
49 }
50
51 private:
52 __device__
53 double dxy(int x, int y)
54 {
55 return sqrt(pow(x - this->dim2, 2.0) + pow(y - this->dim2, 2.0));
56 }
57
58
59 /*--------------------------------------*\
60 |* Attributs *|
61 \*-------------------------------------*/
62
63 private:
64 const double dim2;
65
66 // Tools
67
68 };
69
70 #endif
71
72 /*----------------------------------------------------------------------*\
73 |* End *|
74 \*---------------------------------------------------------------------*/