Ejemplo n.º 1
0
        internal static Dictionary <string, object> ExtLinesAndOffsetsFromBBox(Polygon2d poly, double patientRoomDepth = 16, double recompute = 5)
        {
            if (!ValidateObject.CheckPoly(poly))
            {
                return(null);
            }
            Polygon2d     polyReg       = new Polygon2d(poly.Points);
            List <Line2d> allSplitLines = new List <Line2d>();
            Polygon2d     polyBBox      = Polygon2d.ByPoints(ReadData.FromPointsGetBoundingPoly(polyReg.Points));

            allSplitLines = polyBBox.Lines;
            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) }
            });
        }
Ejemplo n.º 2
0
        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> MakeProgCirculationPolys(List <Line2d> circulationNetwork, List <Polygon2d> polyProgList, double circulationWidth = 8, double circulationFrequency = 0.5, int designSeed = 10)
        {
            if (!ValidateObject.CheckPolyList(polyProgList))
            {
                return(null);
            }
            if (circulationNetwork == null || circulationNetwork.Count == 0)
            {
                return(null);
            }
            List <Line2d> flatLineList    = new List <Line2d>();
            List <bool>   IsDuplicateList = new List <bool>();

            polyProgList = PolygonUtility.SmoothPolygonList(polyProgList, 5);

            //flatten all the polys in each depts to make it one list
            List <Polygon2d> circulationPolyList = new List <Polygon2d>();
            List <Polygon2d> updatedProgPolyList = new List <Polygon2d>();
            List <int>       deptIdList          = new List <int>();
            double           allowedCircRatio    = 4;
            List <double>    areaProgPolyList    = new List <double>();

            for (int i = 0; i < polyProgList.Count; i++)
            {
                areaProgPolyList.Add(PolygonUtility.AreaPolygon(polyProgList[i]));
            }

            double maxArea = areaProgPolyList.Max();

            areaProgPolyList.Sort();
            int    value      = (int)(areaProgPolyList.Count / 3);
            double areaThresh = areaProgPolyList[value];
            Random ran        = new Random(designSeed);

            for (int i = 0; i < circulationNetwork.Count; i++)
            {
                Line2d splitter   = circulationNetwork[i];
                double someNumber = BasicUtility.RandomBetweenNumbers(ran, 1, 0);
                if (someNumber > circulationFrequency)
                {
                    continue;
                }
                for (int j = 0; j < polyProgList.Count; j++)
                {
                    Polygon2d progPoly = polyProgList[j];
                    double    areaPoly = PolygonUtility.AreaPolygon(progPoly);

                    Point2d midPt       = LineUtility.LineMidPoint(splitter);
                    Point2d nudgedMidPt = LineUtility.NudgeLineMidPt(splitter, progPoly, 0.5);
                    bool    checkInside = GraphicsUtility.PointInsidePolygonTest(progPoly, nudgedMidPt);

                    if (checkInside)
                    {
                        Dictionary <string, object> splitResult    = SplitObject.SplitByLine(progPoly, splitter, circulationWidth);
                        List <Polygon2d>            polyAfterSplit = (List <Polygon2d>)(splitResult["PolyAfterSplit"]);
                        if (ValidateObject.CheckPolyList(polyAfterSplit))
                        {
                            double areaA = PolygonUtility.AreaPolygon(polyAfterSplit[0]), areaB = PolygonUtility.AreaPolygon(polyAfterSplit[1]);
                            if (areaA < areaB)
                            {
                                if (polyAfterSplit[0].Points != null)
                                {
                                    if (ValidateObject.CheckPolyBBox(polyAfterSplit[0], allowedCircRatio))
                                    {
                                        circulationPolyList.Add(polyAfterSplit[0]);
                                    }
                                }
                                updatedProgPolyList.Add(polyAfterSplit[1]);
                            }
                            else
                            {
                                if (polyAfterSplit[1].Points != null)
                                {
                                    if (ValidateObject.CheckPolyBBox(polyAfterSplit[1], allowedCircRatio))
                                    {
                                        circulationPolyList.Add(polyAfterSplit[1]);
                                    }
                                }
                                updatedProgPolyList.Add(polyAfterSplit[0]);
                            }
                        } // end of if loop checking polylist
                    }     // end of check inside
                }         // end of for loop j
            }             // end of for loop i

            return(new Dictionary <string, object>
            {
                { "ProgCirculationPoly", (circulationPolyList) }
            });
        }
        public static Dictionary <string, object> MakeDeptCirculationPolys(List <DeptData> deptData, List <List <Line2d> > circulationNetwork, double circulationWidth = 8)
        {
            if (deptData == null || deptData.Count == 0 || circulationNetwork == null || circulationNetwork.Count == 0)
            {
                return(null);
            }
            List <Line2d>    cleanLineList       = LineUtility.FlattenLine2dList(circulationNetwork);
            List <Polygon2d> allDeptPolyList     = new List <Polygon2d>();
            List <Polygon2d> circulationPolyList = new List <Polygon2d>();
            List <Polygon2d> updatedDeptPolyList = new List <Polygon2d>();
            List <int>       deptIdList          = new List <int>();

            for (int i = 0; i < deptData.Count; i++)
            {
                List <Polygon2d> deptPolyList = deptData[i].PolyAssignedToDept;
                if (!ValidateObject.CheckPolyList(deptPolyList))
                {
                    continue;
                }
                for (int j = 0; j < deptPolyList.Count; j++)
                {
                    deptIdList.Add(i);
                    allDeptPolyList.Add(deptPolyList[j]);
                }
            }

            for (int i = 0; i < cleanLineList.Count; i++)
            {
                Line2d splitter = cleanLineList[i];
                for (int j = 0; j < allDeptPolyList.Count; j++)
                {
                    Polygon2d deptPoly    = allDeptPolyList[j];
                    Point2d   midPt       = LineUtility.LineMidPoint(splitter);
                    Point2d   nudgedMidPt = LineUtility.NudgeLineMidPt(splitter, deptPoly, 0.5);
                    if (GraphicsUtility.PointInsidePolygonTest(deptPoly, nudgedMidPt))
                    {
                        Dictionary <string, object> splitResult    = SplitObject.SplitByLine(deptPoly, splitter, circulationWidth);
                        List <Polygon2d>            polyAfterSplit = (List <Polygon2d>)(splitResult["PolyAfterSplit"]);
                        if (ValidateObject.CheckPolyList(polyAfterSplit))
                        {
                            double areaA = PolygonUtility.AreaPolygon(polyAfterSplit[0]);
                            double areaB = PolygonUtility.AreaPolygon(polyAfterSplit[1]);
                            if (areaA < areaB)
                            {
                                circulationPolyList.Add(polyAfterSplit[0]);
                                updatedDeptPolyList.Add(polyAfterSplit[1]);
                            }
                            else
                            {
                                circulationPolyList.Add(polyAfterSplit[1]);
                                updatedDeptPolyList.Add(polyAfterSplit[0]);
                            }
                        }
                    } // end of check inside
                }     // end of for loop j
            }         // end of for loop i

            List <List <Polygon2d> > deptPolyBranchedInList = new List <List <Polygon2d> >();
            List <int> distinctIdList = deptIdList.Distinct().ToList();

            for (int i = 0; i < distinctIdList.Count; i++)
            {
                List <Polygon2d> polyForDeptBranch = new List <Polygon2d>();
                for (int j = 0; j < deptIdList.Count; j++)
                {
                    if (deptIdList[j] == i)
                    {
                        if (j < updatedDeptPolyList.Count)
                        {
                            polyForDeptBranch.Add(updatedDeptPolyList[j]);
                        }
                    }
                }
                deptPolyBranchedInList.Add(polyForDeptBranch);
            }
            return(new Dictionary <string, object>
            {
                { "DeptCirculationPoly", (circulationPolyList) },
                { "UpdatedDeptPolys", (deptPolyBranchedInList) }
            });
        }