Exemplo n.º 1
0
    public static double FindDistanceToSegmentRiver(DisplayNode point, DisplayNode dpnode, DisplayNode dpnode2)
    {
        float dx = dpnode2.x - dpnode.x;
        float dy = dpnode2.y - dpnode.y;

        if ((dx == 0) && (dy == 0))
        {
            // It's a point not a line segment.
            dx = point.x - dpnode.x;
            dy = point.y - dpnode.y;
            return(Math.Sqrt(dx * dx + dy * dy));
        }
        // Calculate the t that minimizes the distance.
        float t = ((point.x - dpnode.x) * dx + (point.y - dpnode.y) * dy) / (dx * dx + dy * dy);

        // See if this represents one of the segment's
        // end points or a point in the middle.
        if (t < 0)
        {
            dx = point.x - dpnode.x;
            dy = point.y - dpnode.y;
        }
        else if (t > 1)
        {
            dx = point.x - dpnode2.x;
            dy = point.y - dpnode2.y;
        }
        else
        {
            dx = point.x - (dpnode.x + t * dx);
            dy = point.y - (dpnode.y + t * dy);
        }
        return(Math.Sqrt(dx * dx + dy * dy));
    }
Exemplo n.º 2
0
    /// <summary>
    /// Context Click selection. Here you'll need to register your own using a string identifier
    /// </summary>
    public void ContextCallback(object obj)
    {
        switch (obj.ToString())
        {
        case "calcNode":
            CalcNode.Create(new Rect(mousePos.x, mousePos.y, 200, 100));    //CalcNode calcNode = CalcNode.Create (new Rect (mousePos.x, mousePos.y, 200, 100));
            break;

        case "inputNode":
            InputNode.Create(new Rect(mousePos.x, mousePos.y, 100, 50));    //InputNode inputNode = InputNode.Create (new Rect (mousePos.x, mousePos.y, 100, 50));
            break;

        case "displayNode":
            DisplayNode.Create(new Rect(mousePos.x, mousePos.y, 100, 50));  //DisplayNode displayNode = DisplayNode.Create (new Rect (mousePos.x, mousePos.y, 100, 50));
            break;

        case "dialNode":
            DialNode.Create(new Rect(mousePos.x, mousePos.y, 200, 100));    //DialNode dialNode = DialNode.Create(new Rect(mousePos.x, mousePos.y, 200, 100));
            break;

        case "deleteNode":
            Node node = NodeAtPosition(mousePos);
            if (node != null)
            {
                nodeCanvas.nodes.Remove(node);
                node.OnDelete();
            }
            break;
        }
    }
Exemplo n.º 3
0
 public void DisplayPOINode(DisplayNode poiNode, Icon icon, string name)
 {
     if (PositionService.IsWithinBounds(poiNode.x, poiNode.y, mapData))
     {
         Vector3 nodePosition = PositionService.GetUnityPosition(poiNode, heightAdjustment, mapData);
         GenerateNodeGameObject(nodePosition, icon, name);
         GenerateLabelLine(poiNode);
     }
 }
Exemplo n.º 4
0
 private void GeneratePoiNodes(OSMData osmData)
 {
     foreach (POINode poiNode in osmData.poiNodes)
     {
         DisplayNode displayNode = ChangeLatLonToDisplayNode(poiNode.lon, poiNode.lat, mapData);
         Icon        icon        = iconHandler.SelectIcon(poiNode.icon);
         poiDisplay.DisplayPOINode(displayNode, icon, poiNode.name);
     }
 }
Exemplo n.º 5
0
    public void GenerateNode(DisplayNode node)
    {
        if (!PositionService.IsWithinBounds(node.x, node.y, mapData))
        {
            return;
        }
        Vector3 nodePosition = PositionService.GetUnityPosition(node, lineHeightAdjustment, mapData);

        this.nodePositions.Add(nodePosition);
    }
    public override Node Create(Vector2 pos)
    {     // This function has to be registered in Node_Editor.ContextCallback
        DisplayNode node = CreateInstance <DisplayNode> ();

        node.name = "Display Node";
        node.rect = new Rect(pos.x, pos.y, 150, 50);

        NodeInput.Create(node, "Value", "Float");

        return(node);
    }
