zxhproj v 2.2
zxhproj
|
00001 00002 /*========================================================================= 00003 00004 Program: ZXH Registration Software 00005 Author: Xiahai Zhuang 00006 Module: $RCSfle: zxh.h $ 00007 Language: C++ 00008 Date: $Date: From 2004-01 $ 00009 Version: $Revision: 1.0, 2.0 $ 00010 00011 =========================================================================*/ 00012 00013 extern int glbVerboseOutput ; 00014 00015 00016 #ifndef zxh_h 00017 #define zxh_h 00018 #include "zxhDllExport.h" 00019 #include <fstream> 00020 #include <sstream> 00021 #include <iostream> 00022 #include <string> 00023 #include <math.h> 00024 #include <stdio.h> 00025 #include <stdlib.h> 00026 00027 namespace zxh 00028 { 00035 00036 #ifndef zxhuchar 00037 #define zxhuchar unsigned char 00038 #endif 00039 #ifndef zxhushort 00040 #define zxhushort unsigned short int 00041 #endif 00042 #ifndef zxhlfloat 00043 #define zxhlfloat long double 00044 #endif 00045 #ifndef ImageDimensionMax 00046 #define ImageDimensionMax 4 00047 #endif 00048 #ifndef ZXH_PI 00049 #define ZXH_PI 3.14159f 00050 #endif 00051 #ifndef ZXH_GrayLevelOfSurface 00052 #define ZXH_GrayLevelOfSurface 1 00053 #endif 00054 #ifndef ZXH_Protect_Small_Float 00055 #define ZXH_Protect_Small_Float 100000 00056 #endif 00057 #ifndef ZXH_FloatPrecision 00058 #define ZXH_FloatPrecision 1.0e-20f 00059 #endif 00060 #ifndef ZXH_LFloatPrecision 00061 #define ZXH_LFloatPrecision 1.0e-200 00062 #endif 00063 #ifndef ZXH_Background 00064 #define ZXH_Background 0 00065 #endif 00066 #ifndef ZXH_EMPTY 00067 #define ZXH_EMPTY -32768 00068 #endif 00069 #ifndef ZXH_Foreground 00070 #define ZXH_Foreground 1 //Now for both char and short 00071 #endif 00072 #ifndef ZXH_DefaultOptimiseStep 00073 #define ZXH_DefaultOptimiseStep 50 00074 #endif 00075 #ifndef ZXH_BSPLINE 00076 #define ZXH_BSPLINE 1024 00077 #define ZXH_BSPLINE_PLUS 1025 00078 #endif 00079 00080 #ifndef ZXH_InfiniteLargeFloat 00081 #define ZXH_InfiniteLargeFloat 1.0e20f 00082 #endif 00083 00084 #ifndef ZXH_MaxRegistrations 00085 #define ZXH_MaxRegistrations 20 00086 #endif 00087 00088 #ifndef ZXH_PHASE_FLOAT_INT 00089 #define ZXH_PHASE_FLOAT_INT 10000.0 00090 #endif 00091 00092 #ifndef ZXH_Mask 00093 #define ZXH_Mask 0 00094 #endif 00095 #ifndef ZXH_WeightIntRatio 00096 #define ZXH_WeightIntRatio 100.0 00097 #endif 00098 00099 #ifndef ZXH_MATRIX44 00100 #define ZXH_MATRIX44 00101 typedef struct { float m[4][4] ;} zxhmat44 ; 00102 typedef zxhmat44 mat44 ; 00103 #endif 00104 //#ifndef ZXH_FFD_PRECOMPUTE_SIZE 00105 //#define ZXH_FFD_PRECOMPUTE_SIZE 100 00106 //#endif 00107 00108 #define ZXH_LocalAffineMaxNumber 20 00109 #define ZXH_LocalAffineExponent 2 //1.5 2, 4 00110 #define ZXH_LocalAffineFacetWeighting 0.5f //1.0/6=0.16667, 1.0/3=0.333333, 1/2, 00111 // Weight=1+1*( ((1/0.5)^e-1) /0.5 ), if NOT pre-compute weight , then is Distance =0 00112 #define ZXH_LocalAffineWithinRegionWeight 0 00113 00114 // verbose output: 00115 // 0 only output error, and resultant infoa 00116 // 1 include 0 and success info 00117 // 2 include 1 and debug info 00118 00119 enum TypeHistogramCompute {PDFType_ParzenWindow_BSpline=1, PDFType_Histogram=2, PDFType_PV=3, UniformVolumeHistogram}; 00120 00121 enum TypeMutualInformation { MutualInformation=1, NormalizedMutualInformation=2, MixtureProbabilityModel=3} ; 00122 00123 enum TypeSEMIKernelFunction { SEMIGaussian=-1, SEMIBSplineZeroOrder=0, SEMIBSpline=3, SEMIMixtureModel=10}; 00124 #ifndef SpatialMutualInformationSum 00125 #define SpatialMutualInformationSum float(-0.998) 00126 #endif 00127 #ifndef SpatialMutualInformationMagnitude 00128 #define SpatialMutualInformationMagnitude float(-0.997) 00129 #endif 00130 //#ifndef SpatialMutualInformationSearchScope 00131 //#define SpatialMutualInformationSearchScope 1 int(-smisigma * 2) 00132 //#endif 00133 00134 #ifndef ZXH_NV_NOISELEVEL 00135 #define ZXH_NV_NOISELEVEL float(0.02) 00136 #endif 00137 00138 #ifndef BSplineHistogramPaddingBins 00139 #define BSplineHistogramPaddingBins 4 //2*2 00140 #define BSplineHistogramPaddingBinsFrom -1 00141 #define BSplineHistogramPaddingBinsTo 2 00142 #define BSplineHistogramPaddingBinsOffset 2 //BSplineHistogramPaddingBins/2 00143 #endif 00144 00147 ZXH_DLL_EXPORT void trim_left(std::string & s) ; 00148 00150 ZXH_DLL_EXPORT void trim_right(std::string& s) ; 00151 00153 ZXH_DLL_EXPORT void trim_both(std::string& s) ; 00154 00156 ZXH_DLL_EXPORT void case_upper(std::string& s); 00157 00159 ZXH_DLL_EXPORT void case_lower(std::string& s); 00160 00162 ZXH_DLL_EXPORT bool is_option( std::string s ); 00164 ZXH_DLL_EXPORT bool is_digital( std::string s ); 00165 00167 ZXH_DLL_EXPORT void ParseStringLine(std::string& sContent,std::string& sComment, std::string& strLine); 00168 00170 ZXH_DLL_EXPORT bool FindStringFromStream(char*buffer,int buffersize,std::ifstream&ifs,char* substring); 00171 00173 ZXH_DLL_EXPORT bool NextContentLine(std::string& sContent,char*buffer,int buffersize,std::ifstream&ifs); 00174 00176 ZXH_DLL_EXPORT bool ScanInteger(std::ifstream & ifs,char*buffer,int ibuffersize,int& idata); 00177 00179 ZXH_DLL_EXPORT bool ScanFloat(std::ifstream&ifs,char*buffer,int ibuffersize,float& fdata); 00180 00182 ZXH_DLL_EXPORT bool ScanString(std::ifstream&ifs,char*buffer,int ibuffersize,char*pdata); 00183 00185 00187 ZXH_DLL_EXPORT void Swap2Bytes(void* p); 00189 ZXH_DLL_EXPORT void Swap4Bytes(void* p); 00191 ZXH_DLL_EXPORT void Swap8Bytes(void* p); 00193 ZXH_DLL_EXPORT void Swap10Bytes(void* p); 00195 ZXH_DLL_EXPORT void SwapBytes(void* p,unsigned char nbyte); 00197 00199 ZXH_DLL_EXPORT std::string GetExtension(const std::string filename); 00201 ZXH_DLL_EXPORT std::string GetFileNameNoPath(const std::string filename); 00203 ZXH_DLL_EXPORT std::string GetFileNamePath(const std::string filename); 00205 ZXH_DLL_EXPORT std::string GetFileNameNoExtension(const std::string filename); 00206 00208 ZXH_DLL_EXPORT float absf( const float f ) ; 00210 ZXH_DLL_EXPORT int round( const float f ) ; 00212 ZXH_DLL_EXPORT float maxf( const float f1, const float f2 ) ; 00214 ZXH_DLL_EXPORT float minf( const float f1, const float f2 ); 00216 ZXH_DLL_EXPORT void echo_arguments( int argc, char* argv[] ) ; 00218 ZXH_DLL_EXPORT void echo_zxh(); 00220 ZXH_DLL_EXPORT void NormaliseVector( float v[], int dimension ) ; 00222 ZXH_DLL_EXPORT float MagnitudeOfVector( const float v[], const int dimension ); 00223 00225 ZXH_DLL_EXPORT bool fileexists(const std::string filename); 00226 00228 ZXH_DLL_EXPORT float Gaussian( const float f, const float u, const float sigma ) ; 00230 ZXH_DLL_EXPORT float NGaussian( const float f ) ; 00232 ZXH_DLL_EXPORT 00233 template <class type> 00234 bool InclusiveBetween( type value, type from, type to ) 00235 { 00236 if( value>=from && value <= to ) 00237 return true ; 00238 return false ; 00239 }; 00241 ZXH_DLL_EXPORT 00242 template <class TYPE> 00243 TYPE abs( TYPE f ) 00244 { 00245 if( f>=0 ) return f ; 00246 return -f ; 00247 } 00249 ZXH_DLL_EXPORT 00250 template <class TYPE> 00251 TYPE SqaredDistance( TYPE *co1, TYPE *co2, int Dimension ) 00252 { 00253 TYPE dis = 0; 00254 for(int i=0;i<Dimension;++i) 00255 dis += (co1[i]-co2[i])*(co1[i]-co2[i]); 00256 return dis; 00257 } 00258 /* matrix op */ 00260 ZXH_DLL_EXPORT void MatrixIdentity(float *pMatDes, const int iMatrixLength ) ; 00262 ZXH_DLL_EXPORT void SetMatrix(float *pMatDes, const float* pMatSrc1, const int iMatrixLength ) ; 00264 ZXH_DLL_EXPORT void MultiplyMatrix(float *pMatDes, const float* pMatSrc1, const float* pMatSrc2, const int iMatrixLength ) ; 00266 ZXH_DLL_EXPORT void MultiplyMatrixVector(float *pVecDes, const float* pMatSrc, const float* pVecSrc, const int iMatrixLength ) ; 00268 ZXH_DLL_EXPORT float DeterminentMatrix3D(const float *pMat, const int iMatrixRowLength ) ; 00270 ZXH_DLL_EXPORT void InvertMatrix3D(float* pInvMat, const float* pForMat, const int iMatrixRowLength); 00272 ZXH_DLL_EXPORT void InvertMatrix4D3D( zxhmat44 &inv, const zxhmat44 &forward ) ; 00273 00275 //template <class TYPE> 00276 //TYPE BSpline ( TYPE u ) 00277 ZXH_DLL_EXPORT float BSpline(float u) ; 00279 ZXH_DLL_EXPORT float BSplineDerivative(float u) ; 00281 ZXH_DLL_EXPORT float BSplineSecondDerivative ( float u ) ; 00283 ZXH_DLL_EXPORT float BSplinei(int iOrd,float u) ; 00285 ZXH_DLL_EXPORT float DerivativeOfBSplinei(int iOrd, float u) ; 00287 ZXH_DLL_EXPORT float SecondDerivativeOfBSplinei(int iOrd,float u) ; 00288 //************ Macro ***************// 00289 #define MIN(f1,f2) ((f1)>=(f2)?(f2):(f1)) 00290 #define MAX(f1,f2) ((f1)<=(f2)?(f2):(f1)) 00291 00292 #define ISMITYPE(pMetric) \ 00293 (strstr(pMetric->GetMetricType().c_str(),"_MI_")!=NULL) 00294 00295 #define ISSEMITYPE(pMetric) \ 00296 (strstr(pMetric->GetMetricType().c_str(),"_SEMI_")!=NULL) 00297 00298 #define ISMULTIIMAGETYPE(pMetric) \ 00299 (strstr(pMetric->GetMetricType().c_str(),"_MULTIIMAGE_")!=NULL) 00300 00301 #define ISPHASETYPE(pMetric) \ 00302 (strstr(pMetric->GetMetricType().c_str(),"_PHASE_")!=NULL) 00303 00304 #define ISCONSTDISCRETEPATHTYPE(pMetric) \ 00305 (strstr(pMetric->GetMetricType().c_str(),"_CONSTDISCRETEPATH_")!=NULL) 00306 00307 #define ISMICNSTTYPE(pMetric) \ 00308 (strstr(pMetric->GetMetricType().c_str(),"_MI_")!=NULL&&strstr(pMetric->GetMetricType().c_str(),"_CNST_")!=NULL) 00309 00310 #define ISRMSTYPE(pMetric)\ 00311 (strstr(pMetric->GetMetricType().c_str(),"_RMS_")!=NULL) 00312 00313 #define ISCCTYPE(pMetric)\ 00314 (strstr(pMetric->GetMetricType().c_str(),"_CC_")!=NULL) 00315 00316 #define ISNVTYPE(pMetric)\ 00317 (strstr(pMetric->GetMetricType().c_str(),"_NV_")!=NULL) 00318 00319 #define ISFFDMETRIC(pMetric)\ 00320 (strstr(pMetric->GetMetricType().c_str(),"_FFD_")!=NULL) 00321 00322 #define ISFFD2METRIC(pMetric)\ 00323 (strstr(pMetric->GetMetricType().c_str(),"_FFD2_")!=NULL) 00324 00325 #define ISLOCALAFFINEMETRIC(pMetric)\ 00326 (strstr(pMetric->GetMetricType().c_str(),"_LAFFS_")!=NULL) 00327 00328 #define SetFFDMetric2Metric(FFDMetricObject,MetricObject) \ 00329 { if(ISMITYPE(MetricObject)) FFDMetricObject = ((zxhMetricMIFFD*) MetricObject); \ 00330 if(ISPHASETYPE(MetricObject))FFDMetricObject = ((zxhMetricPhaseFFD*) MetricObject); \ 00331 if(ISRMSTYPE(MetricObject))FFDMetricObject = ((zxhMetricRMS*) MetricObject); \ 00332 if(ISNVTYPE(MetricObject)) FFDMetricObject = ((zxhMetricNV*) MetricObject); \ 00333 if(ISCCTYPE(MetricObject)) FFDMetricObject = ((zxhMetricCCFFD2*) MetricObject); \ 00334 }; 00335 00336 #define SetLocalAffinesMetric2Metric(LAMetricObject,MetricObject) \ 00337 { if(ISPHASETYPE(MetricObject)) LAMetricObject = (zxhMetricPhaseLocalAffines*) MetricObject ; \ 00338 if(ISMITYPE(MetricObject)) LAMetricObject = (zxhMetricMILocalAffines*) MetricObject ; \ 00339 }; 00340 00341 //if(ISNVTYPE(MetricObject)) LAMetricObject = ((zxhMetricNV*) MetricObject); 00342 00343 /* if(ISCCTYPE(MetricObject)) LAMetricObject = (zxhMetricCC*) MetricObject ; 00344 if(ISRMSTYPE(MetricObject))LAMetricObject = (zxhMetricRMS*) MetricObject ; 00345 if(ISNVTYPE(MetricObject)) LAMetricObject = (zxhMetricNV*) MetricObject ;};*/ 00346 00347 00348 }//end of zxh 00349 //#ifdef __cpluscplus 00350 // } 00351 //#endif 00352 00353 #endif //zxh_h 00354