1139 lines
34 KiB
C++
1139 lines
34 KiB
C++
#include "InfraredTemp.h"
|
||
#include "../../config/ConfigManager.h"
|
||
#include <fstream>
|
||
#include <atlbase.h>
|
||
#include "../../global.h"
|
||
#include "../../Logger.h"
|
||
#include <GL/mesa_gl.h>
|
||
#include <GL/glu.h>
|
||
#include <GL/khronos_glext.h>
|
||
#include <fstream>
|
||
#include "../../utils/DataByte.h"
|
||
#include "turbojpeg.h"
|
||
|
||
unsigned char RAY_AAL_CKSUM(unsigned char* buf, int len);
|
||
|
||
InfraredTemp::InfraredTemp()
|
||
:m_Thread(INVALID_HANDLE_VALUE)
|
||
, m_RunFlag(false)
|
||
, m_IsConnect(false)
|
||
, m_VideoSrcDataUpdate(false)
|
||
, m_TempSrcDataUpdate(false)
|
||
, m_MaxTemp(FLT_MIN)
|
||
, m_ShowFlag(false)
|
||
, m_LogFlag(false)
|
||
{
|
||
m_InfraredTempCfg = ConfigManager::GetInstance()->GetInfraredTempCfg();
|
||
m_MachineCfg = ConfigManager::GetInstance()->GetMachineCfg();
|
||
}
|
||
|
||
InfraredTemp::~InfraredTemp()
|
||
{
|
||
DeleteCriticalSection(&m_CS);
|
||
DeleteCriticalSection(&m_ShowCS);
|
||
DeleteCriticalSection(&m_WaitCS);
|
||
delete[]m_VideoSrcData;
|
||
delete[]m_VideoShowData;
|
||
delete[]m_TempSrcData;
|
||
delete[]m_TempCalcData;
|
||
int res = sdk_logoutDevice(m_Handle);
|
||
if (res == -1)
|
||
{
|
||
g_log->TraceInfo(u8"热成像登出失败");
|
||
}
|
||
sdk_release();
|
||
}
|
||
|
||
bool InfraredTemp::Init()
|
||
{
|
||
m_MouseX = 0;
|
||
m_MouseY = 0;
|
||
//m_TempValueFix = 15.0f;
|
||
srand(time(0));
|
||
InitializeCriticalSection(&m_CS);
|
||
InitializeCriticalSection(&m_ShowCS);
|
||
InitializeCriticalSection(&m_WaitCS);
|
||
m_ImageWidth = 640;
|
||
m_ImageHeight = 512;
|
||
m_Aspect = (float)m_ImageWidth / m_ImageHeight;
|
||
m_VideoSrcData = new char[m_ImageWidth * m_ImageWidth * 1.5];
|
||
m_VideoShowData = new char[m_ImageWidth * m_ImageHeight * 1.5];
|
||
m_TempSrcData = new unsigned short[m_ImageWidth * m_ImageHeight];
|
||
m_TempCalcData = new float[m_ImageWidth * m_ImageHeight];
|
||
m_TempSrcTraData=new float[m_ImageWidth * m_ImageHeight];
|
||
|
||
|
||
CalcPrintPlatform();
|
||
sdk_set_type(0,(char*) "888888",(char*) "888888");
|
||
if (sdk_initialize() != 0) {
|
||
g_log->TraceInfo(u8"热成像初始化失败");
|
||
}
|
||
m_Handle = sdk_create();
|
||
return true;
|
||
}
|
||
|
||
bool InfraredTemp::IsConnect()
|
||
{
|
||
//if (g_isDebug)return true;
|
||
bool rel = false;
|
||
EnterCriticalSection(&m_CS);
|
||
rel = m_IsConnect;
|
||
LeaveCriticalSection(&m_CS);
|
||
return rel;
|
||
}
|
||
|
||
void InfraredTemp::SetConnect(bool bvalue)
|
||
{
|
||
EnterCriticalSection(&m_CS);
|
||
m_IsConnect = bvalue;
|
||
LeaveCriticalSection(&m_CS);
|
||
}
|
||
|
||
void InfraredTemp::Connect()
|
||
{
|
||
|
||
|
||
if (m_InfraredTempCfg->m_IsForceConnect->GetValue()) {
|
||
m_ChanelInfo.channel = 0;
|
||
sprintf_s(m_ChanelInfo.szServerName, sizeof(m_ChanelInfo.szServerName), "IRCAM");
|
||
sprintf_s(m_ChanelInfo.szIP, sizeof(m_ChanelInfo.szIP), m_InfraredTempCfg->m_ForceConnectIP->GetValueStr().c_str());
|
||
m_ChanelInfo.wPortNum = 3000;
|
||
m_ChanelInfo.byChanNum = 0;
|
||
m_ChanelInfo.byChanNum2 = 0;
|
||
m_ChanelInfo.iStreamNum = 0;
|
||
m_ChanelInfo.iStreamNum2 = 0;
|
||
strcpy_s(m_ChanelInfo.szUserName, "888888");
|
||
strcpy_s(m_ChanelInfo.szPWD, "888888");
|
||
//sprintf_s(m_ChanelInfo.szUserName, sizeof(m_ChanelInfo.szUserName), "888888");
|
||
//sprintf_s(m_ChanelInfo.szPWD, sizeof(m_ChanelInfo.szPWD), "888888");
|
||
}
|
||
else {
|
||
DeviceList dl;
|
||
if (sdk_search_device(m_Handle, dl) == -1)
|
||
{
|
||
|
||
return;
|
||
}
|
||
Sleep(1000);
|
||
if (dl.iNumber > 0)
|
||
{
|
||
m_ChanelInfo = dl.DevInfo[0];
|
||
m_ChanelInfo.channel = 0;
|
||
strcpy_s(m_ChanelInfo.szUserName, "888888");
|
||
strcpy_s(m_ChanelInfo.szPWD, "888888");
|
||
// sprintf_s(m_ChanelInfo.szUserName, sizeof(m_ChanelInfo.szUserName), "888888");
|
||
// sprintf_s(m_ChanelInfo.szPWD, sizeof(m_ChanelInfo.szPWD), "888888");
|
||
|
||
|
||
}
|
||
else {
|
||
//sdk_release();
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (sdk_loginDevice(m_Handle, m_ChanelInfo) != 0)
|
||
{
|
||
//sdk_release();
|
||
return;
|
||
}
|
||
SetMessageCallBack(m_Handle, MessageCallBackHandle, this);
|
||
if (SetDeviceVideoCallBack(m_Handle, VideoCallBackHandle, this) != 0)
|
||
{
|
||
//sdk_release();
|
||
|
||
return;
|
||
}
|
||
if (SetTempCallBack(m_Handle, TempCallBackHandle, this) != 0)
|
||
{
|
||
//sdk_release();
|
||
|
||
return;
|
||
}
|
||
|
||
int iOSD = 0;
|
||
INF_OSD osd_info = INF_OSD(0, 0, 0, 0);
|
||
sdk_LoadParamOsd(m_Handle, m_ChanelInfo, &iOSD, &osd_info);
|
||
m_InfraredTempCfg->m_OSDSwitch->SetValue(iOSD == 1 ? true : false);
|
||
m_InfraredTempCfg->m_GlobalTempAdd->SetValue(osd_info.m_g_temp_add == 1 ? true : false);
|
||
m_InfraredTempCfg->m_GlobalTempParamAdd->SetValue(osd_info.m_g_temp_param_add == 1 ? true : false);
|
||
m_InfraredTempCfg->m_PseudoColorBarsAdd->SetValue(osd_info.m_pseudo_add == 1 ? true : false);
|
||
m_InfraredTempCfg->m_HighLowTempCursorAdd->SetValue(osd_info.m_low_hight_temp_pos == 1 ? true : false);
|
||
|
||
if (SetSerialCallBack(m_Handle, m_ChanelInfo, SerialCallBackHandle, this) != 0)
|
||
{
|
||
g_log->TraceInfo("SetSerialCallBack error");
|
||
}
|
||
envir_param ep;
|
||
sdk_get_envir_param(m_Handle, m_ChanelInfo, &ep);
|
||
ep.airTemp = m_InfraredTempCfg->m_AirTemp->GetValue();
|
||
ep.distance = m_InfraredTempCfg->m_Distance->GetValue();
|
||
ep.emissivity = m_InfraredTempCfg->m_Emissivity->GetValue();
|
||
ep.humidity = m_InfraredTempCfg->m_Humidity->GetValue();
|
||
ep.reflectTemp = m_InfraredTempCfg->m_ReflectTemp->GetValue();
|
||
sdk_set_envir_param(m_Handle, m_ChanelInfo, ep);
|
||
sdk_envir_effect(m_Handle);
|
||
|
||
int iUnit = 0;
|
||
if (sdk_get_temp_unit(m_Handle, m_ChanelInfo, &iUnit) != 0) {
|
||
g_log->TraceInfo("sdk_get_temp_unit error");
|
||
}
|
||
m_InfraredTempCfg->m_TempUnit->SetValue(iUnit);
|
||
|
||
int iWidth = 0;
|
||
int iHeight = 0;
|
||
if (sdk_get_width(m_Handle, &iWidth) == 0)
|
||
{
|
||
if (sdk_get_height(m_Handle, &iHeight) == 0)
|
||
{
|
||
}
|
||
}
|
||
|
||
//char recvBufSN[512] = { 0 };
|
||
//char recvBufPN[512] = { 0 };
|
||
//if (sdk_get_SN_PN(m_Handle, m_ChanelInfo, recvBufSN, recvBufPN) == 0)
|
||
//{
|
||
// g_log->TraceInfo("sn:%s pn:%s", recvBufSN, recvBufPN);
|
||
/*sz.Format(_T("SN:%s"), recvBufSN);
|
||
GetDlgItem(IDC_STATIC_SN)->SetWindowText(sz);
|
||
|
||
sz.Format(_T("PN:%s"), recvBufPN);
|
||
GetDlgItem(IDC_STATIC_PN)->SetWindowText(sz);
|
||
|
||
if (sz.Mid(8, 1) == "H")
|
||
{
|
||
tempMeasType = 1;
|
||
((CComboBox*)GetDlgItem(IDC_COMBO_GAIN))->EnableWindow(FALSE);
|
||
}
|
||
else
|
||
{
|
||
tempMeasType = 0;
|
||
((CComboBox*)GetDlgItem(IDC_COMBO_GAIN))->EnableWindow(TRUE);
|
||
}*/
|
||
// }
|
||
|
||
//if (ReadPN(recvBufPN) == 0)
|
||
//{
|
||
// g_log->TraceInfo("pn:%s", recvBufPN);
|
||
//sz.Format(_T("%s"), recvBufPN);
|
||
//if (sz.Left(5) == "AT31U" || sz.Left(5) == "AT61U")
|
||
//{
|
||
// tempMeasType = 2;
|
||
// ((CComboBox*)GetDlgItem(IDC_COMBO_GAIN))->EnableWindow(TRUE);
|
||
//}
|
||
//}
|
||
|
||
//GetGain();
|
||
|
||
//UpdateAutoFocus();
|
||
}
|
||
|
||
void InfraredTemp::Startup()
|
||
{
|
||
if (m_Thread != INVALID_HANDLE_VALUE)return;
|
||
m_RunFlag = true;
|
||
m_Thread = AtlCreateThread(RunPorc, this);
|
||
}
|
||
|
||
void InfraredTemp::Shutdown()
|
||
{
|
||
m_RunFlag = false;
|
||
if (m_Thread != INVALID_HANDLE_VALUE)
|
||
{
|
||
if (WaitForSingleObject(m_Thread, 500) == WAIT_TIMEOUT)
|
||
{
|
||
TerminateThread(m_Thread, 1);
|
||
}
|
||
CloseHandle(m_Thread);
|
||
m_Thread = INVALID_HANDLE_VALUE;
|
||
}
|
||
|
||
}
|
||
|
||
DWORD WINAPI InfraredTemp::RunPorc(InfraredTemp* _this)
|
||
{
|
||
if (_this)
|
||
{
|
||
_this->Run();
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
void InfraredTemp::Run()
|
||
{
|
||
while (m_RunFlag) {
|
||
if (!IsConnect())
|
||
{
|
||
Connect();
|
||
int count = 0;
|
||
while (count<15 && m_RunFlag) {
|
||
Sleep(200);
|
||
count++;
|
||
if (IsConnect()) {
|
||
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
EnterCriticalSection(&m_CS);
|
||
bool isTempUpdate = false;
|
||
|
||
if (m_TempSrcDataUpdate) {
|
||
memcpy(m_TempCalcData, m_TempSrcTraData, m_ImageWidth* m_ImageHeight *sizeof(float));
|
||
m_TempSrcDataUpdate = false;
|
||
isTempUpdate = true;
|
||
}
|
||
/*else {
|
||
if (m_InfraredTempCtrl.sdk_get_TempImaging(&m_TempImageEnable) == 0)
|
||
{
|
||
if (m_TempImageEnable == 2)
|
||
{
|
||
//不支持温度成像切换
|
||
m_IsNewNios = false;
|
||
}
|
||
else
|
||
{
|
||
m_IsNewNios = true;
|
||
}
|
||
}
|
||
}*/
|
||
LeaveCriticalSection(&m_CS);
|
||
|
||
if (isTempUpdate)
|
||
{
|
||
EnterCriticalSection(&m_ShowCS);
|
||
m_MaxTemp = -FLT_MAX;
|
||
//m_MouseXYTemp = m_TempCalcData[m_MouseY*m_ImageWidth + m_MouseX];
|
||
for (size_t regIndex = 0; regIndex < m_TempRegions.size(); regIndex++) {
|
||
TempRegion* tr = m_TempRegions[regIndex];
|
||
float minValue = FLT_MAX;
|
||
float maxValue = -FLT_MAX;
|
||
double sumValue = 0.0;
|
||
int valueCount = 0;
|
||
double avgValue = 0.0;
|
||
if (!m_InfraredTempCfg->m_UseManualPoints) {
|
||
int startY = tr->m_Pa.y < tr->m_Pb.y ? tr->m_Pa.y : tr->m_Pb.y;
|
||
int endY = tr->m_Pd.y > tr->m_Pc.y ? tr->m_Pd.y : tr->m_Pc.y;
|
||
if (startY < 0)startY = 0;
|
||
if (endY >= m_ImageHeight)endY = m_ImageHeight - 1;
|
||
for (int yIndex = startY; yIndex <= endY; yIndex++) {
|
||
int startX = tr->m_Pa.x < tr->m_Pd.x ? tr->m_Pa.x : tr->m_Pd.x;
|
||
int endX = tr->m_Pb.x < tr->m_Pc.x ? tr->m_Pc.x : tr->m_Pb.x;
|
||
if (startX < 0)startX = 0;
|
||
if (endX >= m_ImageWidth)endX = m_ImageWidth - 1;
|
||
for (int xIndex = startX; xIndex <= endX; xIndex++) {
|
||
//int iTemp = (int)m_TempCalcData[yIndex * m_ImageWidth + xIndex];
|
||
float fK = m_TempCalcData[yIndex * m_ImageWidth + xIndex];
|
||
float fC = fK - 273.15f;
|
||
float fF = (fC * 9.0f / 5.0f) + 32.0f;
|
||
if (fC < minValue)minValue = fC;
|
||
if (fC > maxValue)maxValue = fC;
|
||
sumValue += fC;
|
||
valueCount++;
|
||
}
|
||
}
|
||
if (valueCount != 0)avgValue = sumValue / valueCount;
|
||
if (m_InfraredTempCfg->m_IsAvgCalcValue) {
|
||
tr->m_AvgMinTemp.AddValue(minValue);
|
||
tr->m_AvgMaxTemp.AddValue(maxValue);
|
||
tr->m_AvgAvgTemp.AddValue(avgValue);
|
||
tr->m_MinTemp = tr->m_AvgMinTemp.GetAverage();
|
||
tr->m_MaxTemp = tr->m_AvgMaxTemp.GetAverage();
|
||
tr->m_AvgTemp = tr->m_AvgAvgTemp.GetAverage();
|
||
}
|
||
else {
|
||
tr->m_MinTemp = minValue;
|
||
tr->m_MaxTemp = maxValue;
|
||
tr->m_AvgTemp = avgValue;
|
||
}
|
||
if (tr->m_MaxTemp > m_MaxTemp)m_MaxTemp = tr->m_MaxTemp;
|
||
if (tr->m_MaxTemp > tr->m_PrintMaxTemp)tr->m_PrintMaxTemp = tr->m_MaxTemp;
|
||
}
|
||
else {
|
||
if (m_JobController) {
|
||
int layerIndex = m_JobController->GetJob()->GetCurrentLayerIndex();
|
||
for (map<unsigned int, LayerTempPointConfig::LayerRegion*>::iterator it = tr->m_LayerTempPointConfig->m_LayerRegions.begin(); it != tr->m_LayerTempPointConfig->m_LayerRegions.end(); it++) {
|
||
LayerTempPointConfig::LayerRegion* lr = it->second;
|
||
if (lr->startIndex <= layerIndex && lr->endIndex >= layerIndex)
|
||
{
|
||
list<LayerTempPointConfig::TempPoint*>*tps = tr->m_LayerTempPointConfig->m_LayerTempPoints[lr];
|
||
for (list<LayerTempPointConfig::TempPoint*>::iterator tpIt = tps->begin(); tpIt != tps->end(); tpIt++) {
|
||
LayerTempPointConfig::TempPoint* tp = (*tpIt);
|
||
//int iTemp = (int)m_TempCalcData[tp->y * m_ImageWidth + tp->x];
|
||
float fK = m_TempCalcData[tp->y * m_ImageWidth + tp->x];
|
||
float fC = fK - 273.15f;
|
||
float fF = (fC * 9.0f / 5.0f) + 32.0f;
|
||
if (fC < minValue)minValue = fC;
|
||
if (fC > maxValue)maxValue = fC;
|
||
sumValue += fC;
|
||
valueCount++;
|
||
}
|
||
if (valueCount != 0)avgValue = sumValue / valueCount;
|
||
if (m_InfraredTempCfg->m_IsAvgCalcValue) {
|
||
tr->m_AvgMinTemp.AddValue(minValue);
|
||
tr->m_AvgMaxTemp.AddValue(maxValue);
|
||
tr->m_AvgAvgTemp.AddValue(avgValue);
|
||
tr->m_MinTemp = tr->m_AvgMinTemp.GetAverage();
|
||
tr->m_MaxTemp = tr->m_AvgMaxTemp.GetAverage();
|
||
tr->m_AvgTemp = tr->m_AvgAvgTemp.GetAverage();
|
||
}
|
||
else {
|
||
tr->m_MinTemp = minValue;
|
||
tr->m_MaxTemp = maxValue;
|
||
tr->m_AvgTemp = avgValue;
|
||
}
|
||
if (tr->m_MaxTemp > m_MaxTemp)m_MaxTemp = tr->m_MaxTemp;
|
||
if (tr->m_MaxTemp > tr->m_PrintMaxTemp)tr->m_PrintMaxTemp = tr->m_MaxTemp;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
}
|
||
|
||
if (m_ShowFlag) {
|
||
bool isUpdateShow = false;
|
||
EnterCriticalSection(&m_CS);
|
||
if (m_VideoSrcDataUpdate)
|
||
{
|
||
memcpy(m_VideoShowData, m_VideoSrcData, m_VideoDataLength);
|
||
m_VideoSrcDataUpdate = false;
|
||
isUpdateShow = true;
|
||
}
|
||
LeaveCriticalSection(&m_CS);
|
||
//#ifdef _DEBUG
|
||
// isUpdateShow = true;
|
||
//ndif
|
||
if (isUpdateShow) {
|
||
EnterCriticalSection(&m_ShowCS);
|
||
cv::Mat myuv(m_ImageHeight + m_ImageHeight / 2, m_ImageWidth, CV_8UC1, (unsigned char *)m_VideoShowData);
|
||
m_MatSrc.release();
|
||
m_ShowMat.release();
|
||
cvtColor(myuv, m_MatSrc, CV_YUV420p2RGB);
|
||
resize(m_MatSrc, m_ShowMat, cv::Size(m_ImageWidth, m_ImageHeight), 0, 0, 2);
|
||
int ch = m_ShowMat.channels();
|
||
switch (ch)
|
||
{
|
||
case 1:
|
||
cvtColor(m_ShowMat, m_ShowMat, CV_GRAY2BGRA); // GRAY单通道
|
||
break;
|
||
case 3:
|
||
cvtColor(m_ShowMat, m_ShowMat, CV_BGR2BGRA); // BGR三通道
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
cv::polylines(m_ShowMat, m_PrintPlatform.points, true, cv::Scalar(150, 150, 150), 1, 1, 0);
|
||
//cv::circle(m_ShowMat,cv::Point(m_PrintPlatform.centX,m_PrintPlatform.centY),3, cv::Scalar(150, 150, 150),1,1,0);
|
||
//cv::rectangle(m_ShowMat, cv::Point(m_PrintPlatform.startX, m_PrintPlatform.startY), cv::Point(m_PrintPlatform.endX, m_PrintPlatform.endY), cv::Scalar(150, 150, 150), 1, 1, 0);
|
||
for (size_t regIndex = 0; regIndex < m_TempRegions.size(); regIndex++) {
|
||
TempRegion* tr = m_TempRegions[regIndex];
|
||
cv::polylines(m_ShowMat, tr->m_RegionPoints, true, cv::Scalar(0, 255, 0), 1, 1, 0);
|
||
//cv::rectangle(m_ShowMat, cv::Point(tr->startX, tr->startY), cv::Point(tr->endX, tr->endY), cv::Scalar(0, 255, 0), 1, 1, 0);
|
||
cv::putText(m_ShowMat, to_string(tr->m_Id), cv::Point(tr->m_Pa.x + 3, tr->m_Pa.y + 10), cv::FONT_HERSHEY_SIMPLEX, 0.4, cv::Scalar(255, 0, 0), 1);
|
||
}
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
}
|
||
}
|
||
Sleep(100);
|
||
}
|
||
}
|
||
|
||
|
||
unsigned int InfraredTemp::GetShowImage()
|
||
{
|
||
EnterCriticalSection(&m_ShowCS);
|
||
if (!m_ShowMat.data) {
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
return m_GLTex;
|
||
}
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
|
||
if (TryEnterCriticalSection(&m_ShowCS)) {
|
||
if (m_GLTex == 0) {
|
||
GenTex(&m_GLTex, m_ImageWidth, m_ImageHeight, m_ShowMat.data);
|
||
}
|
||
/* else if (m_OriginalWidth != m_ImgWidth || m_OriginalHeight != m_ImgHeight) {
|
||
m_ImgWidth = m_OriginalWidth;
|
||
m_ImgHeight = m_OriginalHeight;
|
||
m_Aspect = (float)m_ImgWidth / m_ImgHeight;
|
||
glDeleteTextures(1, &m_GLTex);
|
||
GenTex(&m_GLTex, m_ImgWidth, m_ImgHeight, m_OriginalData);
|
||
}*/
|
||
else {
|
||
glBindTexture(GL_TEXTURE_2D, m_GLTex);
|
||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_ImageWidth, m_ImageHeight, GL_BGRA_EXT, GL_UNSIGNED_BYTE, m_ShowMat.data);
|
||
glBindTexture(GL_TEXTURE_2D, 0);
|
||
}
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
}
|
||
return m_GLTex;
|
||
}
|
||
|
||
void InfraredTemp::GenTex(uint32_t *tex, unsigned int w, unsigned int h, void * data)
|
||
{
|
||
glGenTextures(1, tex);
|
||
if (*tex > 0) {
|
||
glBindTexture(GL_TEXTURE_2D, *tex);
|
||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, data);
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||
glBindTexture(GL_TEXTURE_2D, 0);
|
||
}
|
||
}
|
||
|
||
bool InfraredTemp::InitLog(IFImage* ifimage)
|
||
{
|
||
if (m_VideoDataLength <= 0)return false;
|
||
EnterCriticalSection(&m_CS);
|
||
int videodatalength = m_VideoDataLength;
|
||
int width = m_ImageWidth;
|
||
int height = m_ImageHeight;
|
||
unsigned char* imtemp = new unsigned char[videodatalength];
|
||
float* data = new float[width * height];
|
||
memcpy(imtemp, m_VideoSrcData, videodatalength);
|
||
memcpy(&data[0], m_TempSrcTraData, width * height * sizeof(float));
|
||
LeaveCriticalSection(&m_CS);
|
||
|
||
cv::Mat myuv(height + height / 2, width, CV_8UC1, imtemp);
|
||
cv::Mat rgbimage;
|
||
cvtColor(myuv, rgbimage, CV_YUV420p2RGBA);
|
||
std::vector<unsigned char> dataEncode;
|
||
vector<int> compression_params;
|
||
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY);
|
||
compression_params.push_back(100);
|
||
cv::imencode(".jpg", rgbimage, dataEncode, compression_params);
|
||
if (!dataEncode.empty()) {
|
||
ifimage->m_Image = new unsigned char[dataEncode.size()];
|
||
for (size_t i = 0; i < dataEncode.size(); i++) {
|
||
ifimage->m_Image[i] = dataEncode[i];
|
||
}
|
||
ifimage->m_ImageLength = dataEncode.size();
|
||
}
|
||
else {
|
||
ifimage->m_ImageLength = 0;
|
||
}
|
||
delete[] imtemp;
|
||
rgbimage.release();
|
||
ifimage->m_ImageCols = width;
|
||
ifimage->m_ImageRows = height;
|
||
ifimage->m_IFData = data;
|
||
|
||
|
||
return true;
|
||
}
|
||
|
||
void InfraredTemp::UpdateEnv()
|
||
{
|
||
if (!IsConnect())return;
|
||
envir_param ep;
|
||
sdk_get_envir_param(m_Handle, m_ChanelInfo, &ep);
|
||
ep.emissivity = m_InfraredTempCfg->m_Emissivity->GetValue();
|
||
ep.airTemp = m_InfraredTempCfg->m_AirTemp->GetValue();
|
||
ep.reflectTemp = m_InfraredTempCfg->m_AirTemp->GetValue();
|
||
ep.humidity = m_InfraredTempCfg->m_Humidity->GetValue();
|
||
ep.distance = m_InfraredTempCfg->m_Distance->GetValue();
|
||
sdk_set_envir_param(m_Handle, m_ChanelInfo, ep);
|
||
sdk_envir_effect(m_Handle);
|
||
}
|
||
|
||
void InfraredTemp::SetOSD()
|
||
{
|
||
if (!IsConnect())return;
|
||
sdk_osd_switch(m_Handle, m_ChanelInfo, m_InfraredTempCfg->m_OSDSwitch->GetValue() ? 1 : 0);
|
||
}
|
||
void InfraredTemp::UpdateOSD()
|
||
{
|
||
if (!IsConnect())return;
|
||
int iOSD = 0;
|
||
INF_OSD osd_info = INF_OSD(0, 0, 0, 0);
|
||
sdk_LoadParamOsd(m_Handle, m_ChanelInfo, &iOSD, &osd_info);
|
||
|
||
osd_info.m_g_temp_add = m_InfraredTempCfg->m_GlobalTempAdd->GetValue() ? 1 : 0;
|
||
osd_info.m_g_temp_param_add = m_InfraredTempCfg->m_GlobalTempParamAdd->GetValue() ? 1 : 0;
|
||
osd_info.m_pseudo_add = m_InfraredTempCfg->m_PseudoColorBarsAdd->GetValue() ? 1 : 0;
|
||
osd_info.m_low_hight_temp_pos = m_InfraredTempCfg->m_HighLowTempCursorAdd->GetValue() ? 1 : 0;
|
||
sdk_SetInfOsd(m_Handle, m_ChanelInfo, osd_info);
|
||
}
|
||
|
||
void InfraredTemp::UpdateColorPalette()
|
||
{
|
||
if (!IsConnect())return;
|
||
int rel=sdk_set_color_plate(m_Handle, m_ChanelInfo, m_InfraredTempCfg->m_ColorPalette->GetValue());
|
||
//g_log->TraceInfo(u8"更改色板模式:%d %d", m_InfraredTempCfg->m_ColorPalette, rel);
|
||
}
|
||
|
||
/*void InfraredTemp::UpdateGain()
|
||
{
|
||
unsigned char gainType = m_InfraredTempCfg->m_GainType;
|
||
if (gainType == 2)
|
||
{
|
||
gainType = 3;
|
||
}
|
||
|
||
unsigned char szCmd[0x09] =
|
||
{
|
||
0xAA, 0x05, 0x07, 0x01, 0x01, 0x00, 0x00, 0xEB, 0xAA
|
||
};
|
||
szCmd[0x05] = gainType;
|
||
szCmd[0x06] = RAY_AAL_CKSUM(szCmd, 0x06);
|
||
|
||
//Send Request
|
||
m_InfraredTempCtrl.sdk_serial_cmd_send((char*)szCmd, 0x09);
|
||
}*/
|
||
|
||
/*void InfraredTemp::GetGain()
|
||
{
|
||
unsigned char cmd[9] = { 0xAA, 0x05, 0x07, 0x01, 0x00, 0x00, 0x00, 0xEB, 0xAA };
|
||
|
||
cmd[0x06] = RAY_AAL_CKSUM(cmd, 0x06);
|
||
|
||
if (m_InfraredTempCtrl.sdk_serial_cmd_send((char*)cmd, 9) == 0)
|
||
{
|
||
int rsize = 0;
|
||
char rbuffer[512];
|
||
if (m_InfraredTempCtrl.sdk_serial_cmd_receive(rbuffer,&rsize)==0) {
|
||
if (rsize > 3 && rbuffer[0] == 0x55 && rbuffer[1] == rsize - 4 && rbuffer[2] == 0x07 && rbuffer[3] == 0x01 && rbuffer[4] == 0x33)
|
||
{
|
||
m_InfraredTempCfg->m_GainType = rbuffer[5];
|
||
}
|
||
}
|
||
|
||
}
|
||
}*/
|
||
|
||
void InfraredTemp::UpdateOverTurn()
|
||
{
|
||
|
||
switch (m_InfraredTempCfg->m_OverTurn->GetValue())
|
||
{
|
||
case 0: {
|
||
unsigned char cmd[9] = { 0xAA, 0x05, 0x00, 0x30, 0x01, 0x01, 0xE1, 0xEB, 0xAA };
|
||
//cmd[0x05] = 0;
|
||
//cmd[0x06] = RAY_AAL_CKSUM(cmd, 0x06);
|
||
sdk_serial_cmd_send(m_Handle, (char*)cmd, 9);
|
||
}break;
|
||
case 1: {
|
||
unsigned char cmd[9] = { 0xAA, 0x05, 0x00, 0x30, 0x01, 0x02, 0xE2, 0xEB, 0xAA };
|
||
//cmd[0x05] = 0;
|
||
//cmd[0x06] = RAY_AAL_CKSUM(cmd, 0x06);
|
||
sdk_serial_cmd_send(m_Handle, (char*)cmd, 9);
|
||
}break;
|
||
case 2: {
|
||
unsigned char cmd[9] = { 0xAA, 0x05, 0x00, 0x30, 0x01, 0x04, 0xE4, 0xEB, 0xAA };
|
||
//cmd[0x05] = 0;
|
||
//cmd[0x06] = RAY_AAL_CKSUM(cmd, 0x06);
|
||
sdk_serial_cmd_send(m_Handle, (char*)cmd, 9);
|
||
}break;
|
||
case 3: {
|
||
unsigned char cmd[9] = { 0xAA, 0x05, 0x00, 0x30, 0x01, 0x08, 0xE8, 0xEB, 0xAA };
|
||
//cmd[0x05] = 0;
|
||
//cmd[0x06] = RAY_AAL_CKSUM(cmd, 0x06);
|
||
sdk_serial_cmd_send(m_Handle, (char*)cmd, 9);
|
||
}break;
|
||
}
|
||
}
|
||
|
||
void InfraredTemp::UpdateAutoFocus()
|
||
{
|
||
unsigned char cmd[9] = { 0xAA, 0x05, 0x08, 0x2F, 0x01, 0x00, 0x00, 0xEB, 0xAA };
|
||
|
||
cmd[0x05] = 0;
|
||
cmd[0x06] = RAY_AAL_CKSUM(cmd, 0x06);
|
||
sdk_serial_cmd_send(m_Handle, (char*)cmd, 9);
|
||
}
|
||
|
||
void InfraredTemp::UpdateTempUnit()
|
||
{
|
||
VSNET_TEMPUNIT_S vts;
|
||
vts.m_unit = m_InfraredTempCfg->m_TempUnit->GetValue();
|
||
sdk_set_temp_unit(m_Handle, m_ChanelInfo, m_InfraredTempCfg->m_TempUnit->GetValue());
|
||
}
|
||
|
||
void InfraredTemp::MessageCallBackHandle(IRNETHANDLE hHandle, WPARAM wParam, LPARAM lParam, void *context)
|
||
{
|
||
InfraredTemp* it = (InfraredTemp*)context;
|
||
switch (wParam)
|
||
{
|
||
case LAUMSG_LINKMSG: {
|
||
switch (lParam) {
|
||
case 0: {
|
||
//连接成功
|
||
it->SetConnect(true);
|
||
g_log->TraceKeyInfo(u8"热成像连接成功");
|
||
}break;
|
||
case 1: {
|
||
//用户停止连接
|
||
it->SetConnect(false);
|
||
g_log->TraceKeyInfo(u8"热成像用户停止连接");
|
||
}break;
|
||
case 2: {
|
||
//连接失败
|
||
it->SetConnect(false);
|
||
g_log->TraceKeyInfo(u8"热成像连接失败");
|
||
}break;
|
||
case 3: {
|
||
//连接断开
|
||
it->SetConnect(false);
|
||
g_log->TraceKeyInfo(u8"热成像连接断开");
|
||
}break;
|
||
case 4: {
|
||
//端口冲突
|
||
g_log->TraceKeyInfo(u8"热成像端口冲突");
|
||
}break;
|
||
}
|
||
}break;
|
||
}
|
||
}
|
||
|
||
void InfraredTemp::TempCallBackHandle(char *pBuffer, long BufferLen, void* pContext)
|
||
{
|
||
InfraredTemp* it = (InfraredTemp*)pContext;
|
||
EnterCriticalSection(&it->m_CS);
|
||
if (!it->m_TempSrcDataUpdate) {
|
||
//g_log->TraceInfo("tempcallLength:%d", BufferLen);
|
||
memcpy(it->m_TempSrcData, pBuffer, it->m_ImageWidth* it->m_ImageHeight * 2);
|
||
for (int j = 0; j < it->m_ImageHeight; j++)
|
||
{
|
||
for (int i = 0; i < it->m_ImageWidth; i++)
|
||
{
|
||
//判断温度区间0~7300,则温度换算公式(换算为摄氏度)(Value+7000)/30-273.2
|
||
//7301~16383, (Value-3300)/15-273.2
|
||
// if (it->m_TempImageEnable&& it->m_IsNewNios)
|
||
// {
|
||
if (it->m_TempSrcData[j * it->m_ImageWidth + i] > 7300) //7301~16383, (Value-3300)/15-273.2
|
||
{
|
||
//it->m_TempValueFix = 15.0f;
|
||
it->m_TempSrcTraData[j * it->m_ImageWidth + i] = (float)(it->m_TempSrcData[j * it->m_ImageWidth + i] - 3300)/15.0f;
|
||
}
|
||
else //0~7300,则温度换算公式(换算为摄氏度)(Value + 7000) / 30 - 273.2
|
||
{
|
||
//it->m_TempValueFix = 30.0f;
|
||
it->m_TempSrcTraData[j * it->m_ImageWidth + i] = (float)(it->m_TempSrcData[j * it->m_ImageWidth + i] + 7000)/30.0f;
|
||
}
|
||
// }
|
||
// else
|
||
// {
|
||
// it->m_TempValueFix = 10.0f;
|
||
// }
|
||
}
|
||
}
|
||
it->m_TempSrcDataUpdate = true;
|
||
}
|
||
LeaveCriticalSection(&it->m_CS);
|
||
}
|
||
|
||
void InfraredTemp::VideoCallBackHandle(char *pBuffer, long BufferLen, int width, int height, void* pContext)
|
||
{
|
||
InfraredTemp* it = (InfraredTemp*)pContext;
|
||
if ((it->m_ShowFlag && !it->m_VideoSrcDataUpdate) || it->m_LogFlag)
|
||
{
|
||
EnterCriticalSection(&it->m_CS);
|
||
memcpy(it->m_VideoSrcData, pBuffer, BufferLen);
|
||
it->m_VideoSrcDataUpdate = true;
|
||
it->m_VideoDataLength = BufferLen;
|
||
LeaveCriticalSection(&it->m_CS);
|
||
}
|
||
}
|
||
|
||
void InfraredTemp::SerialCallBackHandle(char *pRecvDataBuff, int BuffSize, void* pContext)
|
||
{
|
||
InfraredTemp* it = (InfraredTemp*)pContext;
|
||
}
|
||
|
||
unsigned char RAY_AAL_CKSUM(unsigned char* buf, int len)
|
||
{
|
||
unsigned char cksum = 0;
|
||
int i;
|
||
|
||
for (i = 0; i < len; i++)
|
||
{
|
||
cksum += buf[i];
|
||
}
|
||
|
||
return cksum;
|
||
}
|
||
|
||
void InfraredTemp::AddTempRegion(TempRegion* tr)
|
||
{
|
||
if (!tr)return;
|
||
EnterCriticalSection(&m_ShowCS);
|
||
m_TempRegions.push_back(tr);
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
}
|
||
|
||
void InfraredTemp::ClearTempRegion()
|
||
{
|
||
EnterCriticalSection(&m_ShowCS);
|
||
for (size_t i = 0; i < m_TempRegions.size(); i++) {
|
||
delete m_TempRegions[i];
|
||
m_TempRegions[i] = NULL;
|
||
}
|
||
m_TempRegions.clear();
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
}
|
||
|
||
void InfraredTemp::CalcPrintPlatform()
|
||
{
|
||
EnterCriticalSection(&m_ShowCS);
|
||
m_PrintPlatform.points.clear();
|
||
m_PrintPlatform.pa.x = m_InfraredTempCfg->m_PlatformAX->GetValue();
|
||
m_PrintPlatform.pa.y = m_InfraredTempCfg->m_PlatformAY->GetValue();
|
||
m_PrintPlatform.pb.x = m_InfraredTempCfg->m_PlatformBX->GetValue();
|
||
m_PrintPlatform.pb.y = m_InfraredTempCfg->m_PlatformBY->GetValue();
|
||
m_PrintPlatform.pc.x = m_InfraredTempCfg->m_PlatformCX->GetValue();
|
||
m_PrintPlatform.pc.y = m_InfraredTempCfg->m_PlatformCY->GetValue();
|
||
m_PrintPlatform.pd.x = m_InfraredTempCfg->m_PlatformDX->GetValue();
|
||
m_PrintPlatform.pd.y = m_InfraredTempCfg->m_PlatformDY->GetValue();
|
||
m_PrintPlatform.points.push_back(m_PrintPlatform.pa);
|
||
m_PrintPlatform.points.push_back(m_PrintPlatform.pb);
|
||
m_PrintPlatform.points.push_back(m_PrintPlatform.pc);
|
||
m_PrintPlatform.points.push_back(m_PrintPlatform.pd);
|
||
|
||
cv::Point2f srcTri[4];
|
||
srcTri[0] = cv::Point2f(0, 0);
|
||
srcTri[1] = cv::Point2f(m_MachineCfg->m_PlatformLength, 0);
|
||
srcTri[2] = cv::Point2f(0, m_MachineCfg->m_PlatformWidth);
|
||
srcTri[3] = cv::Point2f(m_MachineCfg->m_PlatformLength, m_MachineCfg->m_PlatformWidth);
|
||
cv::Point2f dstTri[4];
|
||
dstTri[0] = cv::Point2f(m_PrintPlatform.pa.x, m_PrintPlatform.pa.y);
|
||
dstTri[1] = cv::Point2f(m_PrintPlatform.pb.x, m_PrintPlatform.pb.y);
|
||
dstTri[2] = cv::Point2f(m_PrintPlatform.pd.x, m_PrintPlatform.pd.y);
|
||
dstTri[3] = cv::Point2f(m_PrintPlatform.pc.x, m_PrintPlatform.pc.y);
|
||
cv::Mat warp_mat = getPerspectiveTransform(srcTri, dstTri);
|
||
|
||
const int row = warp_mat.rows;
|
||
const int col = warp_mat.cols;
|
||
//double temp[3][3];
|
||
|
||
for (int i = 0; i < 3; i++) {
|
||
for (int j = 0; j < 3; j++) {
|
||
m_PlatformRef[i][j] = warp_mat.at<double>(i, j);
|
||
}
|
||
}
|
||
|
||
|
||
for (size_t regIndex = 0; regIndex < m_TempRegions.size(); regIndex++) {
|
||
TempRegion* tr = m_TempRegions[regIndex];
|
||
CalcRefRegion(tr);
|
||
}
|
||
/*m_PrintPlatform.startX = m_InfraredTempCfg->m_PlatformStartX;
|
||
m_PrintPlatform.startY = m_InfraredTempCfg->m_PlatformStartY;
|
||
m_PrintPlatform.endX = m_InfraredTempCfg->m_PlatformEndX;
|
||
m_PrintPlatform.endY = m_InfraredTempCfg->m_PlatformEndY;
|
||
m_PrintPlatform.ratioX = (float)(m_PrintPlatform.endX - m_PrintPlatform.startX) / m_MachineCfg->m_PlatformLength;
|
||
m_PrintPlatform.ratioY = (float)(m_PrintPlatform.endY - m_PrintPlatform.startY)/m_MachineCfg->m_PlatformWidth;
|
||
m_PrintPlatform.centX = m_PrintPlatform.startX+(m_PrintPlatform.endX - m_PrintPlatform.startX) / 2;
|
||
m_PrintPlatform.centY = m_PrintPlatform.startY+(m_PrintPlatform.endY - m_PrintPlatform.startY) / 2;
|
||
|
||
for (size_t regIndex = 0; regIndex < m_TempRegions.size(); regIndex++) {
|
||
TempRegion* tr = m_TempRegions[regIndex];
|
||
CalcRefRegion(tr);
|
||
}*/
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
}
|
||
|
||
void InfraredTemp::CalcRefRegion(TempRegion* tr)
|
||
{
|
||
if (!tr)return;
|
||
|
||
float halfWidth = (float)m_MachineCfg->m_PlatformLength / 2.0f;
|
||
float halfHigh = (float)m_MachineCfg->m_PlatformWidth / 2.0f;
|
||
float ax = halfWidth + tr->m_PartMinX;
|
||
float ay = halfHigh - tr->m_PartMaxY;
|
||
float bx = halfWidth + tr->m_PartMaxX;
|
||
float by = halfHigh - tr->m_PartMaxY;
|
||
float cx = halfWidth + tr->m_PartMaxX;
|
||
float cy = halfHigh - tr->m_PartMinY;
|
||
float dx = halfWidth + tr->m_PartMinX;
|
||
float dy = halfHigh - tr->m_PartMinY;
|
||
|
||
tr->m_Pa.x = (m_PlatformRef[0][0] * ax + m_PlatformRef[0][1] * ay + m_PlatformRef[0][2]) / (m_PlatformRef[2][0] * ax + m_PlatformRef[2][1] * ay + m_PlatformRef[2][2]);
|
||
tr->m_Pa.y = (m_PlatformRef[1][0] * ax + m_PlatformRef[1][1] * ay + m_PlatformRef[1][2]) / (m_PlatformRef[2][0] * ax + m_PlatformRef[2][1] * ay + m_PlatformRef[2][2]);
|
||
tr->m_Pb.x = (m_PlatformRef[0][0] * bx + m_PlatformRef[0][1] * by + m_PlatformRef[0][2]) / (m_PlatformRef[2][0] * bx + m_PlatformRef[2][1] * by + m_PlatformRef[2][2]);
|
||
tr->m_Pb.y = (m_PlatformRef[1][0] * bx + m_PlatformRef[1][1] * by + m_PlatformRef[1][2]) / (m_PlatformRef[2][0] * bx + m_PlatformRef[2][1] * by + m_PlatformRef[2][2]);
|
||
tr->m_Pc.x = (m_PlatformRef[0][0] * cx + m_PlatformRef[0][1] * cy + m_PlatformRef[0][2]) / (m_PlatformRef[2][0] * cx + m_PlatformRef[2][1] * cy + m_PlatformRef[2][2]);
|
||
tr->m_Pc.y = (m_PlatformRef[1][0] * cx + m_PlatformRef[1][1] * cy + m_PlatformRef[1][2]) / (m_PlatformRef[2][0] * cx + m_PlatformRef[2][1] * cy + m_PlatformRef[2][2]);
|
||
tr->m_Pd.x = (m_PlatformRef[0][0] * dx + m_PlatformRef[0][1] * dy + m_PlatformRef[0][2]) / (m_PlatformRef[2][0] * dx + m_PlatformRef[2][1] * dy + m_PlatformRef[2][2]);
|
||
tr->m_Pd.y = (m_PlatformRef[1][0] * dx + m_PlatformRef[1][1] * dy + m_PlatformRef[1][2]) / (m_PlatformRef[2][0] * dx + m_PlatformRef[2][1] * dy + m_PlatformRef[2][2]);
|
||
|
||
|
||
if (tr->m_Pa.x < 0)tr->m_Pa.x = 0;
|
||
if (tr->m_Pa.x >= m_ImageWidth) tr->m_Pa.x = m_ImageWidth - 1;
|
||
|
||
if (tr->m_Pb.x < 0)tr->m_Pb.x = 0;
|
||
if (tr->m_Pb.x >= m_ImageWidth) tr->m_Pb.x = m_ImageWidth - 1;
|
||
|
||
if (tr->m_Pc.x < 0)tr->m_Pc.x = 0;
|
||
if (tr->m_Pc.x >= m_ImageWidth) tr->m_Pc.x = m_ImageWidth - 1;
|
||
|
||
if (tr->m_Pd.x < 0)tr->m_Pd.x = 0;
|
||
if (tr->m_Pd.x >= m_ImageWidth) tr->m_Pd.x = m_ImageWidth - 1;
|
||
|
||
if (tr->m_Pa.y < 0)tr->m_Pa.y = 0;
|
||
if (tr->m_Pa.y >= m_ImageHeight) tr->m_Pa.y = m_ImageHeight - 1;
|
||
|
||
if (tr->m_Pb.y < 0)tr->m_Pb.y = 0;
|
||
if (tr->m_Pb.y >= m_ImageHeight) tr->m_Pb.y = m_ImageHeight - 1;
|
||
|
||
if (tr->m_Pc.y < 0)tr->m_Pc.y = 0;
|
||
if (tr->m_Pc.y >= m_ImageHeight) tr->m_Pc.y = m_ImageHeight - 1;
|
||
|
||
if (tr->m_Pd.y < 0)tr->m_Pd.y = 0;
|
||
if (tr->m_Pd.y >= m_ImageHeight) tr->m_Pd.y = m_ImageHeight - 1;
|
||
|
||
tr->m_RegionPoints.clear();
|
||
tr->m_RegionPoints.push_back(tr->m_Pa);
|
||
tr->m_RegionPoints.push_back(tr->m_Pb);
|
||
tr->m_RegionPoints.push_back(tr->m_Pc);
|
||
tr->m_RegionPoints.push_back(tr->m_Pd);
|
||
//g_log->TraceKeyInfo(u8"centx:%d centy:%d startx:%d starty:%d endx:%d endy:%d", m_PrintPlatform.centX, m_PrintPlatform.centY, tr->startX, tr->startY, tr->endX, tr->endY);
|
||
}
|
||
|
||
void InfraredTemp::GetPartTemp(vector<PartTempStat>& pts)
|
||
{
|
||
EnterCriticalSection(&m_ShowCS);
|
||
for (size_t regIndex = 0; regIndex < m_TempRegions.size(); regIndex++) {
|
||
TempRegion* tr = m_TempRegions[regIndex];
|
||
PartTempStat stat;
|
||
stat.id = tr->m_Id;
|
||
//stat.pid = tr->m_Pid;
|
||
stat.avgTemp = tr->m_AvgTemp;
|
||
stat.minTemp = tr->m_MinTemp;
|
||
stat.maxTemp = tr->m_MaxTemp;
|
||
stat.printMaxTemp = tr->m_PrintMaxTemp;
|
||
pts.push_back(stat);
|
||
}
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
}
|
||
|
||
/*
|
||
void InfraredTemp::GetPartTempCtrlPower(vector<PartTempStat>& pts)
|
||
{
|
||
EnterCriticalSection(&m_ShowCS);
|
||
for (size_t regIndex = 0; regIndex < m_TempRegions.size(); regIndex++) {
|
||
TempRegion* tr = m_TempRegions[regIndex];
|
||
PartTempStat stat;
|
||
stat.id = tr->m_Id;
|
||
//stat.pid = tr->m_Pid;
|
||
stat.avgTemp = tr->m_AvgTemp;
|
||
stat.minTemp = tr->m_MinTemp;
|
||
stat.maxTemp = tr->m_MaxTemp;
|
||
stat.printMaxTemp = tr->m_PrintMaxTemp;
|
||
if (m_InfraredTempCfg->m_TempCtrlType == InfraredTempCfg::CTRL_POWER) {
|
||
float dif = tr->m_MaxTemp - tr->m_LastWaitTemp;
|
||
if (dif > 0) {
|
||
float rel = dif - m_InfraredTempCfg->m_DeltaTemp;
|
||
if (rel > 0)
|
||
{
|
||
tr->m_DifTemp = dif;
|
||
tr->m_DifPower -= m_InfraredTempCfg->m_DeltaPower;
|
||
|
||
tr->m_LastWaitTemp = tr->m_MaxTemp;
|
||
}
|
||
}
|
||
else {
|
||
float rel = dif + m_InfraredTempCfg->m_DeltaTemp;
|
||
if (rel < 0) {
|
||
tr->m_DifTemp = dif;
|
||
tr->m_DifPower += m_InfraredTempCfg->m_DeltaPower;
|
||
|
||
tr->m_LastWaitTemp = tr->m_MaxTemp;
|
||
}
|
||
}
|
||
stat.difTemp = dif;
|
||
stat.difPower = tr->m_DifPower;
|
||
if (m_JobController && m_JobController->GetJob()) {
|
||
MetaData* md = m_JobController->GetJob()->GetMetaData();
|
||
if (md) {
|
||
md->GetPart(tr->m_Id)->powerAdjustValue = tr->m_DifPower;
|
||
}
|
||
}
|
||
}
|
||
pts.push_back(stat);
|
||
}
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
}
|
||
|
||
*/
|
||
void InfraredTemp::GetPartTempCoveredWait(vector<PartTempStat>& pts)
|
||
{
|
||
EnterCriticalSection(&m_ShowCS);
|
||
for (size_t regIndex = 0; regIndex < m_TempRegions.size(); regIndex++) {
|
||
TempRegion* tr = m_TempRegions[regIndex];
|
||
PartTempStat stat;
|
||
stat.id = tr->m_Id;
|
||
//stat.pid = tr->m_Pid;
|
||
stat.avgTemp = tr->m_AvgTemp;
|
||
stat.minTemp = tr->m_MinTemp;
|
||
stat.maxTemp = tr->m_MaxTemp;
|
||
stat.printMaxTemp = tr->m_PrintMaxTemp;
|
||
tr->m_LastWaitTemp = tr->m_MaxTemp;
|
||
pts.push_back(stat);
|
||
}
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
}
|
||
|
||
void InfraredTemp::ResetPrintMax()
|
||
{
|
||
EnterCriticalSection(&m_ShowCS);
|
||
for (size_t regIndex = 0; regIndex < m_TempRegions.size(); regIndex++) {
|
||
TempRegion* tr = m_TempRegions[regIndex];
|
||
tr->m_PrintMaxTemp = tr->m_MaxTemp;
|
||
}
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
}
|
||
|
||
void InfraredTemp::ResetWaitFlag()
|
||
{
|
||
EnterCriticalSection(&m_ShowCS);
|
||
for (size_t regIndex = 0; regIndex < m_TempRegions.size(); regIndex++) {
|
||
TempRegion* tr = m_TempRegions[regIndex];
|
||
tr->m_HadWait = false;
|
||
}
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
}
|
||
|
||
bool InfraredTemp::IsPartWaited(int partid)
|
||
{
|
||
bool rel = false;
|
||
EnterCriticalSection(&m_ShowCS);
|
||
for (size_t regIndex = 0; regIndex < m_TempRegions.size(); regIndex++) {
|
||
TempRegion* tr = m_TempRegions[regIndex];
|
||
|
||
if (tr->m_Id == partid)
|
||
{
|
||
rel = tr->m_HadWait;
|
||
break;
|
||
}
|
||
}
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
return rel;
|
||
}
|
||
|
||
void InfraredTemp::SetPartWaited(int partid)
|
||
{
|
||
EnterCriticalSection(&m_ShowCS);
|
||
for (size_t regIndex = 0; regIndex < m_TempRegions.size(); regIndex++) {
|
||
TempRegion* tr = m_TempRegions[regIndex];
|
||
if (tr->m_Id == partid)
|
||
{
|
||
tr->m_HadWait = true;
|
||
break;
|
||
}
|
||
}
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
}
|
||
|
||
bool InfraredTemp::IsOverChillDown()
|
||
{
|
||
bool rel = false;
|
||
EnterCriticalSection(&m_ShowCS);
|
||
if (m_MaxTemp > m_InfraredTempCfg->m_ChillDowmTemp->GetValue())
|
||
{
|
||
rel = true;
|
||
}
|
||
else rel = false;
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
return rel;
|
||
}
|
||
|
||
void InfraredTemp::SaveTempData()
|
||
{
|
||
ofstream ofs("d:/image.dat", ios::binary);
|
||
if (ofs.is_open())
|
||
{
|
||
|
||
EnterCriticalSection(&m_CS);
|
||
for (int i = 0; i < m_ImageWidth*m_ImageHeight * 1.5; i++) {
|
||
ofs.write(&m_VideoSrcData[i], 1);
|
||
}
|
||
ofs.flush();
|
||
LeaveCriticalSection(&m_CS);
|
||
ofs.close();
|
||
}
|
||
|
||
ofs.open("d:/srctemp.dat", ios::binary);
|
||
{
|
||
|
||
EnterCriticalSection(&m_CS);
|
||
char* data = (char*)m_TempSrcData;
|
||
for (int i = 0; i < m_ImageWidth*m_ImageHeight * 2; i++) {
|
||
ofs.write(&data[i], 1);
|
||
}
|
||
ofs.flush();
|
||
LeaveCriticalSection(&m_CS);
|
||
ofs.close();
|
||
}
|
||
}
|
||
|
||
|
||
|
||
void InfraredTemp::SetAvgSize()
|
||
{
|
||
EnterCriticalSection(&m_ShowCS);
|
||
for (size_t regIndex = 0; regIndex < m_TempRegions.size(); regIndex++) {
|
||
TempRegion* tr = m_TempRegions[regIndex];
|
||
tr->SetAvgSize(m_InfraredTempCfg->m_AvgCalcValueType->GetValue());
|
||
}
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
}
|
||
|
||
bool InfraredTemp::WaitTempReady(int partId)
|
||
{
|
||
bool rel = false;
|
||
EnterCriticalSection(&m_ShowCS);
|
||
for (size_t regIndex = 0; regIndex < m_TempRegions.size(); regIndex++) {
|
||
TempRegion* tr = m_TempRegions[regIndex];
|
||
if (tr->m_Id == partId)
|
||
{
|
||
if (tr->m_HadWait)
|
||
{
|
||
rel = true;
|
||
break;
|
||
}
|
||
if (tr->m_MaxTemp <= m_InfraredTempCfg->m_ChillDowmTemp->GetValue()) {
|
||
rel = true;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
LeaveCriticalSection(&m_ShowCS);
|
||
return rel;
|
||
}
|
||
|
||
unsigned int InfraredTemp::GetShowIFImage(unsigned char* data, unsigned long size, int* width, int* height)
|
||
{
|
||
if (data == NULL || size == 0)
|
||
return 0;
|
||
|
||
int inSubsamp, inColorspace;
|
||
tjhandle tjInstance = tjInitDecompress();
|
||
if (tjDecompressHeader3(tjInstance, data, size, width, height,
|
||
&inSubsamp, &inColorspace) < 0) {
|
||
tjDestroy(tjInstance);
|
||
return 0;
|
||
}
|
||
|
||
unsigned char* ptmp = tjAlloc((*width) * (*height) * tjPixelSize[TJPF_RGBA]);
|
||
if (tjDecompress2(tjInstance, data, size, ptmp, *width, 0, *height, TJPF_RGBA, 0) < 0) {
|
||
tjFree(ptmp);
|
||
tjDestroy(tjInstance);
|
||
return 0;
|
||
}
|
||
|
||
tjDestroy(tjInstance);
|
||
glDeleteTextures(1, &m_LogGLTex);
|
||
m_LogGLTex = 0;
|
||
GenTex(&m_LogGLTex, *width, *height, ptmp);
|
||
tjFree(ptmp);
|
||
return m_LogGLTex;
|
||
} |