예제 #1
0
        /// <summary>
        /// Draws from a cache or draws new visuals if neccessary.
        /// </summary>
        /// <param name="size"></param>
        public virtual void Draw(GraphSize size)
        {
            _visuals.Clear();

            CheckToleranceCache(size);
            CheckGraphCache(size);
        }
예제 #2
0
        /// <summary>
        /// Clears the cache and draws everything again.
        /// </summary>
        /// <param name="size"></param>
        public virtual void Redraw(GraphSize size)
        {
            _graphCache.Clear();
            _toleranceCache.Clear();

            Draw(size);
        }
예제 #3
0
        private Matrix3x2 GetPrintTransfrom(Rect imageableRect, GraphSize graphSize, out Size size)
        {
            var       translateVector = new Vector2((float)imageableRect.X, (float)imageableRect.Y);
            Matrix3x2 transform       = Matrix3x2.CreateTranslation(translateVector);

            if (graphSize == GraphSize.FullPage)
            {
                size = new Size(imageableRect.Width, imageableRect.Height);
            }
            else if (graphSize == GraphSize.Window)
            {
                size = _graph.RenderSize;
                double ratio = Math.Min(imageableRect.Width / size.Width, imageableRect.Height / size.Height);
                if (ratio < 1)
                {
                    transform *= Matrix3x2.CreateScale((float)ratio);
                }
            }
            else
            {
                Debug.Fail($"Unexpected GraphSize {graphSize}.");
            }

            return(transform);
        }
예제 #4
0
 /// <summary>
 /// Clears the cache of visuals that represent data.
 /// </summary>
 /// <param name="size"></param>
 public virtual void RedrawSource(GraphSize size)
 {
     if (_visuals.Count > 1)
     {
         _visuals.RemoveAt(1);
     }
     _graphCache.Clear();
     CheckGraphCache(size);
 }
예제 #5
0
        private void PrintDocument_Preview(CanvasPrintDocument sender, CanvasPreviewEventArgs args)
        {
            PrintTaskOptions       options = args.PrintTaskOptions;
            PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(options);
            Rect          imageableRect = GetImageableRect(options, args.PageNumber);
            GraphSize     size          = GetOptionValue <GraphSize>(printDetailedOptions);
            LabelLocation labelLocation = GetOptionValue <LabelLocation>(printDetailedOptions);

            DrawPage(args.DrawingSession, imageableRect, size, labelLocation);
        }
예제 #6
0
        public OutputNode(Graph owner) : base(owner)
        {
            Title       = "Output Image";
            Description = "This is the final image";
            Rectangle graphViewRectangle = owner.GetViewRectangle();

            Size     = new GraphSize(150, 60);
            Location = new GraphLocation((graphViewRectangle.X + graphViewRectangle.Width) - (Size.Width + 10), graphViewRectangle.Height / 2);
            Add(new OutputImageItem()
            {
                Size = new GraphSize(Size.Width, 30)
            });
        }
예제 #7
0
파일: InputNode.cs 프로젝트: wwwK/FlowGraph
        public InputNode(Image img, Graph owner) : base(owner)
        {
            Title       = "Input Image";
            Description = "This is the original image";
            Rectangle graphViewRectangle = owner.GetViewRectangle();

            Size     = new GraphSize(150, 60);
            Location = new GraphLocation(graphViewRectangle.X + 10, graphViewRectangle.Height / 2);
            Add(new InputImageItem(img)
            {
                Size = new GraphSize(Size.Width, 30)
            });
        }
예제 #8
0
        public IntNode(Graph owner) : base(owner)
        {
            Title       = "Int value";
            Description = "This is a interger value";
            Rectangle graphViewRectangle = owner.GetViewRectangle();

            Size     = new GraphSize(150, 60);
            Location = new GraphLocation(graphViewRectangle.Width / 2, graphViewRectangle.Height / 2);
            Add(new IntValueItem(ConnectorType.Output)
            {
                Size = new GraphSize(Size.Width, 30)
            });
        }
