SDC C-Project CF Review 프로그램
kojingeun
2023-11-24 c112cf54a238afa473e7eb0ea6298e06f4957658
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#pragma once
 
#include "MosisAssem/AssemParam.h"
#include "MosisAssem/AssemDefect.h"
#include <math.h>
 
class CScanCell;
 
enum DefectLocation        { DefectLoc_Pattern = 0, DefectLoc_Crack, DefectLoc_BM, DefectLoc_ASG };
enum CellLineType        { CellLine_Gate = 0, CellLine_Data };
enum DefectFiltering    { Filtering_NO = 0, Filtering_CO };        // Filtering_CO : Cosmic Ray FALSE
#define        DEFECTIMAGE_WIDTH        280
#define        DEFECTIMAGE_HEIGHT        120
 
class CInspectParam : public CConvParam
{
public:
    int    m_iFrame;
    CScanCell *m_pScanCell;
    BOOL        m_bUseMatchFilter;
    BOOL        m_MatchFilter2by2;
    int m_EchoThreshold;
    //int m_iModel;
};
 
 
class CReDefect
{
public:
    enum ReKind{Re_Other, Re_TFE_CIRCLE, Re_PI_CONVEX, Re_PI_CONCAVE};
public:
    float    m_Mean1, m_Mean2;
    float    m_StdDeviation1, m_StdDeviation2;
    float    m_Mean, m_StdDeviation;
    float    m_Rough;
 
    float    m_ProMean1, m_ProMean2;        // Æò±Õ°ª°ú StdDeviation ºñ±³½Ã mean°ª¿¡ °¡ÁßÄ¡¸¦ µÎ¾î º¯°æÇÑ mean °ªÀ» »ç¿ëÇÑ´Ù.
    void    CalcProcessMean(float minus= -1.2, float plus= 0.8)
    {
        if(m_Mean1 < 0)
        {
            m_ProMean1= m_Mean1*minus;
        }else
        {
            m_ProMean1= m_Mean1*plus;
        }
 
        if(m_Mean2 < 0)
        {
            m_ProMean2= m_Mean2*minus;
        }else
        {
            m_ProMean2= m_Mean2*plus;
        }
    }
 
    ReKind    m_ReKind, m_ReKind2;
    int        m_ReStage;
 
#define AutoStage() m_ReStage++;
#define AutoReturn(kind)    {m_ReKind= kind; return m_ReKind;}
 
    ReKind JudgeTFE(float mean1, float dev1, float rough)
    {
        m_Mean1= mean1, m_StdDeviation1= dev1;
        m_ReStage= 0;
        m_Rough= rough;
 
        m_ReKind= Re_Other;
        if(m_StdDeviation1 < 10)
            AutoReturn(Re_Other);
 
        CalcProcessMean(-1.2f, 0.8f);
        AutoStage();
        if(m_ProMean1 < m_StdDeviation1)
            AutoReturn(Re_TFE_CIRCLE);
 
        AutoReturn(Re_Other);
    }
 
    ReKind    JudgeTFE(float mean1, float dev1, float mean2, float dev2, float mean, float dev, float rough)
    {
        m_Mean1= mean1, m_StdDeviation1= dev1;
        m_Mean2= mean2, m_StdDeviation2= dev2;
        m_Mean= mean, m_StdDeviation= dev;
        m_Rough= rough;
 
        m_ReStage= 0;
        m_ReKind= Re_Other;
        if(m_StdDeviation1 < 10 && m_StdDeviation2 < 10)
            AutoReturn(Re_Other);
 
        CalcProcessMean(-1.2f, 0.8f);
    
    AutoStage();
        if(m_ProMean1 < m_StdDeviation1)
            AutoReturn(Re_TFE_CIRCLE);
 
    AutoStage();
        if(m_ProMean2 < m_StdDeviation2)
            AutoReturn(Re_TFE_CIRCLE);
 
    AutoStage();
        if(fabs(m_Mean1- m_Mean2) > 15)
        {
            if(m_Mean1 > -10 || m_Mean2 > -10)
            AutoReturn(Re_TFE_CIRCLE);
        }
 
        AutoReturn(Re_Other);
    }
 
