Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / API_Bilat_Image_GL_Cuda / INC / gpu / DomaineMath_GPU.h
1 #ifndef DOMAINE_MATH_GPU_H
2 #define DOMAINE_MATH_GPU_H
3
4 #include "envGLImageCudas.h"
5 #include "cuda.h"
6 #include "DomaineEcran_GPU.h"
7 #include <string>
8
9 using std::string;
10 using std::ostream;
11
12 #define GPU_SCOPE __host__ __device__
13
14 /*----------------------------------------------------------------------*\
15 |* Declaration *|
16 \*---------------------------------------------------------------------*/
17
18 /*--------------------------------------*\
19 |* Public *|
20 \*-------------------------------------*/
21
22 namespace gpu
23 {
24 /**
25 * (x0,y0) upper left corner of a dx x dy square.
26 * x[x0,x1] y[y0,y1]
27 */
28 class CBI_GLIMAGE_CUDA DomaineMath
29 {
30 /*--------------------------------------*\
31 |* Constructor *|
32 \*-------------------------------------*/
33
34 public:
35
36 __host__
37 __device__ DomaineMath() :
38 x0(0.0), y0(0.0), x1(0.0), y1(0.0), dxDw(0.0), dyDh(0.0)
39 {
40 // rien
41 }
42
43 __host__
44 __device__ DomaineMath(double x0, double y0, double x1, double y1) :
45 x0(x0), y0(y0), x1(x1), y1(y1), dxDw(0.0), dyDh(0.0)
46 {
47 // rien
48 }
49
50 /*--------------------------------------*\
51 |* Methodes *|
52 \*--------------------------------------*/
53
54 /*------------------------------*\
55 |* CPU *|
56 \*-----------------------------*/
57
58 public:
59
60 __host__
61 string toString() const;
62
63
64
65 private:
66
67 /**
68 * called only by ImageFonctionelMOOs_A, so Host Only!
69 */
70 __host__
71 void computeDxDy(int w, int h);
72
73 /*------------------------------*\
74 |* GPU/CPU *|
75 \*-----------------------------*/
76
77 public:
78
79 __host__ __device__
80 gpu::DomaineMath extractDomaineFromSelection(const gpu::DomaineEcran &domaineSelection, int dxEcran, int dyEcran) const
81 {
82 double zoomX = dxEcran / (double) domaineSelection.dx;
83 double zoomY = dyEcran / (double) domaineSelection.dy;
84
85 double dxResult = dx() / zoomX;
86 double dyResult = dy() / zoomY;
87
88 double pourcentageX = domaineSelection.x0 / (double) dxEcran;
89 double pourcentageY = domaineSelection.y0 / (double) dyEcran;
90
91 return DomaineMath::create(x0 + (pourcentageX * dx()), y0 + (pourcentageY * dy()), dxResult, dyResult);
92 }
93
94 __host__ __device__
95 double dx() const
96 {
97 return x1 - x0;
98 }
99
100 __host__ __device__
101 double dy() const
102 {
103 return y1 - y0;
104 }
105
106 /**
107 * toXY est uniquement utilisable lorsque le domaine a été associé a une ImageFonctionelle!
108 */
109
110 __host__ __device__
111 void toXY(int i, int j, double* ptrX, double* ptrY) const
112 {
113 *ptrX = x0 + j * dxDw;
114 *ptrY = y0 + i * dyDh;
115 }
116
117 __host__ __device__
118 static gpu::DomaineMath create(double x0, double y0, double dx, double dy)
119 {
120 return DomaineMath(x0, y0, x0 + dx, y0 + dy);
121 }
122
123 /*--------------------------------------*\
124 |* Attributs *|
125 \*-------------------------------------*/
126
127 public:
128
129 //Input
130 double x0;
131 double y0;
132 double x1;
133 double y1;
134
135 private:
136
137 // Tools
138 double dxDw; //old dx
139 double dyDh; //old dy
140
141 friend class ImageFonctionelMOOs_A;
142 // Toutes les méthode de la classe ImageFonctionelMOOs_A sont amie
143 };
144
145 CBI_GLIMAGE_CUDA __host__ ostream& operator<<(ostream& stream, const gpu::DomaineMath& domaine);
146
147 }
148 #endif
149
150 /*----------------------------------------------------------------------*\
151 |* End *|
152 \*---------------------------------------------------------------------*/
153