#ifndef RIPPLING_MATH_H_\r
#define RIPPLING_MATH_H_\r
\r
-#include <math.h>\r
+#include <cmath>\r
\r
/*----------------------------------------------------------------------*\\r
|* Declaration *|\r
class RipplingProvider\r
{\r
public:\r
-\r
static Rippling* createMOO(void);\r
static Image* createGL(void);\r
\r
--- /dev/null
+#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
--- /dev/null
+#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
--- /dev/null
+#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
--- /dev/null
+#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
--- /dev/null
+#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
--- /dev/null
+#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
#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
\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
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