コード例 #1
0
        public static Dictionary <string, object> FindDeptCirculationNetwork(List <DeptData> deptData, Polygon2d leftOverPoly = null, bool noExternalWall = false, double circulationFrequency = 0.75)
        {
            if (deptData == null || deptData.Count == 0)
            {
                return(null);
            }
            double                limit = 0;
            List <Polygon2d>      polygonsAllDeptList = new List <Polygon2d>();
            List <DeptData>       deptDataAllDeptList = new List <DeptData>();
            List <List <string> > deptNamesNeighbors  = new List <List <string> >();
            List <List <Line2d> > lineCollection      = new List <List <Line2d> >();

            //make flattened list of all dept data and dept polys
            for (int i = 0; i < deptData.Count; i++)
            {
                List <Polygon2d> polyList = deptData[i].PolyAssignedToDept;
                if (!ValidateObject.CheckPolyList(polyList))
                {
                    continue;
                }
                for (int j = 0; j < polyList.Count; j++)
                {
                    polygonsAllDeptList.Add(polyList[j]);
                    deptDataAllDeptList.Add(deptData[i]);
                }
            }
            if (leftOverPoly != null)
            {
                polygonsAllDeptList.Add(leftOverPoly);
            }
            //else Trace.WriteLine("leftover poly found null, so not added");
            List <Line2d> networkLine = new List <Line2d>();

            for (int i = 0; i < polygonsAllDeptList.Count; i++)
            {
                Polygon2d polyA = polygonsAllDeptList[i];
                for (int j = i + 1; j < polygonsAllDeptList.Count; j++)
                {
                    Polygon2d polyB = polygonsAllDeptList[j];
                    Dictionary <string, object> checkNeighbor = PolygonUtility.FindPolyAdjacentEdge(polyA, polyB, limit);
                    if (checkNeighbor != null)
                    {
                        if ((bool)checkNeighbor["Neighbour"] == true)
                        {
                            networkLine.Add((Line2d)checkNeighbor["SharedEdge"]);
                        }
                    }
                }
            }

            // if externalWalls not necessary
            List <Line2d>    extraLines  = new List <Line2d>();
            List <Polygon2d> polyKeyList = new List <Polygon2d>();

            if (noExternalWall)
            {
                polyKeyList = deptData[0].PolyAssignedToDept;
                for (int i = 0; i < polyKeyList.Count; i++)
                {
                    Polygon2d polyA = polyKeyList[i];
                    for (int j = i + 1; j < polyKeyList.Count; j++)
                    {
                        Polygon2d polyB = polyKeyList[j];
                        Dictionary <string, object> checkNeighbor = PolygonUtility.FindPolyAdjacentEdgeEdit(polyA, polyB, 0.05);
                        if (checkNeighbor != null)
                        {
                            if ((bool)checkNeighbor["Neighbour"] == true)
                            {
                                networkLine.Add((Line2d)checkNeighbor["SharedEdge"]);
                                extraLines.Add((Line2d)checkNeighbor["SharedEdge"]);
                            }
                        }
                    }
                }
            }
            List <Line2d> cleanNetworkLines = LineUtility.RemoveDuplicateLines(networkLine);

            // extend the lines found
            for (int i = 0; i < cleanNetworkLines.Count; i++)
            {
                cleanNetworkLines[i] = LineUtility.ExtendLine(cleanNetworkLines[i], 2000);
            }

            cleanNetworkLines = RemoveNetworkRedundancy(cleanNetworkLines, circulationFrequency);

            //return cleanNetworkLines;
            return(new Dictionary <string, object>
            {
                { "CirculationNetworkLines", (cleanNetworkLines) }
            });
        }