예제 #9
0
        public GrayScaleNode(Graph owner) : base(owner)
        {
            Title       = "Gray Scale";
            Description = "This will apply a grayscale filter to the source image";
            Rectangle graphViewRectangle = owner.GetViewRectangle();

            Location = new GraphLocation(graphViewRectangle.Width / 2, graphViewRectangle.Height / 2);
            Size     = new GraphSize(250, 100);
            Add(new GrayScaleImageItem()
            {
                Size = new GraphSize(Size.Width, 30)
            });
        }
예제 #10
0
        public MirrorNode(Graph owner, RotateFlipType type) : base(owner)
        {
            Title       = "Mirror";
            Description = "This will apply a mirror filter to the source image";
            Rectangle graphViewRectangle = owner.GetViewRectangle();

            Location = new GraphLocation(graphViewRectangle.Width / 2, graphViewRectangle.Height / 2);
            Size     = new GraphSize(250, 100);
            Add(new MirrorItem(type)
            {
                Size = new GraphSize(Size.Width, 30)
            });
        }
예제 #11
0
        private void PrintDocument_Print(CanvasPrintDocument sender, CanvasPrintEventArgs args)
        {
            PrintTaskOptions       options = args.PrintTaskOptions;
            PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(options);
            Rect          imageableRect = GetImageableRect(options, pageNumber: 1);
            GraphSize     size          = GetOptionValue <GraphSize>(printDetailedOptions);
            LabelLocation labelLocation = GetOptionValue <LabelLocation>(printDetailedOptions);

            using (CanvasDrawingSession drawingSession = args.CreateDrawingSession())
            {
                DrawPage(drawingSession, imageableRect, size, labelLocation);
            }
        }
예제 #12
0
        /// <summary>
        /// Builds the mapping between game objects and waypoints for
        /// the given graph size
        /// </summary>
        /// <param name="size">graph size</param>
        static void BuildGameObjectIdWaypointDictionary(GraphSize size)
        {
            gameObjectIdWaypoints.Clear();
            Waypoint startWaypoint = GraphUtils.GetStartWaypoint(size);

            gameObjectIdWaypoints.Add(startWaypoint.gameObject.id, startWaypoint);
            Waypoint endWaypoint = GraphUtils.GetEndWaypoint(size);

            gameObjectIdWaypoints.Add(endWaypoint.gameObject.id, endWaypoint);
            Waypoint[] waypoints = GraphUtils.GetWaypoints(size);
            foreach (Waypoint waypoint in waypoints)
            {
                gameObjectIdWaypoints.Add(waypoint.gameObject.id, waypoint);
            }
        }
예제 #13
0
 private void CheckToleranceCache(GraphSize size)
 {
     if (_toleranceCache.ContainsKey(size))
     {
         _visuals.Add(_toleranceCache[size]);
     }
     else
     {
         var visual = DrawToleranceVisual();
         if (visual != null)
         {
             _visuals.Add(visual);
             _toleranceCache.Add(size, visual);
         }
     }
 }
예제 #14
0
 private void CheckGraphCache(GraphSize size)
 {
     if (_graphCache.ContainsKey(size))
     {
         _visuals.Add(_graphCache[size]);
     }
     else
     {
         var visual = DrawGraphVisual();
         if (visual != null)
         {
             _visuals.Add(visual);
             _graphCache.Add(size, visual);
         }
     }
 }
예제 #15
0
        public void Draw(GraphSize size)
        {
            _visuals.Clear();

            if (_cache.ContainsKey(size))
            {
                _visuals.Add(_cache[size]);
            }
            else
            {
                var visual = CreateVisualFromScale(ScaleCache.Instance.Labels[size]);
                if (visual != null)
                {
                    _cache.Add(size, visual);
                    _visuals.Add(visual);
                }
            }
        }
예제 #16
0
        public ResizeNode(Graph owner) : base(owner)
        {
            Title       = "Resize";
            Description = "This will resize the image";
            Rectangle graphViewRectangle = owner.GetViewRectangle();

            Location = new GraphLocation(graphViewRectangle.Width / 2, graphViewRectangle.Height / 2);
            Size     = new GraphSize(250, 100);
            Add(new ResizeImageItem()
            {
                Size = new GraphSize(Size.Width, 30)
            });
            Add(new IntValueItem(ConnectorType.Input)
            {
                Size = new GraphSize(Size.Width, 30)
            });
            Add(new IntValueItem(ConnectorType.Input)
            {
                Size = new GraphSize(Size.Width, 30)
            });
        }
