ImageMaskRandomPointsNode
This commit is contained in:
@@ -58,6 +58,8 @@
|
||||
#include <noggit/Red/NodeEditor/Nodes/Data/GetVariableLazyNode.hpp>
|
||||
#include <noggit/Red/NodeEditor/Nodes/Data/SetVariableNode.hpp>
|
||||
#include <noggit/Red/NodeEditor/Nodes/Data/DeleteVariableNode.hpp>
|
||||
#include <noggit/Red/NodeEditor/Nodes/Data/String/StringEndsWithNode.hpp>
|
||||
#include <noggit/Red/NodeEditor/Nodes/Data/String/StringSizeNode.hpp>
|
||||
#include <noggit/Red/NodeEditor/Nodes/Math/Matrix/MatrixNode.hpp>
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/Data/Image/LoadImageNode.hpp>
|
||||
@@ -75,6 +77,7 @@
|
||||
#include <noggit/Red/NodeEditor/Nodes/Data/Image/ImageMirrorNode.hpp>
|
||||
#include <noggit/Red/NodeEditor/Nodes/Data/Image/ImageResizeNode.hpp>
|
||||
#include <noggit/Red/NodeEditor/Nodes/Data/Image/ImageGaussianBlurNode.hpp>
|
||||
#include <noggit/Red/NodeEditor/Nodes/Data/Image/ImageMaskRandomPointsNode.hpp>
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/Data/Noise/NoisePerlinNode.hpp>
|
||||
#include <noggit/Red/NodeEditor/Nodes/Data/Noise/NoiseToImageNode.hpp>
|
||||
@@ -183,6 +186,11 @@ namespace noggit
|
||||
ret->registerModel<ImageToGrayscaleNode>("Data//Image");
|
||||
ret->registerModel<ImageMirrorNode>("Data//Image");
|
||||
ret->registerModel<ImageGaussianBlurNode>("Data//Image");
|
||||
ret->registerModel<ImageMaskRandomPointsNode>("Data//Image");
|
||||
|
||||
// String
|
||||
ret->registerModel<StringEndsWithNode>("Data//String");
|
||||
ret->registerModel<StringSizeNode>("Data//String");
|
||||
|
||||
// Noise
|
||||
ret->registerModel<NoisePerlinNode>("Data//Noise//Generators");
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "ImageMaskRandomPointsNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
ImageMaskRandomPointsNode::ImageMaskRandomPointsNode()
|
||||
: LogicNodeBase()
|
||||
{
|
||||
setName("ImageMaskRandomPointsNode");
|
||||
setCaption("Image Mask Random Points");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPortDefault<LogicData>(PortType::In, "Logic", true);
|
||||
addPortDefault<ImageData>(PortType::In, "Image", true);
|
||||
addPortDefault<IntegerData>(PortType::In, "Seed<Integer>", true);
|
||||
addPortDefault<DecimalData>(PortType::In, "Density<Decimal>", true);
|
||||
auto density = static_cast<QDoubleSpinBox*>(_in_ports[3].default_widget);
|
||||
density->setMinimum(-1.0);
|
||||
density->setValue(0.5);
|
||||
density->setMaximum(1.0001);
|
||||
|
||||
|
||||
addPort<LogicData>(PortType::Out, "Logic", true);
|
||||
addPort<ListData>(PortType::Out, "List<Vector2D>", true);
|
||||
_out_ports[1].data_type->set_parameter_type("vec2");
|
||||
}
|
||||
|
||||
void ImageMaskRandomPointsNode::compute()
|
||||
{
|
||||
QImage* image = static_cast<ImageData*>(_in_ports[1].in_value.lock().get())->value_ptr();
|
||||
|
||||
QRandomGenerator rand;
|
||||
rand.seed(defaultPortData<IntegerData>(PortType::In, 2)->value());
|
||||
|
||||
_data.clear();
|
||||
|
||||
double density = defaultPortData<DecimalData>(PortType::In, 3)->value();
|
||||
|
||||
for (int i = 0; i < image->width(); ++i)
|
||||
{
|
||||
for (int j = 0; j < image->height(); ++j)
|
||||
{
|
||||
double random_value = rand.bounded(1.0001);
|
||||
bool chance_value = rand.bounded(1.0001) < density;
|
||||
if (random_value < qGray(image->pixelColor(i, j).rgb()) && chance_value)
|
||||
_data.push_back(std::make_shared<Vector2DData>(glm::vec2(i, j)));
|
||||
}
|
||||
}
|
||||
|
||||
_out_ports[0].out_value = std::make_shared<LogicData>(true);
|
||||
Q_EMIT dataUpdated(0);
|
||||
|
||||
auto list = std::make_shared<ListData>(&_data);
|
||||
list->set_parameter_type(_out_ports[1].data_type->type().parameter_type_id);
|
||||
_out_ports[1].out_value = std::move(list);
|
||||
|
||||
Q_EMIT dataUpdated(1);
|
||||
}
|
||||
|
||||
NodeValidationState ImageMaskRandomPointsNode::validate()
|
||||
{
|
||||
return LogicNodeBase::validate();
|
||||
}
|
||||
|
||||
QJsonObject ImageMaskRandomPointsNode::save() const
|
||||
{
|
||||
QJsonObject json_obj = BaseNode::save();
|
||||
|
||||
return json_obj;
|
||||
}
|
||||
|
||||
void ImageMaskRandomPointsNode::restore(const QJsonObject& json_obj)
|
||||
{
|
||||
BaseNode::restore(json_obj);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_IMAGEMASKRANDOMPOINTSNODE_HPP
|
||||
#define NOGGIT_IMAGEMASKRANDOMPOINTSNODE_HPP
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/LogicNodeBase.hpp>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
class ImageMaskRandomPointsNode : public LogicNodeBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ImageMaskRandomPointsNode();
|
||||
void compute() override;
|
||||
NodeValidationState validate() override;
|
||||
QJsonObject save() const override;
|
||||
void restore(QJsonObject const& json_obj) override;
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<NodeData>> _data;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_IMAGEMASKRANDOMPOINTSNODE_HPP
|
||||
@@ -0,0 +1,43 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "StringEndsWithNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
StringEndsWithNode::StringEndsWithNode()
|
||||
: BaseNode()
|
||||
{
|
||||
setName("StringEndsWithNode");
|
||||
setCaption("String Ends With");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPort<StringData>(PortType::In, "String", true);
|
||||
addDefaultWidget(new QLabel(&_embedded_widget), PortType::In, 0);
|
||||
addPortDefault<StringData>(PortType::In, "Ending<String>", true);
|
||||
|
||||
addPort<BooleanData>(PortType::Out, "Boolean", true);
|
||||
}
|
||||
|
||||
void StringEndsWithNode::compute()
|
||||
{
|
||||
_out_ports[0].out_value = std::make_shared<BooleanData>(
|
||||
QString::fromStdString(static_cast<StringData*>(_in_ports[0].in_value.lock().get())->value()).endsWith(
|
||||
defaultPortData<StringData>(PortType::In, 1)->value().c_str()));
|
||||
|
||||
Q_EMIT dataUpdated(0);
|
||||
}
|
||||
|
||||
NodeValidationState StringEndsWithNode::validate()
|
||||
{
|
||||
if (!static_cast<StringData*>(_in_ports[0].in_value.lock().get()))
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: failed to evaluate string input.");
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
return _validation_state;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_STRINGENDSWITHNODE_HPP
|
||||
#define NOGGIT_STRINGENDSWITHNODE_HPP
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.hpp>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
|
||||
namespace noggit
|
||||
{
|
||||
namespace Red::NodeEditor::Nodes
|
||||
{
|
||||
class StringEndsWithNode : public BaseNode
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
StringEndsWithNode();
|
||||
void compute() override;
|
||||
NodeValidationState validate() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //NOGGIT_STRINGENDSWITHNODE_HPP
|
||||
@@ -0,0 +1,38 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "StringSizeNode.hpp"
|
||||
|
||||
#include <noggit/Red/NodeEditor/Nodes/BaseNode.inl>
|
||||
#include <noggit/Red/NodeEditor/Nodes/DataTypes/GenericData.hpp>
|
||||
|
||||
using namespace noggit::Red::NodeEditor::Nodes;
|
||||
|
||||
StringSizeNode::StringSizeNode()
|
||||
: BaseNode()
|
||||
{
|
||||
setName("StringSizeNode");
|
||||
setCaption("String Size");
|
||||
_validation_state = NodeValidationState::Valid;
|
||||
|
||||
addPort<StringData>(PortType::In, "String", true);
|
||||
addPort<UnsignedIntegerData>(PortType::Out, "Size<UInteger>", true);
|
||||
}
|
||||
|
||||
void StringSizeNode::compute()
|
||||
{
|
||||
_out_ports[0].out_value = std::make_shared<UnsignedIntegerData>(static_cast<StringData*>(_in_ports[0].in_value.lock().get())->value().size());
|
||||
|
||||
Q_EMIT dataUpdated(0);
|
||||
}
|
||||
|
||||
NodeValidationState StringSizeNode::validate()
|
||||
{
|
||||
if (!static_cast<StringData*>(_in_ports[0].in_value.lock().get()))
|
||||
{
|
||||
setValidationState(NodeValidationState::Error);
|
||||
setValidationMessage("Error: failed to evaluate string input.");
|
||||
return _validation_state;
|
||||
}
|
||||
|
||||
return _validation_state;
|
||||
}
|
||||
@@ -177,6 +177,7 @@ struct DefaultDecimalWidget
|
||||
{
|
||||
auto widget = new QDoubleSpinBox(parent);
|
||||
widget->setRange(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max());
|
||||
widget->setDecimals(7);
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#define NOGGIT_CONTEXT_HPP
|
||||
|
||||
#include <noggit/World.h>
|
||||
#include <noggit/Red/ViewportManager/ViewportManager.hpp>
|
||||
#include "NodeScene.hpp"
|
||||
#include <external/tsl/robin_map.h>
|
||||
|
||||
@@ -34,9 +35,12 @@ namespace noggit
|
||||
NodeExecutionContext getContextType() { return _context_type; };
|
||||
void makeCurrent();
|
||||
VariableMap* getVariableMap() { return &_variable_map; };
|
||||
World* getWorld() { return _world; };
|
||||
ViewportManager::ViewportManager* getViewport() { return _viewport; };
|
||||
|
||||
private:
|
||||
World* _world;
|
||||
ViewportManager::ViewportManager* _viewport;
|
||||
tsl::robin_map<std::string, QJsonDocument> _scene_cache;
|
||||
NodeExecutionContext _context_type;
|
||||
VariableMap _variable_map;
|
||||
|
||||
@@ -194,11 +194,7 @@ bool LogicBranch::executeNodeLeaves(Node* node, Node* source_node)
|
||||
continue;
|
||||
|
||||
if (connected_model->isLogicNode())
|
||||
{
|
||||
connected_model->setValidationState(NodeValidationState::Error);
|
||||
connected_model->setValidationMessage("Error: Logic node is out of logic flow.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!executeNodeLeaves(connected_node, node))
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user