chore: init
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
#pragma once
|
||||
|
||||
#include "cudas.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Declaration *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
class Rippling3DMath
|
||||
{
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Constructor *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
public:
|
||||
|
||||
__device__ Rippling3DMath(uint w , uint h , float t) :
|
||||
dim2(w >>1), //
|
||||
t(t)
|
||||
{
|
||||
// rien
|
||||
}
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Methodes *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Par rapport a la version 2D, on calcule ici le niveau de gris en float et non en uchar.
|
||||
* ce niveau de gris est ensuite utiliser pour:
|
||||
* - la hauteur en float
|
||||
* - la couleur une fois caste en uchar
|
||||
* </pre>
|
||||
*/
|
||||
__device__
|
||||
void xyz(uchar4* ptrColorIJGM , float3* ptrSommetXYZGM , int i , int j)
|
||||
{
|
||||
// on calcul levelGray qu une seule fois, puis on l'utilise pour :
|
||||
// - la "couleur"
|
||||
// - la hauteur
|
||||
|
||||
float levelGrayFloat0255 = levelGray(i, j); // car la surface sera plus "lisse" en float qu'en uchar et z peut etre en float.
|
||||
|
||||
// color
|
||||
{
|
||||
uchar levelGris = (uchar)levelGrayFloat0255; // car la couleur est en uchar
|
||||
|
||||
// Indication:
|
||||
// (I1) Utiliser i et j pour obtenir x et y
|
||||
//
|
||||
// Warning :
|
||||
// (W1) i est sur l'axe y, i est y, presque
|
||||
// (W2) j est sur l'aye x, j est x, presque
|
||||
// (W3) Pour que le centre de graviter de la forme soit au centre de "l ecran", et pour pouvoir
|
||||
// tourner avec la souris autour du centre de gravite:
|
||||
// - decaler de dim2 sur l'axe des x
|
||||
// - decaler de dim2 sur l'axe des y
|
||||
|
||||
// TODO RIPPLING 3D
|
||||
}
|
||||
|
||||
// sommet (float3 est une structure a 3 champs x y et z (3 float)
|
||||
{
|
||||
// Indication : pour la hauteur z utiliser 6 x levelGrayFloat0255s (plus joli)
|
||||
|
||||
// TODO RIPPLING 3D
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/*---------------------*\
|
||||
|* level gray *|
|
||||
\*--------------------*/
|
||||
|
||||
__inline__
|
||||
__device__
|
||||
float levelGray(int i , int j ) // en float in [0,255]
|
||||
{
|
||||
// TODO RIPPLING 3D
|
||||
return -1;
|
||||
}
|
||||
|
||||
__inline__
|
||||
__device__
|
||||
void dij(int i , int j, float* ptrResult )
|
||||
{
|
||||
// TODO RIPPLING 3D
|
||||
}
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Attributs *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
private:
|
||||
|
||||
// Input
|
||||
float t;
|
||||
|
||||
// Tools
|
||||
int dim2; // dim2=dim/2
|
||||
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "Rippling3DMath.h"
|
||||
#include "Thread2D.cu.h"
|
||||
#include "Indices.cu.h"
|
||||
|
||||
#include "cudas.h"
|
||||
|
||||
#include "DomainMath3D_GPU.h"
|
||||
using namespace gpu;
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Implementation *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* w nbPoint en x
|
||||
* h nbPoint en y
|
||||
*
|
||||
* domaineMath pas utiliser ici
|
||||
*/
|
||||
__global__ void rippling3DCuda(float3* tabVerticesXYZGM , uchar4* tabVerticesColorGM , int w , int h , float t)
|
||||
{
|
||||
Rippling3DMath rippling3DMath(w, h, t);
|
||||
|
||||
// Indication :
|
||||
// (I1) comme en 2D
|
||||
// (I2) domaineMath pas utiliser ici
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
101
Student_Cuda_3D_Surface/src/core/a_highmap/a_rippling3D/host/Rippling3D_RGBA.cu
Executable file
101
Student_Cuda_3D_Surface/src/core/a_highmap/a_rippling3D/host/Rippling3D_RGBA.cu
Executable file
@@ -0,0 +1,101 @@
|
||||
#include "Rippling3D_RGBA.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "Maths.h"
|
||||
#include "cudas.h"
|
||||
|
||||
using std::to_string;
|
||||
|
||||
using gpu::DomainMath3D;
|
||||
using gpu::SurfaceStrip_RGBA_uchar4;
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Declaration *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Imported *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
extern __global__ void rippling3DCuda(float3* tabVerticesXYZGM, uchar4* tabVerticesColorGM, int w, int h,float t);
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Implementation *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
/*-------------------------*\
|
||||
|* Constructeur *|
|
||||
\*-------------------------*/
|
||||
|
||||
Rippling3D_RGBA::Rippling3D_RGBA(const Grid& grid , int w , int h , const DomainMath3D& domaineMath , double dt) :
|
||||
// Parent
|
||||
SurfaceStrip_RGBA_uchar4(w, h, domaineMath), //
|
||||
// Inputs
|
||||
dg(grid.dg), //
|
||||
db(grid.db), //
|
||||
// Inputs animation
|
||||
dt(dt)
|
||||
{
|
||||
// Tools
|
||||
this->t=0;
|
||||
this->title = "Rippling3D_RGBA_uchar4";
|
||||
}
|
||||
|
||||
Rippling3D_RGBA::~Rippling3D_RGBA()
|
||||
{
|
||||
// rien
|
||||
}
|
||||
|
||||
/*-------------------------*\
|
||||
|* Surcharge *|
|
||||
\*------------------------*/
|
||||
|
||||
/**
|
||||
* Override
|
||||
* Call periodicly by the api
|
||||
*/
|
||||
void Rippling3D_RGBA::fillVertex(float3* tabVerticesXYZGM , uchar4* tabVerticesColorGM , uint w , uint h , const gpu::DomainMath3D& domaineMath)
|
||||
{
|
||||
rippling3DCuda<<<dg,db>>>(tabVerticesXYZGM,tabVerticesColorGM,w,h,t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override
|
||||
* Call periodicly by the api
|
||||
*/
|
||||
void Rippling3D_RGBA::animationStep(bool& isNeedUpdate)
|
||||
{
|
||||
this->t+=dt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override
|
||||
* Call periodicly by the api
|
||||
*/
|
||||
void Rippling3D_RGBA::paintPrimitives(Graphic2D& graphic2D)
|
||||
{
|
||||
graphic2D.setFont(TIMES_ROMAN_24);
|
||||
|
||||
float r = 0.5f;
|
||||
float g = 0.5f;
|
||||
float b = 0.5f;
|
||||
|
||||
graphic2D.setColorRGB(r, g, b);
|
||||
|
||||
// TOP : Para Animation
|
||||
{
|
||||
string message = "t= " + to_string(t);
|
||||
graphic2D.drawTitleTop(message);
|
||||
}
|
||||
|
||||
// BOTTOM : Title
|
||||
{
|
||||
graphic2D.drawTitleBottom(title);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
123
Student_Cuda_3D_Surface/src/core/a_highmap/a_rippling3D/host/Rippling3D_RGBA.h
Executable file
123
Student_Cuda_3D_Surface/src/core/a_highmap/a_rippling3D/host/Rippling3D_RGBA.h
Executable file
@@ -0,0 +1,123 @@
|
||||
#pragma once
|
||||
|
||||
#include "Grid.h"
|
||||
#include "SurfaceStrip_GPU.h"
|
||||
#include "DomainMath3D_GPU.h"
|
||||
#include "Variateur.cu.h"
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Declaration *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Concept:
|
||||
*
|
||||
* La couleur d'une surface est defini par
|
||||
* - nombre de cannaux couleurs
|
||||
* - type des cannaux couleurs
|
||||
*
|
||||
* Dans cet api, on peut choisir ces deux propri<72>t<EFBFBD>s
|
||||
* - #cannaux couleurs
|
||||
* - #type des cannaux
|
||||
*
|
||||
* Type predefinis:
|
||||
*
|
||||
* SurfaceStrip_RGBA_uchar4
|
||||
* SurfaceStrip_RGB_uchar3
|
||||
*
|
||||
* SurfaceStrip_RGBA_float4
|
||||
* SurfaceStrip_RGB_float3
|
||||
*
|
||||
* SurfaceStrip_HSBA_float4
|
||||
* SurfaceStrip_HSB_float3
|
||||
* SurfaceStrip_HA_float2
|
||||
* SurfaceStrip_HUE_float
|
||||
*
|
||||
* Contraintes:
|
||||
*
|
||||
* Le choix du type des cannaux couleurs influence le type de l'image apparaissant dans la methode fillVertex.
|
||||
* Il faut etre coherent! En cas de mauvais matching, une erreur de compilation surviendra (attention elle est pas forcement tr<74>s explicite).
|
||||
*
|
||||
* Exemples:
|
||||
*
|
||||
* SurfaceStrip_RGBA_float4 virtual void fillImage(float4* ptrTabColors,...)
|
||||
* SurfaceStrip_RGB_uchar3 virtual void fillImage(uchar3* ptrTabColors,...) // ou unsigned char si uchar non disponible
|
||||
* SurfaceStrip_HUE_float virtual void fillImage(float* ptrTabColors,...)
|
||||
*
|
||||
* Types predefinis naturel:
|
||||
*
|
||||
* SurfaceStrip_RGBA_uchar4
|
||||
* SurfaceStrip_HSBA_float4
|
||||
* SurfaceStrip_HUE_float
|
||||
*
|
||||
* Les versions a 3 cannaux (uchar3 et float3) ne sont a priori pas super en terme de performance en cuda pour l'utilisation du tiling en sm.
|
||||
*
|
||||
*
|
||||
* Notes:
|
||||
*
|
||||
* (N1) Implementation:
|
||||
* Les types prededinis se trouve dans
|
||||
* - SurfaceStrip_CPU.h
|
||||
* - SurfaceStrip_GPU.h
|
||||
*
|
||||
* (N2) Extension:
|
||||
* On pourrait ajouter d'autres types predefinis!
|
||||
*
|
||||
*/
|
||||
class Rippling3D_RGBA: public gpu::SurfaceStrip_RGBA_uchar4
|
||||
{
|
||||
/*--------------------------------------*\
|
||||
|* Constructor *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
public:
|
||||
|
||||
Rippling3D_RGBA(const Grid& grid , int w , int h , const gpu::DomainMath3D& domaineMath , double dt);
|
||||
|
||||
virtual ~Rippling3D_RGBA();
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Methodes *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
public:
|
||||
|
||||
/*-------------------------*\
|
||||
|* Override Surface *|
|
||||
\*------------------------*/
|
||||
|
||||
/**
|
||||
* Call periodicly by the api
|
||||
*/
|
||||
virtual void fillVertex(float3* tabVerticesXYZGM , uchar4* tabVerticesColorGM , uint w ,uint h ,
|
||||
const gpu::DomainMath3D& domaineMath);
|
||||
|
||||
/**
|
||||
* Call periodicly by the api
|
||||
*/
|
||||
virtual void animationStep(bool& isNeedUpdate);
|
||||
|
||||
/**
|
||||
* Call periodicly by the api
|
||||
*/
|
||||
virtual void paintPrimitives(Graphic2D& graphic2D);
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Attributs *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
private:
|
||||
|
||||
// Inputs
|
||||
double dt;
|
||||
dim3 dg;
|
||||
dim3 db;
|
||||
|
||||
// Tools
|
||||
string title;
|
||||
double t;
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
@@ -0,0 +1,56 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "Grid.h"
|
||||
#include "Hardware.h"
|
||||
#include "Maths.h"
|
||||
|
||||
#include "Rippling3D_RGBA.h"
|
||||
#include "Rippling3DProvider.h"
|
||||
|
||||
#include "DomainMath3D_GPU.h"
|
||||
|
||||
using gpu::DomainMath3D;
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Implementation *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* static
|
||||
*/
|
||||
SurfaceStrip_I* Rippling3DProvider::createSurfaceStrip()
|
||||
{
|
||||
// Dimension
|
||||
int w = 960;
|
||||
int h = w; // contrainte temporaire! Doit eter carrer, sinon bug!
|
||||
|
||||
// Animation;
|
||||
float dt = 2 * PI / 10;
|
||||
|
||||
// Domaine init
|
||||
double x1 = -w / 2;
|
||||
double y1 = -h / 2;
|
||||
|
||||
double x2 = w / 2;
|
||||
double y2 = h / 2;
|
||||
|
||||
double z1 = 0;
|
||||
double z2 = 6 * 255;
|
||||
|
||||
DomainMath3D domaineMath(x1, x2, y1, y2, z1, z2); // Attention ordre, pas idem DomainMath2D, ici x1,x2, ...
|
||||
|
||||
// Grid Cuda
|
||||
int mp = Hardware::getMPCount();
|
||||
int coreMP = Hardware::getCoreCountMP();
|
||||
|
||||
dim3 dg(mp, 4, 1); // disons, a optimiser selon le gpu, peut drastiqument ameliorer ou baisser les performances
|
||||
dim3 db(coreMP, 4, 1); // disons, a optimiser selon le gpu, peut drastiqument ameliorer ou baisser les performances
|
||||
Grid grid(dg, db);
|
||||
|
||||
return new Rippling3D_RGBA(grid, w, h, domaineMath, dt); // Model
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "SurfaceStrip_I.h"
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Declaration *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
class Rippling3DProvider
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static SurfaceStrip_I* createSurfaceStrip();
|
||||
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "RipplingWindow.h"
|
||||
|
||||
#include "Rippling3DProvider.h"
|
||||
|
||||
|
||||
using std::cout;
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Implementation *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
/*-------------------------*\
|
||||
|* Constructeur *|
|
||||
\*-------------------------*/
|
||||
|
||||
RipplingWindow::RipplingWindow(RenderMode renderMode) : //
|
||||
renderMode(renderMode)
|
||||
{
|
||||
this->ptrSurfaceStrip = Rippling3DProvider::createSurfaceStrip();
|
||||
|
||||
// Scene
|
||||
this->ptrScene = new SurfaceSceneStrip(this->ptrSurfaceStrip);
|
||||
|
||||
// Scene Options
|
||||
{
|
||||
this->ptrScene->setAppearance(renderMode); // RENDER_MODE_FILL RENDER_MODE_LINE RENDER_MODE_POINT
|
||||
|
||||
BoundViewOption boundViewOptionRippling(false, false, false, false, false, false);
|
||||
this->ptrScene->setBoundViewOption(boundViewOptionRippling);
|
||||
}
|
||||
|
||||
// Window
|
||||
this->prtWindow = new GLUTWindowScene(this->ptrScene, "Rippling", 1024, 768, 10, 10); // w x px py
|
||||
|
||||
cout<<"Rippling : warning : rotate to the sunny side of the surface to see the rippling.\n";
|
||||
}
|
||||
|
||||
RipplingWindow::~RipplingWindow()
|
||||
{
|
||||
// delete this->ptrScene; // pas besoin fait dans ptrSurfaceStrip
|
||||
delete this->ptrSurfaceStrip;
|
||||
delete this->prtWindow;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "SurfaceSceneStrip.h"
|
||||
#include "GLUTWindowScene.h"
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Declaration *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
class RipplingWindow
|
||||
{
|
||||
/*--------------------------------------*\
|
||||
|* Constructor *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* RenderMode:
|
||||
* - RENDER_MODE_FILL
|
||||
* - RENDER_MODE_LINE
|
||||
* - RENDER_MODE_POINT
|
||||
* </pre>
|
||||
*/
|
||||
RipplingWindow(RenderMode renderMode = RenderMode::RENDER_MODE_FILL);
|
||||
|
||||
virtual ~RipplingWindow();
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Methodes *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Attributs *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
private:
|
||||
|
||||
// Inputs
|
||||
RenderMode renderMode;
|
||||
|
||||
// Tools
|
||||
SurfaceStrip_I* ptrSurfaceStrip;
|
||||
SurfaceSceneStrip* ptrScene;
|
||||
GLUTWindowScene* prtWindow;
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "Mandelbrot3DMath.h"
|
||||
#include "Thread2D.cu.h"
|
||||
#include "Indices.cu.h"
|
||||
|
||||
#include "cudas.h"
|
||||
|
||||
#include "DomainMath3D_GPU.h"
|
||||
using namespace gpu;
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Implementation *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* w nbPoint en x
|
||||
* h nbPoint en y
|
||||
*/
|
||||
__global__ void mandelbrot3DCuda(float3* tabVerticesXYZGM , uchar4* tabVerticesColorGM , int w , int h , DomainMath3D domaineMath , int n)
|
||||
{
|
||||
Mandelbrot3DMath mandelbrot3DMath(n);
|
||||
|
||||
const int TID = Thread2D::tid();
|
||||
const int NB_THREAD = Thread2D::nbThread();
|
||||
|
||||
const int WH = w * h;
|
||||
|
||||
float x;
|
||||
float y;
|
||||
float DX;
|
||||
float DY;
|
||||
|
||||
int vertexI;
|
||||
int vertexJ;
|
||||
|
||||
domaineMath.delta(w, h, &DX, &DY);
|
||||
|
||||
int s = TID;
|
||||
while (s < WH)
|
||||
{
|
||||
Indices::toIJ(s, w, &vertexI, &vertexJ); // update (vertexI, vertexJ)
|
||||
|
||||
domaineMath.toXY(DX, DY, vertexI, vertexJ, &x, &y);
|
||||
|
||||
mandelbrot3DMath.xyz(&tabVerticesColorGM[s], &tabVerticesXYZGM[s], x, y);
|
||||
|
||||
s += NB_THREAD;
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
#include <cuda_fp16.h>
|
||||
|
||||
//#include "Calibreur.cu.h"
|
||||
#include "Colors.cu.h"
|
||||
|
||||
//Half
|
||||
#define DEUX (half)2
|
||||
#define QUATRE (half)4
|
||||
#define ZERO (half)0
|
||||
|
||||
// float
|
||||
//#define DEUX 2.f
|
||||
//#define QUATRE 4.f
|
||||
//#define ZERO 0.f
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Declaration *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
class Mandelbrot3DMath
|
||||
{
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Constructor *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
public:
|
||||
|
||||
__device__ Mandelbrot3DMath(int n) :
|
||||
n(n)
|
||||
{
|
||||
// rien
|
||||
}
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Methodes *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
public:
|
||||
|
||||
__device__
|
||||
void xyz(uchar4* ptrColorIJ , float3* ptrSommetXYZ , float x , float y)
|
||||
{
|
||||
ptrSommetXYZ->x = x;
|
||||
ptrSommetXYZ->y = y;
|
||||
|
||||
int k = suite((half)x, (half)y); // in [0,n]
|
||||
|
||||
if (k >= n)
|
||||
{
|
||||
// sommet
|
||||
{
|
||||
// TODO hauteur 0
|
||||
}
|
||||
|
||||
// color black
|
||||
{
|
||||
// TODO comme en 2D
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float h01 = k / (float)(n - 1); // in [0,1]
|
||||
|
||||
// sommet
|
||||
{
|
||||
// TODO utiliser la fonction z ci-dessous
|
||||
}
|
||||
|
||||
// color
|
||||
{
|
||||
// TODO comme end 2D
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/*---------------------*\
|
||||
|* suite *|
|
||||
\*--------------------*/
|
||||
|
||||
__inline__
|
||||
__device__
|
||||
int suite(half x , half y)
|
||||
{
|
||||
// TODO comme en 2D
|
||||
}
|
||||
|
||||
/*---------------------*\
|
||||
|* hauteur *|
|
||||
\*--------------------*/
|
||||
|
||||
__inline__
|
||||
__device__
|
||||
float z(float h01)
|
||||
{
|
||||
const int M = 8; //disons
|
||||
return logs(h01, M) + 0.5f;
|
||||
}
|
||||
|
||||
__inline__
|
||||
__device__
|
||||
float logs(float z, const int M)
|
||||
{
|
||||
for (int i = 0; i <= M; i++)
|
||||
{
|
||||
z = log(z + 1.0f);
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Attributs *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
private:
|
||||
|
||||
// Input
|
||||
int n;
|
||||
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
@@ -0,0 +1,103 @@
|
||||
#include "Mandelbrot3D_RGBA.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "Maths.h"
|
||||
#include "cudas.h"
|
||||
|
||||
using std::to_string;
|
||||
|
||||
using gpu::DomainMath3D;
|
||||
using gpu::SurfaceStrip_RGBA_uchar4;
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Declaration *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Imported *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
extern __global__ void mandelbrot3DCuda(float3* tabVerticesXYZGM, uchar4* tabVerticesColorGM, int w, int h, DomainMath3D domaineMath, int n);
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Implementation *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
/*-------------------------*\
|
||||
|* Constructeur *|
|
||||
\*-------------------------*/
|
||||
|
||||
Mandelbrot3D_RGBA::Mandelbrot3D_RGBA(const Grid& grid , int w , int h , const DomainMath3D& domaineMath , int nMin,int nMax) :
|
||||
// Parent
|
||||
SurfaceStrip_RGBA_uchar4(w, h, domaineMath), //
|
||||
// Inputs
|
||||
dg(grid.dg), //
|
||||
db(grid.db), //
|
||||
// Inputs animation
|
||||
nMin(nMin), nMax(nMax),
|
||||
// Tools animation
|
||||
variateurN(Interval<int>(nMin, nMax), 1) // tools animation
|
||||
{
|
||||
// Tools
|
||||
this->title = "Mandelbrot_RGBA_uchar4";
|
||||
this->n = nMin;
|
||||
}
|
||||
|
||||
Mandelbrot3D_RGBA::~Mandelbrot3D_RGBA()
|
||||
{
|
||||
// rien
|
||||
}
|
||||
|
||||
/*-------------------------*\
|
||||
|* Surcharge *|
|
||||
\*------------------------*/
|
||||
|
||||
/**
|
||||
* Override
|
||||
* Call periodicly by the api
|
||||
*/
|
||||
void Mandelbrot3D_RGBA::fillVertex(float3* tabVerticesXYZGM , uchar4* tabVerticesColorGM , uint w , uint h , const gpu::DomainMath3D& domaineMath)
|
||||
{
|
||||
mandelbrot3DCuda<<<dg,db>>>(tabVerticesXYZGM,tabVerticesColorGM,w,h,domaineMath,n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override
|
||||
* Call periodicly by the api
|
||||
*/
|
||||
void Mandelbrot3D_RGBA::animationStep(bool& isNeedUpdate)
|
||||
{
|
||||
this->n = variateurN.varierAndGet(); // in [nMIn,nMax]
|
||||
}
|
||||
|
||||
/**
|
||||
* Override
|
||||
* Call periodicly by the api
|
||||
*/
|
||||
void Mandelbrot3D_RGBA::paintPrimitives(Graphic2D& graphic2D)
|
||||
{
|
||||
graphic2D.setFont(TIMES_ROMAN_24);
|
||||
|
||||
float r = 0.5f;
|
||||
float g = 0.5f;
|
||||
float b = 0.5f;
|
||||
|
||||
graphic2D.setColorRGB(r, g, b);
|
||||
|
||||
// TOP : Para Animation
|
||||
{
|
||||
string message = "n = " + to_string(n);
|
||||
graphic2D.drawTitleTop(message);
|
||||
}
|
||||
|
||||
// BOTTOM : Title
|
||||
{
|
||||
graphic2D.drawTitleBottom(title);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
#pragma once
|
||||
|
||||
#include "Grid.h"
|
||||
#include "SurfaceStrip_GPU.h"
|
||||
#include "DomainMath3D_GPU.h"
|
||||
#include "Variateur.cu.h"
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Declaration *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Concept:
|
||||
*
|
||||
* La couleur d'une surface est defini par
|
||||
* - nombre de cannaux couleurs
|
||||
* - type des cannaux couleurs
|
||||
*
|
||||
* Dans cet api, on peut choisir ces deux propri<72>t<EFBFBD>s
|
||||
* - #cannaux couleurs
|
||||
* - #type des cannaux
|
||||
*
|
||||
* Type predefinis:
|
||||
*
|
||||
* SurfaceStrip_RGBA_uchar4
|
||||
* SurfaceStrip_RGB_uchar3
|
||||
*
|
||||
* SurfaceStrip_RGBA_float4
|
||||
* SurfaceStrip_RGB_float3
|
||||
*
|
||||
* SurfaceStrip_HSBA_float4
|
||||
* SurfaceStrip_HSB_float3
|
||||
* SurfaceStrip_HA_float2
|
||||
* SurfaceStrip_HUE_float
|
||||
*
|
||||
* Contraintes:
|
||||
*
|
||||
* Le choix du type des cannaux couleurs influence le type de l'image apparaissant dans la methode fillVertex.
|
||||
* Il faut etre coherent! En cas de mauvais matching, une erreur de compilation surviendra (attention elle est pas forcement tr<74>s explicite).
|
||||
*
|
||||
* Exemples:
|
||||
*
|
||||
* SurfaceStrip_RGBA_float4 virtual void fillImage(float4* ptrTabColors,...)
|
||||
* SurfaceStrip_RGB_uchar3 virtual void fillImage(uchar3* ptrTabColors,...) // ou unsigned char si uchar non disponible
|
||||
* SurfaceStrip_HUE_float virtual void fillImage(float* ptrTabColors,...)
|
||||
*
|
||||
* Types predefinis naturel:
|
||||
*
|
||||
* SurfaceStrip_RGBA_uchar4
|
||||
* SurfaceStrip_HSBA_float4
|
||||
* SurfaceStrip_HUE_float
|
||||
*
|
||||
* Les versions a 3 cannaux (uchar3 et float3) ne sont a priori pas super en terme de performance en cuda pour l'utilisation du tiling en sm.
|
||||
*
|
||||
*
|
||||
* Notes:
|
||||
*
|
||||
* (N1) Implementation:
|
||||
* Les types prededinis se trouve dans
|
||||
* - SurfaceStrip_CPU.h
|
||||
* - SurfaceStrip_GPU.h
|
||||
*
|
||||
* (N2) Extension:
|
||||
* On pourrait ajouter d'autres types predefinis!
|
||||
*
|
||||
*/
|
||||
class Mandelbrot3D_RGBA: public gpu::SurfaceStrip_RGBA_uchar4
|
||||
{
|
||||
/*--------------------------------------*\
|
||||
|* Constructor *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
public:
|
||||
|
||||
Mandelbrot3D_RGBA(const Grid& grid , int w , int h , const gpu::DomainMath3D& domaineMath , int nMin , int nMax);
|
||||
|
||||
virtual ~Mandelbrot3D_RGBA();
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Methodes *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
public:
|
||||
|
||||
/*-------------------------*\
|
||||
|* Override Surface *|
|
||||
\*------------------------*/
|
||||
|
||||
/**
|
||||
* Call periodicly by the api
|
||||
*/
|
||||
virtual void fillVertex(float3* tabVerticesXYZGM , uchar4* tabVerticesColorGM , uint w ,uint h ,
|
||||
const gpu::DomainMath3D& domaineMath);
|
||||
|
||||
/**
|
||||
* Call periodicly by the api
|
||||
*/
|
||||
virtual void animationStep(bool& isNeedUpdate);
|
||||
|
||||
/**
|
||||
* Call periodicly by the api
|
||||
*/
|
||||
virtual void paintPrimitives(Graphic2D& graphic2D);
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Attributs *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
private:
|
||||
|
||||
// Inputs
|
||||
int nMin;
|
||||
int nMax;
|
||||
dim3 dg;
|
||||
dim3 db;
|
||||
|
||||
// Tools
|
||||
string title;
|
||||
int n;
|
||||
Variateur<int> variateurN;
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "Grid.h"
|
||||
#include "Hardware.h"
|
||||
#include "Maths.h"
|
||||
|
||||
#include "Mandelbrot3D_RGBA.h"
|
||||
#include "Mandelbrot3DProvider.h"
|
||||
|
||||
#include "DomainMath3D_GPU.h"
|
||||
|
||||
using gpu::DomainMath3D;
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Implementation *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* static
|
||||
*/
|
||||
SurfaceStrip_I* Mandelbrot3DProvider::createSurfaceStrip()
|
||||
{
|
||||
// Dimension
|
||||
int w = 3200;
|
||||
int h = w; // contrainte temporaire! Doit eter carrer, sinon bug!
|
||||
|
||||
// Animation
|
||||
int nMin = 5;
|
||||
int nMax = 75;
|
||||
|
||||
// Domaine init
|
||||
double x1 = -2.1;
|
||||
double y1 = -1.3;
|
||||
|
||||
double x2 = 0.8;
|
||||
double y2 = 1.3;
|
||||
|
||||
double z1 = 0;
|
||||
double z2 = 1;
|
||||
|
||||
DomainMath3D domaineMath(x1, x2, y1, y2, z1, z2); // Attention ordre, pas idem DomainMath2D, ici x1,x2, ...
|
||||
|
||||
// Grid Cuda
|
||||
int mp = Hardware::getMPCount();
|
||||
int coreMP = Hardware::getCoreCountMP();
|
||||
|
||||
dim3 dg(mp, 4, 1); // disons, a optimiser selon le gpu, peut drastiqument ameliorer ou baisser les performances
|
||||
dim3 db(coreMP, 4, 1); // disons, a optimiser selon le gpu, peut drastiqument ameliorer ou baisser les performances
|
||||
Grid grid(dg, db);
|
||||
|
||||
return new Mandelbrot3D_RGBA(grid, w, h, domaineMath, nMin, nMax); // Model
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "SurfaceStrip_I.h"
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Declaration *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
class Mandelbrot3DProvider
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static SurfaceStrip_I* createSurfaceStrip();
|
||||
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "MandelbrotWindow.h"
|
||||
|
||||
#include "Mandelbrot3DProvider.h"
|
||||
|
||||
using std::cout;
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Implementation *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
/*-------------------------*\
|
||||
|* Constructeur *|
|
||||
\*-------------------------*/
|
||||
|
||||
MandelbrotWindow::MandelbrotWindow(RenderMode renderMode) : //
|
||||
renderMode(renderMode)
|
||||
{
|
||||
this->ptrSurfaceStrip = Mandelbrot3DProvider::createSurfaceStrip();
|
||||
|
||||
// Scene
|
||||
this->ptrScene = new SurfaceSceneStrip(this->ptrSurfaceStrip);
|
||||
|
||||
// Scene Options
|
||||
{
|
||||
this->ptrScene->setAppearance(renderMode); // RENDER_MODE_FILL RENDER_MODE_LINE RENDER_MODE_POINT
|
||||
|
||||
BoundViewOption boundViewOptionRippling(false, false, false, false, false, false);
|
||||
this->ptrScene->setBoundViewOption(boundViewOptionRippling);
|
||||
}
|
||||
|
||||
// Window
|
||||
this->prtWindow = new GLUTWindowScene(this->ptrScene, "Mandelbrot", 1024, 768, 50, 50); // w x px py
|
||||
}
|
||||
|
||||
MandelbrotWindow::~MandelbrotWindow()
|
||||
{
|
||||
// delete this->ptrScene; // pas besoin fait dans ptrSurfaceStrip
|
||||
delete this->ptrSurfaceStrip;
|
||||
delete this->prtWindow;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "SurfaceSceneStrip.h"
|
||||
#include "GLUTWindowScene.h"
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Declaration *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
class MandelbrotWindow
|
||||
{
|
||||
/*--------------------------------------*\
|
||||
|* Constructor *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* RenderMode:
|
||||
* - RENDER_MODE_FILL
|
||||
* - RENDER_MODE_LINE
|
||||
* - RENDER_MODE_POINT
|
||||
* </pre>
|
||||
*/
|
||||
MandelbrotWindow(RenderMode renderMode = RenderMode::RENDER_MODE_FILL);
|
||||
|
||||
virtual ~MandelbrotWindow();
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Methodes *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
/*--------------------------------------*\
|
||||
|* Attributs *|
|
||||
\*-------------------------------------*/
|
||||
|
||||
private:
|
||||
|
||||
// Inputs
|
||||
RenderMode renderMode;
|
||||
|
||||
// Tools
|
||||
SurfaceStrip_I* ptrSurfaceStrip;
|
||||
SurfaceSceneStrip* ptrScene;
|
||||
GLUTWindowScene* prtWindow;
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
51
Student_Cuda_3D_Surface/src/main.cpp
Executable file
51
Student_Cuda_3D_Surface/src/main.cpp
Executable file
@@ -0,0 +1,51 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "CudaContextSimple.h"
|
||||
#include "Limits.h"
|
||||
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Imported *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
extern int mainCore(const Args& args);
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Implementation *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
int main(int argc , char** argv)
|
||||
{
|
||||
//Limits::show();
|
||||
|
||||
CudaContextSimple cudaContext;
|
||||
|
||||
// public
|
||||
{
|
||||
cudaContext.deviceId = 0; // in [0,2] width Server Cuda3
|
||||
|
||||
cudaContext.deviceDriver = DeviceDriver::LOAD_CURRENT; // LOAD_CURRENT LOAD_ALL
|
||||
cudaContext.deviceInfo = DeviceInfo::ALL_SIMPLE; // NONE ALL ALL_SIMPLE CURRENT
|
||||
}
|
||||
|
||||
// private
|
||||
{
|
||||
cudaContext.args.argc = argc;
|
||||
cudaContext.args.argv = argv;
|
||||
|
||||
cudaContext.mainCore = mainCore;
|
||||
}
|
||||
|
||||
return cudaContext.process();
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
32
Student_Cuda_3D_Surface/src/mainCore.cpp
Executable file
32
Student_Cuda_3D_Surface/src/mainCore.cpp
Executable file
@@ -0,0 +1,32 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "GLUTWindowManagers.h"
|
||||
#include "Args.h"
|
||||
|
||||
#include "RipplingWindow.h"
|
||||
#include "MandelbrotWindow.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* Implementation *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
void mainCore(const Args& args)
|
||||
{
|
||||
GLUTWindowManagers::init(args.argc, args.argv);
|
||||
|
||||
RipplingWindow rippling(RenderMode::RENDER_MODE_FILL); // RENDER_MODE_FILL RENDER_MODE_LINE RENDER_MODE_POINT
|
||||
//MandelbrotWindow mandelbrot(RenderMode::RENDER_MODE_FILL); // RENDER_MODE_FILL RENDER_MODE_LINE RENDER_MODE_POINT
|
||||
|
||||
// Info
|
||||
cout << "\nTourner-Zoomer\n" << endl;
|
||||
|
||||
// Run
|
||||
GLUTWindowManagers::getInstance()->runALL(); // bloquant
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*\
|
||||
|* End *|
|
||||
\*---------------------------------------------------------------------*/
|
||||
Reference in New Issue
Block a user