00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef MACROS_H
00018 #define MACROS_H
00019
00020 #ifndef DEG2RAD
00021 #define DEG2RAD(x) ((x) * 0.01745329251994329575)
00022 #endif
00023
00024 #ifndef RAD2DEG
00025 #define RAD2DEG(x) ((x) * 57.29577951308232087721)
00026 #endif
00027
00028
00029 #ifdef __cplusplus
00030
00031 #define READ_FILE(fvar,fname) \
00032 std::ifstream fvar(fname);\
00033 if (!fvar) throw std::runtime_error("Could not open file for reading: "#fname);
00034 #define WRITE_FILE(fvar,fname) \
00035 std::ofstream fvar(fname);\
00036 if (!fvar) throw std::runtime_error("Could not open file for writing "#fname);
00037 #define WRITE_VRML_FILE(fvar,fname) \
00038 std::ofstream fvar(fname);\
00039 if (!fvar) throw std::runtime_error("Could not open file for writing "#fname);\
00040 fvar << "#VRML V2.0 utf8\n";
00041 #define FSKIP_LINE(f) \
00042 {char c=' ';while(c != '\n' && !(f).eof()) (f).get(c);}
00043 #define FSKIP_WHITESPACES(f) \
00044 {char c; do f.get(c); while(isspace(c)); f.unget();}
00045 #define FCOPY_LINE(f, g) \
00046 {char _c=' ';while(_c != '\n' && !(f).eof()){ (f).get(_c); (g).put(_c);}}
00047 #define FGET_LINE(f,l) \
00048 {l = ""; char c=' '; while(c!='\n' && !f.eof()) l+=c=f.get();}
00049 #define DEL_FEXT(fname) \
00050 {std::string::size_type d = fname.find_last_of('.'); \
00051 if (d!=std::string::npos) fname = fname.substr(0,d);}
00052 #define GET_FEXT(fname,fext) \
00053 {std::string::size_type d = fname.find_last_of('.'); \
00054 fext = (d!=std::string::npos) ? fname.substr(d+1) : "";}
00055 #define TO_UPPER(s) \
00056 std::transform(s.begin(), s.end(), s.begin(), (int(*)(int)) std::toupper)
00057 #define TO_LOWER(s) \
00058 std::transform(s.begin(), s.end(), s.begin(), (int(*)(int)) std::tolower)
00059
00060 #ifndef PVAR
00061 #define PVAR(s) \
00062 #s << " = " << (s) << std::flush
00063 #endif
00064 #ifndef PVARN
00065 #define PVARN(s) \
00066 #s << " = " << (s) << "\n"
00067 #endif
00068 #ifndef PVARC
00069 #define PVARC(s) \
00070 #s << " = " << (s) << ", " << std::flush
00071 #endif
00072 #ifndef PVARS
00073 #define PVARS(s) \
00074 #s << " = " << (s) << " " << std::flush
00075 #endif
00076 #ifndef PVARA
00077 #define PVARA(s) \
00078 #s << " = " << RAD2DEG(s) << "deg" << std::flush
00079 #endif
00080 #ifndef PVARAN
00081 #define PVARAN(s) \
00082 #s << " = " << RAD2DEG(s) << "deg\n"
00083 #endif
00084 #ifndef PVARAC
00085 #define PVARAC(s) \
00086 #s << " = " << RAD2DEG(s) << "deg, " << std::flush
00087 #endif
00088 #ifndef PVARAS
00089 #define PVARAS(s) \
00090 #s << " = " << RAD2DEG(s) << "deg " << std::flush
00091 #endif
00092
00093 #define FIXED(s) \
00094 std::fixed << s << std::resetiosflags(std::ios_base::fixed)
00095
00096 #endif // __cplusplus
00097
00098 #ifndef GET_COLOR
00099 #define GET_COLOR(i, size, r, g, b) \
00100 ((floor(i*6./(double)size) == 0) || (floor(i*6./(double)size) == 6) ? \
00101 (r=1,g=(i*6./size-floor(i*6./size)),b=0) : \
00102 ((floor(i*6./(double)size) == 1) ? (r=1.-(i*6./size-floor(i*6./size)),g=1,b=0) : \
00103 ((floor(i*6./(double)size) == 2) ? (r=0,g=1,b=(i*6./size-floor(i*6./size))) : \
00104 ((floor(i*6./(double)size) == 3) ? (r=0,g=1-(i*6./size-floor(i*6./size)), b=1) : \
00105 ((floor(i*6./(double)size) == 4) ? (r=(i*6./size-floor(i*6./size)),g=0, b=1) : \
00106 (r=1,g=0, b=1-(i*6./size-floor(i*6./size))))))))
00107 #endif
00108
00109 #define PREC 1e-12
00110 #define SQRT2 1.414213562373095145474621858738828450441
00111 #define SQRT3 1.732050807568877293527446341505872366943
00112
00113 #ifndef MIN
00114 #define MIN(a,b) ((a)<(b)?(a):(b))
00115 #endif
00116
00117 #ifndef MIN3
00118 #define MIN3(a,b,c) MIN((a),MIN((b),(c)))
00119 #endif
00120
00121 #ifndef MIN4
00122 #define MIN4(a,b,c,d) MIN((d),MIN3((a),(b),(c)))
00123 #endif
00124
00125 #ifndef MAX
00126 #define MAX(a,b) ((a)>(b)?(a):(b))
00127 #endif
00128
00129 #ifndef MAX3
00130 #define MAX3(a,b,c) MAX((a),MAX((b),(c)))
00131 #endif
00132
00133 #ifndef MAX4
00134 #define MAX4(a,b,c,d) MAX((d),MAX3((a),(b),(c)))
00135 #endif
00136
00137 #ifndef SQR
00138 #define SQR(x) ((x)*(x))
00139 #endif
00140
00141 #ifndef CUB
00142 #define CUB(x) ((x)*(x)*(x))
00143 #endif
00144
00145 #ifndef HYPOT
00146 #define HYPOT(x,y) (sqrt(SQR(x) + SQR(y)))
00147 #endif
00148
00149 #ifndef HYPOT_SQUARED
00150 #define HYPOT_SQUARED(x,y) (SQR(x) + SQR(y))
00151 #endif
00152
00153 #ifndef ROUND
00154 #define ROUND(x) ((x) < 0 ? (int)((x) - .5): (int) ((x) + .5))
00155 #endif
00156
00157 #ifndef IS_INT
00158 #define IS_INT(a) (fabs(ROUND(a)-(a))<PREC)
00159 #endif
00160
00161 #ifndef SIGN
00162 #define SIGN(a) ((a)>0?1:((a)<0?-1:0))
00163 #endif
00164
00165 #ifndef IS_ZERO
00166 #define IS_ZERO(f) (fabs(f) < 1e-12)
00167 #endif
00168
00169 #ifndef IS_EQUAL
00170 #define IS_EQUAL(f, g) (fabs(f - g) < 1e-12)
00171 #endif
00172
00173 #ifndef ERASE_STRUCT
00174 #define ERASE_STRUCT(var) memset(&var, 0, sizeof(var))
00175 #endif
00176
00177 #ifndef ERASE_ARRAY
00178 #define ERASE_ARRAY(var, size) memset(var, 0, size*sizeof(*var))
00179 #endif
00180
00181 #ifndef SET_ARRAY
00182 #define SET_ARRAY(var, value, size) {for (int i=0; i<(int)size; ++i) var[i]=value;}
00183 #endif
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3) && !defined(__GCCXML__)))
00195 #define AISNAV_IS_POD(T) __is_pod(T)
00196 #endif
00197
00198
00199 #ifndef AISNAV_IS_POD
00200 #define AISNAV_IS_POD(T) (0)
00201 #endif
00202
00203 #endif