improved vector_cellmap function

This commit is contained in:
esther 2024-05-02 21:02:48 +02:00
parent 0188b9e29d
commit 77467594bd
2 changed files with 24 additions and 30 deletions

View File

@ -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;
};
};

View File

@ -5,6 +5,7 @@
#include <gdal/ogr_feature.h>
#include <gdal/ogr_geometry.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <vector>
#include <cstdint>
@ -15,9 +16,9 @@
std::vector<Point> 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<Point> points;
std::vector<Point> points; // Initiating a vector of points
for (int i = 0; i<length; i++) {
int y = i/(heightmap->width-1);
int x = i%(heightmap->width-1);
@ -50,38 +51,28 @@ std::vector<std::vector<Point>> 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<Point> 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<Point> line;
line.push_back(points.back());
points.pop_back();
else if (candidate.y -1 == current.x) {
current.next = &candidate;
}
}
}
}