00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __UTILITIES_H_
00019 #define __UTILITIES_H_
00020
00021
00022 #ifdef _WIN32
00023 #include <windows.h>
00024 #include <gl/gl.h>
00025 #include <gl/glu.h>
00026 #include "gl/glut.h"
00027 #include "ipc.h"
00028
00029
00030 #elif __APPLE__
00031 #include <unistd.h>
00032 #include <sys/time.h>
00033 #include <ipc.h>
00034
00035
00036 #else
00037 #include <unistd.h>
00038 #include <sys/time.h>
00039 #include <ipc/ipc.h>
00040 #include <opencv/cv.h>
00041 #include <opencv/highgui.h>
00042
00043 #endif
00044
00045
00046 #include <stdlib.h>
00047 #include <iostream>
00048 #include <fstream>
00049 #include <stdio.h>
00050 #include <string.h>
00051 #include <math.h>
00052
00053
00054
00055
00056 using namespace std;
00057
00060 #define Assert(Assertion, FailText) __Assert( (Assertion), (FailText), __FILE__, __LINE__)
00061
00062
00063 #define PI 3.14159265
00064
00067 void __Assert(bool Assertion, const char* FailText, const char* FileName, int LineNumber);
00068
00071 void UtilSleep(float SleepTime);
00072
00074 void UtilGetTime(unsigned int* seconds, unsigned int* milliseconds);
00075
00076
00077 #if _WIN32
00078
00080 class HighresClock
00081 {
00082 public:
00083
00084 HighresClock()
00085 {
00086
00087 QueryPerformanceFrequency(&TicksPerSec);
00088
00089
00090 QueryPerformanceCounter(&startTime);
00091
00092
00093 Start(); Stop();
00094 }
00095
00096 void Stop()
00097 {
00098 QueryPerformanceCounter(&endTime);
00099 }
00100
00101
00102 float GetTime()
00103 {
00104
00105 cpuTime.QuadPart = endTime.QuadPart - startTime.QuadPart;
00106 return (float)cpuTime.QuadPart / (float)TicksPerSec.QuadPart;
00107 }
00108
00109 void Start()
00110 {
00111 QueryPerformanceCounter(&startTime);
00112 }
00113
00114 private:
00115 LARGE_INTEGER TicksPerSec;
00116 LARGE_INTEGER startTime, endTime, cpuTime;
00117 };
00118
00119
00120 #else
00121
00123 class HighresClock
00124 {
00125 public:
00126
00127 HighresClock()
00128 {
00129
00130 gettimeofday(&startTime, NULL);
00131
00132
00133 Start(); Stop();
00134 }
00135
00136 void Stop()
00137 {
00138 gettimeofday(&endTime, NULL);
00139 }
00140
00141 float GetTime()
00142 {
00143
00144
00145 float secondDif = float(endTime.tv_sec - startTime.tv_sec);
00146 return float(float(endTime.tv_usec) / 1000.0f - float(startTime.tv_usec) / 1000.0f) / 1000.0f + secondDif;
00147 }
00148
00149 void Start()
00150 {
00151 gettimeofday(&startTime, NULL);
00152 }
00153
00154 private:
00155 struct timeval startTime, endTime;
00156 };
00157
00158 #endif // End of UNIX version
00159
00162 void itoa(char *dest, int val);
00163
00164
00165 #endif