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
// SISPitch.cpp: implementation of the CSISPitch class.
//
//////////////////////////////////////////////////////////////////////
 
#include "stdafx.h"
#include "SISPitch.h"
 
#include "SISBuffer.h"
#include "SISMath.h"
 
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
 
BOOL CSISPitch::CheckPitch(CSISBuffer buffer, CRect rect)
{
    m_xPitch= 0;
    m_yPitch= 0;
    m_Rect= rect;
    
    int xIntPitch= (int)m_xPitchOrigin;
    int yIntPitch= (int)m_yPitchOrigin;
    
    if(xIntPitch < 10 || yIntPitch < 10)
        return FALSE;
    if(rect.top < 0)
        return FALSE;
    CSISHive1B<int64> m_DifferenceHive;
    if(m_DifferenceHive.SetSize(m_xSearchRange*2+ 2, FALSE) < 1)
        return FALSE;
    if(m_DifferenceHive.SetSize(m_ySearchRange*2+ 2, FALSE) < 1)
        return FALSE;
    
    int64 *differences= m_DifferenceHive.GetData(0);
    int i;
    
    double xResult= -1;
    double yResult= -1;
    int x, y, x2, y2;
 
 
    x= rect.left;
    y= rect.top;
    x2= x+ xIntPitch- m_xSearchRange;
    y2= y;
 
    if(rect.left+ xIntPitch+ m_xSearchRange*2+ m_CheckWidth < rect.right)
    {
        for(i= 0; i< m_xSearchRange*2; i++)
        {
            differences[i]= CSISMath::GetAbsDiff(buffer, x, y, m_CheckWidth, m_CheckHeight, buffer, x2+ i, y2);
        }
        xResult= CSISMath::SearchMinimum(differences, m_xSearchRange*2);
    }
    if(xResult >= 0)
    {
        m_xPitch= x2- x+ xResult;
    }else
        m_xPitch= 0;
 
 
    x2= x;
    y2= y+ yIntPitch- m_ySearchRange;
    if(rect.top+ yIntPitch+ m_ySearchRange*2+ m_CheckHeight < rect.bottom)
    {
        for(i= 0; i< m_ySearchRange*2; i++)
        {
            differences[i]= CSISMath::GetAbsDiff(buffer, x, y, m_CheckWidth, m_CheckHeight, buffer, x2, y2+ i);
        }
        yResult= CSISMath::SearchMinimum(differences, m_ySearchRange*2);
    }
    if(yResult >= 0)
    {
        m_yPitch= y2- y+ yResult;
    }else
        m_yPitch= 0;
    
    return xResult >= 0 && yResult >= 0;
}