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