//////////////////////////////////////////////////////////////////// // Common.h // // Copyright 2007 cDc@seacave // Distributed under the Boost Software License, Version 1.0 // (See http://www.boost.org/LICENSE_1_0.txt) #ifndef _COMMON_COMMON_H_ #define _COMMON_COMMON_H_ // D E F I N E S /////////////////////////////////////////////////// #include "Config.h" // macros controlling the verbosity #define TD_VERBOSE_OFF 0 #define TD_VERBOSE_ON 1 #define TD_VERBOSE_DEBUG 2 #ifndef TD_VERBOSE #ifdef _RELEASE #define TD_VERBOSE TD_VERBOSE_ON #else #define TD_VERBOSE TD_VERBOSE_DEBUG #endif #endif #if TD_VERBOSE == TD_VERBOSE_OFF #define VERBOSE LOG #define DEBUG_LEVEL(n,...) #else #ifndef VERBOSITY_LEVEL namespace SEACAVE { extern int g_nVerbosityLevel; } #define VERBOSITY_LEVEL g_nVerbosityLevel #endif #define VERBOSE LOG #define DEBUG_LEVEL(n,...) { if (n < VERBOSITY_LEVEL) VERBOSE(__VA_ARGS__); } #endif #define DEBUG(...) DEBUG_LEVEL(0, __VA_ARGS__) #define DEBUG_EXTRA(...) DEBUG_LEVEL(1, __VA_ARGS__) #define DEBUG_ULTIMATE(...) DEBUG_LEVEL(2, __VA_ARGS__) // macros that simplify timing tasks #define TD_TIMER_OFF 0 #define TD_TIMER_ON 1 #ifndef TD_TIMER #define TD_TIMER TD_TIMER_ON #endif #if TD_TIMER == TD_TIMER_OFF #define TD_TIMER_START() #define TD_TIMER_UPDATE() #define TD_TIMER_GET() 0 #define TD_TIMER_GET_INT() 0 #define TD_TIMER_GET_FMT() String() #define TD_TIMER_STARTD() #define TD_TIMER_UPDATED() #endif #if TD_TIMER == TD_TIMER_ON #define TD_TIMER_START() TIMER_START() #define TD_TIMER_UPDATE() TIMER_UPDATE() #define TD_TIMER_GET() TIMER_GET() #define TD_TIMER_GET_INT() TIMER_GET_INT() #define TD_TIMER_GET_FMT() TIMER_GET_FORMAT() #if TD_VERBOSE == TD_VERBOSE_OFF #define TD_TIMER_STARTD() #define TD_TIMER_UPDATED() #else #define TD_TIMER_STARTD() TIMER_START() #define TD_TIMER_UPDATED() TIMER_UPDATE() #endif #endif // macros redirecting standard streams to the log #define LOG_OUT() GET_LOG() //or std::cout #define LOG_ERR() GET_LOG() //or std::cerr // macros simplifying the task of composing file paths; // WORKING_FOLDER and WORKING_FOLDER_FULL must be defined as strings // containing the relative/full path to the working folder #ifndef WORKING_FOLDER namespace SEACAVE { class String; extern String g_strWorkingFolder; // empty by default (current folder) extern String g_strWorkingFolderFull; // full path to current folder } #define WORKING_FOLDER g_strWorkingFolder // empty by default (current folder) #define WORKING_FOLDER_FULL g_strWorkingFolderFull // full path to current folder #endif #define INIT_WORKING_FOLDER {SEACAVE::Util::ensureValidFolderPath(WORKING_FOLDER); WORKING_FOLDER_FULL = SEACAVE::Util::getFullPath(WORKING_FOLDER);} // initialize working folders #define MAKE_PATH(str) SEACAVE::Util::getSimplifiedPath(WORKING_FOLDER+SEACAVE::String(str)) // add working directory to the given file name #define MAKE_PATH_SAFE(str) (SEACAVE::Util::isFullPath((str).c_str()) ? SEACAVE::String(str) : MAKE_PATH(str)) // add working directory to the given file name only if not full path already #define MAKE_PATH_FULL(p,s) (SEACAVE::Util::isFullPath((s).c_str()) ? SEACAVE::String(s) : SEACAVE::Util::getSimplifiedPath((p)+(s))) // add the given path to the given file name #define MAKE_PATH_REL(p,s) SEACAVE::Util::getRelativePath(p,s) // remove the given path from the given file name #define GET_PATH_FULL(str) (SEACAVE::Util::isFullPath((str).c_str()) ? SEACAVE::Util::getFilePath(str) : SEACAVE::Util::getSimplifiedPath(WORKING_FOLDER_FULL+SEACAVE::Util::getFilePath(str))) // retrieve the full path to the given file // macros simplifying the task of managing options #define DECOPT_SPACE(SPACE) namespace SPACE { \ void init(); \ void update(); \ extern SEACAVE::VoidArr arrFncOpt; \ extern SEACAVE::CConfigTable oConfig; \ } #define DEFOPT_SPACE(SPACE, name) namespace SPACE { \ SEACAVE::CConfigTable oConfig(name); \ typedef LPCTSTR (*FNCINDEX)(); \ typedef void (*FNCINIT)(SEACAVE::IDX); \ typedef void (*FNCUPDATE)(); \ VoidArr arrFncOpt; \ void init() { \ FOREACH(i, arrFncOpt) \ ((FNCINIT)arrFncOpt[i])(i); \ } \ void update() { \ FOREACH(i, arrFncOpt) \ ((FNCUPDATE)arrFncOpt[i])(); \ } \ } #define DEFVAR_OPTION(SPACE, flags, type, name, title, desc, ...) namespace SPACE { \ type name; \ LPCTSTR defval_##name(NULL); \ void update_##name() { \ SEACAVE::String::FromString(oConfig[title].val, name); \ } \ void init_##name(SEACAVE::IDX idx) { \ LPCTSTR const vals[] = {__VA_ARGS__}; \ arrFncOpt[idx] = (void*)update_##name; \ SMLVALUE& val = oConfig[title]; \ CFGITEM& opt = *((CFGITEM*)val.data); \ opt.state = flags; \ val.val = opt.defval = (defval_##name != NULL ? defval_##name : vals[0]); \ opt.vals.Insert(opt.defval); \ for (size_t i=1; i Sphere2f; typedef TSphere Sphere3f; typedef TAABB AABB2f; typedef TAABB AABB3f; typedef TOBB OBB2f; typedef TOBB OBB3f; typedef TRay Ray2f; typedef TRay Ray3f; typedef TLine Line2f; typedef TLine Line3f; typedef TTriangle Triangle2f; typedef TTriangle Triangle3f; typedef TPlane Planef; typedef TPoint2 Point2f; typedef TPoint3 Point3f; typedef TMatrix Vec2f; typedef TMatrix Vec3f; typedef TMatrix Vec4f; typedef TMatrix Matrix2x2f; typedef TMatrix Matrix3x3f; typedef TMatrix Matrix3x4f; typedef TMatrix Matrix4x4f; typedef TSphere Sphere2d; typedef TSphere Sphere3d; typedef TAABB AABB2d; typedef TAABB AABB3d; typedef TOBB OBB2d; typedef TOBB OBB3d; typedef TRay Ray2d; typedef TRay Ray3d; typedef TLine Line2d; typedef TLine Line3d; typedef TTriangle Triangle2d; typedef TTriangle Triangle3d; typedef TPlane Planed; typedef TPoint2 Point2d; typedef TPoint3 Point3d; typedef TMatrix Vec2d; typedef TMatrix Vec3d; typedef TMatrix Vec4d; typedef TMatrix Matrix2x2d; typedef TMatrix Matrix3x3d; typedef TMatrix Matrix3x4d; typedef TMatrix Matrix4x4d; typedef TSphere Sphere2; typedef TSphere Sphere3; typedef TAABB AABB2; typedef TAABB AABB3; typedef TOBB OBB2; typedef TOBB OBB3; typedef TRay Ray2; typedef TRay Ray3; typedef TLine Line2; typedef TLine Line3; typedef TTriangle Triangle2; typedef TTriangle Triangle3; typedef TPlane Plane; typedef TPoint2 Point2; typedef TPoint3 Point3; typedef TMatrix Vec2; typedef TMatrix Vec3; typedef TMatrix Vec4; typedef TMatrix Matrix2x2; typedef TMatrix Matrix3x3; typedef TMatrix Matrix3x4; typedef TMatrix Matrix4x4; typedef TQuaternion Quaternion; typedef TRMatrixBase RMatrixBase; // camera matrix types typedef Point3 CMatrix; typedef RMatrixBase RMatrix; typedef Matrix3x3 KMatrix; typedef Matrix3x4 PMatrix; // reconstructed 3D point type typedef Vec3 X3D; typedef SEACAVE::cList X3DArr; typedef SEACAVE::cList IndexArr; typedef CLISTDEF0(REAL) REALArr; typedef CLISTDEF0(Point2f) Point2fArr; typedef CLISTDEF0(Point3f) Point3fArr; typedef CLISTDEF0(Point2d) Point2dArr; typedef CLISTDEF0(Point3d) Point3dArr; typedef CLISTDEF0(Point2) Point2Arr; typedef CLISTDEF0(Point3) Point3Arr; typedef CLISTDEF0(Vec4) Vec4Arr; typedef CLISTDEF0(Matrix3x3) Matrix3x3Arr; typedef CLISTDEF0(Matrix3x4) Matrix3x4Arr; typedef CLISTDEF0(CMatrix) CMatrixArr; typedef CLISTDEF0(RMatrix) RMatrixArr; typedef CLISTDEF0(KMatrix) KMatrixArr; typedef CLISTDEF0(PMatrix) PMatrixArr; typedef CLISTDEF0(ImageRef) ImageRefArr; typedef CLISTDEF0(Pixel8U) Pixel8UArr; typedef CLISTDEF0(Pixel32F) Pixel32FArr; typedef CLISTDEF0(Color8U) Color8UArr; typedef CLISTDEF0(Color32F) Color32FArr; /*----------------------------------------------------------------*/ } // namespace SEACAVE // define specialized cv:DataType<> DEFINE_CVDATATYPE(SEACAVE::Vec2f) DEFINE_CVDATATYPE(SEACAVE::Vec3f) DEFINE_CVDATATYPE(SEACAVE::Vec4f) DEFINE_CVDATATYPE(SEACAVE::Matrix2x2f) DEFINE_CVDATATYPE(SEACAVE::Matrix3x3f) DEFINE_CVDATATYPE(SEACAVE::Matrix3x4f) DEFINE_CVDATATYPE(SEACAVE::Matrix4x4f) DEFINE_CVDATATYPE(SEACAVE::Vec2d) DEFINE_CVDATATYPE(SEACAVE::Vec3d) DEFINE_CVDATATYPE(SEACAVE::Vec4d) DEFINE_CVDATATYPE(SEACAVE::Matrix2x2d) DEFINE_CVDATATYPE(SEACAVE::Matrix3x3d) DEFINE_CVDATATYPE(SEACAVE::Matrix3x4d) DEFINE_CVDATATYPE(SEACAVE::Matrix4x4d) /*----------------------------------------------------------------*/ #endif // _COMMON_COMMON_H_