00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef CONCOMP_H
00021 #define CONCOMP_H
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 namespace tesseract {
00035
00036
00037 class ConCompPt {
00038 public:
00039 ConCompPt(int x, int y) {
00040 x_ = x;
00041 y_ = y;
00042 next_pt_ = NULL;
00043 }
00044 inline int x() { return x_; }
00045 inline int y() { return y_; }
00046 inline void Shift(int dx, int dy) {
00047 x_ += dx;
00048 y_ += dy;
00049 }
00050 inline ConCompPt * Next() { return next_pt_; }
00051 inline void SetNext(ConCompPt *pt) { next_pt_ = pt; }
00052
00053 private:
00054 int x_;
00055 int y_;
00056 ConCompPt *next_pt_;
00057 };
00058
00059 class ConComp {
00060 public:
00061 ConComp();
00062 virtual ~ConComp();
00063
00064 inline ConCompPt *Head() { return head_; }
00065 inline int Left() const { return left_; }
00066 inline int Top() const { return top_; }
00067 inline int Right() const { return right_; }
00068 inline int Bottom() const { return bottom_; }
00069 inline int Width() const { return right_ - left_ + 1; }
00070 inline int Height() const { return bottom_ - top_ + 1; }
00071
00072
00073 inline static int Left2RightComparer(const void *comp1,
00074 const void *comp2) {
00075 return (*(reinterpret_cast<ConComp * const *>(comp1)))->left_ +
00076 (*(reinterpret_cast<ConComp * const *>(comp1)))->right_ -
00077 (*(reinterpret_cast<ConComp * const *>(comp2)))->left_ -
00078 (*(reinterpret_cast<ConComp * const *>(comp2)))->right_;
00079 }
00080
00081
00082 inline static int Right2LeftComparer(const void *comp1,
00083 const void *comp2) {
00084 return (*(reinterpret_cast<ConComp * const *>(comp2)))->right_ -
00085 (*(reinterpret_cast<ConComp * const *>(comp1)))->right_;
00086 }
00087
00088
00089 inline bool LeftMost() const { return left_most_; }
00090 inline bool RightMost() const { return right_most_; }
00091 inline void SetLeftMost(bool left_most) { left_most_ = left_most; }
00092 inline void SetRightMost(bool right_most) { right_most_ = right_most;
00093 }
00094 inline int ID () const { return id_; }
00095 inline void SetID(int id) { id_ = id; }
00096 inline int PtCnt () const { return pt_cnt_; }
00097
00098 bool Add(int x, int y);
00099
00100 bool Merge(ConComp *con_comp);
00101
00102 void Shift(int dx, int dy);
00103
00104 ConComp **Segment(int max_hist_wnd, int *concomp_cnt);
00105
00106 int *CreateHistogram(int max_hist_wnd);
00107
00108 int *SegmentHistogram(int *hist_array, int *seg_pt_cnt);
00109
00110 private:
00111 int id_;
00112 bool left_most_;
00113 bool right_most_;
00114 int left_;
00115 int top_;
00116 int right_;
00117 int bottom_;
00118 ConCompPt *head_;
00119 ConCompPt *tail_;
00120 int pt_cnt_;
00121 };
00122 }
00123
00124 #endif // CONCOMP_H