contour-creator/src/main.cpp

48 lines
1.4 KiB
C++

#include "HeightMap.hh"
#include "CaseMap.hh"
#include <iostream>
#include <ostream>
#include <vector>
#include <gdal/gdal.h>
#include "gdal/gdal_priv.h"
#include <gdal/gdal_frmts.h>
CaseMap produce_casemap(HeightMap* heightmap, float z)
{
int *cases = (int *) CPLMalloc(sizeof(int)*(heightmap->width-1)*(heightmap->height-1));
for (int i = 0; i<(heightmap->width-1)*(heightmap->height-1); i++) {
int y = i/(heightmap->width-1);
int x = i%(heightmap->width-1);
int result = (heightmap->get_pixel(x,y+1)>z) +
(heightmap->get_pixel(x+1,y+1)>z)*2 +
(heightmap->get_pixel(x+1,y)>z)*4 +
(heightmap->get_pixel(x,y)>z)*8;
*(cases + i) = result;
}
return CaseMap(heightmap->width-1, heightmap->height-1, cases);
}
int main(int argc, const char* argv[])
{
const char* filepath = argv[1];
HeightMap map(filepath);
std::cout << "x: " << map.width << " y: " << map.height << "\n";
std::cout << "max: " << map.max << " min: " << map.min << "\n";
auto casemap = produce_casemap(&map, 40.0);
for (int y = 0; y < casemap.height; y++)
{
for (int x = 0; x < casemap.width; x++)
{
if (casemap.get_case(x, y) && casemap.get_case(x, y)!=15) {
std::cout << x << ","<< y << "=" << casemap.get_case(x, y) << " ";
}
}
std::cout << "\n";
}
}