tried to implement finding contour lines

This commit is contained in:
esther 2024-04-30 15:07:04 +02:00
parent d046e18c43
commit 228945a767

View File

@ -36,6 +36,8 @@ std::vector<Point> produce_cellmap(HeightMap* heightmap, float z)
} }
std::vector<std::vector<Point>> vector_cellmap(HeightMap* heightmap, int interval) std::vector<std::vector<Point>> vector_cellmap(HeightMap* heightmap, int interval)
{ {
int num_contours = (heightmap->max - heightmap->min)/interval; int num_contours = (heightmap->max - heightmap->min)/interval;
@ -48,9 +50,44 @@ std::vector<std::vector<Point>> vector_cellmap(HeightMap* heightmap, int interva
#pragma omp for #pragma omp for
for (int i = 1; i <= num_contours; i++) 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<Point> 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<Point> line;
line.push_back(points.back());
points.pop_back();
}
}
}
}
} }
#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());
} }
@ -184,5 +221,5 @@ int main(int argc, const char* argv[])
auto cellmap = produce_cellmap(&map, 40); auto cellmap = produce_cellmap(&map, 40);
auto cellmaps = vector_cellmap(&map, 5); auto cellmaps = vector_cellmap(&map, 5);
//write_output_file(cellmaps, "out.geojson"); write_output_file(cellmaps, "out.geojson");
} }