From c75e6a92ea84a9cb41f10d3b0f9656bcdec404a6 Mon Sep 17 00:00:00 2001 From: Phuntsok Drak-pa Date: Sat, 27 Apr 2019 18:04:32 +0200 Subject: [PATCH] some bugs fixed --- include/genimg/methods.hh | 1 - include/genimg/shapes.hh | 5 +++-- src/main.cc | 2 +- src/methods.cc | 8 ++++---- src/parseargs.cc | 42 +++++++++++++++++++-------------------- src/shapes.cc | 19 ++++++++---------- 6 files changed, 37 insertions(+), 40 deletions(-) diff --git a/include/genimg/methods.hh b/include/genimg/methods.hh index ef73521..28f9241 100644 --- a/include/genimg/methods.hh +++ b/include/genimg/methods.hh @@ -2,7 +2,6 @@ #include "shapes.hh" -#include #include #include diff --git a/include/genimg/shapes.hh b/include/genimg/shapes.hh index ce526b3..dafe65a 100644 --- a/include/genimg/shapes.hh +++ b/include/genimg/shapes.hh @@ -3,6 +3,7 @@ #include #include #include +#include class Shape { @@ -31,8 +32,8 @@ public: Shape &operator=(Shape &&other) noexcept = delete; /// \brief Generates a shape's points - void operator()(cv::Point &&t_max_pos, int const t_max_size, - int const t_min_size = 0) noexcept; + void update(cv::Point &&t_max_pos, int const t_max_size, + int const t_min_size = 0) noexcept; [[nodiscard]] auto get_points() const noexcept -> std::array const & diff --git a/src/main.cc b/src/main.cc index 4f26ca8..e8d58c1 100644 --- a/src/main.cc +++ b/src/main.cc @@ -8,6 +8,7 @@ int main(int ac, char **av) { std::srand(std::time(nullptr)); + spdlog::set_level(spdlog::level::debug); auto const arguments = parse_args(ac, av); spdlog::set_level(arguments.verbose ? spdlog::level::debug : spdlog::level::info); @@ -15,7 +16,6 @@ int main(int ac, char **av) spdlog::debug("Input file:\t{}", arguments.input_path.native()); spdlog::debug("Output file:\t{}", arguments.output_path.native()); spdlog::debug("Iterations:\t{}", arguments.iterations); - ImageManipulator image_process{arguments.input_path, arguments.output_path, arguments.iterations, arguments.shape}; image_process.exec_method(arguments.method, arguments.controlled_size, diff --git a/src/methods.cc b/src/methods.cc index e292752..a59e659 100644 --- a/src/methods.cc +++ b/src/methods.cc @@ -202,8 +202,8 @@ ImageManipulator::euclidian_distance(cv::Mat const &t_img) const noexcept void ImageManipulator::create_shape() noexcept { - shape_(cv::Point{reference_.size().width, reference_.size().height}, - std::min(reference_.size().width, reference_.size().height)); + shape_.update(cv::Point{reference_.size().width, reference_.size().height}, + std::min(reference_.size().width, reference_.size().height)); } void ImageManipulator::create_controlled_shape() noexcept @@ -216,8 +216,8 @@ void ImageManipulator::create_controlled_shape() noexcept / 2.0f) * coef); int const max_size = min_size * 2 + 1; - shape_(cv::Point{reference_.size().width, reference_.size().height}, max_size, - min_size); + shape_.update(cv::Point{reference_.size().width, reference_.size().height}, + max_size, min_size); } /** diff --git a/src/parseargs.cc b/src/parseargs.cc index 9bacda2..5e3dde5 100644 --- a/src/parseargs.cc +++ b/src/parseargs.cc @@ -45,26 +45,25 @@ void processFilenames(po::variables_map const &t_vm, path const &t_input, { ParsedArgs ret{}; 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: \"output_\" + input path)") - ("iterations,n", po::value(), "Number of iterations (default: 2000)") - ("method,m", po::value(), "Method number to be used (default: 1)") - ("form,f", po::value(), "Select shape (1:square, 2:triangle)") - ("cols,c", po::value(), - "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(), - "For method 5 only, number of rows the reference image should be " - "divided into. (default: 1)") - ("submethod,S", po::value(), - "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"); + desc.add_options()("help,h", "Display this help message")( + "input,i", po::value(), + "Input image")("output,o", po::value(), + "Image output path (default: \"output_\" + input path)")( + "iterations,n", po::value(), "Number of iterations (default: 2000)")( + "method,m", po::value(), "Method number to be used (default: 1)")( + "form,f", po::value(), "Select shape (1:square, 2:triangle)")( + "cols,c", po::value(), + "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(), + "For method 5 only, number of rows the reference image should be " + "divided into. (default: 1)")( + "submethod,S", po::value(), + "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"); po::variables_map vm; po::store(po::parse_command_line(t_ac, t_av, desc), vm); po::notify(vm); @@ -82,10 +81,11 @@ void processFilenames(po::variables_map const &t_vm, path const &t_input, ret.output_path = output_path; ret.iterations = vm.count("iterations") ? vm["iterations"].as() : DEFAULT_ITERATIONS; + spdlog::debug("arg: {}", vm.count("form") ? vm["form"].as() : 1); ret.method = vm.count("method") ? vm["method"].as() : 1; switch (vm.count("form") ? vm["form"].as() : 1) { case 2: ret.shape = Shape::ShapeType::Triangle; break; - case 1: [[fallthrough]]; + case 1: ret.shape = Shape::ShapeType::Square; break; default: ret.shape = Shape::ShapeType::Square; break; } diff --git a/src/shapes.cc b/src/shapes.cc index 7660679..39b235e 100644 --- a/src/shapes.cc +++ b/src/shapes.cc @@ -8,11 +8,8 @@ using point_arr = std::array; Shape::Shape(Shape::ShapeType const t_type) : type_{t_type} { switch (t_type) { - case ShapeType::Triangle: { - nb_points_ = 3; - break; - } - case ShapeType::Square: [[fallthrough]]; + case ShapeType::Triangle: nb_points_ = 3; break; + case ShapeType::Square: nb_points_ = 4; break; default: nb_points_ = 4; break; } } @@ -31,8 +28,8 @@ Shape::Shape(Shape &&other) noexcept * for * \return Array of points describing the shape */ -void Shape::operator()(cv::Point &&t_max_pos, int const t_max_size, - int const t_min_size) noexcept +void Shape::update(cv::Point &&t_max_pos, int const t_max_size, + int const t_min_size) noexcept { int const size = (rand() % (t_max_size - t_min_size)) + t_min_size; cv::Point const top_left @@ -47,11 +44,11 @@ void Shape::operator()(cv::Point &&t_max_pos, int const t_max_size, void Shape::create_triangle_points(cv::Point const &t_top_left, int const t_size) noexcept { - bool top_left = rand() % 1 == 0; - points_ = { + bool top_left = rand() % 2 == 0; + points_ = { cv::Point{top_left ? t_top_left.x : t_top_left.x + t_size, t_top_left.y}, cv::Point{top_left ? t_top_left.x + t_size : t_top_left.x, - t_top_left.y + t_size}, + t_top_left.y + rand() % t_size}, cv::Point{t_top_left.x + rand() % t_size, t_top_left.y + t_size}, cv::Point{0, 0}}; } @@ -61,6 +58,6 @@ void Shape::create_square_points(cv::Point const &t_top_left, { points_ = {cv::Point{t_top_left.x, t_top_left.y}, cv::Point{t_top_left.x, t_top_left.y + t_size}, - cv::Point{t_top_left.x + t_size, t_top_left.y}, + cv::Point{t_top_left.x + t_size, t_top_left.y + t_size}, cv::Point{t_top_left.x + t_size, t_top_left.y}}; }