include ${ROOT_MAKEFILE_PRIVATE_COMMON}/commonLinux.mk\r
\r
include ${ROOT_MAKEFILE_PUBLIC_CUDA}/cudaGCC.mk\r
-#include cudaGCC.mk\r
+-include cudaLinux.mk\r
\r
include ${ROOT_MAKEFILE_PRIVATE_CUDA}/makeCudaGCC.mk\r
\r
\r
public:\r
\r
- void calibrer(float& value)\r
+ void calibrer(float& value) const\r
{\r
value = value * pente + translation;\r
}\r
\r
- float getPente()\r
+ float getPente() const\r
{\r
return this->pente;\r
}\r
\r
- float getTranslation()\r
+ float getTranslation() const\r
{\r
return this->translation;\r
}\r
public:\r
\r
__BOTH__\r
- void calibrer(float& value)\r
+ void calibrer(float& value) const\r
{\r
value = value * pente + translation;\r
}\r
\r
__BOTH__\r
- float getPente()\r
+ float getPente() const\r
{\r
return this->pente;\r
}\r
\r
__BOTH__\r
- float getTranslation()\r
+ float getTranslation() const\r
{\r
return this->translation;\r
}\r
#\r
# Notes\r
#\r
-# (N1) Les options de compilation sont souvent les memes d'un projet à l'autre.\r
-# Ces options communes à tout le workspace se trouve daan la partie public du projet BUILDER.\r
+# (N1) Les options de compilation sont souvent les memes d'un projet � l'autre.\r
+# Ces options communes � tout le workspace se trouve daan la partie public du projet BUILDER.\r
# \r
-# (N2) Vous pouvez redefinir ou surcharger ces options dans ce present .mk pour customizer un projet spécifique.\r
+# (N2) Vous pouvez redefinir ou surcharger ces options dans ce present .mk pour customizer un projet sp�cifique.\r
#\r
# (N3) Pour modifier la configuration de tous vos projets, modifier directement les .mk generiques dans le BUILDER\r
#\r
# nvcc #\r
#########\r
\r
-#NVCCFLAGS+= --ptxas-options=-v\r
+NVCCFLAGS+= --ptxas-options=-v\r
NVCCLDFLAGS+=\r
\r
#########\r
|* Public *|\r
\*-------------------------------------*/\r
\r
-__global__ void fractal(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n, float t);\r
+__global__ void fractalMandelbrot(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n);\r
+__global__ void fractalJulia(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n, float c_r, float c_i);\r
+__device__ void fractal(uchar4* ptrDevPixels, int w, int h, const DomaineMath& domaineMath, int n, const FractalMath& fractalMath);\r
\r
/*--------------------------------------*\\r
|* Private *|\r
|* Private *|\r
\*-------------------------------------*/\r
\r
-__global__ void fractal(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n, float t)\r
+\r
+__global__ void fractalMandelbrot(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n)\r
+ {\r
+ FractalMandelbrotMath fractalMath(n);\r
+ fractal(ptrDevPixels, w, h, domaineMath, n, fractalMath);\r
+ }\r
+\r
+__global__ void fractalJulia(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n, float c_r, float c_i)\r
{\r
- FractalMath fractalMath(n);\r
+ FractalJuliaMath fractalMath(n, c_r, c_i);\r
+ fractal(ptrDevPixels, w, h, domaineMath, n, fractalMath);\r
+ }\r
\r
+__device__ void fractal(uchar4* ptrDevPixels, int w, int h, const DomaineMath& domaineMath, int n, const FractalMath& fractalMath)\r
+ {\r
const int TID = Indice2D::tid();\r
const int NB_THREAD = Indice2D::nbThread();\r
const int WH = w * h;\r
\r
int s = TID;\r
while (s < WH)\r
- {\r
- IndiceTools::toIJ(s, w, &pixelI, &pixelJ); // update (pixelI, pixelJ)\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
+ // (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
+ fractalMath.colorXY(&color, x, y);\r
\r
- ptrDevPixels[s] = color;\r
+ ptrDevPixels[s] = color;\r
\r
- s += NB_THREAD;\r
- }\r
+ s += NB_THREAD;\r
+ }\r
}\r
\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
+ /**\r
+ * n: le nombre maximum d'iterations afin de savoir si Zi diverge ou non.\r
+ */\r
__device__\r
FractalMath(int n)\r
- : n(n), calibreur(IntervalF(-1, 1), IntervalF(0, 1))\r
+ : n(n), calibreur(IntervalF(1, n), IntervalF(0, 1))\r
{\r
}\r
\r
- /*--------------------------------------*\\r
- |* Methodes *|\r
- \*-------------------------------------*/\r
+ __device__\r
+ virtual ~FractalMath() {}\r
\r
public:\r
/**\r
* y=pixelJ\r
*/\r
__device__\r
- void colorXY(uchar4* ptrColor, float x, float y, float t)\r
+ void colorXY(uchar4* ptrColor, float x, float y) const\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
+ // Z courant.\r
+ float z_r, z_i;\r
+ this->initZ(z_r, z_i, x, y);\r
+\r
+ int i = 0;\r
+ while (i < this->n)\r
+ {\r
+ i++;\r
+\r
+ nextZ(z_r, z_i, x, y);\r
+\r
+ if (isDivergent(z_r, z_i))\r
+ break;\r
+ }\r
+\r
+ if (i == this->n)\r
+ {\r
+ ptrColor->x = 0;\r
+ ptrColor->y = 0;\r
+ ptrColor->z = 0;\r
+ }\r
+ else\r
+ {\r
+ float s = static_cast<float>(i);\r
+ this->calibreur.calibrer(s);\r
+ ColorTools::HSB_TO_RVB(s, ptrColor);\r
+ }\r
}\r
\r
private:\r
__device__\r
- float f(float x, float y,float t)\r
+ static bool isDivergent(float a, float b)\r
{\r
- return sin(x * n + t) * cos(y * n + t);\r
+ return pow(a, 2) + pow(b, 2) > 4;\r
}\r
\r
+ __device__\r
+ virtual void initZ(float& z_r, float& z_i, float x, float y) const = 0;\r
\r
- /*--------------------------------------*\\r
- |* Attributs *|\r
- \*-------------------------------------*/\r
+ __device__\r
+ virtual void nextZ(float& z_r, float& z_i, float x, float y) const = 0;\r
\r
private:\r
- // Input\r
int n;\r
-\r
- // Tools\r
CalibreurF calibreur;\r
};\r
\r
-#endif\r
+class FractalMandelbrotMath : public FractalMath\r
+ {\r
+ public:\r
+ /**\r
+ * n: le nombre maximum d'iterations afin de savoir si Zi diverge ou non.\r
+ */\r
+ __device__\r
+ FractalMandelbrotMath(int n)\r
+ : FractalMath(n)\r
+ {\r
+ }\r
\r
-/*----------------------------------------------------------------------*\\r
- |* End *|\r
- \*---------------------------------------------------------------------*/\r
+ private:\r
+ __device__\r
+ void initZ(float& z_r, float& z_i, float, float) const\r
+ {\r
+ z_r = 0.0;\r
+ z_i = 0.0;\r
+ }\r
+\r
+ __device__\r
+ void nextZ(float& z_r, float& z_i, float x, float y) const\r
+ {\r
+ // Z^2 + (x, iy) :\r
+ float z_r_tmp = pow(z_r, 2) - pow(z_i, 2);\r
+ z_i = 2 * z_r * z_i + y;\r
+ z_r = z_r_tmp + x;\r
+ }\r
+ };\r
+\r
+class FractalJuliaMath : public FractalMath\r
+ {\r
+ public:\r
+ /**\r
+ * n: le nombre maximum d'iterations afin de savoir si Zi diverge ou non.\r
+ */\r
+ __device__\r
+ FractalJuliaMath(int n, float c_r, float c_i)\r
+ : FractalMath(n), c_r(c_r), c_i(c_i)\r
+ {\r
+ }\r
+\r
+ private:\r
+ __device__\r
+ void initZ(float& z_r, float& z_i, float x, float y) const\r
+ {\r
+ z_r = x;\r
+ z_i = y;\r
+ }\r
+\r
+ __device__\r
+ void nextZ(float& z_r, float& z_i, float, float) const\r
+ {\r
+ // Z^2 + C :\r
+ float z_r_tmp = pow(z_r, 2) - pow(z_i, 2);\r
+ z_i = 2 * z_r * z_i + this->c_i;\r
+ z_r = z_r_tmp + this->c_r;\r
+ }\r
+\r
+ float c_r, c_i;\r
+ };\r
+\r
+#endif\r
using std::cout;\r
using std::endl;\r
\r
-/*----------------------------------------------------------------------*\\r
- |* Declaration *|\r
- \*---------------------------------------------------------------------*/\r
+extern __global__ void fractalMandelbrot(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n);\r
+extern __global__ void fractalJulia(uchar4* ptrDevPixels, int w, int h, DomaineMath domaineMath, int n, float c_r, float c_i);\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
+Fractal::Fractal(int w, int h)\r
+ : w(w), h(h),\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
delete this->ptrDomaineMathInit;\r
}\r
\r
-/*-------------------------*\\r
- |* Methode *|\r
- \*-------------------------*/\r
-\r
/**\r
* Override\r
*/\r
-void Fractal::runGPU(uchar4* ptrDevPixels, const DomaineMath& domaineMath)\r
+int Fractal::getW()\r
{\r
- fractal<<<dg,db>>>(ptrDevPixels, this->w, this->h, domaineMath, this->n, this->t);\r
+ return this->w;\r
}\r
\r
/**\r
* Override\r
*/\r
-void Fractal::animationStep()\r
+int Fractal::getH()\r
{\r
- this->t = this->variateurAnimation.varierAndGet();\r
+ return this->h;\r
}\r
\r
-/*--------------*\\r
- |* get *|\r
- \*--------------*/\r
-\r
+DomaineMath* Fractal::getDomaineMathInit()\r
+ {\r
+ return this->ptrDomaineMathInit;\r
+ }\r
\r
/**\r
* Override\r
*/\r
-int Fractal::getW()\r
+string Fractal::getTitle()\r
{\r
- return this->w;\r
+ return this->title;\r
}\r
\r
-/**\r
- * Override\r
- */\r
-int Fractal::getH()\r
+/////\r
+\r
+FractalMandelbrot::FractalMandelbrot(int w, int h, float dn)\r
+ : Fractal(w, h), variateurAnimationN(IntervalF(30, 100), dn)\r
{\r
- return this->h;\r
+ this->ptrDomaineMathInit = new DomaineMath(-2, -1.3, 0.8, 1.3);\r
}\r
\r
-DomaineMath* Fractal::getDomaineMathInit()\r
+void FractalMandelbrot::animationStep()\r
{\r
- return this->ptrDomaineMathInit;\r
+ this->n = this->variateurAnimationN.varierAndGet();\r
}\r
\r
-/**\r
- * Override\r
- */\r
-float Fractal::getT()\r
+float FractalMandelbrot::getT()\r
{\r
- return this->t;\r
+ return this->n;\r
}\r
\r
-/**\r
- * Override\r
- */\r
-string Fractal::getTitle()\r
+void FractalMandelbrot::runGPU(uchar4* ptrDevPixels, const DomaineMath& domaineMath)\r
{\r
- return this->title;\r
+ fractalMandelbrot<<<dg,db>>>(ptrDevPixels, this->w, this->h, domaineMath, static_cast<int>(this->n));\r
+ }\r
+\r
+/////\r
+\r
+FractalJulia::FractalJulia(int w, int h, float dn, float z_r_min, float z_r_max, float z_i_min, float z_i_max)\r
+ : Fractal(w, h), z_r(z_r_min), z_i(z_i_min), variateurAnimationR(IntervalF(-0.8, -0.7), 0.0005), variateurAnimationI(IntervalF(-0.3, 0.3/*0.15*/), 0.0004)\r
+ {\r
+ this->ptrDomaineMathInit = new DomaineMath(-1.7, -1.4, 1.7, 1.4);\r
+ }\r
+\r
+void FractalJulia::animationStep()\r
+ {\r
+ this->z_r = this->variateurAnimationR.varierAndGet();\r
+ this->z_i = this->variateurAnimationI.varierAndGet();\r
}\r
\r
-/*--------------------------------------*\\r
- |* Private *|\r
- \*-------------------------------------*/\r
+float FractalJulia::getT()\r
+ {\r
+ return this->z_r;\r
+ }\r
\r
-/*----------------------------------------------------------------------*\\r
- |* End *|\r
- \*---------------------------------------------------------------------*/\r
+void FractalJulia::runGPU(uchar4* ptrDevPixels, const DomaineMath& domaineMath)\r
+ {\r
+ fractalJulia<<<dg,db>>>(ptrDevPixels, this->w, this->h, domaineMath, 300, this->z_r, this->z_i);\r
+ }\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
+ Fractal(int w, int h);\r
+ virtual ~Fractal();\r
\r
public:\r
- void runGPU(uchar4* ptrDevPixels, const DomaineMath& domaineMath) /*override*/;\r
- void animationStep() /*override*/;\r
+ int getW() /*override*/;\r
+ int getH() /*override*/;\r
+ DomaineMath* getDomaineMathInit() /*override*/;\r
\r
- int getW() /*override*/;\r
- int getH() /*override*/;\r
- DomaineMath* getDomaineMathInit() /*override*/;\r
+ string getTitle(void) /*override*/;\r
\r
- float getT() /*override*/;\r
- string getTitle(void) /*override*/;\r
+ protected:\r
+ // Inputs\r
+ const int w;\r
+ const int h;\r
+\r
+ // Tools\r
+ const dim3 dg;\r
+ const dim3 db;\r
+\r
+ DomaineMath* ptrDomaineMathInit;\r
+\r
+ // Outputs\r
+ const string title;\r
+ };\r
+\r
+class FractalMandelbrot : public Fractal\r
+ {\r
+ public:\r
+ FractalMandelbrot(int w, int h, float dn);\r
+ void animationStep();\r
+ float getT() /*override*/;\r
\r
private:\r
- // Inputs\r
- const int w;\r
- const int h;\r
- int n;\r
+ void runGPU(uchar4* ptrDevPixels, const DomaineMath& domaineMath) /*override*/;\r
\r
- // Tools\r
- const dim3 dg;\r
- const dim3 db;\r
- float t;\r
+ VariateurF variateurAnimationN;\r
\r
- VariateurF variateurAnimation;\r
- DomaineMath* ptrDomaineMathInit;\r
+ float n;\r
+ };\r
+\r
+class FractalJulia : public Fractal\r
+ {\r
+ public:\r
+ FractalJulia(int w, int h, float dn, float z_r_min, float z_r_max, float z_i_min, float z_i_max);\r
+ void animationStep();\r
+ float getT() /*override*/;\r
+\r
+ private:\r
+ void runGPU(uchar4* ptrDevPixels, const DomaineMath& domaineMath) /*override*/;\r
\r
- // Outputs\r
- const string title;\r
+ float z_r, z_i;\r
+ VariateurF variateurAnimationI;\r
+ VariateurF variateurAnimationR;\r
};\r
\r
#endif\r
|* static *|\r
\*----------------*/\r
\r
-Fractal* FractalProvider::create()\r
+Fractal* FractalProvider::createMandelbrot()\r
{\r
- int dw = 16 * 30;\r
+ int dw = 16 * 50;\r
int dh = 16 * 30;\r
\r
- float dt = 2 * PI / 8000;\r
- int n = 2;\r
+ return new FractalMandelbrot(dw, dh, 0.2);\r
+ }\r
+\r
+\r
+Fractal* FractalProvider::createJulia()\r
+ {\r
+ int dw = 16 * 50;\r
+ int dh = 16 * 30;\r
\r
- return new Fractal(dw, dh, dt, n);\r
+ return new FractalJulia(dw, dh, 0.01, -0.745, -0.32, -0.09, 0.1);\r
}\r
\r
-ImageFonctionel* FractalProvider::createGL()\r
+ImageFonctionel* FractalProvider::createMandelbrotGL()\r
+ {\r
+ ColorRGB_01* ptrColorTitre = new ColorRGB_01(0, 0, 0);\r
+ return new ImageFonctionel(createMandelbrot(), ptrColorTitre); // both ptr destroy by destructor of ImageFonctionel\r
+ }\r
+\r
+\r
+ImageFonctionel* FractalProvider::createJuliaGL()\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
+ return new ImageFonctionel(createJulia(), ptrColorTitre); // both ptr destroy by destructor of ImageFonctionel\r
}\r
\r
/*--------------------------------------*\\r
class FractalProvider\r
{\r
public:\r
- static Fractal* create(void);\r
- static ImageFonctionel* createGL(void);\r
+ static Fractal* createMandelbrot();\r
+ static Fractal* createJulia();\r
+\r
+ static ImageFonctionel* createMandelbrotGL();\r
+ static ImageFonctionel* createJuliaGL();\r
};\r
\r
#endif\r
{\r
//Rippling0Image* ptrRippling0 = Rippling0Provider::createGL();\r
//Image* ptrRippling = RipplingProvider::createGL();\r
-\r
- ImageFonctionel* ptrFractalMandelbrot = FractalProvider::createGL();\r
+ //ImageFonctionel* ptrFractalMandelbrot = FractalProvider::createMandelbrotGL();\r
+ ImageFonctionel* ptrFractalJulia = FractalProvider::createJuliaGL();\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
-\r
- GLUTImageViewers fractalMandelbrotViewer(ptrFractalMandelbrot, true, true, 20, 20);\r
+ //GLUTImageViewers fractalMandelbrotViewer(ptrFractalMandelbrot, 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
// destruction\r
//delete ptrRippling0;\r
//delete ptrRippling;\r
-\r
- delete ptrFractalMandelbrot;\r
+ //delete ptrFractalMandelbrot;\r
+ delete ptrFractalJulia;\r
\r
return EXIT_SUCCESS;\r
}\r