Esempio n. 1
0
        /// <summary>
        /// Intantiates a new object of this class.
        /// </summary>
        public GameBoard()
        {
            this.tileValueGrid      = new int?[this.maxGameBoardSize + 1, this.maxGameBoardSize + 1];
            this.tileGrid           = new TriominoTile[this.maxGameBoardSize, this.maxGameBoardSize];
            this.NumbTilesOnBoard   = 0;
            this.tilesWithFreeFaces = new Dictionary <string, List <TileFace> >();

            List <Vertex>    vertices      = new List <Vertex>();
            List <HyperEdge> twoSidedEdges = new List <HyperEdge>();

            for (int i = 0; i < 6; i++)
            {
                for (int j = i; j < 6; j++)
                {
                    vertices.Add(new Vertex(i + "" + j));
                    if (i != j)
                    {
                        vertices.Add(new Vertex(j + "" + i));
                    }

                    twoSidedEdges.Add(new HyperEdge(i + "" + j, j + "" + i));
                }
            }

            tileGraph = new HyperGraph(vertices);
            foreach (HyperEdge twoSidedEdge in twoSidedEdges)
            {
                tileGraph.AddEdge(twoSidedEdge);
            }
        }
        public void HyperGraph_GetAdjacentEdges_has_to_work()
        {
            HyperGraph hyperGraph = new HyperGraph();
            Vertex     v1         = hyperGraph.AddVertex("00");
            Vertex     v2         = hyperGraph.AddVertex("01");
            Vertex     v3         = hyperGraph.AddVertex("10");

            HyperEdge h1 = hyperGraph.AddEdge("00", "00", "00");
            HyperEdge h2 = hyperGraph.AddEdge("00", "01", "10");
            HyperEdge h3 = hyperGraph.AddEdge("00", "00");
            HyperEdge h4 = hyperGraph.AddEdge("01", "10");

            List <HyperEdge> neighbors = hyperGraph.GetAdjacentEdges(v1).ToList();

            Assert.AreEqual(3, neighbors.Count);
            Assert.IsTrue(neighbors.Contains(h1));
            Assert.IsTrue(neighbors.Contains(h2));
            Assert.IsTrue(neighbors.Contains(h3));

            neighbors = hyperGraph.GetAdjacentEdges(v2).ToList();
            Assert.AreEqual(2, neighbors.Count);
            Assert.IsTrue(neighbors.Contains(h2));
            Assert.IsTrue(neighbors.Contains(h4));

            neighbors = hyperGraph.GetAdjacentEdges(v2, 2).ToList();
            Assert.AreEqual(1, neighbors.Count);
            Assert.IsTrue(neighbors.Contains(h4));

            neighbors = hyperGraph.GetAdjacentEdges(v2, 3).ToList();
            Assert.AreEqual(1, neighbors.Count);
            Assert.IsTrue(neighbors.Contains(h2));
        }
        public void GraphGenerator_Create_Triomino_Graph_has_to_work()
        {
            HyperGraph triominoGraph = GraphGenerator.CreateTriominoGraph();

            Assert.AreEqual(56, triominoGraph.Edges.Where(e => e.IsThreeSidedEdge()).Count());
            Assert.AreEqual(21, triominoGraph.Edges.Where(e => e.IsTwoSidedEdge()).Count());
        }
Esempio n. 4
0
        public void GetAllCycles_must_work()
        {
            string     path       = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName, "TestFiles", "tEdgeGraph.txt");
            HyperGraph hyperGraph = GraphGenerator.LoadHyperGraphFromFile(path);

            List <List <Tuple <HyperEdge, string> > > cycles = hyperGraph.GetAllSimpleCycles2();
        }
Esempio n. 5
0
 public CircularLayoutAlgorithm(HyperGraph graph,
                                IDictionary <Vertex, Point> vertexPositions,
                                IDictionary <Vertex, Size> vertexSizes)
 {
     Graph           = graph;
     VertexPositions = vertexPositions;
     VertexSizes     = vertexSizes;
 }
        public void HyperGraph_AddVertex_has_to_work()
        {
            HyperGraph hyperGraph = new HyperGraph();
            Vertex     v1         = hyperGraph.AddVertex("00");

            Assert.AreEqual(v1, hyperGraph.Vertices.First());
            Assert.IsFalse(hyperGraph.AddVertex(new Vertex("00")));
            Assert.AreEqual(v1, hyperGraph.AddVertex("00"));
        }
