clang format update

parent bc9dcf41
This diff is collapsed.
#pragma once
#include <filesystem>
#include "shapes.hh"
#include <filesystem>
struct ParsedArgs {
std::filesystem::path input_path;
std::filesystem::path output_path;
std::filesystem::path input_path;
std::filesystem::path output_path;
Shape::ShapeType shape;
int iterations;
int method;
int cols;
int rows;
int submethod;
bool controlled_size;
bool verbose;
int iterations;
int method;
int cols;
int rows;
int submethod;
bool controlled_size;
bool verbose;
};
/// \brief Parses the arguments passed to the program
[[nodiscard]] auto parse_args(int, char**) -> ParsedArgs;
[[nodiscard]] auto parse_args(int, char **) -> ParsedArgs;
......@@ -4,60 +4,62 @@
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
class Shape {
public:
static constexpr int MAX_POINTS{4};
enum class ShapeType { Square, Triangle };
/// \brief Default constructor
Shape() = delete;
Shape(Shape::ShapeType const t_type);
/// \brief Copy constructor
Shape(const Shape& other) = default;
/// \brief Move constructor
Shape(Shape&& other) noexcept;
/// \brief Destructor
virtual ~Shape() noexcept = default;
/// \brief Copy assignment operator
Shape& operator=(const Shape& other) = delete;
/// \brief Move assignment operator
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;
[[nodiscard]] auto get_points() const noexcept
-> std::array<cv::Point, Shape::MAX_POINTS> const&
{
return points_;
}
/// \brief Returns the type of shape described by the object
[[nodiscard]] auto get_type() const noexcept -> ShapeType const&
{
return type_;
}
[[nodiscard]] auto get_nb_points() const noexcept { return nb_points_; }
protected:
private:
void create_square_points(cv::Point const& t_top_left,
int const t_size) noexcept;
void create_triangle_points(cv::Point const& t_top_left,
int const t_size) noexcept;
ShapeType const type_{ShapeType::Square};
std::array<cv::Point, Shape::MAX_POINTS> points_{
cv::Point{0, 0}, cv::Point{0, 0}, cv::Point{0, 0}, cv::Point{0, 0}};
int nb_points_{Shape::MAX_POINTS};
class Shape
{
public:
static constexpr int MAX_POINTS{4};
enum class ShapeType { Square, Triangle };
/// \brief Default constructor
Shape() = delete;
Shape(Shape::ShapeType const t_type);
/// \brief Copy constructor
Shape(const Shape &other) = default;
/// \brief Move constructor
Shape(Shape &&other) noexcept;
/// \brief Destructor
virtual ~Shape() noexcept = default;
/// \brief Copy assignment operator
Shape &operator=(const Shape &other) = delete;
/// \brief Move assignment operator
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;
[[nodiscard]] auto get_points() const noexcept
-> std::array<cv::Point, Shape::MAX_POINTS> const &
{
return points_;
}
/// \brief Returns the type of shape described by the object
[[nodiscard]] auto get_type() const noexcept -> ShapeType const &
{
return type_;
}
[[nodiscard]] auto get_nb_points() const noexcept
{
return nb_points_;
}
protected:
private:
void create_square_points(cv::Point const &t_top_left,
int const t_size) noexcept;
void create_triangle_points(cv::Point const &t_top_left,
int const t_size) noexcept;
ShapeType const type_{ShapeType::Square};
std::array<cv::Point, Shape::MAX_POINTS> points_{
cv::Point{0, 0}, cv::Point{0, 0}, cv::Point{0, 0}, cv::Point{0, 0}};
int nb_points_{Shape::MAX_POINTS};
};
#include "methods.hh"
#include "parseargs.hh"
#include <cstdlib>
#include <ctime>
#include <iostream>
int main(int ac, char** av)
int main(int ac, char **av)
{
std::srand(std::time(nullptr));
auto const arguments = parse_args(ac, av);
spdlog::set_level(arguments.verbose ? spdlog::level::debug
: spdlog::level::info);
spdlog::set_pattern("[thread %t] %+");
spdlog::debug("Input file:\t{}", arguments.input_path.native());
spdlog::debug("Output file:\t{}", arguments.output_path.native());
spdlog::debug("Iterations:\t{}", arguments.iterations);
std::srand(std::time(nullptr));
auto const arguments = parse_args(ac, av);
spdlog::set_level(arguments.verbose ? spdlog::level::debug
: spdlog::level::info);
spdlog::set_pattern("[thread %t] %+");
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,
arguments.cols, arguments.rows,
arguments.submethod);
image_process.write_file();
ImageManipulator image_process{arguments.input_path, arguments.output_path,
arguments.iterations, arguments.shape};
image_process.exec_method(arguments.method, arguments.controlled_size,
arguments.cols, arguments.rows,
arguments.submethod);
image_process.write_file();
}
This diff is collapsed.
#include "parseargs.hh"
#include <boost/program_options.hpp>
#include <iostream>
constexpr int DEFAULT_ITERATIONS = 2000;
using path = std::filesystem::path;
using path = std::filesystem::path;
namespace po = boost::program_options;
/**
......@@ -19,17 +20,15 @@ namespace po = boost::program_options;
* \param[out] t_input Input path
* \param[out] t_output Output path
*/
void processFilenames(po::variables_map const& t_vm,
path const& t_input,
path& t_output)
void processFilenames(po::variables_map const &t_vm, path const &t_input,
path &t_output)
{
if (!t_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");
}
if (!t_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");
}
}
/**
......@@ -42,62 +41,58 @@ void processFilenames(po::variables_map const& t_vm,
* \param[in] t_av Arguments passed to the program
* \return Tuple of path, path, int, int, int, int, int, bool and bool
*/
[[nodiscard]] auto parse_args(int t_ac, char** t_av) -> ParsedArgs
[[nodiscard]] auto parse_args(int t_ac, char **t_av) -> ParsedArgs
{
ParsedArgs ret{};
po::options_description desc("Allowed options");
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");
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(!vm.count("help"));
}
ParsedArgs ret{};
po::options_description desc("Allowed options");
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");
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(!vm.count("help"));
}
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);
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);
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.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;
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;
}
#include "shapes.hh"
#include <cmath>
#include <utility>
......@@ -6,22 +7,18 @@ using point_arr = std::array<cv::Point, 4>;
Shape::Shape(Shape::ShapeType const t_type) : type_{t_type}
{
switch (t_type) {
case ShapeType::Triangle: {
nb_points_ = 3;
break;
}
case ShapeType::Square:
[[fallthrough]];
default:
nb_points_ = 4;
break;
}
switch (t_type) {
case ShapeType::Triangle: {
nb_points_ = 3;
break;
}
case ShapeType::Square: [[fallthrough]];
default: nb_points_ = 4; break;
}
}
Shape::Shape(Shape&& other) noexcept
: type_{std::move(other.type_)},
points_{std::move(other.points_)},
Shape::Shape(Shape &&other) noexcept
: type_{std::move(other.type_)}, points_{std::move(other.points_)},
nb_points_{std::move(other.nb_points_)}
{
}
......@@ -34,39 +31,36 @@ 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,
void Shape::operator()(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
= {rand() % (t_max_pos.x - size), rand() % (t_max_pos.y - size)};
if (type_ == ShapeType::Triangle) {
create_triangle_points(top_left, size);
}
else { // ShapeType::Square
create_square_points(top_left, size);
}
int const size = (rand() % (t_max_size - t_min_size)) + t_min_size;
cv::Point const top_left
= {rand() % (t_max_pos.x - size), rand() % (t_max_pos.y - size)};
if (type_ == ShapeType::Triangle) {
create_triangle_points(top_left, size);
} else { // ShapeType::Square
create_square_points(top_left, size);
}
}
void Shape::create_triangle_points(cv::Point const& t_top_left,
void Shape::create_triangle_points(cv::Point const &t_top_left,
int const t_size) noexcept
{
bool top_left = rand() % 1 == 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},
cv::Point{t_top_left.x + rand() % t_size, t_top_left.y + t_size},
cv::Point{0, 0}};
bool top_left = rand() % 1 == 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},
cv::Point{t_top_left.x + rand() % t_size, t_top_left.y + t_size},
cv::Point{0, 0}};
}
void Shape::create_square_points(cv::Point const& t_top_left,
void Shape::create_square_points(cv::Point const &t_top_left,
int const t_size) noexcept
{
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}};
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}};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment