#pragma once
|
|
#include <map>
|
#include <list>
|
#include <vector>
|
#include "SplineInspect.h"
|
#include "ChamferInspect.h"
|
#include "EDGE_DIPM.h"
|
|
using namespace std;
|
|
enum EM_NOTCH_MSG_ERR{ERR_NO_MASTERIMG=0,ERR_NO_ORGIMG,ERR_FIND_POS,NORMAL_EXE};
|
|
typedef struct _NOTCH_Parm_STU
|
{
|
BOOL bChipIns;
|
BOOL bSizeIns;
|
int nChipDiff;
|
int nSizeDiff;
|
int nDetThres;
|
int nEdgeThres;
|
int nSizeThres;
|
int nChipThres;
|
int nSkipSize;
|
double dBlank2EdgeRatio;
|
BOOL bSplineChip[2];
|
int nSpInsSize[2];
|
int nChamferSize;
|
int nChamferDiff;
|
int nNoDetSkipSize;
|
int nDetSkipSize;
|
double dCamRes;
|
int nPointInsAveCount;
|
|
_NOTCH_Parm_STU()
|
{
|
Reset();
|
}
|
void Reset()
|
{
|
bChipIns = bSizeIns = bSplineChip[0] = bSplineChip[1] = FALSE;
|
nChipDiff = nDetThres = nEdgeThres = nChipThres = nSkipSize = 0;
|
nSpInsSize[0] = nSpInsSize[1] = nSizeDiff = nChamferSize = nChamferDiff = nNoDetSkipSize = nDetSkipSize = 0;
|
dCamRes = dBlank2EdgeRatio = 0.;
|
nPointInsAveCount = 5;
|
}
|
}NOTCH_Parm_STU;
|
|
typedef struct _NOTCH_Master_STU
|
{
|
BOOL bLoad;
|
COwnerBuffer imgBuf;
|
int nPosX;
|
int nPosY;
|
int nMaxX;
|
int nMaxY;
|
|
_NOTCH_Master_STU()
|
{
|
Reset();
|
}
|
void Reset()
|
{
|
bLoad = FALSE;
|
imgBuf.ReleaseSpace();
|
nPosX = nPosY = nMaxX = nMaxY = 0;
|
}
|
}NOTCH_Master_STU;
|
|
typedef struct _PointD
|
{
|
double X,Y;
|
|
_PointD()
|
{
|
Reset();
|
}
|
_PointD(double dX,double dY)
|
{
|
X = dX;
|
Y = dY;
|
}
|
void Reset()
|
{
|
X = Y = 0.;
|
}
|
}PointD;
|
|
typedef struct _NOTCH_ObjFind_STU
|
{
|
double dMatPosX;
|
double dMatPosY;
|
int nEdgeTop;
|
int nEdgeBot;
|
|
_NOTCH_ObjFind_STU()
|
{
|
Reset();
|
}
|
void Reset()
|
{
|
dMatPosX = dMatPosY = 0.;
|
nEdgeTop = nEdgeBot = 0;
|
}
|
}NOTCH_ObjFind_STU;
|
|
typedef struct _NOTCH_Merge_STU
|
{
|
int nStart;
|
int nEnd;
|
int nSize;
|
|
_NOTCH_Merge_STU()
|
{
|
Reset();
|
}
|
void Reset()
|
{
|
nStart = nEnd = -1;
|
nSize = 0;
|
}
|
}NOTCH_Merge_STU;
|
|
typedef struct _NOTCH_Circle_STU
|
{
|
PointD pointF;
|
PointD pointS;
|
|
_NOTCH_Circle_STU()
|
{
|
Reset();
|
}
|
void Reset()
|
{
|
pointF = pointS = PointD(0,0);
|
}
|
}NOTCH_Circle_STU;
|
|
typedef struct _NOTCH_RangePos_STU
|
{
|
CPoint pointCAD;
|
CPoint pointImg;
|
double dDist;
|
int nInsCount;//20140528
|
|
_NOTCH_RangePos_STU()
|
{
|
Reset();
|
}
|
void Reset()
|
{
|
pointCAD = pointImg = CPoint(0,0);
|
dDist = 0.;
|
nInsCount = 0;//20140528
|
}
|
}NOTCH_RangePos_STU,*pNOTCH_RangePos_STU;
|
|
struct SortYPos : public std::binary_function<pair<int,CPoint>, pair<int,CPoint>, bool>
|
{
|
bool operator()(const pair<int,CPoint> & lhs, const pair<int,CPoint> & rhs)
|
{
|
return lhs.second.y > rhs.second.y;
|
}
|
};
|
struct ResSortYPos : public std::binary_function<pair<int,CPoint>, pair<int,CPoint>, bool>
|
{
|
bool operator()(const pair<int,CPoint> & lhs, const pair<int,CPoint> & rhs)
|
{
|
return lhs.second.y < rhs.second.y;
|
}
|
};
|
struct SortSPYPos : public std::binary_function<pair<int,CSplinePoint>, pair<int,CSplinePoint>, bool>
|
{
|
bool operator()(const pair<int,CSplinePoint> & lhs, const pair<int,CSplinePoint> & rhs)
|
{
|
return lhs.second.rotate.y < rhs.second.rotate.y;
|
}
|
};
|
#define MAX_NOTCH_SCAN_COUNT 4
|
#define MAX_NOTCH_DEFECT_COUNT 1000
|
|
class CSISBuffer;
|
|
class AFX_EXT_CLASS CNotchCut
|
{
|
public:
|
CNotchCut(void);
|
virtual ~CNotchCut(void);
|
|
public:
|
void Reset();
|
BOOL LoadData(CString strFile);
|
BOOL CopyModelData(CNotchCut *pNotch);
|
BOOL AdjustTilt(int index,double dTheta,double baseCenY);
|
void SetParm(NOTCH_Parm_STU &parm);
|
int NotchExecute(CSISBuffer &pOrg,double *dResult,double *dResult_Dy,pNOTCH_RangePos_STU pRangeRes,pNOTCH_RangePos_STU pRangeRes_Dy,pNOTCH_RangePos_STU pRangeRes_Cham,int nRangeCnt,COwnerBuffer &pRes,COwnerBuffer &pRes_Dy,COwnerBuffer &pRes_Cham,double *dAvgThick,int iDimension
|
, double *dFeedbackXY, int icam,double *dGlassXY,double dAlign2GlassX,int iLeftLine,BOOL bSaveDebug,CString strSavePath,double dTheta); //20140528
|
BOOL WriteModelData(CString strFile,CString strRecipe,CString strCut,std::multimap<int, CSplinePoint> *pPoint);
|
BOOL ReadModelData(CString strFile,int index);
|
CChipBlob *GetResultDefect(){return m_ResultDefect;}
|
int GetDefectCount(){return m_nDefectCount;}
|
void SetNotchInsPoint(std::vector<CPoint> *InsPoint, int index);//20140528
|
void FindCenterPos(CSISBuffer &pImg,int &nPosX,int &nPosY,int nSkipSize=10);//20140528
|
|
protected:
|
BOOL CalDiffXY(std::multimap<int,CSplinePoint> *mapDist,double *dDx,double *dDy);
|
void CalRangeVal(std::multimap<int,CSplinePoint> *mapDist,double *dResDist,pNOTCH_RangePos_STU dRangeRes,int nRangeCnt,int nCenX,int nCenY,int nStartX,int nFirstY,int nLastY);
|
void CalRangeVal_New(std::multimap<int,CSplinePoint> *mapDist,std::multimap<int,CSplinePoint> *mapDist_Dy,double *dResDist,double *dResDist_Dy,pNOTCH_RangePos_STU dRangeRes,pNOTCH_RangePos_STU dRangeRes_Dy,pNOTCH_RangePos_STU dRangeRes_Cham,int nRangeCnt,int nCenX,int nCenY,int nStartX,int nFirstY,int nLastY,std::multimap<int,CSplinePoint> *mapChamfer);//20140528
|
int CropDataXY2(std::multimap<int,CSplinePoint> *mapCrop,std::multimap<int,CSplinePoint> *mapDist,int nStartX,int nFirstY,int nLastY,double *dResDist);
|
int CropDataXY2_Chamfer(std::multimap<int,CSplinePoint> *mapCrop,std::multimap<int,CSplinePoint> *mapDist,int nStartX,int nFirstY,int nLastY);//20140528
|
CSplinePoint FindCenter2Vec(std::multimap<int,CSplinePoint> *mapCrop,int nCenY,int *nPosition);
|
void GetRangeAvgThick(std::multimap<int,CSplinePoint> *mapCrop,pNOTCH_RangePos_STU pReangeRes,CSplinePoint spCenter,int nRangeCnt);
|
void GetRangeAvgThick_New(std::multimap<int,CSplinePoint> *mapCrop,pNOTCH_RangePos_STU pReangeRes,CPoint point,int nRangeCnt);//20140528
|
void GetRangeAvgThick_New_Cham(std::multimap<int,CSplinePoint> *mapCropChamfer,pNOTCH_RangePos_STU pReangeRes,CPoint point,int nRangeCnt);//20140528
|
void Inspection_Size(CSISBuffer &pOrg,COwnerBuffer &pRes,COwnerBuffer &pRes_Dy,COwnerBuffer &pRes_Cham,CSISBuffer &pBinEdge,CSISBuffer &pBin,double *dChamferAvgThick,double *dChipAvgThick,int nCenX,int nCenY,int nGlass2Edge,double *dFeedbackXY
|
,int iDimension, int icam, std::multimap<int,CSplinePoint> *mapDist,std::multimap<int,CSplinePoint> *mapDist_Dy,double *dGlassXY,double *dResult,std::multimap<int,CSplinePoint> *mapChamfer,double dTheta); //20140528
|
void ThinImage(CSISBuffer &pBinThin,int iscan, int icam);
|
BOOL DistInspection(CSISBuffer &pTgt,CSISBuffer &pOrg,double *dResult,double *dRangeRes,double *dAvgThick,int nCenX,int nCenY,int nGlass2Edge, double *dFeedbackXY,int iscan, int icam);
|
BOOL DistInspection_New(CSISBuffer &pBin,CSISBuffer &pOrg,double *dChamferThick,double *dChipAvgThick,int nCenX,int nCenY,int nGlass2Edge
|
, double *dFeedbackXY,int iDimension, int icam, std::multimap<int,CSplinePoint> *mapDist,std::multimap<int,CSplinePoint> *mapDist_Dy,double *dGlassXY,int *nUpVPos,int *nDwVPos,std::multimap<int,CSplinePoint> *mapChamfer,double dTheta); //20140528
|
BOOL Inspection_SpChip(CSISBuffer &pBin,CSISBuffer &pOrg,int nGlass2Edge,int nUpVPos,int nDwVPos);
|
int Defect_Analyze(std::multimap<double,CDetectPoint> *mapDist,double dAvgThick);
|
void GetSpChipData(vector<pair<int,CPoint>> *pVec,CRect *rectIns);
|
double Detect_Position(CSISBuffer &pBin,CSISBuffer &pOrg,std::multimap<double,CDetectPoint> *mapDist
|
,vector<pair<int,CPoint>> *vecData);
|
void DrawImgRect(CSISBuffer &pOrg,double dX,double dY,int nValue=128);
|
int AnalysisThick(CRect rectImg,double dRes,int nJudgeThick,double dAvgThick);
|
int GetRangeDivThick(std::multimap<int, CSplinePoint> *mapCrop,CSplinePoint spCenter,int nCenterPos,pNOTCH_RangePos_STU pRangeRes,int nRangeCnt,BOOL bOpt,int nDivRange);
|
void SetBrokenDefect(CPoint pointBroken);
|
|
protected:
|
void AssertRect(CRect &rect,CSISBuffer pOrg);
|
int FindLeftLine(CSISBuffer &pImg,CRect rect,int nThres);
|
int FindLeftLineReal(CSISBuffer &pImg,CRect rect,int nThres);
|
void SetNotchImgResPoint(COwnerBuffer *pRes,pNOTCH_RangePos_STU RangeVal,int nRangeCnt);
|
void bresenham_Line(COwnerBuffer *pRes,CPoint posStart,CPoint posEnd,BYTE color);
|
|
protected:
|
void FindRealPos(CSISBuffer &pOrg,CSISBuffer &pBin,int iLeftLine,int &nCenX,int &nCenY
|
,int *nStartX,int *nFisrtY,int *nLastY,int iCam,int iDem,int nSkipSize=10);
|
void FindYPosMerge(std::vector<int> *vList,std::vector<NOTCH_Merge_STU> *vMergeList);
|
void FindYPosPixel(CSISBuffer &pImg,CRect rect,std::vector<int> *vList,int nThres,int u,BOOL bDir=TRUE);
|
int FindAccumYPos(CSISBuffer &pImg,CRect rect,int nThres);
|
void FindRealAccumXY(CSISBuffer &pImg,CRect rect,int nThres,int *nStartX,int *nFirstY,int *nLastY);
|
double FindRealAccumYPos(CSISBuffer &pImg,int nSkipSize,int nThres,int *iLeftLine);
|
double FindRealCenter(CSISBuffer &pImg,CRect rect,int nThres,int *nStartX,int *nFirstY,int *nLastY);
|
void FindRealYPosMerge(std::vector<int> *vList,std::vector<NOTCH_Merge_STU> *vMergeList);
|
void MakeFoldImage(CSISBuffer &pImg,int nPosY);
|
void MakeReal2Cad(CSISBuffer &pOrg,int nCenX,int nCenY,int iDimension=0, int icam=0);
|
void MakeReal2AlignCad(CSISBuffer &pOrg,int nCenY,int nForeX,int iDimension=0, int icam=0);
|
void MakeReal2Cad_Image(CSISBuffer &pOrg,COwnerBuffer &pRes,int nValue=128);
|
void ResetData();
|
PointD GetCenterPointFrom3Points(const PointD& S, const PointD& M, const PointD& E);
|
void Exe_ChipInspect(CSISBuffer &pBin,CSISBuffer &pOrg,int iCam);
|
double FindCenterThickness(CSISBuffer &pOrg,CSISBuffer &pBin,int nCenX,int nCenY,int icam,int iDimension);
|
|
public:
|
vector<pair<int,CPoint>> m_mapMaster;
|
std::multimap<int, CPoint> m_mapOrgMaster[MAX_NOTCH_SCAN_COUNT];
|
std::multimap<int, CPoint> m_mapAlignMaster[MAX_NOTCH_SCAN_COUNT];
|
vector<pair<int,CPoint>> m_mapMaster_InsPos;//20140528
|
std::multimap<int, CPoint> m_mapOrgMaster_InsPos[MAX_NOTCH_SCAN_COUNT];//20140528
|
std::multimap<int, CPoint> m_mapAlignMaster_InsPos[MAX_NOTCH_SCAN_COUNT];//20140528
|
vector<pair<int,CSplinePoint>> m_mapChipData;
|
CChipBlob m_ResultDefect[MAX_NOTCH_DEFECT_COUNT];
|
int m_nDefectCount;
|
|
public:
|
NOTCH_Parm_STU m_InsParm;
|
NOTCH_Master_STU m_MasterParm[MAX_NOTCH_SCAN_COUNT];
|
NOTCH_Master_STU m_AlignMasterParm[MAX_NOTCH_SCAN_COUNT];
|
NOTCH_ObjFind_STU m_ObjectInfo;
|
BOOL m_bSaveDebug;
|
CString m_strSavePath;
|
int m_nNoDetCount,m_nTotalCount;
|
};
|