From 77467594bd879c868efbf289568b79aa1f6d528e Mon Sep 17 00:00:00 2001 From: esther Date: Thu, 2 May 2024 21:02:48 +0200 Subject: [PATCH] improved vector_cellmap function --- src/contour_creator.hh | 5 ++++- src/main.cpp | 49 +++++++++++++++++------------------------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/contour_creator.hh b/src/contour_creator.hh index 54d29b9..4bc45f5 100644 --- a/src/contour_creator.hh +++ b/src/contour_creator.hh @@ -43,10 +43,13 @@ class Point int x; int y; int mscase; + Point * next; + Point * previous; Point(int x, int y, int mscase){ this -> x = x; this -> y = y; this -> mscase = mscase; - + this -> next = nullptr; + this -> previous = nullptr; }; }; diff --git a/src/main.cpp b/src/main.cpp index f72ba76..8da17d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -15,9 +16,9 @@ std::vector produce_cellmap(HeightMap* heightmap, float z) { - int length = (heightmap->width-1)*(heightmap->height-1); + int length = (heightmap->width-1)*(heightmap->height-1); // Defining length of vector uint8_t *cells = (uint8_t *) CPLMalloc(sizeof(uint8_t)*length); - std::vector points; + std::vector points; // Initiating a vector of points for (int i = 0; iwidth-1); int x = i%(heightmap->width-1); @@ -50,38 +51,28 @@ std::vector> vector_cellmap(HeightMap* heightmap, int interva #pragma omp for for (int i = 1; i <= num_contours; i++) { - auto points = produce_cellmap(heightmap, heightmap->min + interval*i) ; - std::vector line; - line.push_back(points.back()); - points.pop_back(); + auto points = produce_cellmap(heightmap, heightmap->min + interval*i); - while (points.size() != 0){ - Point current_point = points.back(); - for (int j=0; j < points.size(); j++){ - Point next = points[j]; - if (&next != &points.back()) { - if (next.x +1 == current_point.x) { - line.push_back(next); - points.erase(points.begin()+j); + + for (int j = 0; j < points.size(); j++){ + Point current = points[j]; + //std::cout << points_allocated << " " << points.size() << "\n"; + for (int k = 0; k < points.size(); k++){ + Point candidate = points[k]; + if (candidate.next != nullptr) { + if (candidate.x +1 == current.x) { + current.next = &candidate; } - else if (next.x -1 == current_point.x) { - line.push_back(next); - points.erase(points.begin()+j); + else if (candidate.x -1 == current.x) { + current.next = &candidate; } - else if (next.y +1 == current_point.y) { - line.push_back(next); - points.erase(points.begin()+j); + else if (candidate.y +1 == current.x) { + current.next = &candidate; } - else if (next.y -1 == current_point.y) { - line.push_back(next); - points.erase(points.begin()+j); - } - else { - vec_private.push_back(line); - std::vector line; - line.push_back(points.back()); - points.pop_back(); + else if (candidate.y -1 == current.x) { + current.next = &candidate; } + } } }