1 ////////////////////////////////////////////////////////////////////////////
2 //	File:		GlobalUtil.h
3 //	Author:		Changchang Wu
4 //	Description :
5 //		GlobalParam:	Global parameters
6 //		ClockTimer:		Timer
7 //		GlobalUtil:		Global Function wrapper
8 //
9 //	Copyright (c) 2007 University of North Carolina at Chapel Hill
10 //	All Rights Reserved
11 //
12 //	Permission to use, copy, modify and distribute this software and its
13 //	documentation for educational, research and non-profit purposes, without
14 //	fee, and without a written agreement is hereby granted, provided that the
15 //	above copyright notice and the following paragraph appear in all copies.
16 //
17 //	The University of North Carolina at Chapel Hill make no representations
18 //	about the suitability of this software for any purpose. It is provided
19 //	'as is' without express or implied warranty.
20 //
21 //	Please send BUG REPORTS to ccwu@cs.unc.edu
22 //
23 ////////////////////////////////////////////////////////////////////////////
24 
25 
26 #ifndef _GLOBAL_UTILITY_H
27 #define _GLOBAL_UTILITY_H
28 
29 
30 //wrapper for some shader function
31 //class ProgramGPU;
32 class LiteWindow;
33 
34 class GlobalParam
35 {
36 public:
37 	static GLuint	_texTarget;
38 	static GLuint   _iTexFormat;
39 	static int		_texMaxDim;
40 	static int		_texMaxDimGL;
41     static int      _texMinDim;
42 	static int		_MemCapGPU;
43 	static int		_FitMemoryCap;
44 	static int		_verbose;
45 	static int		_timingS;
46 	static int		_timingO;
47 	static int		_timingL;
48 	static int		_usePackedTex;
49 	static int		_IsNvidia;
50 	static int		_KeepShaderLoop;
51 	static int		_UseCUDA;
52     static int      _UseOpenCL;
53 	static int		_UseDynamicIndexing;
54 	static int		_debug;
55 	static int		_MaxFilterWidth;
56 	static float	_FilterWidthFactor;
57 	static float    _OrientationWindowFactor;
58 	static float	_DescriptorWindowFactor;
59 	static int		_MaxOrientation;
60 	static int      _OrientationPack2;
61 	static int		_ListGenGPU;
62 	static int		_ListGenSkipGPU;
63 	static int		_SupportNVFloat;
64 	static int		_SupportTextureRG;
65 	static int		_FullSupported;
66 	static float	_MaxFeaturePercent;
67 	static int		_MaxLevelFeatureNum;
68 	static int		_DescriptorPPR;
69 	static int		_DescriptorPPT; //pixel per texture for one descriptor
70 	static int		_FeatureTexBlock;
71 	static int		_NarrowFeatureTex; //implemented but no performance improvement
72 	static int		_SubpixelLocalization;
73 	static int		_ProcessOBO; //not implemented yet
74     static int      _TruncateMethod;
75 	static int		_PreciseBorder; //implemented
76 	static int		_UseSiftGPUEX;
77 	static int		_ForceTightPyramid;
78 	static int		_octave_min_default;
79 	static int		_octave_num_default;
80 	static int		_InitPyramidWidth;
81 	static int		_InitPyramidHeight;
82 	static int		_PreProcessOnCPU;
83 	static int		_GoodOpenGL;
84 	static int		_FixedOrientation;
85 	static int		_LoweOrigin;
86 	static int		_ExitAfterSIFT;
87 	static int		_NormalizedSIFT;
88 	static int		_BinarySIFT;
89 	static int		_KeepExtremumSign;
90 	static int		_FeatureCountThreshold;
91     static int      _KeyPointListForceLevel0;
92 	static int		_DarknessAdaption;
93 
94 	//for compatability with old version:
95 	static float	_OrientationExtraFactor;
96 	static float	_OrientationGaussianFactor;
97 	static float    _MulitiOrientationThreshold;
98 
99 	////////////////////////////////////////
100 	static int				_WindowInitX;
101 	static int				_WindowInitY;
102 	static const char*		_WindowDisplay;
103     static int              _DeviceIndex;
104 };
105 
106 
107 class ClockTimer
108 {
109 private:
110 	char _current_event[256];
111 	int  _time_start;
112 	int  _time_stop;
113 public:
114 	static int	  ClockMS();
115 	static double CLOCK();
116 	static void	  InitHighResolution();
117 	void StopTimer(int verb = 1);
118 	void StartTimer(const char * event, int verb=0);
119 	float  GetElapsedTime();
120 };
121 
122 class GlobalUtil:public GlobalParam
123 {
124     static ClockTimer _globalTimer;
125 public:
CLOCK()126 	inline static double CLOCK()				{	return ClockTimer::CLOCK();			}
StopTimer()127 	inline static void StopTimer()				{	_globalTimer.StopTimer(_timingS);			}
StartTimer(const char * event)128 	inline static void StartTimer(const char * event)	{	_globalTimer.StartTimer(event, _timingO);	}
GetElapsedTime()129 	inline static float GetElapsedTime()		{	return _globalTimer.GetElapsedTime();		}
130 
131 	static void FitViewPort(int width, int height);
132 	static void SetTextureParameter();
133 	static void SetTextureParameterUS();
134 #ifdef _DEBUG
135 	static void CheckErrorsGL(const char* location = NULL);
136 #else
137 	static void inline CheckErrorsGL(const char* location = NULL){};
138 #endif
139 	static bool CheckFramebufferStatus();
140 	//initialize Opengl parameters
141 	static void SelectDisplay();
142 	static void InitGLParam(int NotTargetGL = 0);
143 	static void SetGLParam();
144 	static int  CreateWindowEZ();
145 	static void CleanupOpenGL();
146     static void SetDeviceParam(int argc, char** argv);
147     static int  CreateWindowEZ(LiteWindow* window);
148 };
149 
150 
151 #if defined(_MSC_VER) && _MSC_VER == 1200
152 #define max(a,b)    (((a) > (b)) ? (a) : (b))
153 #define min(a,b)    (((a) < (b)) ? (a) : (b))
154 #endif
155 
156 #endif
157 
158