fixed some functions' arguments, inlined some other simple functions

This commit is contained in:
Phuntsok Drak-pa 2019-04-25 02:53:30 +02:00
parent 8ec3db2450
commit 0aa81fdec0
2 changed files with 49 additions and 59 deletions

View File

@ -30,13 +30,35 @@ class ImageManipulator {
int const t_width, int const t_width,
int const t_height); int const t_height);
/// \brief Copy assignment operator /**
[[nodiscard]] auto operator=(const ImageManipulator& other) * \brief Copy assignment operator
-> ImageManipulator; *
* Copy assignment operator, will copy all of the inputs members except for
* its mutex, a new one will be generated.
*
* \param[in] other Element to copy
* \return ImageManipulator
*/
[[nodiscard]] inline auto operator=(const ImageManipulator& other)
-> ImageManipulator
{
return ImageManipulator(other);
}
/// \brief Move assignment operator /**
[[nodiscard]] auto operator=(ImageManipulator&& other) noexcept * \brief Move assignment operator
-> ImageManipulator; *
* Move assignment operator, will move all of the inputs members except for
* its mutex, a new one will be generated.
*
* \param[in] other Element to move
* \return ImageManipulator
*/
[[nodiscard]] inline auto operator=(ImageManipulator&& other) noexcept
-> ImageManipulator
{
return ImageManipulator{std::move(other)};
}
/// \brief Execute the nth method on the current object /// \brief Execute the nth method on the current object
void exec_method(int const t_nb_method, void exec_method(int const t_nb_method,
@ -45,11 +67,19 @@ class ImageManipulator {
int const t_rows, int const t_rows,
int const t_submethod); int const t_submethod);
/// \brief Write the generated image to the output path /**
void write_file() const; * \brief Write the generated image to the output path
*
* Write the generated image as a file to the specified path stored in the
* object
*/
inline void write_file() const
{
cv::imwrite(output_path_, generated_image_);
}
/// \brief Returns a reference to the generated image /// \brief Returns a reference to the generated image
[[nodiscard]] auto const& get_generated_image() const noexcept [[nodiscard]] inline auto const& get_generated_image() const noexcept
{ {
return generated_image_; return generated_image_;
} }
@ -72,12 +102,12 @@ class ImageManipulator {
[[nodiscard]] auto get_controlled_square_values() const noexcept; [[nodiscard]] auto get_controlled_square_values() const noexcept;
/// \brief Generates a candidate for image generation improvement /// \brief Generates a candidate for image generation improvement
[[nodiscard]] auto create_candidate(bool const t_controlled_size) const; [[nodiscard]] auto create_candidate(bool const t_controlled_size) const;
/// \brief Generates organized views of the reference image for method 5 /// \brief Generates organized views of the reference image for method 5
[[nodiscard]] auto generate_tiles(int const t_cols, int const t_rows) const; [[nodiscard]] auto generate_tiles(int const t_cols, int const t_rows) const;
/// \brief Gets all colors from the reference image /// \brief Gets all colors from the reference image
void get_color_set(); void get_color_set();
/// \brief Threaded helper for \ref get_color_set /// \brief Threaded helper for \ref get_color_set
void threaded_get_color(int t_h); void threaded_get_color(int const t_h);
/// \brief Draw a square on an image /// \brief Draw a square on an image
void draw_square(cv::Mat& t_img, void draw_square(cv::Mat& t_img,
cv::Point const& t_top_left, cv::Point const& t_top_left,
@ -85,8 +115,8 @@ class ImageManipulator {
cv::Scalar const& t_color) const; cv::Scalar const& t_color) const;
/// \brief Update this objects generated image /// \brief Update this objects generated image
void update_gen_image(cv::Mat const& t_img, double const t_diff); void update_gen_image(cv::Mat const& t_img, double const t_diff);
/// \brief Merges tiles generated by method5 /// \brief Merges tiles generated by method5
void merge_tiles(std::vector<std::vector<ImageManipulator>> t_tiles); void merge_tiles(std::vector<std::vector<ImageManipulator>> const& t_tiles);
/// \brief First method as described in the /// \brief First method as described in the
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf) /// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
void method1(); void method1();

View File

@ -103,35 +103,6 @@ ImageManipulator::ImageManipulator(cv::Mat const& t_origin_image,
} }
} }
// operators //////////////////////////////////////////////////////////////////
/**
* Copy assignment operator, will copy all of the inputs members except for
* its mutex, a new one will be generated.
*
* \param[in] other Element to copy
* \return ImageManipulator
*/
[[nodiscard]] auto ImageManipulator::operator=(const ImageManipulator& other)
-> ImageManipulator
{
return ImageManipulator(other);
}
/**
* Move assignment operator, will move all of the inputs members except for
* its mutex, a new one will be generated.
*
* \param[in] other Element to move
* \return ImageManipulator
*/
[[nodiscard]] auto ImageManipulator::operator=(
ImageManipulator&& other) noexcept -> ImageManipulator
{
return ImageManipulator{std::move(other)};
}
// public methods ///////////////////////////////////////////////////////////// // public methods /////////////////////////////////////////////////////////////
/** /**
@ -180,15 +151,6 @@ void ImageManipulator::exec_method(int const t_nb_method,
} }
} }
/**
* Write the generated image as a file to the specified path stored in the
* object
*/
void ImageManipulator::write_file() const
{
cv::imwrite(output_path_, generated_image_);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Private // // Private //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -345,7 +307,7 @@ void ImageManipulator::get_color_set()
* colors_, then resumes the other threads. Helper function for \ref * colors_, then resumes the other threads. Helper function for \ref
* get_color_set * get_color_set
*/ */
void ImageManipulator::threaded_get_color(int t_h) void ImageManipulator::threaded_get_color(int const t_h)
{ {
if (t_h > reference_.size().height) { if (t_h > reference_.size().height) {
return; return;
@ -412,26 +374,24 @@ void ImageManipulator::update_gen_image(cv::Mat const& t_img,
* \param t_tiles Collection of tiles to be merged together * \param t_tiles Collection of tiles to be merged together
*/ */
void ImageManipulator::merge_tiles( void ImageManipulator::merge_tiles(
std::vector<std::vector<ImageManipulator>> t_tiles) std::vector<std::vector<ImageManipulator>> const& t_tiles)
{ {
std::vector<cv::Mat> columns{}; std::vector<cv::Mat> columns{};
for (auto const& col : t_tiles) { std::for_each(t_tiles.begin(), t_tiles.end(), [&columns](auto const& col) {
std::vector<cv::Mat> column_arr{}; std::vector<cv::Mat> column_arr{};
cv::Mat column_img{}; cv::Mat column_img{};
for (auto const& tile : col) { std::for_each(col.begin(), col.end(), [&column_arr](auto const& tile) {
column_arr.push_back(tile.get_generated_image()); column_arr.push_back(tile.get_generated_image());
} });
vconcat(column_arr, column_img); vconcat(column_arr, column_img);
columns.push_back(std::move(column_img)); columns.push_back(std::move(column_img));
} });
hconcat(columns, generated_image_); hconcat(columns, generated_image_);
} }
void ImageManipulator::method1() void ImageManipulator::method1()
{ {
spdlog::debug("Beginning method1, initial difference: {}", diff_); spdlog::debug("Beginning method1, initial difference: {}", diff_);
spdlog::debug("nb_total_iter: {}, nb_remaining_iter: {}", total_iterations_,
remaining_iter_);
while (remaining_iter_ > 0 && diff_ > 0.0) { while (remaining_iter_ > 0 && diff_ > 0.0) {
auto temp_image = generated_image_.clone(); auto temp_image = generated_image_.clone();
auto const [rand_x, rand_y, size] = get_square_values(); auto const [rand_x, rand_y, size] = get_square_values();