Implémentation de RipplingMath.h
[GPU.git] / WCudaMSE / Student_OMP_Image / src / cpp / core / 01_Rippling / c_math / RipplingMath.h
1 #ifndef RIPPLING_MATH_H_
2 #define RIPPLING_MATH_H_
3
4 #include "MathTools.h"
5 #include <cmath>
6 using namespace std;
7
8 /*----------------------------------------------------------------------*\
9 |* Declaration *|
10 \*---------------------------------------------------------------------*/
11
12 /*--------------------------------------*\
13 |* Public *|
14 \*-------------------------------------*/
15
16 /**
17 * Dans un header only pour preparer la version cuda
18 */
19 class RipplingMath
20 {
21
22 /*--------------------------------------*\
23 |* Constructeur *|
24 \*-------------------------------------*/
25
26 public:
27 RipplingMath(unsigned int w, unsigned int h)
28 : dim2 { w / 2.0 }
29 {
30 }
31
32 virtual ~RipplingMath()
33 {
34 //rien
35 }
36
37 /*--------------------------------------*\
38 |* Methode *|
39 \*-------------------------------------*/
40
41 public:
42 void colorIJ(uchar4* ptrColor, int i, int j, float t)
43 {
44 const double dxy10 = dxy(j, i) / 10.0;
45 const double grayLevelFloat = 128.0 + 127.0 * cos(dxy10 - t / 7.0) / (dxy10 + 1);
46 const uchar grayLevel = (uchar)(long(grayLevelFloat) % 256);
47
48 ptrColor->x = grayLevel;
49 ptrColor->y = grayLevel;
50 ptrColor->z = grayLevel;
51
52 ptrColor->w = 255; // Opaque.
53 }
54
55 private:
56 inline double dxy(int x, int y) // par exmple
57 {
58 return sqrt(pow(x - this->dim2, 2.0) + pow(y - this->dim2, 2.0));
59 }
60
61 private:
62
63 /*--------------------------------------*\
64 |* Attribut *|
65 \*-------------------------------------*/
66
67 private:
68 const double dim2; // = dim / 2.
69 };
70
71 #endif
72
73 /*----------------------------------------------------------------------*\
74 |* End *|
75 \*---------------------------------------------------------------------*/