mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2024-12-04 21:10:17 +00:00
Compare commits
3 Commits
29a7ddb083
...
d046e18c43
Author | SHA1 | Date | |
---|---|---|---|
|
d046e18c43 | ||
|
33dd409c43 | ||
|
5cd5627bb7 |
@ -36,3 +36,17 @@ class CellMap
|
|||||||
CellMap(int width, int height, uint8_t* cells, OGRSpatialReference reference_system, double* geotransform);
|
CellMap(int width, int height, uint8_t* cells, OGRSpatialReference reference_system, double* geotransform);
|
||||||
int get_cell(int x,int y);
|
int get_cell(int x,int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Point
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int mscase;
|
||||||
|
Point(int x, int y, int mscase){
|
||||||
|
this -> x = x;
|
||||||
|
this -> y = y;
|
||||||
|
this -> mscase = mscase;
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
18
src/main.cpp
18
src/main.cpp
@ -13,10 +13,11 @@
|
|||||||
#include <gdal/gdal_frmts.h>
|
#include <gdal/gdal_frmts.h>
|
||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
|
|
||||||
CellMap produce_cellmap(HeightMap* heightmap, float z)
|
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);
|
||||||
uint8_t *cells = (uint8_t *) CPLMalloc(sizeof(uint8_t)*length);
|
uint8_t *cells = (uint8_t *) CPLMalloc(sizeof(uint8_t)*length);
|
||||||
|
std::vector<Point> points;
|
||||||
for (int i = 0; i<length; i++) {
|
for (int i = 0; i<length; i++) {
|
||||||
int y = i/(heightmap->width-1);
|
int y = i/(heightmap->width-1);
|
||||||
int x = i%(heightmap->width-1);
|
int x = i%(heightmap->width-1);
|
||||||
@ -24,23 +25,26 @@ CellMap produce_cellmap(HeightMap* heightmap, float z)
|
|||||||
(heightmap->get_pixel(x+1,y)>z)*2 +
|
(heightmap->get_pixel(x+1,y)>z)*2 +
|
||||||
(heightmap->get_pixel(x+1,y+1)>z)*4 +
|
(heightmap->get_pixel(x+1,y+1)>z)*4 +
|
||||||
(heightmap->get_pixel(x,y+1)>z)*8;
|
(heightmap->get_pixel(x,y+1)>z)*8;
|
||||||
*(cells + i) = result;
|
if (result != 0 and result != 15 ) {
|
||||||
|
points.push_back(Point(x, y, result));
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return CellMap(heightmap->width-1, heightmap->height-1, cells, heightmap->reference_system, heightmap->geotransform);
|
return points;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CellMap> 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;
|
||||||
std::vector<CellMap> vector_contours;
|
std::vector<std::vector<Point>> vector_contours;
|
||||||
omp_set_num_threads(12);
|
omp_set_num_threads(12);
|
||||||
|
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
{
|
{
|
||||||
std::vector<CellMap> vec_private;
|
std::vector<std::vector<Point>> vec_private;
|
||||||
#pragma omp for
|
#pragma omp for
|
||||||
for (int i = 1; i <= num_contours; i++)
|
for (int i = 1; i <= num_contours; i++)
|
||||||
{
|
{
|
||||||
@ -180,5 +184,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");
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user