From 912eafb9dde1fef2fcb7bd1964f83c334f4110ee Mon Sep 17 00:00:00 2001 From: Phuntsok Drak-pa Date: Thu, 28 Mar 2019 12:26:05 +0100 Subject: [PATCH] New coding style --- .clang-format | 32 +++++ include/genimg/common.hh | 8 +- include/genimg/drawing.hh | 7 +- include/genimg/methods.hh | 8 +- include/genimg/parseargs.hh | 6 +- src/common.cc | 48 +++---- src/drawing.cc | 50 +++---- src/main.cc | 63 ++++----- src/methods.cc | 265 +++++++++++++++++++----------------- src/parseargs.cc | 71 +++++----- 10 files changed, 308 insertions(+), 250 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..6e68f2a --- /dev/null +++ b/.clang-format @@ -0,0 +1,32 @@ +--- +BasedOnStyle: Chromium +AlignEscapedNewlinesLeft: 'true' +AlignTrailingComments: 'true' +AllowShortBlocksOnASingleLine: 'true' +AllowShortIfStatementsOnASingleLine: 'false' +AllowShortLoopsOnASingleLine: 'false' +AlwaysBreakBeforeMultilineStrings: 'true' +AlwaysBreakTemplateDeclarations: 'true' +BreakBeforeBinaryOperators: 'true' +BreakBeforeBraces: Stroustrup +BreakBeforeTernaryOperators: 'true' +BreakConstructorInitializersBeforeComma: 'false' +ColumnLimit: '80' +ConstructorInitializerAllOnOneLineOrOnePerLine: 'true' +Cpp11BracedListStyle: 'true' +IndentCaseLabels: 'true' +KeepEmptyLinesAtTheStartOfBlocks: 'false' +Language: Cpp +MaxEmptyLinesToKeep: '2' +PointerAlignment: Left +SpaceBeforeAssignmentOperators: 'true' +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: 'false' +SpacesInAngles: 'false' +SpacesInCStyleCastParentheses: 'false' +SpacesInParentheses: 'false' +Standard: Cpp11 +TabWidth: '2' +UseTab: ForIndentation + +... diff --git a/include/genimg/common.hh b/include/genimg/common.hh index 049e9cf..7da98ee 100644 --- a/include/genimg/common.hh +++ b/include/genimg/common.hh @@ -1,15 +1,15 @@ #ifndef GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_ #define GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_ +#include #include #include -#include #include #include -[[nodiscard]] std::pair -init_image(std::string const &) noexcept; +[[nodiscard]] std::pair init_image( + std::string const&) noexcept; -[[nodiscard]] double euclidian_distance(cv::Mat const &, cv::Mat const &); +[[nodiscard]] double euclidian_distance(cv::Mat const&, cv::Mat const&); #endif /* GENETIC_IMAGE_INCLUDE_GENIMG_COMMON_HH_ */ diff --git a/include/genimg/drawing.hh b/include/genimg/drawing.hh index db0c615..e386268 100644 --- a/include/genimg/drawing.hh +++ b/include/genimg/drawing.hh @@ -6,7 +6,10 @@ enum class Shapes { Square, Circle }; -void draw_shape(cv::Mat &, cv::Point const &, int const, cv::Scalar const &, - Shapes const &); +void draw_shape(cv::Mat&, + cv::Point const&, + int const, + cv::Scalar const&, + Shapes const&); #endif /* GENETIC_IMAGE_INCLUDE_GENIMG_DRAWING_HH_ */ diff --git a/include/genimg/methods.hh b/include/genimg/methods.hh index edd095b..392ac36 100644 --- a/include/genimg/methods.hh +++ b/include/genimg/methods.hh @@ -1,14 +1,14 @@ #ifndef GENETIC_IMAGE_INCLUDE_GENIMG_METHODS_HH_ #define GENETIC_IMAGE_INCLUDE_GENIMG_METHODS_HH_ +#include #include #include -#include -void method1(cv::Mat const &, cv::Mat &, int); +void method1(cv::Mat const&, cv::Mat&, int); -void method2(cv::Mat const &, cv::Mat &, int); +void method2(cv::Mat const&, cv::Mat&, int); -void method3(cv::Mat const &, cv::Mat &, int); +void method3(cv::Mat const&, cv::Mat&, int); #endif /* GENETIC_IMAGE_INCLUDE_GENIMG_METHODS_HH_ */ diff --git a/include/genimg/parseargs.hh b/include/genimg/parseargs.hh index 575f9a3..6494b1b 100644 --- a/include/genimg/parseargs.hh +++ b/include/genimg/parseargs.hh @@ -4,8 +4,8 @@ #include #include -[[nodiscard]] std::tuple -parse_args(int, char **); +[[nodiscard]] std:: + tuple + parse_args(int, char**); #endif /* GENETIC_IMAGE_INCLUDE_GENIMG_PARSEARGS_HH_ */ diff --git a/src/common.cc b/src/common.cc index 1c32777..0f4518f 100644 --- a/src/common.cc +++ b/src/common.cc @@ -3,29 +3,31 @@ #include #include -[[nodiscard]] std::pair -init_image(std::string const &t_input_file) noexcept { - cv::Mat input_image = cv::imread(t_input_file, cv::IMREAD_COLOR); - if (!input_image.data) { - spdlog::critical("Could not open or find image!\n"); - exit(-1); - } - spdlog::debug("Image loaded!"); - spdlog::debug("Width:\t\t{}", input_image.size().width); - spdlog::debug("Height:\t{}", input_image.size().height); - cv::Mat process_image(input_image.size().height, input_image.size().width, - CV_8UC3, cv::Scalar(0, 0, 0)); - return std::make_pair(std::move(input_image), process_image); +[[nodiscard]] std::pair init_image( + std::string const& t_input_file) noexcept +{ + cv::Mat input_image = cv::imread(t_input_file, cv::IMREAD_COLOR); + if (!input_image.data) { + spdlog::critical("Could not open or find image!\n"); + exit(-1); + } + spdlog::debug("Image loaded!"); + spdlog::debug("Width:\t\t{}", input_image.size().width); + spdlog::debug("Height:\t{}", input_image.size().height); + cv::Mat process_image(input_image.size().height, input_image.size().width, + CV_8UC3, cv::Scalar(0, 0, 0)); + return std::make_pair(std::move(input_image), process_image); } -[[nodiscard]] double euclidian_distance(cv::Mat const &t_img1, - cv::Mat const &t_img2) { - double euclidian = 0.0; - for (auto itr1 = t_img1.begin(), itr2 = t_img2.begin(); - itr1 != t_img1.end() && itr2 != t_img2.end(); - ++itr1, ++itr2) { - euclidian += std::pow(*itr1 - *itr2, 2); - } - euclidian = std::sqrt(euclidian); - return euclidian; +[[nodiscard]] double euclidian_distance(cv::Mat const& t_img1, + cv::Mat const& t_img2) +{ + double euclidian = 0.0; + for (auto itr1 = t_img1.begin(), itr2 = t_img2.begin(); + itr1 != t_img1.end() && itr2 != t_img2.end(); + ++itr1, ++itr2) { + euclidian += std::pow(*itr1 - *itr2, 2); + } + euclidian = std::sqrt(euclidian); + return euclidian; } diff --git a/src/drawing.cc b/src/drawing.cc index 0cd8e90..f9ca480 100644 --- a/src/drawing.cc +++ b/src/drawing.cc @@ -1,31 +1,35 @@ #include "drawing.hh" +#include #include #include #include -#include -void drawSquare(cv::Mat &t_img, cv::Point const &t_top_left, int const t_size, - cv::Scalar const &t_color) { - auto points = std::make_unique(4); - points.get()[0] = t_top_left; - points.get()[1] = cv::Point{t_top_left.x, t_top_left.y + t_size}; - points.get()[2] = cv::Point{t_top_left.x + t_size, t_top_left.y + t_size}; - points.get()[3] = cv::Point{t_top_left.x + t_size, t_top_left.y}; - // spdlog::debug("Size:{} 1[{},{}] 2[{},{}] 3[{},{}] 4[{},{}]", t_size, - // points[0].x, points[0].y, points[1].x, points[1].y, points[2].x, - // points[2].y, points[3].x, points[3].y); - fillConvexPoly(t_img, points.get(), 4, t_color); +void drawSquare(cv::Mat& t_img, + cv::Point const& t_top_left, + int const t_size, + cv::Scalar const& t_color) +{ + auto points = std::make_unique(4); + points.get()[0] = t_top_left; + points.get()[1] = cv::Point{t_top_left.x, t_top_left.y + t_size}; + points.get()[2] = cv::Point{t_top_left.x + t_size, t_top_left.y + t_size}; + points.get()[3] = cv::Point{t_top_left.x + t_size, t_top_left.y}; + fillConvexPoly(t_img, points.get(), 4, t_color); } -void draw_shape(cv::Mat &t_img, cv::Point const &t_top_left, int const t_size, - cv::Scalar const &t_color, Shapes const &t_shape) { - switch (t_shape) { - case Shapes::Square: { - drawSquare(t_img, t_top_left, t_size, t_color); - break; - } - default: - spdlog::error("Shape does not exist. Aborting..."); - std::exit(1); - } +void draw_shape(cv::Mat& t_img, + cv::Point const& t_top_left, + int const t_size, + cv::Scalar const& t_color, + Shapes const& t_shape) +{ + switch (t_shape) { + case Shapes::Square: { + drawSquare(t_img, t_top_left, t_size, t_color); + break; + } + default: + spdlog::error("Shape does not exist. Aborting..."); + std::exit(1); + } } diff --git a/src/main.cc b/src/main.cc index 0a8603c..81e45a5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,38 +1,39 @@ -#include "common.hh" -#include "methods.hh" -#include "parseargs.hh" #include #include #include +#include "common.hh" +#include "methods.hh" +#include "parseargs.hh" -int main(int ac, char **av) { - std::srand(std::time(nullptr)); - auto const [input_file, output_file, iterations, method, verbose] = - parse_args(ac, av); - spdlog::set_level(verbose ? spdlog::level::debug : spdlog::level::info); - spdlog::debug("Input file:\t{}", input_file.native()); - spdlog::debug("Output file:\t{}", output_file.native()); - spdlog::debug("Iterations:\t{}", iterations); - auto [input_image, process_image] = init_image(input_file.native()); +int main(int ac, char** av) +{ + std::srand(std::time(nullptr)); + auto const [input_file, output_file, iterations, method, verbose] + = parse_args(ac, av); + spdlog::set_level(verbose ? spdlog::level::debug : spdlog::level::info); + spdlog::debug("Input file:\t{}", input_file.native()); + spdlog::debug("Output file:\t{}", output_file.native()); + spdlog::debug("Iterations:\t{}", iterations); + auto [input_image, process_image] = init_image(input_file.native()); - switch (method) { - case 1: { - method1(input_image, process_image, iterations); - break; - } - case 2: { - method2(input_image, process_image, iterations); - break; - } - case 3: { - method3(input_image, process_image, iterations); - break; - } - default: - spdlog::error("Requested method {} is not implemented."); - std::exit(-1); - } + switch (method) { + case 1: { + method1(input_image, process_image, iterations); + break; + } + case 2: { + method2(input_image, process_image, iterations); + break; + } + case 3: { + method3(input_image, process_image, iterations); + break; + } + default: + spdlog::error("Requested method {} is not implemented."); + std::exit(-1); + } - cv::imwrite(output_file.native(), process_image); - return 0; + cv::imwrite(output_file.native(), process_image); + return 0; } diff --git a/src/methods.cc b/src/methods.cc index 8ae79a9..727dd7c 100644 --- a/src/methods.cc +++ b/src/methods.cc @@ -1,11 +1,11 @@ #include "methods.hh" -#include "common.hh" -#include "drawing.hh" #include #include #include #include #include +#include "common.hh" +#include "drawing.hh" auto const thread_nbr = std::thread::hardware_concurrency(); std::mutex numbers_mutex; @@ -17,148 +17,161 @@ using std::rand; namespace methods_private { -void adjustSize(cv::Mat const &t_process_img, cv::Point &t_top_left, int size) { - int const height = t_process_img.size().height; - int const width = t_process_img.size().width; - int const shape_total_width = t_top_left.x + size; - int const shape_total_height = t_top_left.y + size; - if (int const diff = shape_total_height - height; diff > 0) { - t_top_left.y -= diff + 1; - } - if (int const diff = shape_total_width - width; diff > 0) { - t_top_left.x -= diff + 1; - } +void adjustSize(cv::Mat const& t_process_img, cv::Point& t_top_left, int size) +{ + int const height = t_process_img.size().height; + int const width = t_process_img.size().width; + int const shape_total_width = t_top_left.x + size; + int const shape_total_height = t_top_left.y + size; + if (int const diff = shape_total_height - height; diff > 0) { + t_top_left.y -= diff + 1; + } + if (int const diff = shape_total_width - width; diff > 0) { + t_top_left.x -= diff + 1; + } } -[[nodiscard]] cv::Scalar randomColor() { - static std::uniform_int_distribution<> dis(0, 255); - return cv::Scalar(rand() % 255, rand() % 255, rand() % 255); +[[nodiscard]] cv::Scalar randomColor() +{ + static std::uniform_int_distribution<> dis(0, 255); + return cv::Scalar(rand() % 255, rand() % 255, rand() % 255); } -void newSquare1(cv::Mat &t_process_img, cv::Point &&t_top_left, int t_size) { - adjustSize(t_process_img, t_top_left, t_size); - draw_shape(t_process_img, t_top_left, t_size, randomColor(), Shapes::Square); +void newSquare1(cv::Mat& t_process_img, cv::Point&& t_top_left, int t_size) +{ + adjustSize(t_process_img, t_top_left, t_size); + draw_shape(t_process_img, t_top_left, t_size, randomColor(), Shapes::Square); } -void threadedGetColor(cv::Mat const &t_reference, ColorSet &t_colors, int t_h) { - if (t_h > t_reference.size().height) - return; - for (int w = 0; w < t_reference.size().width; w += 3) { - Color temp = {t_reference.at(t_h, w), - t_reference.at(t_h, w + 1), - t_reference.at(t_h, w + 2)}; - auto pos = std::find(std::begin(t_colors), std::end(t_colors), temp); - if (pos == std::end(t_colors)) { - numbers_mutex.lock(); - t_colors.push_back(temp); - numbers_mutex.unlock(); - } - } +void threadedGetColor(cv::Mat const& t_reference, ColorSet& t_colors, int t_h) +{ + if (t_h > t_reference.size().height) + return; + for (int w = 0; w < t_reference.size().width; w += 3) { + Color temp + = {t_reference.at(t_h, w), t_reference.at(t_h, w + 1), + t_reference.at(t_h, w + 2)}; + auto pos = std::find(std::begin(t_colors), std::end(t_colors), temp); + if (pos == std::end(t_colors)) { + numbers_mutex.lock(); + t_colors.push_back(temp); + numbers_mutex.unlock(); + } + } } -[[nodiscard]] ColorSet getColorSet(cv::Mat const &t_reference) { - ColorSet res{}; - for (int h = 0; h < t_reference.size().height; h += thread_nbr) { - std::vector thread_list{}; - for (int i = 0; i < thread_nbr; ++i) { - thread_list.push_back(std::thread(methods_private::threadedGetColor, - std::ref(t_reference), std::ref(res), - h + i)); - } - for (auto &th : thread_list) - th.join(); - } - res.shrink_to_fit(); - return res; +[[nodiscard]] ColorSet getColorSet(cv::Mat const& t_reference) +{ + ColorSet res{}; + for (int h = 0; h < t_reference.size().height; h += thread_nbr) { + std::vector thread_list{}; + for (int i = 0; i < thread_nbr; ++i) { + thread_list.push_back(std::thread(methods_private::threadedGetColor, + std::ref(t_reference), std::ref(res), + h + i)); + } + for (auto& th : thread_list) + th.join(); + } + res.shrink_to_fit(); + return res; } -void newSquare2(cv::Mat &t_process_img, cv::Point &&t_top_left, int t_size, - Color const &t_color) { - draw_shape(t_process_img, t_top_left, t_size, - cv::Scalar{static_cast(t_color[0]), - static_cast(t_color[1]), - static_cast(t_color[2])}, - Shapes::Square); +void newSquare2(cv::Mat& t_process_img, + cv::Point&& t_top_left, + int t_size, + Color const& t_color) +{ + draw_shape(t_process_img, t_top_left, t_size, + cv::Scalar{static_cast(t_color[0]), + static_cast(t_color[1]), + static_cast(t_color[2])}, + Shapes::Square); } -} // namespace methods_private +} // namespace methods_private -void method1(cv::Mat const &t_reference, cv::Mat &t_output, int t_iterations) { - auto diff = euclidian_distance(t_reference, t_output); - spdlog::debug("Beginning method1, initial difference: {}", diff); - while (t_iterations > 0 && diff >= 0) { - auto temp_image = t_output.clone(); - int const rand_x = rand() % temp_image.size().width; - int const rand_y = rand() % temp_image.size().height; - int const size = rand() % std::min(t_reference.size().width - rand_x, - t_reference.size().height - rand_y); - methods_private::newSquare1(temp_image, cv::Point{rand_x, rand_y}, size); - if (auto const new_diff = euclidian_distance(t_reference, temp_image); - new_diff < diff) { - diff = new_diff; - temp_image.copyTo(t_output); - --t_iterations; - spdlog::debug("iteration:{} diff:{}", t_iterations, diff); - } - } +void method1(cv::Mat const& t_reference, cv::Mat& t_output, int t_iterations) +{ + auto diff = euclidian_distance(t_reference, t_output); + spdlog::debug("Beginning method1, initial difference: {}", diff); + while (t_iterations > 0 && diff >= 0) { + auto temp_image = t_output.clone(); + int const rand_x = rand() % temp_image.size().width; + int const rand_y = rand() % temp_image.size().height; + int const size = rand() + % std::min(t_reference.size().width - rand_x, + t_reference.size().height - rand_y); + methods_private::newSquare1(temp_image, cv::Point{rand_x, rand_y}, size); + if (auto const new_diff = euclidian_distance(t_reference, temp_image); + new_diff < diff) { + diff = new_diff; + temp_image.copyTo(t_output); + --t_iterations; + spdlog::debug("iteration:{} diff:{}", t_iterations, diff); + } + } } -void method2(cv::Mat const &t_reference, cv::Mat &t_output, int t_iterations) { - auto diff = euclidian_distance(t_reference, t_output); - spdlog::debug("Beginning method2, initial difference: {}", diff); - spdlog::debug("Running {} threads.", thread_nbr); - auto const colors = methods_private::getColorSet(t_reference); - spdlog::debug("{} colors detected.", colors.size()); +void method2(cv::Mat const& t_reference, cv::Mat& t_output, int t_iterations) +{ + auto diff = euclidian_distance(t_reference, t_output); + spdlog::debug("Beginning method2, initial difference: {}", diff); + spdlog::debug("Running {} threads.", thread_nbr); + auto const colors = methods_private::getColorSet(t_reference); + spdlog::debug("{} colors detected.", colors.size()); - while (t_iterations > 0) { - auto temp_image = t_output.clone(); - int const rand_x = rand() % temp_image.size().width; - int const rand_y = rand() % temp_image.size().height; - int const size = rand() % std::min(t_reference.size().width - rand_x, - t_reference.size().height - rand_y); - methods_private::newSquare2(temp_image, cv::Point{rand_x, rand_y}, size, - colors[rand() % colors.size()]); - if (auto new_diff = euclidian_distance(t_reference, temp_image); - new_diff < diff) { - diff = new_diff; - temp_image.copyTo(t_output); - --t_iterations; - spdlog::debug("iteration:{} diff:{}", t_iterations, diff); - } - } + while (t_iterations > 0) { + auto temp_image = t_output.clone(); + int const rand_x = rand() % temp_image.size().width; + int const rand_y = rand() % temp_image.size().height; + int const size = rand() + % std::min(t_reference.size().width - rand_x, + t_reference.size().height - rand_y); + methods_private::newSquare2(temp_image, cv::Point{rand_x, rand_y}, size, + colors[rand() % colors.size()]); + if (auto new_diff = euclidian_distance(t_reference, temp_image); + new_diff < diff) { + diff = new_diff; + temp_image.copyTo(t_output); + --t_iterations; + spdlog::debug("iteration:{} diff:{}", t_iterations, diff); + } + } } -void method3(cv::Mat const &t_reference, cv::Mat &t_output, int t_iterations) { - auto const init_iter = t_iterations; - auto diff = euclidian_distance(t_reference, t_output); - spdlog::debug("Beginning method2, initial difference: {}", diff); - spdlog::debug("Running {} threads.", thread_nbr); - auto const colors = methods_private::getColorSet(t_reference); - spdlog::debug("{} colors detected.", colors.size()); +void method3(cv::Mat const& t_reference, cv::Mat& t_output, int t_iterations) +{ + auto const init_iter = t_iterations; + auto diff = euclidian_distance(t_reference, t_output); + spdlog::debug("Beginning method2, initial difference: {}", diff); + spdlog::debug("Running {} threads.", thread_nbr); + auto const colors = methods_private::getColorSet(t_reference); + spdlog::debug("{} colors detected.", colors.size()); - while (t_iterations > 0) { - auto temp_image = t_output.clone(); - int const rand_x = rand() % temp_image.size().width; - int const rand_y = rand() % temp_image.size().height; - float const coef = - static_cast(t_iterations) / static_cast(init_iter); - int const min_size = static_cast( - (static_cast( - std::min(t_reference.size().width, t_reference.size().height)) / - 2.0f) * - coef); - int const max_size = min_size * 2 + 1; - int const size = rand() % (max_size - min_size) + min_size; + while (t_iterations > 0) { + auto temp_image = t_output.clone(); + int const rand_x = rand() % temp_image.size().width; + int const rand_y = rand() % temp_image.size().height; + float const coef + = static_cast(t_iterations) / static_cast(init_iter); + int const min_size = static_cast( + (static_cast( + std::min(t_reference.size().width, t_reference.size().height)) + / 2.0f) + * coef); + int const max_size = min_size * 2 + 1; + int const size = rand() % (max_size - min_size) + min_size; - methods_private::newSquare2(temp_image, cv::Point{rand_x, rand_y}, size, - colors[rand() % colors.size()]); - if (auto new_diff = euclidian_distance(t_reference, temp_image); - new_diff < diff) { - diff = new_diff; - temp_image.copyTo(t_output); - spdlog::debug("iteration:{} diff:{} size: {} coef:{} min:{} max:{}", - t_iterations, diff, size, coef, min_size, max_size); - --t_iterations; - } - } + methods_private::newSquare2(temp_image, cv::Point{rand_x, rand_y}, size, + colors[rand() % colors.size()]); + if (auto new_diff = euclidian_distance(t_reference, temp_image); + new_diff < diff) { + diff = new_diff; + temp_image.copyTo(t_output); + spdlog::debug("iteration:{} diff:{} size: {} coef:{} min:{} max:{}", + t_iterations, diff, size, coef, min_size, max_size); + --t_iterations; + } + } } diff --git a/src/parseargs.cc b/src/parseargs.cc index dfb9720..67d44d5 100644 --- a/src/parseargs.cc +++ b/src/parseargs.cc @@ -8,43 +8,46 @@ constexpr int DEFAULT_ITERATIONS = 5000; 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"); - } +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"); + } } [[nodiscard]] std::tuple parse_args(int t_ac, - char **t_av) { - po::options_description desc("Allowed options"); - desc.add_options() - ("help,h", "Display this help message") - ("input,i", po::value(), "Input image") - ("output,o", po::value(), - "Image output path (default: input path + \"_output\")") - ("method,m", po::value(), "Method number to be used (default: 1)") - ("iterations,n", po::value(), "Number of iterations (default: 5000)") - ("verbose,v", "Enables verbosity"); - 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); - } + char** t_av) +{ + po::options_description desc("Allowed options"); + desc.add_options()("help,h", "Display this help message")( + "input,i", po::value(), "Input image")( + "output,o", po::value(), + "Image output path (default: input path + \"_output\")")( + "method,m", po::value(), "Method number to be used (default: 1)")( + "iterations,n", po::value(), "Number of iterations (default: 5000)")( + "verbose,v", "Enables verbosity"); + 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); + } - auto const input_path = vm["input"].as(); - auto output_path = - vm.count("output") ? vm["output"].as() : input_path.filename(); - processFilenames(vm, input_path, output_path); + auto const input_path = vm["input"].as(); + auto output_path + = vm.count("output") ? vm["output"].as() : input_path.filename(); + processFilenames(vm, input_path, output_path); - return std::make_tuple(input_path, output_path, - vm.count("iterations") ? vm["iterations"].as() - : DEFAULT_ITERATIONS, - vm.count("method") ? vm["method"].as() : 1, - vm.count("verbose") ? true : false); + return std::make_tuple( + input_path, output_path, + vm.count("iterations") ? vm["iterations"].as() : DEFAULT_ITERATIONS, + vm.count("method") ? vm["method"].as() : 1, + vm.count("verbose") ? true : false); }