segments a concomp based on pixel density histogram local minima if there were none found, it returns NULL this is more useful than creating a clone of itself
| 178 | // if there were none found, it returns NULL |
| 179 | // this is more useful than creating a clone of itself |
| 180 | ConComp **ConComp::Segment(int max_hist_wnd, int *concomp_cnt) { |
| 181 | // init |
| 182 | (*concomp_cnt) = 0; |
| 183 | |
| 184 | // No pts |
| 185 | if (head_ == NULL) { |
| 186 | return NULL; |
| 187 | } |
| 188 | |
| 189 | int seg_pt_cnt = 0; |
| 190 | |
| 191 | // create the histogram |
| 192 | int *hist_array = CreateHistogram(max_hist_wnd); |
| 193 | if (hist_array == NULL) { |
| 194 | return NULL; |
| 195 | } |
| 196 | |
| 197 | int *x_seg_pt = SegmentHistogram(hist_array, &seg_pt_cnt); |
| 198 | |
| 199 | // free histogram |
| 200 | delete []hist_array; |
| 201 | |
| 202 | // no segments, nothing to do |
| 203 | if (seg_pt_cnt == 0) { |
| 204 | delete []x_seg_pt; |
| 205 | return NULL; |
| 206 | } |
| 207 | |
| 208 | // create concomp array |
| 209 | ConComp **concomp_array = new ConComp *[seg_pt_cnt + 1]; |
| 210 | |
| 211 | for (int concomp = 0; concomp <= seg_pt_cnt; concomp++) { |
| 212 | concomp_array[concomp] = new ConComp(); |
| 213 | |
| 214 | // split concomps inherit the ID this concomp |
| 215 | concomp_array[concomp]->SetID(id_); |
| 216 | } |
| 217 | |
| 218 | // set the left and right most attributes of the |
| 219 | // appropriate concomps |
| 220 | concomp_array[0]->left_most_ = true; |
| 221 | concomp_array[seg_pt_cnt]->right_most_ = true; |
| 222 | |
| 223 | // assign pts to concomps |
| 224 | ConCompPt *pt_ptr = head_; |
| 225 | while (pt_ptr != NULL) { |
| 226 | int seg_pt; |
| 227 | |
| 228 | // find the first seg-pt that exceeds the x value |
| 229 | // of the pt |
| 230 | for (seg_pt = 0; seg_pt < seg_pt_cnt; seg_pt++) { |
| 231 | if ((x_seg_pt[seg_pt] + left_) > pt_ptr->x()) { |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | // add the pt to the proper concomp |
| 237 | if (concomp_array[seg_pt]->Add(pt_ptr->x(), pt_ptr->y()) == false) { |