Пример #1
0
        public IPositionSet QueryConvexHull()
        {
            #region code for algorithm demo
            if (GetChildPositionSetInSpecificLevelOfConvexHull != null)
            {
                GetChildPositionSetInSpecificLevelOfConvexHull(m2mStructure.GetLevel(1), 1, m2mStructure.GetChildPositionSetByParentPart(0, m2mStructure.GetLevel(0).GetPartRefByPartIndex(0, 0)));
            }
            #endregion

            IPositionSet PositionSetInConvexHull = convexHullEngine.ConvexHull(
                m2mStructure.GetChildPositionSetByParentPart(0, m2mStructure.GetLevel(0).GetPartRefByPartIndex(0, 0)));

            for (int i = 1; i < m2mStructure.GetLevelNum(); i++)
            {
                ILevel currentLevel = m2mStructure.GetLevel(i);

                #region code for algorithm demo
                if (GetConvexHullPositionSetInSpecificLevel != null)
                {
                    GetConvexHullPositionSetInSpecificLevel(currentLevel, i, PositionSetInConvexHull);
                }
                #endregion

                tempChildPositionList = new List <IPosition>();

                tempChildPositionList.Capacity = 4 * PositionSetInConvexHull.GetNum();

                PositionSetInConvexHull.InitToTraverseSet();

                IPosition hullStartPoint = null;
                IPosition temp1          = null;
                IPosition temp2          = null;

                if (PositionSetInConvexHull.NextPosition())
                {
                    temp1          = PositionSetInConvexHull.GetPosition();
                    hullStartPoint = temp1;
                    AddChildPositionSetToList(i, temp1);

                    #region code for algorithm demo
                    if (GetLinePositionSetInSpecificLevel != null)
                    {
                        linePositionSetInSpecificLevel = new PositionSetEdit_ImplementByICollectionTemplate();
                        linePositionSetInSpecificLevel.AddPosition(new Position_Point(temp1.GetX(), temp1.GetY()));
                    }
                    #endregion
                }

                #region code for algorithm demo
                if (GetRepresentativeHullInSpecificLevel != null)
                {
                    representativeHull = new PositionSetEdit_ImplementByICollectionTemplate();
                }
                #endregion

                bool isWaitingLastPoint = true;

                //遍历该层凸包的每个分块,以确定下一层的候选分块
                while (true)
                {
                    if (isWaitingLastPoint)
                    {
                        if (PositionSetInConvexHull.NextPosition() == false)
                        {
                            isWaitingLastPoint = false;
                            temp2 = hullStartPoint;
                        }
                        else
                        {
                            temp2 = PositionSetInConvexHull.GetPosition();
                            AddChildPositionSetToList(i, temp2);
                        }
                    }
                    else
                    {
                        break;
                    }

                    IPosition start = new Position_Point(currentLevel.ConvertRealValueToRelativeValueX(((IPart)temp1).GetRandomOneFormDescendantPoint().GetX()), currentLevel.ConvertRealValueToRelativeValueY(((IPart)temp1).GetRandomOneFormDescendantPoint().GetY()));
                    IPosition end   = new Position_Point(currentLevel.ConvertRealValueToRelativeValueX(((IPart)temp2).GetRandomOneFormDescendantPoint().GetX()), currentLevel.ConvertRealValueToRelativeValueY(((IPart)temp2).GetRandomOneFormDescendantPoint().GetY()));

                    IPositionSet tempPositionSet = writeLineInGridEngine.WriteLineInGrid(currentLevel.GetGridWidth(), currentLevel.GetGridHeight(), start, end);

                    #region code for algorithm demo
                    if (GetRepresentativeHullInSpecificLevel != null)
                    {
                        representativeHull.AddPosition(start);
                        representativeHull.AddPosition(end);
                        GetRepresentativeHullInSpecificLevel(m2mStructure.GetLevel(i), i, representativeHull);
                    }
                    #endregion

                    tempPositionSet.InitToTraverseSet();

                    while (tempPositionSet.NextPosition())
                    {
                        IPosition tempPosition = tempPositionSet.GetPosition();

                        IPart tempPart = currentLevel.GetPartRefByPartIndex(currentLevel.ConvertRelativeValueToPartSequenceX(tempPosition.GetX()),
                                                                            currentLevel.ConvertRelativeValueToPartSequenceY(tempPosition.GetY()));

                        #region code for algorithm demo
                        if (GetLinePositionSetInSpecificLevel != null)
                        {
                            linePositionSetInSpecificLevel.AddPosition(new Position_Point(currentLevel.ConvertRelativeValueToPartSequenceX(tempPosition.GetX())
                                                                                          , currentLevel.ConvertRelativeValueToPartSequenceY(tempPosition.GetY())));
                        }
                        #endregion

                        if (tempPart != null)
                        {
                            AddChildPositionSetToList(i, tempPart);
                        }
                    }

                    #region code for algorithm demo
                    if (GetLinePositionSetInSpecificLevel != null)
                    {
                        if (isWaitingLastPoint)
                        {
                            linePositionSetInSpecificLevel.AddPosition(new Position_Point(temp2.GetX(), temp2.GetY()));
                        }
                    }
                    #endregion

                    #region code for algorithm demo
                    if (GetLinePositionSetInSpecificLevel != null)
                    {
                        GetLinePositionSetInSpecificLevel(m2mStructure.GetLevel(i), i, linePositionSetInSpecificLevel);
                    }
                    #endregion

                    temp1 = temp2;
                }

                IPositionSet ChildPositionSetInConvexHull = new PositionSetEdit_ImplementByICollectionTemplate(tempChildPositionList);

                #region code for algorithm demo
                if (GetChildPositionSetInSpecificLevelOfConvexHull != null)
                {
                    if (i < m2mStructure.GetLevelNum() - 1)
                    {
                        GetChildPositionSetInSpecificLevelOfConvexHull(m2mStructure.GetLevel(i + 1), i + 1, ChildPositionSetInConvexHull);
                    }
                }
                #endregion

                PositionSetInConvexHull =
                    convexHullEngine.ConvexHull(ChildPositionSetInConvexHull);
            }

            #region code for algorithm demo
            if (GetRealConvexHull != null)
            {
                GetRealConvexHull(PositionSetInConvexHull);
            }
            #endregion

            return(PositionSetInConvexHull);
        }
