Beispiel #1
0
        public void GetsData()
        {
            // Get the parent PipelineVM and add DiagramNode
            var vm   = MainViewModelTest.GetInstance().PipelineViewModel;
            var node = new NodeViewModel(new HistogramNode(), vm);

            vm.Nodes.Add(node);
            vm.Parent.Model.Graph.AddNode(node.Model);

            var hvm = new HistogramViewModel((HistogramNode)vm.Nodes.Single().Model);

            // Generates an array of 1 Frame with randomly filled Data
            var testSize = new Size(5, 5);

            Frame[] inputs = { new Frame(testSize) };
            for (var x = 0; x < testSize.Width; x++)
            {
                for (var y = 0; y < testSize.Height; y++)
                {
                    inputs[0][x, y] = new Rgb((byte)(x + y), (byte)(x + y), (byte)(x + y));
                }
            }

            hvm.NodeModel.Type = HistogramType.R;

            // porcess one frame with chosen type
            hvm.NodeModel.Process(inputs, 0);
            hvm.Handle(null);

            Assert.NotEmpty(hvm.Data.Data);
        }
Beispiel #2
0
        public void CanAddInput()
        {
            var posMock = new Mock <IGetPosition>();

            posMock.Setup(p => p.GetElementSize(It.IsAny <IViewAware>())).Returns(new Size(4, 4));
            posMock.Setup(p => p.ViewLoaded(It.IsAny <IViewAware>())).Returns(Observable.Never <Unit>());

            PipelineViewModel vm = MainViewModelTest.GetInstance(
                container => container.ComposeExportedValue <IGetPosition>(posMock.Object)
                ).PipelineViewModel;

            var node0 = new NodeViewModel(new BlurNode(), vm);

            vm.Nodes.Add(node0);
            vm.Parent.Model.Graph.AddNode(node0.Model);
            var node1 = new NodeViewModel(new WeightedAveragedMergeNode(), vm);

            vm.Nodes.Add(node1);
            vm.Parent.Model.Graph.AddNode(node1.Model);

            Assert.Equal(0, node1.Model.Inputs.Count);
            Assert.Equal(1, node1.Inputs.Count());

            vm.InOutputMouseDown(node0.Outputs.First());
            vm.InOutputMouseUp(node1.Inputs.Last());

            Assert.Equal(1, node1.Model.Inputs.Count);
            Assert.Equal(2, node1.Inputs.Count());
            Assert.Equal(node1.Inputs.First(), vm.Edges.Single().StartViewModel);
        }
Beispiel #3
0
        public void ResetReferenceWithExistingGraphControls()
        {
            // Set the GraphTypes
            IoC.GetAllInstances = type => new IGraphType[] { new PixelDiff() };

            // Get the parent PipelineVM and add DiagramNode
            var vm   = MainViewModelTest.GetInstance().PipelineViewModel;
            var node = new NodeViewModel(new DiagramNode(), vm);

            vm.Nodes.Add(node);
            vm.Parent.Model.Graph.AddNode(node.Model);

            var DVM = new DiagramViewModel((DiagramNode)vm.Nodes.Single().Model);

            // Add Input Node for DiagramNode with 3 Outputs.
            var sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3);
            var inputs     = sourceNode.Process(null, 0);

            // Add reference video to node.
            var reference = new Node.Input {
                Source = sourceNode.Outputs[0]
            };

            DVM.NodeModel.Inputs.Add(reference);

            // Add other Outputs as Inputs to DiagramNode.
            var video = new Node.Input {
                Source = sourceNode.Outputs[1]
            };

            DVM.NodeModel.Inputs.Add(video);
            var altRef = new Node.Input {
                Source = sourceNode.Outputs[2]
            };

            DVM.NodeModel.Inputs.Add(altRef);

            DVM.Reference   = DVM.Videos.ElementAt(0);
            DVM.ChosenVideo = DVM.Videos.ElementAt(1);
            DVM.AddGraph();

            var dgvm = DVM.Graphs.Single();

            // ChosenType = PixelDifference
            dgvm.CurrentType = dgvm.AvailableTypes.ElementAt(0);

            // porcess one frame with first reference
            DVM.NodeModel.ProcessCore(inputs, 0);
            DVM.Handle(null);

            DVM.Reference = DVM.Videos.ElementAt(2);

            // porcess one frame with second reference
            DVM.NodeModel.ProcessCore(inputs, 1);
            DVM.Handle(null);

            Assert.Equal(dgvm.AvailableTypes.ElementAt(0).Model.Process(inputs[1], inputs[0]), dgvm.Model.Data[0].Value);
            Assert.Equal(dgvm.AvailableTypes.ElementAt(0).Model.Process(inputs[1], inputs[2]), dgvm.Model.Data[1].Value);
        }
