This commit is contained in:
Aang23 2025-01-23 15:57:53 +01:00
parent 9f03fe6b0e
commit 3ca782d435
4 changed files with 106 additions and 7 deletions

View file

@ -32,7 +32,7 @@ namespace image
{
auto tkts = splitString(p.tkt, ',');
for (int i = 0; i < p.img->channels(); i++)
equParser.DefineVar(tkts.size() == p.img->channels() ? tkts[i] : (p.tkt + "_" + std::to_string(i + 1)), &p.val[i]);
equParser.DefineVar(tkts.size() > i ? tkts[i] : (p.tkt + "_" + std::to_string(i + 1)), &p.val[i]);
}
if (p.img->depth() > depth)

View file

@ -31,6 +31,8 @@ namespace satdump
{ return std::make_shared<ImageGetProj_Node>(); });
flowgraph.node_internal_registry.emplace("image_reproj", []()
{ return std::make_shared<ImageReproj_Node>(); });
flowgraph.node_internal_registry.emplace("image_equation", []()
{ return std::make_shared<ImageEquation_Node>(); });
}
DatasetProductHandler::~DatasetProductHandler()

View file

@ -29,6 +29,15 @@ namespace satdump
std::vector<InOutConfig> outputs;
bool has_run;
public:
std::function<void(InOutConfig, bool)> add_io_callback;
void addInputDynamic(InOutConfig cfg)
{
inputs.push_back(cfg);
add_io_callback(cfg, false);
}
public:
void reset()
{
@ -75,8 +84,8 @@ namespace satdump
const std::shared_ptr<NodeInternal> internal;
bool pos_was_set = false;
double pos_x = 0;
double pos_y = 0;
float pos_x = 0;
float pos_y = 0;
struct InOut
{
@ -97,15 +106,23 @@ namespace satdump
node_io.push_back({f->getNewNodeIOID(&node_io), io.name, false});
for (auto &io : internal->outputs)
node_io.push_back({f->getNewNodeIOID(&node_io), io.name, true});
internal->add_io_callback = [this, f](NodeInternal::InOutConfig io, bool out)
{
node_io.push_back({f->getNewNodeIOID(&node_io), io.name, out});
};
}
Node(nlohmann::json j, std::shared_ptr<NodeInternal> i)
Node(Flowgraph *f, nlohmann::json j, std::shared_ptr<NodeInternal> i)
: id(j["id"]), internal_id(j["int_id"]), title(i->title), node_io(j["io"]), internal(i)
{
internal->from_json(j["int_cfg"]);
internal->add_io_callback = [this, f](NodeInternal::InOutConfig io, bool out)
{
node_io.push_back({f->getNewNodeIOID(&node_io), io.name, out});
};
pos_x = j.contains("pos_x") ? j["pos_x"].get<double>() : 0;
pos_y = j.contains("pos_y") ? j["pos_y"].get<double>() : 0;
pos_x = j.contains("pos_x") ? j["pos_x"].get<float>() : 0;
pos_y = j.contains("pos_y") ? j["pos_y"].get<float>() : 0;
}
nlohmann::json getJSON()
@ -168,7 +185,7 @@ namespace satdump
for (auto &n : j["nodes"].items())
{
auto i = node_internal_registry[n.value()["int_id"]]();
nodes.push_back(std::make_shared<Node>(n.value(), i));
nodes.push_back(std::make_shared<Node>(this, n.value(), i));
}
links = j["links"];
}

View file

@ -5,6 +5,7 @@
#include "common/image/meta.h"
#include "projection/projection.h"
#include "projection/reprojector.h"
#include "common/image/equation.h"
namespace satdump
{
@ -122,4 +123,83 @@ namespace satdump
nlohmann::json to_json() { return {}; }
void from_json(nlohmann::json j) {}
};
class ImageEquation_Node : public NodeInternal
{
private:
struct ChConfig
{
std::string input_name;
std::string tokens;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(ChConfig, input_name, tokens);
};
std::vector<ChConfig> channels;
std::string equation;
public:
ImageEquation_Node()
: NodeInternal("Image Equation")
{
outputs.push_back({"Image"});
}
void process()
{
std::vector<image::EquationChannel> ch;
for (int i = 0; i < channels.size(); i++)
{
std::shared_ptr<image::Image> img = std::static_pointer_cast<image::Image>(inputs[i].ptr);
ch.push_back({channels[i].tokens, img.get()});
logger->warn(channels[i].tokens);
}
std::shared_ptr<image::Image> img_out = std::make_shared<image::Image>();
*img_out = image::generate_image_equation(ch, equation);
outputs[0].ptr = img_out;
has_run = true;
}
void render()
{
ImGui::SetNextItemWidth(200 * ui_scale);
ImGui::InputTextMultiline("Equation", &equation);
for (auto &c : channels)
{
ImGui::Separator();
ImGui::Text(c.input_name.c_str());
ImGui::SameLine();
ImGui::SetNextItemWidth(200 * ui_scale);
ImGui::InputText(std::string("##input" + c.input_name).c_str(), &c.tokens);
}
ImGui::Separator();
if (ImGui::Button("Add"))
{
std::string name = "Img" + std::to_string(channels.size() + 1);
addInputDynamic({name});
channels.push_back({name, "chimg" + std::to_string(channels.size() + 1)});
}
}
nlohmann::json to_json()
{
nlohmann::json j;
j["equation"] = equation;
j["channels"] = channels;
return j;
}
void from_json(nlohmann::json j)
{
equation = j["equation"];
channels = j["channels"];
inputs.clear();
for (auto &c : channels)
inputs.push_back({c.input_name});
}
};
}