mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2024-11-21 23:00:18 +00:00
Implemented cli
This commit is contained in:
parent
08255875c1
commit
43f8b78830
@ -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
|
||||
|
39
src/main.cpp
39
src/main.cpp
@ -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";
|
||||
|
||||
map.blur(0.8);
|
||||
|
||||
auto lines = create_lines(&map, 5);
|
||||
write_output_file(lines, "out.geojson", &map);
|
||||
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";
|
||||
|
||||
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";
|
||||
}
|
Loading…
Reference in New Issue
Block a user