Esempio n. 7
0
        public void HyperGraph_must_work()
        {
            string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName, "TestFiles", "tEdgePieces.txt");
            //string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "TestFiles", "tEdgePieces.txt");

            HyperGraph hyperGraph = GraphGenerator.LoadHyperGraphFromFile(path);

            //Tuple<string, int>[] degrees = hyperGraph.GetVertexDegrees();
            Tuple <string, int>[] degrees = hyperGraph.GetVertexEulerDegrees();

            int greenEdgeDegree = 0;
            int redEdgeDegree   = 0;
            int redEdgeCount    = 0;
            int greenEdgeCount  = 0;
            int evenEdgeDegree  = 0;
            int evenEdgeCount   = 0;
            int maxDegree       = degrees.Select(d => d.Item2).Max();

            Tuple <string, int>[] maxDegrees = degrees.Where(d => d.Item2 == 6).ToArray();

            foreach (Tuple <string, int> tuple in degrees)
            {
                int i = Convert.ToInt32(tuple.Item1[0]);
                int j = Convert.ToInt32(tuple.Item1[1]);

                if (i < j)
                {
                    greenEdgeDegree += tuple.Item2;
                    greenEdgeCount++;
                }
                else if (i > j)
                {
                    redEdgeDegree += tuple.Item2;
                    redEdgeCount++;
                }
                else
                {
                    evenEdgeDegree += tuple.Item2;
                    evenEdgeCount++;
                }
            }

            Tuple <string, int>[] orderedDegrees = degrees.OrderBy(t => t.Item2).ThenBy(t => t.Item1).ToArray();

            string outputPath = @"C:\Users\Moritz\Dropbox\Studium\Fulda\5_SS19\Project\Triominos\Graphsuite\GraphSuite\Files";
            string outputFile = "tEdgePiecesEulerDegrees.txt";

            if (File.Exists(Path.Combine(outputPath, outputFile)))
            {
                File.Delete(Path.Combine(outputPath, outputFile));
            }

            File.WriteAllLines(Path.Combine(outputPath, outputFile), degrees.OrderBy(x => x.Item1).Select(d => d.Item1 + " => " + d.Item2));
            //Tuple<int, Stack<Tuple<string, HyperEdge<string>>>>[] cycles = hyperGraph.GetAllSimpleCycles();
        }
        public HyperGraphViewModel(HyperGraph graph)
        {
            Graph = graph;

            InvalidateMeasureButtonCommand =
                ReactiveCommand.Create <PocHyperGraphLayout>(OnInvalidateMeasureButtonCommand);
            InvalidateArrangeButtonCommand =
                ReactiveCommand.Create <PocHyperGraphLayout>(OnInvalidateArrangeButtonCommand);
            ReLayoutCommand       = ReactiveCommand.Create <PocHyperGraphLayout>(OnReLayoutCommand);
            SaveGraphImageCommand = ReactiveCommand.Create <PocHyperGraphLayout>(OnSaveGraphImageCommand);
        }
            public static HyperGraph ReadGraph(string inFilename)
            {
                StreamReader srGraph     = new StreamReader(inFilename);
                int          modalityNum = Convert.ToInt32(srGraph.ReadLine());
                int          nodeNum     = Convert.ToInt32(srGraph.ReadLine());

                List <SingleNode>[] nodes = new List <SingleNode> [modalityNum];
                for (int i = 0; i < modalityNum; i++)
                {
                    nodes[i] = new List <SingleNode>();
                }
                List <Edge> edges = new List <Edge>();

                for (int i = 0; i < nodeNum; i++)
                {
                    string[]      items     = srGraph.ReadLine().Split(new char[] { ':', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    int           modality  = Convert.ToInt32(items[0]);
                    int           index     = Convert.ToInt32(items[1]);
                    int           count     = items.Count();
                    int           day       = Convert.ToInt32(items[count - 1]);
                    int           label     = Convert.ToInt32(items[count - 2]);
                    int           gridIndex = Convert.ToInt32(items[count - 3]);
                    List <double> data      = new List <double>();
                    for (int j = 2; j < count - 3; j++)
                    {
                        data.Add(Convert.ToDouble(items[j]));
                    }
                    nodes[modality - 1].Add(new SingleNode(index, data, label, modality, gridIndex, day));
                }

                int edgeNum = Convert.ToInt32(srGraph.ReadLine());

                while (srGraph.Peek() > 0)
                {
                    string[] items   = srGraph.ReadLine().Split(new char[] { ' ' });
                    int      startID = Convert.ToInt32(items[0]);
                    int      endID   = Convert.ToInt32(items[1]);
                    double   weight  = Convert.ToDouble(items[2]);
                    int      type    = Convert.ToInt32(items[3]);
                    edges.Add(new Edge(startID, endID, weight, type));
                }
                srGraph.Close();

                HyperGraph graph = new HyperGraph(nodes, edges);

                return(graph);
            }
        public static async Task <HyperGraph> CollectionToHyperGraphTaskAsync(
            IMongoCollection <BsonDocument> bsonDocCollection)
        {
            var hyperGraph = new HyperGraph(bsonDocCollection.CollectionNamespace.CollectionName);

            await foreach (var keys in ParseCollectionAsync(bsonDocCollection.AsQueryable()))
            {
                var edge = new HyperEdge {
                    Weight = 1
                };

                foreach (var key in keys)
                {
                    var vertex = hyperGraph.Vertices.FirstOrDefault(v => v.Data?.Equals(key) ?? false);
                    if (vertex is null)
                    {
                        vertex = new Vertex(key);
                        hyperGraph.Vertices.Add(vertex);
                    }

                    vertex.HyperEdges.Add(edge);
                    edge.Vertices.Add(vertex);
                }

                var existHyperEdge = hyperGraph.HyperEdges.FirstOrDefault(he => he.Vertices.SetEquals(edge.Vertices));
                if (existHyperEdge is null)
                {
                    hyperGraph.HyperEdges.Add(edge);
                }
                else
                {
                    foreach (var vertex in edge.Vertices)
                    {
                        vertex.HyperEdges.RemoveWhere(e => e.Id == edge.Id);
                        vertex.HyperEdges.Add(existHyperEdge);
                    }

                    existHyperEdge.Weight++;
                }
            }

            return(hyperGraph);
        }
        public void HyperGraph_has_to_work()
        {
            string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName, "TestFiles", "tEdgeGraph.txt");
            //string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "TestFiles", "tEdgePieces.txt");

            HyperGraph hyperGraph = GraphGenerator.LoadHyperGraphFromFile(path);

            //Tuple<string, int>[] degrees = hyperGraph.GetVertexDegrees();
            Tuple <string, int>[] degrees = hyperGraph.GetVertexEulerDegrees();

            string outputPath = @"C:\Users\Moritz\source\repos\GraphSuite\Files";
            string outputFile = "tEdgeEulerDegrees.txt";

            if (File.Exists(Path.Combine(outputPath, outputFile)))
            {
                File.Delete(Path.Combine(outputPath, outputFile));
            }

            File.WriteAllLines(Path.Combine(outputPath, outputFile), degrees.OrderBy(x => x.Item1).Select(d => d.Item1 + " => " + d.Item2));
            //Tuple<int, Stack<Tuple<string, HyperEdge<string>>>>[] cycles = hyperGraph.GetAllSimpleCycles();
        }
        public void GetTileSideStructure()
        {
            string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName, "TestFiles", "tEdgePieces.txt");
            //string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "TestFiles", "tEdgePieces.txt");

            HyperGraph hyperGraph = GraphGenerator.LoadHyperGraphFromFile(path);

            Dictionary <string, int> tileSideStructure = new Dictionary <string, int>();

            int structureCount = 0;

            foreach (HyperEdge edge in hyperGraph.Edges)
            {
                structureCount = edge.GreenSideCount() * 100 + edge.BlueSideCount() * 10 + edge.RedSideCount();

                tileSideStructure.Add(edge.ToString(), structureCount);
            }

            //Dictionary<string, int> onlyblue = tileSideStructure.Where(kv => kv.Value % 10 == 0).ToDictionary(kv => kv.Key, kv => kv.Value);
            //Dictionary<string, int> onlyGreen = tileSideStructure.Where(kv => kv.Value % 100 == 0).ToDictionary(kv => kv.Key, kv => kv.Value);
            //Dictionary<string, int> containsBlueAndGreen = tileSideStructure.Where(kv => kv.Value > 100 && (kv.Value % 100) >= 10).ToDictionary(kv => kv.Key, kv => kv.Value);
            //Dictionary<string, int> rest = tileSideStructure.Where(kv => !onlyblue.Keys.Contains(kv.Key) && !containsBlueAndGreen.Keys.Contains(kv.Key)).ToDictionary(kv => kv.Key, kv => kv.Value);
            //Dictionary<string, int> redAndBlue = tileSideStructure.Where(kv => kv.Value % 2 == 1).ToDictionary(kv => kv.Key, kv => kv.Value);

            HyperEdge[] onlyBlue        = hyperGraph.Edges.Where(e => e.BlueSideCount() == 3).ToArray();
            HyperEdge[] onlyGreen       = hyperGraph.Edges.Where(e => e.GreenSideCount() == 3).ToArray();
            HyperEdge[] onlyRed         = hyperGraph.Edges.Where(e => e.RedSideCount() == 3).ToArray();
            HyperEdge[] twoBlueOneGreen = hyperGraph.Edges.Where(e => e.BlueSideCount() == 2 && e.GreenSideCount() == 1).ToArray();
            HyperEdge[] twoBlueOneRed   = hyperGraph.Edges.Where(e => e.BlueSideCount() == 2 && e.RedSideCount() == 1).ToArray();
            HyperEdge[] twoGreenOneBlue = hyperGraph.Edges.Where(e => e.BlueSideCount() == 1 && e.GreenSideCount() == 2).ToArray();
            HyperEdge[] twoGreenOneRed  = hyperGraph.Edges.Where(e => e.RedSideCount() == 1 && e.GreenSideCount() == 2).ToArray();
            HyperEdge[] greenRedBlue    = hyperGraph.Edges.Where(e => e.BlueSideCount() == 1 && e.GreenSideCount() == 1 && e.RedSideCount() == 1).ToArray();
            HyperEdge[] moreThanOneRed  = hyperGraph.Edges.Where(e => e.RedSideCount() > 1).ToArray();

            //30 = 6
            //201 = 20
            //111 = 30
        }
        public void HyperGraph_AddEdge_has_to_work()
        {
            HyperGraph hyperGraph = new HyperGraph();

            Assert.ThrowsException <ArgumentException>(() => { hyperGraph.AddEdge("00", "00", "00"); }, "This graph does not conatin a vertex with value '00'.");

            Vertex    v1 = hyperGraph.AddVertex("00");
            HyperEdge h1 = hyperGraph.AddEdge("00", "00", "00");

            Assert.AreEqual(3, h1.VertexCount());
            Assert.IsTrue(h1.ContainsOnVertexBasis(v1));

            HyperEdge h2 = new HyperEdge("00", "01", "10");

            Assert.ThrowsException <ArgumentException>(() => { hyperGraph.AddEdge(new Vertex("00"), new Vertex("01"), new Vertex("10")); }, $"This graph does not conatin a vertex with value '01'");

            Vertex v2 = hyperGraph.AddVertex("11");
            Vertex v3 = hyperGraph.AddVertex("01");
            Vertex v4 = hyperGraph.AddVertex("10");

            Assert.ThrowsException <ArgumentException>(() => hyperGraph.AddEdge(v2, v2, v2), "Vertices must not be equal.");
            HyperEdge h3 = hyperGraph.AddEdge(v1, v3, v4);

            Assert.IsTrue(h3.ContainsOnVertexBasis(v1));
            Assert.IsTrue(h3.ContainsOnVertexBasis(v3));
            Assert.IsTrue(h3.ContainsOnVertexBasis(v4));

            Assert.IsFalse(h3.ContainsOnEdgeBasis(v1));
            Assert.IsFalse(h3.ContainsOnEdgeBasis(v3));
            Assert.IsFalse(h3.ContainsOnEdgeBasis(v4));

            HyperEdge h4 = new HyperEdge(new Vertex("00"), new Vertex("01"), new Vertex("10"));

            Assert.IsTrue(hyperGraph.HasEdge(h4));
            Assert.ThrowsException <ArgumentException>(() => { hyperGraph.AddEdge(new Vertex("00"), new Vertex("01"), new Vertex("10")); }, $"This Graph has already an edge '-00-01-10->'.");
            Assert.ThrowsException <ArgumentException>(() => { hyperGraph.AddEdge("00", "01", "10"); }, $"This Graph has already an edge '-00-01-10->'.");
        }
