Ajout du squelette de Newton.
authorgburri <gregory.burri@master.hes-so.ch>
Thu, 13 Nov 2014 09:21:00 +0000 (10:21 +0100)
committergburri <gregory.burri@master.hes-so.ch>
Thu, 13 Nov 2014 09:21:00 +0000 (10:21 +0100)
WCudaMSE/BilatTools_Cuda_Image/src/core/cudaImageTools/fonctionel/header/AnimableFonctionel_I.h
WCudaMSE/Student_Cuda_Image/src/cpp/core/02_Mandelbrot_Julia/provider/FractalProvider.cpp
WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/moo/device/NewtonDevice.cu [new file with mode: 0755]
WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/moo/device/math/NewtonMath.h [new file with mode: 0755]
WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/moo/host/Newton.cu [new file with mode: 0755]
WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/moo/host/Newton.h [new file with mode: 0755]
WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/provider/NewtonProvider.cpp [new file with mode: 0755]
WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/provider/NewtonProvider.h [new file with mode: 0755]
WCudaMSE/Student_Cuda_Image/src/cpp/core/mainGL.cpp

index 6fb67ce..098790d 100755 (executable)
@@ -21,8 +21,7 @@ using std::string;
 class AnimableFonctionel_I\r
     {\r
     public:\r
-\r
-       //virtual ~Animable_I(void)=0;\r
+        virtual ~AnimableFonctionel_I() {}\r
 \r
        virtual void runGPU(uchar4* ptrDevPixels,const DomaineMath& domaineMath)=0;\r
        virtual void animationStep(void)=0;\r
index 125225d..47df25e 100755 (executable)
@@ -37,7 +37,6 @@ Fractal* FractalProvider::createMandelbrot()
     return new FractalMandelbrot(dw, dh, 0.2);\r
     }\r
 \r
