Esempio n. 1
0
        //gets list of polygon2ds and find the most closest polygon2d to the center , to place the central stn
        internal static Dictionary <string, object> MakeCentralStation(List <Polygon2d> polygonsList, Point2d centerPt)
        {
            if (polygonsList == null || polygonsList.Count == 0)
            {
                return(null);
            }
            if (polygonsList.Count < 2)
            {
                return(new Dictionary <string, object>
                {
                    { "PolyCentral", (polygonsList) },
                    { "IndexInPatientPoly", (0) }
                });
            }
            List <Polygon2d> newPolyLists = new List <Polygon2d>();
            List <double>    distanceList = new List <double>();
            double           minArea = 100, ratio = 0.5, dis = 0;; int dir = 0;
            List <int>       indices     = PolygonUtility.SortPolygonsFromAPoint(polygonsList, centerPt);
            Polygon2d        polyToPlace = polygonsList[indices[0]];
            double           area        = PolygonUtility.AreaPolygon(polyToPlace);

            if (area > minArea)
            {
                List <double> spans = PolygonUtility.GetSpansXYFromPolygon2d(polyToPlace.Points);
                if (spans[0] > spans[1])
                {
                    dir = 1;
                    dis = spans[0] / 2;
                }
                else
                {
                    dir = 0;
                    dis = spans[1] / 2;
                }
                Random ran = new Random();
                //Dictionary<string, object> splittedPoly = BasicSplitPolyIntoTwo(polyToPlace, ratio, dir);
                //Dictionary<string, object> splittedPoly = SplitByDistanceFromPoint(polyToPlace, dis, dir);
                Dictionary <string, object> splittedPoly     = SplitObject.SplitByDistance(polyToPlace, ran, dis, dir);
                List <Polygon2d>            polyReturnedList = (List <Polygon2d>)splittedPoly["PolyAfterSplit"];
                if (!ValidateObject.CheckPolyList(polyReturnedList))
                {
                    return(null);
                }
                List <int> ind = PolygonUtility.SortPolygonsFromAPoint(polyReturnedList, centerPt);
                newPolyLists.Add(polyReturnedList[ind[0]]);
                newPolyLists.Add(polyReturnedList[ind[1]]);
            }
            else
            {
                newPolyLists.Add(polyToPlace);
            }
            return(new Dictionary <string, object>
            {
                { "PolyCentral", (newPolyLists) },
                { "IndexInPatientPoly", (indices[0]) }
            });
        }