Exemplo n.º 7
0
    public static DisplayNode Create(Rect NodeRect)
    {     // This function has to be registered in Node_Editor.ContextCallback
        DisplayNode node = ScriptableObject.CreateInstance <DisplayNode> ();

        node.name = "Display Node";
        node.rect = NodeRect;

        NodeInput.Create(node, "Value", typeof(float));

        node.Init();
        return(node);
    }
Exemplo n.º 8
0
    public static Vector3 GetUnityPosition(DisplayNode node, float heightAdjustment, MapData mapData)
    {
        float height = mapData.GetNormalized(node.x, node.y);

        float xFromCenter = node.x - mapData.GetWidth() / 2;
        float yFromCenter = (mapData.GetHeight() / 2) - node.y;

        float scale = 1 / ((float)Mathf.Max(mapData.GetWidth(), mapData.GetHeight()) - 1);

        Vector3 nodePosition = new Vector3((float)xFromCenter * scale, height + heightAdjustment, (float)yFromCenter * scale);

        return(nodePosition);
    }
Exemplo n.º 9
0
 public bool InRiver(List <DisplayNode> displayNodes, float x, float y)
 {
     for (int i = 0; i < displayNodes.Count - 1; i++)
     {
         DisplayNode point      = new DisplayNode((int)x, (int)y);
         DisplayNode riverNode1 = displayNodes[i];
         DisplayNode riverNode2 = displayNodes[i + 1];
         if (SegmentUtil.FindDistanceToSegmentRiver(point, riverNode1, riverNode2) < riverWidthConstant)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 10
0
    private bool IsPointInPolygon(List <DisplayNode> areaBounds, DisplayNode point)
    {
        int  i, j;
        bool c = false;

        for (i = 0, j = areaBounds.Count - 1; i < areaBounds.Count; j = i++)
        {
            if ((((areaBounds[i].x <= point.x) && (point.x < areaBounds[j].x)) ||
                 ((areaBounds[j].x <= point.x) && (point.x < areaBounds[i].x))) &&
                (point.y < (areaBounds[j].y - areaBounds[i].y) * (point.x - areaBounds[i].x)
                 / (areaBounds[j].x - areaBounds[i].x) + areaBounds[i].y))
            {
                c = !c;
            }
        }
        return(c);
    }
Exemplo n.º 11
0
            // add display node

            // @params

            // Node newNode -> Node contains all data for the Node. This is a simple way to instantiate its display representation;

            // Node parentNode -> parent node is stored to draw parent/child relationships graphically.

            // int level -> Level indicates the depth of the Node. This will be stored to later represent the Y position of the Node.

            // int numberLevelNodes -> value indicates the number of nodes at the passed level value. This is used to calculate the X position of the node.

            // int levelPosition -> value indicates X position of the current node. Level may contain 0 - numberLevelNodes nodes. X position will depend on the value contained herein.

            // DisplayNode displayNode -> if parameter is null, instantiate new display node; else -> use this parameter as adding display node.

            public void AddDisplayNode(Node newNode, DisplayNode parentNode, int level, int numberLevelNodes, int levelPosition, DisplayNode newDisplayNode)
            {
                DisplayNode displayNode = null;


                if (newDisplayNode == null)
                {
                    displayNode = new DisplayNode();
                }
                else
                {
                    displayNode = newDisplayNode;
                }

                // TODO: Display Node can contain node string

                displayNode.SetDisplayStr(newNode.getNodeStr());

                displayNode.SetParent(parentNode);

                displayNode.SetLevel(level);

                // node partition width

                int nodePartitionWidth = width / numberLevelNodes;

                int displayNodeX = nodePartitionWidth * levelPosition;

                nodePartitionWidth /= 2;

                displayNodeX += nodePartitionWidth;

                displayNodeX -= nodeSize / 2;

                displayNode.SetX(displayNodeX);

                nodes.Add(displayNode);

                Console.WriteLine("Node: " + displayNode);

                Console.WriteLine("Add Display Node Parameters; Level: " + level + " NumberLevelNodes: " + numberLevelNodes + " LevelPosition: " + levelPosition);
            }
Exemplo n.º 12
0
    public void FindDistanceToSegmentRiverTest()
    {
        DisplayNode dpnode  = new DisplayNode(4, 4);
        DisplayNode dpnode2 = new DisplayNode(4, 4);
        DisplayNode point   = new DisplayNode(6, 4);

        Assert.AreEqual(SegmentUtil.FindDistanceToSegmentRiver(point, dpnode, dpnode2), 2);
        dpnode  = new DisplayNode(4, 4);
        dpnode2 = new DisplayNode(6, 6);
        point   = new DisplayNode(6, 6);
        Assert.AreEqual(SegmentUtil.FindDistanceToSegmentRiver(point, dpnode, dpnode2), (double)0.0);
        dpnode  = new DisplayNode(12, 12);
        dpnode2 = new DisplayNode(18, 18);
        point   = new DisplayNode(6, 16);
        Assert.AreEqual(SegmentUtil.FindDistanceToSegmentRiver(point, dpnode, dpnode2), 7.211102550927978);
        dpnode  = new DisplayNode(24, 24);
        dpnode2 = new DisplayNode(18, 18);
        point   = new DisplayNode(6, 16);
        Assert.AreEqual(SegmentUtil.FindDistanceToSegmentRiver(point, dpnode, dpnode2), 12.165525060596439);
    }
Exemplo n.º 13
0
    public void GenerateLabelLine(DisplayNode poiNode)
    {
        GameObject labelLine = new GameObject();

        LineRenderer lineRenderer = labelLine.AddComponent <LineRenderer>();

        lineRenderer.positionCount = 2;
        Vector3[] endpoints = new Vector3[] {
            PositionService.GetUnityPosition(poiNode, heightAdjustment, mapData),
            PositionService.GetUnityPosition(poiNode, 0, mapData)
        };
        lineRenderer.SetPositions(endpoints);
        lineRenderer.widthMultiplier = this.lineWidthMultiplier;
        lineRenderer.useWorldSpace   = false;

        labelLine.transform.SetParent(this.transform);

        Material[] materials = new Material[] { new Material(Shader.Find("Unlit/Color")) };
        labelLine.GetComponent <Renderer>().sharedMaterials      = materials;
        labelLine.GetComponent <Renderer>().sharedMaterial.color = ColorHandler.SelectColor("poiLine");
    }
Exemplo n.º 14
0
        public void Setup()
        {
            m_ConverterPoint = new Point(11.0,
                                         22.0);
            m_Converter = Substitute.For <IGeometryPointToWindowsPointConverter>();
            m_Converter.Point.Returns(m_ConverterPoint);

            m_Point = new Point(1.0,
                                2.0);

            m_StrokeBrush = Brushes.Aqua;
            m_FillBrush = Brushes.Yellow;

            m_Sut = new DisplayNode(m_Converter,
                                    1,
                                    m_Point.X,
                                    m_Point.Y,
                                    3.0,
                                    4.0,
                                    m_FillBrush,
                                    m_StrokeBrush,
                                    5.0);
        }
        public MainWindow()
        {
            InitializeComponent();



            context = new NodeGraphContext();

            nodeChest = new NodeChest(context);

            SimpleNode sm = new SimpleNode();

            nodeChest.addNode(sm.Node);

            graph = new NodeGraph(context);
            graph.pipeStiffness = 0;

            container.Children.Add(graph);
            //chestContainer.Children.Add(nodeChest);


            nodeChest.ScrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;

            ConstantNode node = new ConstantNode();

            node.Node.position = new Point(50, 50);

            DisplayNode node2 = new DisplayNode();

            node2.Node.position = new Point(500, 30);

            graph.addNode(node.Node);
            graph.addNode(node2.Node);

            new Connection(node.Node.getOutputs()[0], node2.Node.getInputs()[0]);
        }
Exemplo n.º 16
0
        public void Test40()
        {
            // Step 1: create an arbitrary acyclical pipeline with an input and a manipulation node
            MainViewModel  mvm   = MainViewModelTest.GetInstance();
            VideoInputNode video = new VideoInputNode();
            BlurNode       blur  = new BlurNode()
            {
                Type = BlurType.Gaussian, Radius = 3
            };
            DisplayNode display = new DisplayNode();
            // We'll have to dump this node's output later, so we need a ViewModel
            NodeViewModel blurVM = new NodeViewModel(blur, mvm.PipelineViewModel);

            mvm.Model.Graph.AddNode(video);
            mvm.Model.Graph.AddNode(blur);
            mvm.Model.Graph.AddNode(display);
            mvm.Model.Graph.AddEdge(video.Outputs[0], blur.Inputs[0]);
            mvm.Model.Graph.AddEdge(blur.Outputs[0], display.Inputs[0]);
            // Assert that the graph is well-formed
            Assert.Contains(video, mvm.Model.Graph.Nodes);
            Assert.Contains(blur, mvm.Model.Graph.Nodes);
            Assert.Contains(display, mvm.Model.Graph.Nodes);
            Assert.Equal(blur.Inputs[0].Source, video.Outputs[0]);
            Assert.Equal(display.Inputs[0].Source, blur.Outputs[0]);

            // Step 2: change the video input data
            Assert.False(display.InputIsValid);
            video.FileName = new FilePath(@"..\..\..\..\resources\americanFootball_352x240_125.yuv");
            Assert.True(display.InputIsValid);

            // Step 3: open the DisplayNode's output and play the video
            DisplayViewModel output = display.Window;

            Assert.Equal(display, output.NodeModel);

            Assert.False(mvm.Model.IsPlaying);
            mvm.ReplayStateViewModel.PlayPause();
            Assert.True(mvm.Model.IsPlaying);

            // Step 4: Change a node's options while the video is playing
            blur.Radius = 0;
            Assert.True(mvm.Model.IsPlaying);
            Assert.True(display.InputIsValid);

            // Step 5: change replay speed while video is playing
            int oldSpeed = mvm.Model.Speed;

            mvm.ReplayStateViewModel.Slower();
            Assert.True(oldSpeed > mvm.Model.Speed);

            // Step 6: pause the video
            mvm.ReplayStateViewModel.PlayPause();
            Assert.False(mvm.Model.IsPlaying);

            // Step 7: resumes the video
            mvm.ReplayStateViewModel.PlayPause();
            Assert.True(mvm.Model.IsPlaying);

            // Step 8: resets the video playing state
            mvm.ReplayStateViewModel.Stop();
            Assert.Equal(0, mvm.Model.CurrentTick);
            Assert.False(mvm.Model.IsPlaying);

            // Step 9: save the video as yuv file
            blurVM.SaveNodeOutput(blur.Outputs[0]);
            // Since we can't create a FileChooser here, we'll have to invoke the SaveNodeOutputViewModel directly
            System.IO.MemoryStream  stream = new System.IO.MemoryStream();
            SaveNodeOutputViewModel saveVM = new SaveNodeOutputViewModel(blur.Outputs[0], stream, mvm.Model);

            Assert.Equal(mvm.Model.Graph.TickCount, saveVM.TickCount);
            // I'm sorry for this. I really am. I found no better way of testing this.
            System.Threading.Thread.Sleep(1000);
            try {
                Assert.NotEqual(0, stream.Capacity);
            } catch (ObjectDisposedException) {
                // This means the SaveNodeOutputViewModel is already done and has disposed of its stream
                // That's just another possibility that's just as valid, and signifies proper execution
            }
        }
Exemplo n.º 17
0
        public DisplayTree search(NodeTree tree, String targetString)
        {
            // memory to maintain unvisited children

            List <Node> queue = new List <Node>();

            // iterate over all nodes (breadth first search)

            queue.Add(tree.GetTreeA());

            int currentLevelCount = 1;

            int nextLevelCount = 0;

            int currentLevel = 1;

            Console.WriteLine("First Level: " + currentLevel);

            Node currentNode = null;

            // counter to begin iterating over newly added children to instantiate display nodes

            int displayIterBegin = 1;

            // counter to end iterating over newly added children to instantiate display nodes

            int displayIterEnd = 1;

            // test if display tree has been instantiated

            if (displayTree == null)
            {
                displayTree = new DisplayTree(width, height, nodeSize);
            }

            DisplayNode currentParentDisplayNode = new DisplayNode();

            // add the root display node

            displayTree.AddDisplayNode(queue.ElementAt(0), null, currentLevel, 1, nextLevelCount, currentParentDisplayNode);

            List <DisplayNode> childDisplayNodes = new List <DisplayNode>();

            List <DisplayNode> parentDisplayNodes = new List <DisplayNode>();

            parentDisplayNodes.Add(currentParentDisplayNode);

            List <Node> childNodes = new List <Node>();

            while (queue.Count > 0)
            {
                currentNode = queue.ElementAt(0);

                queue.RemoveAt(0);

                // get current parent display node

                currentParentDisplayNode = parentDisplayNodes.ElementAt(0);

                parentDisplayNodes.RemoveAt(0);

                Console.WriteLine("Current Node Str: " + currentNode.getNodeStr());

                Node currentNodeChild = null;

                while ((currentNodeChild = currentNode.getNextChild()) != null)
                {
                    queue.Add(currentNodeChild);

                    nextLevelCount++;

                    displayIterEnd++;

                    DisplayNode displayNode = new DisplayNode();

                    displayNode.SetParent(currentParentDisplayNode);

                    childDisplayNodes.Add(displayNode);

                    childNodes.Add(currentNodeChild);
                }

                currentLevelCount--;

                if (queue.Count > 0)
                {
                    if (currentLevelCount == 0)
                    {
                        parentDisplayNodes.Clear();

                        currentLevel++;

                        for (int levelCounter = 0; levelCounter < childDisplayNodes.Count; levelCounter++)
                        {
                            // add the display node

                            displayTree.AddDisplayNode(childNodes.ElementAt(levelCounter), childDisplayNodes.ElementAt(levelCounter).GetParent(), currentLevel, nextLevelCount, levelCounter, childDisplayNodes.ElementAt(levelCounter));

                            parentDisplayNodes.Add(childDisplayNodes.ElementAt(levelCounter));
                        }

                        Console.WriteLine("Level has incremented! " + currentLevel);

                        currentLevelCount = nextLevelCount;

                        nextLevelCount = 0;

                        childDisplayNodes.Clear();

                        childNodes.Clear();
                    }
                }
            }

            Console.WriteLine("Final Current Level: " + currentLevel);

            displayTree.CalculateDisplayTreeYValues(currentLevel);

            return(displayTree);
        }
Exemplo n.º 18
0
 public void SetParent(DisplayNode newParent)
 {
     parent = newParent;
 }
Exemplo n.º 19
0
    public void AddDisplayNode(OSMNode node)
    {
        DisplayNode displayNode = ChangeLatLonToDisplayNode(node.lon, node.lat, mapData);

        displayNodes.Add(displayNode);
    }
Exemplo n.º 20
0
        /// <summary>
        /// Get a list of display nodes in depth-first order.
        /// </summary>
        /// <returns></returns>
        internal IList <DisplayNode> GetDisplayNodes()
        {
            if (NumPoses == 0)
            {
                return(Array.Empty <DisplayNode>());
            }
            var nodesOut = new List <DisplayNode>(NumPoses);

            // List of children for each node
            var tree = new Dictionary <int, List <int> >();

            for (var i = 0; i < NumPoses; i++)
            {
                var parent = GetParentIndex(i);
                if (i == -1)
                {
                    continue;
                }

                if (!tree.ContainsKey(parent))
                {
                    tree[parent] = new List <int>();
                }
                tree[parent].Add(i);
            }

            // Store (index, depth) in the stack
            var stack = new Stack <(int, int)>();

            stack.Push((0, 0));

            while (stack.Count != 0)
            {
                var(current, depth) = stack.Pop();
                var obj = GetObjectAt(current);

                var node = new DisplayNode
                {
                    NodeObject    = obj,
                    Enabled       = IsPoseEnabled(current),
                    OriginalIndex = current,
                    Depth         = depth
                };
                nodesOut.Add(node);

                // Add children
                if (tree.ContainsKey(current))
                {
                    // Push to the stack in reverse order
                    var children = tree[current];
                    for (var childIdx = children.Count - 1; childIdx >= 0; childIdx--)
                    {
                        stack.Push((children[childIdx], depth + 1));
                    }
                }

                // Safety check
                // This shouldn't even happen, but in case we have a cycle in the graph
                // exit instead of looping forever and eating up all the memory.
                if (nodesOut.Count > NumPoses)
                {
                    return(nodesOut);
                }
            }

            return(nodesOut);
        }
 public DisplayNodeAndEdges(DisplayNode displayNode, IBidirectionalGraph <DisplayNode, DisplayEdge> owner)
 {
     DisplayNode = displayNode;
     _owner      = owner;
 }
Exemplo n.º 22
0
		public DisplayViewModel(DisplayNode node)
			: base(node, null)
		{
			NodeModel = node;
		}
Exemplo n.º 23
0
 public DisplayViewModel(DisplayNode node)
     : base(node, null)
 {
     NodeModel = node;
 }