之前的部落格裡面的很多代碼,有一些自己定義的資料類型,很多人很迷糊,下面把My Code定義的公用部分貼出來,方便大家查看代碼。
/***************************************************************************** Time: 2009-09-21* Project: 遙感平台* Purpose: 核心庫檔案* Author: 李民錄* Copyright (c) 2009, liminlu0314@gmail.com* Describe:提供常用的資料類型定義等*****************************************************************************/#ifndef IMGALG_H#define IMGALG_H/*** \file ImgCore.h* @brief 核心類型定義** 匯出介面(使用C語言方式),核心類型定義*//*** 忽略在MS Widows平台上的警告 lml 2010-10-19* warning C4100: “*”: 未引用的形參* warning C4190: “identifier1”有指定的 C 連結,但返回了與 C 不相容的 UDT“identifier2”* warning C4251: 類“type”需要由類“type2”的用戶端使用 dll 介面* warning C4275: 非 DLL 介面類鍵“identifier”作為 DLL 介面類鍵“identifier”的基使用* warning C4305: 從“type1”到“type2”截斷* warning C4309: 截斷常數值* warning C4819: 該檔案包含不能在當前字碼頁(936)中表示的字元。請將該檔案儲存為 Unicode 格式以防止資料丟失* warning C4996: 使用了非標準擴充: 限定名中使用了枚舉*/#if defined(_MSC_VER) && (_MSC_VER >= 1400)#pragma warning(disable: 4100 4190 4251 4275 4305 4309 4819 4996 )#endif/*** @brief 是否使用Vld記憶體泄露監測工具*/#if _USEVLD#if _DEBUG//在debug模式下檢測記憶體泄露#include "vld.h"#endif#endif/*** @brief 是否使用LOG工具進行寫日誌*/#if _USELOG#define USE_LOG4CPP#endif#include <float.h>#include <algorithm>#include <deque>#include <fstream>#include <limits>#include <map>#include <stack>#include <string>#include <vector>using namespace std;/*** @brief 匯出符號定義*/#ifdef IMGALG_EXPORTS#define IMGALG_API __declspec(dllexport)#else#define IMGALG_API __declspec(dllimport)#endif/*** @brief 定義NULL*/#ifndef NULL# define NULL 0#endif/*** @brief 定義FALSE*/#ifndef FALSE# define FALSE 0#endif/*** @brief 定義TRUE*/#ifndef TRUE# define TRUE 1#endif#ifndef MAX/*! 求最大值 */# define MIN(a, b) ((a<b) ? a : b)/*! 求最小值 */# define MAX(a, b) ((a>b) ? a : b)#endif/*** @brief 定義ABS,求絕對值*/#ifndef ABS# define ABS(x) ((x<0) ? (-1*(x)) : x)#endif/*** @brief 定義PI=3.141592653...以及度和弧度轉換*/#ifndef M_PI/*! 定義圓周率PI */# define M_PI 3.1415926535897932384626433832795/*! 弧度轉度 */# define DEG_PER_RAD ((double)(180.0/M_PI))/*! 度轉弧度 */# define RAD_PER_DEG ((double)(M_PI/180.0))#endif/*** @brief 定義平方*/#ifndef M_SQUARE# define M_SQUARE(x) (x)*(x)#endif/*** @brief 定義立方*/#ifndef M_CUBE# define M_CUBE(x) (x)*(x)*(x)#endif/*! 判斷浮點數是否NaN值 */inline bool isnan(const float& v) { return _isnan(v) ? true : false; }/*! 判斷double數是否NaN值 */inline bool isnan(const double& v) { return _isnan(v) ? true : false; }/*! 擷取double的NaN值 */inline double nan() { return numeric_limits<double>::quiet_NaN(); }/*** @brief float類型的極值*/#ifndef FLT_EQUALS/*! 浮點數是否相等 */#define FLT_EQUALS(x, y) (fabs((double)x-y)<FLT_EPSILON)/*! 浮點數是否相等(指定比較閾值) */#define FLT_EQUALS_N(x, y, z) (fabs((double)x-y)<z)#endif#ifndef FLT_ZERO/*! 浮點數是否為0 */#define FLT_ZERO(x) (fabs(x)<FLT_EPSILON)#endif/*** @brief 釋放數組*/#define RELEASE(x)if(x!=NULL) {delete []x; x = NULL;}/*** @brief 將全域地區設為作業系統預設區域*/#define SET_LOCAL{ locale::global(locale("")); setlocale(LC_ALL,"Chinese-simplified"); }/*** @brief 還原全域地區設定*/#define REVERT_LOCALlocale::global(locale("C"))#ifndef EQUAL#if defined(WIN32) || defined(WIN32CE)/*! 比較字串是否相等 */# define EQUALN(a, b, n) (_strnicmp(a, b, n) == 0)/*! 比較字串是否相等 */# define EQUAL(a, b) (_stricmp(a, b) == 0)#else/*! 比較字串是否相等 */# define EQUALN(a, b, n) (strncasecmp(a, b, n) == 0)/*! 比較字串是否相等 */# define EQUAL(a, b) (strcasecmp(a, b) == 0)#endif#endif/*! byte */typedef unsigned charbyte;/*! 8U */typedef unsigned charDT_8U;/*! 16U */typedef unsigned shortDT_16U;/*! 16S */typedef shortDT_16S;/*! 32U */typedef unsigned intDT_32U;/*! 32S */typedef intDT_32S;/*! 32F */typedef floatDT_32F;/*! 64F */typedef doubleDT_64F;/*! 成功執行 */const int RE_SUCCESS= 0;/*! 檔案不存在 */const int RE_FILENOTEXIST= 1;/*! 檔案格式不被支援 */const int RE_FILENOTSUPPORT= 2;/*! 映像資料類型不正確 */const int RE_FILETYPEERROR= 3;/*! 建立映像失敗 */const int RE_CREATEFAILED= 4;/*! 輸入參數錯誤 */const int RE_PARAMERROR= 5;/*! 其他錯誤 */const int RE_FAILED= 6;/*! 映像不存在公用地區 */const int RE_NOSAMEEXTENT= 7;/*! 使用者取消操作 */const int RE_USERCANCEL= 8;/*! 檔案已經被使用 */const int RE_FILEISUESED= 9;/*! 不支援的像素深度 */const int RE_DEPTHNOTSUPPORT= 10;/*! 波段數量不符合要求 */const int RE_BANDCOUNTERROR= 11;/*! 檔案不存在投影 */const int RE_NOPROJECTION= 12;/*! 投影不一致 */const int RE_PROJECTIONDIFF= 13;#endif