X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=WCudaMSE%2FStudent_Cuda_Image%2Fsrc%2Fcpp%2Fcore%2F02_Mandelbrot_Julia%2Fmoo%2Fdevice%2Fmath%2FFractalMath.h;h=aff0b79bbf091c27b8767adff00a477c17cb9ccd;hb=bd178531f80f8bc41c998d1c4588f9e18cc29389;hp=2bd56ae764275626b4edb2bb05b1b3e88ffe53e6;hpb=7798b7c27cf13aaeada22faae8648df8cb339f1b;p=GPU.git diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/device/math/FractalMath.h b/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/device/math/FractalMath.h index 2bd56ae..aff0b79 100755 --- a/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/device/math/FractalMath.h +++ b/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/device/math/FractalMath.h @@ -6,32 +6,20 @@ #include "CalibreurF.h" #include "ColorTools.h" -/*----------------------------------------------------------------------*\ - |* Declaration *| - \*---------------------------------------------------------------------*/ - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - class FractalMath { - - /*--------------------------------------*\ - |* Constructor *| - \*-------------------------------------*/ - public: - + /** + * n: le nombre maximum d'iterations afin de savoir si Zi diverge ou non. + */ __device__ FractalMath(int n) - : n(n), calibreur(IntervalF(-1, 1), IntervalF(0, 1)) + : n(n), calibreur(IntervalF(1, n), IntervalF(0, 1)) { } - /*--------------------------------------*\ - |* Methodes *| - \*-------------------------------------*/ + __device__ + virtual ~FractalMath() {} public: /** @@ -39,40 +27,115 @@ class FractalMath * y=pixelJ */ __device__ - void colorXY(uchar4* ptrColor, float x, float y, float t) + void colorXY(uchar4* ptrColor, float x, float y) const { - float z = f(x, y, t); - - calibreur.calibrer(z); - float hue01 = z; - - ColorTools::HSB_TO_RVB(hue01, ptrColor); // update color - - ptrColor->w = 255; // opaque + // Z courant. + float z_r, z_i; + this->initZ(z_r, z_i, x, y); + + int i = 0; + while (i < this->n) + { + i++; + + nextZ(z_r, z_i, x, y); + + if (isDivergent(z_r, z_i)) + break; + } + + if (i == this->n) + { + ptrColor->x = 0; + ptrColor->y = 0; + ptrColor->z = 0; + } + else + { + float s = static_cast(i); + this->calibreur.calibrer(s); + ColorTools::HSB_TO_RVB(s, ptrColor); + } } private: __device__ - float f(float x, float y,float t) + static bool isDivergent(float a, float b) { - return sin(x * n + t) * cos(y * n + t); + return pow(a, 2) + pow(b, 2) > 4; } + __device__ + virtual void initZ(float& z_r, float& z_i, float x, float y) const = 0; - /*--------------------------------------*\ - |* Attributs *| - \*-------------------------------------*/ + __device__ + virtual void nextZ(float& z_r, float& z_i, float x, float y) const = 0; private: - // Input int n; - - // Tools CalibreurF calibreur; }; -#endif +class FractalMandelbrotMath : public FractalMath + { + public: + /** + * n: le nombre maximum d'iterations afin de savoir si Zi diverge ou non. + */ + __device__ + FractalMandelbrotMath(int n) + : FractalMath(n) + { + } -/*----------------------------------------------------------------------*\ - |* End *| - \*---------------------------------------------------------------------*/ + private: + __device__ + void initZ(float& z_r, float& z_i, float, float) const + { + z_r = 0.0; + z_i = 0.0; + } + + __device__ + void nextZ(float& z_r, float& z_i, float x, float y) const + { + // Z^2 + (x, iy) : + float z_r_tmp = pow(z_r, 2) - pow(z_i, 2); + z_i = 2 * z_r * z_i + y; + z_r = z_r_tmp + x; + } + }; + +class FractalJuliaMath : public FractalMath + { + public: + /** + * n: le nombre maximum d'iterations afin de savoir si Zi diverge ou non. + */ + __device__ + FractalJuliaMath(int n, float c_r, float c_i) + : FractalMath(n), c_r(c_r), c_i(c_i) + { + } + + private: + __device__ + void initZ(float& z_r, float& z_i, float x, float y) const + { + z_r = x; + z_i = y; + } + + __device__ + void nextZ(float& z_r, float& z_i, float, float) const + { + // Z^2 + C : + float z_r_tmp = pow(z_r, 2) - pow(z_i, 2); + z_i = 2 * z_r * z_i + this->c_i; + z_r = z_r_tmp + this->c_r; + } + + float c_r, c_i; + }; + +#endif