Implemented cli

This commit is contained in:
Trygve 2024-05-07 13:29:49 +02:00
parent 08255875c1
commit 43f8b78830
2 changed files with 30 additions and 9 deletions

View File

@ -3,4 +3,4 @@ rm -rf build
mkdir build
cmake -DCMAKE_BUILD_TYPE=Debug -B build
cmake --build build --parallel
build/contour-creator 'example_files/crop.tif'
build/contour-creator --interval=1 --blur example_files/crop.tif

View File

@ -12,6 +12,7 @@
#include "gdal/gdal_priv.h"
#include <gdal/gdal_frmts.h>
#include <omp.h>
#include "argh.h"
std::vector<Point> produce_cellmap(HeightMap* heightmap, float z)
{
@ -227,14 +228,34 @@ void write_output_file(std::vector<std::vector<Point>> all_points, const char *f
int main(int argc, const char* argv[])
{
const char* filepath = argv[1];
HeightMap map(filepath);
argh::parser cmdl(argv);
std::cout << "x: " << map.width << " y: " << map.height << "\n";
std::cout << "max: " << map.max << " min: " << map.min << "\n";
if (cmdl[{ "-h", "--help" }])
{
std::cout << "Usage:\n"
<< "contour_creator [OPTIONS] <input_file>\n"
<< "-o; --output <FILENAME.geojson> - File to write output to (Default: contours.geojson)\n"
<< "-i; --interval <int> - Set the interval between contours (Default: 5)\n"
<< "-b; --blur - Blur the image\n"
<< "--stats - Print statistical information about the heightmap\n";
exit(0);
}
int interval;
cmdl({"-i", "--interval"}, 5) >> interval;
if (interval <= 0)
std::cerr << "Interval must be valid positive integer!" << "\n";
map.blur(0.8);
std::string output_file;
cmdl({"-o", "--output"}, "contours.geojson") >> output_file;
auto lines = create_lines(&map, 5);
write_output_file(lines, "out.geojson", &map);
std::string input_file;
cmdl(1) >> input_file;
HeightMap map(input_file.c_str());
if (cmdl[{"-b", "--blur"}])
map.blur(0.8);
auto lines = create_lines(&map, interval);
write_output_file(lines, output_file.c_str(), &map);
std::cout << "Contours written to " << output_file << " 🗺️\n";
}