Esempio n. 14
0
        public void AddToHyperGraph(ShaderPatcherLayer.NodeGraph nodeGraph, HyperGraph.IGraphModel graph)
        {
                //
                //      Convert from the "ShaderPatcherLayer" representation back to
                //      our graph control nodes. 
                //
                //      This is required for robust serialisation. We can't easily
                //      serialise in and out the graph control objects directly, because
                //      it risks problems if the rendering code or shader fragment objects
                //      change. That is, it's not very version-robust.
                //
                //      It's better to serialise a slightly higher level representation
                //      that just contains the node names and connections. That way, we 
                //      can adapt to changes in the tool and data.
                //
            {
                    // --------< Basic Nodes >--------
                var newNodes = new Dictionary<int, Node>();
                var nodeIdToControlNode = new Dictionary<UInt64, Node>();
                foreach (var n in nodeGraph.Nodes)
                {
                    if (!newNodes.ContainsKey(n.VisualNodeId))
                    {
                        var visualNode = nodeGraph.VisualNodes[n.VisualNodeId];

                        // also look for preview settings...
                        var previewSettings = nodeGraph.PreviewSettingsObjects.Where(x => x.VisualNodeId == n.VisualNodeId).FirstOrDefault();
                        Node newNode = null;
                        if (n.NodeType == ShaderPatcherLayer.Node.Type.Procedure)
                        {
                            var fn = _shaderFragments.GetFunction(n.FragmentArchiveName);
                            newNode = _nodeCreator.CreateNode(fn, n.FragmentArchiveName, previewSettings);
                        }
                        else
                        {
                            var ps = _shaderFragments.GetParameterStruct(n.FragmentArchiveName);
                            newNode = _nodeCreator.CreateParameterNode(ps, n.FragmentArchiveName, AsSourceType(n.NodeType));
                        }

                        if (newNode != null)
                        {
                            MatchVisualNode(newNode, visualNode);
                            newNodes[n.VisualNodeId] = newNode;
                            nodeIdToControlNode[n.NodeId] = newNode;
                        }
                    }
                }

                graph.AddNodes(newNodes.Values);

                    // --------< Node Connections >--------
                foreach (var c in nodeGraph.NodeConnections)
                {
                    if (nodeIdToControlNode.ContainsKey(c.InputNodeID) && nodeIdToControlNode.ContainsKey(c.OutputNodeID))
                    {
                        var inputItem = FindOrCreateNodeItem(nodeIdToControlNode[c.InputNodeID],
                            (item) => (item.Output != null && item.Output.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.InputParameterName)),
                            () => new ShaderFragmentNodeItem(c.InputParameterName, c.InputType, null, false, true));
                        
                        var outputItem = FindOrCreateNodeItem(nodeIdToControlNode[c.OutputNodeID],
                            (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                            () => new ShaderFragmentNodeItem(c.OutputParameterName, c.OutputType, null, true, false));

                        graph.Connect(inputItem.Output, outputItem.Input);
                    }
                }

                    // --------< Constant Connections >--------
                foreach (var c in nodeGraph.ConstantConnections)
                {
                    if (nodeIdToControlNode.ContainsKey(c.OutputNodeID))
                    {
                        var node = nodeIdToControlNode[c.OutputNodeID];
                        var outputItem = FindOrCreateNodeItem(node,
                            (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                            () => new ShaderFragmentNodeItem(c.OutputParameterName, "float", null, true, false));

                        var connection = new NodeConnection();
                        connection.To = outputItem.Input;
                        connection.Name = c.Value;
                        node.AddConnection(connection);
                    }
                }

                    // --------< Input Parameter Connections >--------
                foreach (var c in nodeGraph.InputParameterConnections)
                {
                    if (!nodeIdToControlNode.ContainsKey(c.OutputNodeID)) continue;

                    var dstItem = FindOrCreateNodeItem(
                        nodeIdToControlNode[c.OutputNodeID],
                        (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                        () => new ShaderFragmentNodeItem(c.OutputParameterName, c.Type, null, true, false));

                    Node srcNode;
                    if (!newNodes.ContainsKey(c.VisualNodeId))
                    {
                        srcNode = _nodeCreator.CreateInterfaceNode("Inputs", InterfaceDirection.In);
                        MatchVisualNode(srcNode, nodeGraph.VisualNodes[c.VisualNodeId]);
                        newNodes[c.VisualNodeId] = srcNode;
                        graph.AddNode(srcNode);
                    } 
                    else
                        srcNode = newNodes[c.VisualNodeId];

                    var srcItem = FindOrCreateNodeItem(
                        srcNode,
                        (item) => {
                            var i = item as ShaderFragmentInterfaceParameterItem;
                            if (i==null) return false;
                            return i.Name.Equals(c.Name) && i.Type.Equals(c.Type) && i.Semantic.Equals(c.Semantic);
                        },
                        () => new ShaderFragmentInterfaceParameterItem(c.Name, c.Type, InterfaceDirection.In) { Semantic = c.Semantic, Default = c.Default });

                    graph.Connect(srcItem.Output, dstItem.Input);
                }

                    // --------< Output Parameter Connections >--------
                foreach (var c in nodeGraph.OutputParameterConnections)
                {
                    if (!nodeIdToControlNode.ContainsKey(c.InputNodeID)) continue;

                    var srcItem = FindOrCreateNodeItem(
                        nodeIdToControlNode[c.InputNodeID],
                        (item) => (item.Output != null && item.Output.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.InputParameterName)),
                        () => new ShaderFragmentNodeItem(c.InputParameterName, c.Type, null, false, true));

                    Node dstNode;
                    if (!newNodes.ContainsKey(c.VisualNodeId))
                    {
                        dstNode = _nodeCreator.CreateInterfaceNode("Outputs", InterfaceDirection.Out);
                        MatchVisualNode(dstNode, nodeGraph.VisualNodes[c.VisualNodeId]);
                        newNodes[c.VisualNodeId] = dstNode;
                        graph.AddNode(dstNode);
                    }
                    else
                        dstNode = newNodes[c.VisualNodeId];

                    var dstItem = FindOrCreateNodeItem(
                        dstNode,
                        (item) =>
                        {
                            var i = item as ShaderFragmentInterfaceParameterItem;
                            if (i == null) return false;
                            return i.Name.Equals(c.Name) && i.Type.Equals(c.Type) && i.Semantic.Equals(c.Semantic);
                        },
                        () => new ShaderFragmentInterfaceParameterItem(c.Name, c.Type, InterfaceDirection.Out) { Semantic = c.Semantic });

                    graph.Connect(srcItem.Output, dstItem.Input);
                }
            }
        }
Esempio n. 15
0
            //
            //      Convert from the "ViewModel" to the "Model"
            //
            //      We don't maintain the ShaderPatcherLayer.NodeGraph representation
            //      permanently... But we need this for serialization and shader
            //      generation operations
            //
            //      So, let's just build it from the graph control object.
            //
        public ShaderPatcherLayer.NodeGraph ToShaderPatcherLayer(HyperGraph.IGraphModel graph)
        {
            ShaderPatcherLayer.NodeGraph nodeGraph = new ShaderPatcherLayer.NodeGraph();
            Dictionary<Node, int> nodeToVisualNodeId = new Dictionary<Node, int>();
            foreach (Node n in graph.Nodes)
            {
                var nTag = n.Tag as ShaderFragmentNodeTag;
                if (nTag == null) continue;

                // Create a "visual node" (unless it already exists)
                //      --  this contains information that only affects the rendered
                //          graphs, not the output shader
                int visualNodeId;
                if (nodeToVisualNodeId.ContainsKey(n))
                {
                    visualNodeId = nodeToVisualNodeId[n];
                }
                else
                {
                    visualNodeId = nodeGraph.VisualNodes.Count();
                    nodeToVisualNodeId.Add(n, visualNodeId);
                    nodeGraph.VisualNodes.Add(
                        new ShaderPatcherLayer.VisualNode()
                        {
                            Location = n.Location,
                            State = (n.Collapsed) ? ShaderPatcherLayer.VisualNode.StateType.Collapsed : ShaderPatcherLayer.VisualNode.StateType.Normal
                        });
                }

                // Potentially build a "node" in the patcher layer. This is only required
                // if we're referencing some object in the shader fragments archive
                if (!string.IsNullOrEmpty(nTag.ArchiveName))
                {
                    ShaderPatcherLayer.Node resultNode = new ShaderPatcherLayer.Node() {
                        FragmentArchiveName = nTag.ArchiveName, NodeId = nTag.Id,
                        VisualNodeId = visualNodeId };

                    if (n.Tag is ShaderParameterNodeTag)
                    {
                        //  This is a hack... But there should be a drop down list that
                        //  can tell us the type of this parameter struct box.
                        foreach (var i in n.Items)
                        {
                            if (i is HyperGraph.Items.NodeDropDownItem)
                            {
                                var dropDown = (HyperGraph.Items.NodeDropDownItem)i;
                                var stringForm = dropDown.Items[dropDown.SelectedIndex];
                                var parameterSource = ShaderFragmentNodeCreator.AsEnumValue<ShaderFragmentArchive.Parameter.SourceType>(stringForm, ShaderFragmentNodeCreator.ParamSourceTypeNames);
                                resultNode.NodeType = AsNodeType(parameterSource);
                            }
                        }
                    }
                    else
                    {
                        resultNode.NodeType = ShaderPatcherLayer.Node.Type.Procedure;
                    }

                    nodeGraph.Nodes.Add(resultNode);
                }

                // Build connections...
                foreach (NodeConnection connection in n.Connections)
                {
                    if (connection.To != null)
                    {
                        var dstNode = connection.To.Node.Tag as ShaderFragmentNodeTag;
                        if (dstNode == null) continue;

                        var dstItem = connection.To.Item as ShaderFragmentNodeItem;
                        if (dstItem == null) continue;

                        if (connection.From == null && connection.To.Node == n)
                        {
                                // this is a direct constant connection. It connects the value either to a constant value, or some named variable
                            nodeGraph.ConstantConnections.Add(
                                new ShaderPatcherLayer.ConstantConnection() 
                                    {   Value = connection.Name,
                                        OutputNodeID = dstNode.Id, OutputParameterName = dstItem.Name });
                        }
                        else if (connection.To.Node == n && connection.To.Item is ShaderFragmentInterfaceParameterItem)
                        {
                                // this is an output parameter. This is the only case where we creating the connection
                                // while processing the node on the "out" side
                            var outputParam = (ShaderFragmentInterfaceParameterItem)connection.To.Item;
                            var resultConnection = new ShaderPatcherLayer.OutputParameterConnection
                                {
                                    VisualNodeId = visualNodeId,    // (visual node for the output box)
                                    Type = outputParam.Type,
                                    Name = outputParam.Name,
                                    Semantic = outputParam.Semantic
                                };
                            if (connection.From.Item is ShaderFragmentNodeItem)
                            {
                                var tag = connection.From.Item.Node.Tag as ShaderFragmentNodeTag;
                                if (tag != null) resultConnection.InputNodeID = tag.Id;
                                resultConnection.InputParameterName = ((ShaderFragmentNodeItem)connection.From.Item).Name;
                            }
                            nodeGraph.OutputParameterConnections.Add(resultConnection);
                        }
                        else if (connection.From.Node == n)
                        {
                            if (connection.From.Item is ShaderFragmentInterfaceParameterItem)
                            {
                                // it's an input parameter... we just need type, name, semantic
                                var inputParam = (ShaderFragmentInterfaceParameterItem)connection.From.Item;
                                nodeGraph.InputParameterConnections.Add(
                                    new ShaderPatcherLayer.InputParameterConnection
                                        {
                                            OutputNodeID = dstNode.Id,
                                            OutputParameterName = dstItem.Name,
                                            VisualNodeId = visualNodeId,
                                            Type = inputParam.Type,
                                            Name = inputParam.Name,
                                            Semantic = inputParam.Semantic,
                                            Default = inputParam.Default
                                        });
                            }
                            else if (connection.To.Item is ShaderFragmentInterfaceParameterItem)
                            {
                                // it's an output parameter... 
                                // this will be handled when processing the node on the out side
                            }
                            else
                            {
                                // This is an output to the next node
                                var resultConnection = new ShaderPatcherLayer.NodeConnection()
                                    {
                                        InputNodeID = nTag.Id,
                                        OutputNodeID = dstNode.Id,
                                        OutputParameterName = dstItem.Name,
                                        OutputType = TypeFromNodeItem(dstItem)
                                    };

                                if (connection.From.Item is ShaderFragmentNodeItem)
                                {
                                    var sourceItem = (ShaderFragmentNodeItem)connection.From.Item;
                                    resultConnection.InputParameterName = sourceItem.Name;
                                    resultConnection.InputType = TypeFromNodeItem(sourceItem);
                                }
                                nodeGraph.NodeConnections.Add(resultConnection);
                            }
                        }
                    }
                    else if (connection.From != null && connection.From.Node == n)
                    {
                            // when connection.To is null, it could be an attached output connection
                        var resultConnection = new ShaderPatcherLayer.OutputParameterConnection()
                            {
                                Name = connection.Name,
                                InputNodeID = nTag.Id
                            };

                        if (connection.From.Item is ShaderFragmentNodeItem)
                        {
                            var sourceItem = (ShaderFragmentNodeItem)connection.From.Item;
                            resultConnection.InputParameterName = sourceItem.Name;
                            resultConnection.Type = TypeFromNodeItem(sourceItem);
                        }
                        nodeGraph.OutputParameterConnections.Add(resultConnection);
                    }
                }

                // build the preview settings objects
                foreach (var i in n.Items)
                {
                    var preview = i as ShaderFragmentPreviewItem;
                    if (preview == null) continue;
                    
                    var settings = preview.PreviewSettings;
                    settings.VisualNodeId = visualNodeId;
                    nodeGraph.PreviewSettingsObjects.Add(settings);
                }
            }

            return nodeGraph;
        }
Esempio n. 16
0
 void Model_NodeAdded(object sender, HyperGraph.AcceptNodeEventArgs e) { SetDirty(true); }
Esempio n. 17
0
 private void MatchVisualNode(HyperGraph.Node dst, ShaderPatcherLayer.VisualNode src)
 {
     dst.Location = src.Location;
     dst.Collapsed = src.State == ShaderPatcherLayer.VisualNode.StateType.Collapsed;
 }
Esempio n. 18
0
        private static void ParameterNodeTypeChanged(object sender, HyperGraph.Items.AcceptNodeSelectionChangedEventArgs args)
        {
            if (sender is HyperGraph.Items.NodeDropDownItem)
            {
                var item = (HyperGraph.Items.NodeDropDownItem)sender;
                var node = item.Node;

                var newType = AsSourceType(item.Items[args.Index]);

                    //  We might have to change the input/output settings on this node
                bool isOutput = newType == ShaderFragmentArchive.Parameter.SourceType.Output;
                var oldItems = new List<HyperGraph.NodeItem>(node.Items);
                foreach (var i in oldItems)
                {
                    if (i is ShaderFragmentNodeItem)
                    {
                                // if this is a node item with exactly 1 input/output
                                // and it is not in the correct direction, then we have to change it.
                                //  we can't change directly. We need to delete and recreate this node item.
                        var fragItem = (ShaderFragmentNodeItem)i;
                        if (    (fragItem.Output.Enabled ^ fragItem.Input.Enabled) == true &&
                                (fragItem.Output.Enabled) != (isOutput == false))
                        {
                            var newItem = new ShaderFragmentNodeItem(
                                fragItem.Name, fragItem.Type, fragItem.ArchiveName,
                                isOutput ? true : false, isOutput ? false : true);
                            node.RemoveItem(fragItem);
                            node.AddItem(newItem);
                        }
                    }
                }
            }
        }
Esempio n. 19
0
 void Model_NodeRemoved(object sender, HyperGraph.NodeEventArgs e) { SetDirty(true); }
Esempio n. 20
0
        public static void UpdateGraphConnectionsForParameter(
                                HyperGraph.GraphControl graphControl,
                                String oldArchiveName, String newArchiveName)
        {
            //      Look for connections in the graph using the "oldArchiveName" and
            //      update them with parameter state information from "newArchiveName"

            foreach (var n in graphControl.Nodes)
            {
                foreach (var item in n.Items)
                {
                    if (item is ShaderFragmentNodeItem)
                    {
                        var i = (ShaderFragmentNodeItem)item;
                        if (i.ArchiveName != null && i.ArchiveName.Equals(oldArchiveName))
                        {
                            i.ArchiveName = newArchiveName;

                            //      Name and Type are cached on the connector
                            //      so, we have to update them with the latest info...
                            var param = ShaderFragmentArchive.Archive.GetParameter(newArchiveName);
                            if (param!=null)
                            {
                                i.Name = param.Name;
                                i.Type = param.Type;
                            }
                            else
                            {
                                i.Name = "<<unknown>>";
                                i.Type = "<<unknown>>";
                            }
                        }
                    }
                }
            }
        }
        public void HyperGraph_IsPartOfHexagon_has_to_work()
        {
            List <Vertex>    vertices      = new List <Vertex>();
            List <HyperEdge> twoSidedEdges = new List <HyperEdge>();

            for (int i = 0; i < 6; i++)
            {
                for (int j = i; j < 6; j++)
                {
                    vertices.Add(new Vertex(i + "" + j));
                    if (i != j)
                    {
                        vertices.Add(new Vertex(j + "" + i));
                    }

                    twoSidedEdges.Add(new HyperEdge(i + "" + j, j + "" + i));
                }
            }

            HyperGraph hyperGraph = new HyperGraph(vertices);

            foreach (HyperEdge twoSidedEdge in twoSidedEdges)
            {
                hyperGraph.AddEdge(twoSidedEdge);
            }

            HyperEdge edge0 = new HyperEdge("00", "00", "00", TileOrientation.Straight);
            HyperEdge edge1 = new HyperEdge("00", "02", "20", TileOrientation.Flipped);
            HyperEdge edge2 = new HyperEdge("02", "22", "20", TileOrientation.DoubleTiltLeft);
            HyperEdge edge3 = new HyperEdge("01", "12", "20", TileOrientation.Flipped);
            HyperEdge edge4 = new HyperEdge("01", "11", "10", TileOrientation.DoubleTiltRight);
            HyperEdge edge5 = new HyperEdge("00", "01", "10", TileOrientation.TiltRight);

            List <Hexagon> hexagons = new List <Hexagon>();

            HyperEdge addedEdge0 = hyperGraph.AddEdge(edge0);

            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge0, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge1, edge0, out HyperEdge addedEdge1));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge1, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge2, edge1, out HyperEdge addedEdge2));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge2, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge3, edge2, out HyperEdge addedEdge3));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge3, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge4, edge3, out HyperEdge addedEdge4));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge4, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge5, edge4, out HyperEdge addedEdge5));
            addedEdge5.AddDirectNeighbor(addedEdge0);
            Assert.IsTrue(hyperGraph.IsPartOfHexagon(edge5, out hexagons));
            Assert.AreEqual(1, hexagons.Count);

            //-----------------------------------------------------------------------------------
            hyperGraph = new HyperGraph(vertices);
            foreach (HyperEdge twoSidedEdge in twoSidedEdges)
            {
                hyperGraph.AddEdge(twoSidedEdge);
            }

            addedEdge1 = hyperGraph.AddEdge(edge1);
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge1, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge2, edge1, out addedEdge2));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge2, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge3, edge2, out addedEdge3));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge3, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge4, edge3, out addedEdge4));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge4, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge5, edge4, out addedEdge5));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge5, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge0, edge5, out addedEdge0));
            addedEdge0.AddDirectNeighbor(addedEdge1);
            Assert.IsTrue(hyperGraph.IsPartOfHexagon(edge0, out hexagons));
            Assert.AreEqual(1, hexagons.Count);

            //-----------------------------------------------------------------------------------
            hyperGraph = new HyperGraph(vertices);
            foreach (HyperEdge twoSidedEdge in twoSidedEdges)
            {
                hyperGraph.AddEdge(twoSidedEdge);
            }

            addedEdge2 = hyperGraph.AddEdge(edge2);
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge2, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge3, edge2, out addedEdge3));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge3, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge4, edge3, out addedEdge4));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge4, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge5, edge4, out addedEdge5));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge5, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge0, edge5, out addedEdge0));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge0, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge1, edge0, out addedEdge1));
            addedEdge1.AddDirectNeighbor(addedEdge2);
            Assert.IsTrue(hyperGraph.IsPartOfHexagon(edge1, out hexagons));
            Assert.AreEqual(1, hexagons.Count);

            //-----------------------------------------------------------------------------------
            hyperGraph = new HyperGraph(vertices);
            foreach (HyperEdge twoSidedEdge in twoSidedEdges)
            {
                hyperGraph.AddEdge(twoSidedEdge);
            }

            addedEdge3 = hyperGraph.AddEdge(edge3);
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge3, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge4, edge3, out addedEdge4));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge4, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge5, edge4, out addedEdge5));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge5, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge0, edge5, out addedEdge0));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge0, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge1, edge0, out addedEdge1));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge1, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge2, edge1, out addedEdge2));
            addedEdge2.AddDirectNeighbor(addedEdge3);
            Assert.IsTrue(hyperGraph.IsPartOfHexagon(edge2, out hexagons));
            Assert.AreEqual(1, hexagons.Count);

            //-----------------------------------------------------------------------------------
            hyperGraph = new HyperGraph(vertices);
            foreach (HyperEdge twoSidedEdge in twoSidedEdges)
            {
                hyperGraph.AddEdge(twoSidedEdge);
            }

            addedEdge4 = hyperGraph.AddEdge(edge4);
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge4, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge5, edge4, out addedEdge5));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge5, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge0, edge5, out addedEdge0));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge0, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge1, edge0, out addedEdge1));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge1, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge2, edge1, out addedEdge2));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge2, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge3, edge2, out addedEdge3));
            addedEdge3.AddDirectNeighbor(addedEdge4);
            Assert.IsTrue(hyperGraph.IsPartOfHexagon(edge3, out hexagons));
            Assert.AreEqual(1, hexagons.Count);

            //-----------------------------------------------------------------------------------
            hyperGraph = new HyperGraph(vertices);
            foreach (HyperEdge twoSidedEdge in twoSidedEdges)
            {
                hyperGraph.AddEdge(twoSidedEdge);
            }

            addedEdge5 = hyperGraph.AddEdge(edge5);
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge5, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge0, edge5, out addedEdge0));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge0, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge1, edge0, out addedEdge1));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge1, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge2, edge1, out addedEdge2));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge2, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge3, edge2, out addedEdge3));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge3, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge4, edge3, out addedEdge4));
            addedEdge4.AddDirectNeighbor(addedEdge5);
            Assert.IsTrue(hyperGraph.IsPartOfHexagon(edge4, out hexagons));
            Assert.AreEqual(1, hexagons.Count);

            //----------------------------------------------------------------------------------
            HyperEdge edge6 = new HyperEdge("02", "24", "40", TileOrientation.DoubleTiltLeft);
            HyperEdge edge7 = new HyperEdge("04", "45", "50", TileOrientation.TiltLeft);
            HyperEdge edge8 = new HyperEdge("05", "55", "50", TileOrientation.Straight);
            HyperEdge edge9 = new HyperEdge("00", "05", "50", TileOrientation.TiltLeft);

            hyperGraph = new HyperGraph(vertices);
            foreach (HyperEdge twoSidedEdge in twoSidedEdges)
            {
                hyperGraph.AddEdge(twoSidedEdge);
            }

            addedEdge1 = hyperGraph.AddEdge(edge1);
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge1, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge2, edge1, out addedEdge2));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge2, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge3, edge2, out addedEdge3));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge3, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge4, edge3, out addedEdge4));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge4, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge5, edge4, out addedEdge5));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge5, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge6, edge1, out HyperEdge addedEdge6));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge6, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge7, edge6, out HyperEdge addedEdge7));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge7, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge8, edge7, out HyperEdge addedEdge8));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge8, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge9, edge8, out HyperEdge addedEdge9));
            Assert.IsFalse(hyperGraph.IsPartOfHexagon(edge9, out hexagons));
            Assert.AreEqual(0, hexagons.Count);

            Assert.IsTrue(hyperGraph.AddEdgeWithDirectNeighbor(edge0, edge5, out addedEdge0));
            addedEdge0.AddDirectNeighbor(addedEdge1);
            addedEdge0.AddDirectNeighbor(addedEdge9);
            Assert.IsTrue(hyperGraph.IsPartOfHexagon(edge0, out hexagons));
            Assert.AreEqual(2, hexagons.Count);
        }
