internal static Dictionary <string, object> FindOuterLinesAndOffsets(Polygon2d poly, double patientRoomDepth = 16, double extension = 8000, double recompute = 5) { if (!ValidateObject.CheckPoly(poly)) { return(null); } Polygon2d polyReg = new Polygon2d(poly.Points); List <Line2d> hLines = new List <Line2d>(); List <Line2d> vLines = new List <Line2d>(); List <Point2d> hMidPt = new List <Point2d>(); List <Point2d> vMidPt = new List <Point2d>(); List <Line2d> nonOrthoLines = new List <Line2d>(); int countOrtho = 0, countNonOrtho = 0; for (int i = 0; i < polyReg.Points.Count; i++) { int a = i, b = i + 1; if (i == polyReg.Points.Count - 1) { b = 0; } Line2d line = new Line2d(polyReg.Points[a], polyReg.Points[b]); int lineType = ValidateObject.CheckLineOrient(line); if (lineType > -1) { if (lineType == 0) { Line2d extendedLine = LineUtility.ExtendLine(line, extension); hLines.Add(extendedLine); hMidPt.Add(LineUtility.LineMidPoint(line)); } if (lineType == 1) { Line2d extendedLine = LineUtility.ExtendLine(line, extension); vLines.Add(extendedLine); vMidPt.Add(LineUtility.LineMidPoint(line)); } countOrtho += 1; } else { countNonOrtho += 1; nonOrthoLines.Add(line); } } List <Line2d> selectedHLines = new List <Line2d>(); List <Line2d> selectedVLines = new List <Line2d>(); int hIndLow = CodeToBeTested.ReturnLowestPointFromList(hMidPt); int hIndHigh = CodeToBeTested.ReturnHighestPointFromList(hMidPt); int vIndLow = PointUtility.LowestPointFromList(vMidPt); int vIndHigh = PointUtility.HighestPointFromList(vMidPt); if (hIndLow > -1) { selectedHLines.Add(hLines[hIndLow]); } if (hIndHigh > -1) { selectedHLines.Add(hLines[hIndHigh]); } if (vIndLow > -1) { selectedVLines.Add(vLines[vIndLow]); } if (vIndHigh > -1) { selectedVLines.Add(vLines[vIndHigh]); } List <Line2d> allSplitLines = new List <Line2d>(); allSplitLines.AddRange(selectedHLines); allSplitLines.AddRange(selectedVLines); List <double> splitLineLength = new List <double>(); for (int i = 0; i < allSplitLines.Count; i++) { splitLineLength.Add(allSplitLines[i].Length); } List <int> sortedIndices = BasicUtility.Quicksort(splitLineLength); if (sortedIndices != null) { sortedIndices.Reverse(); } List <Line2d> offsetLines = new List <Line2d>(); List <Point2d> midPtsOffsets = new List <Point2d>(); for (int i = 0; i < allSplitLines.Count; i++) { offsetLines.Add(LineUtility.Offset(allSplitLines[i], patientRoomDepth)); midPtsOffsets.Add(LineUtility.NudgeLineMidPt(allSplitLines[i], poly, patientRoomDepth)); } List <Line2d> offsetSortedLines = new List <Line2d>(); for (int i = 0; i < offsetLines.Count; i++) { offsetSortedLines.Add(offsetLines[sortedIndices[i]]); } return(new Dictionary <string, object> { { "SplittableLines", (allSplitLines) }, { "OffsetLines", (offsetSortedLines) }, { "SortedIndices", (sortedIndices) }, { "OffsetMidPts", (midPtsOffsets) }, { "NonOrthoLines", (nonOrthoLines) } }); }
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) } }); }