-
Notifications
You must be signed in to change notification settings - Fork 2
/
device_window_t.cu
83 lines (76 loc) · 2.33 KB
/
device_window_t.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//NOT WORKING WITH NEWER THRUST VERSION
#include <iostream>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include "device_window.cuh"
/**
* @brief Functor returning a gaussian
* \f[
f(x,y) = Ae^{-(\frac{(x-x_0)^2}{2\sigma_x^2} + \frac{(y-y_0)^2}{2\sigma_y^2}}
\f]
*/
struct Gaussian
{
/**
* @brief Functor returning a gaussian
*
* @param x0 x-center-coordinate
* @param y0 y-center-coordinate
* @param sigma_x x - variance
* @param sigma_y y - variance
* @param amp Amplitude
*/
Gaussian( float x0, float y0, float sigma_x, float sigma_y, float amp)
: x00(x0), y00(y0), sigma_x(sigma_x), sigma_y(sigma_y), amplitude(amp){}
/**
* @brief Return the value of the gaussian
*
* \f[
f(x,y) = Ae^{-(\frac{(x-x_0)^2}{2\sigma_x^2} + \frac{(y-y_0)^2}{2\sigma_y^2}}
\f]
* @param x x - coordinate
* @param y y - coordinate
*
* @return gaussian
*/
float operator()(float x, float y)
{
return amplitude*
exp( -((x-x00)*(x-x00)/2./sigma_x/sigma_x +
(y-y00)*(y-y00)/2./sigma_y/sigma_y) );
}
private:
float x00, y00, sigma_x, sigma_y, amplitude;
};
const unsigned Nx = 20, Ny = 10;
const float lx = 2., ly = 2.;
const float hx = lx/(float)Nx, hy = ly/(float)Ny;
int main()
{
//Create Window and set window title
GLFWwindow* w = draw::glfwInitAndCreateWindow( 800, 400, "Hello world!");
draw::RenderDeviceData render( 1,1);
// generate a vector on the grid to visualize
Gaussian g( 1.2, 0.3, .1, .1, 1);
thrust::host_vector<float> visual(Nx*Ny);
for(unsigned i=0; i<Ny; i++)
for( unsigned j=0; j<Nx; j++)
visual[i*Nx+j] = g( (float)j*hx, (float)i*hy);
thrust::device_vector<float> dvisual1 = visual;
for(unsigned i=0; i<Ny; i++)
for( unsigned j=0; j<Nx; j++)
visual[i*Nx+j] = -g( (float)j*hx, (float)i*hy);
thrust::device_vector<float> dvisual2 = visual;
//create a colormap
draw::ColorMapRedBlueExt colors( 1.);
//set scale
colors.scale() = 1.;
while ( !glfwWindowShouldClose( w))
{
render.renderQuad( dvisual1, Nx, Ny, colors);
//render.renderQuad( dvisual2, Nx, Ny, colors);
glfwSwapBuffers(w);
glfwWaitEvents();
}
return 0;
}