2019-03-19 12:49:37 +00:00
|
|
|
#include "parseargs.hh"
|
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
|
|
|
|
2019-03-19 13:22:44 +00:00
|
|
|
constexpr int DEFAULT_ITERATIONS = 5000;
|
|
|
|
|
2019-03-20 11:34:46 +00:00
|
|
|
using path = std::filesystem::path;
|
|
|
|
namespace po = boost::program_options;
|
|
|
|
|
|
|
|
void processFilenames(po::variables_map const &vm, path const &t_input,
|
|
|
|
path &t_output) {
|
|
|
|
if (!vm.count("output")) {
|
|
|
|
t_output.replace_filename("output_" +
|
|
|
|
std::string{t_input.filename().string()});
|
|
|
|
} else if (!t_output.has_extension()) {
|
|
|
|
t_output.replace_extension(".png");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-27 12:33:22 +00:00
|
|
|
[[nodiscard]] std::tuple<path, path, int, int, bool> parse_args(int t_ac,
|
|
|
|
char **t_av) {
|
2019-03-19 12:49:37 +00:00
|
|
|
po::options_description desc("Allowed options");
|
2019-03-27 12:33:22 +00:00
|
|
|
desc.add_options()("help,h", "Display this help message")(
|
|
|
|
"input,i", po::value<path>(),
|
|
|
|
"Input image")("output,o", po::value<path>(),
|
|
|
|
"Image output path (default: input path + \"_output\")")(
|
|
|
|
"method,m", po::value<int>(), "Method number to be used (default: 1)")(
|
|
|
|
"iterations,n", po::value<int>(),
|
|
|
|
"Number of iterations (default: 5000)")("verbose,v", "Enables verbosity");
|
2019-03-19 12:49:37 +00:00
|
|
|
po::variables_map vm;
|
|
|
|
po::store(po::parse_command_line(t_ac, t_av, desc), vm);
|
|
|
|
po::notify(vm);
|
|
|
|
if (vm.count("help") || !vm.count("input")) {
|
|
|
|
std::cout << desc << "\n";
|
|
|
|
std::exit(1);
|
|
|
|
}
|
2019-03-20 11:34:46 +00:00
|
|
|
|
|
|
|
auto const input_path = vm["input"].as<path>();
|
|
|
|
auto output_path =
|
|
|
|
vm.count("output") ? vm["output"].as<path>() : input_path.filename();
|
|
|
|
processFilenames(vm, input_path, output_path);
|
|
|
|
|
2019-03-24 20:34:04 +00:00
|
|
|
return std::make_tuple(input_path, output_path,
|
|
|
|
vm.count("iterations") ? vm["iterations"].as<int>()
|
|
|
|
: DEFAULT_ITERATIONS,
|
|
|
|
vm.count("method") ? vm["method"].as<int>() : 1,
|
|
|
|
vm.count("verbose") ? true : false);
|
2019-03-19 12:49:37 +00:00
|
|
|
}
|