Blender V2.61 - r43446

utilities.h

Go to the documentation of this file.
00001 
00004 /******************************************************************************
00005  *
00006  * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method
00007  * Copyright 2003-2006 Nils Thuerey
00008  *
00009  * Global C style utility funcions
00010  *
00011  *****************************************************************************/
00012 #ifndef UTILITIES_H
00013 #include "ntl_vector3dim.h"
00014 
00015 
00016 /* debugging outputs , debug level 0 (off) to 10 (max) */
00017 #ifdef ELBEEM_PLUGIN
00018 #ifdef DEBUG
00019 #undef DEBUG
00020 #endif
00021 #define DEBUG 0
00022 #else // ELBEEM_PLUGIN
00023 #define DEBUG 10
00024 #endif // ELBEEM_PLUGIN
00025 extern "C" int gDebugLevel;
00026 
00027 
00028 // time measurements
00029 typedef unsigned long myTime_t;
00030 
00031 
00032 // state of the simulation world
00033 // default
00034 #define SIMWORLD_INVALID       0
00035 // performing init
00036 #define SIMWORLD_INITIALIZING  1
00037 // after init, before starting simulation
00038 #define SIMWORLD_INITED        2
00039 // stop of the simulation run, can be continued later
00040 #define SIMWORLD_STOP          3
00041 // error during init
00042 #define SIMWORLD_INITERROR    -1
00043 // error during simulation
00044 #define SIMWORLD_PANIC        -2
00045 // general error 
00046 #define SIMWORLD_GENERICERROR -3
00047 
00048 // access global state of elbeem simulator
00049 void setElbeemState(int set);
00050 int  getElbeemState(void);
00051 int  isSimworldOk(void);
00052 
00053 // access elbeem simulator error string
00054 void setElbeemErrorString(const char* set);
00055 char* getElbeemErrorString(void);
00056 
00057 
00058 /* debug output function */
00059 #define DM_MSG        1
00060 #define DM_NOTIFY     2
00061 #define DM_IMPORTANT  3
00062 #define DM_WARNING    4
00063 #define DM_ERROR      5
00064 #define DM_DIRECT     6
00065 #define DM_FATAL      7
00066 void messageOutputFunc(string from, int id, string msg, myTime_t interval);
00067 
00068 /* debugging messages defines */
00069 #ifdef DEBUG 
00070 #if LBM_PRECISION==2
00071 #define MSGSTREAM std::ostringstream msg; msg.precision(15); msg.width(17);
00072 #else
00073 #define MSGSTREAM std::ostringstream msg; msg.precision(7); msg.width(9);
00074 #endif
00075 
00076 #   define debMsgDirect(mStr)                         if(gDebugLevel>0)      { std::ostringstream msg; msg << mStr; messageOutputFunc(string(""), DM_DIRECT, msg.str(), 0); }
00077 #   define debMsgStd(from,id,mStr,level)              if(gDebugLevel>=level) { MSGSTREAM; msg << mStr <<"\n"; messageOutputFunc(from, id, msg.str(), 0); }
00078 #   define debMsgNnl(from,id,mStr,level)              if(gDebugLevel>=level) { MSGSTREAM; msg << mStr       ; messageOutputFunc(from, id, msg.str(), 0); }
00079 #   define debMsgInter(from,id,mStr,level, interval)  if(gDebugLevel>=level) { MSGSTREAM; msg << mStr <<"\n"; messageOutputFunc(from, id, msg.str(), interval); }
00080 #   define debugOut(mStr,level)                       if(gDebugLevel>=level) { debMsgStd("D",DM_MSG,mStr,level); }
00081 #   define debugOutNnl(mStr,level)                    if(gDebugLevel>=level) { debMsgNnl("D",DM_MSG,mStr,level); }
00082 #   define debugOutInter(mStr,level, interval)        debMsgInter("D",DM_MSG ,mStr,level, interval); 
00083 /* Error output function */
00084 #define errMsg(from,mStr)                           if(gDebugLevel>0){ MSGSTREAM; msg << mStr <<"\n"; messageOutputFunc(from, DM_ERROR,   msg.str(), 0); }
00085 #define warnMsg(from,mStr)                          if(gDebugLevel>0){ MSGSTREAM; msg << mStr <<"\n"; messageOutputFunc(from, DM_WARNING, msg.str(), 0); }
00086 
00087 #else
00088 // no messages at all...
00089 #   define debMsgDirect(mStr)
00090 #   define debMsgStd(from,id,mStr,level)
00091 #   define debMsgNnl(from,id,mStr,level)
00092 #   define debMsgInter(from,id,mStr,level, interval)
00093 #   define debugOut(mStr,level)  
00094 #   define debugOutNnl(mStr,level)  
00095 #   define debugOutInter(mStr,level, interval) 
00096 #   define errMsg(from,mStr)
00097 #   define warnMsg(from,mStr)
00098 #endif
00099 
00100 #define errorOut(mStr) { errMsg("D",mStr); }
00101 
00102 // fatal errors - have to be handled 
00103 #define errFatal(from,mStr,errCode) { \
00104     setElbeemState(errCode); \
00105     MSGSTREAM; msg << mStr; \
00106     messageOutputFunc(from, DM_FATAL, msg.str(), 0); \
00107 }
00108 
00109 
00111 int convertString2Int(const char *str, int alt);
00112 
00114 string convertFlags2String(int flags);
00115 
00117 myTime_t getTime();
00119 string getTimeString(myTime_t usecs);
00120 
00122 bool checkBoundingBox(ntlVec3Gfx s, ntlVec3Gfx e, string checker);
00123 
00125 void resetGlobalColorSetting();
00126 
00127 
00129 #define PRINT_VEC(x,y,z) " ["<<(x)<<","<<(y)<<","<<(z)<<"] "
00130 
00132 #define PRINT_VEC2D(x,y) " ["<<(x)<<","<<(y)<<"] "
00133 
00135 #define PRINT_IJK_NBL PRINT_VEC(i+D::dfVecX[l],j+D::dfVecY[l],k+D::dfVecZ[l])
00136 
00138 #define PRINT_IJK PRINT_VEC(i,j,k)
00139 
00141 #define PRINT_IJ PRINT_VEC2D(i,j)
00142 
00144 #define PRINT_NTLVEC(v) " ["<<(v)[0]<<","<<(v)[1]<<","<<(v)[2]<<"] "
00145 
00147 #define PRINT_NTLVEC2D(v) " ["<<(v)[0]<<","<<(v)[1]<<"] "
00148 
00150 #define PRINT_TRIANGLE(t,mpV)  " { "<<PRINT_VEC( (mpV[(t).getPoints()[0]][0]),(mpV[(t).getPoints()[0]][1]),(mpV[(t).getPoints()[0]][2]) )<<\
00151     PRINT_VEC( (mpV[(t).getPoints()[1]][0]),(mpV[(t).getPoints()[1]][1]),(mpV[(t).getPoints()[1]][2]) )<<" | "<<\
00152     PRINT_VEC( (mpV[(t).getPoints()[2]][0]),(mpV[(t).getPoints()[2]][1]),(mpV[(t).getPoints()[2]][2]) )<<" } "
00153 
00154 
00155 // write png image
00156 int writePng(const char *fileName, unsigned char **rowsp, int w, int h);
00157 
00158 /* some useful templated functions 
00159  * may require some operators for the classes
00160  */
00161 
00162 /* minimum */
00163 #ifdef MIN
00164 #undef MIN
00165 #endif
00166 template < class T >
00167 inline T
00168 MIN( T a, T b )
00169 { return (a < b) ? a : b ; }
00170 
00171 /* maximum */
00172 #ifdef MAX
00173 #undef MAX
00174 #endif
00175 template < class T >
00176 inline T
00177 MAX( T a, T b )
00178 { return (a < b) ? b : a ; }
00179 
00180 /* absolute value */
00181 template < class T >
00182 inline T
00183 ABS( T a )
00184 { return (0 < a) ? a : -a ; }
00185 
00186 /* sign of the value */
00187 template < class T >
00188 inline T
00189 SIGNUM( T a )
00190 { return (0 < a) ? 1 : -1 ; }
00191 
00192 /* sign, returns -1,0,1 depending on sign/value=0 */
00193 template < class T >
00194 inline T
00195 SIGNUM0( T a )
00196 { return (0 < a) ? 1 : ( a < 0 ? -1 : 0 ) ; }
00197 
00198 /* round to nearest integer */
00199 inline int
00200 ROUND(double d)
00201 { return int(d + 0.5); }
00202 
00203 /* square function */
00204 template < class T >
00205 inline T
00206 SQUARE( T a )
00207 { return a*a; }
00208 
00209 
00210 #define UTILITIES_H
00211 #endif