From 95649f005baef3303f793d8c368d5c36b4155014 Mon Sep 17 00:00:00 2001 From: Trygve Date: Mon, 6 May 2024 23:50:11 +0200 Subject: [PATCH] ITS WORKING (somewhat) --- src/main.cpp | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1f7b809..9aa9fae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,24 +47,22 @@ 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); std::vector line; int x; int y; + int points_allocated = 0; + x = points[0].x; + y = points[0].y; + points[0].allocated = true; + line.push_back(points[0]); for (int j = 0; j < points.size(); j++){ - Point* current = &points[j]; - current->allocated=true; - line.push_back(points[j]); - x = points[j].x; - y = points[j].y; - - //std::cout << points_allocated << " " << points.size() << "\n"; for (int k = 0; k < points.size(); k++){ Point* candidate = &points[k]; if (!candidate->allocated) { @@ -73,35 +71,51 @@ std::vector> vector_cellmap(HeightMap* heightmap, int interva x = candidate->x; y = candidate->y; line.push_back(*candidate); + points_allocated++; break; } - else if (candidate->x == x -1&& candidate->y == y) { + else if (candidate->x == x -1 && candidate->y == y) { x = candidate->x; y = candidate->y; candidate->allocated = true; line.push_back(*candidate); + points_allocated++; break; } - else if (candidate->y == y +1&& candidate->x == x) { + else if (candidate->x == x && candidate->y == y + 1) { x = candidate->x; y = candidate->y; candidate->allocated = true; line.push_back(*candidate); + points_allocated++; break; } - else if (candidate->y == y -1&& candidate->x == x) { + else if (candidate->x == x && candidate->y == y - 1) { x = candidate->x; y = candidate->y; candidate->allocated = true; line.push_back(*candidate); + points_allocated++; break; } } } - if (x == points[j].x && y == points[j].y) + if (j > points_allocated) { - vector_contours.push_back(line); - std::vector line; + vec_private.push_back(line); + line.clear(); + //std::cout << points.size() << " "; + for (int k = 0; k < points.size(); k++){ + Point* candidate = &points[k]; + if (!candidate->allocated) + { + line.push_back(*candidate); + x = candidate->x; + y = candidate->y; + points_allocated++; + break; + } + } } } @@ -109,9 +123,9 @@ std::vector> vector_cellmap(HeightMap* heightmap, int interva //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; @@ -172,7 +186,7 @@ void write_output_file(std::vector> all_points, const char *f OGRLayer *poLayer; - poLayer = poDS->CreateLayer( "contours", /*&(cellmaps[0]).reference_system*/ NULL, wkbLineString, NULL ); + poLayer = poDS->CreateLayer( "contours", &heightmap->reference_system, wkbLineString, NULL ); if( poLayer == NULL ) { printf( "Layer creation failed.\n" ); @@ -220,7 +234,7 @@ void write_output_file(std::vector> all_points, const char *f //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 sometimes becomes random pointer?????