From 4f709d3b07dfbb620b89216f71329936a0d938d5 Mon Sep 17 00:00:00 2001 From: Trygve Date: Sun, 5 May 2024 16:53:00 +0200 Subject: [PATCH] Use linked list to store the order of the points --- src/main.cpp | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e598baf..7c35e4c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,12 +7,14 @@ #include #include #include +#include #include #include #include #include "gdal/gdal_priv.h" #include #include +#include std::vector produce_cellmap(HeightMap* heightmap, float z) { @@ -45,10 +47,10 @@ std::vector> vector_cellmap(HeightMap* heightmap, int interva std::vector> vector_contours; omp_set_num_threads(12); - #pragma omp parallel + //#pragma omp parallel { std::vector> vec_private; - #pragma omp for + //#pragma omp for for (int i = 1; i <= num_contours; i++) { auto points = produce_cellmap(heightmap, heightmap->min + interval*i); @@ -86,15 +88,17 @@ std::vector> vector_cellmap(HeightMap* heightmap, int interva if (current->next == nullptr) { current->endpoint = true; - std::cout << "🤕"; + std::cout << "🤕";std::cout.flush(); } } - vec_private.push_back(points); + //vec_private.push_back(points); + vector_contours.push_back(points); + std::cout << vector_contours.size(); } - #pragma omp critical + //#pragma omp critical - vector_contours.insert(vector_contours.end(), vec_private.begin(), vec_private.end()); + //vector_contours.insert(vector_contours.end(), vec_private.begin(), vec_private.end()); } return vector_contours; @@ -183,33 +187,44 @@ void write_output_file(std::vector> all_points, const char *f feature->SetField( "Name", j ); - std::vector points = all_points[j]; - Point* current = &points[50]; + std::vector* points = &all_points[j]; + + + + Point* current = &points->at(0); + int points_allocated = 0; while (true) { //int x_raw = i%width; //int y_raw = i/height; int x_raw = current->x; int y_raw = current->y; + /* + if (x_raw > 500 || y_raw > 400) + { + std::cout << "🤯";std::cout.flush(); + continue; + } + */ auto [x, y] = local_to_projected(heightmap->geotransform, x_raw, y_raw); //auto [x_bl, y_bl, x_tr, y_tr] = marching_squares_lookup(*(cellmap->cells + i) ); //std::cout << x_raw << ", " << y_raw << " ";std::cout.flush(); //geometry->setPoint( geometry->getNumPoints(), x+x_tr*0.25, y+y_tr*0.25 ); //geometry->setPoint( geometry->getNumPoints(), x+x_bl*0.25, y+y_bl*0.25 ); - geometry->setPoint(geometry->getNumPoints(),x_raw ,y_raw ); + geometry->setPoint(geometry->getNumPoints(),x ,y ); current->allocated = true; current = current->previous; //current sometimes becomes random pointer????? - if (current == nullptr) + if (current == nullptr or current->allocated) { - for (int k = 0; ksize(); k++) { - if (points[k].endpoint and !points[k].allocated) + if (points->at(k).endpoint and !points->at(k).allocated) { - current = &points[k]; + current = &points->at(k); } } - if (current == nullptr){std::cout << "🫠"; break; } + if (current == nullptr){std::cout << "🫠";std::cout.flush(); break; } } } @@ -225,7 +240,6 @@ void write_output_file(std::vector> all_points, const char *f exit( 1 ); } OGRFeature::DestroyFeature( feature ); - break; } GDALClose( poDS );