BasicTestWin.cpp
Go to the documentation of this file.
00001 
00002 //      File:           BasicTestWin.cpp
00003 //      Author:         Changchang Wu
00004 //      Description : implementation of the BasicTestWin class.
00005 //
00006 //
00007 //
00008 //      Copyright (c) 2007 University of North Carolina at Chapel Hill
00009 //      All Rights Reserved
00010 //
00011 //      Permission to use, copy, modify and distribute this software and its
00012 //      documentation for educational, research and non-profit purposes, without
00013 //      fee, and without a written agreement is hereby granted, provided that the
00014 //      above copyright notice and the following paragraph appear in all copies.
00015 //      
00016 //      The University of North Carolina at Chapel Hill make no representations
00017 //      about the suitability of this software for any purpose. It is provided
00018 //      'as is' without express or implied warranty. 
00019 //
00020 //      Please send BUG REPORTS to ccwu@cs.unc.edu
00021 //
00023 #ifdef _WIN32
00024 #define WIN32_LEAN_AND_MEAN
00025 #include <windows.h>
00026 #define SIFTGPU_DLL
00027 #endif
00028 
00029 #include "time.h"
00030 #include "stdlib.h"
00031 #include <iostream>
00032 using std::iostream;
00033 
00034 #ifdef __APPLE__
00035         #include "OpenGL/OpenGL.h"
00036 #else
00037         #include "GL/gl.h"
00038 #endif
00039 
00040 #include "../SiftGPU/SiftGPU.h"
00041 #include "BasicTestWin.h"
00042 
00044 // Construction/Destruction
00046 
00047 BasicTestWin::BasicTestWin()
00048 {
00049         _view = 0;
00050         _sub_view = 0;
00051         _motion = 0;
00052         _looping = 0;
00053         _current = 0;
00054 
00055 
00056         //
00057         _win_w = _win_h = 0;
00058         _imgWidth = _imgHeight = 0;
00059         _displayScale = 1.0f;
00060         _sift = new SiftGPUEX();
00061 }
00062 
00063 BasicTestWin::~BasicTestWin()
00064 {
00065         _motion = 0;
00066         _looping = 0;
00067 }
00068 
00069 
00070 
00071 void BasicTestWin::Display()
00072 {
00073         glMatrixMode(GL_MODELVIEW);
00074         glLoadIdentity();
00075         glClear(GL_COLOR_BUFFER_BIT);
00076         _transform.transform(_displayScale);
00077         if(_sift)       _sift->DisplaySIFT();
00078         glFlush();
00079         glFinish();
00080 
00081 }
00082 
00083 void BasicTestWin::OnIdle()
00084 {
00085         if(_looping && ! _motion)
00086         {
00087                 KeyInput('r');
00088                 UpdateDisplay();
00089         }
00090 
00091 }
00092 void BasicTestWin::KeyInput(int  key)
00093 {
00094         switch(key)
00095         {
00096         case '+':
00097         case '=':
00098                 _transform.scaleup();
00099                 break;
00100         case '-':
00101                 _transform.scaledown();
00102                 break;
00103         case '\r':
00104                 _view++;
00105                 _sub_view =0;
00106                 SetView();
00107                 break;
00108         case '\b':
00109                 _view--;
00110                 _sub_view = 0;
00111                 SetView();
00112                 break;
00113         case ' ':
00114         case '.':
00115                 _sub_view++;
00116                 SetView();
00117                 break;
00118         case ',':
00119                 _sub_view--;
00120                 SetView();
00121                 break;
00122         case 'o':
00123         case 'O':
00124                 _transform.reset();
00125                 break;
00126         case 'd':
00127         case 'D':
00128                 if(_sift) _sift->ToggleDisplayDebug();
00129                 break;
00130         case 'r':
00131         case 'R':
00132                 if(_sift)
00133                 {
00134                         _sift->RunSIFT(++_current);
00135                         _stat_frames++;
00136                         FitWindow();
00137                 }
00138                 break;
00139         case 'c':
00140         case 'C':
00141                 if(_sift) _sift->RandomizeColor();
00142                 break;
00143         case 'q':
00144         case 'Q':
00145                 if(_sift) _sift->SetVerbose(-1);
00146                 break;
00147         case 'v':
00148                 if(_sift) _sift->SetVerbose(4);
00149                 break;
00150         case 'x':
00151         case 'X':
00152         case 27:
00153                 exit(0);
00154                 break;
00155         case 'l':
00156         case 'L':
00157                 _looping = ! _looping;
00158                 if(_looping)
00159                 {
00160                         _stat_tstart = (float)clock();
00161                         _stat_frames = 0;
00162                 }else
00163                 {
00164                         float t   = ((float)clock() - _stat_tstart)/CLOCKS_PER_SEC;
00165                         float fps = _stat_frames/t; 
00166                         std::cout<<"************************************\n"
00167                                      <<fps << " Hz : " << _stat_frames << " frames in " << t << " sec \n"
00168                                      <<"************************************\n";
00169                 }
00170                 break;
00171         }
00172 }
00173 
00174 
00175 
00176 void BasicTestWin::MoveMouse(int x, int y)
00177 {
00178         if(_motion==0)return;
00179         _transform.translate(x-_motion_x, y-_motion_y);
00180         _motion_x = x;
00181         _motion_y = y;
00182         UpdateDisplay();
00183 }
00184 
00185 void BasicTestWin::ReShape(int w, int h)
00186 {
00187         glViewport(0, 0, w, h);            
00188     glMatrixMode(GL_PROJECTION);    
00189     glLoadIdentity();               
00190         glOrtho(0, w, h, 0,0,1);
00191     glMatrixMode(GL_MODELVIEW);     
00192     glLoadIdentity();  
00193 
00194         _win_w = w;
00195         _win_h = h;
00196 }
00197 
00198 void BasicTestWin::RunSiftGPU()
00199 {
00200         if(_sift->RunSIFT())
00201         {
00202                 _sift->SetVerbose(2);
00203                 FitWindow();
00204         }else
00205         {
00206                 exit(0);
00207         }
00208 }
00209 
00210 void BasicTestWin::ParseSiftParam(int argc, char** argv)
00211 {
00212         _sift->ParseParam(argc, argv);
00213         _sift->SetVerbose(5);
00214         _win_x = _win_y = -1;
00215         _sift->GetInitWindowPotition(_win_x, _win_y);
00216 }
00217 
00218 
00219 
00220 
00221 void BasicTestWin::FitWindow()
00222 {
00223         int w, h , dw, dh;
00224         _sift->GetImageDimension(w, h);
00225         
00226 
00227         if(w <=0 || h <=0 ) return;
00228 
00229 
00230         if( w == _imgWidth || h == _imgHeight)
00231         {
00232                 ReShape(_win_w, _win_h);
00233                 return;
00234         }
00235         
00236         
00237         _transform.setcenter(w*0.5, h*0.5);
00238 
00240 
00241         dw =_imgWidth = w;
00242         dh =_imgHeight = h;
00243 
00244         _displayScale = 1.0;
00245 
00246         while(dw>1024 || dh >1024)
00247         {
00248                 dw>>=1;
00249                 dh>>=1;
00250                 _displayScale *= 0.5;
00251         }
00252 
00253         while(dw < 512 && dh < 512)
00254         {
00255                 dw <<= 1;
00256                 dh <<= 1;
00257                 _displayScale*= 2.0;
00258         }
00259 
00260         if ( dw > _win_w || dh > _win_h)
00261         {
00262                 _win_w = dw;
00263                 _win_h = dh;
00264                 SetDisplaySize(dw, dh);
00265         }else
00266         {
00267                 ReShape(_win_w, _win_h);
00268         }
00269 }
00270 
00271 
00272 
00273 
00274 void BasicTestWin::SetView()
00275 {
00276         if(_sift)
00277         {
00278                 _sift->SetView(_view, _sub_view, _title);
00279                 SetWindowTitle(_title);
00280         }
00281 }
00282 
00283 void BasicTestWin::StartMotion(int x, int y)
00284 {
00285         _motion = 1;
00286         _motion_x = x;
00287         _motion_y = y;
00288 }
00289 
00290 void BasicTestWin::EndMotion()
00291 {
00292         _motion = 0;
00293 }
00294 
00295 
00296 void BasicTestWin::SetVerbose()
00297 {
00298         _sift->SetVerbose();
00299 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


rgbd_registration
Author(s): Ross Kidson
autogenerated on Thu May 23 2013 15:36:52