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_height);
/// \brief Copy assignment operator
[[nodiscard]] auto operator=(const ImageManipulator& other)
-> ImageManipulator;
/**
* \brief Copy assignment operator
*
* 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
-> ImageManipulator;
/**
* \brief Move assignment operator
*
* 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
void exec_method(int const t_nb_method,
@ -45,11 +67,19 @@ class ImageManipulator {
int const t_rows,
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
[[nodiscard]] auto const& get_generated_image() const noexcept
[[nodiscard]] inline auto const& get_generated_image() const noexcept
{
return generated_image_;
}
@ -77,7 +107,7 @@ class ImageManipulator {
/// \brief Gets all colors from the reference image
void 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
void draw_square(cv::Mat& t_img,
cv::Point const& t_top_left,
@ -86,7 +116,7 @@ class ImageManipulator {
/// \brief Update this objects generated image
void update_gen_image(cv::Mat const& t_img, double const t_diff);
/// \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
/// [report](https://labs.phundrak.fr/phundrak/genetic-images/blob/master/report/report.pdf)
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 /////////////////////////////////////////////////////////////
/**
@ -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 //
///////////////////////////////////////////////////////////////////////////////
@ -345,7 +307,7 @@ void ImageManipulator::get_color_set()
* colors_, then resumes the other threads. Helper function for \ref
* 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) {
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
*/
void ImageManipulator::merge_tiles(
std::vector<std::vector<ImageManipulator>> t_tiles)
std::vector<std::vector<ImageManipulator>> const& t_tiles)
{
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{};
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());
}
});
vconcat(column_arr, column_img);
columns.push_back(std::move(column_img));
}
});
hconcat(columns, generated_image_);
}
void ImageManipulator::method1()
{
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) {
auto temp_image = generated_image_.clone();
auto const [rand_x, rand_y, size] = get_square_values();