Commencement du labo Mandelbrot et Julia.
authorgburri <gregory.burri@master.hes-so.ch>
Wed, 29 Oct 2014 22:47:30 +0000 (23:47 +0100)
committergburri <gregory.burri@master.hes-so.ch>
Wed, 29 Oct 2014 22:47:30 +0000 (23:47 +0100)
WCudaMSE/Student_Cuda_Image/src/cpp/core/01_Rippling/moo/device/math/RipplingMath.h
WCudaMSE/Student_Cuda_Image/src/cpp/core/01_Rippling/provider/RipplingProvider.h
WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/device/FractalDevice.cu [new file with mode: 0755]
WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/device/math/FractalMath.h [new file with mode: 0755]
WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/host/Fractal.cu [new file with mode: 0755]
WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/moo/host/Fractal.h [new file with mode: 0755]
WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/provider/FractalProvider.cpp [new file with mode: 0755]
WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/provider/FractalProvider.h [new file with mode: 0755]
WCudaMSE/Student_Cuda_Image/src/cpp/core/mainGL.cpp
WCudaMSE/Tuto_Image_Cuda/src/cpp/core/02_Damier_Zoomable/moo/host/Damier.cu

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