This commit is contained in:
Trygve 2024-05-07 10:34:29 +02:00
parent 93fcbc6a39
commit df7cac1095
2 changed files with 3 additions and 41 deletions

View File

@ -43,15 +43,10 @@ class Point
int x;
int y;
int mscase;
Point * next;
Point * previous;
bool endpoint = false;
bool allocated = false;
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,16 +5,13 @@
#include <gdal/ogr_feature.h>
#include <gdal/ogr_geometry.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <string>
#include <vector>
#include <cstdint>
#include <gdal/gdal.h>
#include "gdal/gdal_priv.h"
#include <gdal/gdal_frmts.h>
#include <omp.h>
#include <fstream>
std::vector<Point> produce_cellmap(HeightMap* heightmap, float z)
{
@ -30,22 +27,15 @@ std::vector<Point> produce_cellmap(HeightMap* heightmap, float z)
(heightmap->get_pixel(x,y+1)>z)*8;
if (result != 0 and result != 15 ) {
points.push_back(Point(x, y, result));
};
}
return points;
}
std::vector<std::vector<Point>> vector_cellmap(HeightMap* heightmap, int interval)
std::vector<std::vector<Point>> create_lines(HeightMap* heightmap, int interval)
{
int num_contours = (heightmap->max - heightmap->min)/interval;
std::vector<std::vector<Point>> vector_contours;
omp_set_num_threads(12);
#pragma omp parallel
{
@ -117,11 +107,7 @@ std::vector<std::vector<Point>> vector_cellmap(HeightMap* heightmap, int interva
}
}
}
}
//vec_private.push_back(points);
//vector_contours.push_back(points);
//std::cout << vector_contours.size();
}
#pragma omp critical
@ -213,31 +199,15 @@ void write_output_file(std::vector<std::vector<Point>> all_points, const char *f
feature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
feature->SetField( "Name", j );
std::vector<Point> points = all_points[j];
for (int k = 0; k < points.size(); k++)
{
//int x_raw = i%width;
//int y_raw = i/height;
int x_raw = points[k].x;
int y_raw = points[k].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 ,y );
//current sometimes becomes random pointer?????
}
if ( feature->SetGeometry(geometry) != OGRERR_NONE)
@ -253,7 +223,6 @@ void write_output_file(std::vector<std::vector<Point>> all_points, const char *f
}
OGRFeature::DestroyFeature( feature );
}
GDALClose( poDS );
}
@ -267,8 +236,6 @@ int main(int argc, const char* argv[])
map.blur(0.8);
auto cellmap = produce_cellmap(&map, 40);
auto cellmaps = vector_cellmap(&map, 5);
write_output_file(cellmaps, "out.geojson", &map);
auto lines = create_lines(&map, 5);
write_output_file(lines, "out.geojson", &map);
}