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
coutln.h
Go to the documentation of this file.
1 /**********************************************************************
2 * File: coutln.c (Formerly: coutline.c)
3 * Description: Code for the C_OUTLINE class.
4 * Author: Ray Smith
5 * Created: Mon Oct 07 16:01:57 BST 1991
6 *
7 * (C) Copyright 1991, Hewlett-Packard Ltd.
8 ** Licensed under the Apache License, Version 2.0 (the "License");
9 ** you may not use this file except in compliance with the License.
10 ** You may obtain a copy of the License at
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
17 *
18 **********************************************************************/
19
20 #ifndef COUTLN_H
21 #define COUTLN_H
22
23 #include "crakedge.h"
24 #include "mod128.h"
25 #include "bits16.h"
26 #include "rect.h"
27 #include "blckerr.h"
28 #include "scrollview.h"
29
30 #define INTERSECTING MAX_INT16//no winding number
31
32 //mask to get step
33 #define STEP_MASK 3
34
35 enum C_OUTLINE_FLAGS
36 {
37 COUT_INVERSE //White on black blob
38 };
39
40 class DLLSYM C_OUTLINE; //forward declaration
41 struct Pix;
42
43 ELISTIZEH (C_OUTLINE)
44 class DLLSYM C_OUTLINE:public ELIST_LINK
45 {
46 public:
47 C_OUTLINE() { //empty constructor
48 steps = NULL;
49 }
50 C_OUTLINE( //constructor
51 CRACKEDGE *startpt, //from edge detector
52 ICOORD bot_left, //bounding box //length of loop
53 ICOORD top_right,
54 inT16 length);
55 C_OUTLINE(ICOORD startpt, //start of loop
56 DIR128 *new_steps, //steps in loop
57 inT16 length); //length of loop
58 //outline to copy
59 C_OUTLINE(C_OUTLINE *srcline, FCOORD rotation); //and rotate
60
61 // Build a fake outline, given just a bounding box and append to the list.
62 static void FakeOutline(const TBOX& box, C_OUTLINE_LIST* outlines);
63
64 ~C_OUTLINE () { //destructor
65 if (steps != NULL)
66 free_mem(steps);
67 steps = NULL;
68 }
69
70 BOOL8 flag( //test flag
71 C_OUTLINE_FLAGS mask) const { //flag to test
72 return flags.bit (mask);
73 }
74 void set_flag( //set flag value
75 C_OUTLINE_FLAGS mask, //flag to test
76 BOOL8 value) { //value to set
77 flags.set_bit (mask, value);
78 }
79
80 C_OUTLINE_LIST *child() { //get child list
81 return &children;
82 }
83
84 //access function
85 const TBOX &bounding_box() const {
86 return box;
87 }
88 void set_step( //set a step
89 inT16 stepindex, //index of step
90 inT8 stepdir) { //chain code
91 int shift = stepindex%4 * 2;
92 uinT8 mask = 3 << shift;
93 steps[stepindex/4] = ((stepdir << shift) & mask) |
94 (steps[stepindex/4] & ~mask);
95 //squeeze 4 into byte
96 }
97 void set_step( //set a step
98 inT16 stepindex, //index of step
99 DIR128 stepdir) { //direction
100 //clean it
101 inT8 chaindir = stepdir.get_dir() >> (DIRBITS - 2);
102 //difference
103 set_step(stepindex, chaindir);
104 //squeeze 4 into byte
105 }
106
107 //get start position
108 const ICOORD &start_pos() const {
109 return start;
110 }
111 inT32 pathlength() const { //get path length
112 return stepcount;
113 }
114 // Return step at a given index as a DIR128.
115 DIR128 step_dir(inT16 index) const {
116 return DIR128((inT16)(((steps[index/4] >> (index%4 * 2)) & STEP_MASK) <<
117 (DIRBITS - 2)));
118 }
119 // Return the step vector for the given outline position.
120 ICOORD step(inT16 index) const { //index of step
121 return step_coords[(steps[index/4] >> (index%4 * 2)) & STEP_MASK];
122 }
123
124 inT32 area(); //return area
125 inT32 perimeter(); // Total perimeter of self and 1st level children.
126 inT32 outer_area(); //return area
127 inT32 count_transitions( //count maxima
128 inT32 threshold); //size threshold
129
130 BOOL8 operator< ( //containment test
131 const C_OUTLINE & other) const;
132 BOOL8 operator> ( //containment test
133 C_OUTLINE & other) const
134 {
135 return other < *this; //use the < to do it
136 }
137 inT16 winding_number( //get winding number
138 ICOORD testpt) const; //around this point
139 //get direction
140 inT16 turn_direction() const;
141 void reverse(); //reverse direction
142
143 void move( // reposition outline
144 const ICOORD vec); // by vector
145
146 // If this outline is smaller than the given min_size, delete this and
147 // remove from its list, via *it, after checking that *it points to this.
148 // Otherwise, if any children of this are too small, delete them.
149 // On entry, *it must be an iterator pointing to this. If this gets deleted
150 // then this is extracted from *it, so an iteration can continue.
151 void RemoveSmallRecursive(int min_size, C_OUTLINE_IT* it);
152
153 // Renders the outline to the given pix, with left and top being
154 // the coords of the upper-left corner of the pix.
155 void render(int left, int top, Pix* pix) const;
156
157 // Renders just the outline to the given pix (no fill), with left and top
158 // being the coords of the upper-left corner of the pix.
159 void render_outline(int left, int top, Pix* pix) const;
160
161 #ifndef GRAPHICS_DISABLED
162 void plot( //draw one
163 ScrollView* window, //window to draw in
164 ScrollView::Color colour) const; //colour to draw it
165 #endif // GRAPHICS_DISABLED
166
167 C_OUTLINE& operator=(const C_OUTLINE& source);
168
169 static C_OUTLINE* deep_copy(const C_OUTLINE* src) {
170 C_OUTLINE* outline = new C_OUTLINE;
171 *outline = *src;
172 return outline;
173 }
174
175 static ICOORD chain_step(int chaindir);
176
177 private:
178 int step_mem() const { return (stepcount+3) / 4; }
179
180 TBOX box; //boudning box
181 ICOORD start; //start coord
182 uinT8 *steps; //step array
183 inT16 stepcount; //no of steps
184 BITS16 flags; //flags about outline
185 C_OUTLINE_LIST children; //child elements
186 static ICOORD step_coords[4];
187 };
188 #endif