-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrixSlicerElement.cs
103 lines (91 loc) · 3.74 KB
/
MatrixSlicerElement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.Text;
using MetaphysicsIndustries.Solus;
using System.Drawing;
using MetaphysicsIndustries.Epiphany;
using MetaphysicsIndustries.Acuity;
using MetaphysicsIndustries.Utilities;
namespace MetaphysicsIndustries.Amethyst
{
[Serializable]
public class MatrixSlicerElement : AmethystElement
{
public MatrixSlicerElement()
: base(new MatrixSlicerNode())
{
Size = new SizeV(Size.Width + 50, Size.Height);
}
protected override void InitTerminals()
{
base.InitTerminals();
TerminalsByConnection[Node.MatrixInput].Size *= 2;
TerminalsByConnection[Node.StartRow].DisplayText = "r";
TerminalsByConnection[Node.StartColumn].DisplayText = "c";
TerminalsByConnection[Node.NumberOfRows].DisplayText = "Nr";
TerminalsByConnection[Node.NumberOfColumns].DisplayText = "Nc";
TerminalsByConnection[Node.Output].Size *= 2;
}
public new MatrixSlicerNode Node
{
get { return (MatrixSlicerNode)base.Node; }
}
[Serializable]
public class MatrixSlicerNode : Node
{
public MatrixSlicerNode()
: base("Slicer")
{
}
private InputConnection<Matrix> _matrixInput = new InputConnection<Matrix>("Matrix Input");
public InputConnection<Matrix> MatrixInput
{
get { return _matrixInput; }
}
private InputConnection<int> _startRow = new InputConnection<int>("StartRow");
public InputConnection<int> StartRow
{
get { return _startRow; }
}
private InputConnection<int> _startColumn = new InputConnection<int>("Start Column");
public InputConnection<int> StartColumn
{
get { return _startColumn; }
}
private InputConnection<int> _numberOfRows = new InputConnection<int>("Number Of Rows");
public InputConnection<int> NumberOfRows
{
get { return _numberOfRows; }
}
private InputConnection<int> _numberOfColumns = new InputConnection<int>("Number Of Columns");
public InputConnection<int> NumberOfColumns
{
get { return _numberOfColumns; }
}
private OutputConnection<Matrix> _output = new OutputConnection<Matrix>("Output");
public OutputConnection<Matrix> Output
{
get { return _output; }
}
protected override void InitConnections()
{
InputConnectionBases.Add(MatrixInput);
InputConnectionBases.Add(StartRow);
InputConnectionBases.Add(StartColumn);
InputConnectionBases.Add(NumberOfRows);
InputConnectionBases.Add(NumberOfColumns);
OutputConnectionBases.Add(Output);
}
public override void Execute(Dictionary<InputConnectionBase, object> inputs, Dictionary<OutputConnectionBase, object> outputs)
{
Matrix input = (Matrix)inputs[MatrixInput];
int startRow = (int)inputs[StartRow];
int startColumn = (int)inputs[StartColumn];
int numberOfRows = (int)inputs[NumberOfRows];
int numberOfColumns = (int)inputs[NumberOfColumns];
Matrix output = input.GetSlice(startRow, startColumn, numberOfRows, numberOfColumns);
outputs[Output] = output;
}
}
}
}