working on image eval functions

main
Brett 2024-01-27 12:28:37 -05:00
parent 99c802552e
commit badb0c2ac6
4 changed files with 85 additions and 8 deletions

View File

@ -242,6 +242,8 @@ inline static allowed_funcs<function_t> intersection_comp(const allowed_funcs<fu
return set; return set;
} }
float eval_AMF(const image& img); // distribution from normality (DFN)
float eval_DNF_SW(const image& img);
float eval_DNF_KS(const image& img);
#endif //GP_IMAGE_TEST_FUNCTIONS_H #endif //GP_IMAGE_TEST_FUNCTIONS_H

View File

@ -36,7 +36,7 @@ inline blt::area_allocator<image_data_t, 32> img_allocator;
class image class image
{ {
private: private:
std::variant<image_data_t*, blt::vec3, float> data; mutable std::variant<image_data_t*, blt::vec3, float> data;
public: public:
image() image()
{ {
@ -133,6 +133,34 @@ class image
} }
} }
[[nodiscard]] const image_data_t& getData() const
{
if (std::holds_alternative<image_data_t*>(data))
return *std::get<image_data_t*>(data);
else
{
blt::vec3 color = std::visit(blt::lambda_visitor{
[](const image_data_t*) -> blt::vec3 {
BLT_ASSERT("There has been an error in the matrix. You should not have gotten here!");
return {};
},
[](const blt::vec3& v) -> blt::vec3 {
return v;
},
[](float f) -> blt::vec3 {
return blt::vec3{f, f, f};
}
}, data);
data = img_allocator.allocate(1);
img_allocator.construct(std::get<image_data_t*>(data));
for (auto& v : *std::get<image_data_t*>(data))
v = color;
return *std::get<image_data_t*>(data);
}
}
[[nodiscard]] blt::vec3 get(blt::i32 x = 0, blt::i32 y = 0) const [[nodiscard]] blt::vec3 get(blt::i32 x = 0, blt::i32 y = 0) const
{ {
return std::visit(blt::lambda_visitor{ return std::visit(blt::lambda_visitor{

View File

@ -231,8 +231,21 @@ void f_if(image& img, float x, float y, blt::size_t argc, const image** argv, co
img.set(i3, xi, yi); img.set(i3, xi, yi);
} }
float eval_AMF(const image& img) float eval_DNF_SW(const image& img)
{ {
std::vector<float> order(width * height);
std::sort(order.begin(), order.end());
for (const auto& v : img.getData())
order.push_back(v.magnitude());
return 0; return 0;
} }
float eval_DNF_KS(const image& img)
{
return 0;
}

View File

@ -142,6 +142,7 @@ struct node
if (argc > 0) if (argc > 0)
std::cout << ") "; std::cout << ") ";
} }
public: public:
explicit node(function_t type): type(type) explicit node(function_t type): type(type)
{ {
@ -162,9 +163,12 @@ struct node
static std::random_device dev; static std::random_device dev;
static std::mt19937_64 engine{dev()}; static std::mt19937_64 engine{dev()};
std::uniform_int_distribution<int> choice(0, 1); std::uniform_int_distribution<int> choice(0, 1);
std::uniform_int_distribution<int> select(0, OPERATOR_COUNT - 1);
node* n = createNode(static_cast<function_t>(select(engine))); static auto NON_TERMINALS = intersection_comp(FUNC_ALLOW_ANY, FUNC_ALLOW_TERMINALS_SET);
std::uniform_int_distribution<int> select(0, NON_TERMINALS.size() - 1);
node* n = createNode(NON_TERMINALS[select(engine)]);
std::queue<std::pair<node*, size_t>> grow_queue; std::queue<std::pair<node*, size_t>> grow_queue;
size_t current_depth = 0; size_t current_depth = 0;
@ -293,9 +297,33 @@ void update(std::int32_t w, std::int32_t h)
root->evaluate_tree(); root->evaluate_tree();
BLT_INFO("Preprocess"); BLT_INFO("Preprocess");
// if (root->hasImage()) float mx = 0, my = 0, mz = 0;
// for (auto& v : root->getImage().getData()) float sx = 0, sy = 0, sz = 0;
// v = v.normalize(); if (root->hasImage())
{
for (auto& v : root->getImage().getData())
{
//v = v.normalize();
for (int i = 0; i < 3; i++)
v[i] = std::abs(v[i]);
mx = std::max(v.x(), mx);
my = std::max(v.y(), my);
mz = std::max(v.z(), mz);
sx = std::min(v.x(), sx);
sy = std::min(v.y(), sy);
sz = std::min(v.z(), sz);
}
for (auto& v : root->getImage().getData())
{
if (mx - sx != 0)
v[0] = (v.x() - sx) / (mx - sx);
if (my - sy != 0)
v[1] = (v.y() - sy) / (my - sy);
if (mz - sz != 0)
v[2] = (v.z() - sz) / (mz - sz);
}
}
BLT_INFO("Uploading"); BLT_INFO("Uploading");
//delete texture; //delete texture;
@ -313,6 +341,12 @@ void update(std::int32_t w, std::int32_t h)
root->printTree(); root->printTree();
} }
if (ImGui::Button("Eval"))
{
if (root && root->hasImage())
BLT_DEBUG(eval_AMF(root->getImage()));
}
auto lw = 512.0f; auto lw = 512.0f;
auto lh = 512.0f; auto lh = 512.0f;
//renderer_2d.drawRectangle(blt::vec4{0.5, 0.0, 1.0, 1.0}, //renderer_2d.drawRectangle(blt::vec4{0.5, 0.0, 1.0, 1.0},