changed function signature (best practices)

This commit is contained in:
Phuntsok Drak-pa 2019-03-27 14:31:07 +01:00
parent fe530235a2
commit 99c815a561
3 changed files with 16 additions and 15 deletions

View File

@ -5,10 +5,10 @@
#include <opencv2/highgui/highgui.hpp> #include <opencv2/highgui/highgui.hpp>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
void method1(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations); void method1(cv::Mat const &, cv::Mat &, int);
void method2(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations); void method2(cv::Mat const &, cv::Mat &, int);
void method3(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations); void method3(cv::Mat const &, cv::Mat &, int);
#endif /* GENETIC_IMAGE_INCLUDE_GENIMG_METHODS_HH_ */ #endif /* GENETIC_IMAGE_INCLUDE_GENIMG_METHODS_HH_ */

View File

@ -40,7 +40,7 @@ void newSquare1(cv::Mat &t_process_img, cv::Point &&t_top_left, int t_size) {
draw_shape(t_process_img, t_top_left, t_size, randomColor(), Shapes::Square); draw_shape(t_process_img, t_top_left, t_size, randomColor(), Shapes::Square);
} }
void threadedGetColor(cv::Mat &t_reference, ColorSet &t_colors, int t_h) { void threadedGetColor(cv::Mat const &t_reference, ColorSet &t_colors, int t_h) {
if (t_h > t_reference.size().height) if (t_h > t_reference.size().height)
return; return;
for (int w = 0; w < t_reference.size().width; w += 3) { for (int w = 0; w < t_reference.size().width; w += 3) {
@ -56,7 +56,7 @@ void threadedGetColor(cv::Mat &t_reference, ColorSet &t_colors, int t_h) {
} }
} }
[[nodiscard]] ColorSet getColorSet(cv::Mat &t_reference) { [[nodiscard]] ColorSet getColorSet(cv::Mat const &t_reference) {
ColorSet res{}; ColorSet res{};
for (int h = 0; h < t_reference.size().height; h += thread_nbr) { for (int h = 0; h < t_reference.size().height; h += thread_nbr) {
std::vector<std::thread> thread_list{}; std::vector<std::thread> thread_list{};
@ -83,7 +83,7 @@ void newSquare2(cv::Mat &t_process_img, cv::Point &&t_top_left, int t_size,
} // namespace methods_private } // namespace methods_private
void method1(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations) { void method1(cv::Mat const &t_reference, cv::Mat &t_output, int t_iterations) {
auto diff = euclidian_distance(t_reference, t_output); auto diff = euclidian_distance(t_reference, t_output);
spdlog::debug("Beginning method1, initial difference: {}", diff); spdlog::debug("Beginning method1, initial difference: {}", diff);
while (t_iterations > 0 && diff >= 0) { while (t_iterations > 0 && diff >= 0) {
@ -103,7 +103,7 @@ void method1(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations) {
} }
} }
void method2(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations) { void method2(cv::Mat const &t_reference, cv::Mat &t_output, int t_iterations) {
auto diff = euclidian_distance(t_reference, t_output); auto diff = euclidian_distance(t_reference, t_output);
spdlog::debug("Beginning method2, initial difference: {}", diff); spdlog::debug("Beginning method2, initial difference: {}", diff);
spdlog::debug("Running {} threads.", thread_nbr); spdlog::debug("Running {} threads.", thread_nbr);
@ -128,7 +128,7 @@ void method2(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations) {
} }
} }
void method3(cv::Mat &t_reference, cv::Mat &t_output, int t_iterations) { void method3(cv::Mat const &t_reference, cv::Mat &t_output, int t_iterations) {
auto const init_iter = t_iterations; auto const init_iter = t_iterations;
auto diff = euclidian_distance(t_reference, t_output); auto diff = euclidian_distance(t_reference, t_output);
spdlog::debug("Beginning method2, initial difference: {}", diff); spdlog::debug("Beginning method2, initial difference: {}", diff);

View File

@ -21,13 +21,14 @@ void processFilenames(po::variables_map const &vm, path const &t_input,
[[nodiscard]] std::tuple<path, path, int, int, bool> parse_args(int t_ac, [[nodiscard]] std::tuple<path, path, int, int, bool> parse_args(int t_ac,
char **t_av) { char **t_av) {
po::options_description desc("Allowed options"); po::options_description desc("Allowed options");
desc.add_options()("help,h", "Display this help message")( desc.add_options()
"input,i", po::value<path>(), ("help,h", "Display this help message")
"Input image")("output,o", po::value<path>(), ("input,i", po::value<path>(), "Input image")
"Image output path (default: input path + \"_output\")")( ("output,o", po::value<path>(),
"method,m", po::value<int>(), "Method number to be used (default: 1)")( "Image output path (default: input path + \"_output\")")
"iterations,n", po::value<int>(), ("method,m", po::value<int>(), "Method number to be used (default: 1)")
"Number of iterations (default: 5000)")("verbose,v", "Enables verbosity"); ("iterations,n", po::value<int>(), "Number of iterations (default: 5000)")
("verbose,v", "Enables verbosity");
po::variables_map vm; po::variables_map vm;
po::store(po::parse_command_line(t_ac, t_av, desc), vm); po::store(po::parse_command_line(t_ac, t_av, desc), vm);
po::notify(vm); po::notify(vm);