From 7798b7c27cf13aaeada22faae8648df8cb339f1b Mon Sep 17 00:00:00 2001 From: gburri Date: Wed, 29 Oct 2014 23:47:30 +0100 Subject: [PATCH] Commencement du labo Mandelbrot et Julia. --- .../moo/device/math/RipplingMath.h | 2 +- .../01_Rippling/provider/RipplingProvider.h | 1 - .../moo/device/FractalDevice.cu | 78 +++++++++++ .../moo/device/math/FractalMath.h | 78 +++++++++++ .../02_Mandelbrot_Julia/moo/host/Fractal.cu | 129 ++++++++++++++++++ .../02_Mandelbrot_Julia/moo/host/Fractal.h | 44 ++++++ .../provider/FractalProvider.cpp | 55 ++++++++ .../provider/FractalProvider.h | 27 ++++ .../src/cpp/core/mainGL.cpp | 22 +-- .../02_Damier_Zoomable/moo/host/Damier.cu | 2 +- 10 files changed, 427 insertions(+), 11 deletions(-) create mode 100755 WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/device/FractalDevice.cu create mode 100755 WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/device/math/FractalMath.h create mode 100755 WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/host/Fractal.cu create mode 100755 WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/host/Fractal.h create mode 100755 WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/provider/FractalProvider.cpp create mode 100755 WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/provider/FractalProvider.h diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/01_Rippling/moo/device/math/RipplingMath.h b/WCudaMSE/Student_Cuda_Image/src/cpp/core/01_Rippling/moo/device/math/RipplingMath.h index e90a060..af60ac2 100755 --- a/WCudaMSE/Student_Cuda_Image/src/cpp/core/01_Rippling/moo/device/math/RipplingMath.h +++ b/WCudaMSE/Student_Cuda_Image/src/cpp/core/01_Rippling/moo/device/math/RipplingMath.h @@ -1,7 +1,7 @@ #ifndef RIPPLING_MATH_H_ #define RIPPLING_MATH_H_ -#include +#include /*----------------------------------------------------------------------*\ |* Declaration *| diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/01_Rippling/provider/RipplingProvider.h b/WCudaMSE/Student_Cuda_Image/src/cpp/core/01_Rippling/provider/RipplingProvider.h index 7774169..2cda92d 100755 --- a/WCudaMSE/Student_Cuda_Image/src/cpp/core/01_Rippling/provider/RipplingProvider.h +++ b/WCudaMSE/Student_Cuda_Image/src/cpp/core/01_Rippling/provider/RipplingProvider.h @@ -15,7 +15,6 @@ class RipplingProvider { public: - static Rippling* createMOO(void); static Image* createGL(void); diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/device/FractalDevice.cu b/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/device/FractalDevice.cu new file mode 100755 index 0000000..8281489 --- /dev/null +++ b/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/device/FractalDevice.cu @@ -0,0 +1,78 @@ +#include + +#include "Indice2D.h" +#include "IndiceTools.h" +#include "DomaineMath.h" +#include "cudaTools.h" +#include "Device.h" + +#include "FractalMath.h" + +using std::cout; +using std::endl; + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Imported *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +__global__ void fractal(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n, float t); + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +__global__ void fractal(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n, float t) + { + FractalMath fractalMath(n); + + const int TID = Indice2D::tid(); + const int NB_THREAD = Indice2D::nbThread(); + const int WH = w * h; + + uchar4 color; + color.z = 255; // Par défaut, l'image est opaque. + + double x, y; + int pixelI, pixelJ; + + int s = TID; + while (s < WH) + { + IndiceTools::toIJ(s, w, &pixelI, &pixelJ); // update (pixelI, pixelJ) + + // (i,j) domaine ecran + // (x,y) domaine math + domaineMath.toXY(pixelI, pixelJ, &x, &y); // (i,j) -> (x,y) + + fractalMath.colorXY(&color,x, y, t); // update color + + ptrDevPixels[s] = color; + + s += NB_THREAD; + } + } + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ + 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 new file mode 100755 index 0000000..2bd56ae --- /dev/null +++ b/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/device/math/FractalMath.h @@ -0,0 +1,78 @@ +#ifndef FRACTAL_MATH_H_ +#define FRACTAL_MATH_H_ + +#include + +#include "CalibreurF.h" +#include "ColorTools.h" + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +class FractalMath + { + + /*--------------------------------------*\ + |* Constructor *| + \*-------------------------------------*/ + + public: + + __device__ + FractalMath(int n) + : n(n), calibreur(IntervalF(-1, 1), IntervalF(0, 1)) + { + } + + /*--------------------------------------*\ + |* Methodes *| + \*-------------------------------------*/ + + public: + /** + * x=pixelI + * y=pixelJ + */ + __device__ + void colorXY(uchar4* ptrColor, float x, float y, float t) + { + float z = f(x, y, t); + + calibreur.calibrer(z); + float hue01 = z; + + ColorTools::HSB_TO_RVB(hue01, ptrColor); // update color + + ptrColor->w = 255; // opaque + } + + private: + __device__ + float f(float x, float y,float t) + { + return sin(x * n + t) * cos(y * n + t); + } + + + /*--------------------------------------*\ + |* Attributs *| + \*-------------------------------------*/ + + private: + // Input + int n; + + // Tools + CalibreurF calibreur; + }; + +#endif + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/host/Fractal.cu b/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/host/Fractal.cu new file mode 100755 index 0000000..a92b86b --- /dev/null +++ b/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/host/Fractal.cu @@ -0,0 +1,129 @@ +#include +#include + +#include "Fractal.h" +#include "Device.h" + +using std::cout; +using std::endl; + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Imported *| + \*-------------------------------------*/ + +extern __global__ void fractal(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n, float t); + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/*-------------------------*\ + |* Constructeur *| + \*-------------------------*/ + +Fractal::Fractal(int w, int h, float dt, int n) + : w(w), h(h), n(n), + dg(8, 8, 1), + db(16, 16, 1), + t(0), + variateurAnimation(IntervalF(0, 2 * PI), dt), + ptrDomaineMathInit(new DomaineMath(-2, -1.3, 0.8, 1.3)), + title("Fractal Cuda") + { + assert(w == h); + + //print(dg, db); + Device::assertDim(dg, db); + } + +Fractal::~Fractal() + { + delete this->ptrDomaineMathInit; + } + +/*-------------------------*\ + |* Methode *| + \*-------------------------*/ + +/** + * Override + */ +void Fractal::runGPU(uchar4* ptrDevPixels, const DomaineMath& domaineMath) + { + fractal<<>>(ptrDevPixels, this->w, this->h, domaineMath, this->n, this->t); + } + +/** + * Override + */ +void Fractal::animationStep() + { + this->t = this->variateurAnimation.varierAndGet(); + } + +/*--------------*\ + |* get *| + \*--------------*/ + + +/** + * Override + */ +int Fractal::getW() + { + return this->w; + } + +/** + * Override + */ +int Fractal::getH() + { + return this->h; + } + +DomaineMath* Fractal::getDomaineMathInit() + { + return this->ptrDomaineMathInit; + } + +/** + * Override + */ +float Fractal::getT() + { + return this->t; + } + +/** + * Override + */ +string Fractal::getTitle() + { + return this->title; + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ + diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/host/Fractal.h b/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/host/Fractal.h new file mode 100755 index 0000000..4dbfe65 --- /dev/null +++ b/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/host/Fractal.h @@ -0,0 +1,44 @@ +#ifndef FRACTAL_H_ +#define FRACTAL_H_ + +#include "cudaTools.h" +#include "AnimableFonctionel_I.h" +#include "MathTools.h" +#include "VariateurF.h" + +class Fractal : public AnimableFonctionel_I + { + public: + Fractal(int w, int h, float dt, int n); + virtual ~Fractal(void); + + public: + void runGPU(uchar4* ptrDevPixels, const DomaineMath& domaineMath) /*override*/; + void animationStep() /*override*/; + + int getW() /*override*/; + int getH() /*override*/; + DomaineMath* getDomaineMathInit() /*override*/; + + float getT() /*override*/; + string getTitle(void) /*override*/; + + private: + // Inputs + const int w; + const int h; + int n; + + // Tools + const dim3 dg; + const dim3 db; + float t; + + VariateurF variateurAnimation; + DomaineMath* ptrDomaineMathInit; + + // Outputs + const string title; + }; + +#endif diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/provider/FractalProvider.cpp b/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/provider/FractalProvider.cpp new file mode 100755 index 0000000..9a824a2 --- /dev/null +++ b/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/provider/FractalProvider.cpp @@ -0,0 +1,55 @@ +#include "FractalProvider.h" + + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Imported *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/*-----------------*\ + |* static *| + \*----------------*/ + +Fractal* FractalProvider::create() + { + int dw = 16 * 30; + int dh = 16 * 30; + + float dt = 2 * PI / 8000; + int n = 2; + + return new Fractal(dw, dh, dt, n); + } + +ImageFonctionel* FractalProvider::createGL() + { + ColorRGB_01* ptrColorTitre = new ColorRGB_01(0, 0, 0); + return new ImageFonctionel(create(), ptrColorTitre); // both ptr destroy by destructor of ImageFonctionel + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/provider/FractalProvider.h b/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/provider/FractalProvider.h new file mode 100755 index 0000000..b749235 --- /dev/null +++ b/WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/provider/FractalProvider.h @@ -0,0 +1,27 @@ +#ifndef FRACTAL_PROVIDER_H_ +#define FRACTAL_PROVIDER_H_ + +#include "Fractal.h" +#include "ImageFonctionel.h" + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +class FractalProvider + { + public: + static Fractal* create(void); + static ImageFonctionel* createGL(void); + }; + +#endif + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ + diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/mainGL.cpp b/WCudaMSE/Student_Cuda_Image/src/cpp/core/mainGL.cpp index 4b6a217..c853716 100755 --- a/WCudaMSE/Student_Cuda_Image/src/cpp/core/mainGL.cpp +++ b/WCudaMSE/Student_Cuda_Image/src/cpp/core/mainGL.cpp @@ -10,6 +10,8 @@ #include "Rippling0Provider.h" #include "RipplingProvider.h" +#include "FractalProvider.h" + using std::cout; using std::endl; using std::string; @@ -42,22 +44,26 @@ int mainGL(void); int mainGL(void) { - Rippling0Image* ptrRippling0 = Rippling0Provider::createGL(); - Image* ptrRippling = RipplingProvider::createGL(); - // TODO : Insert autres Images ... + //Rippling0Image* ptrRippling0 = Rippling0Provider::createGL(); + //Image* ptrRippling = RipplingProvider::createGL(); + + ImageFonctionel* ptrFractalMandelbrot = FractalProvider::createGL(); const bool isAnimation = true; const bool isSelection = true; - GLUTImageViewers rippling0Viewer(ptrRippling0, isAnimation, isSelection, 0, 0); - GLUTImageViewers ripplingViewer(ptrRippling, isAnimation, isSelection, 10, 10); - // TODO : Insert here autres ImageViewers ... + //GLUTImageViewers rippling0Viewer(ptrRippling0, isAnimation, isSelection, 0, 0); + //GLUTImageViewers ripplingViewer(ptrRippling, isAnimation, isSelection, 10, 10); + + GLUTImageViewers fractalMandelbrotViewer(ptrFractalMandelbrot, true, true, 20, 20); GLUTImageViewers::runALL(); // Bloquant, Tant qu'une fenetre est ouverte // destruction - delete ptrRippling0; - delete ptrRippling; + //delete ptrRippling0; + //delete ptrRippling; + + delete ptrFractalMandelbrot; return EXIT_SUCCESS; } diff --git a/WCudaMSE/Tuto_Image_Cuda/src/cpp/core/02_Damier_Zoomable/moo/host/Damier.cu b/WCudaMSE/Tuto_Image_Cuda/src/cpp/core/02_Damier_Zoomable/moo/host/Damier.cu index 52ba530..32970d6 100755 --- a/WCudaMSE/Tuto_Image_Cuda/src/cpp/core/02_Damier_Zoomable/moo/host/Damier.cu +++ b/WCudaMSE/Tuto_Image_Cuda/src/cpp/core/02_Damier_Zoomable/moo/host/Damier.cu @@ -46,7 +46,7 @@ Damier::Damier(int w, int h, float dt, int n) : this->dg = dim3(8, 8, 1); // disons a optimiser this->db = dim3(16, 16, 1); // disons a optimiser this->t = 0; - ptrDomaineMathInit=new DomaineMath(0,0,2*PI,2*PI); + ptrDomaineMathInit= new DomaineMath(0,0,2*PI,2*PI); //Outputs this->title = "[API Image Fonctionelle] : Damier zoomable CUDA"; -- 2.43.0