2
2
Copyright (c) 1993-2008, Cognitive Technologies
5
����������� ��������� ��������������� � ������������� ��� � ���� ��������� ����,
6
��� � � �������� �����, � ����������� ��� ���, ��� ���������� ��������� �������:
8
* ��� ��������� ��������������� ��������� ���� ������ ���������� ���������
9
���� ����������� �� ��������� �����, ���� ������ ������� � �����������
11
* ��� ��������� ��������������� ��������� ���� � ������������ �/��� �
12
������ ����������, ������������ ��� ���������������, ������ �����������
13
��������� ���� ���������� �� ��������� �����, ���� ������ ������� �
14
����������� ����� �� ��������.
15
* �� �������� Cognitive Technologies, �� ����� �� ����������� �� �����
16
���� ������������ � �������� �������� ��������� �/��� �����������
17
���������, ���������� �� ���� ��, ��� ���������������� �����������
20
��� ��������� ������������� ����������� ��������� ���� �/��� ������� ������ "���
21
��� ����" ��� ������-���� ���� ��������, ���������� ���� ��� ���������������,
22
������� �������� ������������ �������� � ����������� ��� ���������� ����, �� ��
23
������������� ���. �� �������� ��������� ���� � �� ���� ������ ����, �������
24
����� �������� �/��� �������� �������������� ���������, �� � ���� ������ ��
25
��Ѩ� ���������������, ������� ����� �����, ���������, ����������� ���
26
������������� ������, ��������� � �������������� ��� ���������� ����������
27
������������� ������������� ��������� (������� ������ ������, ��� ������,
28
������� ���������, ��� ������ �/��� ������ �������, ���������� ��-�� ��������
29
������� ��� �/��� ������ ��������� �������� ��������� � ������� �����������,
30
�� �� ������������� ����� ��������), �� �� ������������� ���, ���� ���� �����
31
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
5
Разрешается повторное распространение и использование как в виде исходного кода,
6
так и в двоичной форме, с изменениями или без, при соблюдении следующих условий:
8
* При повторном распространении исходного кода должны оставаться указанное
9
выше уведомление об авторском праве, этот список условий и последующий
11
* При повторном распространении двоичного кода в документации и/или в
12
других материалах, поставляемых при распространении, должны сохраняться
13
указанная выше информация об авторском праве, этот список условий и
14
последующий отказ от гарантий.
15
* Ни название Cognitive Technologies, ни имена ее сотрудников не могут
16
быть использованы в качестве средства поддержки и/или продвижения
17
продуктов, основанных на этом ПО, без предварительного письменного
20
ЭТА ПРОГРАММА ПРЕДОСТАВЛЕНА ВЛАДЕЛЬЦАМИ АВТОРСКИХ ПРАВ И/ИЛИ ДРУГИМИ ЛИЦАМИ "КАК
21
ОНА ЕСТЬ" БЕЗ КАКОГО-ЛИБО ВИДА ГАРАНТИЙ, ВЫРАЖЕННЫХ ЯВНО ИЛИ ПОДРАЗУМЕВАЕМЫХ,
22
ВКЛЮЧАЯ ГАРАНТИИ КОММЕРЧЕСКОЙ ЦЕННОСТИ И ПРИГОДНОСТИ ДЛЯ КОНКРЕТНОЙ ЦЕЛИ, НО НЕ
23
ОГРАНИЧИВАЯСЬ ИМИ. НИ ВЛАДЕЛЕЦ АВТОРСКИХ ПРАВ И НИ ОДНО ДРУГОЕ ЛИЦО, КОТОРОЕ
24
МОЖЕТ ИЗМЕНЯТЬ И/ИЛИ ПОВТОРНО РАСПРОСТРАНЯТЬ ПРОГРАММУ, НИ В КОЕМ СЛУЧАЕ НЕ
25
НЕСЁТ ОТВЕТСТВЕННОСТИ, ВКЛЮЧАЯ ЛЮБЫЕ ОБЩИЕ, СЛУЧАЙНЫЕ, СПЕЦИАЛЬНЫЕ ИЛИ
26
ПОСЛЕДОВАВШИЕ УБЫТКИ, СВЯЗАННЫЕ С ИСПОЛЬЗОВАНИЕМ ИЛИ ПОНЕСЕННЫЕ ВСЛЕДСТВИЕ
27
НЕВОЗМОЖНОСТИ ИСПОЛЬЗОВАНИЯ ПРОГРАММЫ (ВКЛЮЧАЯ ПОТЕРИ ДАННЫХ, ИЛИ ДАННЫЕ,
28
СТАВШИЕ НЕГОДНЫМИ, ИЛИ УБЫТКИ И/ИЛИ ПОТЕРИ ДОХОДОВ, ПОНЕСЕННЫЕ ИЗ-ЗА ДЕЙСТВИЙ
29
ТРЕТЬИХ ЛИЦ И/ИЛИ ОТКАЗА ПРОГРАММЫ РАБОТАТЬ СОВМЕСТНО С ДРУГИМИ ПРОГРАММАМИ,
30
НО НЕ ОГРАНИЧИВАЯСЬ ЭТИМИ СЛУЧАЯМИ), НО НЕ ОГРАНИЧИВАЯСЬ ИМИ, ДАЖЕ ЕСЛИ ТАКОЙ
31
ВЛАДЕЛЕЦ ИЛИ ДРУГОЕ ЛИЦО БЫЛИ ИЗВЕЩЕНЫ О ВОЗМОЖНОСТИ ТАКИХ УБЫТКОВ И ПОТЕРЬ.
33
33
Redistribution and use in source and binary forms, with or without modification,
34
34
are permitted provided that the following conditions are met:
57
57
/*------------------------------------------------------------------------------------------------*/
60
\brief ���������� ������� �������������� �������
61
\author ��������� ��������
60
\brief Реализация типовых геометрических функций
61
\author Александр Михайлов
64
64
/*------------------------------------------------------------------------------------------------*/
65
/* N-� �������� 21.04.2005:
66
- ���������� � ��������� ����������, ������������� � ������ "AMU_Geom.CPP" � 02.03.2001 */
65
/* N-я Редакция 21.04.2005:
66
- приведение к стандарту алгоритмов, реализованных в модуле "AMU_Geom.CPP" к 02.03.2001 */
67
67
/*------------------------------------------------------------------------------------------------*/
69
/* ������������ ����� */
69
/* межпроектные чужие */
70
70
#include "skew1024.h"
71
/* ������������ ��� (����������) */
71
/* общесорсовые мои (отдаваемые) */
72
72
#include "amt_geom.h"
73
/*---------- ���������� ��������� ----------------------------------------------------------*/
73
/*---------- Управление локальное ----------------------------------------------------------*/
74
74
/*+ (AverageRoundToBig) +*/
75
static const double HALF = .5; ///< �������� :-)
75
static const double HALF = .5; ///< половина :-)
76
76
/*+ (MakeInternalRectId) +*/
77
static const int SIZE_SKEW_SCALE = 1024; ///< ������� ����� �����
78
/** ������������ �� ������ ���� ��� ����������� ������������� */
77
static const int SIZE_SKEW_SCALE = 1024; ///< масштаб шкалы углов
78
/** Максимальный по модулю угол для нормального распознавания */
79
79
static const int MAX_ABS_SKEW = SIZE_SKEW_SCALE / 2;
80
/*---------- ��������� ������� -------------------------------------------------------------*/
80
/*---------- Локальные функции -------------------------------------------------------------*/
82
\brief ������� ��������� ����� �� ������
83
\param pA [in/out] - ��������� �� ����� - ������ ����� � �������� �����������
84
\param pB [in/out] - ��������� �� ����� - ����� ����� � �������� �����������
85
\param Lev [in] - ������� ��������� � ��������� �����������
86
\param Lev_A [in] - ������� ������ ����� � ��������� �����������
87
\param Lev_B [in] - ������� ����� ����� � ��������� �����������
88
\param LimIsMax [in] - ������� �� ����� ������� ���������
89
\param Near [in] - ���������� ������ (?)
90
\retval bool - ��� �������� ��� ���
82
\brief Функция обрезания линии по уровню
83
\param pA [in/out] - указатель на точку - начало линии в реальных координатах
84
\param pB [in/out] - указатель на точку - конец линии в реальных координатах
85
\param Lev [in] - уровень обрезания в идеальных координатах
86
\param Lev_A [in] - уровень начала линии в идеальных координатах
87
\param Lev_B [in] - уровень конца линии в идеальных координатах
88
\param LimIsMax [in] - верхнюю ли часть обрезка оставлять
89
\param Near [in] - расширение уровня (?)
90
\retval bool - так обрезали или нет
92
92
static bool CanUse (Point16 *pA, Point16 *pB, const int Lev, const int Lev_A, const int Lev_B
93
93
, const bool LimIsMax, const int Near)
96
if (LimIsMax)//������� ������������ ������
96
if (LimIsMax)//уровень ограничивает сверху
98
98
if ((Lev_A <= Lev + Near) && (Lev_B <= Lev + Near))
100
100
if ((Lev_A >= Lev + Near) && (Lev_B >= Lev + Near))
102
/* ������� ����� ������� */
102
/* Находим точку деления */
103
103
C.x = ((Lev - Lev_B) * pA->x + (Lev_A - Lev) * pB->x) / (Lev_A - Lev_B);
104
104
C.y = ((Lev - Lev_B) * pA->y + (Lev_A - Lev) * pB->y) / (Lev_A - Lev_B);
105
if (Lev_A > Lev)//�������� ��������
105
if (Lev_A > Lev)//обрезаем верхушку
138
138
/*------------------------------------------------------------------------------------------------*/
140
\brief ������� ���������� � ����������� � ������� �������
141
\param a [in] - ������ �����������
142
\param a [in] - ������ �����������
143
\retval int - ���������
140
\brief Функция усреднения с округлением в большую сторону
141
\param a [in] - первое усредняемое
142
\param a [in] - второе усредняемое
143
\retval int - результат
145
inline static int AverageRoundToBig (Int16 a, Int16 b)
145
inline static int AverageRoundToBig (int16_t a, int16_t b)
147
147
return static_cast<int>(HALF * (a + b + 1));
149
/*---------- ���������� ������� ------------------------------------------------------------*/
150
void RotateRect (const Rect16 *pRcRe, Rect16 *pRcId, Int32 Skew)
149
/*---------- Переходные функции ------------------------------------------------------------*/
150
void RotateRect (const Rect16 *pRcRe, Rect16 *pRcId, int32_t Skew)
152
152
Point32 DirIdeal = {0};
153
/* ���������� ������ �������� ���� */
153
/* Координаты левого верхнего угла */
154
154
DirIdeal.x = AverageRoundToBig (pRcRe->left, pRcRe->right);
155
155
DirIdeal.y = pRcRe->top;
156
156
::Deskew (DirIdeal, -Skew);
157
pRcId->top = static_cast<Int16>(DirIdeal.y);
158
/* ���������� ������� �������� ���� */
157
pRcId->top = static_cast<int16_t>(DirIdeal.y);
158
/* Координаты правого верхнего угла */
159
159
DirIdeal.x = AverageRoundToBig (pRcRe->left, pRcRe->right);
160
160
DirIdeal.y = pRcRe->bottom;
161
161
::Deskew (DirIdeal, -Skew);
162
pRcId->bottom = static_cast<Int16>(DirIdeal.y);
163
/* ���������� ������ ������� ���� */
162
pRcId->bottom = static_cast<int16_t>(DirIdeal.y);
163
/* Координаты левого нижнего угла */
164
164
DirIdeal.x = pRcRe->left;
165
165
DirIdeal.y = AverageRoundToBig (pRcRe->top, pRcRe->bottom);
166
166
::Deskew (DirIdeal, -Skew);
167
pRcId->left = static_cast<Int16>(DirIdeal.x);
168
/* ���������� ������� ������� ���� */
167
pRcId->left = static_cast<int16_t>(DirIdeal.x);
168
/* Координаты правого нижнего угла */
169
169
DirIdeal.x = pRcRe->right;
170
170
DirIdeal.y = AverageRoundToBig (pRcRe->top, pRcRe->bottom);
171
171
::Deskew (DirIdeal, -Skew);
172
pRcId->right = static_cast<Int16>(DirIdeal.x);
172
pRcId->right = static_cast<int16_t>(DirIdeal.x);
174
174
/*------------------------------------------------------------------------------------------------*/
175
175
void FindMinimIdealRegion (const int nRc, const int *pDo, const Rect16 *pRcIdeal, Rect16 *pMIR)
177
/* ������� ������ ������� ���������� */
177
/* находим первую стоящую компоненту */
180
180
for (i = 0; i < nRc; i++)
301
301
::Deskew (RigTop, -Skew);
302
302
::Deskew (LefBot, -Skew);
303
303
::Deskew (RigBot, -Skew);
304
if (Skew >= 0)//�� ������� ������� �� ������ �������� ����
304
if (Skew >= 0)//по часовой стрелке из левого верхнего угла
306
pRcId->top = static_cast<Int16>(LefTop.y);
307
pRcId->bottom = static_cast<Int16>(RigBot.y);
308
pRcId->left = static_cast<Int16>(LefBot.x);
309
pRcId->right = static_cast<Int16>(RigTop.x);
306
pRcId->top = static_cast<int16_t>(LefTop.y);
307
pRcId->bottom = static_cast<int16_t>(RigBot.y);
308
pRcId->left = static_cast<int16_t>(LefBot.x);
309
pRcId->right = static_cast<int16_t>(RigTop.x);
313
pRcId->top = static_cast<Int16>(RigTop.y);
314
pRcId->bottom = static_cast<Int16>(LefBot.y);
315
pRcId->left = static_cast<Int16>(LefTop.x);
316
pRcId->right = static_cast<Int16>(RigBot.x);
313
pRcId->top = static_cast<int16_t>(RigTop.y);
314
pRcId->bottom = static_cast<int16_t>(LefBot.y);
315
pRcId->left = static_cast<int16_t>(LefTop.x);
316
pRcId->right = static_cast<int16_t>(RigBot.x);
318
318
if (pRcId->top > pRcId->bottom)
324
324
/*------------------------------------------------------------------------------------------------*/
325
/*---------- ��������� ������� -------------------------------------------------------------*/
325
/*---------- Локальные функции -------------------------------------------------------------*/
326
326
static bool CanUse (Point16 *pA, Point16 *pB, const int Lev, const int Lev_A, const int Lev_B
327
327
, const bool LimIsMax, int Near);
328
inline static int AverageRoundToBig (Int16 a, Int16 b);
328
inline static int AverageRoundToBig (int16_t a, int16_t b);
329
329
/*------------------------------------------------------------------------------------------------*/