Rippling CUDA Warmup et Smart.
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 00_Rippling_warmup / 03_math / Rippling0Math.h
index 67b4387..3879d1d 100755 (executable)
@@ -1,7 +1,7 @@
 #ifndef RIPPLING_0_MATH_H_\r
 #define RIPPLING_0_MATH_H_\r
 \r
-#include <math.h>\r
+#include <cmath>\r
 #include "MathTools.h"\r
 \r
 /*----------------------------------------------------------------------*\\r
@@ -23,14 +23,8 @@ class Rippling0Math
 \r
        __device__\r
        Rippling0Math(int w, int h)\r
+           : dim2(w / 2.0)\r
            {\r
-           // TODO\r
-           }\r
-\r
-       __device__\r
-       Rippling0Math(const Rippling0Math& source)\r
-           {\r
-           // TODO\r
            }\r
 \r
        /*--------------------------------------*\\r
@@ -46,33 +40,32 @@ class Rippling0Math
        __device__\r
        void color(int i, int j, float t, uchar4* ptrColor)\r
            {\r
-           // Debug (a mettre en commentaire)\r
-               {\r
-               unsigned char levelGris = 128; //in [0.255]  (debug image)\r
-               ptrColor->x = levelGris;\r
-               ptrColor->y = levelGris;\r
-               ptrColor->z = levelGris;\r
-               }\r
-\r
-           // Vrai problem\r
-               {\r
-               // TODO\r
-               }\r
-\r
-           //color.w = 255; // opaque\r
+           const double dxy10 = dxy(j, i) / 10.0;\r
+           const double grayLevelFloat = 128.0 + 127.0 * cos(dxy10 - 100.0 * t / 7.0) / (dxy10 + 1);\r
+           const uchar grayLevel = (uchar)(long(grayLevelFloat) % 256);\r
+\r
+           ptrColor->x = grayLevel;\r
+           ptrColor->y = grayLevel;\r
+           ptrColor->z = grayLevel;\r
            }\r
 \r
     private:\r
+       __device__\r
+       double dxy(int x, int y)\r
+           {\r
+           return sqrt(pow(x - this->dim2, 2.0) + pow(y - this->dim2, 2.0));\r
+           }\r
 \r
        /*--------------------------------------*\\r
        |*              Attributs               *|\r
         \*-------------------------------------*/\r
 \r
     private:\r
+       const double dim2;\r
 \r
     };\r
 \r
-#endif \r
+#endif\r
 \r
 /*----------------------------------------------------------------------*\\r
  |*                    End                                             *|\r