Beispiel #4
0
 private object IoCAggregator(System.Type type, string str)
 {
     if (type == typeof(MainViewModel))
     {
         return(MainViewModelTest.GetInstance());
     }
     return(new EventAggregator());
 }
Beispiel #5
0
        public void CanDeleteLine()
        {
            // Set the GraphTypes
            IoC.GetAllInstances = type => new IGraphType[] { new PixelDiff() };

            // Get the parent PipelineVM and add DiagramNode
            var vm   = MainViewModelTest.GetInstance().PipelineViewModel;
            var node = new NodeViewModel(new DiagramNode(), vm);

            vm.Nodes.Add(node);
            vm.Parent.Model.Graph.AddNode(node.Model);

            var DVM = new DiagramViewModel((DiagramNode)vm.Nodes.Single().Model);

            // Add Input Node for DiagramNode with 3 Outputs.
            var sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3);
            var inputs     = sourceNode.Process(null, 0);

            // Add reference video to node.
            var reference = new Node.Input {
                Source = sourceNode.Outputs[0]
            };

            DVM.NodeModel.Inputs.Add(reference);

            // Add other Outputs as Inputs to DiagramNode.
            var video = new Node.Input {
                Source = sourceNode.Outputs[1]
            };

            DVM.NodeModel.Inputs.Add(video);
            var annVid = new Node.Input {
                Source = sourceNode.Outputs[2]
            };

            DVM.NodeModel.Inputs.Add(annVid);

            DVM.Reference   = DVM.Videos.ElementAt(0);
            DVM.ChosenVideo = DVM.Videos.ElementAt(1);
            DVM.AddGraph();

            var dgvm = DVM.Graphs.Single();

            // Set the ChosenType of the DiagramGraphViewModel to PixelDifference
            dgvm.CurrentType = dgvm.AvailableTypes.First();

            Assert.NotEmpty(DVM.Lines);
            Assert.NotEmpty(DVM.NodeModel.Graphs);

            DVM.DeleteGraph(dgvm);

            Assert.Empty(DVM.Lines);
            Assert.Empty(DVM.NodeModel.Graphs);
        }
Beispiel #6
0
        public void DisplaysDynamicallyAddedOutputs()
        {
            var vm = MainViewModelTest.GetInstance().PipelineViewModel;

            var nodeMock = new Mock <Node>(new object[] { 0, null });            // input count, output count
            var nodeVM   = new NodeViewModel(nodeMock.Object, vm);

            Assert.False(nodeVM.HasOutputs);
            Assert.Empty(nodeVM.Outputs);

            nodeMock.Object.Outputs.Add(new Node.Output(nodeMock.Object));
            Assert.True(nodeVM.HasOutputs);
            Assert.Equal(nodeMock.Object.Outputs[0], nodeVM.Outputs.Single().Model);
        }
Beispiel #7
0
        public void CanRemoveNode()
        {
            PipelineViewModel vm = MainViewModelTest.GetInstance().PipelineViewModel;

            var node0 = new NodeViewModel(new BlurNode(), vm);

            vm.Nodes.Add(node0);
            vm.Parent.Model.Graph.AddNode(node0.Model);

            Assert.PropertyChanged(vm, "Edges", node0.RemoveNode);

            Assert.DoesNotContain(node0, vm.Nodes);
            Assert.DoesNotContain(node0.Model, vm.Parent.Model.Graph.Nodes);
        }
