Skip to content

Commit

Permalink
Add zeroed edges node
Browse files Browse the repository at this point in the history
  • Loading branch information
otto-link committed Sep 30, 2023
1 parent 5dfcaea commit 1882942
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 9 deletions.
16 changes: 15 additions & 1 deletion include/hesiod/control_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ static const std::map<std::string, std::string> category_mapping = {
{"WaveSine", "Primitive/Function"},
{"White", "Primitive/Random"},
{"WhiteDensityMap", "Primitive/Random"},
{"Worley", "Primitive/Coherent Noise"}};
{"Worley", "Primitive/Coherent Noise"},
{"ZeroedEdges", "Math/Boundaries"}};

//----------------------------------------
// Generic nodes
Expand Down Expand Up @@ -1233,4 +1234,17 @@ class Worley : public Primitive
int seed = DEFAULT_SEED;
};

class ZeroedEdges : public gnode::Node
{
public:
ZeroedEdges(std::string id);

void update_inner_bindings();

void compute();

protected:
hmap::HeightMap value_out = hmap::HeightMap();
};

} // namespace hesiod::cnode
11 changes: 11 additions & 0 deletions include/hesiod/view_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,17 @@ class ViewWorley : public ViewNode, public hesiod::cnode::Worley
bool link_kxy = true;
};

class ViewZeroedEdges : public ViewNode, public hesiod::cnode::ZeroedEdges
{
public:
ViewZeroedEdges(std::string id);

bool render_settings();

void serialize_save(cereal::JSONOutputArchive &ar);
void serialize_load(cereal::JSONInputArchive &ar);
};

// // HELPERS

void img_to_texture(std::vector<uint8_t> img,
Expand Down
62 changes: 62 additions & 0 deletions src/nodes/control_node/zeroed_edges.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General
* Public License. The full license is in the file LICENSE, distributed with
* this software. */
#include "macrologger.h"

#include "hesiod/control_node.hpp"

namespace hesiod::cnode
{

ZeroedEdges::ZeroedEdges(std::string id) : gnode::Node(id)
{
this->node_type = "ZeroedEdges";
this->category = category_mapping.at(this->node_type);

this->add_port(gnode::Port("input", gnode::direction::in, dtype::dHeightMap));
this->add_port(gnode::Port("dr",
gnode::direction::in,
dtype::dHeightMap,
gnode::optional::yes));

this->add_port(
gnode::Port("output", gnode::direction::out, dtype::dHeightMap));
this->update_inner_bindings();
}

void ZeroedEdges::update_inner_bindings()
{
LOG_DEBUG("inner bindings [%s]", this->id.c_str());
this->set_p_data("output", (void *)&(this->value_out));
}

void ZeroedEdges::compute()
{
LOG_DEBUG("computing node [%s]", this->id.c_str());

hmap::HeightMap *p_input_hmap = static_cast<hmap::HeightMap *>(
(void *)this->get_p_data("input"));
hmap::HeightMap *p_input_dr = static_cast<hmap::HeightMap *>(
(void *)this->get_p_data("dr"));

this->value_out = *p_input_hmap;

if (!p_input_dr)
hmap::transform(
this->value_out,
[](hmap::Array &z, hmap::Vec2<float> shift, hmap::Vec2<float> scale)
{ hmap::zeroed_edges(z, nullptr, shift, scale); });

else
hmap::transform(this->value_out,
*p_input_dr,
[](hmap::Array &z,
hmap::Array &dr,
hmap::Vec2<float> shift,
hmap::Vec2<float> scale)
{ hmap::zeroed_edges(z, &dr, shift, scale); });

this->value_out.smooth_overlap_buffers();
}

} // namespace hesiod::cnode
6 changes: 0 additions & 6 deletions src/nodes/view_node/view_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ bool ViewKernel::render_settings()
}
has_changed |= this->trigger_update_after_edit();

// ImGui::SliderInt("shape.x", &this->shape.x, 1, 256);
// has_changed |= this->trigger_update_after_edit();

// ImGui::SliderInt("shape.y", &this->shape.y, 1, 256);
// has_changed |= this->trigger_update_after_edit();

if (hesiod::gui::listbox_map_enum(this->kernel_map, this->kernel, 128.f))
{
this->force_update();
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/view_node/view_thermal_auto_bedrock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool ViewThermalAutoBedrock::render_settings()

has_changed |= this->render_settings_header();

ImGui::SliderFloat("talus_global", &this->talus_global, 0.f, 0.5f, "%.2f");
ImGui::SliderFloat("talus_global", &this->talus_global, 0.f, 4.f, "%.2f");
has_changed |= this->trigger_update_after_edit();

ImGui::SliderInt("iterations", &this->iterations, 1, 200);
Expand Down
38 changes: 38 additions & 0 deletions src/nodes/view_node/view_zeroed_edges.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General
* Public License. The full license is in the file LICENSE, distributed with
* this software. */
#include "macrologger.h"

#include "hesiod/gui.hpp"
#include "hesiod/view_node.hpp"

namespace hesiod::vnode
{

ViewZeroedEdges::ViewZeroedEdges(std::string id)
: ViewNode(), hesiod::cnode::ZeroedEdges(id)
{
this->set_p_control_node((gnode::Node *)this);
this->set_preview_port_id("output");
}

bool ViewZeroedEdges::render_settings()
{
bool has_changed = false;
has_changed |= this->render_settings_header();

has_changed |= this->render_settings_footer();
return has_changed;
}

void ViewZeroedEdges::serialize_save(cereal::JSONOutputArchive &)
{
// empty
}

void ViewZeroedEdges::serialize_load(cereal::JSONInputArchive &)
{
// empty
}

} // namespace hesiod::vnode
6 changes: 6 additions & 0 deletions src/nodes/view_tree/add_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,12 @@ std::string ViewTree::add_view_node(std::string control_node_type,
this->overlap);
this->add_node(p_view_node);
}
else if (control_node_type == "ZeroedEdges")
{
std::shared_ptr p_view_node =
std::make_shared<hesiod::vnode::ViewZeroedEdges>(id);
this->add_node(p_view_node);
}
else
{
LOG_ERROR("unknown node type: [%s]", control_node_type.c_str());
Expand Down

0 comments on commit 1882942

Please sign in to comment.