Definitions.h

Go to the documentation of this file.
00001 /* $Id: Definitions.h,v 1.4 2002/11/05 14:31:15 anonymous Exp $ */
00002 
00003 #ifndef __DEFINITIONS_H
00004 #define __DEFINITIONS_H
00005 
00006 #ifdef WIN32
00007 #include <wtypes.h>
00008 #undef max
00009 #endif
00010 
00011 #include <vecmath/Vector4d.h>
00012 #include <vecmath/Vector4f.h>
00013 #include <vecmath/Vector3f.h>
00014 #include <vecmath/Vector3d.h>
00015 #include <vecmath/Vector2f.h>
00016 #include <vecmath/Vector2d.h>
00017 #include <vecmath/Matrix3f.h>
00018 #include <vecmath/Matrix4f.h>
00019 #include <vecmath/Matrix3d.h>
00020 #include <vecmath/Matrix4d.h>
00021 #include <vecmath/Color3f.h>
00022 
00023 //#if defined(_MSC_VER)
00024 #include <float.h>
00025 #define MAXFLOAT FLT_MAX
00026 #define MAXDOUBLE DBL_MAX
00027 #define MINDOUBLE DBL_MIN
00028 //#else
00029 //#include <values.h>
00030 //#endif
00031 
00032 #include <math.h>
00033 #include <typeinfo>
00034 #include <stack>
00035 
00036 #include <esg/Export>
00037 
00042 #if defined(WIN32) && !defined(__MINGW32__) 
00043 #  include <hash_map>       
00044      namespace Sgi = std; 
00045 #else 
00046 #  if (__GNUC__ < 3) 
00047 #    include <hash_map> 
00048     namespace Sgi { using ::hash_map; }; /* inherit globals */ 
00049 #  else 
00050 #    include <ext/hash_map> 
00051 #    if (__GNUC__ == 3 && __GNUC_MINOR__ == 0) 
00052     namespace Sgi = std;                 /* GCC 3.0 */ 
00053 #    else 
00054     namespace Sgi = ::__gnu_cxx;         /* GCC 3.1 and later */ 
00055 #    endif 
00056 #  endif 
00057 #endif 
00058 
00059 using namespace std;
00060 
00061 
00062 namespace esg {
00063 
00064 class OGSCENE_EXPORT SceneGraphObject; // declaration
00065 
00066 typedef Vector4d Vector4;
00067 typedef Vector3d Vector3;
00068 typedef Vector3d Vertex3;
00069 typedef Vector2d Vector2;
00070 typedef Vector2d Vertex2;
00071 typedef Matrix3d Matrix3;
00072 typedef Matrix4d Matrix4;
00073 typedef double   ESGfloat;
00074 typedef int      ESGbitmask;
00075 typedef int      ESGint;
00076 
00077 #define ESG_MAXFLOAT  MAXDOUBLE
00078 #define ESG_MINFLOAT -MAXDOUBLE
00079 
00080 #define MAX_VEC_VALUE  MAXFLOAT
00081 #define MIN_VEC_VALUE -MAXFLOAT
00082 
00083 #ifndef MAXUNSIGNED
00084 #define MAXUNSIGNED UINT_MAX
00085 #endif
00086 #ifndef MINUNSIGNED
00087 #define MINUNSIGNED UINT_MIN
00088 #endif
00089 
00090 #ifndef PI
00091 #define PI M_PI
00092 #endif
00093 
00094 
00095 struct Cache {
00096     virtual ~Cache() {}
00097 };
00098 
00099 
00100 struct Interval {
00101     float min;
00102     float max;
00103 
00104 #ifdef WIN32
00105     Interval (float a = MAXFLOAT, float b = -MAXFLOAT) { min = a; max = b; }
00106     Interval (const Interval& src) { min = src.min; max = src.max; }
00107 #else
00108     Interval (float a = MAXFLOAT, float b = -MAXFLOAT) : min(a), max(b) {}
00109     Interval (const Interval& src) : min(src.min), max(src.max) {}
00110 #endif
00111 };
00112 
00113 
00114 #define IS_INSTANCE_OF(a,b) (typeid(a) == typeid(b))
00115 
00116     /*
00117      * Macros for ray transformation
00118      */
00119 
00120 #define ESG_INVERSE_TR_RAY(rMat,tVec,sVec,srcO,dstO,srcD,dstD) {\
00121     (rMat).transpose(); \
00122     (rMat).transform(srcD, dstD); \
00123     (dstO).sub(srcO, tVec);   /* origin = (R^T * origin) - (R^T * tr) = */ \
00124     (rMat).transform(dstO);   /*        = R^T * (origin - tr)           */ \
00125     if ((sVec).x) (dstO).x *= 1.0 / (sVec).x; \
00126     if ((sVec).y) (dstO).y *= 1.0 / (sVec).y; \
00127     if ((sVec).z) (dstO).z *= 1.0 / (sVec).z; }
00128 
00129 #define ESG_INVERSE_TR_POINT(rMat, tVec, sVec, srcP, dstP) { \
00130     (rMat).transpose(); \
00131     (dstP).sub(srcP, tVec); \
00132     (rMat).transform(dstP); \
00133     if ((sVec).x) (dstP).x *= 1.0 / (sVec).x; \
00134     if ((sVec).y) (dstP).y *= 1.0 / (sVec).y; \
00135     if ((sVec).z) (dstP).z *= 1.0 / (sVec).z; }
00136 
00137 #define ESG_INVERSE_TR_DIR(rMat, srcD, dstD) { \
00138     (rMat).transpose(); \
00139     (rMat).transform(srcD, dstD); }
00140 
00141     /*
00142      * Random number generators
00143      */
00144     //#define ESG_INIT_RAND()  { srand((unsigned int) time(NULL)); }
00145     //#define ESG_DBL_RAND_H   ((double)(    (double)rand()/(RAND_MAX + 1.0)))//[0,1)
00146     //#define ESG_DBL_RAND_F   ((double)(    (double)rand()/(double)RAND_MAX))//[0,1]
00147     //#define ESG_INT_RAND_H(x)((int)   ((x)*(double)rand()/(RAND_MAX + 1.0)))//[0,x)
00148     //#define ESG_INT_RAND_F(x)((int)   ((x)*(double)rand()/(double)RAND_MAX))//[0,x]
00149     
00150 #define ESG_INIT_RAND() { srand((long int) time(NULL)); }
00151 
00152 #ifdef WIN32
00153 #define ESG_DBL_RAND ((double)((double)rand()/(RAND_MAX + 1.0))) //[0,1)
00154 #else
00155 #define ESG_DBL_RAND ((double)drand48()) //[0,1)
00156 #endif
00157     
00158 #define ESG_INT_RAND(x) ((int)((x)*(double)rand()/(RAND_MAX + 1.0))) //[0,x)
00159 
00160     
00161     /*
00162      * Portable gaussian random number generator
00163      * (from "Numerical Recipes", GASDEV)
00164      * Returns a uniform random deviate between 0.0 and 1.0.  'iseed' must be
00165      * less than M1 to avoid repetition, and less than (2**31-C1)/A1 [= 300718]
00166      * to avoid overflow.
00167      */
00168 #define ESG_M1  134456
00169 #define ESG_IA1   8121
00170 #define ESG_IC1  28411
00171 #define ESG_RM1 1.0/ESG_M1
00172 
00173 #define ESG_GAUSS_RAND(/*long*/ iseed, ret) { \
00174     double v1, v2, r; \
00175     long   ix1 = 0; \
00176     long   ix2 = (iseed); \
00177     do { \
00178         ix1 = (ESG_IC1 + ix2 * ESG_IA1) % ESG_M1; \
00179         ix2 = (ESG_IC1 + ix1 * ESG_IA1) % ESG_M1; \
00180         v1  = ix1 * 2.0 * ESG_RM1 - 1.0; \
00181         v2  = ix2 * 2.0 * ESG_RM1 - 1.0; \
00182         r   = v1 * v1 + v2 * v2; \
00183     } while (r >= 1.0); \
00184     ret = v1 * sqrt((double)(-2.0 * log((double)r) / r)); \
00185 }
00186 
00187     /*
00188      * Bob Jenkins invented this great, reasonably fast, very nice
00189      * hash function.  Check out his web page:
00190      * http://ourworld.compuserve.com/homepages/bob_jenkins/blockcip.htm
00191      */
00192 #define ESG_HASH_RAND(/*int*/ _a, /*int*/ _b, /*int*/ _c, ret) { \
00193     int a = _a; \
00194     int b = _b; \
00195     int c = _c; \
00196     a -= b; a -= c; a ^= (c>>13); \
00197     b -= c; b -= a; b ^= (a<<8);  \
00198     c -= a; c -= b; c ^= (b>>13); \
00199     a -= b; a -= c; a ^= (c>>12); \
00200     b -= c; b -= a; b ^= (a<<16); \
00201     c -= a; c -= b; c ^= (b>>5);  \
00202     a -= b; a -= c; a ^= (c>>3);  \
00203     b -= c; b -= a; b ^= (a<<10); \
00204     c -= a; c -= b; c ^= (b>>15); \
00205     ret = c & 0xffff ; \
00206 }
00207 
00208 
00209 }; // namespace
00210 
00211 #endif // __DEFINITIONS_H

Generated on Wed Jun 28 12:24:28 2006 for esg by  doxygen 1.4.6