contour-creator/src/main.cpp

49 lines
1.4 KiB
C++
Raw Normal View History

2024-04-06 11:18:28 +00:00
#include "HeightMap.hh"
2024-04-11 13:23:44 +00:00
#include "CaseMap.hh"
2024-04-06 15:22:03 +00:00
#include <iostream>
2024-04-08 15:34:03 +00:00
#include <ostream>
2024-04-11 13:23:44 +00:00
#include <vector>
2024-04-11 17:30:09 +00:00
#include <cstdint>
2024-04-11 13:23:44 +00:00
#include <gdal/gdal.h>
2024-04-11 13:37:33 +00:00
#include "gdal/gdal_priv.h"
#include <gdal/gdal_frmts.h>
2024-04-11 13:23:44 +00:00
2024-04-11 16:56:44 +00:00
CaseMap produce_casemap(HeightMap* heightmap, float z)
2024-04-11 13:23:44 +00:00
{
2024-04-11 17:30:09 +00:00
uint8_t *cases = (uint8_t *) CPLMalloc(sizeof(uint8_t)*(heightmap->width-1)*(heightmap->height-1));
2024-04-11 16:56:44 +00:00
for (int i = 0; i<(heightmap->width-1)*(heightmap->height-1); i++) {
2024-04-11 14:27:03 +00:00
int y = i/(heightmap->width-1);
int x = i%(heightmap->width-1);
2024-04-11 17:30:09 +00:00
uint8_t result = (heightmap->get_pixel(x,y+1)>z) +
2024-04-11 16:56:44 +00:00
(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;
2024-04-11 14:27:03 +00:00
}
2024-04-11 16:56:44 +00:00
return CaseMap(heightmap->width-1, heightmap->height-1, cases);
2024-04-11 14:27:03 +00:00
2024-04-11 13:23:44 +00:00
}
2024-04-06 11:18:28 +00:00
int main(int argc, const char* argv[])
{
const char* filepath = argv[1];
HeightMap map(filepath);
2024-04-08 15:34:03 +00:00
std::cout << "x: " << map.width << " y: " << map.height << "\n";
std::cout << "max: " << map.max << " min: " << map.min << "\n";
2024-04-11 14:27:03 +00:00
auto casemap = produce_casemap(&map, 40.0);
2024-04-11 16:56:44 +00:00
2024-04-11 14:27:03 +00:00
for (int y = 0; y < casemap.height; y++)
2024-04-06 11:18:28 +00:00
{
2024-04-11 14:27:03 +00:00
for (int x = 0; x < casemap.width; x++)
2024-04-06 11:18:28 +00:00
{
2024-04-11 16:56:44 +00:00
if (casemap.get_case(x, y) && casemap.get_case(x, y)!=15) {
std::cout << x << ","<< y << "=" << casemap.get_case(x, y) << " ";
2024-04-11 14:27:03 +00:00
}
2024-04-06 11:18:28 +00:00
}
2024-04-11 17:30:09 +00:00
//std::cout << "\n";
2024-04-06 11:18:28 +00:00
}
}