当前位置: 首页>>代码示例>>C#>>正文


C# Graph.CalculateConnectivity方法代码示例

本文整理汇总了C#中Graph.CalculateConnectivity方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.CalculateConnectivity方法的具体用法?C# Graph.CalculateConnectivity怎么用?C# Graph.CalculateConnectivity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph的用法示例。


在下文中一共展示了Graph.CalculateConnectivity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToCrossedGraph

    public Graph ToCrossedGraph() {
        List<OctreeNode> leaves = root.Leaves();
        Dictionary<long, Node> dict = new Dictionary<long, Node>();
        Dictionary<OctreeNode, HashSet<Node>> dictNodes = new Dictionary<OctreeNode, HashSet<Node>>();
        Dictionary<string, bool> arcAdded = new Dictionary<string, bool>();
        List<Node> nodes = new List<Node>();
        List<int[]> coords = new List<int[]>();

        foreach (OctreeNode o in leaves) {
            if (!o.blocked) {
                for (int i = 0; i < 8; i++) {
                    int[] index = o.cornerIndex(i);
                    long key = GetNodeKey(index);
                    if (!dict.ContainsKey(key)) {
                        Node node = GetNodeFromDict(index, dict, nodes);
                        coords.Add(index);
                        for (int j = 0; j < 8; j++) {
                            int[] gridIndex = new int[] { index[0] - 1 + cornerDir[j,0], index[1] - 1 + cornerDir[j, 1], index[2] - 1 + cornerDir[j, 2] };
                            OctreeNode voxel = Find(gridIndex);
                            if (voxel != null && !voxel.blocked) {
                                if (!dictNodes.ContainsKey(voxel)) {
                                    dictNodes.Add(voxel, new HashSet<Node> { node });
                                } else {
                                    dictNodes[voxel].Add(node);
                                }
                            }
                        }
                    }
                }
            }
        }
        foreach (OctreeNode voxel in dictNodes.Keys) {
            List<Node> enclosingNodes = new List<Node>(dictNodes[voxel]);
            for (int i = 0; i < enclosingNodes.Count - 1; i++) {
                for (int j = i + 1; j < enclosingNodes.Count; j++) {
                    Node n1 = enclosingNodes[i];
                    Node n2 = enclosingNodes[j];
                    int[] coord1 = coords[n1.index];
                    int[] coord2 = coords[n2.index];
                    if (( coord1[0] == coord2[0] || coord1[1] == coord2[1] || coord1[2] == coord2[2]) && (coord1[0] - coord2[0]) % 2 == 0 && (coord1[1] - coord2[1]) % 2 == 0 && (coord1[2] - coord2[2]) % 2 == 0) {
                        int[] coordM = new int[] { (coord1[0] + coord2[0]) / 2, (coord1[1] + coord2[1]) / 2, (coord1[2] + coord2[2]) / 2 };
                        if (dict.ContainsKey(GetNodeKey(coordM))) {
                            continue;
                        }
                    }
                    string arcKey = GetArcKeyS(coord1, coord2);
                    bool temp;
                    if (!arcAdded.TryGetValue(arcKey, out temp)) {
                        arcAdded[arcKey] = true;
                        n1.arcs.Add(new Arc(n1, n2));
                        n2.arcs.Add(new Arc(n2, n1));
                    }
                }
            }
        }
        Graph g = new Graph();
        g.nodes = nodes;
        g.CalculateConnectivity();
        g.type = Graph.GraphType.CROSSED;
        crossedGraph = g;
        crossedGraphDictionary = dict;
        crossedGraphBoundingNodesDictionary = dictNodes;
        return g;
    }
开发者ID:supercontact,项目名称:PathFindingEnhanced,代码行数:64,代码来源:Octree.cs

示例2: ToCenterGraph

 public Graph ToCenterGraph() {
     List<OctreeNode> leaves = root.Leaves();
     Dictionary<OctreeNode, Node> dict = new Dictionary<OctreeNode, Node>();
     int count = 0;
     List<Node> nodes = new List<Node>();
     foreach (OctreeNode q in leaves) {
         if (!q.blocked) {
             Node n = new Node(q.center, count);
             dict.Add(q, n);
             nodes.Add(n);
             count++;
         }
     }
     foreach (OctreeNode q in leaves) {
         if (!q.blocked) {
             if (q.level == 0) continue;
             Node n = dict[q];
             for (int i = 0; i < 6; i++) {
                 OctreeNode found = Find(new int[] { q.index[0] + dir[i, 0], q.index[1] + dir[i, 1], q.index[2] + dir[i, 2] }, q.level);
                 if (found == null || found.blocked) continue;
                 if (found.level < q.level) {
                     Node nFound = dict[found];
                     n.arcs.Add(new Arc(n, nFound));
                     nFound.arcs.Add(new Arc(nFound, n));
                 } else if (found.children == null) {
                     Node nFound = dict[found];
                     n.arcs.Add(new Arc(n, nFound));
                 }
             }
         }
     }
     Graph g = new Graph();
     g.nodes = nodes;
     g.CalculateConnectivity();
     g.type = Graph.GraphType.CENTER;
     centerGraph = g;
     centerGraphDictionary = dict;
     return g;
 }