    ReKind    JudgePI(float mean1, float dev1, float mean2, float dev2, float mean, float dev, float rough)
    {
        m_Mean1= mean1, m_StdDeviation1= dev1;
        m_Mean2= mean2, m_StdDeviation2= dev2;
        m_Mean= mean, m_StdDeviation= dev;
        m_Rough= rough;
 
        m_ReStage= 0;
        m_ReKind= Re_Other;
 
        if(m_StdDeviation1 < 10 && m_StdDeviation2 < 10)
        {
            AutoReturn(Re_Other);
        }
 
        AutoStage();
        if(m_Mean1 < 10 && m_Mean2 < 10)
        {
            AutoReturn(Re_Other);
        }
 
        float absDiff= fabs(m_Mean1- m_Mean2);
 
        CalcProcessMean(-1.2f, 0.8f);
 
 
        AutoStage();
        if(m_ProMean1 < m_StdDeviation1 || m_ProMean2 < m_StdDeviation2)
        {
            if(m_Mean2 > m_Mean1)
            {
                AutoReturn(Re_PI_CONVEX);
            }else
            {
                AutoReturn(Re_PI_CONCAVE);
            }
        }
 
        AutoStage();
        if((m_Mean1 > 0 || m_Mean2 > 0) && absDiff > 15)
        {
            if(m_Mean2 > m_Mean1)
            {
                AutoReturn(Re_PI_CONVEX);
            }else
            {
                AutoReturn(Re_PI_CONCAVE);
            }
        }
 
 
        AutoReturn(Re_Other);
    }
};
 
class CDefect  : public CReDefect
{
public:
    int                m_nIndex;
    int                m_nScanIdx;
    int                m_iModel;
    CDefectBlob        m_Defect;
    DefectLocation    m_DefectLoc;
    DefectFiltering    m_DefectFiltering;
    char            m_strPosition[20];    
    //BYTE            m_Image[DEFECTIMAGE_WIDTH * DEFECTIMAGE_HEIGHT + 1];
 
    //OhByungGil
    int                m_iFrameIdx;
 
    CDefect()
    {
        Reset();
    }
    virtual ~CDefect()
    {
 
    }
    void Reset()
    {
        m_nIndex            = -1;
        m_nScanIdx            = -1;
        m_iModel            = -1;
        m_Defect.Reset();
        m_DefectLoc            = DefectLoc_Pattern;
        m_DefectFiltering    = Filtering_NO;
        ZeroMemory(m_strPosition, 20);
        //ZeroMemory(m_Image, DEFECTIMAGE_WIDTH * DEFECTIMAGE_HEIGHT + 1);
    }
};
 
class CBlobStorage;
class CMosisBuffer;
class CConvParam;
class CAssemControl;
class CZoneReference;
 
class CDefectStorage
{
protected:
    CRITICAL_SECTION    m_csDefect;
 
public:
    int                m_nDefect;
    CDefect            *m_pDefect;
 
    int                m_maxDefect;
    int                m_nDefectSpace;
 
    int        InitDefectStorage(int maxDefect= 10000);
    void    ResetDefectStorage()    ;
    int        GetDefectCount() {return m_nDefect;}
    CDefect* GetDefect(int i){return m_pDefect+ i;}
 
public:
    CDefectStorage(void);
    ~CDefectStorage(void);
 
    int        ExtractDefect(CZoneReference *pZoneReference, CBlobStorage *pBlobStorage, CInspectParam *pParam, int iModel, int nCosmicThreshold, BOOL bDelBlack, BOOL bDelWhite, int filterSize, BOOL bDelGeneral);
    BOOL    IsCosmicRayDefect(CDefectBlob *blob, CMosisBuffer &fBuffer, int crFilterThreshold);
    void    CheckDefectRect(CPoint* pVertex, CRect* pRect, int nX, int nY);
 
    int        StopInspection(CAssemControl *pAssemControl);
};