예제 #17
0
파일: MergeNode.cs 프로젝트: wwwK/FlowGraph
        public MergeNode(Graph owner) : base(owner)
        {
            Title       = "Merge Images";
            Description = "This will merge the specified images";
            Rectangle graphViewRectangle = owner.GetViewRectangle();

            Size     = new GraphSize(150, 60);
            Location = new GraphLocation(graphViewRectangle.Width / 2, graphViewRectangle.Height / 2);
            Add(new IntValueItem(ConnectorType.Input)
            {
                Size = new GraphSize(Size.Width, 20)
            });
            Add(new IntValueItem(ConnectorType.Input)
            {
                Size = new GraphSize(Size.Width, 20)
            });
            Add(new MergeInputItem()
            {
                Size = new GraphSize(Size.Width, 30)
            });
            Add(new MergeOutputItem()
            {
                Size = new GraphSize(Size.Width, 1)
            });
            Add(new MergeInputItem()
            {
                Size = new GraphSize(Size.Width, 30)
            });
            Add(new IntValueItem(ConnectorType.Input)
            {
                Size = new GraphSize(Size.Width, 20)
            });
            Add(new IntValueItem(ConnectorType.Input)
            {
                Size = new GraphSize(Size.Width, 20)
            });
        }
예제 #18
0
 virtual protected void OnGraphSizeChanged(GraphSize oldSize, GraphSize newSize)
 {
     OnGraphSizeTransitionStarted();
     VisualStateManager.GoToState(this, newSize.ToString(), true);
 }
