Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
olutil.cpp
Go to the documentation of this file.
1 /* -*-C-*-
2 ********************************************************************************
3 *
4 * File: olutil.c (Formerly olutil.c)
5 * Description:
6 * Author: Mark Seaman, OCR Technology
7 * Created: Fri Oct 16 14:37:00 1987
8 * Modified: Fri May 17 13:11:24 1991 (Mark Seaman) marks@hpgrlt
9 * Language: C
10 * Package: N/A
11 * Status: Reusable Software Component
12 *
13 * (c) Copyright 1987, Hewlett-Packard Company.
14 ** Licensed under the Apache License, Version 2.0 (the "License");
15 ** you may not use this file except in compliance with the License.
16 ** You may obtain a copy of the License at
17 ** http://www.apache.org/licenses/LICENSE-2.0
18 ** Unless required by applicable law or agreed to in writing, software
19 ** distributed under the License is distributed on an "AS IS" BASIS,
20 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 ** See the License for the specific language governing permissions and
22 ** limitations under the License.
23 *
24 *********************************************************************************/
25 /*----------------------------------------------------------------------
26 I n c l u d e s
27 ----------------------------------------------------------------------*/
28 #include "olutil.h"
29 #include "structures.h"
30 #include "blobs.h"
31 #include "const.h"
32
33 #ifdef __UNIX__
34 #include <assert.h>
35 #endif
36
37 /*----------------------------------------------------------------------
38 F u n c t i o n s
39 ----------------------------------------------------------------------*/
40 /**********************************************************************
41 * correct_blob_order
42 *
43 * Check to see if the blobs are in the correct order. If they are not
44 * then swap which outlines are attached to which blobs.
45 **********************************************************************/
46 void correct_blob_order(TBLOB *blob1, TBLOB *blob2) {
47 TPOINT origin1;
48 TPOINT origin2;
49 TESSLINE *temp;
50
51 blob_origin(blob1, &origin1);
52 blob_origin(blob2, &origin2);
53
54 if (origin1.x > origin2.x) {
55 temp = blob2->outlines;
56 blob2->outlines = blob1->outlines;
57 blob1->outlines = temp;
58 }
59 }
60
61
62 /**********************************************************************
63 * eliminate_duplicate_outlines
64 *
65 * Find and delete any duplicate outline records in this blob.
66 **********************************************************************/
67 void eliminate_duplicate_outlines(TBLOB *blob) {
68 TESSLINE *outline;
69 TESSLINE *other_outline;
70 TESSLINE *last_outline;
71
72 for (outline = blob->outlines; outline; outline = outline->next) {
73
74 for (last_outline = outline, other_outline = outline->next;
75 other_outline;
76 last_outline = other_outline, other_outline = other_outline->next) {
77
78 if (same_outline_bounds (outline, other_outline)) {
79 last_outline->next = other_outline->next;
80 // This doesn't leak - the outlines share the EDGEPTs.
81 other_outline->loop = NULL;
82 delete other_outline;
83 other_outline = last_outline;
84 // If it is part of a cut, then it can't be a hole any more.
85 outline->is_hole = false;
86 }
87 }
88 }
89 }
90
91 /**********************************************************************
92 * setup_blob_outlines
93 *
94 * Set up each of the outlines in this blob.
95 **********************************************************************/
96 void setup_blob_outlines(TBLOB *blob) {
97 TESSLINE *outline;
98
99 for (outline = blob->outlines; outline; outline = outline->next) {
100 outline->ComputeBoundingBox();
101 }
102 }