Beispiel #8
0
        public void CannotAddDgvmWithoutChosenVid()
        {
            // Set the GraphTypes
            IoC.GetAllInstances = type => new IGraphType[] { new PixelDiff() };

            // Get the parent PipelineVM and add DiagramNode
            var vm   = MainViewModelTest.GetInstance().PipelineViewModel;
            var node = new NodeViewModel(new DiagramNode(), vm);

            vm.Nodes.Add(node);
            vm.Parent.Model.Graph.AddNode(node.Model);

            var DVM = new DiagramViewModel((DiagramNode)vm.Nodes.Single().Model);

            // Add Input Node for DiagramNode with 3 Outputs.
            var sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3);
            var inputs     = sourceNode.Process(null, 0);

            // Add reference video to node.
            var reference = new Node.Input {
                Source = sourceNode.Outputs[0]
            };

            DVM.NodeModel.Inputs.Add(reference);

            // Add other Outputs as Inputs to DiagramNode.
            var video = new Node.Input {
                Source = sourceNode.Outputs[1]
            };

            DVM.NodeModel.Inputs.Add(video);
            var altRef = new Node.Input {
                Source = sourceNode.Outputs[2]
            };

            DVM.NodeModel.Inputs.Add(altRef);

            DVM.Reference = DVM.Videos.ElementAt(0);
            // No video chosen.
            Assert.False(DVM.CanAddGraph);
        }
Beispiel #9
0
        public void CanMoveNode()
        {
            var vm = MainViewModelTest.GetInstance().PipelineViewModel;

            var node0 = new NodeViewModel(new BlurNode(), vm);

            vm.Nodes.Add(node0);
            vm.Parent.Model.Graph.AddNode(node0.Model);

            var mock = new Mock <IMouseEventInfo>();

            mock.Setup(e => e.GetPosition(vm)).Returns(new Point(5, 4));
            vm.NodeMouseDown(node0, mock.Object);

            mock.Setup(e => e.GetPosition(vm)).Returns(new Point(25, 14));
            mock.SetupGet(e => e.LeftButton).Returns(MouseButtonState.Pressed);
            vm.MouseMove(mock.Object);
            vm.MouseUp();

            Assert.Equal(new Point(20, 10), node0.Position);
        }
Beispiel #10
0
        public void RendersNodeToFileCorrectly()
        {
            string input         = @"..\..\..\..\resources\americanFootball_352x240_125.yuv";
            var    windowManMock = new Mock <IWindowManager>();
            var    conductorMock = new Mock <IConductor>();

            windowManMock.Setup(w => w.ShowDialog(It.IsAny <IScreen>(), null, null)).Callback <object, object, object>((viewModel, _, __) => {
                var screen    = (Screen)viewModel;
                screen.Parent = conductorMock.Object;
                ((IActivate)screen).Activate();
                while (screen.IsActive)
                {
                    Thread.Sleep(100);
                }
            });
            conductorMock.Setup(c => c.DeactivateItem(It.IsAny <IScreen>(), true))
            .Callback <object, bool>((window, _) => ((IDeactivate)window).Deactivate(close: true))
            .Verifiable();
            var vm = MainViewModelTest.GetInstance(cont => cont.ComposeExportedValue <IWindowManager>(windowManMock.Object)).PipelineViewModel;

            var node = new NodeViewModel(new VideoInputNode {
                FileName = new FilePath(input)
            }, vm);

            vm.Parent.Model.Graph.AddNode(node.Model);
            var stream = new MemoryStream();

            IEnumerator <IResult> result = node.SaveNodeOutput(node.Model.Outputs[0]).GetEnumerator();

            result.MoveNext();
            var file = (ChooseFileResult)result.Current;

            Assert.Equal(false, file.OpenReadOnly);
            file.Stream = () => stream;
            result.MoveNext();

            Assert.Equal(File.ReadAllBytes(input).Length, stream.ToArray().Length);
        }