예제 #19
0
        /// <summary>
        /// Tests the SortedLinkedList and Traveler classes
        /// </summary>
        /// <param name="args">command-line args</param>
        static void Main(string[] args)
        {
            // Graph test objects
            Graph <Waypoint> correctSmallGraph;
            Graph <Waypoint> correctMediumGraph;
            Graph <Waypoint> correctLargeGraph;

            // SearchNode test objects
            SearchNode <Waypoint> searchNode;

            // SortedLinkedList test objects
            SortedLinkedList <SearchNode <Waypoint> > testList =
                new SortedLinkedList <SearchNode <Waypoint> >();

            // GraphBuilder test object
            GraphBuilder graphBuilder;

            // Traveler test object
            Traveler traveler;

            // set up UnityEngine delegates
            GameObject.AddGetComponentDelegate(typeof(Waypoint), GetWaypointComponent);
            GameObject.AddFindObjectByTagDelegate(FindGameObjectWithTag);
            GameObject.AddFindObjectsByTagDelegate(FindGameObjectsWithTag);

            // correct graphs
            correctSmallGraph  = GraphUtils.GetCorrectGraph(GraphSize.Small);
            correctMediumGraph = GraphUtils.GetCorrectGraph(GraphSize.Medium);
            correctLargeGraph  = GraphUtils.GetCorrectGraph(GraphSize.Large);

            // loop while there's more input
            string input = Console.ReadLine();

            while (input[0] != 'q')
            {
                // extract test case number from string
                GetInputValueFromString(input);

                // execute selected test case
                switch (testCaseNumber)
                {
                case 1:
                    // test SortedLinkedList Add method with single node
                    testList.Clear();
                    testList.Add(SearchNodeUtils.GetSearchNode(Vector3.zero, 1, 0));
                    if (testList.Count == 1 &&
                        ListContentsEqual(testList, "0"))
                    {
                        Console.WriteLine("Passed");
                    }
                    else
                    {
                        Console.WriteLine("FAILED");
                    }
                    break;

                case 2:
                    // test SortedLinkedList Add method with two equal nodes
                    // (comparison is based on distance of search nodes)
                    testList.Clear();
                    testList.Add(SearchNodeUtils.GetSearchNode(Vector3.zero, 1, 0));
                    testList.Add(SearchNodeUtils.GetSearchNode(Vector3.zero, 2, 0));
                    if (testList.Count == 2 &&
                        ListContentsEqual(testList, "0c0"))
                    {
                        Console.WriteLine("Passed");
                    }
                    else
                    {
                        Console.WriteLine("FAILED");
                    }
                    break;

                case 3:
                    // test SortedLinkedList Add method with multiple unequal nodes
                    // (comparison is based on distance of search nodes)
                    testList.Clear();
                    testList.Add(SearchNodeUtils.GetSearchNode(Vector3.zero, 1, 1));
                    testList.Add(SearchNodeUtils.GetSearchNode(Vector3.zero, 2, 0));
                    testList.Add(SearchNodeUtils.GetSearchNode(Vector3.zero, 3, 2));
                    if (testList.Count == 3 &&
                        ListContentsEqual(testList, "0c1c2"))
                    {
                        Console.WriteLine("Passed");
                    }
                    else
                    {
                        Console.WriteLine("FAILED");
                    }
                    break;

                case 4:
                    // test SortedLinkedList Reposition method with
                    // no change in position
                    // (comparison is based on distance of search nodes)
                    testList.Clear();
                    testList.Add(SearchNodeUtils.GetSearchNode(Vector3.zero, 1, 1));
                    testList.Add(SearchNodeUtils.GetSearchNode(Vector3.zero, 2, 0));
                    searchNode = SearchNodeUtils.GetSearchNode(Vector3.zero, 3, 2);
                    testList.Add(searchNode);
                    testList.Reposition(searchNode);
                    if (testList.Count == 3 &&
                        ListContentsEqual(testList, "0c1c2"))
                    {
                        Console.WriteLine("Passed");
                    }
                    else
                    {
                        Console.WriteLine("FAILED");
                    }
                    break;

                case 5:
                    // test SortedLinkedList Reposition method with
                    // change in position
                    // (comparison is based on distance of search nodes)
                    testList.Clear();
                    testList.Add(SearchNodeUtils.GetSearchNode(Vector3.zero, 1, 1));
                    testList.Add(SearchNodeUtils.GetSearchNode(Vector3.zero, 2, 0));
                    searchNode = SearchNodeUtils.GetSearchNode(Vector3.zero, 3, 2);
                    testList.Add(searchNode);
                    searchNode.Distance = 0.5f;
                    testList.Reposition(searchNode);
                    if (testList.Count == 3 &&
                        ListContentsEqual(testList, "0c0.5c1"))
                    {
                        Console.WriteLine("Passed");
                    }
                    else
                    {
                        Console.WriteLine("FAILED");
                    }
                    break;

                case 6:
                    // test GraphBuilder class for small graph
                    currentSize = GraphSize.Small;
                    BuildGameObjectIdWaypointDictionary(currentSize);
                    graphBuilder = new GraphBuilder(new GameObject(int.MaxValue,
                                                                   new Transform(Vector3.zero)));
                    graphBuilder.Awake();
                    if (GraphUtils.WaypointGraphsEqual(correctSmallGraph,
                                                       GraphBuilder.Graph))
                    {
                        Console.WriteLine("Passed");
                    }
                    else
                    {
                        Console.WriteLine("FAILED");
                    }
                    break;

                case 7:
                    // test GraphBuilder class for large graph
                    currentSize = GraphSize.Large;
                    BuildGameObjectIdWaypointDictionary(currentSize);
                    graphBuilder = new GraphBuilder(new GameObject(int.MaxValue,
                                                                   new Transform(Vector3.zero)));
                    graphBuilder.Awake();
                    if (GraphUtils.WaypointGraphsEqual(correctLargeGraph,
                                                       GraphBuilder.Graph))
                    {
                        Console.WriteLine("Passed");
                    }
                    else
                    {
                        Console.WriteLine("FAILED");
                    }
                    break;

                case 8:
                    // test Traveler class for small graph
                    currentSize = GraphSize.Small;
                    BuildGameObjectIdWaypointDictionary(currentSize);
                    GraphBuilder.Graph = correctSmallGraph;
                    traveler           = new Traveler(new GameObject(int.MaxValue,
                                                                     new Transform(Vector3.zero)));
                    traveler.Start();
                    if (WithinOneHundredth(traveler.PathLength, 9))
                    {
                        Console.WriteLine("Passed");
                    }
                    else
                    {
                        Console.WriteLine("FAILED");
                    }
                    break;

                case 9:
                    // test Traveler class for medium graph
                    currentSize = GraphSize.Medium;
                    BuildGameObjectIdWaypointDictionary(currentSize);
                    GraphBuilder.Graph = correctMediumGraph;
                    traveler           = new Traveler(new GameObject(int.MaxValue,
                                                                     new Transform(Vector3.zero)));
                    traveler.Start();
                    if (WithinOneHundredth(traveler.PathLength, 18.0111f))
                    {
                        Console.WriteLine("Passed");
                    }
                    else
                    {
                        Console.WriteLine("FAILED");
                    }
                    break;

                case 10:
                    // test Traveler class for large graph
                    currentSize = GraphSize.Large;
                    BuildGameObjectIdWaypointDictionary(currentSize);
                    GraphBuilder.Graph = correctLargeGraph;
                    traveler           = new Traveler(new GameObject(int.MaxValue,
                                                                     new Transform(Vector3.zero)));
                    traveler.Start();
                    if (WithinOneHundredth(traveler.PathLength, 19.4451f))
                    {
                        Console.WriteLine("Passed");
                    }
                    else
                    {
                        Console.WriteLine("FAILED");
                    }
                    break;

                    /*
                     * // The following cases were for testing the ListContentsEqual
                     * // method and are never run by the autograder
                     * case 11:
                     * // testing ListContentsEqual method
                     * // empty sorted list
                     * testList = new SortedLinkedList<SearchNode<Waypoint>>();
                     * Console.WriteLine(ListContentsEqual(testList, ""));
                     * break;
                     * case 12:
                     * // testing ListContentsEqual method
                     * // 2 more elements in sorted list than expected
                     * testList = new SortedLinkedList<SearchNode<Waypoint>>();
                     * testList.Add(GetSearchNode(Vector3.zero,0,0));
                     * testList.Add(GetSearchNode(Vector3.zero, 0, 0));
                     * testList.Add(GetSearchNode(Vector3.zero, 0, 0));
                     * Console.WriteLine(ListContentsEqual(testList, "0"));
                     * break;
                     * case 13:
                     * // testing ListContentsEqual method
                     * // 1 more element in sorted list than expected
                     * testList = new SortedLinkedList<SearchNode<Waypoint>>();
                     * testList.Add(GetSearchNode(Vector3.zero, 0, 0));
                     * testList.Add(GetSearchNode(Vector3.zero, 0, 0));
                     * testList.Add(GetSearchNode(Vector3.zero, 0, 0));
                     * Console.WriteLine(ListContentsEqual(testList, "0,0"));
                     * break;
                     * case 14:
                     * // testing ListContentsEqual method
                     * // fewer elements in sorted list than expected
                     * testList = new SortedLinkedList<SearchNode<Waypoint>>();
                     * testList.Add(GetSearchNode(Vector3.zero, 0, 0));
                     * Console.WriteLine(ListContentsEqual(testList, "0,0"));
                     * break;
                     */
                }

                input = Console.ReadLine();
            }
        }
