diff --git a/build&run.sh b/build&run.sh index 1a0521d..4b6dd80 100755 --- a/build&run.sh +++ b/build&run.sh @@ -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' \ No newline at end of file +build/contour-creator --interval=1 --blur example_files/crop.tif diff --git a/src/main.cpp b/src/main.cpp index 91e78e3..510f4d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,7 @@ #include "gdal/gdal_priv.h" #include #include +#include "argh.h" std::vector produce_cellmap(HeightMap* heightmap, float z) { @@ -227,14 +228,34 @@ void write_output_file(std::vector> all_points, const char *f 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"; + argh::parser cmdl(argv); - map.blur(0.8); + if (cmdl[{ "-h", "--help" }]) + { + std::cout << "Usage:\n" + << "contour_creator [OPTIONS] \n" + << "-o; --output - File to write output to (Default: contours.geojson)\n" + << "-i; --interval - 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"; - auto lines = create_lines(&map, 5); - write_output_file(lines, "out.geojson", &map); + std::string output_file; + cmdl({"-o", "--output"}, "contours.geojson") >> output_file; + + 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"; } \ No newline at end of file