SDC C-Project CF Review 프로그램
LYW
2021-08-17 9aa3a8ff940e89bb0b5c75bc8abd0864e4c85874
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#pragma once
 
#include "MosisAssem/MosisStrg.h"
 
class CMosisBuffer;
 
typedef CMosisBlock<int> CPitchBlock;
typedef CMosisBlock<int> CIntBlock;
 
 
#define SPR_SHIFT    4
#define SPR_MULTI    16
 
 
struct stPitchParam
{
    enum PP_Dir{PP_HORIZONTAL= 0, PP_VERTICAL= 1};
public:
    double    PitchStart, PitchEnd;    // ÇÇÄ¡ Ã£´Â ¹üÀ§
    double    TiltStart, TiltEnd;        // Tilt Ã£´Â ¹üÀ§
    int        Width, Height;            // ÇÇÄ¡ Æò°¡¸¦ À§ÇÑ ºñ±³ Å©±â.
    int        Direction;                // 0- xÃà- Horizontal,        1- yÃà- Vertical
 
    int        Interval;                // ¾ó¸¶ÀÇ °Å¸®¸¸Å­ ¶³¾îÁ®¼­ °Ë»çÇÒ±î...
    int        Dist;                    // 2d °Ë»ç¸¦ À§ÇÑ cross ¹æÇâ Pitch interval
    int        ZeroBack;                // 3ÀÌÇÏ Noise´Â ¹«½ÃÇÑ´Ù. ½ÇÁ¦ noiseÁ¦°Å½Ã ÇÇÄ¡ÀÇ ¶³¸² Çö»óÀÌ Àû¾îÁø´Ù.
    int        Expand;                    // Expand »çÀÌÁî ¸¸Å­ ÇÇÄ¡ µ¥ÀÌÅ͸¦ È®Àå½ÃŲ´Ù.
 
    double    ResultPitch;            // Pitch °á°ú¹°
 
public:
    stPitchParam()
    {
        PitchStart= 10;
        PitchEnd= 300;
        TiltStart= -1;
        TiltEnd= 1;
        Width= 128;
        Height= 128;
        Direction= PP_HORIZONTAL;
 
        ZeroBack= 3;
        Interval= 16;
        Dist= 16;
        Expand= 10000;
        ResultPitch=0.;
    }
 
    void SetEnv(int interval, int width, int height, int zeroback, int expand, int dist= 16)
    {
        if(interval >= 16)
            Interval= interval;
        else
            Interval= 16;
 
        Interval= Interval>>4<<4;    // IntervalÀº 16ÀÇ ¹è¼ö¸¸ °¡´É.
 
        if(dist >= 16)
            Dist= dist;
        else
            Dist= 16;
        Dist= Dist>>4<<4;        // Dist ´Â 16ÀÇ ¹è¼ö¸¸ °¡´É.
 
        if(width >= 16)
            Width= width;
        else
            Width= 16;
 
        if(height >= 16)
            Height= height;
        else
            Height= 16;
 
        ZeroBack= zeroback;
 
        Expand= expand;
    }
 
    void    SetTiltRange(double tiltStart, double tiltEnd)
    {
        TiltStart= tiltStart;
        TiltEnd= tiltEnd;
    }
 
    void    SetPitchRange(double start, double end, double tiltStart=0, double tiltEnd=0)
    {
        if(start < 2)
            start= 2;
        if(end < 3)
            end= 3;
 
        if(end < start)
        {
            PitchStart    = end;
            PitchEnd    = start;
        }else
        {
            PitchStart    = start;
            PitchEnd    = end;
        }
 
        if(tiltEnd < tiltStart)
        {
            TiltStart= tiltEnd;
            TiltEnd= tiltStart;
        }else
        {
            TiltStart= tiltStart;
            TiltEnd= tiltEnd;
        }
    }
    double    GetMiddlePitch()
    {
        return (PitchEnd+ PitchStart)/2;
    }
    double GetPitchRange()
    {
        return (PitchEnd- PitchStart)/2;
    }
    double GetMiddleTilt()
    {
        return (TiltEnd+ TiltStart)/2;
    }
    double GetTiltRange()
    {
        return (TiltEnd- TiltStart)/2;
    }
};
 
class CPitchStat;
 
class CPitchRepre
{
protected:
    int        m_iFrame;
    int        m_BasePitch16, m_MinPitch16, m_MaxPitch16;
    int        m_MinTilt16, m_MaxTilt16;
public:
    double    GetBasePitch(){return (double)m_BasePitch16/SPR_MULTI;}
    double    GetMinPitch(){return (double)m_MinPitch16/SPR_MULTI;}
    double    GetMaxPitch(){return (double)m_MaxPitch16/SPR_MULTI;}
    double    GetMinTilt(){return (double)m_MinTilt16/SPR_MULTI;}
    double    GetMaxTilt(){return (double)m_MaxTilt16/SPR_MULTI;}
    friend CPitchStat;
};
 
class CPitchStat : public CPitchRepre,  public CPitchBlock
{
public:
    CPitchStat(void);
    ~CPitchStat(void);
    int        m_iStartEstmated, m_iEndEstmated;
    int        m_iStartPitch;
    int        m_iEndPitch;
    int        m_IntervalStore;
    int        m_IntervalSearch;
    stPitchParam m_PitchParam;
 
    CMosisBlock<CPitchRepre>    m_PitchRepres;
 
