Skip to content

Commit

Permalink
Update Valley class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samir55 committed Dec 2, 2017
1 parent 0f8634e commit 4d52dd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/LineSegmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,18 @@ 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));
}
}

// 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);
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions src/LineSegmentation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,22 @@ 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.
int position;
///< 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);
Expand Down

0 comments on commit 4d52dd5

Please sign in to comment.