Esempio n. 22
0
        private void OnConnectorDoubleClick(object sender, HyperGraph.GraphControl.NodeConnectorEventArgs e)
        {
            var interfItem = e.Connector.Item as ShaderFragmentInterfaceParameterItem;
            if (interfItem != null)
            {
                EditInterfaceParameter(interfItem);
                return;
            }

            // For input connectors, we can try to add a constant connection
            if (e.Connector == e.Connector.Item.Input)
            {
                EditSimpleConnection(e.Connector);
            }
        }
Esempio n. 23
0
        //
        //      Convert from the "ViewModel" to the "Model"
        //
        //      We don't maintain the ShaderPatcherLayer.NodeGraph representation
        //      permanently... But we need this for serialization and shader
        //      generation operations
        //
        //      So, let's just build it from the graph control object.
        //
        public static ShaderPatcherLayer.NodeGraph ToShaderPatcherLayer(HyperGraph.GraphControl graphControl)
        {
            ShaderPatcherLayer.NodeGraph nodeGraph = new ShaderPatcherLayer.NodeGraph();
            Dictionary<Node, int> nodeToVisualNodeId = new Dictionary<Node, int>();
            foreach (Node n in graphControl.Nodes)
            {
                if (n.Tag is ShaderFragmentNodeTag)
                {
                    ShaderFragmentNodeTag nTag           = (ShaderFragmentNodeTag)n.Tag;
                    ShaderPatcherLayer.Node resultNode   = new ShaderPatcherLayer.Node();
                    resultNode.FragmentArchiveName       = nTag.ArchiveName;
                    resultNode.NodeId                    = nTag.Id;

                    if (n.Tag is ShaderParameterNodeTag)
                    {
                        //  This is a hack... But there should be a drop down list that
                        //  can tell us the type of this parameter struct box.
                        foreach (var i in n.Items)
                        {
                            if (i is HyperGraph.Items.NodeDropDownItem)
                            {
                                var dropDown = (HyperGraph.Items.NodeDropDownItem)i;
                                var stringForm = dropDown.Items[dropDown.SelectedIndex];
                                var parameterSource = ShaderFragmentNodeCreator.AsSourceType(stringForm);
                                resultNode.NodeType = AsNodeType(parameterSource);
                            }
                        }
                    }
                    else
                    {
                        resultNode.NodeType = ShaderPatcherLayer.Node.Type.Procedure;
                    }

                    {
                        if (nodeToVisualNodeId.ContainsKey(n))
                        {
                            resultNode.VisualNodeId = nodeToVisualNodeId[n];
                        }
                        else
                        {
                            resultNode.VisualNodeId = nodeGraph.VisualNodes.Count();
                            nodeToVisualNodeId.Add(n, resultNode.VisualNodeId);
                            var visualNode = new ShaderPatcherLayer.VisualNode();
                            visualNode.Location = n.Location;
                            if (n.Collapsed)
                            {
                                visualNode.State = ShaderPatcherLayer.VisualNode.StateType.Collapsed;
                            }
                            else
                            {
                                visualNode.State = ShaderPatcherLayer.VisualNode.StateType.Normal;
                            }
                            nodeGraph.VisualNodes.Add(visualNode);
                        }
                    }

                    nodeGraph.Nodes.Add(resultNode);

                    foreach (NodeConnection connection in n.Connections)
                    {
                        if (connection.From == null)
                        {
                                // this is a direct constant connection. It connects the value either to a constant value, or some named variable
                            if (connection.To != null)
                            {
                                Node destination = connection.To.Node;
                                if (destination.Tag is ShaderFragmentNodeTag)
                                {
                                    ShaderFragmentNodeTag dTag = (ShaderFragmentNodeTag)destination.Tag;
                                    ShaderPatcherLayer.NodeConstantConnection resultConnection = new ShaderPatcherLayer.NodeConstantConnection();
                                    resultConnection.Value = connection.Name;
                                    resultConnection.OutputNodeID = dTag.Id;
                                    if (connection.To.Item is ShaderFragmentNodeItem)
                                    {
                                        ShaderFragmentNodeItem destinationItem = (ShaderFragmentNodeItem)connection.To.Item;
                                        resultConnection.OutputParameterName = destinationItem.Name;
                                    }

                                    nodeGraph.NodeConstantConnections.Add(resultConnection);
                                }
                            }
                        }
                        else if (connection.From.Node == n)
                        {
                                // This is an output to the next node
                            Node destination = connection.To.Node;
                            if (destination.Tag is ShaderFragmentNodeTag)
                            {
                                ShaderFragmentNodeTag dTag = (ShaderFragmentNodeTag)destination.Tag;
                                ShaderPatcherLayer.NodeConnection resultConnection = new ShaderPatcherLayer.NodeConnection();
                                resultConnection.InputNodeID = nTag.Id;
                                resultConnection.OutputNodeID = dTag.Id;
                                if (connection.To.Item is ShaderFragmentNodeItem)
                                {
                                    ShaderFragmentNodeItem destinationItem = (ShaderFragmentNodeItem)connection.To.Item;
                                    resultConnection.OutputParameterName = destinationItem.Name;
                                    resultConnection.OutputType = TypeFromNodeItem(destinationItem);
                                }
                                if (connection.From.Item is ShaderFragmentNodeItem)
                                {
                                    ShaderFragmentNodeItem sourceItem = (ShaderFragmentNodeItem)connection.From.Item;
                                    resultConnection.InputParameterName = sourceItem.Name;
                                    resultConnection.InputType = TypeFromNodeItem(sourceItem);
                                }

                                nodeGraph.NodeConnections.Add(resultConnection);
                            }
                        }
                    }
                }
            }

            return nodeGraph;
        }
