nodes: revise array type

This commit is contained in:
itsmattkc
2022-09-18 22:43:30 -07:00
parent 7a1e1cdb49
commit 4dbfbd63ec
5 changed files with 45 additions and 28 deletions
+12 -11
View File
@@ -119,9 +119,9 @@ void PolygonGenerator::GenerateFrame(FramePtr frame, const GenerateJob &job) con
QImage img((uchar *) frame->data(), frame->width(), frame->height(), frame->linesize_bytes(), QImage::Format_RGBA8888_Premultiplied);
img.fill(Qt::transparent);
QVector<NodeValue> points = job.Get(kPointsInput).value< QVector<NodeValue> >();
auto points = job.Get(kPointsInput).toArray();
QPainterPath path = GeneratePath(points);
QPainterPath path = GeneratePath(points, InputArraySize(kPointsInput));
QPainter p(&img);
double par = frame->video_params().pixel_aspect_ratio().toDouble();
@@ -171,7 +171,7 @@ void PolygonGenerator::UpdateGizmoPositions(const NodeValueRow &row, const NodeG
{
QPointF half_res(globals.resolution_by_par().x()/2, globals.resolution_by_par().y()/2);
QVector<NodeValue> points = row[kPointsInput].value< QVector<NodeValue> >();
auto points = row[kPointsInput].toArray();
int current_pos_sz = gizmo_position_handles_.size();
@@ -196,8 +196,9 @@ void PolygonGenerator::UpdateGizmoPositions(const NodeValueRow &row, const NodeG
bez_gizmo2->SetSmaller(true);
}
if (!points.isEmpty()) {
for (int i=0; i<points.size(); i++) {
int pts_sz = InputArraySize(kPointsInput);
if (!points.empty()) {
for (int i=0; i<pts_sz; i++) {
const Bezier &pt = points.at(i).toBezier();
QPointF main = pt.ToPointF() + half_res;
@@ -213,7 +214,7 @@ void PolygonGenerator::UpdateGizmoPositions(const NodeValueRow &row, const NodeG
}
}
poly_gizmo_->SetPath(GeneratePath(points).translated(half_res));
poly_gizmo_->SetPath(GeneratePath(points, pts_sz).translated(half_res));
}
ShaderCode PolygonGenerator::GetShaderCode(const ShaderRequest &request) const
@@ -246,19 +247,19 @@ void PolygonGenerator::AddPointToPath(QPainterPath *path, const Bezier &before,
after.ToPointF());
}
QPainterPath PolygonGenerator::GeneratePath(const QVector<NodeValue> &points)
QPainterPath PolygonGenerator::GeneratePath(const NodeValueArray &points, int size)
{
QPainterPath path;
if (!points.isEmpty()) {
const Bezier &first_pt = points.first().toBezier();
if (!points.empty()) {
const Bezier &first_pt = points.at(0).toBezier();
path.moveTo(first_pt.ToPointF());
for (int i=1; i<points.size(); i++) {
for (int i=1; i<size; i++) {
AddPointToPath(&path, points.at(i-1).toBezier(), points.at(i).toBezier());
}
AddPointToPath(&path, points.last().toBezier(), first_pt);
AddPointToPath(&path, points.at(size-1).toBezier(), first_pt);
}
return path;
+1 -1
View File
@@ -68,7 +68,7 @@ protected slots:
private:
static void AddPointToPath(QPainterPath *path, const Bezier &before, const Bezier &after);
static QPainterPath GeneratePath(const QVector<NodeValue> &points);
static QPainterPath GeneratePath(const NodeValueArray &points, int size);
template<typename T>
void ValidateGizmoVectorSize(QVector<T*> &vec, int new_sz);
+5
View File
@@ -212,6 +212,11 @@ public:
return input_ids_;
}
virtual bool IsInputActiveAtTime(const QString &input, int element, const TimeRange &r) const
{
return true;
}
bool HasInputWithID(const QString& id) const
{
return input_ids_.contains(id);
+21 -14
View File
@@ -80,11 +80,11 @@ NodeValue NodeTraverser::GenerateRowValue(const Node *node, const QString &input
if (value.array()) {
// Resolve each element of array
QVector<NodeValueTable> tables = value.value<QVector<NodeValueTable> >();
QVector<NodeValue> output(tables.size());
NodeValueTableArray tables = value.value<NodeValueTableArray>();
NodeValueArray output;
for (int i=0; i<tables.size(); i++) {
output[i] = GenerateRowValueElement(node, input, i, &tables[i], time);
for (auto it=tables.begin(); it!=tables.end(); it++) {
output[it->first] = GenerateRowValueElement(node, input, it->first, &it->second, time);
}
value = NodeValue(value.type(), QVariant::fromValue(output), value.source(), value.array(), value.tag());
@@ -195,6 +195,10 @@ TexturePtr NodeTraverser::GetMainTextureFromJob(const GenerateJob &job)
NodeValueTable NodeTraverser::ProcessInput(const Node* node, const QString& input, const TimeRange& range)
{
if (!node->IsInputActiveAtTime(input, -1, range)) {
return NodeValueTable();
}
// If input is connected, retrieve value directly
if (node->IsInputConnected(input)) {
@@ -214,18 +218,21 @@ NodeValueTable NodeTraverser::ProcessInput(const Node* node, const QString& inpu
if (is_array) {
// Value is an array, we will return a list of NodeValueTables
QVector<NodeValueTable> array_tbl(node->InputArraySize(input));
NodeValueTableArray array_tbl;
for (int i=0; i<array_tbl.size(); i++) {
NodeValueTable& sub_tbl = array_tbl[i];
TimeRange adjusted_range = node->InputTimeAdjustment(input, i, range);
int sz = node->InputArraySize(input);
for (int i=0; i<sz; i++) {
if (node->IsInputActiveAtTime(input, i, range)) {
NodeValueTable& sub_tbl = array_tbl[i];
TimeRange adjusted_range = node->InputTimeAdjustment(input, i, range);
if (node->IsInputConnected(input, i)) {
Node *output = node->GetConnectedOutput(input, i);
sub_tbl = GenerateTable(output, adjusted_range, node);
} else {
QVariant input_value = node->GetValueAtTime(input, adjusted_range.in(), i);
sub_tbl.Push(node->GetInputDataType(input), input_value, node);
if (node->IsInputConnected(input, i)) {
Node *output = node->GetConnectedOutput(input, i);
sub_tbl = GenerateTable(output, adjusted_range, node);
} else {
QVariant input_value = node->GetValueAtTime(input, adjusted_range.in(), i);
sub_tbl.Push(node->GetInputDataType(input), input_value, node);
}
}
}
+6 -2
View File
@@ -31,11 +31,15 @@
#include "node/splitvalue.h"
#include "render/color.h"
#include "render/texture.h"
#include "undo/undocommand.h"
namespace olive {
class Node;
class NodeValue;
class NodeValueTable;
using NodeValueArray = std::map<int, NodeValue>;
using NodeValueTableArray = std::map<int, NodeValueTable>;
class NodeValue
{
@@ -339,7 +343,7 @@ public:
QVector3D toVec3() const { return value<QVector3D>(); }
QVector4D toVec4() const { return value<QVector4D>(); }
Bezier toBezier() const { return value<Bezier>(); }
QVector<NodeValue> toArray() const { return value<QVector<NodeValue> >(); }
NodeValueArray toArray() const { return value<NodeValueArray>(); }
private:
Type type_;