From c535eec958c8c5309775ceb91eb97d4c4b942d4a Mon Sep 17 00:00:00 2001 From: Trygve Date: Mon, 6 May 2024 11:37:10 +0200 Subject: [PATCH] Debugging without omp --- src/main.cpp | 84 +++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7c35e4c..1f7b809 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,47 +54,60 @@ std::vector> vector_cellmap(HeightMap* heightmap, int interva for (int i = 1; i <= num_contours; i++) { auto points = produce_cellmap(heightmap, heightmap->min + interval*i); - + std::vector line; + int x; + int y; 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->previous == nullptr and candidate != current->previous) { - - if (candidate->x +1 == current->x && candidate->y == current->y) { - current->next = candidate; - candidate->previous = current; + if (!candidate->allocated) { + if (candidate->x == x +1 && candidate->y == y) { + candidate->allocated = true; + x = candidate->x; + y = candidate->y; + line.push_back(*candidate); break; } - else if (candidate->x -1 == current->x && candidate->y == current->y) { - current->next = candidate; - candidate->previous = current; + else if (candidate->x == x -1&& candidate->y == y) { + x = candidate->x; + y = candidate->y; + candidate->allocated = true; + line.push_back(*candidate); break; } - else if (candidate->y +1 == current->y && candidate->x == current->x) { - current->next = candidate; - candidate->previous = current; + else if (candidate->y == y +1&& candidate->x == x) { + x = candidate->x; + y = candidate->y; + candidate->allocated = true; + line.push_back(*candidate); break; } - else if (candidate->y -1 == current->y && candidate->x == current->x) { - current->next = candidate; - candidate->previous = current; + else if (candidate->y == y -1&& candidate->x == x) { + x = candidate->x; + y = candidate->y; + candidate->allocated = true; + line.push_back(*candidate); break; } } - } - if (current->next == nullptr) + if (x == points[j].x && y == points[j].y) { - current->endpoint = true; - std::cout << "🤕";std::cout.flush(); + vector_contours.push_back(line); + std::vector line; } } //vec_private.push_back(points); - vector_contours.push_back(points); - std::cout << vector_contours.size(); + //vector_contours.push_back(points); + //std::cout << vector_contours.size(); } //#pragma omp critical @@ -187,18 +200,14 @@ void write_output_file(std::vector> all_points, const char *f feature->SetField( "Name", j ); - std::vector* points = &all_points[j]; + std::vector points = all_points[j]; - - - Point* current = &points->at(0); - int points_allocated = 0; - while (true) + for (int k = 0; k < points.size(); k++) { //int x_raw = i%width; //int y_raw = i/height; - int x_raw = current->x; - int y_raw = current->y; + int x_raw = points[k].x; + int y_raw = points[k].y; /* if (x_raw > 500 || y_raw > 400) { @@ -211,21 +220,10 @@ 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 ,y ); - current->allocated = true; - current = current->previous; + geometry->setPoint(geometry->getNumPoints(),x_raw ,y_raw ); + //current sometimes becomes random pointer????? - if (current == nullptr or current->allocated) - { - for (int k = 0; ksize(); k++) - { - if (points->at(k).endpoint and !points->at(k).allocated) - { - current = &points->at(k); - } - } - if (current == nullptr){std::cout << "🫠";std::cout.flush(); break; } - } + } if ( feature->SetGeometry(geometry) != OGRERR_NONE)