You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

389 lines
12 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef __BASE_STRUCT_H
#define __BASE_STRUCT_H
#include "baseDefine.h"
#include "baseConstant.h"
#include "iAlgorithm.h"
#define BASE_MAX_FILE_PATH 260
#define BASE_MAX_FOLDER_NAME_SIZE 64
#define BASE_MAX_FILE_NAME_SIZE 64
enum emTpFolderNameList {
TP_FOLDER_NAME_CONFIG = 0,
TP_FOLDER_NAME_PICTURE = 1,
TP_FOLDER_NAME_UI = 2,
TP_FOLDER_NAME_MAX_NUM = 32,
};
typedef struct tagTP_GLOBAL_DATA{
char tgdMainPath[BASE_MAX_FILE_PATH];
char tgdUserPath[BASE_MAX_FILE_PATH];
char tgdDllPath[BASE_MAX_FILE_PATH];
char tgdFolderNames[TP_FOLDER_NAME_MAX_NUM][BASE_MAX_FOLDER_NAME_SIZE];
void* tgdpDllPaths;//pointer to a stringlist
}TP_GLOBAL_DATA;
inline ZStringA TPConfigFileWholePath(const TP_GLOBAL_DATA* pGlobal, const char* szFile) {
ZStringA szFileName(pGlobal->tgdMainPath);
szFileName.append(pGlobal->tgdFolderNames[TP_FOLDER_NAME_CONFIG]).append(szFile).append(TP_STR::cszJsonSuffix);
return szFileName;
}
enum emTpImageShowType {
TP_IMAGE_SHOW_NO = 0,
TP_IMAGE_SHOW_EVERY = 1,
TP_IMAGE_SHOW_NEW = 2,
};
typedef struct tagTP_CORE_SETTING{
int threadsCount;
int imageShowType;
}TP_CORE_SETTING;
enum emTpDeviceType {
DEV_CAM_NONE = 0,
DEV_CAM_VIRTUAL = 100,
DEV_CAM_VIRTUAL_FOLDER = 100,
DEV_CAM_BITFLOW = 110,
DEV_CAM_BITFLOW_BI = 110,
DEV_CAM_GIGE = 120,
DEV_CAM_USB = 130,
DEV_CAM_HIK = 140,
DEV_CAM_VIMBA = 150,
DEV_CAM_BAUMER = 160,
DEV_CAM_ADLINK = 170,
DEV_CAM_DAHUA = 180,
DEV_CAM_BASLER = 190,
DEV_CAM_PTGRAY = 200,
DEV_CAM_EURESYS = 220,
DEV_CAM_DALSA = 230,
};
static const QMap<emTpDeviceType, QString> gCameraNamesMap = {
{ DEV_CAM_NONE, "Unknown(0)" },
{ DEV_CAM_VIRTUAL, "Virtual Camera(100)" },
{ DEV_CAM_VIRTUAL_FOLDER, "Virtual Camera(100)" },
{ DEV_CAM_BITFLOW, "BitFlow(110)" },
{ DEV_CAM_BITFLOW_BI, "BitFlow(110)" },
{ DEV_CAM_GIGE, "Gige(120)" },
{ DEV_CAM_USB, "USB Camera(130)" },
{ DEV_CAM_HIK, "HIK(140)" },
{ DEV_CAM_VIMBA, "Vimba(150)" },
{ DEV_CAM_BAUMER, "Baumer(160)" },
{ DEV_CAM_ADLINK, "AdLink(170)" },
{ DEV_CAM_DAHUA, "DaHua(180)" },
{ DEV_CAM_BASLER, "Basler(190)" },
{ DEV_CAM_PTGRAY, "PtGray(200)" },
{ DEV_CAM_EURESYS, "Euresys(220)" },
{ DEV_CAM_DALSA, "Dalsa(230)" }
};
#define TP_STRING_MAX_SIZE 256
enum emTpCameraStatus{
TP_CAMERA_STATUS_UNINIT = 0, // 未初始化(刚从配置文件加载)
TP_CAMERA_STATUS_INITED = 1, // 已初始化即加载DLL成功
TP_CAMERA_STATUS_OPENED = 2, // 已打开
TP_CAMERA_STATUS_STARTED = 3, // 运行中
TP_CAMERA_STATUS_STOPPED = 4, // 暂停
TP_CAMERA_STATUS_CLOSED = 5, // 已关闭
};
static const QMap<emTpCameraStatus, QString> gCameraStatusMap = {
{ TP_CAMERA_STATUS_UNINIT, "Uninitialized" },
{ TP_CAMERA_STATUS_INITED, "Initialized" },
{ TP_CAMERA_STATUS_OPENED, "Opened" },
{ TP_CAMERA_STATUS_STARTED, "Running" },
{ TP_CAMERA_STATUS_STOPPED, "Paused" },
{ TP_CAMERA_STATUS_CLOSED, "Closed" }
};
typedef struct tagTP_CAMERA_OPTION {
tagTP_CAMERA_OPTION()
:id(0), deviceType(0), save(0), loop(0), width(0),
height(0), zoom(0), format(TP_COLOR_NONE), algorithm(0), exposure(0),
boardType(0), boardNum(0), gain(0), bIgnoreImage(false),
bNeedRgbSwapped(false), bAutoOpen(true), bAutoPush(true),
status(TP_CAMERA_STATUS_UNINIT)
{ }
int id;
int deviceType;
BYTE save;
BYTE loop;//
BYTE reserve[2];
QString showName;
QString uniqueName;
int width;
int height;
int zoom;
emTpColorFormat format;
QString folder;
QString saveImgSuffix;
int algorithm;
QString relyOnCamera;
long exposure;
int boardType;
int boardNum;
long gain;
QString dllsuffix;
QString sBoardName;
QString sBoardConfigFile;
// used inner
bool bIgnoreImage;
QStringList* pSerials;
bool bNeedRgbSwapped;
QString macAddress;
bool bAutoOpen;
QString cameraFilePath;
bool bAutoPush; // 默认一旦得到图片就直接push进pool。
// camera status - used for app inside
emTpCameraStatus status;
bool operator==(const tagTP_CAMERA_OPTION& rhs)
{
return (id == rhs.id) && (deviceType == rhs.deviceType) &&
(save == rhs.save) && (loop == rhs.loop) &&
(showName == rhs.showName) &&
(uniqueName == rhs.uniqueName) &&
(zoom == rhs.zoom) && (format == rhs.format) &&
(folder == rhs.folder) &&
(saveImgSuffix == rhs.saveImgSuffix) &&
(algorithm == rhs.algorithm) && (relyOnCamera == rhs.relyOnCamera) &&
(exposure == rhs.exposure) && (boardType == rhs.boardType) &&
(boardNum == rhs.boardNum) &&
(gain == rhs.gain) &&
(dllsuffix == rhs.dllsuffix) &&
(sBoardName == rhs.sBoardName) &&
(sBoardConfigFile == rhs.sBoardConfigFile) &&
(bAutoPush == rhs.bAutoPush) &&
(bNeedRgbSwapped == rhs.bNeedRgbSwapped);
}
}TP_CAMERA_OPTION;
enum emTpCommType {
TP_COMM_TYPE_NO = 0,
TP_COMM_TYPE_SERIAL = 1,
TP_COMM_TYPE_USB = 2,
TP_COMM_TYPE_TCP_CLIENT = 3, // 主机作为客户端
TP_COMM_TYPE_TCP_SERVER = 4, // 主机作为服务端
TP_COMM_TYPE_TCP_CLIENT_SESSION = 5, // 主机作为服务端,接受的客户端会话
};
enum emTpDeviceTriggerMode {
DEV_TRIGGER_MODE_STOP = 0,
DEV_TRIGGER_MODE_OUT = 1,
DEV_TRIGGER_MODE_AUTO = 2,
DEV_TRIGGER_MODE_FIXED_AUTO = 3,
DEV_TRIGGER_MODE_SOFT = 4,
// DEV_TRIGGER_MODE_MANUAL = 3,
};
enum emTpTriggerDirection {
TRIGGER_DIRECT_FOREWARD = 0,
TRIGGER_DIRECT_BACKWARD = 1,
TRIGGER_DIRECT_REPEAT = 2,
};
typedef struct tagTP_CAMERAPOOL_OPTION {
emTpDeviceTriggerMode triggerMode;
emTpTriggerDirection triggerDirection;
int frameRate;
int fixedFrames;
}TP_CAMERAPOOL_OPTION;
// typedef struct tagTP_CAMERA_WIN {
// tagTP_CAMERA_WIN()
// :images(1), buffers(2),
// bitsPerPixel(32), index(0),
// bufferW(0), bufferH(0), mirror(0),
// bCacheOriginImage(false), bNeedRgbSwapped(false)
// {}
// QString key;//widget name
// QString device;//camera key
// quint8 images;
// quint8 buffers;
// quint8 bitsPerPixel;
// quint8 index;
// int bufferW;
// int bufferH;
// int mirror;//0:no, 1:horizontal, 2:vertical, 3: both
// bool bCacheOriginImage;
// bool bNeedRgbSwapped;
//
// bool operator==(const tagTP_CAMERA_WIN& rhs)
// {
// return (key == rhs.key) && (device == rhs.device) &&
// (images == rhs.images) && (buffers == rhs.buffers) &&
// (bitsPerPixel == rhs.bitsPerPixel) &&
// (index == rhs.index) &&
// (bufferW == rhs.bufferW) && (bufferH == rhs.bufferH) &&
// (mirror == rhs.mirror) &&
// (bCacheOriginImage == rhs.bCacheOriginImage) &&
// (bNeedRgbSwapped == rhs.bNeedRgbSwapped);
// }
// }TP_CAMERA_WIN;
// enum emTpUiDataType {
// TP_UI_DATA_FROM_CORECTRL = 0,
// TP_UI_DATA_FROM_ALGORITHM = 0x10000,
// TP_UI_DATA_FROM_CAMERA = 0x20000,
// TP_UI_DATA_FROM_COMMUNICATE = 0x30000,
// };
//Q_DECLARE_METATYPE(emTpUiDataType)
// typedef struct tagTP_IO_OUT_CONTROL {
// BYTE index;
// BYTE state;//0 or 1
// WORD mSecToSwitch;//0 for no Switch;
// }TP_IO_OUT_CONTROL;
static const QMap<emTpColorFormat, QString> gColorNameMap = {
{ TP_COLOR_NONE, "None" },
{ TP_COLOR_Y800, "GRAY8" },
{ TP_COLOR_RGB24, "RGB24" },
{ TP_COLOR_RGB32, "RGB32" },
{ TP_COLOR_Y16, "GRAY16" },
{ TP_COLOR_RGB48, "RGB48" },
{ TP_COLOR_BGR24, "BGR24" },
{ TP_COLOR_BGR32, "BGR32" }
};
#define TP_LOG_TAIL " - " << __FUNCTION__
#define TP_DEBUG(msg) qDebug() << msg << TP_LOG_TAIL;
#define TP_WARN(msg) qWarning() << msg << TP_LOG_TAIL;
#define TP_ERROR(msg) qCritical() << msg << TP_LOG_TAIL;
//global functions
namespace TP_FUNCS
{
#define F_INLINE inline
F_INLINE QString ImageFileName(DWORD nFrameNumber, const TP_CAMERA_OPTION* pCamOpt, const char* szSuffix)
{
QStringList invaldcha = (QStringList() << "\\" << "/" << "*" << "?" << "<" << ">" << "|" << ":");
QDateTime dt = QDateTime::currentDateTime();
QString strCamName = pCamOpt->uniqueName;
foreach(const QString &str, invaldcha) {
strCamName.remove(str);
}
QString strName = pCamOpt->folder + strCamName
+ "_" + dt.toString("yyyy_MM_dd_hh_mm_ss_zzz") + "_"
+ QString::number(nFrameNumber) + szSuffix/*".BMP"*/;
return strName;
}
F_INLINE QString ImageFileName(DWORD nFrameNumber, const TP_CAMERA_OPTION* pCamOpt)
{
QStringList invaldcha = (QStringList() << "\\" << "/" << "*" << "?" << "<" << ">" << "|" << ":");
QDateTime dt = QDateTime::currentDateTime();
QString strCamName = pCamOpt->uniqueName;
//foreach(const QString &str, invaldcha) {
// strCamName.remove(str);
//}
strCamName.remove(":");
QString strName = pCamOpt->folder + strCamName
+ "_" + dt.toString("yyyy_MM_dd_hh_mm_ss_zzz") + "_"
+ QString::number(nFrameNumber) + pCamOpt->saveImgSuffix;
return strName;
}
F_INLINE emTpColorFormat FromQImageFormat(const QImage &image)
{
if (QImage::Format_RGB32 == image.format())
{
return TP_COLOR_RGB32;
}
else if (QImage::Format_RGB888 == image.format())
{
return TP_COLOR_RGB24;
}
else if (QImage::Format_Indexed8 == image.format())
{
return TP_COLOR_Y800;
}
else if (QImage::Format_RGB16 == image.format())
{
return TP_COLOR_Y16;
}
else if (QImage::Format_ARGB32 == image.format())
{
return TP_COLOR_RGB48;
}
else
{
return TP_COLOR_NONE;
}
}
F_INLINE QImage::Format ToQImageFormat(emTpColorFormat colorFormat)
{
if (TP_COLOR_RGB32 == colorFormat)
{
return QImage::Format_RGB32;
}
else if (TP_COLOR_RGB24 == colorFormat)
{
return QImage::Format_RGB888;
}
else if (TP_COLOR_Y800 == colorFormat)
{
return QImage::Format_Indexed8;
}
else if (TP_COLOR_Y16 == colorFormat)
{
return QImage::Format_RGB16;
}
else if (TP_COLOR_RGB48 == colorFormat)
{
return QImage::Format_ARGB32;
}
else
{
return QImage::Format_Invalid;
}
}
F_INLINE int BitsPerPixels(emTpColorFormat colorFormat)
{
if (TP_COLOR_RGB32 == colorFormat)
{
return 32;
}
else if (TP_COLOR_RGB24 == colorFormat)
{
return 24;
}
else if (TP_COLOR_Y800 == colorFormat)
{
return 8;
}
else if (TP_COLOR_Y16 == colorFormat)
{
return 16;
}
else
{
return 0;
}
}
F_INLINE bool isValidImgSuffix(const QString& str)
{
static QRegExp rx("(\\w*|\\w*\\*)\\.(?:bmp|jpeg|jpg|png)", Qt::CaseInsensitive);
return rx.exactMatch(str);
}
// IPV4 only
F_INLINE bool isValidIPAddress(const QString& str)
{
// [0,255].[0,255].[0,255].[0,255]
static QRegExp rx("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?).){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)");
return rx.exactMatch(str);
}
}
#endif