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