Esempio n. 1
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) }
            });
        }
Esempio n. 2
0
        internal static Dictionary <string, object> PolygonPolygonCommonEdgeDict(Polygon2d poly, Polygon2d other)
        {
            bool check = false;

            if (poly == null || other == null)
            {
                return(null);
            }

            double    eps      = 200;
            Polygon2d polyReg  = new Polygon2d(poly.Points);
            Polygon2d otherReg = new Polygon2d(other.Points);
            Dictionary <string, object> UpdatedCenters = ComputePolyCentersAlign(polyReg, otherReg);

            Point2d centerPoly  = (Point2d)UpdatedCenters["CenterPolyA"];
            Point2d centerOther = (Point2d)UpdatedCenters["CenterPolyB"];

            polyReg  = (Polygon2d)UpdatedCenters["PolyA"];
            otherReg = (Polygon2d)UpdatedCenters["PolyB"];
            //make vectors
            Vector2d centerToCen  = new Vector2d(centerPoly, centerOther);
            Vector2d centerToCenX = new Vector2d(centerToCen.X, 0);
            Vector2d centerToCenY = new Vector2d(0, centerToCen.Y);
            //make centerLine
            Line2d   centerLine = new Line2d(centerPoly, centerOther);
            Vector2d keyVec;

            if (centerToCenX.Length > centerToCenY.Length)
            {
                keyVec = new Vector2d(centerToCenX.X, centerToCenX.Y);
            }
            else
            {
                keyVec = new Vector2d(centerToCenY.X, centerToCenY.Y);
            }
            //check line poly intersection between centertocen vector and each polys
            Line2d lineInPolyReg  = CodeToBeTested.LinePolygonIntersectionReturnLine(polyReg.Points, centerLine, centerOther);
            Line2d lineInOtherReg = CodeToBeTested.LinePolygonIntersectionReturnLine(otherReg.Points, centerLine, centerPoly);

            //find distance d1 and d2 from two centers to linepolyintersection line
            Point2d projectedPtOnPolyReg  = GraphicsUtility.ProjectedPointOnLine(lineInPolyReg, centerPoly);
            Point2d projectedPtOnOtherReg = GraphicsUtility.ProjectedPointOnLine(lineInOtherReg, centerOther);

            double dist1 = PointUtility.DistanceBetweenPoints(centerPoly, projectedPtOnPolyReg);
            double dist2 = PointUtility.DistanceBetweenPoints(centerOther, projectedPtOnOtherReg);

            double totalDistance = 2 * (dist1 + dist2);
            Line2d lineMoved     = new Line2d(lineInPolyReg.StartPoint, lineInPolyReg.EndPoint);

            lineMoved = LineUtility.Move(lineMoved, centerPoly);
            Point2d projectedPt = GraphicsUtility.ProjectedPointOnLine(lineMoved, centerOther);
            double  distance    = PointUtility.DistanceBetweenPoints(projectedPt, centerOther);

            bool isNeighbour = false;

            if (totalDistance - eps < distance && distance < totalDistance + eps)
            {
                isNeighbour = true;
            }
            else
            {
                isNeighbour = false;
            }

            return(new Dictionary <string, object>
            {
                { "Neighbour", (isNeighbour) },
                { "SharedEdgeA", (lineInPolyReg) },
                { "SharedEdgeB", (lineInOtherReg) },
                { "LineMoved", (lineMoved) },
                { "CenterToCenterLine", (centerLine) },
                { "CenterPolyPoint", (centerPoly) },
                { "CenterPolyOtherPoint", (centerOther) },
            });
        }