root / rgbdslam / external / siftgpu / src / TestWin / BasicTestWin.cpp @ 9240aaa3
History | View | Annotate | Download (4.88 KB)
1 |
////////////////////////////////////////////////////////////////////////////
|
---|---|
2 |
// File: BasicTestWin.cpp
|
3 |
// Author: Changchang Wu
|
4 |
// Description : implementation of the BasicTestWin class.
|
5 |
//
|
6 |
//
|
7 |
//
|
8 |
// Copyright (c) 2007 University of North Carolina at Chapel Hill
|
9 |
// All Rights Reserved
|
10 |
//
|
11 |
// Permission to use, copy, modify and distribute this software and its
|
12 |
// documentation for educational, research and non-profit purposes, without
|
13 |
// fee, and without a written agreement is hereby granted, provided that the
|
14 |
// above copyright notice and the following paragraph appear in all copies.
|
15 |
//
|
16 |
// The University of North Carolina at Chapel Hill make no representations
|
17 |
// about the suitability of this software for any purpose. It is provided
|
18 |
// 'as is' without express or implied warranty.
|
19 |
//
|
20 |
// Please send BUG REPORTS to ccwu@cs.unc.edu
|
21 |
//
|
22 |
////////////////////////////////////////////////////////////////////////////
|
23 |
#ifdef _WIN32
|
24 |
#define WIN32_LEAN_AND_MEAN
|
25 |
#include <windows.h> |
26 |
#define SIFTGPU_DLL
|
27 |
#endif
|
28 |
|
29 |
#include "time.h" |
30 |
#include "stdlib.h" |
31 |
#include <iostream> |
32 |
using std::iostream;
|
33 |
|
34 |
#ifdef __APPLE__
|
35 |
#include "OpenGL/OpenGL.h" |
36 |
#else
|
37 |
#include "GL/gl.h" |
38 |
#endif
|
39 |
|
40 |
#include "../SiftGPU/SiftGPU.h" |
41 |
#include "BasicTestWin.h" |
42 |
|
43 |
//////////////////////////////////////////////////////////////////////
|
44 |
// Construction/Destruction
|
45 |
//////////////////////////////////////////////////////////////////////
|
46 |
|
47 |
BasicTestWin::BasicTestWin() |
48 |
{ |
49 |
_view = 0;
|
50 |
_sub_view = 0;
|
51 |
_motion = 0;
|
52 |
_looping = 0;
|
53 |
_current = 0;
|
54 |
|
55 |
|
56 |
//
|
57 |
_win_w = _win_h = 0;
|
58 |
_imgWidth = _imgHeight = 0;
|
59 |
_displayScale = 1.0f; |
60 |
_sift = new SiftGPUEX();
|
61 |
} |
62 |
|
63 |
BasicTestWin::~BasicTestWin() |
64 |
{ |
65 |
_motion = 0;
|
66 |
_looping = 0;
|
67 |
} |
68 |
|
69 |
|
70 |
|
71 |
void BasicTestWin::Display()
|
72 |
{ |
73 |
glMatrixMode(GL_MODELVIEW); |
74 |
glLoadIdentity(); |
75 |
glClear(GL_COLOR_BUFFER_BIT); |
76 |
_transform.transform(_displayScale); |
77 |
if(_sift) _sift->DisplaySIFT();
|
78 |
glFlush(); |
79 |
glFinish(); |
80 |
|
81 |
} |
82 |
|
83 |
void BasicTestWin::OnIdle()
|
84 |
{ |
85 |
if(_looping && ! _motion)
|
86 |
{ |
87 |
KeyInput('r');
|
88 |
UpdateDisplay(); |
89 |
} |
90 |
|
91 |
} |
92 |
void BasicTestWin::KeyInput(int key) |
93 |
{ |
94 |
switch(key)
|
95 |
{ |
96 |
case '+': |
97 |
case '=': |
98 |
_transform.scaleup(); |
99 |
break;
|
100 |
case '-': |
101 |
_transform.scaledown(); |
102 |
break;
|
103 |
case '\r': |
104 |
_view++; |
105 |
_sub_view =0;
|
106 |
SetView(); |
107 |
break;
|
108 |
case '\b': |
109 |
_view--; |
110 |
_sub_view = 0;
|
111 |
SetView(); |
112 |
break;
|
113 |
case ' ': |
114 |
case '.': |
115 |
_sub_view++; |
116 |
SetView(); |
117 |
break;
|
118 |
case ',': |
119 |
_sub_view--; |
120 |
SetView(); |
121 |
break;
|
122 |
case 'o': |
123 |
case 'O': |
124 |
_transform.reset(); |
125 |
break;
|
126 |
case 'd': |
127 |
case 'D': |
128 |
if(_sift) _sift->ToggleDisplayDebug();
|
129 |
break;
|
130 |
case 'r': |
131 |
case 'R': |
132 |
if(_sift)
|
133 |
{ |
134 |
_sift->RunSIFT(++_current); |
135 |
_stat_frames++; |
136 |
FitWindow(); |
137 |
} |
138 |
break;
|
139 |
case 'c': |
140 |
case 'C': |
141 |
if(_sift) _sift->RandomizeColor();
|
142 |
break;
|
143 |
case 'q': |
144 |
case 'Q': |
145 |
if(_sift) _sift->SetVerbose(-1); |
146 |
break;
|
147 |
case 'v': |
148 |
if(_sift) _sift->SetVerbose(4); |
149 |
break;
|
150 |
case 'x': |
151 |
case 'X': |
152 |
case 27: |
153 |
exit(0);
|
154 |
break;
|
155 |
case 'l': |
156 |
case 'L': |
157 |
_looping = ! _looping; |
158 |
if(_looping)
|
159 |
{ |
160 |
_stat_tstart = (float)clock();
|
161 |
_stat_frames = 0;
|
162 |
}else
|
163 |
{ |
164 |
float t = ((float)clock() - _stat_tstart)/CLOCKS_PER_SEC; |
165 |
float fps = _stat_frames/t;
|
166 |
std::cout<<"************************************\n"
|
167 |
<<fps << " Hz : " << _stat_frames << " frames in " << t << " sec \n" |
168 |
<<"************************************\n";
|
169 |
} |
170 |
break;
|
171 |
} |
172 |
} |
173 |
|
174 |
|
175 |
|
176 |
void BasicTestWin::MoveMouse(int x, int y) |
177 |
{ |
178 |
if(_motion==0)return; |
179 |
_transform.translate(x-_motion_x, y-_motion_y); |
180 |
_motion_x = x; |
181 |
_motion_y = y; |
182 |
UpdateDisplay(); |
183 |
} |
184 |
|
185 |
void BasicTestWin::ReShape(int w, int h) |
186 |
{ |
187 |
glViewport(0, 0, w, h); |
188 |
glMatrixMode(GL_PROJECTION); |
189 |
glLoadIdentity(); |
190 |
glOrtho(0, w, h, 0,0,1); |
191 |
glMatrixMode(GL_MODELVIEW); |
192 |
glLoadIdentity(); |
193 |
|
194 |
_win_w = w; |
195 |
_win_h = h; |
196 |
} |
197 |
|
198 |
void BasicTestWin::RunSiftGPU()
|
199 |
{ |
200 |
if(_sift->RunSIFT())
|
201 |
{ |
202 |
_sift->SetVerbose(2);
|
203 |
FitWindow(); |
204 |
}else
|
205 |
{ |
206 |
exit(0);
|
207 |
} |
208 |
} |
209 |
|
210 |
void BasicTestWin::ParseSiftParam(int argc, char** argv) |
211 |
{ |
212 |
_sift->ParseParam(argc, argv); |
213 |
_sift->SetVerbose(5);
|
214 |
_win_x = _win_y = -1;
|
215 |
_sift->GetInitWindowPotition(_win_x, _win_y); |
216 |
} |
217 |
|
218 |
|
219 |
|
220 |
|
221 |
void BasicTestWin::FitWindow()
|
222 |
{ |
223 |
int w, h , dw, dh;
|
224 |
_sift->GetImageDimension(w, h); |
225 |
|
226 |
|
227 |
if(w <=0 || h <=0 ) return; |
228 |
|
229 |
|
230 |
if( w == _imgWidth || h == _imgHeight)
|
231 |
{ |
232 |
ReShape(_win_w, _win_h); |
233 |
return;
|
234 |
} |
235 |
|
236 |
|
237 |
_transform.setcenter(w*0.5, h*0.5); |
238 |
|
239 |
///
|
240 |
|
241 |
dw =_imgWidth = w; |
242 |
dh =_imgHeight = h; |
243 |
|
244 |
_displayScale = 1.0; |
245 |
|
246 |
while(dw>1024 || dh >1024) |
247 |
{ |
248 |
dw>>=1;
|
249 |
dh>>=1;
|
250 |
_displayScale *= 0.5; |
251 |
} |
252 |
|
253 |
while(dw < 512 && dh < 512) |
254 |
{ |
255 |
dw <<= 1;
|
256 |
dh <<= 1;
|
257 |
_displayScale*= 2.0; |
258 |
} |
259 |
|
260 |
if ( dw > _win_w || dh > _win_h)
|
261 |
{ |
262 |
_win_w = dw; |
263 |
_win_h = dh; |
264 |
SetDisplaySize(dw, dh); |
265 |
}else
|
266 |
{ |
267 |
ReShape(_win_w, _win_h); |
268 |
} |
269 |
} |
270 |
|
271 |
|
272 |
|
273 |
|
274 |
void BasicTestWin::SetView()
|
275 |
{ |
276 |
if(_sift)
|
277 |
{ |
278 |
_sift->SetView(_view, _sub_view, _title); |
279 |
SetWindowTitle(_title); |
280 |
} |
281 |
} |
282 |
|
283 |
void BasicTestWin::StartMotion(int x, int y) |
284 |
{ |
285 |
_motion = 1;
|
286 |
_motion_x = x; |
287 |
_motion_y = y; |
288 |
} |
289 |
|
290 |
void BasicTestWin::EndMotion()
|
291 |
{ |
292 |
_motion = 0;
|
293 |
} |
294 |
|
295 |
|
296 |
void BasicTestWin::SetVerbose()
|
297 |
{ |
298 |
_sift->SetVerbose(); |
299 |
} |