Exemplo n.º 1
0
        //初始化地图,在地图被更改之后调用
        public void InitEngineForMap(IPositionSet_Connected mapPositionSet_Connected)
        {
            this.mapPositionSet_Connected = mapPositionSet_Connected;

            M2MSCreater_ForGeneralM2MStruture m2m_Creater_ForGeneralM2MStruture = new M2MSCreater_ForGeneralM2MStruture();

            m2m_Creater_ForGeneralM2MStruture.PartType = typeof(Part_Multi);
            m2m_Creater_ForGeneralM2MStruture.SetPointInPartFactor(50);
            m2m_Creater_ForGeneralM2MStruture.SetUnitNumInGridLength(3);
            m2mStructure = m2m_Creater_ForGeneralM2MStruture.CreateAutomatically(mapPositionSet_Connected);
            m2mStructure.Preprocessing(mapPositionSet_Connected);
            BuildPartSetConnectionForM2MStructure buildPartSetConnectionForM2MStructure = new BuildPartSetConnectionForM2MStructure();

            buildPartSetConnectionForM2MStructure.TraversalEveryLevelAndBuild(m2mStructure);

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

            int num = (int)(Math.Sqrt((double)mapPositionSet_Connected.GetNum()));

            path = new List <IPosition_Connected>(num * 2);

            if (num > 0)
            {
                open = new PriorityQueue <IPosition_Connected>(num * 4, com);
            }
            else
            {
                open = new PriorityQueue <IPosition_Connected>(com);
            }
        }
Exemplo n.º 2
0
        public void PreProcess(IPositionSet positionSet)
        {
            #region code for algorithm demo
            if (GetPositionSetToGetConvexHull != null)
            {
                GetPositionSetToGetConvexHull(positionSet);
            }
            #endregion

            //请在这里改变不同的m2mStructure实现。
            M2MSCreater_ForGeneralM2MStruture m2m_Creater_ForGeneralM2MStruture = new M2MSCreater_ForGeneralM2MStruture();

            m2m_Creater_ForGeneralM2MStruture.SetPointInPartFactor(set_pointInPartFactor);

            m2mStructure = m2m_Creater_ForGeneralM2MStruture.CreateAutomatically(positionSet);

            m2mStructure.Preprocessing(positionSet);

            #region code for algorithm demo
            if (GetM2MStructure != null)
            {
                GetM2MStructure(m2mStructure);
            }
            #endregion
        }
Exemplo n.º 3
0
        private void OnGetM2MStructure(IM2MStructure m2mStructure)
        {
            lock (layers)
            {
                layers.Add(new Layer_M2MStructure(m2mStructure));
            }

            flowControlerForm.BeginInvoke(Update);
            flowControlerForm.SuspendAndRecordWorkerThread();
        }
Exemplo n.º 4
0
        public Layer_M2MStructure(IM2MStructure m2mStructure)
        {
            this.m2mStructure = m2mStructure;
            layerList         = new Layer_M2MLevel[m2mStructure.GetLevelNum()];

            for (int i = 0; i < layerList.Length; i++)
            {
                layerList[i] = new Layer_M2MLevel(m2mStructure.GetLevel(i));
            }

            UpdateLayerListTransform();

            maxRect = layerList[0].MaxRect;
        }
            public void InitToGetTheNearestPointInPart(IPart part, int AncestorLevelSequence, IM2MStructure M2MS, IPosition point)
            {
                this.AncestorLevelSequence = AncestorLevelSequence;
                this.M2MS = M2MS;

                currentPart           = part;
                comparePoint          = point;
                nearestDistanceSquare = float.MaxValue;

                upperBound = float.MaxValue;
                lowerBound = 0;
                leftBound  = 0;
                rightBound = float.MaxValue;
            }
Exemplo n.º 6
0
        public Layer_PartSet_Connected(IM2MStructure m2mStructure, int levelSequence)
        {
            this.m2mStructure  = m2mStructure;
            this.levelSequence = levelSequence;

            positionSetDrawerPump = new PositionSetDrawerPump(this);

            pointCoordinateDrawer.Visible = false;

            connectionDrawer.LineWidth    = 1;
            pointDrawer.IsDrawPointBorder = true;
            pointDrawer.PointRadius       = 1;

            PartColor = GenerateColor.GetSimilarColor(MainColor);
        }
