2 Commits

Author SHA1 Message Date
43f8b78830 Implemented cli 2024-05-07 13:29:49 +02:00
08255875c1 Added the argh library as a subproject 2024-05-07 11:40:33 +02:00
5 changed files with 46 additions and 14 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "extern/argh"]
path = extern/argh
url = https://github.com/adishavit/argh.git

View File

@@ -1,15 +1,22 @@
cmake_minimum_required(VERSION 3.20)
project(
contour-creator
LANGUAGES CXX)
find_package(GDAL CONFIG REQUIRED)
add_executable(${PROJECT_NAME}
src/HeightMap.cpp src/CellMap.cpp src/main.cpp
)
# Argh is a simple argrument parser
add_subdirectory(extern/argh)
target_link_libraries(${PROJECT_NAME} PRIVATE argh)
# Gdal is used for geodata IO
find_package(GDAL CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE GDAL::GDAL)
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(${PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX)
endif()
target_link_libraries(${PROJECT_NAME} GDAL::GDAL)

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

1
extern/argh vendored Submodule

Submodule extern/argh added at 431bf323ac

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";
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, 5);
write_output_file(lines, "out.geojson", &map);
auto lines = create_lines(&map, interval);
write_output_file(lines, output_file.c_str(), &map);
std::cout << "Contours written to " << output_file << " 🗺️\n";
}