Beispiel #11
0
        public void CanDropNode()
        {
            PipelineViewModel vm = MainViewModelTest.GetInstance().PipelineViewModel;

            var mock = new Mock <IDragEventInfo>();

            mock.Setup(e => e.GetData <NodeType>()).Returns(new NodeType {
                Type = typeof(BlurNode)
            });
            mock.Setup(e => e.GetPosition(vm)).Returns(new Point(42, 21));
            mock.SetupProperty(e => e.Effects, DragDropEffects.Copy);

            vm.CheckClearance(mock.Object);
            Assert.Equal(DragDropEffects.Copy, mock.Object.Effects);

            vm.Drop(mock.Object);

            var node = vm.Nodes.Single().Model;

            Assert.True(node is BlurNode);
            Assert.Equal(42, node.X);
            Assert.Equal(21, node.Y);
        }
Beispiel #12
0
        public void CanDragEdge()
        {
            var posMock = new Mock <IGetPosition>();

            posMock.Setup(p => p.GetElementSize(It.IsAny <IViewAware>())).Returns(new Size(4, 4));
            posMock.Setup(p => p.ViewLoaded(It.IsAny <IViewAware>())).Returns(Observable.Never <Unit>());

            PipelineViewModel vm = MainViewModelTest.GetInstance(
                container => container.ComposeExportedValue <IGetPosition>(posMock.Object)
                ).PipelineViewModel;

            var node0 = new NodeViewModel(new BlurNode(), vm);

            vm.Nodes.Add(node0);
            vm.Parent.Model.Graph.AddNode(node0.Model);
            var node1 = new NodeViewModel(new BlurNode(), vm);

            vm.Nodes.Add(node1);
            vm.Parent.Model.Graph.AddNode(node1.Model);

            posMock.Setup(p => p.GetElementPosition(node0.Outputs.Single(), vm)).Returns(new Point(10, 10));
            posMock.Setup(p => p.GetElementPosition(node0.Inputs.Single(), vm)).Returns(new Point(30, 10));
            posMock.Setup(p => p.GetElementPosition(node1.Inputs.Single(), vm)).Returns(new Point(40, 10));

            // Start edge from node0 output

            Assert.PropertyChanged(vm, "DraggedEdge",
                                   () => vm.InOutputMouseDown(node0.Outputs.First())
                                   );

            var edge = vm.DraggedEdge;

            Assert.Equal(new Point(12, 12), edge.StartPoint);
            Assert.Equal(new Point(12, 12), edge.EndPoint);
            Assert.Equal(EdgeStatus.Indeterminate, edge.Status);

            // Move node0

            posMock.Setup(p => p.GetElementPosition(node0.Outputs.Single(), vm)).Returns(new Point(20, 10));
            Assert.PropertyChanged(edge, "Geometry",
                                   () => node0.Position = new Point(-1, -1) // Trigger ViewPositionChanged
                                   );
            Assert.Equal(new Point(22, 12), edge.StartPoint);
            Assert.Equal(new Point(22, 12), edge.EndPoint);

            // Drag edge

            var mouseMock = new Mock <IMouseEventInfo>();

            mouseMock.Setup(m => m.GetPosition(vm)).Returns(new Point(50, 50));
            mouseMock.SetupGet(m => m.LeftButton).Returns(MouseButtonState.Pressed);
            vm.MouseMove(mouseMock.Object);

            Assert.Equal(EdgeStatus.Indeterminate, edge.Status);
            Assert.Equal(new Point(50, 50), edge.EndPoint);

            // Drag edge over node0 input

            var e = new RoutedEventArgs(Mouse.MouseMoveEvent);

            vm.InOutputMouseMove(node0.Inputs.Single(), e);

            Assert.Equal(new Point(32, 12), edge.EndPoint);
            Assert.Equal(EdgeStatus.Invalid, edge.Status);

            // Drag edge over node1 input

            vm.InOutputMouseMove(node1.Inputs.Single(), e);

            Assert.Equal(new Point(42, 12), edge.EndPoint);
            Assert.Equal(EdgeStatus.Valid, edge.Status);

            // Drop edge on node1 input

            vm.InOutputMouseUp(node1.Inputs.Single());

            Assert.Equal(new Point(42, 12), vm.Edges.Single().StartPoint);
            Assert.Equal(new Point(22, 12), vm.Edges.Single().EndPoint);
            Assert.NotNull(vm.Edges.Single().Geometry);
        }
