mirror of
https://gitlab.com/Trygve/contour-creator.git
synced 2026-03-14 16:04:04 +00:00
Compare commits
2 Commits
Statistics
...
cli-argume
| Author | SHA1 | Date | |
|---|---|---|---|
| 43f8b78830 | |||
| 08255875c1 |
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "extern/argh"]
|
||||
path = extern/argh
|
||||
url = https://github.com/adishavit/argh.git
|
||||
@@ -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)
|
||||
@@ -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
1
extern/argh
vendored
Submodule
Submodule extern/argh added at 431bf323ac
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";
|
||||
}
|
||||
Reference in New Issue
Block a user