ENRIT/InterfaceManager.cpp
@@ -638,7 +638,7 @@
         if(pCamera == NULL)
            continue;         
         pBuffer = m_pInspect[iCam]->GetFullImgBuffer(iScan);
         pBuffer = m_pInspect[iCam]->GetFullImgBuffer(iScan);
         if(pBuffer == NULL)
            continue;         
@@ -654,11 +654,160 @@
   g_pLog->DisplayMessage(_T("Full Image Save Completed : Time[%d]"),GetTickCount()-dwTick);
}
void CInterfaceManager::CoordProfileJudge(HISTORY_RESULT& pHistory)
{
   PROFILECHAMFER_RESULT_DATA* pProfileResult1 = m_GlassData.GetProfileInspectData();
   pHistory.bResult = TRUE;
   CINSPECT_JUDGEMENT_PARM* pJudges = m_GlassRecipe.GetJudgePrm();
   NgInfo ngArray[3][NG_INF_TOTAL];
   BlVision_GetSoftVisionApp()->Execute(4, ngArray[0]);
   BlVision_GetSoftVisionApp()->Execute(5, ngArray[1]);
   BlVision_GetSoftVisionApp()->Execute(7, ngArray[2]);
   pHistory.nProAlarmResultCountB = 0;
   pHistory.nProAlarmResultCountA = 0;
   pHistory.nProAlarmResultCountD = 0;
   pHistory.nProAlarmResultCountC = 0;
   for (int i = 0; i < 3; i++)
   {
      /*A-BOT*/
      if (i == 0)
      {
         for (int c = 33; c < 47; c++)
         {
            if (pProfileResult1->ProfileData[c].bUseJudge == 1)
            {
               if (pHistory.nProfileDiff[c] > pJudges->nMinProfileNgCount_MinDiff[4])
               {
                  pHistory.bResult = FALSE;
               }
               if (pHistory.nProfileDiff[c] < -1 * pProfileResult1->ProfileData[c].nJudgeMinus || pHistory.nProfileDiff[c] > pProfileResult1->ProfileData[c].nJudgePlus)
               {
                  pHistory.nProAlarmResultCountA += 1;
               }
            }
         }
         for (int z = 0; z < 50; z++)
         {
            if (ngArray[i][z].ngType == 5 && ngArray[i][z].id < 6)
            {
               if (ngArray[i][z].maxValue<ngArray[i][z].result || ngArray[i][z].minValue>ngArray[i][z].result)
               {
                  pHistory.nProAlarmResultCountA += 1;
                  if (pHistory.nProAlarmResultCountA > pJudges->nMinProfileNgCount[4] || ngArray[i][z].result > pJudges->nMinProfileNgCount_MinDiff[4])
                     pHistory.bResult = FALSE;
               }
            }
            if (ngArray[i][z].ngType == 5 && (5 < ngArray[i][z].id && ngArray[i][z].id < 11))
            {
               if (ngArray[i][z].maxValue<ngArray[i][z].result || ngArray[i][z].minValue>ngArray[i][z].result)
               {
                  pHistory.nProAlarmResultCountA += 1;
                  if (pHistory.nProAlarmResultCountA > pJudges->nMinProfileNgCount[4] || ngArray[i][z].result > pJudges->nMinProfileNgCount_MinDiff[4])
                     pHistory.bResult = FALSE;
               }
            }
         }
      }
      /*B-BOT*/
      if (i == 1)
      {
         for (int c = 0; c < 10; c++)
         {
            if (pProfileResult1->ProfileData[c].bUseJudge == 1)
            {
               if (pHistory.nProfileDiff[c] > pJudges->nMinProfileNgCount_MinDiff[5])
               {
                  pHistory.bResult = FALSE;
               }
               if (pHistory.nProfileDiff[c] < -1 * pProfileResult1->ProfileData[c].nJudgeMinus || pHistory.nProfileDiff[c] > pProfileResult1->ProfileData[c].nJudgePlus)
               {
                  pHistory.nProAlarmResultCountB += 1;
               }
            }
         }
         for (int z = 0; z < 50; z++)
         {
            if (ngArray[i][z].ngType == 5 && ngArray[i][z].id < 6)
            {
               if (ngArray[i][z].maxValue<ngArray[i][z].result || ngArray[i][z].minValue>ngArray[i][z].result)
               {
                  pHistory.nProAlarmResultCountB += 1;
                  if (pHistory.nProAlarmResultCountB > pJudges->nMinProfileNgCount[5] || ngArray[i][z].result > pJudges->nMinProfileNgCount_MinDiff[5])
                     pHistory.bResult = FALSE;
               }
            }
         }
      }
      /*D-BOT*/
      if (i == 2)
      {
         for (int c = 23; c < 33; c++)
         {
            if (pProfileResult1->ProfileData[c].bUseJudge == 1)
            {
               if (pHistory.nProfileDiff[c] > pJudges->nMinProfileNgCount_MinDiff[7])
               {
                  pHistory.bResult = FALSE;
               }
               if (pHistory.nProfileDiff[c] < -1 * pProfileResult1->ProfileData[c].nJudgeMinus || pHistory.nProfileDiff[c] > pProfileResult1->ProfileData[c].nJudgePlus)
               {
                  pHistory.nProAlarmResultCountD += 1;
               }
            }
         }
         for (int z = 0; z < 50; z++)
         {
            if (ngArray[i][z].ngType == 5 && ngArray[i][z].id < 6)
            {
               if (ngArray[i][z].maxValue<ngArray[i][z].result || ngArray[i][z].minValue>ngArray[i][z].result)
               {
                  pHistory.nProAlarmResultCountD += 1;
                  if (pHistory.nProAlarmResultCountD > pJudges->nMinProfileNgCount[7] || ngArray[i][z].result > pJudges->nMinProfileNgCount_MinDiff[7])
                     pHistory.bResult = FALSE;
               }
            }
         }
      }
   }
   for (int i = 10; i < 23; i++)
   {
      if (pProfileResult1->ProfileData[i].bUseJudge == 1)
      {
         if (pHistory.nProfileDiff[i] < -1 * pProfileResult1->ProfileData[i].nJudgeMinus || pHistory.nProfileDiff[i] > pProfileResult1->ProfileData[i].nJudgePlus)
         {
            pHistory.nProAlarmResultCountC += 1;
            if (pHistory.nProAlarmResultCountD > pJudges->nMinProfileNgCount[6] || pHistory.nProfileDiff[i] > pJudges->nMinProfileNgCount_MinDiff[6])
               pHistory.bResult = FALSE;
         }
      }
   }
}
void CInterfaceManager::WritePLCResult(HISTORY_RESULT &pHistory)
{
   short *pResult = m_GlassData.GetGlassResultInfo();
   ZeroMemory(pResult,sizeof(short)*5);
   if (m_HardwareRecipe.GetCoordProfileUse() == 1)
   {
      CoordProfileJudge(pHistory);
      if (pHistory.nDefectCnt- (pHistory.nProAlarmResultCountD+ pHistory.nProAlarmResultCountB+ pHistory.nProAlarmResultCountA+ pHistory.nProAlarmResultCountC) >0 )
         pHistory.bResult = FALSE;
   }
   // 0 : OK, 1 : NG
   if(pHistory.bResult == TRUE)
   {
@@ -667,24 +816,85 @@
   }
   else
   {
      pResult[0] = 1;
      g_pLog->DisplayMessage(_T("Inspection Result Glass %s - NG"),g_pBase->m_strHPanelID);
      if (g_pLog->m_nHoleAlarmState ==TRUE)
      {
         pResult[10] = g_pLog->m_nHoleAlarmState;
         pResult[0] = 1;
         g_pLog->m_nHoleAlarmState = 0;
         g_pLog->DisplayMessage(_T("Inspection Result Glass %s - NG, Hole Alarm%d-NG"), g_pBase->m_strHPanelID, pResult[10]);
      }
      else
      {
         pResult[0] = 1;
         pResult[10] = 0;
         g_pLog->DisplayMessage(_T("Inspection Result Glass %s - NG"), g_pBase->m_strHPanelID);
      }
   }
   m_GlassData.GetStageTheta(0,pResult[1],pResult[2]);
   m_GlassData.GetStageTheta(1,pResult[3],pResult[4]);
   m_pControlInterface->SendCIMData(pResult,PLC_ADDR_GLASS_JUDEMENT,5);
   g_pLog->DisplayMessage(_T("write PLC Result Data : Resut %d,1_L_Theat %d,1_S_Theat %d,2_L_Theat %d,2_S_Theat %d"),pResult[0],pResult[1],pResult[2],pResult[3],pResult[4]);
   m_pControlInterface->SendCIMData(pResult,PLC_ADDR_GLASS_JUDEMENT,11);
   g_pLog->DisplayMessage(_T("write PLC Result Data : Resut %d,1_L_Theat %d,1_S_Theat %d,2_L_Theat %d,2_S_Theat %d,pResult[10]:%d"),pResult[0],pResult[1],pResult[2],pResult[3],pResult[4], pResult[10]);
   INS_PROFILE_RESULT_INFO *pProfileResult = m_GlassData.GetProfileResultInfo();
   for(int i=0;i<MAX_PROFILE_SETTING_COUNT;i++)
   {
      pProfileResult->nProfileData[i] = pHistory.nProfileDiff[i];
      /*pProfileResult->nProfileData[i] = pHistory.nProfileDiff[i];
      pProfileResult->nChamferUp[i] = pHistory.nChamferThickUp[i];
      pProfileResult->nChamferDn[i] = pHistory.nChamferThickDn[i];
      pProfileResult->nChamferDn[i] = pHistory.nChamferThickDn[i];*/
      //上报测量精度及研磨量数据到CIM
      if (i<10)
      {
         pProfileResult->nProfileData[i] = pHistory.nAVGProfileDiff[1];
         pProfileResult->nChamferUp[i] = pHistory.nAVGChamferThickUp[1];
         pProfileResult->nChamferDn[i] = pHistory.nAVGChamferThickDn[1];
      }
      if (i<23&&i>=10)
      {
         pProfileResult->nProfileData[i] = pHistory.nAVGProfileDiff[2];
         pProfileResult->nChamferUp[i] = pHistory.nAVGChamferThickUp[2];
         pProfileResult->nChamferDn[i] = pHistory.nAVGChamferThickDn[2];
      }if (i<33&&i>=23)
      {
         pProfileResult->nProfileData[i] = pHistory.nAVGProfileDiff[3];
         pProfileResult->nChamferUp[i] = pHistory.nAVGChamferThickUp[3];
         pProfileResult->nChamferDn[i] = pHistory.nAVGChamferThickDn[3];
      }if (i<46&&i>=33)
      {
         pProfileResult->nProfileData[i] = pHistory.nAVGProfileDiff[0];
         pProfileResult->nChamferUp[i] = pHistory.nAVGChamferThickUp[0];
         pProfileResult->nChamferDn[i] = pHistory.nAVGChamferThickDn[0];
      }if (i<59&&i>=46)
      {
         pProfileResult->nProfileData[i] = pHistory.nAVGProfileDiff[4];
         pProfileResult->nChamferUp[i] = pHistory.nAVGChamferThickUp[4];
         pProfileResult->nChamferDn[i] = pHistory.nAVGChamferThickDn[4];
      }
      if (i<64&&i>=59)
      {
         pProfileResult->nProfileData[i] = pHistory.nAVGProfileDiff[5];
         pProfileResult->nChamferUp[i] = pHistory.nAVGChamferThickUp[5];
         pProfileResult->nChamferDn[i] = pHistory.nAVGChamferThickDn[5];
      }if (i<69&&i>=64)
      {
         pProfileResult->nProfileData[i] = pHistory.nAVGProfileDiff[7];
         pProfileResult->nChamferUp[i] = pHistory.nAVGChamferThickUp[7];
         pProfileResult->nChamferDn[i] = pHistory.nAVGChamferThickDn[7];
      }if (i<74&&i>=69)
      {
         pProfileResult->nProfileData[i] = pHistory.nAVGProfileDiff[6];
         pProfileResult->nChamferUp[i] = pHistory.nAVGChamferThickUp[6];
         pProfileResult->nChamferDn[i] = pHistory.nAVGChamferThickDn[6];
      }if (i<79&&i>=74)
      {
         pProfileResult->nProfileData[i] = pHistory.nAVGProfileDiff[8];
         pProfileResult->nChamferUp[i] = pHistory.nAVGChamferThickUp[8];
         pProfileResult->nChamferDn[i] = pHistory.nAVGChamferThickDn[8];
      }
   }
   m_pControlInterface->SendCIMData((short*)pProfileResult,PLC_ADDR_PROFILE_JUDEMENT,MAX_PROFILE_SETTING_COUNT*3);
@@ -2203,43 +2413,44 @@
   return TRUE;
}
#define IMAGE_COMPRESSRATIO      50
#define IMAGE_COMPRESSRATIO   50
int CInterfaceManager::LoadFullImage(CString strPath,int iSide,int nStartY, CGlass_Data *pGlassData,const bool bIsDebugImg)
{
   int  nHeight = -1;
   int nHeight = -1;
   if (strPath.IsEmpty() || iSide < 0 || iSide > MAX_DIMENSION_COUNT) {
      g_pLog->DisplayMessage(_T("Load Full Image Fail(%s, %d)"), strPath, iSide);
      return nHeight;
   }
#if 0
   USES_CONVERSION;
   char str_filename[200];
   sprintf_s(str_filename, "%s", W2A(strPath));
   IplImage *Iplimg = cvLoadImage(str_filename, CV_LOAD_IMAGE_GRAYSCALE);
   LPBYTE      lpImg = NULL;
   LPBYTE lpImg = NULL;
   IplImage* Iplimg = cvLoadImage(str_filename, CV_LOAD_IMAGE_GRAYSCALE);
   g_pLog->DisplayMessage(_T("Image Size: %d x %d"), Iplimg->width, Iplimg->height);
   if(Iplimg)
   {
      if(bIsDebugImg == true) //Debug image
      {
         UINT uiReadLine = 0;
   if (Iplimg) {
      if (bIsDebugImg == true) {
         UINT uiReadLine = 0;
         //          lpImg = GetGrabBuffer((DimensionDir)iSide,nStartY);
         //          if(lpImg != NULL)
         //          {
         //             memcpy(lpImg, &Iplimg->imageData[0] , Iplimg->widthStep*Iplimg->height);
         //          }
         //
         for(int i = 0; i < Iplimg->height; i++)
         {
            lpImg = GetGrabBuffer((DimensionDir)iSide,nStartY+i);
            if(lpImg == NULL)
         //lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY);
         //if (lpImg != NULL) {
         //   memcpy(lpImg, &Iplimg->imageData[0], Iplimg->widthStep * Iplimg->height);
         //}
         for (int i = 0; i < Iplimg->height; i++) {
            lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY + i);
            if (lpImg == NULL)
               break;
            memcpy(lpImg, &Iplimg->imageData[uiReadLine] , Iplimg->widthStep);
            uiReadLine += Iplimg->widthStep;
            memcpy(lpImg, &Iplimg->imageData[uiReadLine], Iplimg->widthStep);
            uiReadLine += Iplimg->widthStep;
         }
         if(pGlassData != NULL)
         {
            INS_EDGE_RESULT_INFO *pResInfo =  pGlassData->GetEdgeResultInfo((DimensionDir)iSide);
            if(pResInfo != NULL)
         if (pGlassData != NULL) {
            INS_EDGE_RESULT_INFO* pResInfo = pGlassData->GetEdgeResultInfo((DimensionDir)iSide);
            if (pResInfo != NULL)
            {
               pResInfo->nGlassStartLine = 0;
               pResInfo->nGlassEndLine = Iplimg->height + nStartY;
@@ -2249,35 +2460,31 @@
         nHeight = Iplimg->height;
         cvReleaseImage(&Iplimg);
      }
      else //Full image
      {
      else {
         //Full image
         const double dRatio = 1.0 - static_cast<double>(IMAGE_COMPRESSRATIO / 100.0);
         IplImage *resizeImage = cvCreateImage(cvSize((int)(Iplimg->width/dRatio), (int)(Iplimg->height/dRatio)), IPL_DEPTH_8U, 1);
         IplImage* resizeImage = cvCreateImage(cvSize((int)(Iplimg->width / dRatio), (int)(Iplimg->height / dRatio)), IPL_DEPTH_8U, 1);
         cvResize(Iplimg, resizeImage, CV_INTER_CUBIC);
         lpImg = GetGrabBuffer((DimensionDir)iSide,nStartY);
         if(lpImg != NULL)
         {
            memcpy(lpImg, &Iplimg->imageData[0] , resizeImage->widthStep*resizeImage->height);
         lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY);
         if (lpImg != NULL) {
            memcpy(lpImg, &Iplimg->imageData[0], resizeImage->widthStep * resizeImage->height);
         }
         //          UINT uiReadLine = 0;
         //          for(int i = 0; i < resizeImage->height; i++)
         //          {
         //             lpImg = GetGrabBuffer((DimensionDir)iSide,nStartY+i);
         //             if(lpImg == NULL)
         //                break;
         //             memcpy(lpImg, &resizeImage->imageData[uiReadLine] , resizeImage->widthStep);
         //             uiReadLine += resizeImage->widthStep;
         //          }
         //UINT uiReadLine = 0;
         //for (int i = 0; i < resizeImage->height; i++) {
         //   lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY + i);
         //   if (lpImg == NULL)
         //      break;
         //   memcpy(lpImg, &resizeImage->imageData[uiReadLine], resizeImage->widthStep);
         //   uiReadLine += resizeImage->widthStep;
         //}
         if(pGlassData != NULL)
         {
            INS_EDGE_RESULT_INFO *pResInfo =  pGlassData->GetEdgeResultInfo((DimensionDir)iSide);
            if(pResInfo != NULL)
            {
         if (pGlassData != NULL) {
            INS_EDGE_RESULT_INFO* pResInfo = pGlassData->GetEdgeResultInfo((DimensionDir)iSide);
            if (pResInfo != NULL) {
               pResInfo->nGlassStartLine = 0;
               pResInfo->nGlassEndLine = Iplimg->height + nStartY;
            }
@@ -2289,12 +2496,72 @@
      }
      strPath.Append(_T("_OK"));
   }
   else
   else {
      strPath.Append(_T("_NG"));
   }
#else
   // 加载灰度图像
   std::string strFilename = CT2A(strPath);
   cv::Mat img = cv::imread(strFilename, cv::IMREAD_GRAYSCALE);
   g_pLog->DisplayMessage(_T("%s"),(TCHAR*)(LPCTSTR)strPath);
   if (!img.empty()) {
      g_pLog->DisplayMessage(_T("Image Size: %d x %d"), img.cols, img.rows);
   SetSlashText(GLOBAL_DEFINE::emText, strPath, RGB(0,0,0));
      if (bIsDebugImg) {
         for (int i = 0; i < img.rows; ++i) {
            LPBYTE lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY + i);
            if (lpImg == NULL) {
               break;
            }
            memcpy(lpImg, img.ptr(i), img.cols);
         }
         if (pGlassData != NULL) {
            INS_EDGE_RESULT_INFO* pResInfo = pGlassData->GetEdgeResultInfo((DimensionDir)iSide);
            if (pResInfo != NULL) {
               pResInfo->nGlassStartLine = 0;
               pResInfo->nGlassEndLine = img.rows + nStartY;
            }
         }
         nHeight = img.rows;
      }
      else {
         // 按比例缩放
         const double dRatio = 1.0 - static_cast<double>(IMAGE_COMPRESSRATIO) / 100.0;
         int newWidth = static_cast<int>(img.cols / dRatio);
         int newHeight = static_cast<int>(img.rows / dRatio);
         cv::Size newSize(newWidth, newHeight);
         cv::Mat resized;
         cv::resize(img, resized, newSize, 0, 0, cv::INTER_CUBIC);
         LPBYTE lpImg = GetGrabBuffer((DimensionDir)iSide, nStartY);
         if (lpImg != NULL) {
            memcpy(lpImg, resized.data, resized.cols * resized.rows);
         }
         if (pGlassData != NULL) {
            INS_EDGE_RESULT_INFO* pResInfo = pGlassData->GetEdgeResultInfo((DimensionDir)iSide);
            if (pResInfo != NULL) {
               pResInfo->nGlassStartLine = 0;
               pResInfo->nGlassEndLine = resized.rows + nStartY;
            }
         }
         nHeight = resized.rows;
      }
      strPath.Append(_T("_OK"));
   }
   else {
      strPath.Append(_T("_NG"));
   }
#endif // 0
   g_pLog->DisplayMessage(_T("%s"), (TCHAR*)(LPCTSTR)strPath);
   SetSlashText(GLOBAL_DEFINE::emText, strPath, RGB(0, 0, 0));
   return nHeight;
}