Exemplo n.º 7
0
        private void TestForViewer(object sender, EventArgs e)
        {
            painterDialog.Show();

            painterDialog.Reset();
            painterDialog.HoldOnMode();

            RandomPositionSet_InFixedDistribution randomPositionSet1 = new RandomPositionSet_InFixedDistribution
                                                                           (10000, distributionStyle.GaussianDistribution);

            new ConfiguratedByForm(randomPositionSet1);
            randomPositionSet1.Produce();

            RandomPositionSet_InFixedDistribution randomPositionSet2 = new RandomPositionSet_InFixedDistribution
                                                                           (10000, distributionStyle.LaplaceDistribution);

            new ConfiguratedByForm(randomPositionSet2);
            randomPositionSet2.Produce();

            M2MSCreater_ForGeneralM2MStruture m2m_Creater_ForGeneralM2MStruture = new M2MSCreater_ForGeneralM2MStruture();
            IM2MStructure m2mStructure = m2m_Creater_ForGeneralM2MStruture.CreateAutomatically(randomPositionSet2);

            m2mStructure.Preprocessing(randomPositionSet2);

            painterDialog.Clear();
            painterDialog.DrawPositionSet(randomPositionSet1);
            painterDialog.DrawPositionSet(randomPositionSet2);
            painterDialog.DrawM2MLevel(m2mStructure.GetLevel(m2mStructure.GetLevelNum() - 1));
            painterDialog.DrawM2MStructure(m2mStructure);
            Layer_PositionSet layer = new Layer_PositionSet_Point(GetRamSet2());

            layer.SetPositionSetTransformByM2MLevel(m2mStructure.GetLevel(m2mStructure.GetLevelNum() - 1));
            //painterDialog.Painter.Layers.Add(layer);
            painterDialog.Show();

            painterDialog.Clear();
            painterDialog.DrawPath(GetRamSet(1000, 800));
            painterDialog.DrawPositionSet(GetRamSet(500, 400));
            painterDialog.DrawConvexHull(GetRamSet2());
            painterDialog.DrawSquareFrame(GetRamSet(500, 400));
            painterDialog.Show();

            painterDialog.Reset();
        }
Exemplo n.º 8
0
        public void DrawM2MStructure(IM2MStructure m2mStructure)
        {
            layers.Add(new Layer_M2MStructure(m2mStructure));

            IfNotHoldingShowFormInShowMode();
        }
Exemplo n.º 9
0
        public void PreProcess(PositionSetEditSet pointList)
        {
            #region code for algorithm demo
            if (GetPositionSetToGetConvexHull != null)
            {
                GetPositionSetToGetConvexHull(pointList);
            }
            #endregion

            //请在这里改变不同的m2mStructure实现。
            M2MSCreater_ForGeneralM2MStruture m2m_Creater_ForGeneralM2MStruture = new M2MSCreater_ForGeneralM2MStruture();

            m2mStructure = m2m_Creater_ForGeneralM2MStruture.CreateAutomatically(pointList, levelNum);

            PositionSetEdit_ImplementByICollectionTemplate positionSet = new PositionSetEdit_ImplementByICollectionTemplate();



            ILevel bottomLevel = m2mStructure.GetLevel(m2mStructure.GetLevelNum() - 1);

            for (int i = 0; i < pointList.GetPositionSetNum(); i++)
            {
                IPosition start = new Position_Point();
                IPosition end   = new Position_Point();
                IPosition first = new Position_Point();

                IPositionSet positionListTemp = pointList.GetNthPositionSet(i);

                positionListTemp.InitToTraverseSet();
                if (positionListTemp.NextPosition())
                {
                    start = new Position_Point(bottomLevel.ConvertRealValueToRelativeValueX(positionListTemp.GetPosition().GetX()), bottomLevel.ConvertRealValueToRelativeValueY(positionListTemp.GetPosition().GetY()));
                    first = start;
                    positionSet.AddPosition(start);
                }
                while (positionListTemp.NextPosition())
                {
                    end = new Position_Point(bottomLevel.ConvertRealValueToRelativeValueX(positionListTemp.GetPosition().GetX()), bottomLevel.ConvertRealValueToRelativeValueY(positionListTemp.GetPosition().GetY()));
                    IPositionSet positionSetTemp = writeLineInGridEngine.WriteLineInGrid(bottomLevel.GetGridWidth(), bottomLevel.GetGridHeight(), start, end);
                    if (positionSetTemp != null)
                    {
                        positionSetTemp.InitToTraverseSet();
                        while (positionSetTemp.NextPosition())
                        {
                            positionSet.AddPosition(positionSetTemp.GetPosition());
                        }
                    }
                    start = end;
                    positionSet.AddPosition(start);
                }
                IPositionSet positionSetTemp2 = writeLineInGridEngine.WriteLineInGrid(bottomLevel.GetGridWidth(), bottomLevel.GetGridHeight(), end, first);
                if (positionSetTemp2 != null)
                {
                    positionSetTemp2.InitToTraverseSet();
                    while (positionSetTemp2.NextPosition())
                    {
                        positionSet.AddPosition(positionSetTemp2.GetPosition());
                    }
                }
            }

            m2mStructure.Preprocessing(positionSet);

            #region code for algorithm demo
            if (GetM2MStructure != null)
            {
                GetM2MStructure(m2mStructure);
            }
            #endregion
        }