Esempio n. 24
0
 public ShaderFragmentPreviewItem(HyperGraph.GraphControl graphControl, ShaderDiagram.Document doc)
 {
     _graphControl = graphControl; _document = doc; _builder = null;
 }
Esempio n. 25
0
 public static Node CreateNode(ShaderFragmentArchive.Function fn, String archiveName, HyperGraph.GraphControl graphControl, ShaderDiagram.Document doc)
 {
     var node = new Node(fn.Name);
     node.Tag = new ShaderProcedureNodeTag(archiveName);
     node.AddItem(new ShaderFragmentPreviewItem(graphControl, doc));
     foreach (var param in fn.InputParameters)
     {
         node.AddItem(new ShaderFragmentNodeItem(param.Name, param.Type, archiveName + ":" + param.Name, true, false));
     }
     foreach (var output in fn.Outputs)
     {
         node.AddItem(new ShaderFragmentNodeItem(output.Name, output.Type, archiveName + ":" + output.Name, false, true));
     }
     return node;
 }
Esempio n. 26
0
 public static void EditParameter(HyperGraph.GraphControl graphControl, String archiveName)
 {
     //var parameter = ShaderFragmentArchive.Archive.GetParameter(archiveName);
     //if (parameter != null)
     //{
     //    var dialog = new ParameterDialog();
     //    dialog.PullFrom(parameter);
     //    var result = dialog.ShowDialog();
     //    if (result == System.Windows.Forms.DialogResult.OK)
     //    {
     //        var newParam = dialog.Result;
     //
     //        //
     //        //      Have to also update the "Name" and "Type"
     //        //      fields of any ShaderFragmentNodeItems that are
     //        //      using this parameter
     //        //          (also changing the source could change input -> output...)
     //        //
     //
     //        newParam.Name = IdentifierSafeName(newParam.Name);
     //        if (newParam.ArchiveName.Length != 0
     //            && newParam.ArchiveName.Substring(0, 12).Equals("LocalArchive"))
     //        {
     //            newParam.ArchiveName = "LocalArchive[" + newParam.Name + "]";
     //        }
     //
     //        var oldArchiveName = parameter.ArchiveName;
     //        parameter.DeepCopyFrom(newParam);
     //        ShaderFragmentArchive.Archive.RenameParameter(parameter, oldArchiveName);
     //
     //        ShaderFragmentNodeUtil.UpdateGraphConnectionsForParameter(
     //            graphControl, oldArchiveName, parameter.ArchiveName);
     //    }
     //}
 }
