-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvoronoi.h
207 lines (163 loc) · 4.75 KB
/
voronoi.h
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
Guodong Rong
voronoi.h
The header file for voronoi.cpp
Copyright (c) 2005-2006
School of Computing
National University of Singapore
All Rights Reserved.
*/
#include <math.h>
#include <time.h>
#include <GL/glew.h>
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#ifdef WIN32
#include <GL/glut.h>
#include <GL/wglew.h>
#include "imdebug\imdebug.h"
#include "imdebug\imdebuggl.h"
#else
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <GL/freeglut.h>
#include <GL/glext.h>
#endif
#include <cuda_gl_interop.h>
#include "L-BFGS/cutil_inline.h"
#include "L-BFGS/lbfgsb.h"
#define M_PI 3.14159265358979323846
// destination color buffers
const GLenum buffers[] = {
GL_AUX0,
GL_AUX1,
GL_AUX2,
GL_AUX3
};
const GLenum fbo_attachments[] = {
GL_COLOR_ATTACHMENT0_EXT,
GL_COLOR_ATTACHMENT1_EXT,
GL_COLOR_ATTACHMENT2_EXT,
GL_COLOR_ATTACHMENT3_EXT
};
typedef struct VertexSiteType{
float x, y;
}VertexSiteType;
typedef struct SiteType{
VertexSiteType vertices[1];
float color[4];
}SiteType;
int screenwidth, screenheight;
int point_num;
int additional_passes, additional_passes_before;
bool bReCompute;
real stpscal;
bool bReadSitesFromFile;
SiteType *site_list;
SiteType *site_list_dev;
GLuint Processed_Texture[2], Site_Texture, Color_Texture, Energy_Texture[2], IndexColor_Texture;
GLuint FB_objects, RB_object;
int Current_Buffer;
GLuint occlusion_query;
GLuint sampleCount;
GLint oq_available;
GLint oq_bitsSupported;
GLuint vboId;
GLuint colorboId;
cudaGraphicsResource_t grSite;
cudaGraphicsResource_t grVbo;
real* f_tb_host;
real* f_tb_dev;
// For L-BFGS
float *pReadBackValues;
int iSiteTextureHeight;
double EnergyValue;
int numIter;
cublasHandle_t cublasHd;
GLuint ScreenPointsList;
/* New Cg global variables */
CGcontext Context;
CGprofile VertexProfile, FragmentProfile;
CGprogram VP_DrawSites, FP_DrawSites;
CGprogram VP_Flood, FP_Flood;
CGprogram VP_Scatter, FP_Scatter;
CGprogram VP_DrawNewSites, FP_DrawNewSites;
CGprogram VP_DrawSitesOQ, FP_DrawSitesOQ;
CGprogram VP_FinalRender, FP_FinalRender;
CGprogram VP_ComputeEnergy, FP_ComputeEnergy;
CGprogram VP_Deduction, FP_Deduction;
CGprogram VP_ComputeEnergyCentroid, FP_ComputeEnergyCentroid;
CGprogram VP_ScatterCentroid, FP_ScatterCentroid;
// VP_Flood program uniform variables
CGparameter VP_Flood_Steplength;
CGparameter VP_Flood_Size;
// VP_Scatter program uniform variables
CGparameter VP_Scatter_Size;
// VP_DrawNewSites program uniform variables
CGparameter VP_DrawNewSites_Size;
// VP_DrawSitesOQ program uniform variables
CGparameter VP_DrawSitesOQ_Size;
// FP_FinalRender program uniform variables
CGparameter FP_FinalRender_Size;
// FP_ComputeEnergy program uniform variables
CGparameter FP_ComputeEnergy_Size;
// FP_ComputeEnergyCentroid program uniform variables
CGparameter FP_ComputeEnergyCentroid_Size;
// VP_ScatterCentroid program uniform variables
CGparameter VP_ScatterCentroid_Size;
/*********************************************/
void CheckFramebufferStatus();
void DrawSites(real* x, const cudaStream_t& stream);
real BFGSOptimization(void);
real DrawVoronoi(real* x);
void Display(void);
void Keyboard(unsigned char key, int x, int y);
void InitializeGlut(int *argc, char *argv[]);
void DestroyGlut();
void CgErrorCallback(void);
void UpdateSites();
void InitializeSites(int point_num);
void DestroySites();
void InitCg();
// Time...
#ifdef WIN32
typedef LARGE_INTEGER timestamp;
static inline float LI2f(const LARGE_INTEGER &li)
{
// Workaround for compiler bug. Sigh.
float f = unsigned(li.u.HighPart) >> 16; f *= 65536.0f;
f += unsigned(li.u.HighPart) & 0xffff; f *= 65536.0f;
f += unsigned(li.u.LowPart) >> 16; f *= 65536.0f;
f += unsigned(li.u.LowPart) & 0xffff;
return f;
}
static inline float operator - (const timestamp &t1, const timestamp &t2)
{
static LARGE_INTEGER PerformanceFrequency;
static int status = QueryPerformanceFrequency(&PerformanceFrequency);
if (status == 0) return 1.0f;
// return (LI2f(t1) - LI2f(t2)) / LI2f(PerformanceFrequency);
return (t1.QuadPart - t2.QuadPart)/(double)PerformanceFrequency.QuadPart;
}
static inline void get_timestamp(timestamp &now)
{
QueryPerformanceCounter(&now);
}
#else
typedef struct timeval timestamp;
static inline float operator - (const timestamp &t1, const timestamp &t2)
{
return (float)(t1.tv_sec - t2.tv_sec) +
1.0e-6f*(t1.tv_usec - t2.tv_usec);
}
static inline void get_timestamp(timestamp &now)
{
gettimeofday(&now, 0);
}
#endif
timestamp start_time, end_time;
double elapsed_time, total_time;
timestamp start_time_func, end_time_func;
double elapsed_time_func, total_time_func;
//#define DEBUG_TIME