Exemplo n.º 10
0
        private void preProcessForPositionSetConnectedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IPositionSet_Connected pSet = (IPositionSet_Connected)positionSetContainer.GetPositionSet();

            LayersExOptDlg       layers               = new LayersExOptDlg();
            LayersPainterForm    layersPainterForm    = new LayersPainterForm(layers);
            LayersPaintedControl layersPaintedControl = layersPainterForm.LayersPaintedControl;
            LayersEditedControl  layersEditedControl  = new LayersEditedControl();

            layersEditedControl.Dock = DockStyle.Top;
            layersEditedControl.LayersPaintedControl = layersPaintedControl;
            layersPainterForm.Controls.Add(layersEditedControl);

            Layer_PositionSet_Connected layer_PositionSet_Connected = new Layer_PositionSet_Connected(pSet);

            layer_PositionSet_Connected.Point.PointColor     = Color.Yellow;
            layer_PositionSet_Connected.Connection.LineColor = Color.Blue;
            layer_PositionSet_Connected.Connection.LineWidth = 0.6f;
            layer_PositionSet_Connected.Point.PointRadius    = 1.2f;
            layers.Add(layer_PositionSet_Connected);
            layer_PositionSet_Connected.SpringLayerRepresentationChangedEvent(layer_PositionSet_Connected);


            M2MSCreater_ForGeneralM2MStruture m2m_Creater_ForGeneralM2MStruture = new M2MSCreater_ForGeneralM2MStruture();

            m2m_Creater_ForGeneralM2MStruture.PartType = typeof(Part_Multi);
            m2m_Creater_ForGeneralM2MStruture.SetPointInPartFactor(50);
            m2m_Creater_ForGeneralM2MStruture.SetUnitNumInGridLength(3);

            IM2MStructure m2mStructure = m2m_Creater_ForGeneralM2MStruture.CreateAutomatically(pSet);

            m2mStructure.Preprocessing(pSet);

            BuildPartSetConnectionForM2MStructure buildPartSetConnectionForM2MStructure = new BuildPartSetConnectionForM2MStructure();

            buildPartSetConnectionForM2MStructure.TraversalEveryLevelAndBuild(m2mStructure);

            layers.Add(new Layer_M2MStructure(m2mStructure));

            for (int levelSequence = 1; levelSequence < m2mStructure.GetLevelNum(); levelSequence++)
            {
                //ILevel level = m2mStructure.GetLevel(levelSequence);
                //IPart rootPart = m2mStructure.GetLevel(0).GetPartRefByPartIndex(0, 0);
                //IPositionSet positionSet = m2mStructure.GetDescendentPositionSetByAncestorPart(levelSequence, rootPart, 0);

                //List<IPosition_Connected> position_ConnectedList = new List<IPosition_Connected>();
                //positionSet.InitToTraverseSet();
                //while (positionSet.NextPosition())
                //{
                //    position_ConnectedList.Add((IPosition_Connected)positionSet.GetPosition());
                //}

                //PositionSet_Connected positionSet_Connected = new PositionSet_Connected(position_ConnectedList);

                Layer_PartSet_Connected layer_PartSet_Connected = new Layer_PartSet_Connected(m2mStructure, levelSequence);
                //layer_PartSet_Connected.MainColor
                //layer_PartSet_Connected.Active = true;
                //layer_PartSet_Connected.SetPositionSetTransformByM2MLevel(level);

                layers.Add(layer_PartSet_Connected);
            }

            layersPainterForm.ShowDialog();
        }