Beispiel #13
0
        public void ShowOnlyAvailableTypes()
        {
            // Set the GraphTypes
            IoC.GetAllInstances = type => new IGraphType[] { new PixelDiff(), new DecisionDiff(), new IntraBlockFrequency(), new PeakSignalNoiseRatio() };

            // Get the parent PipelineVM and add DiagramNode
            var vm   = MainViewModelTest.GetInstance().PipelineViewModel;
            var node = new NodeViewModel(new DiagramNode(), vm);

            vm.Nodes.Add(node);
            vm.Parent.Model.Graph.AddNode(node.Model);

            var DVM = new DiagramViewModel((DiagramNode)vm.Nodes.Single().Model);

            // Add Input Node for DiagramNode with 3 Outputs.
            var sourceNode = new AnonymousNode(AnonNodeHelper.SourceNode, 3);
            var inputs     = sourceNode.Process(null, 0);

            // Add reference video to node.
            var reference = new Node.Input {
                Source = sourceNode.Outputs[0]
            };

            DVM.NodeModel.Inputs.Add(reference);

            // Add other Outputs as Inputs to DiagramNode.
            var video = new Node.Input {
                Source = sourceNode.Outputs[1]
            };

            DVM.NodeModel.Inputs.Add(video);
            var annVid = new Node.Input {
                Source = sourceNode.Outputs[2]
            };

            DVM.NodeModel.Inputs.Add(annVid);

            DVM.ChosenVideo = DVM.Videos.ElementAt(1);
            DVM.AddGraph();
            var dgvmNoRefNoLog = DVM.Graphs.Last();

            Assert.False(dgvmNoRefNoLog.AvailableTypes.ToList().Exists(type => type.Model.DependsOnReference || type.Model.DependsOnLogfile));

            sourceNode.SettableOutputHasLogfile = true;
            DVM.ChosenVideo = DVM.Videos.ElementAt(2);
            DVM.AddGraph();
            Assert.NotNull(DVM.Graphs);
            var dgvmLogNoRef = DVM.Graphs.Last();

            Assert.False(dgvmLogNoRef.AvailableTypes.ToList().Exists(type => type.Model.DependsOnReference));
            Assert.True(dgvmLogNoRef.AvailableTypes.ToList().Exists(type => type.Model.DependsOnLogfile));
            sourceNode.SettableOutputHasLogfile = false;

            DVM.Reference   = DVM.Videos.ElementAt(0);
            DVM.ChosenVideo = DVM.Videos.ElementAt(1);
            DVM.AddGraph();
            var dgvmLoggedRefNoLog = DVM.Graphs.Last();

            Assert.True(dgvmLoggedRefNoLog.AvailableTypes.ToList().Exists(type => type.Model.DependsOnReference));
            Assert.False(dgvmLoggedRefNoLog.AvailableTypes.ToList().Exists(type => type.Model.DependsOnLogfile));

            sourceNode.SettableOutputHasLogfile = true;
            DVM.ChosenVideo = DVM.Videos.ElementAt(2);
            DVM.AddGraph();
            var dgvmLoggedRefLog = DVM.Graphs.Last();

            Assert.True(dgvmLoggedRefLog.AvailableTypes.ToList().Exists(type => type.Model.DependsOnReference));
            Assert.True(dgvmLoggedRefLog.AvailableTypes.ToList().Exists(type => type.Model.DependsOnLogfile));
            Assert.True(dgvmLoggedRefLog.AvailableTypes.ToList().Exists(type => type.Model.DependsOnAnnotatedReference));
        }