    CMosisBlock<short>    m_ConvBlock;
    CMosisBlock<short>    m_ConvBlock2;
 
#define PITCHSTAT_PADDING    4
 
public:
    BOOL    SetRepreSpace(int n)    { return m_PitchRepres.SetBlockSize(n);}
    void    ResetPitchRepre(){m_PitchRepres.ResetBlock(); m_MinPitch16= m_MinTilt16= INT_MAX; m_MaxPitch16= m_MaxTilt16= INT_MIN;}
    BOOL    CheckPitchNTiltRepre(CMosisBuffer &buff, CRect &rect, stPitchParam &pitchParam, int iFrame);
    BOOL    GetPitchRepre(CPitchRepre *pRepre);
    BOOL    GettiltRepre(CPitchRepre *pRepre);
 
public:
    void    ResetPitchStat(){m_iStartPitch= INT_MAX; m_iEndPitch= -INT_MAX;};
    void    VerifyPitchInfo(int left, int right, int expand, int rightOriginal);
    void    VerifyTiltInfo(int left, int right, int expand, int rightOriginal);
    void    SetPitchInfo(int x, int iPitch16);
    void    ResetConBuff(int nSize);
 
protected:
    double    CheckOnePitch(BYTE* pData, int BuffWidth, int BuffHeight, CRect &rect, stPitchParam &PitchParam);
    BOOL    CheckDynamicPitch(BYTE* pData, int BuffWidth, int BuffHeight, CRect &rect, stPitchParam &PitchParam);
 
    BOOL    CheckTilt(BYTE* pData, int BuffWidth, int BuffHeight, CRect &rect, stPitchParam &PitchParam, double &pitch, double &tilt);
    BOOL    CheckDynamicPitchWithTilt(BYTE* pData, int BuffWidth, int BuffHeight, CRect &rect, stPitchParam &PitchParam);
    BOOL    CheckDynamicTilt(BYTE* pData, int BuffWidth, int BuffHeight, CRect &rect, stPitchParam &PitchParam);
 
    BOOL    CheckFluidPitch(BYTE* pData, int BuffWidth, int BuffHeight, CRect &rect, stPitchParam &PitchParam);
 
public:
    double    CheckOnePitch(CMosisBuffer &buff, CRect &rect, stPitchParam &PitchParam);
    BOOL    CheckDynamicPitch(CMosisBuffer &buff, CRect &rect, stPitchParam &PitchParam);
    void    CheckPitch(CMosisBuffer Frame,CRect &InsRect, double pitch, CString &strGlassID, int iModel, int iRegion, int iFrame);
 
    BOOL    CheckTilt(CMosisBuffer &buff, CRect &rect, stPitchParam &PitchParam, double &pitch, double &tilt);
    BOOL    CheckDynamicPitchWithTilt(CMosisBuffer &buffer, CRect &rect, stPitchParam &PitchParam);
    BOOL    CheckDynamicTilt(CMosisBuffer &buffer, CRect &rect, stPitchParam &PitchParam);
 
    BOOL    CheckFluidPitch(CMosisBuffer &buff, CRect &rect, stPitchParam &PitchParam);
 
public:
    void    WritePitchStat(CString &fileName);
    void    WritePitchRepre(CString &fileName);    // scan º° frame Àüü¿¡ ´ëÇÑ pitch statÀ» º¸¿©ÁÖ±â À§ÇÑ ±â´É
    int*    GetPitch()        {return m_pData;}
    double    GetRealPitch(int i)    {return (double)m_pData[i]/SPR_MULTI;}
    int        GetInterval()    {return m_IntervalStore;}
    void    WriteToBuff(double *p, int &nData);
    int        GetPitchSection()
    {
        if(m_iEndPitch == m_iStartPitch)    return 0;
 
        int np;
        np= m_IntervalSearch/m_IntervalStore;
        return (m_iEndPitch-m_iStartPitch)/np;
    }
};
 
class CPSControl
{
    int    m_nSpace;
    int    m_nModel;
    int m_nThread;
    CPitchStat    *m_pPitchStat;
public:
    CPSControl(){m_nSpace= m_nModel= 0; m_pPitchStat= NULL;};
    ~CPSControl(){ReleaseSpace();};
 
    BOOL SetModelCount(int nModel,int nThread)
    {
        if(nModel*nThread <= m_nSpace)
        {
            m_nModel= nModel;
            m_nThread= nThread;
            return TRUE;
        }
 
        ReleaseSpace();
 
        //yjm bug fix 20101021
        m_pPitchStat = new CPitchStat[nModel*nThread];
 
        if(! m_pPitchStat) return FALSE;
        m_nSpace= nModel*nThread;
        m_nModel= nModel;
        m_nThread= nThread;
        return TRUE;
    }
    void ReleaseSpace()
    {
        if(m_pPitchStat)
            delete[] m_pPitchStat;
        m_nModel= 0;
        m_nSpace= 0;
        m_nThread= 0;
        m_pPitchStat= NULL;
    }
    void ResetPitchStatInfo();
    CPitchStat* GetPitchStat(int iModel,int iThread)
    {
        if(iModel < 0 || iModel >= m_nModel)
        {
            //            AfxMessageBox("GetDynamicPitch()");
            return m_pPitchStat;
        }
        return m_pPitchStat+ (iModel*m_nThread+iThread);
    }
    void CheckPitch(class CScanGlass *pRecipe, int iFrame, int FrameHeight, CMosisBuffer Frame, int iThread);
};