Exemplo n.º 11
0
        private void pathFindingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IPositionSet_Connected positionSet_Connected = (IPositionSet_Connected)positionSetContainer.GetPositionSet();

            Dijkstra dijkstra = new Dijkstra();
            AStar    astar    = new AStar();
            M2M_PF   m2m_PF   = new M2M_PF();

            IM2MStructure m2mStructure = null;

            List <IPosition_Connected> m2mPath = null;
            List <IPosition_Connected> path    = null;

            //计算算法运行时间用
            //IPosition_Connected start = null;
            //IPosition_Connected end = null;
            ISearchPathEngine searchPathEngine1 = m2m_PF;
            ISearchPathEngine searchPathEngine2 = dijkstra;

            m2m_PF.GetM2MStructure             += delegate(IM2MStructure m2mS) { m2mStructure = m2mS; };
            m2m_PF.GetM2MStructureInPreprocess += delegate(IM2MStructure m2mS) { m2mStructure = m2mS; };
            List <ushort> timeStampList = new List <ushort>();

            m2m_PF.GetTimeStamp += delegate(ushort timeStamp) { timeStampList.Add(timeStamp); };

            searchPathEngine1.InitEngineForMap(positionSet_Connected);
            searchPathEngine2.InitEngineForMap(positionSet_Connected);

            //以下代码必须在UI线程中调用,即不能在另开的线程中调用
            LayersExOptDlg       layers               = new LayersExOptDlg();
            LayersPainterForm    layersPainterForm    = new LayersPainterForm(layers);
            LayersPaintedControl layersPaintedControl = layersPainterForm.LayersPaintedControl;
            LayersEditedControl  layersEditedControl  = new LayersEditedControl();

            layersEditedControl.Dock = DockStyle.Top;
            layersEditedControl.LayersPaintedControl = layersPaintedControl;
            layersPainterForm.Controls.Add(layersEditedControl);
            layersPainterForm.Show();

            //打开一个Worker线程来进行算法流程的演示(否则会阻塞UI线程以至于演示不能进行)
            IAsyncResult result = new dDemoProcess(delegate
            {
                Layer_PositionSet_Connected layer_PositionSet_Connected = new Layer_PositionSet_Connected(positionSet_Connected);
                layer_PositionSet_Connected.Point.PointColor            = Color.Yellow;
                layer_PositionSet_Connected.Connection.LineColor        = Color.Blue;
                layer_PositionSet_Connected.Connection.LineWidth        = 0.6f;
                layer_PositionSet_Connected.Point.PointRadius           = 1.2f;
                layers.Add(layer_PositionSet_Connected);
                layer_PositionSet_Connected.SpringLayerRepresentationChangedEvent(layer_PositionSet_Connected);

                for (int levelSequence = 1; levelSequence < m2mStructure.GetLevelNum(); levelSequence++)
                {
                    Layer_PartSet_Connected layer_PartSet_Connected = new Layer_PartSet_Connected(m2mStructure, levelSequence);
                    layer_PartSet_Connected.Visible = false;
                    layers.Add(layer_PartSet_Connected);
                }

                while (true)
                {
                    IPosition_Connected start = (IPosition_Connected)layersEditedControl.GetMouseDoubleChickedNearestPositionInCurrentPositionSet(positionSet_Connected);
                    PositionSet_ConnectedEdit startPointSet = new PositionSet_ConnectedEdit();
                    startPointSet.AddPosition_Connected(start);
                    Layer_PositionSet_Point layerStartPoint = new Layer_PositionSet_Point(startPointSet);
                    layerStartPoint.Active = true;
                    layerStartPoint.Point.IsDrawPointBorder = true;
                    layerStartPoint.Point.PointRadius       = 5;
                    layerStartPoint.Point.PointColor        = Color.PaleGreen;
                    layers.Add(layerStartPoint);
                    layerStartPoint.SpringLayerRepresentationChangedEvent(layerStartPoint);

                    IPosition_Connected end = (IPosition_Connected)layersEditedControl.GetMouseDoubleChickedNearestPositionInCurrentPositionSet(positionSet_Connected);
                    PositionSet_ConnectedEdit endPointSet = new PositionSet_ConnectedEdit();
                    endPointSet.AddPosition_Connected(end);
                    Layer_PositionSet_Point layerEndPoint = new Layer_PositionSet_Point(endPointSet);
                    layerEndPoint.Active = true;
                    layerEndPoint.Point.IsDrawPointBorder = true;
                    layerEndPoint.Point.PointRadius       = 5;
                    layerEndPoint.Point.PointColor        = Color.Cyan;
                    layers.Add(layerEndPoint);
                    layerEndPoint.SpringLayerRepresentationChangedEvent(layerEndPoint);

                    CountTimeTool.TimeCounter timeCounter = new CountTimeTool.TimeCounter();

                    searchPathEngine2.InitEngineForMap(positionSet_Connected);
                    double time2      = timeCounter.CountTimeForRepeatableMethod(delegate { searchPathEngine2.SearchPath(start, end); });
                    path              = searchPathEngine2.SearchPath(start, end);
                    float pathLength2 = ((Dijkstra)searchPathEngine2).GetPathLength();
                    Console.WriteLine("Dijkstra consume time: " + time2 + " path Length = " + pathLength2);

                    searchPathEngine1.InitEngineForMap(positionSet_Connected);

                    //清空timeStampList以记录寻径过程各层的timeStamp
                    double time1 = timeCounter.CountTimeForRepeatableMethod(delegate { searchPathEngine1.SearchPath(start, end); });

                    timeStampList.Clear();
                    m2mPath           = searchPathEngine1.SearchPath(start, end);
                    float pathLength1 = ((M2M_PF)searchPathEngine1).GetPathLength();

                    Console.WriteLine("M2M_PF   consume time: " + time1 + " path Length = " + pathLength1);
                    //searchPathEngine1.SearchPath(start, end);

                    if (searchPathEngine1 is M2M_PF && m2mStructure != null)
                    {
                        for (int levelSequence = 1; levelSequence < m2mStructure.GetLevelNum(); levelSequence++)
                        {
                            ILevel level             = m2mStructure.GetLevel(levelSequence);
                            IPart rootPart           = m2mStructure.GetLevel(0).GetPartRefByPartIndex(0, 0);
                            IPositionSet positionSet = m2mStructure.GetDescendentPositionSetByAncestorPart(levelSequence, rootPart, 0);

                            List <IPosition_Connected> position_ConnectedList = new List <IPosition_Connected>();
                            positionSet.InitToTraverseSet();
                            while (positionSet.NextPosition())
                            {
                                if (positionSet.GetPosition() is IPart_Multi)
                                {
                                    IPart_Multi partMulti = (IPart_Multi)positionSet.GetPosition();
                                    IEnumerable <IPart_Connected> part_ConnectedEnumerable = partMulti.GetSubPartSet();

                                    foreach (IPart_Connected part in part_ConnectedEnumerable)
                                    {
                                        IPosition_Connected tempPartConnected = (IPosition_Connected)part;
                                        if (((Tag_M2M_Part)tempPartConnected.GetAttachment()).isNeedToSearch == true)
                                        {
                                            if (timeStampList[levelSequence - 1] == ((Tag_M2M_Part)tempPartConnected.GetAttachment()).timeStamp)
                                            {
                                                position_ConnectedList.Add(tempPartConnected);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    IPosition_Connected tempPartConnected = (IPosition_Connected)positionSet.GetPosition();
                                    if (((Tag_M2M_Part)tempPartConnected.GetAttachment()).isNeedToSearch == true)
                                    {
                                        if (timeStampList[levelSequence - 1] == ((Tag_M2M_Part)tempPartConnected.GetAttachment()).timeStamp)
                                        {
                                            position_ConnectedList.Add(tempPartConnected);
                                        }
                                    }
                                }
                            }

                            IPositionSet partSet = new PositionSet_Connected(position_ConnectedList);

                            Layer_M2MPartSetInSpecificLevel layer_M2MPartSetInSpecificLevel = new Layer_M2MPartSetInSpecificLevel(m2mStructure.GetLevel(levelSequence), partSet);
                            layer_M2MPartSetInSpecificLevel.Active = true;
                            layer_M2MPartSetInSpecificLevel.Alpha  = 100;
                            //layer_M2MPartSetInSpecificLevel.

                            layers.Add(layer_M2MPartSetInSpecificLevel);

                            //PositionSet_Connected partSet_Connected = new PositionSet_Connected(position_ConnectedList);

                            //Layer_PositionSet_Connected layer_PartSet_Connected = new Layer_PositionSet_Connected(partSet_Connected);
                            ////layer_PartSet_Connected.MainColor
                            ////layer_PartSet_Connected.Active = true;
                            //layer_PartSet_Connected.SetPositionSetTransformByM2MLevel(level);

                            //layers.Add(layer_PartSet_Connected);
                        }
                    }

                    if (path != null)
                    {
                        Layer_PositionSet_Path layer = new Layer_PositionSet_Path(new PositionSet_Connected(path));
                        layer.Active                      = true;
                        layer.PathLine.LineColor          = Color.Black;
                        layer.PathLine.LineWidth          = 2;
                        layer.PathPoint.PointRadius       = 2;
                        layer.PathPoint.IsDrawPointBorder = true;

                        //layer.EditAble = true;
                        //layer.Point.PointColor = Color.Yellow;
                        //layer.Point.PointRadius = 2;
                        //layer.Point.IsDrawPointBorder = true;
                        layers.Add(layer);
                        layer.SpringLayerRepresentationChangedEvent(layer);
                    }
                    else
                    {
                        this.BeginInvoke(new dShow(MessageBox.Show), new object[] { "There is no path between two node" });
                    }

                    if (m2mPath != null)
                    {
                        Layer_PositionSet_Path layer = new Layer_PositionSet_Path(new PositionSet_Connected(m2mPath));
                        layer.Active                      = true;
                        layer.PathLine.LineColor          = Color.Red;
                        layer.PathLine.LineWidth          = 2;
                        layer.PathPoint.PointRadius       = 2;
                        layer.PathPoint.IsDrawPointBorder = true;

                        //layer.EditAble = true;
                        //layer.Point.PointColor = Color.Yellow;
                        //layer.Point.PointRadius = 2;
                        //layer.Point.IsDrawPointBorder = true;
                        layers.Add(layer);
                        layer.SpringLayerRepresentationChangedEvent(layer);
                    }
                    else
                    {
                        this.BeginInvoke(new dShow(MessageBox.Show), new object[] { "There is no path between two node by M2M_PF" });
                    }
                }
            }).BeginInvoke(null, null);
        }
Exemplo n.º 12
0
        private void TestBotton_Click(object sender, EventArgs e)
        {
            PainterDialog painterDialog = new PainterDialog();

            RandomPositionSet_Connected_Config config = new RandomPositionSet_Connected_Config();

            new ConfiguratedByForm(config);
            IPositionSet_ConnectedEdit pSet = config.Produce();

            painterDialog.DrawPositionSet_Connected(pSet);

            M2MSCreater_ForGeneralM2MStruture m2m_Creater_ForGeneralM2MStruture = new M2MSCreater_ForGeneralM2MStruture();

            m2m_Creater_ForGeneralM2MStruture.PartType = typeof(Part_Multi);
            m2m_Creater_ForGeneralM2MStruture.SetPointInPartFactor(10);
            m2m_Creater_ForGeneralM2MStruture.SetUnitNumInGridLength(4);

            IM2MStructure m2mStructure = m2m_Creater_ForGeneralM2MStruture.CreateAutomatically(pSet);

            m2mStructure.Preprocessing(pSet);
            painterDialog.DrawM2MStructure(m2mStructure);

            BuildPartSetConnectionForM2MStructure buildPartSetConnectionForM2MStructure = new BuildPartSetConnectionForM2MStructure();

            buildPartSetConnectionForM2MStructure.GetPartSetInSpecificLevel += delegate(ILevel level, int levelSequence, IPositionSet positionSet) {
                List <IPosition_Connected> position_ConnectedList = new List <IPosition_Connected>();

                positionSet.InitToTraverseSet();
                while (positionSet.NextPosition())
                {
                    IPart_Multi partMulti = (IPart_Multi)positionSet.GetPosition();
                    IEnumerable <IPart_Connected> part_ConnectedEnumerable = partMulti.GetSubPartSet();

                    foreach (IPart_Connected part in part_ConnectedEnumerable)
                    {
                        position_ConnectedList.Add((IPosition_Connected)part);
                    }
                }

                PositionSet_Connected       positionSet_Connected       = new PositionSet_Connected(position_ConnectedList);
                Layer_PositionSet_Connected layer_PositionSet_Connected = new Layer_PositionSet_Connected(positionSet_Connected);
                layer_PositionSet_Connected.SetPositionSetTransformByM2MLevel(level);
                painterDialog.Layers.Add(layer_PositionSet_Connected);

                painterDialog.Show();
            };

            buildPartSetConnectionForM2MStructure.TraversalEveryLevelAndBuild(m2mStructure);

            for (int levelSequence = 1; levelSequence < m2mStructure.GetLevelNum(); levelSequence++)
            {
                ILevel       level       = m2mStructure.GetLevel(levelSequence);
                IPart        rootPart    = m2mStructure.GetLevel(0).GetPartRefByPartIndex(0, 0);
                IPositionSet positionSet = m2mStructure.GetDescendentPositionSetByAncestorPart(levelSequence, rootPart, 0);

                List <IPosition_Connected> position_ConnectedList = new List <IPosition_Connected>();
                positionSet.InitToTraverseSet();
                while (positionSet.NextPosition())
                {
                    if (positionSet.GetPosition() is IPart_Multi)
                    {
                        IPart_Multi partMulti = (IPart_Multi)positionSet.GetPosition();
                        IEnumerable <IPart_Connected> part_ConnectedEnumerable = partMulti.GetSubPartSet();

                        foreach (IPart_Connected part in part_ConnectedEnumerable)
                        {
                            position_ConnectedList.Add((IPosition_Connected)part);
                        }
                    }
                    else
                    {
                        position_ConnectedList.Add((IPosition_Connected)positionSet.GetPosition());
                    }
                }
                PositionSet_Connected positionSet_Connected = new PositionSet_Connected(position_ConnectedList);

                Layer_PositionSet_Connected layer_PartSet_Connected = new Layer_PositionSet_Connected(positionSet_Connected);
                //layer_PartSet_Connected.MainColor
                //layer_PartSet_Connected.Active = true;
                layer_PartSet_Connected.SetPositionSetTransformByM2MLevel(level);

                painterDialog.Layers.Add(layer_PartSet_Connected);
            }

            painterDialog.Show();
            //painterDialog.Show();
        }
Exemplo n.º 13
0
        public AlgorithmDemo_M2M_CH(M2M_CH m2m_CH, Layers layers, FlowControlerForm flowControlerForm, dUpdate update)
        {
            this.m2m_CH            = m2m_CH;
            this.layers            = layers;
            this.flowControlerForm = flowControlerForm;
            this.Update            = update;

            m2m_CH.GetM2MStructure += delegate(IM2MStructure m2mStructure)
            {
                this.m2mStructure = m2mStructure;
            };

            m2m_CH.GetChildPositionSetInSpecificLevelOfConvexHull += delegate
            {
                if (representativeHullLayer != null)
                {
                    representativeHullLayer.Visible = false;
                }
                if (convexHullLayer != null)
                {
                    lock (layers)
                    {
                        convexHullLayer.Visible = false;
                    }
                    flowControlerForm.BeginInvoke(Update);
                    flowControlerForm.SuspendAndRecordWorkerThread();
                }
            };

            m2m_CH.GetConvexHullPositionSetInSpecificLevel += delegate
            {
                if (linePartSetLayer != null)
                {
                    lock (layers)
                    {
                        linePartSetLayer.Visible            = false;
                        BottonLevelPositionSetLayer.Visible = false;
                    }
                    flowControlerForm.BeginInvoke(Update);
                    flowControlerForm.SuspendAndRecordWorkerThread();
                }
            };

            m2m_CH.GetRealConvexHull += delegate
            {
                if (representativeHullLayer != null)
                {
                    lock (layers)
                    {
                        representativeHullLayer.Visible = false;
                    }
                }
                if (convexHullLayer != null)
                {
                    lock (layers)
                    {
                        convexHullLayer.Visible = false;
                    }
                    flowControlerForm.BeginInvoke(Update);
                    flowControlerForm.SuspendAndRecordWorkerThread();
                }
            };

            IsGetM2MStructure = true;
            IsGetPositionSetToGetConvexHull                  = true;
            IsGetConvexHullPositionSetInSpecificLevel        = true;
            IsGetRepresentativeHullInSpecificLevel           = true;
            IsGetLinePositionSetInSpecificLevel              = true;
            IsGetChildPositionSetInSpecificLevelOfConvexHull = true;
            IsGetRealConvexHull = true;

            m2m_CH.GetConvexHullPositionSetInSpecificLevel += delegate
            {
                if (childPositionSetOfConvexHullLayer != null)
                {
                    lock (layers)
                    {
                        childPositionSetOfConvexHullLayer.Visible = false;
                    }
                    flowControlerForm.BeginInvoke(Update);
                    flowControlerForm.SuspendAndRecordWorkerThread();
                }
            };

            m2m_CH.GetConvexHullPositionSetInSpecificLevel += delegate
            {
                if (convexHullLayer != null)
                {
                    lock (layers)
                    {
                        convexHullLayer.ConvexHull.Visible = false;
                    }
                    flowControlerForm.BeginInvoke(Update);
                    flowControlerForm.SuspendAndRecordWorkerThread();
                }
            };

            m2m_CH.GetRealConvexHull += delegate
            {
                if (linePartSetLayer != null)
                {
                    lock (layers)
                    {
                        linePartSetLayer.Visible            = false;
                        BottonLevelPositionSetLayer.Visible = false;
                    }
                    flowControlerForm.BeginInvoke(Update);
                    flowControlerForm.SuspendAndRecordWorkerThread();
                }
            };

            flowControlerForm.SelectConfiguratoinObject(this);
            flowControlerForm.SuspendAndRecordWorkerThread();
        }
        public void TraversalEveryLevelAndBuild(IM2MStructure m2mStructure)
        {
            IPart rootPart = m2mStructure.GetLevel(0).GetPartRefByPartIndex(0, 0);

            IPositionSet bottonLevelPositionSet = m2mStructure.GetBottonLevelPositionSetByAncestorPart(rootPart, 0);

            bottonLevelPositionSet.InitToTraverseSet();

            while (bottonLevelPositionSet.NextPosition())
            {
                ((IPosition_Connected)(bottonLevelPositionSet.GetPosition())).SetAttachment(new Tag_M2M_Position());
            }

            //遍历每一层
            for (int levelSequence = m2mStructure.GetLevelNum() - 1; levelSequence >= 0; levelSequence--)
            {
                Queue <PositionAndPositon> partAndPositonQueue = new Queue <PositionAndPositon>();

                bool isPart = true;

                ILevel       currentLevel             = m2mStructure.GetLevel(levelSequence);
                IPositionSet currrentLevelPositionSet = null;

                //如果处于最底层
                if (levelSequence == m2mStructure.GetLevelNum() - 1)
                {
                    isPart = false;
                }

                if (levelSequence == 0)
                {
                    IPositionSetEdit temp = new Position_Implement.PositionSetEdit_ImplementByICollectionTemplate();
                    temp.AddPosition(rootPart);
                    currrentLevelPositionSet = temp;
                }
                else
                {
                    currrentLevelPositionSet = m2mStructure.GetDescendentPositionSetByAncestorPart(levelSequence, rootPart, 0);
                }

                currrentLevelPositionSet.InitToTraverseSet();

                //遍历每一个分块
                while (currrentLevelPositionSet.NextPosition())
                {
                    List <IPart_Connected> SubPartList = new List <IPart_Connected>();

                    IPart_Multi currentMultiPart = (IPart_Multi)(currrentLevelPositionSet.GetPosition());

                    //计算part的边界
                    float minSequenceX;
                    float maxSequenceX;
                    float minSequenceY;
                    float maxSequenceY;
                    if (isPart)
                    {
                        float unitNumInLength = (int)(m2mStructure.GetLevel(levelSequence + 1).GetUnitNumInHeight() / currentLevel.GetUnitNumInHeight());
                        minSequenceX = currentMultiPart.GetX() * unitNumInLength;
                        maxSequenceX = minSequenceX + unitNumInLength;
                        minSequenceY = currentMultiPart.GetY() * unitNumInLength;
                        maxSequenceY = minSequenceY + unitNumInLength;
                    }
                    else
                    {
                        minSequenceX = currentLevel.ConvertPartSequenceXToRealValue(currentMultiPart.GetX());
                        maxSequenceX = minSequenceX + currentLevel.GetGridWidth();
                        minSequenceY = currentLevel.ConvertPartSequenceYToRealValue(currentMultiPart.GetY());
                        maxSequenceY = minSequenceY + currentLevel.GetGridHeight();
                    }

                    IPositionSet childPositionSetOfCurrentPart = m2mStructure.GetChildPositionSetByParentPart(levelSequence, currentMultiPart);
                    childPositionSetOfCurrentPart.InitToTraverseSet();

                    //遍历每一个子分块或点
                    while (childPositionSetOfCurrentPart.NextPosition())
                    {
                        if (isPart)
                        {
                            IPart_Multi childPartMulti = (IPart_Multi)childPositionSetOfCurrentPart.GetPosition();
                            foreach (IPosition_Connected currentPosition_Connected in childPartMulti.GetSubPartSet())
                            {
                                BFSInOnePoint(partAndPositonQueue, isPart, SubPartList, currentMultiPart, minSequenceX, maxSequenceX, minSequenceY, maxSequenceY, currentPosition_Connected);
                            }
                        }
                        else
                        {
                            IPosition_Connected currentPosition_Connected = (IPosition_Connected)childPositionSetOfCurrentPart.GetPosition();
                            BFSInOnePoint(partAndPositonQueue, isPart, SubPartList, currentMultiPart, minSequenceX, maxSequenceX, minSequenceY, maxSequenceY, currentPosition_Connected);
                        }
                    }
                    //遍历每一个子分块结束

                    currentMultiPart.SetSubPartSet(SubPartList);
                }
                //遍历完某层的每个分块

                //处理还没建立链接的点和分块对
                foreach (PositionAndPositon pap in partAndPositonQueue)
                {
                    IPosition_Connected position_Connected = pap.position;
                    IPart_Connected     currentParentPart  = GetParentPart(position_Connected, isPart);
                    IPart_Connected     currentParentPart2 = GetParentPart(pap.positionInExistPart, isPart);

                    float distance = CalculateTheDistanceBetweenTwoPosition(currentParentPart2, currentParentPart);

                    IPositionSet_Connected_AdjacencyEdit positionSet_Connected_Adjacency = currentParentPart2.GetAdjacencyPositionSetEdit();

                    bool isContain = false;

                    positionSet_Connected_Adjacency.InitToTraverseSet();
                    while (positionSet_Connected_Adjacency.NextPosition())
                    {
                        if (positionSet_Connected_Adjacency.GetPosition() == currentParentPart)
                        {
                            isContain = true;
                            break;
                        }
                    }

                    if (isContain)
                    {
                        continue;
                    }
                    else
                    {
                        positionSet_Connected_Adjacency.AddAdjacency(currentParentPart, distance);
                    }

                    positionSet_Connected_Adjacency = currentParentPart.GetAdjacencyPositionSetEdit();

                    isContain = false;

                    positionSet_Connected_Adjacency.InitToTraverseSet();
                    while (positionSet_Connected_Adjacency.NextPosition())
                    {
                        if (positionSet_Connected_Adjacency.GetPosition() == currentParentPart2)
                        {
                            isContain = true;
                            break;
                        }
                    }

                    if (isContain)
                    {
                        continue;
                    }
                    else
                    {
                        positionSet_Connected_Adjacency.AddAdjacency(currentParentPart2, distance);
                    }
                }

                #region code for algorithm demo
                if (GetPartSetInSpecificLevel != null)
                {
                    GetPartSetInSpecificLevel(m2mStructure.GetLevel(levelSequence), levelSequence, m2mStructure.GetDescendentPositionSetByAncestorPart(levelSequence, rootPart, 0));
                }
                #endregion
            }
            //遍历每一层结束
        }
 public BuildPartSetConnectionForM2MStructure(IM2MStructure m2mStructure)
 {
     TraversalEveryLevelAndBuild(m2mStructure);
 }
 void Init(IM2MStructure m2mS)
 {
     m2mStructure = m2mS;
 }
 public NearestNeighbor_ByM2MStructure(IM2MStructure m2mS)
 {
     Init(m2mS);
 }
        public AlgorithmDemo_M2M_CD(M2M_CD M2M_CD, Layers layers, FlowControlerForm flowControlerForm, dUpdate update)
        {
            this.M2M_CD            = M2M_CD;
            this.layers            = layers;
            this.flowControlerForm = flowControlerForm;
            this.Update            = update;


            M2M_CD.GetCollision += delegate(IPositionSet positionSet)
            {
                System.Diagnostics.Debug.WriteLine("Collision!");

                if (objLayer != null)
                {
                    layers.Remove(objLayer);
                }
                {
                    objLayer = new Layer_PositionSet_Polygon(new PositionSet_Cloned(positionSet));
                    objLayer.PolygonLine.LineColor = Color.Red;
                    objLayer.PolygonLine.LineWidth = 1;
                    layers.Add(objLayer);
                }

                flowControlerForm.BeginInvoke(Update);
                flowControlerForm.SuspendAndRecordWorkerThread();
            };

            M2M_CD.GetNoCollision += delegate(IPositionSet positionSet)
            {
                System.Diagnostics.Debug.WriteLine("NoCollision!");
                if (objLayer != null)
                {
                    layers.Remove(objLayer);
                }
                {
                    objLayer = new Layer_PositionSet_Polygon(new PositionSet_Cloned(positionSet));
                    objLayer.PolygonLine.LineColor = Color.Green;
                    objLayer.PolygonLine.LineWidth = 1;
                    layers.Add(objLayer);
                }
                flowControlerForm.BeginInvoke(Update);
                flowControlerForm.SuspendAndRecordWorkerThread();
            };

            M2M_CD.GetIntersectPart += delegate(ILevel level, IPositionSet positionSet)
            {
                if (linePartSetLayer == null)
                {
                    linePartSetLayer           = new Layer_M2MPartSetInSpecificLevel(level, positionSet);
                    linePartSetLayer.MainColor = Settings.Default.LinePositionSetInSpecificLevelColor;
                    linePartSetLayer.Alpha     = 50;
                    //linePartSetLayer.LineColor = Color.Red;
                    linePartSetLayer.Active = true;
                    layers.Add(linePartSetLayer);
                }
                else
                {
                    linePartSetLayer.SpringLayerRepresentationChangedEvent(linePartSetLayer);
                }
            };

            M2M_CD.GetM2MStructure += delegate(IM2MStructure m2mStructure)
            {
                this.m2mStructure = m2mStructure;
            };

            IsGetM2MStructure = true;
            IsGetPositionSetToGetConvexHull = true;

            flowControlerForm.SelectConfiguratoinObject(this);
            flowControlerForm.SuspendAndRecordWorkerThread();
        }
Exemplo n.º 19
0
 public Layer_M2MStructureGrid(IM2MStructure m2mStructure)
 {
     this.m2mStructure = m2mStructure;
     maxRect           = GetMaxRect();
 }