From 228945a7679ee49729b6457005f9c5db20346793 Mon Sep 17 00:00:00 2001 From: esther Date: Tue, 30 Apr 2024 15:07:04 +0200 Subject: [PATCH] tried to implement finding contour lines --- src/main.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 503d81f..ff46c8d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,6 +36,8 @@ std::vector produce_cellmap(HeightMap* heightmap, float z) } + + std::vector> vector_cellmap(HeightMap* heightmap, int interval) { int num_contours = (heightmap->max - heightmap->min)/interval; @@ -48,9 +50,44 @@ std::vector> vector_cellmap(HeightMap* heightmap, int interva #pragma omp for for (int i = 1; i <= num_contours; i++) { - vec_private.push_back(produce_cellmap(heightmap, heightmap->min + interval*i)); + auto points = produce_cellmap(heightmap, heightmap->min + interval*i) ; + std::vector line; + line.push_back(points.back()); + points.pop_back(); + + 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); + } + else if (next.x -1 == current_point.x) { + line.push_back(next); + points.erase(points.begin()+j); + } + else if (next.y +1 == current_point.y) { + line.push_back(next); + points.erase(points.begin()+j); + } + 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(); + } + } + } + } } #pragma omp critical + vector_contours.insert(vector_contours.end(), vec_private.begin(), vec_private.end()); } @@ -184,5 +221,5 @@ int main(int argc, const char* argv[]) auto cellmap = produce_cellmap(&map, 40); auto cellmaps = vector_cellmap(&map, 5); - //write_output_file(cellmaps, "out.geojson"); + write_output_file(cellmaps, "out.geojson"); } \ No newline at end of file