#include "StdAfx.h" #include "ResultData.h" CResultData::CResultData(void) { m_pInspectOpt = NULL; m_pProfileOpt = NULL; } CResultData::~CResultData(void) { } void CResultData::Reset() { m_bGlassResult = TRUE; m_strPCID = m_strScanStartTime = m_strScanEndTime = m_strRecipeName = _T(""); int i,j; for(i=0;i<2;i++) { m_bNCutSize[i] = TRUE; m_bNCutThick[i] = TRUE; for(j=0;j<2;j++) { m_bCornerResWidth[i][j] = TRUE; m_bCornerResHeight[i][j] = TRUE; m_bSplineRes[i][j] = TRUE; m_nCornerImageCamIdx[i][j] = -1; } for(j=0;j *pCamThick,CAMERA_DIR camDir) { if(pCamThick == NULL || (int)pCamThick->size() <= 0) return 0.; double dSum,dCnt; std::vector::iterator it; STU_THICKPOS *pThick; dSum = dCnt = 0.; for(it=pCamThick->begin();it!=pCamThick->end();it++) { pThick = *it; if(pThick == NULL || pThick->dThick <= 0) continue; switch(camDir) { case CAMDIR_TOP: dSum += pThick->dThick; dCnt++; break; case CAMDIR_BOTTOM: dSum += pThick->dThick; dCnt++; break; } } return dCnt > 0?dSum/dCnt:0.; } BOOL CResultData::GetRangeCheck(int nBase,int nMinus,int nPlus,int nValue) { if(nValue > nBase+nPlus || nValue < nBase-nMinus) return FALSE; return TRUE; } double CResultData::GetCutAreaStdDev(std::vector *pCamThick,CAMERA_DIR camDir,double dAvg) { if(pCamThick == NULL || (int)pCamThick->size() <= 0) return 0.; std::vector::iterator it; STU_THICKPOS *pThick; double dStdDev,dSum,dCnt; dSum = dCnt = dStdDev = 0.; for(it=pCamThick->begin();it!=pCamThick->end();it++) { pThick = *it; if(pThick == NULL || pThick->dThick <= 0) continue; switch(camDir) { case CAMDIR_TOP: dSum += pow((dAvg-pThick->dThick),2); break; case CAMDIR_BOTTOM: dSum += pow((dAvg-pThick->dThick),2); break; } dCnt++; } return dCnt>0?sqrt(dSum/dCnt):0.; } BOOL CResultData::GetJudgePointMaxMin(std::vector *pVecThick,int &nMinPos,int &nMaxPos) { std::vector::iterator it; STU_THICKPOS stuThick; nMinPos = INT_MAX,nMaxPos = 0; for(it=pVecThick->begin();it!=pVecThick->end();it++) { stuThick = *it; if(nMinPos > stuThick.yCoordi) nMinPos = (int)stuThick.yCoordi; if(nMaxPos < stuThick.yCoordi) nMaxPos = (int)stuThick.yCoordi; } return TRUE; } #define CUTAREA_CALCULATE_SIZE 50000 double CResultData::GetJudgePointRangeValue(std::vector *pVecThick,int nGlassSize,int iPos) { std::vector::iterator it; STU_THICKPOS stuThick; int nRange[2]; if(iPos-CUTAREA_CALCULATE_SIZE < 0) { nRange[0] = 0; nRange[1] = CUTAREA_CALCULATE_SIZE*2; } else if(iPos+CUTAREA_CALCULATE_SIZE > nGlassSize) { nRange[0] = nGlassSize - CUTAREA_CALCULATE_SIZE*2; nRange[1] = nGlassSize; } else { nRange[0] = iPos - CUTAREA_CALCULATE_SIZE; nRange[1] = iPos + CUTAREA_CALCULATE_SIZE; } double dValue = 0.,dSum = 0.,dCnt = 0; for(it=pVecThick->begin();it!=pVecThick->end();it++) { stuThick = *it; if(nRange[0] <= stuThick.yCoordi && nRange[1] >= stuThick.yCoordi) { dSum += stuThick.dThick; dCnt++; } } if(dCnt > 0) dValue = dSum/dCnt; return dValue; } void CResultData::GetJudgePointValue(std::vector *pVecThick,CAMERA_DIR camDir,DimensionDir enDir,int nGlassSize) { if(pVecThick == NULL || (int)pVecThick->size() <= 0) return; double dSum = 0.; double dCount = 0.; int nMinPos,nMaxPos; if(GetJudgePointMaxMin(pVecThick,nMinPos,nMaxPos) == FALSE) return; int nJumpVal = abs(nMaxPos-nMinPos)/RUSULT_POINT_COUNT; int i; for(i=0;i=0;v--,iPos++) { CopyMemory(&pTgt[iPos*szImg.cx],&pImg[v*szImg.cx],szImg.cx); } CopyMemory(pImg,pTgt,szImg.cx*szImg.cy); delete[] pTgt,pTgt=NULL; return TRUE; } void CResultData::Save_FullImgProc_ROI(LPBYTE pImg,CSize szImg,CRect ROI,LPBYTE lpIn) { if(pImg == NULL || szImg.cx <= 0 || szImg.cy <= 0) return; int nYStart = ROI.top; int nXStart = ROI.left; //LPBYTE lpStart = pImg + (nYStart % szImg.cy) * szImg.cx + nXStart; LPBYTE lpStart = pImg + nYStart * szImg.cx + nXStart; for (int i = 0; i < ROI.Height(); i++) { memcpy(lpIn + i * ROI.Width(), lpStart + i * szImg.cx, ROI.Width()); } CSize szTemp; szTemp = CSize(ROI.Width(),ROI.Height()); FlipImage(lpIn,szTemp); } double CResultData::GetDimensionAvg(std::vector *pResult) { if(pResult == NULL || pResult->size() <= 0) return 0.; std::vector::iterator it; double dSum,dCount; STU_DIMENSIONPOS *pDimen; dSum = dCount = 0.; for(it=pResult->begin();it!=pResult->end();it++) { pDimen = *it; if(pDimen == NULL || pDimen->dSize <= 0) continue; dSum+=pDimen->dSize; dCount++; } return dCount>0?dSum/dCount:0.; } double CResultData::GetDimensionStd(std::vector *pResult,double dAvg) { if(pResult == NULL || pResult->size() <= 0) return 0.; std::vector::iterator it; double dSum,dCount; STU_DIMENSIONPOS *pDimen; dSum = dCount = 0.; for(it=pResult->begin();it!=pResult->end();it++) { pDimen = *it; if(pDimen == NULL || pDimen->dSize <= 0) continue; dSum += pow((dAvg-pDimen->dSize),2); dCount++; } return dCount>0?sqrt(dSum/dCount):0.; } void CResultData::GetDimensionPointValue(std::vector *pData,DimensionDir enDir) { std::vector::iterator it; STU_DIMENSIONPOS pDimen; double dMinVal,dMaxVal; dMinVal = INT_MAX; dMaxVal = 0; for(it=pData->begin();it!=pData->end();it++) { pDimen = *it; if(dMinVal > pDimen.yCoordi) dMinVal = pDimen.yCoordi; if(dMaxVal < pDimen.yCoordi) dMaxVal = pDimen.yCoordi; } double dJumpVal = fabs(dMaxVal-dMinVal)/RUSULT_POINT_COUNT; for(int i=0;i *pData,double dPos) { double dDiffVal = INT_MAX; double dValue; std::vector::iterator it; STU_DIMENSIONPOS pDimen; dValue = 0; for(it=pData->begin();it!=pData->end();it++) { pDimen = *it; if(dDiffVal > fabs(pDimen.yCoordi-dPos)) { dDiffVal = fabs(pDimen.yCoordi-dPos); dValue = pDimen.dSize; } } return dValue; } void CResultData::CalJudgement() { int i,j; // CutArea for(i=0;i<2;i++)//20140603 { for(j=0;j 0) m_bGlassResult = FALSE; //Notch Range Value//20140721(Dim/chamºÐ¸®) for (int iDim = 0; iDim