예제 #20
0
 public void Redraw(GraphSize size)
 {
     _cache.Clear();
     Draw(size);
 }
예제 #21
0
        private void DrawPage(CanvasDrawingSession drawingSession, Rect imageableRect, GraphSize graphSize, LabelLocation labelLocation)
        {
            drawingSession.Transform = GetPrintTransfrom(imageableRect, graphSize, out Size size);

            _graph.DrawGraph(drawingSession, size, Colors.Black);

            IReadOnlyList <IFunction> functions = _graph.Functions;

            if (functions == null || labelLocation == LabelLocation.None)
            {
                return;
            }

            // Draw function labels.
            string functionString = GetFunctionString(functions, out FuntionLocation[] locations);

            using (var layout = new CanvasTextLayout(drawingSession, functionString, LabelFormat, 100, 20))
            {
                foreach (FuntionLocation location in locations)
                {
                    int start = location.Start;
                    layout.SetColor(start, location.Length, location.Color);
                    int parenLocation = functionString.IndexOf('(', start);

                    // ++ for the f
                    layout.SetTypography(++start, parenLocation - start, SubScriptTypography);
                }

                Vector2 labelPoint = GetLabelLocation(labelLocation, layout.LayoutBounds, size);
                drawingSession.DrawTextLayout(layout, labelPoint, Colors.Black);
            }
        }