-\r
 Fractal* FractalProvider::createJulia()\r
     {\r
     int dw = 16 * 50;\r
diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/moo/device/NewtonDevice.cu b/WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/moo/device/NewtonDevice.cu
new file mode 100755 (executable)
index 0000000..536b75b
--- /dev/null
@@ -0,0 +1,43 @@
+#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 "NewtonMath.h"\r
+\r
+using std::cout;\r
+using std::endl;\r
+\r
+__global__ void newton(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath)\r
+    {\r
+    const int TID = Indice2D::tid();\r
+    const int NB_THREAD = Indice2D::nbThread();\r
+    const int WH = w * h;\r
+\r
+    NewtonMath newtonMath;\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
+        newtonMath.colorXY(&color, x, y);\r
+\r
+        ptrDevPixels[s] = color;\r
+\r
+        s += NB_THREAD;\r
+        }\r
+    }\r
diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/moo/device/math/NewtonMath.h b/WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/moo/device/math/NewtonMath.h
new file mode 100755 (executable)
index 0000000..5edf6ee
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef NEWTON_MATH_H_\r
+#define NEWTON_MATH_H_\r
+\r
+#include <cmath>\r
+\r
+#include "CalibreurF.h"\r
+#include "ColorTools.h"\r
+\r
+class NewtonMath\r
+    {\r
+    public:\r
+       __device__\r
+       NewtonMath()\r
+           : calibreur(IntervalF(1, 100), IntervalF(0, 1))\r
+           {\r
+           }\r
+\r
+       __device__\r
+       virtual ~NewtonMath() {}\r
+\r
+    public:\r
+       /**\r
+        * x=pixelI\r
+        * y=pixelJ\r
+        */\r
+       __device__\r
+       void colorXY(uchar4* ptrColor, float x, float y) const\r
+           {\r
+            ptrColor->x = 0;\r
+            ptrColor->y = 0;\r
+            ptrColor->z = 0;\r
+\r
+            int i = 0;\r
+            float s = static_cast<float>(i);\r
+            this->calibreur.calibrer(s);\r
+            ColorTools::HSB_TO_RVB(s, ptrColor);\r
+           }\r
+\r
+    private:\r
+\r
+    private:\r
+       CalibreurF calibreur;\r
+    };\r
+\r
+#endif\r
diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/moo/host/Newton.cu b/WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/moo/host/Newton.cu
new file mode 100755 (executable)
index 0000000..028f924
--- /dev/null
@@ -0,0 +1,62 @@
+#include <iostream>\r
+#include <assert.h>\r
+\r
+#include "Newton.h"\r
+#include "Device.h"\r
+\r
+using std::cout;\r
+using std::endl;\r
+\r
+extern __global__ void newton(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath);\r
+\r
+Newton::Newton(int w, int h)\r
+    : variateurAnimation(IntervalF(30, 100), 1),\r
+      w(w), h(h),\r
+      dg(8, 8, 1),\r
+      db(16, 16, 1),\r
+      title("Fractal Newton")\r
+    {\r
+    //print(dg, db);\r
+    Device::assertDim(dg, db);\r
+    }\r
+\r
+Newton::~Newton()\r
+    {\r
+    delete this->ptrDomaineMathInit;\r
+    }\r
+\r
+void Newton::runGPU(uchar4* ptrDevPixels, const DomaineMath& domaineMath)\r
+    {\r
+    newton<<<dg,db>>>(ptrDevPixels, this->w, this->h, domaineMath);\r
+    }\r
+\r
+void Newton::animationStep()\r
+    {\r
+    this->t = this->variateurAnimation.varierAndGet();\r
+    }\r
+\r
+int Newton::getW()\r
+    {\r
+    return this->w;\r
+    }\r
+\r
+int Newton::getH()\r
+    {\r
+    return this->h;\r
+    }\r
+\r
+DomaineMath* Newton::getDomaineMathInit()\r
+    {\r
+    return this->ptrDomaineMathInit;\r
+    }\r
+\r
+float Newton::getT()\r
+    {\r
+    return 0;\r
+    }\r
+\r
+string Newton::getTitle()\r
+    {\r
+    return this->title;\r
+    }\r
+\r
diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/moo/host/Newton.h b/WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/moo/host/Newton.h
new file mode 100755 (executable)
index 0000000..ad86979
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef NEWTON_H_\r
+#define NEWTON_H_\r
+\r
+#include "cudaTools.h"\r
+#include "AnimableFonctionel_I.h"\r
+#include "MathTools.h"\r
+#include "VariateurF.h"\r
+\r
+class Newton : public AnimableFonctionel_I\r
+    {\r
+    public:\r
+        Newton(int w, int h);\r
+        ~Newton();\r
+\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
+\r
+        string getTitle(void) /*override*/;\r
+\r
+    private:\r
+        VariateurF variateurAnimation;\r
+        float t;\r
+\r
+        // Inputs\r
+        const int w;\r
+        const int h;\r
+\r
+        const dim3 dg;\r
+        const dim3 db;\r
+\r
+        DomaineMath* ptrDomaineMathInit;\r
+\r
+        const string title;\r
+    };\r
+\r
+#endif\r
diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/provider/NewtonProvider.cpp b/WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/provider/NewtonProvider.cpp
new file mode 100755 (executable)
index 0000000..3a0637f
--- /dev/null
@@ -0,0 +1,15 @@
+#include "NewtonProvider.h"\r
+\r
+Newton* NewtonProvider::create()\r
+    {\r
+    int dw = 16 * 50;\r
+    int dh = 16 * 30;\r
+\r
+    return new Newton(dw, dh);\r
+    }\r
+\r
+ImageFonctionel* NewtonProvider::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
diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/provider/NewtonProvider.h b/WCudaMSE/Student_Cuda_Image/src/cpp/core/03_Newton/provider/NewtonProvider.h
new file mode 100755 (executable)
index 0000000..06d19e1
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef NEWTON_PROVIDER_H_\r
+#define NEWTON_PROVIDER_H_\r
+\r
+#include "Newton.h"\r
+#include "ImageFonctionel.h"\r
+\r
+class NewtonProvider\r
+    {\r
+    public:\r
+       static Newton* create();\r
+       static ImageFonctionel* createGL();\r
+    };\r
+\r
+#endif\r
index 97952e7..f71dc78 100755 (executable)
@@ -47,7 +47,7 @@ int mainGL(void)
     //Rippling0Image* ptrRippling0 = Rippling0Provider::createGL();\r
     //Image* ptrRippling = RipplingProvider::createGL();\r
     //ImageFonctionel* ptrFractalMandelbrot = FractalProvider::createMandelbrotGL();\r
-    ImageFonctionel* ptrFractalJulia = FractalProvider::createJuliaGL();\r
+    //ImageFonctionel* ptrFractalJulia = FractalProvider::createJuliaGL();\r
 \r
     const bool isAnimation = true;\r
     const bool isSelection = true;\r
@@ -55,7 +55,7 @@ int mainGL(void)
     //GLUTImageViewers rippling0Viewer(ptrRippling0, isAnimation, isSelection, 0, 0);\r
     //GLUTImageViewers ripplingViewer(ptrRippling, isAnimation, isSelection, 10, 10);\r
     //GLUTImageViewers fractalMandelbrotViewer(ptrFractalMandelbrot, true, true, 20, 20);\r
-    GLUTImageViewers fractalJuliaViewer(ptrFractalJulia, true, true, 20, 20);\r
+    //GLUTImageViewers fractalJuliaViewer(ptrFractalJulia, true, true, 20, 20);\r
 \r
     GLUTImageViewers::runALL(); // Bloquant, Tant qu'une fenetre est ouverte\r
 \r