Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generation matrix and image #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 51 additions & 10 deletions generating_data/headers/generating_data.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,57 @@
#ifndef _DATA_RENDER_
#define _DATA_RENDER_
#ifndef _GENERATING_DATA_
#define _GENERATING_DATA_

#include <ctime>
#include <random>
#include <limits>

#include "gen_rand_data.hpp"
#include "structer.hpp"

namespace gen_matr_type {
template <typename T>
using num_lim = std::numeric_limits<T>;

namespace data_render {
template <typename T>
void get_random(T& source, int size, int mmax = 256) {
srand(time(0));
void fill(Mtrx<T>& matrix, const double& sparsity = 1.0,
const T& min = num_lim<T>::min(), const T& max = num_lim<T>::max()) {
if (matrix.empty()) return;

gen_rand_data::Generator<T> gen(min, max);

std::mt19937_64 genSparsity{std::random_device{}()};
std::uniform_real_distribution<double> distSparsity(0.0, 1.0);

for (size_t i = 0; i < matrix.height; ++i)
for (size_t j = 0; j < matrix.width; ++j) {
if (sparsity >= distSparsity(genSparsity)) do {
matrix(i, j) = gen();
} while (matrix(i, j) == static_cast<T>(0));

else
matrix(i, j) = static_cast<T>(0);
}
}

template <layout Layout>
void fill(Image<Layout>& image, const double& sparsity = 1.0,
const uint8_t& min = num_lim<uint8_t>::min(),
const uint8_t& max = num_lim<uint8_t>::max()) {
if (image.empty()) return;

gen_rand_data::Generator<uint8_t> gen(num_lim<uint8_t>::min(),
num_lim<uint8_t>::max());

std::mt19937_64 genSparsity{std::random_device{}()};
std::uniform_real_distribution<double> distSparsity(0.0, 1.0);

for (size_t i = 0; i < image.height; ++i)
for (size_t j = 0; j < image.width; ++j) {
if (sparsity >= distSparsity(genSparsity))
image(i, j) = Color<Layout>(gen(), gen(), gen(), gen());

for (int i = 0; i < size; ++i) source[i] = (unsigned char)(rand() % mmax);
else
image(i, j) = Color<Layout>(0, 0, 0, 0);
}
}
} // namespace data_render
} // namespace gen_matr_type

#endif // _DATA_RENDER_
#endif // _GENERATING_DATA_
1 change: 1 addition & 0 deletions generating_data/headers/structer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Mtrx {
Mtrx(const Mtrx& mtrx_m); // copy constructor
Mtrx(Mtrx&& mtrx_m);
ValType* DData() { return data; }
bool empty() const noexcept { return data == nullptr; }

~Mtrx() { delete[] data; } // destructor

Expand Down