开发者ID:supercontact,项目名称:PathFindingEnhanced,代码行数:39,代码来源:Octree.cs

示例3: ToCornerGraph

    public Graph ToCornerGraph() {
        List<OctreeNode> leaves = root.Leaves();
        Dictionary<long, Node> dict = new Dictionary<long, Node>();
        Dictionary<long, bool> arcAdded = new Dictionary<long, bool>();
        List<Node> nodes = new List<Node>();

        foreach (OctreeNode o in leaves) {
            for (int i = 0; i < 12; i++) {
                int[][] threeNeighborDir = ThreeNeighborDir(new int[] { edgeDir[i,0], edgeDir[i,1], edgeDir[i,2]});
                bool draw;
                if (o.blocked) {
                    draw = false;
                    for (int j = 0; j < 3; j++) {
                        draw = !IsBlocked(new int[] { o.index[0] + threeNeighborDir[j][0], o.index[1] + threeNeighborDir[j][1], o.index[2] + threeNeighborDir[j][2] });
                        if (draw) break;
                    }
                } else {
                    draw = true;
                    for (int j = 0; j < 3; j++) {
                        OctreeNode found = Find(new int[] { o.index[0] + threeNeighborDir[j][0], o.index[1] + threeNeighborDir[j][1], o.index[2] + threeNeighborDir[j][2] }, o.level);
                        if (found != null && found.level == o.level && found.children != null) {
                            draw = false;
                            break;
                        }
                    }
                }

                if (draw) {
                    int[][] arcVertexCoord = ArcVertexDir(new int[] { edgeDir[i, 0], edgeDir[i, 1], edgeDir[i, 2] });
                    for (int j = 0; j < 2; j++) {
                        for (int k = 0; k < 3; k++) {
                            arcVertexCoord[j][k] = (o.index[k] * 2 + 1 + arcVertexCoord[j][k]) / 2 * (1 << (maxLevel - o.level));
                        }
                    }
                    long arcKey = GetArcKey(arcVertexCoord[0], arcVertexCoord[1]);
                    bool temp;
                    if (!arcAdded.TryGetValue(arcKey, out temp)) {
                        arcAdded[arcKey] = true;
                        Node n1 = GetNodeFromDict(arcVertexCoord[0], dict, nodes);
                        Node n2 = GetNodeFromDict(arcVertexCoord[1], dict, nodes);
                        n1.arcs.Add(new Arc(n1, n2));
                        n2.arcs.Add(new Arc(n2, n1));
                    }
                }
            }
        }
        Graph g = new Graph();
        g.nodes = nodes;
        g.CalculateConnectivity();
        g.type = Graph.GraphType.CORNER;
        cornerGraph = g;
        cornerGraphDictionary = dict;
        return g;
    }
开发者ID:supercontact,项目名称:PathFindingEnhanced,代码行数:54,代码来源:Octree.cs

示例4: ToCornerGraph

    public Graph ToCornerGraph() {
        List<QuadtreeNode> leaves = root.Leaves();
        Dictionary<int, Node> dict = new Dictionary<int, Node>();
        List<Node> nodes = new List<Node>();

		foreach (QuadtreeNode q in leaves) {
	        for (int i = 0; i < 4; i++) {
	            QuadtreeNode found = Find(new int[] { q.index[0] + dir[i, 0], q.index[1] + dir[i, 1] }, q.level);
				if ((!q.blocked && (found == null || found.blocked)) || (found != null && found.level < q.level)) {
                    Node n1 = GetNodeFromDict(q.cornerGlobalIndex((i + 1) % 4), dict, nodes);
                    Node n2 = GetNodeFromDict(q.cornerGlobalIndex((i + 2) % 4), dict, nodes);
                    n1.arcs.Add(new Arc(n1, n2));
                    n2.arcs.Add(new Arc(n2, n1));
	            } else if (!q.blocked && found.children == null) {
                    Node n1 = GetNodeFromDict(q.cornerGlobalIndex((i + 1) % 4), dict, nodes);
                    Node n2 = GetNodeFromDict(q.cornerGlobalIndex((i + 2) % 4), dict, nodes);
                    n1.arcs.Add(new Arc(n1, n2));
	            }
	        }

        }
        Graph g = new Graph();
        g.nodes = nodes;
        g.CalculateConnectivity();
        return g;
    }
开发者ID:supercontact,项目名称:PathFindingEnhanced,代码行数:26,代码来源:Quadtree.cs


注:本文中的Graph.CalculateConnectivity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。