diff --git a/include/functions.h b/include/functions.h index 0b0151d..4820c60 100644 --- a/include/functions.h +++ b/include/functions.h @@ -242,6 +242,8 @@ inline static allowed_funcs intersection_comp(const allowed_funcs img_allocator; class image { private: - std::variant data; + mutable std::variant data; public: image() { @@ -133,6 +133,34 @@ class image } } + [[nodiscard]] const image_data_t& getData() const + { + if (std::holds_alternative(data)) + return *std::get(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(data)); + + for (auto& v : *std::get(data)) + v = color; + return *std::get(data); + } + } + [[nodiscard]] blt::vec3 get(blt::i32 x = 0, blt::i32 y = 0) const { return std::visit(blt::lambda_visitor{ diff --git a/src/functions.cpp b/src/functions.cpp index 037cc6e..23b38cb 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -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); } -float eval_AMF(const image& img) +float eval_DNF_SW(const image& img) { + std::vector order(width * height); + std::sort(order.begin(), order.end()); + + for (const auto& v : img.getData()) + order.push_back(v.magnitude()); + + return 0; } + +float eval_DNF_KS(const image& img) +{ + return 0; +} + diff --git a/src/main.cpp b/src/main.cpp index f08e7a4..6388862 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -142,6 +142,7 @@ struct node if (argc > 0) std::cout << ") "; } + public: explicit node(function_t type): type(type) { @@ -162,9 +163,12 @@ struct node static std::random_device dev; static std::mt19937_64 engine{dev()}; std::uniform_int_distribution choice(0, 1); - std::uniform_int_distribution select(0, OPERATOR_COUNT - 1); - node* n = createNode(static_cast(select(engine))); + static auto NON_TERMINALS = intersection_comp(FUNC_ALLOW_ANY, FUNC_ALLOW_TERMINALS_SET); + + std::uniform_int_distribution select(0, NON_TERMINALS.size() - 1); + + node* n = createNode(NON_TERMINALS[select(engine)]); std::queue> grow_queue; size_t current_depth = 0; @@ -293,9 +297,33 @@ void update(std::int32_t w, std::int32_t h) root->evaluate_tree(); BLT_INFO("Preprocess"); -// if (root->hasImage()) -// for (auto& v : root->getImage().getData()) -// v = v.normalize(); + float mx = 0, my = 0, mz = 0; + float sx = 0, sy = 0, sz = 0; + 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"); //delete texture; @@ -313,6 +341,12 @@ void update(std::int32_t w, std::int32_t h) root->printTree(); } + if (ImGui::Button("Eval")) + { + if (root && root->hasImage()) + BLT_DEBUG(eval_AMF(root->getImage())); + } + auto lw = 512.0f; auto lh = 512.0f; //renderer_2d.drawRectangle(blt::vec4{0.5, 0.0, 1.0, 1.0},