Пример #2
0
        public override void Draw(Graphics graphics)
        {
            if (Visible)
            {
                SetDrawerGraphic(graphics);

                List <IPosition_Connected> PartMiddlePointList = new List <IPosition_Connected>();

                List <PointF[]> PointArrayList = new List <PointF[]>();

                ILevel       level       = m2mStructure.GetLevel(levelSequence);
                IPart        rootPart    = m2mStructure.GetLevel(0).GetPartRefByPartIndex(0, 0);
                IPositionSet positionSet = m2mStructure.GetDescendentPositionSetByAncestorPart(levelSequence, rootPart, 0);

                Dictionary <IPosition, IPosition_Connected_Edit> partToPositionDictionary = new Dictionary <IPosition, IPosition_Connected_Edit>();

                positionSet.InitToTraverseSet();
                while (positionSet.NextPosition())
                {
                    Position_Connected_Edit PartDeputyPosition_Connected = new Position_Connected_Edit();
                    partToPositionDictionary.Add(positionSet.GetPosition(), PartDeputyPosition_Connected);
                }

                positionSet.InitToTraverseSet();

                while (positionSet.NextPosition())
                {
                    IPart_Connected currentPart = (IPart_Connected)positionSet.GetPosition();

                    IPositionSet bottomLevelPositionSet = m2mStructure.GetBottonLevelPositionSetByAncestorPart(currentPart, levelSequence);

                    IPosition tempPoint = PositionSetAttribute.GetGravityCenter(bottomLevelPositionSet);

                    IPosition_Connected_Edit PartDeputyPosition_Connected;
                    partToPositionDictionary.TryGetValue(positionSet.GetPosition(), out PartDeputyPosition_Connected);
                    PartDeputyPosition_Connected.SetX(tempPoint.GetX());
                    PartDeputyPosition_Connected.SetY(tempPoint.GetY());


                    currentPart.GetAdjacencyPositionSet().InitToTraverseSet();

                    while (currentPart.GetAdjacencyPositionSet().NextPosition())
                    {
                        IPosition_Connected_Edit adjDeputy;
                        partToPositionDictionary.TryGetValue(currentPart.GetAdjacencyPositionSet().GetPosition(), out adjDeputy);

                        PartDeputyPosition_Connected.GetAdjacencyPositionSetEdit().AddAdjacency(
                            adjDeputy, currentPart.GetAdjacencyPositionSet().GetDistanceToAdjacency());
                    }

                    PartMiddlePointList.Add(PartDeputyPosition_Connected);

                    IPositionSet ConvexHullPointSet = null;

                    if (bottomLevelPositionSet.GetNum() > 1)
                    {
                        ConvexHullPointSet = new QuickHull().ConvexHull(bottomLevelPositionSet);
                    }
                    else
                    {
                        ConvexHullPointSet = bottomLevelPositionSet;
                    }

                    PointF[] tempArray = new PointF[ConvexHullPointSet.GetNum()];

                    int sequence = 0;
                    ConvexHullPointSet.InitToTraverseSet();
                    while (ConvexHullPointSet.NextPosition())
                    {
                        tempArray[sequence].X = ConvertRealXToScreenX(ConvexHullPointSet.GetPosition().GetX());
                        tempArray[sequence].Y = ConvertRealYToScreenY(ConvexHullPointSet.GetPosition().GetY());
                        sequence++;
                    }

                    PointArrayList.Add(tempArray);
                }

                Pen   pen   = new Pen(partColor, partBorderWidth);
                Brush brush = new SolidBrush(Color.FromArgb(alpha, partColor));

                foreach (PointF[] pointArray in PointArrayList)
                {
                    if (pointArray.Length >= 2)
                    {
                        graphics.DrawPolygon(pen, pointArray);
                        graphics.FillPolygon(brush, pointArray);
                    }
                }

                this.positionSet = new PositionSet_ConnectedEdit(PartMiddlePointList);

                positionSetDrawerPump.ResetPump();
                positionSetDrawerPump.DrawCoordinate(pointCoordinateDrawer);
                positionSetDrawerPump.DrawPoint(pointDrawer);
                positionSetDrawerPump.DrawConnection(connectionDrawer);
                positionSetDrawerPump.Run();
            }
        }