43 while (pt_ptr !=
NULL) {
67 left_ = left_ <= x ? left_ : x;
68 top_ = top_ <= y ? top_ : y;
69 right_ = right_ >= x ? right_ : x;
70 bottom_ = bottom_ >= y ? bottom_ : y;
84 if (head_ ==
NULL || tail_ ==
NULL ||
85 concomp->head_ ==
NULL || concomp->tail_ ==
NULL) {
90 tail_ = concomp->tail_;
91 left_ = left_ <= concomp->left_ ? left_ : concomp->left_;
92 top_ = top_ <= concomp->top_ ? top_ : concomp->top_;
93 right_ = right_ >= concomp->right_ ? right_ : concomp->right_;
94 bottom_ = bottom_ >= concomp->bottom_ ? bottom_ : concomp->bottom_;
95 pt_cnt_ += concomp->pt_cnt_;
97 concomp->head_ =
NULL;
98 concomp->tail_ =
NULL;
107 int wid = right_ - left_ + 1,
108 hgt = bottom_ - top_ + 1,
111 if (hist_wnd > max_hist_wnd) {
112 hist_wnd = max_hist_wnd;
116 int *hist_array =
new int[wid];
117 if (hist_array ==
NULL) {
121 memset(hist_array, 0, wid *
sizeof(*hist_array));
126 while (pt_ptr !=
NULL) {
127 int x = pt_ptr->
x() - left_,
130 for (
int xdel = -hist_wnd; xdel <= hist_wnd; xdel++, xw++) {
131 if (xw >= 0 && xw < wid) {
136 pt_ptr = pt_ptr->
Next();
147 int wid = right_ - left_ + 1,
148 hgt = bottom_ - top_ + 1;
150 int *x_seg_pt =
new int[wid];
151 if (x_seg_pt ==
NULL) {
157 if (seg_pt_wnd > 1) {
161 for (
int x = 2; x < (wid - 2); x++) {
162 if (hist_array[x] < hist_array[x - 1] &&
163 hist_array[x] < hist_array[x - 2] &&
164 hist_array[x] <= hist_array[x + 1] &&
165 hist_array[x] <= hist_array[x + 2]) {
166 x_seg_pt[(*seg_pt_cnt)++] = x;
168 }
else if (hist_array[x] <= hist_array[x - 1] &&
169 hist_array[x] <= hist_array[x - 2] &&
170 hist_array[x] < hist_array[x + 1] &&
171 hist_array[x] < hist_array[x + 2]) {
172 x_seg_pt[(*seg_pt_cnt)++] = x;
178 if ((*seg_pt_cnt) == 0) {
202 if (hist_array ==
NULL) {
212 if (seg_pt_cnt == 0) {
219 if (concomp_array ==
NULL) {
224 for (
int concomp = 0; concomp <= seg_pt_cnt; concomp++) {
225 concomp_array[concomp] =
new ConComp();
226 if (concomp_array[concomp] ==
NULL) {
228 delete []concomp_array;
233 concomp_array[concomp]->
SetID(id_);
238 concomp_array[0]->left_most_ =
true;
239 concomp_array[seg_pt_cnt]->right_most_ =
true;
243 while (pt_ptr !=
NULL) {
248 for (seg_pt = 0; seg_pt < seg_pt_cnt; seg_pt++) {
249 if ((x_seg_pt[seg_pt] + left_) > pt_ptr->
x()) {
255 if (concomp_array[seg_pt]->
Add(pt_ptr->
x(), pt_ptr->
y()) ==
false) {
257 delete []concomp_array;
261 pt_ptr = pt_ptr->
Next();
266 (*concomp_cnt) = (seg_pt_cnt + 1);
268 return concomp_array;
275 while (pt_ptr !=
NULL) {
276 pt_ptr->
Shift(dx, dy);
277 pt_ptr = pt_ptr->
Next();
int * SegmentHistogram(int *hist_array, int *seg_pt_cnt)
void Shift(int dx, int dy)
void Shift(int dx, int dy)
bool Merge(ConComp *con_comp)
int * CreateHistogram(int max_hist_wnd)
ConComp ** Segment(int max_hist_wnd, int *concomp_cnt)
void SetNext(ConCompPt *pt)