Esempio n. 27
0
        void OnConnectorDoubleClick(object sender, HyperGraph.GraphControl.NodeConnectorEventArgs e)
        {
            var dialog = new HyperGraph.TextEditForm();
            dialog.InputText = "1.0f";

                //  look for an existing simple connection attached to this connector
            foreach(var i in e.Node.Connections)
            {
                if (i.To == e.Connector && i.From == null)
                    dialog.InputText = i.Name;
            }

            var result = dialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                bool foundExisting = false;
                foreach (var i in e.Node.Connections)
                    if (i.To == e.Connector && i.From == null)
                    {
                        i.Name = dialog.InputText;
                        foundExisting = true;
                    }

                if (!foundExisting)
                {
                    var connection = new NodeConnection();
                    connection.To = e.Connector;
                    connection.Name = dialog.InputText;
                    e.Node.AddConnection(connection);
                }

                ShaderFragmentNodeUtil.InvalidateAttachedConstants(graphControl);
            }
        }
Esempio n. 28
0
        public static void AddToHyperGraph(ShaderPatcherLayer.NodeGraph nodeGraph, HyperGraph.GraphControl graphControl, ShaderDiagram.Document doc)
        {
            //
                //      Convert from the "ShaderPatcherLayer" representation back to
                //      our graph control nodes.
                //
                //      This is required for robust serialisation. We can't easily
                //      serialise in and out the graph control objects directly, because
                //      it risks problems if the rendering code or shader fragment objects
                //      change. That is, it's not very version-robust.
                //
                //      It's better to serialise a slightly higher level representation
                //      that just contains the node names and connections. That way, we
                //      can adapt to changes in the tool and data.
                //
            {
                    // --------< Basic Nodes >--------
                var newNodes = new Dictionary<int, Node>();
                var nodeIdToControlNode = new Dictionary<UInt64, Node>();
                foreach (var n in nodeGraph.Nodes)
                {
                    if (!newNodes.ContainsKey(n.VisualNodeId))
                    {
                        if (n.NodeType == ShaderPatcherLayer.Node.Type.Procedure)
                        {
                            var fn = ShaderFragmentArchive.Archive.GetFunction(n.FragmentArchiveName);
                            if (fn != null)
                            {
                                var visualNode = nodeGraph.VisualNodes[n.VisualNodeId];
                                var newNode = ShaderFragmentNodeCreator.CreateNode(fn, n.FragmentArchiveName, graphControl, doc);
                                newNode.Location = visualNode.Location;
                                newNode.Collapsed = visualNode.State == ShaderPatcherLayer.VisualNode.StateType.Collapsed;
                                newNodes[n.VisualNodeId] = newNode;
                                nodeIdToControlNode[n.NodeId] = newNode;
                            }
                        }
                        else
                        {
                            var ps = ShaderFragmentArchive.Archive.GetParameterStruct(n.FragmentArchiveName);
                            if (ps != null)
                            {
                                var visualNode = nodeGraph.VisualNodes[n.VisualNodeId];
                                var newNode = ShaderFragmentNodeCreator.CreateParameterNode(ps, n.FragmentArchiveName, AsSourceType(n.NodeType));
                                newNode.Location = visualNode.Location;
                                newNode.Collapsed = visualNode.State == ShaderPatcherLayer.VisualNode.StateType.Collapsed;
                                newNodes[n.VisualNodeId] = newNode;
                                nodeIdToControlNode[n.NodeId] = newNode;
                            }
                        }
                    }
                }

                graphControl.AddNodes(newNodes.Values);

                    // --------< Node Connections >--------
                foreach (var c in nodeGraph.NodeConnections)
                {
                    if (nodeIdToControlNode.ContainsKey(c.InputNodeID) && nodeIdToControlNode.ContainsKey(c.OutputNodeID))
                    {
                        var inputItem = FindOrCreateNodeItem(nodeIdToControlNode[c.InputNodeID],
                            (item) => (item.Output != null && item.Output.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.InputParameterName)),
                            () => new ShaderFragmentNodeItem("return", c.InputType, null, false, true));

                        var outputItem = FindOrCreateNodeItem(nodeIdToControlNode[c.OutputNodeID],
                            (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                            () => new ShaderFragmentNodeItem(c.OutputParameterName, c.OutputType, null, true, false));

                        graphControl.Connect(inputItem.Output, outputItem.Input);
                    }
                }

                    // --------< Node Constant Connections >--------
                foreach (var c in nodeGraph.NodeConstantConnections)
                {
                    if (nodeIdToControlNode.ContainsKey(c.OutputNodeID))
                    {
                        var node = nodeIdToControlNode[c.OutputNodeID];
                        var outputItem = FindOrCreateNodeItem(node,
                            (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                            () => new ShaderFragmentNodeItem(c.OutputParameterName, "float", null, true, false));

                        var connection = new NodeConnection();
                        connection.To = outputItem.Input;
                        connection.Name = c.Value;
                        node.AddConnection(connection);
                    }
                }

            }
        }
 public static Task SerializeAsync(this HyperGraph graph, Stream stream) =>
 JsonSerializer.SerializeAsync(stream, graph);
Esempio n. 30
0
 //public static Node GetParameterNode(HyperGraph.GraphControl graphControl, UInt64 id)
 //{
 //    foreach (Node n in graphControl.Nodes)
 //    {
 //        if (n.Tag is ShaderParameterNodeTag
 //            && ((ShaderParameterNodeTag)n.Tag).Id == (UInt64)id)
 //        {
 //            return n;
 //        }
 //    }
 //    return null;
 //}
 public static void InvalidateShaderStructure(HyperGraph.GraphControl graphControl)
 {
     foreach (Node n in graphControl.Nodes)
     {
         foreach (NodeItem i in n.Items)
         {
             if (i is ShaderFragmentPreviewItem)
             {
                 ((ShaderFragmentPreviewItem)i).InvalidateShaderStructure();
             }
         }
     }
 }
 public static byte[] Serialize(this HyperGraph graph) =>
 JsonSerializer.Serialize(graph);
Esempio n. 32
0
        public static bool FillInMaterialParameters(ShaderDiagram.Document document, HyperGraph.GraphControl graphControl)
        {
            //
                //      Look for new or removed material parameters
                //      and update the material parameters dictionary
                //
            Dictionary<String, String> newMaterialParameters = new Dictionary<String, String>();
            foreach (Node n in graphControl.Nodes)
            {
                if (n.Tag is ShaderParameterNodeTag && n.Items.Count() > 0)
                {
                        // look for a drop down list element -- this will tell us the type
                    ShaderFragmentArchive.Parameter.SourceType type =
                        ShaderFragmentArchive.Parameter.SourceType.System;
                    foreach (var i in n.Items)
                    {
                        if (i is HyperGraph.Items.NodeDropDownItem)
                        {
                            var dropDown = (HyperGraph.Items.NodeDropDownItem)i;
                            var stringForm = dropDown.Items[dropDown.SelectedIndex];
                            type = ShaderFragmentNodeCreator.AsSourceType(stringForm);
                            break;
                        }
                    }

                    if (type == ShaderFragmentArchive.Parameter.SourceType.Material)
                    {
                        foreach (var i in n.Items)
                        {
                            if (i is ShaderFragmentNodeItem)
                            {
                                ShaderFragmentNodeItem item = (ShaderFragmentNodeItem)i;
                                if (item.Output != null)
                                {
                                    if (!newMaterialParameters.ContainsKey(item.ArchiveName))
                                    {
                                        var param = ShaderFragmentArchive.Archive.GetParameter(item.ArchiveName);
                                        if (param != null)
                                        {
                                            newMaterialParameters.Add(item.ArchiveName, param.Type);
                                        }
                                        else
                                        {
                                            newMaterialParameters.Add(item.ArchiveName, "<<unknown>>");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            bool didSomething = false;
            List<String> entriesToRemove = new List<String>();
            foreach (String s in document.PreviewMaterialState.Keys)
            {
                if (!newMaterialParameters.ContainsKey(s))
                {
                    entriesToRemove.Add(s);
                }
            }

            foreach (String s in entriesToRemove)
            {
                document.PreviewMaterialState.Remove(s);      // does this invalidate the iteration?
                didSomething = true;
            }

            foreach (KeyValuePair<String,String> s in newMaterialParameters)
            {
                if (!document.PreviewMaterialState.ContainsKey(s.Key))
                {
                    var parameter = ShaderFragmentArchive.Archive.GetParameter(s.Key);
                    System.Object def = null;
                    if (parameter != null && parameter.Default != null && parameter.Default.Length > 0)
                    {
                        def = ShaderPatcherLayer.TypeRules.CreateFromString(parameter.Default, parameter.Type);
                    }

                    var parameterName = s.Key;
                    if (parameter!=null) parameterName = parameter.Name;

                    if (def != null)
                    {
                        document.PreviewMaterialState.Add(parameterName, def);
                    }
                    else
                    {
                        document.PreviewMaterialState.Add(parameterName, ShaderPatcherLayer.TypeRules.CreateDefaultObject(s.Value));
                    }

                    didSomething = true;
                }
            }

            return didSomething;
        }
        public void GetTileProbabilities()
        {
            string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName, "TestFiles", "tEdgePieces.txt");
            //string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "TestFiles", "tEdgePieces.txt");

            HyperGraph hyperGraph = GraphGenerator.LoadHyperGraphFromFile(path);

            //Tuple<string, int>[] degrees = hyperGraph.GetVertexDegrees();
            Tuple <string, int>[] degrees = hyperGraph.GetVertexEulerDegrees();

            Dictionary <HyperEdge, float> probabilities = new Dictionary <HyperEdge, float>();

            int blueBlueBlueValues, greenGreenRedValues, greenBlueRedValues;

            blueBlueBlueValues = greenGreenRedValues = greenBlueRedValues = 0;

            foreach (HyperEdge edge in hyperGraph.Edges)
            {
                int tileSideWs = 0;
                foreach (Vertex vertex in edge.Vertices)
                {
                    string reverse = vertex.Value.ReverseString();
                    int    sideWS  = degrees.Where(t => t.Item1.Equals(reverse)).Single().Item2;
                    if (edge.Vertices.Select(v => v.Value).Contains(reverse))
                    {
                        sideWS--;
                    }
                    tileSideWs += sideWS;
                }

                string[]         vertexCounterParts = edge.Vertices.Select(v => v.Value.ReverseString()).ToArray();
                List <HyperEdge> duplicate          = hyperGraph.Edges.Where(e => !e.Equals(edge) && e.Vertices.Select(v => v.Value).Intersect(vertexCounterParts).Count() == 2).ToList();

                // The number for tileSideWs has to be corrected about the number of those tiles,
                // which hold more than one 'counterparts' (max counterparts on one tile is 2)
                // of the actual tile sides.
                tileSideWs = tileSideWs - duplicate.Count;

                //float ws = (float)tileSideWs/168.0f;
                float ws = (float)tileSideWs / 56.0f;
                probabilities.Add(edge, ws);

                switch (edge.Vertices.Select(v => v.Value.GetVertexColor()).Distinct().Count())
                {
                case 1:
                    blueBlueBlueValues += edge.Vertices.Select(v => Int32.Parse(v.Value[0].ToString())).Sum();
                    break;

                case 2:
                    greenGreenRedValues += edge.Vertices.Select(v => Int32.Parse(v.Value[0].ToString())).Sum();
                    break;

                case 3:
                    greenBlueRedValues += edge.Vertices.Select(v => Int32.Parse(v.Value[0].ToString())).Sum();
                    break;

                default:
                    throw new InvalidOperationException($"Cannot determine SideType for Tile: {edge.Vertices.Select(v => v.Value[0].ToString()).Aggregate((a, b) => a + " - " + b)}");
                }

                //45 / 6 => 7.5
                //150 / 20 => 7.5
                //225 / 30 => 7.5
            }

            string outputPath = @"C:\Users\Moritz\Dropbox\Studium\Fulda\5_SS19\Project\Triominos\Graphsuite\GraphSuite\Files";
            string outputFile = "tileProbabilitiesAndValues.txt";

            if (File.Exists(Path.Combine(outputPath, outputFile)))
            {
                File.Delete(Path.Combine(outputPath, outputFile));
            }

            File.WriteAllLines(
                Path.Combine(outputPath, outputFile),
                probabilities.OrderBy(kv => kv.Key.GreenSideCount()).Select(
                    kv => kv.Key.Vertices.Select(v => v.Value[0].ToString()).Aggregate((a, b) => a + "-" + b) + " | " +
                    kv.Key.Vertices.Select(v => Int32.Parse(v.Value[0].ToString())).Sum() + " | " +
                    kv.Key.Vertices.Select(v => v.Value.GetVertexColor().ToString()).Aggregate((a, b) => a + "-" + b) + " | " +
                    kv.Value));
        }
Esempio n. 34
0
 void Model_ConnectionRemoved(object sender, HyperGraph.NodeConnectionEventArgs e) { SetDirty(true); }
Esempio n. 35
0
 void Model_ConnectionAdded(object sender, HyperGraph.AcceptNodeConnectionEventArgs e) { SetDirty(true); }
Esempio n. 36
0
 public static Node GetShaderFragmentNode(HyperGraph.GraphControl graphControl, UInt64 id)
 {
     foreach (Node n in graphControl.Nodes)
     {
         if (n.Tag is ShaderFragmentNodeTag
             && ((ShaderFragmentNodeTag)n.Tag).Id == (UInt64)id)
         {
             return n;
         }
     }
     return null;
 }
Esempio n. 37
0
        public static HyperGraph GenerateTest1()
        {
            var graph = new HyperGraph("Testing");

            var v1  = new Vertex("1");
            var v2  = new Vertex("22");
            var v3  = new Vertex("333");
            var v4  = new Vertex("4444");
            var v5  = new Vertex("55555");
            var v6  = new Vertex("666666");
            var v7  = new Vertex("7777777");
            var v8  = new Vertex("88888888");
            var v9  = new Vertex("999999999");
            var v10 = new Vertex("1010101010");

            var e1 = new HyperEdge {
                Vertices = { v1, v2, v3 }, Weight = 400
            };
            var e2 = new HyperEdge {
                Vertices = { v2, v3, v4 }, Weight = 500
            };
            var e3 = new HyperEdge {
                Vertices = { v3, v4, v5 }, Weight = 600
            };
            var e4 = new HyperEdge {
                Vertices = { v4, v5, v6 }, Weight = 700
            };
            var e5 = new HyperEdge {
                Vertices = { v5, v6, v7 }, Weight = 800
            };
            var e6 = new HyperEdge {
                Vertices = { v6, v7, v8 }, Weight = 900
            };
            var e7 = new HyperEdge {
                Vertices = { v7, v8, v9 }, Weight = 1000
            };
            var e8 = new HyperEdge {
                Vertices = { v8, v9, v10 }, Weight = 50000
            };
            var e9 = new HyperEdge {
                Vertices = { v9, v10, v1 }, Weight = 25000
            };
            var e10 = new HyperEdge {
                Vertices = { v10, v1, v2 }, Weight = 1000000
            };

            v1.HyperEdges.Add(e1);
            v1.HyperEdges.Add(e2);
            v1.HyperEdges.Add(e3);

            v2.HyperEdges.Add(e2);
            v2.HyperEdges.Add(e3);
            v2.HyperEdges.Add(e4);

            v3.HyperEdges.Add(e3);
            v3.HyperEdges.Add(e4);
            v3.HyperEdges.Add(e5);

            v4.HyperEdges.Add(e4);
            v4.HyperEdges.Add(e5);
            v4.HyperEdges.Add(e6);

            v5.HyperEdges.Add(e5);
            v5.HyperEdges.Add(e6);
            v5.HyperEdges.Add(e7);

            v6.HyperEdges.Add(e6);
            v6.HyperEdges.Add(e7);
            v6.HyperEdges.Add(e8);

            v7.HyperEdges.Add(e7);
            v7.HyperEdges.Add(e8);
            v7.HyperEdges.Add(e9);

            v8.HyperEdges.Add(e8);
            v8.HyperEdges.Add(e9);
            v8.HyperEdges.Add(e10);

            v9.HyperEdges.Add(e9);
            v9.HyperEdges.Add(e10);
            v9.HyperEdges.Add(e1);

            v10.HyperEdges.Add(e10);
            v10.HyperEdges.Add(e1);
            v10.HyperEdges.Add(e2);

            graph.Vertices.AddRange(new[]
            {
                v1, v2, v3, v4, v5, v6, v7, v8, v9, v10
            });
            graph.HyperEdges.AddRange(new[]
            {
                // new HyperEdge {Vertices = {v1, v2, v3, v4, v5, v6, v7, v8, v9, v10}, Weight = 500},
                e1,
                e2,
                e3,
                e4,
                e5,
                e6,
                e7,
                e8,
                e9,
                e10,
            });

            return(graph);
        }
Esempio n. 38
0
        private BoundsSpecified GetNodeBounds(HyperGraph.Node element, out Rectangle bounds)
        {
            bounds = GetClientSpaceBounds(element);

            //transform to world coordinates
            // (note -- these transforms could be avoided by calculating the bounds in canvas space directly, without using the PickingAdapter)
            var transformAdapter = _control.As<ITransformAdapter>();
            bounds = GdiUtil.InverseTransform(transformAdapter.Transform, bounds);

            return BoundsSpecified.All;
        }