diff --git a/src/LineSegmentation.cpp b/src/LineSegmentation.cpp index 915eb97..fd89ab1 100755 --- a/src/LineSegmentation.cpp +++ b/src/LineSegmentation.cpp @@ -167,10 +167,10 @@ LineSegmentation::generate_initial_points() { sort(line.valleys_ids.begin(), line.valleys_ids.end()); // Add line points in the first chunks having no valleys. - if (all_valleys_ids[line.valleys_ids.front()]->chunk_order > 0) { + if (all_valleys_ids[line.valleys_ids.front()]->chunk_index > 0) { previous_row = all_valleys_ids[line.valleys_ids.front()]->position; max_row_position = min_row_position = previous_row; - for (int j = 0; j < this->chunks[all_valleys_ids[line.valleys_ids.front()]->chunk_order].start_col; j++) { + for (int j = 0; j < this->chunks[all_valleys_ids[line.valleys_ids.front()]->chunk_index].start_col; j++) { if (c++ == j) line.points.push_back(Point(previous_row, j)); } @@ -178,7 +178,7 @@ LineSegmentation::generate_initial_points() { // Add line points between the valleys. for (auto id : line.valleys_ids) { - int chunk_order = all_valleys_ids[id]->chunk_order, chunk_row = all_valleys_ids[id]->position; + int chunk_order = all_valleys_ids[id]->chunk_index, chunk_row = all_valleys_ids[id]->position; for (int j = this->chunks[chunk_order].start_col; j < this->chunks[chunk_order].start_col + chunk_width; j++) { min_row_position = min(min_row_position, chunk_row); @@ -194,8 +194,8 @@ LineSegmentation::generate_initial_points() { } // Add line points in the last chunks having no valleys. - if (CHUNKS_NUMBER - 1 > all_valleys_ids[line.valleys_ids.back()]->chunk_order) { - int chunk_order = all_valleys_ids[line.valleys_ids.back()]->chunk_order, + if (CHUNKS_NUMBER - 1 > all_valleys_ids[line.valleys_ids.back()]->chunk_index) { + int chunk_order = all_valleys_ids[line.valleys_ids.back()]->chunk_index, chunk_row = all_valleys_ids[line.valleys_ids.back()]->position; for (int j = this->chunks[chunk_order].start_col + chunk_width; j < color_img.cols; j++) { if (c++ == j) @@ -470,6 +470,8 @@ Peak::comp(const Peak &a, const Peak &b) { return a.position < b.position; } +int Valley::ID = 0; + bool Valley::comp(const Valley *a, const Valley *b) { return a->position < b->position; diff --git a/src/LineSegmentation.hpp b/src/LineSegmentation.hpp index 63ff863..9ebcd13 100755 --- a/src/LineSegmentation.hpp +++ b/src/LineSegmentation.hpp @@ -70,7 +70,9 @@ class Peak { /// A class representing the valleys (local minimum points in the histogram) class Valley { public: - int chunk_order; + static int ID; + ///< Next available id. + int chunk_index; ///< The index of the chunk in the chunks vector. int valley_id; ///< The valley id. @@ -78,10 +80,12 @@ class Valley { ///< The row position. bool used; /// Whether it's used by a line or not. + Line* line; + /// The line to which this valley is connected. - Valley(int v_id) : valley_id(v_id), used(false) {} + Valley() : valley_id(ID++), used(false) {} - Valley(int c_id, int v_id, int p, int v) : chunk_order(c_id), valley_id(v_id), position(p), used(false) {} + Valley(int c_id, int p) : chunk_index(c_id), valley_id(ID++), position(p), used(false) {} static bool comp(const Valley *a, const Valley *b);