#include "StdAfx.h"
|
#include "DefectStorage.h"
|
#include "SISBuffer.h"
|
#include "BlobStorage.h"
|
#include "AssemParam.h"
|
#include "MulticamControl.h"
|
#include "Glass_Data.h"
|
#include "HardwareSettings.h"
|
|
CDefectStorage::CDefectStorage(void)
|
{
|
m_nDefectSpace = 0;
|
m_nDefect= m_maxDefect= 0;
|
m_pDefect= NULL;
|
}
|
|
CDefectStorage::~CDefectStorage(void)
|
{
|
if(m_pDefect)
|
delete[] m_pDefect;
|
}
|
|
void CDefectStorage::ResetDefectStorage()
|
{
|
int i;
|
if(m_pDefect != NULL)
|
{
|
for(i= 0; i< m_maxDefect; i++)
|
m_pDefect[i].Reset();
|
}
|
|
m_nDefect= 0;
|
}
|
|
|
int CDefectStorage::InitDefectStorage(int maxDefect)
|
{
|
if(maxDefect <= m_nDefectSpace)
|
{
|
m_maxDefect= maxDefect;
|
return m_maxDefect;
|
}
|
|
if(m_pDefect != NULL)
|
{
|
delete[] m_pDefect;
|
}
|
|
// 16俺狼 咯盒阑 敌促..恐? 郴干..
|
int DefectSapce= maxDefect+ 16;
|
m_pDefect= new CDefect[DefectSapce];
|
|
if(m_pDefect == NULL)
|
{
|
m_maxDefect= m_nDefectSpace= 0;
|
return m_maxDefect;
|
}
|
|
|
m_maxDefect= m_nDefectSpace= maxDefect;
|
|
|
return m_maxDefect;
|
}
|
|
CDefectControl::CDefectControl()
|
{
|
m_pGrabber = NULL;
|
// m_pGlassData = NULL;
|
m_pHWRecipe = NULL;
|
ResetDefectControl();
|
}
|
|
CDefectControl::~CDefectControl()
|
{
|
|
}
|
|
void CDefectControl::ResetDefectControl()
|
{
|
CDefectStorage::ResetDefectStorage();
|
}
|
|
int CDefectControl::CheckDefectCount()
|
{
|
if(m_nDefect >= m_maxDefect)
|
return DIT_CONV_GLASSOVERFLOW;
|
|
return DIT_CONV_SUCCESS;
|
}
|
|
int CDefectControl::ExtractDefect(DimensionDir emDim, int iCam, int iScan, CDefect_Info defectInfo)
|
{
|
if (m_pGrabber == NULL)
|
return m_nDefect;
|
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
|
if (m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
CDefect* pDefect = GetDefect(m_nDefect);
|
if (pDefect == NULL)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
pDefect->Reset();
|
pDefect->m_DefectInfo = defectInfo;
|
|
if (m_pGrabber->GetSmallImage(iScan, pDefect->m_Image
|
, defectInfo.m_ptDefectPos_pxl.x - (DEFECTIMAGE_WIDTH / 2)
|
, defectInfo.m_ptDefectPos_pxl.y - (DEFECTIMAGE_HEIGHT / 2)
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
m_nDefect++;
|
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
int CDefectControl::ExtractDefect_Side(DimensionDir emDim, int iCam, int iScan, std::vector<CDefect_Info>* vecPreDefectList)
|
{
|
if(m_pGrabber == NULL)
|
return m_nDefect;
|
|
if(vecPreDefectList == NULL)
|
return m_nDefect;
|
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
|
if(m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
CDefect_Info* pDefectInfo = NULL;
|
CDefect* pDefect=NULL;
|
|
for(int iDefect=0;iDefect<vecPreDefectList->size();iDefect++)
|
{
|
pDefectInfo = &(*vecPreDefectList)[iDefect];
|
|
if(pDefectInfo == NULL)
|
continue;
|
|
if(m_nDefect >= m_maxDefect)
|
break;
|
|
pDefect = GetDefect(m_nDefect);
|
|
if(pDefect == NULL)
|
break;
|
|
pDefect->Reset();
|
pDefect->m_DefectInfo = *(pDefectInfo);
|
|
if(m_pGrabber->GetSmallImage(iScan, pDefect->m_Image
|
, pDefectInfo->m_ptDefectPos_pxl.x - (DEFECTIMAGE_WIDTH / 2)
|
, pDefectInfo->m_ptDefectPos_pxl.y - (DEFECTIMAGE_HEIGHT / 2)
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
continue;
|
|
m_nDefect++;
|
}
|
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
int CDefectControl::ExtractDefect_Notch(DimensionDir emDim, int iCam, int iScan, int nNotchDefectAreaIdx, std::vector<CDefect_Info>* vecPreDefectList)
|
{
|
if (m_pGrabber == NULL)
|
return m_nDefect;
|
|
if (vecPreDefectList == NULL)
|
return m_nDefect;
|
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
|
if (m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
CDefect_Info* pDefectInfo = NULL;
|
CDefect* pDefect = NULL;
|
|
for (int iDefect = 0; iDefect < vecPreDefectList->size(); iDefect++)
|
{
|
pDefectInfo = &(*vecPreDefectList)[iDefect];
|
|
if (pDefectInfo == NULL)
|
continue;
|
|
if (m_nDefect >= m_maxDefect)
|
break;
|
|
pDefect = GetDefect(m_nDefect);
|
|
if (pDefect == NULL)
|
break;
|
|
pDefect->Reset();
|
pDefect->m_DefectInfo = *(pDefectInfo);
|
pDefect->m_nNotchIdx = nNotchDefectAreaIdx;
|
|
if (m_pGrabber->GetSmallImage(iScan, pDefect->m_Image
|
, pDefectInfo->m_ptDefectPos_pxl.x - (DEFECTIMAGE_WIDTH / 2)
|
, pDefectInfo->m_ptDefectPos_pxl.y - (DEFECTIMAGE_HEIGHT / 2)
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
continue;
|
|
m_nDefect++;
|
}
|
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
int CDefectControl::ExtractDefect_UserDefect(DimensionDir emDim, int iCam, int iScan, int nUserDefectAreaIdx, std::vector<CDefect_Info>* vecPreDefectList)
|
{
|
if(m_pGrabber == NULL)
|
return m_nDefect;
|
|
if(vecPreDefectList == NULL)
|
return m_nDefect;
|
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
|
if(m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
CDefect_Info* pDefectInfo = NULL;
|
CDefect* pDefect=NULL;
|
|
for(int iDefect=0;iDefect<vecPreDefectList->size();iDefect++)
|
{
|
pDefectInfo = &(*vecPreDefectList)[iDefect];
|
|
if(pDefectInfo == NULL)
|
continue;
|
|
if(m_nDefect >= m_maxDefect)
|
break;
|
|
pDefect = GetDefect(m_nDefect);
|
|
if(pDefect == NULL)
|
break;
|
|
pDefect->Reset();
|
pDefect->m_DefectInfo = *(pDefectInfo);
|
pDefect->m_nUserDefectAreaIdx = nUserDefectAreaIdx;
|
|
if(m_pGrabber->GetSmallImage(iScan,pDefect->m_Image
|
, pDefectInfo->m_ptDefectPos_pxl.x - (DEFECTIMAGE_WIDTH / 2)
|
, pDefectInfo->m_ptDefectPos_pxl.y - (DEFECTIMAGE_HEIGHT / 2)
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
continue;
|
|
m_nDefect++;
|
}
|
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
int CDefectControl::ExtractDefect_Measure(DimensionDir emDim, int iCam, int iScan, CDefect_Info defect, double dMeasureResult_um, double dMeasureDiff_um)
|
{
|
if(m_pGrabber == NULL)
|
return m_nDefect;
|
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
|
if(m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
CDefect* pDefect = GetDefect(m_nDefect);
|
|
if(pDefect == NULL)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
pDefect->Reset();
|
pDefect->m_bJudge_NG = TRUE;
|
pDefect->m_dSizeX_um = dMeasureResult_um;
|
pDefect->m_dSizeY_um = dMeasureDiff_um;
|
pDefect->m_dChamfer_um = dMeasureResult_um;
|
pDefect->m_dChamferOff_um = dMeasureDiff_um;
|
pDefect->m_DefectInfo = defect;
|
|
if(m_pGrabber->GetSmallImage(iScan,pDefect->m_Image
|
, defect.m_ptDefectPos_pxl.x - (DEFECTIMAGE_WIDTH / 2)
|
, defect.m_ptDefectPos_pxl.y - (DEFECTIMAGE_HEIGHT / 2)
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
m_nDefect++;
|
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
int CDefectControl::ExtractDefect_Mark(DimensionDir emDim, int iCam, int iScan, CDefect_Info defect)
|
{
|
if(m_pGrabber == NULL)
|
return m_nDefect;
|
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
|
if(m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
CDefect* pDefect = GetDefect(m_nDefect);
|
|
if(pDefect == NULL)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
pDefect->Reset();
|
pDefect->m_bJudge_NG = TRUE;
|
pDefect->m_DefectInfo = defect;
|
|
if(m_pGrabber->GetSmallImage(iScan,pDefect->m_Image
|
, pDefect->m_DefectInfo.m_ptDefectPos_pxl.x - (DEFECTIMAGE_WIDTH / 2)
|
, pDefect->m_DefectInfo.m_ptDefectPos_pxl.y - (DEFECTIMAGE_HEIGHT / 2)
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
m_nDefect++;
|
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
int CDefectControl::ExtractDefect_CorChamfer(DimensionDir emDim, int iCam, int iScan, DefectLocation eDefect, CDefect_Info ptDefect, int nProfileIndex)
|
{
|
if (m_pGrabber == NULL)
|
return m_nDefect;
|
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
|
if (m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
CDefect* pDefect = GetDefect(m_nDefect);
|
|
if (pDefect == NULL)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
pDefect->Reset();
|
pDefect->m_bJudge_NG = TRUE;
|
pDefect->m_dSizeX_um = nProfileIndex;
|
pDefect->m_DefectInfo = ptDefect;
|
|
if (m_pGrabber->GetSmallImage(iScan, pDefect->m_Image
|
, ptDefect.m_ptDefectPos_pxl.x - (DEFECTIMAGE_WIDTH / 2)
|
, ptDefect.m_ptDefectPos_pxl.y - (DEFECTIMAGE_HEIGHT / 2)
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
m_nDefect++;
|
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|