|
1 #ifndef _COMPONENT_H |
|
2 #define _COMPONENT_H |
|
3 #include "stdlib.h" |
|
4 #include <iostream.h> |
|
5 #include "Point.h" |
|
6 #include "system.h" |
|
7 #include "list.h" |
|
8 #include "RLEMap.h" |
|
9 |
|
10 |
|
11 class BitMap; |
|
12 |
|
13 class Component; |
|
14 |
|
15 class Components: public List |
|
16 { |
|
17 public: |
|
18 Components(); |
|
19 ~Components(); |
|
20 |
|
21 Component * compAt(Point p); // returns smallest component that contains |
|
22 // this point. |
|
23 |
|
24 |
|
25 }; |
|
26 |
|
27 class Component{ |
|
28 public: |
|
29 friend class Word; |
|
30 Component(Point ul, Point lr) |
|
31 :ful(ul), flr(lr), fnumBits(0),fasciiId(NULL), fconfid(0), |
|
32 charGroup(0), ffontId(0) |
|
33 { fproperty = new Property[numProperties]; |
|
34 for (int i = 0; i < numProperties; i++) |
|
35 fproperty[i] = 0;}; |
|
36 |
|
37 Component() |
|
38 :ful(-1), flr(-1), fnumBits(0),fasciiId(0),fconfid(0), |
|
39 charGroup(0), ffontId(0) |
|
40 { fproperty = new Property[numProperties]; |
|
41 for (int i = 0; i < numProperties; i++) |
|
42 fproperty[i] = 0;}; |
|
43 ~Component(){ |
|
44 if (fproperty != NULL) delete fproperty; |
|
45 if (fasciiId != NULL) delete fasciiId; |
|
46 } |
|
47 |
|
48 Component * copy(); // make a new copy of the component |
|
49 inline Point & ul() {return ful;}; |
|
50 inline Point & lr() {return flr;}; |
|
51 |
|
52 inline double width() {return (double)(flr.x() - ful.x() + 1); }; |
|
53 inline double height() {return (double)(flr.y() - ful.y() + 1); }; |
|
54 inline double area() { return width()*height(); }; |
|
55 inline int & numBits(){return fnumBits;}; |
|
56 short int charGroup; // values 0-3: 0=acemno, 1=gpqy, 2=dfhikl, 3=j([} |
|
57 int vertShrink(BitMap * bitmap); |
|
58 int horizontalShrink(BitMap * bitmap); |
|
59 |
|
60 int AddToComponent(ListElement* intrvl, RLEMap* rlemap, int horizMerge); |
|
61 /*-------------------------------------------------------------- |
|
62 Primary Purpose: Extend boundaries of component by connected intervals. Arguments: startIntrvl is interval to start from |
|
63 Return Value: Number of intervals added. |
|
64 Effects: Updates component's LR and UL. Deletes all added intervals. |
|
65 ----------------------------------------------------------------*/ |
|
66 |
|
67 // Access entire property vector |
|
68 inline Property * properties() |
|
69 {return fproperty;} |
|
70 |
|
71 // Set or read one value in property vector |
|
72 inline Property & property(int p) // Possibly use overload [] |
|
73 {return fproperty[p];}; |
|
74 |
|
75 // Set or read ascii id; |
|
76 inline Character & asciiId(){ return fasciiId[0];}; |
|
77 |
|
78 inline int asciiLen(){return strlen(fasciiId);} |
|
79 // Set or read font id; |
|
80 inline short int & fontId() {return ffontId;}; |
|
81 |
|
82 inline Confidence & confid(){ return fconfid; }; |
|
83 // Determine heuristic distance between this and comp |
|
84 Distance distance(Component * comp); |
|
85 |
|
86 Point Component::center() { return (Point((ful.x() + flr.x())/2, |
|
87 (ful.y() +flr.y())/2)); }; |
|
88 // Use the BitMap map to set the property vector for |
|
89 // this component |
|
90 |
|
91 |
|
92 void setProperties(RLEMap * map); |
|
93 void setProperties(BitMap * map); |
|
94 void setSectionFlags(short int hflag[], short int vflag[]); |
|
95 |
|
96 |
|
97 void display_bounding_box(); |
|
98 void display_bounding_box(char * color); |
|
99 void display_bounding_box(char * color, double scaleFactor, |
|
100 char * window); |
|
101 Distance recognize(Component * learnedchars); |
|
102 // find best match in learned characters. Set ascii value |
|
103 // and return distance. |
|
104 |
|
105 |
|
106 Distance recognize(Components * learnedgroups, bool allGroups=FALSE); |
|
107 // find best match from learned character groups. Set ascii value |
|
108 // and return distance. |
|
109 |
|
110 void join(Component * comp); |
|
111 inline bool operator < (Component * comp) |
|
112 {if((ul().y() < comp->ul().y())) return TRUE; |
|
113 if((ul().y() > comp->ul().y())) return FALSE; |
|
114 // otherwise if y values are equal |
|
115 return ((ul().x() <= comp->ul().x()) ? TRUE : FALSE); |
|
116 } |
|
117 inline bool operator > (Component * comp) |
|
118 {if((ul().y() > comp->ul().y())) return TRUE; |
|
119 if((ul().y() < comp->ul().y())) return FALSE; |
|
120 // otherwise if y values are equal |
|
121 return((ul().x() > comp->ul().x()) ? TRUE : FALSE); |
|
122 |
|
123 } |
|
124 inline bool xoverlap(Component * comp) |
|
125 { |
|
126 if (ful.x() <= comp->ul().x() && comp->ul().x() <= flr.x()) |
|
127 return TRUE; |
|
128 if (comp->ul().x() < ful.x() && ful.x() < comp->lr().x()) |
|
129 return TRUE; |
|
130 return FALSE; |
|
131 } |
|
132 |
|
133 Property * fproperty; |
|
134 char * fasciiId; |
|
135 private: |
|
136 Point ful; |
|
137 Point flr; |
|
138 int fnumBits; |
|
139 |
|
140 |
|
141 |
|
142 short int ffontId; |
|
143 Confidence fconfid; |
|
144 }; |
|
145 |
|
146 |
|
147 #endif |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |