2019-03-19 12:49:37 +00:00
|
|
|
|
#include "parseargs.hh"
|
|
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
2019-04-09 00:20:33 +00:00
|
|
|
|
constexpr int DEFAULT_ITERATIONS = 2000;
|
2019-03-19 13:22:44 +00:00
|
|
|
|
|
2019-03-20 11:34:46 +00:00
|
|
|
|
using path = std::filesystem::path;
|
|
|
|
|
namespace po = boost::program_options;
|
|
|
|
|
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* \brief Ensures correct output path
|
|
|
|
|
*
|
|
|
|
|
* Checks if an output file exists, and if yes if it has an extension. In case
|
|
|
|
|
* it doesn’t exist, `output_` is appended at the beginning of the input
|
|
|
|
|
* filename. If the output path does not have an extension, the type `.png` is
|
|
|
|
|
* appended at the end of the path.
|
|
|
|
|
*
|
|
|
|
|
* \param[in] t_vm Arguments passed to the program
|
|
|
|
|
* \param[out] t_input Input path
|
|
|
|
|
* \param[out] t_output Output path
|
|
|
|
|
*/
|
|
|
|
|
void processFilenames(po::variables_map const& t_vm,
|
2019-03-28 11:26:05 +00:00
|
|
|
|
path const& t_input,
|
|
|
|
|
path& t_output)
|
|
|
|
|
{
|
2019-04-14 01:58:49 +00:00
|
|
|
|
if (!t_vm.count("output")) {
|
2019-03-28 11:26:05 +00:00
|
|
|
|
t_output.replace_filename("output_"
|
|
|
|
|
+ std::string{t_input.filename().string()});
|
|
|
|
|
}
|
|
|
|
|
else if (!t_output.has_extension()) {
|
|
|
|
|
t_output.replace_extension(".png");
|
|
|
|
|
}
|
2019-03-20 11:34:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-14 01:58:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* Parses the arguments given to the program, formats them and returns them as
|
|
|
|
|
* a tuple. If `-h` or `--help` or a malformed argument is passed, then the
|
|
|
|
|
* list of arguments and their comment will be displayed, and the program will
|
|
|
|
|
* exit.
|
|
|
|
|
*
|
|
|
|
|
* \param[in] t_ac Number of arguments passed to the program
|
|
|
|
|
* \param[in] t_av Arguments passed to the program
|
|
|
|
|
* \return Tuple of path, path, int, int, int, int, int, bool and bool
|
|
|
|
|
*/
|
2019-04-27 13:45:39 +00:00
|
|
|
|
[[nodiscard]] auto parse_args(int t_ac, char** t_av) -> ParsedArgs
|
2019-03-28 11:26:05 +00:00
|
|
|
|
{
|
2019-04-27 13:45:39 +00:00
|
|
|
|
ParsedArgs ret{};
|
2019-03-28 11:26:05 +00:00
|
|
|
|
po::options_description desc("Allowed options");
|
2019-04-27 13:45:39 +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: \"output_\" + input path)")(
|
|
|
|
|
"iterations,n", po::value<int>(), "Number of iterations (default: 2000)")(
|
|
|
|
|
"method,m", po::value<int>(), "Method number to be used (default: 1)")(
|
|
|
|
|
"form,f", po::value<int>(), "Select shape (1:square, 2:triangle)")(
|
|
|
|
|
"cols,c", po::value<int>(),
|
|
|
|
|
"For method 5 only, number of columns the reference image should be "
|
|
|
|
|
"divided into. If the value is equal to 0, then it will be assumed "
|
|
|
|
|
"there will be as many rows as there are collumns. (default: 0)")(
|
|
|
|
|
"rows,r", po::value<int>(),
|
|
|
|
|
"For method 5 only, number of rows the reference image should be "
|
|
|
|
|
"divided into. (default: 1)")(
|
|
|
|
|
"submethod,S", po::value<int>(),
|
|
|
|
|
"Sub-method that will be used to generate the individual tiles from "
|
|
|
|
|
"method 5. (default: 1)")("size,s",
|
|
|
|
|
"Enables controlled size of the random shapes")(
|
|
|
|
|
"verbose,v", "Enables verbosity");
|
2019-03-28 11:26:05 +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";
|
2019-04-13 12:48:21 +00:00
|
|
|
|
std::exit(!vm.count("help"));
|
2019-03-28 11:26:05 +00:00
|
|
|
|
}
|
2019-03-20 11:34:46 +00:00
|
|
|
|
|
2019-03-28 11:26:05 +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-20 11:34:46 +00:00
|
|
|
|
|
2019-04-27 13:45:39 +00:00
|
|
|
|
ret.input_path = input_path;
|
|
|
|
|
ret.output_path = output_path;
|
|
|
|
|
ret.iterations = vm.count("iterations") ? vm["iterations"].as<int>()
|
|
|
|
|
: DEFAULT_ITERATIONS;
|
|
|
|
|
ret.method = vm.count("method") ? vm["method"].as<int>() : 1;
|
|
|
|
|
switch (vm.count("form") ? vm["form"].as<int>() : 1) {
|
|
|
|
|
case 2:
|
|
|
|
|
ret.shape= Shape::ShapeType::Triangle;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
[[fallthrough]];
|
|
|
|
|
default:
|
|
|
|
|
ret.shape = Shape::ShapeType::Square;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret.cols = vm.count("cols") ? vm["cols"].as<int>() : 0;
|
|
|
|
|
ret.rows = vm.count("rows") ? vm["rows"].as<int>() : 1;
|
|
|
|
|
ret.submethod = vm.count("submethod") ? vm["submethod"].as<int>() : 1;
|
|
|
|
|
ret.controlled_size = vm.count("size");
|
|
|
|
|
ret.verbose = vm.count("verbose");
|
|
|
|
|
return ret;
|
2019-03-19 12:49:37 +00:00
|
|
|
|
}
|