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

            layersEditedControl.LayersPaintedControl = layersPaintedControl;
            layersPainterForm.Controls.Add(layersEditedControl);
            FlowControlerForm flowControlerForm = new FlowControlerForm();

            layersPainterForm.MdiParent    = this;
            layersPainterForm.WindowState  = FormWindowState.Maximized;
            layersPainterForm.FormClosing += delegate { flowControlerForm.Close(); };
            layersPainterForm.Show();
            flowControlerForm.Show(layersPainterForm);

            //打开一个Worker线程来进行算法流程的演示(否则会阻塞UI线程以至于演示不能进行)
            IAsyncResult result = new dDemoProcess(delegate
            {
                M2M_NN m2m_NN = new M2M_NN();

                //为对象的事件添加事件响应,以进行算法演示
                AlgorithmDemo_M2M_NN algorithmDemo_M2M_NN = new AlgorithmDemo_M2M_NN(m2m_NN, layers, flowControlerForm, layersPaintedControl.Invalidate);

                m2m_NN.PreProcess(positionSetContainer.GetPositionSet());
                m2m_NN.NearestNeighbor(layersPaintedControl.GetMouseDoubleChickedRealPosition());

                //结束演示(解除事件响应的绑定)
                algorithmDemo_M2M_NN.EndDemo();
            }).BeginInvoke(null, null);
        }
        protected void runDemo(IPositionSet set)
        {
            //以下代码必须在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);
            FlowControlerForm flowControlerForm = new FlowControlerForm();

            layersPainterForm.Show();
            flowControlerForm.Show(layersPainterForm);

            //新建或外部传入待演示对象
            M2M_NN m2m_NN = new M2M_NN();
            M2M_CH m2m_CH = new M2M_CH();

            //打开一个Worker线程来进行算法流程的演示(否则会阻塞UI线程以至于演示不能进行)
            IAsyncResult result = new dDemoProcess(delegate
            {
                ////产生随机点集:
                //RandomPositionSet_InFixedDistribution randomPositionSet_InFixedDistribution = new RandomPositionSet_InFixedDistribution();
                //randomPositionSet_InFixedDistribution.PointNum = 100000;
                //randomPositionSet_InFixedDistribution.DistributionStyle = distributionStyle.ClusterGaussianDistribution;
                //new ConfiguratedByForm(randomPositionSet_InFixedDistribution);
                //randomPositionSet_InFixedDistribution.Produce();

                //编辑点集
                Layer_PositionSet layer;
                if (set is IPositionSet_Connected)
                {
                    layer = new Layer_PositionSet_Connected((IPositionSet_Connected)set);
                    ((Layer_PositionSet_Connected)layer).Point.PointColor        = Color.Yellow;
                    ((Layer_PositionSet_Connected)layer).Point.PointRadius       = 2;
                    ((Layer_PositionSet_Connected)layer).Point.IsDrawPointBorder = true;
                }
                else
                {
                    layer = new Layer_PositionSet_Point(set);
                    ((Layer_PositionSet_Point)layer).Point.PointColor        = Color.Yellow;
                    ((Layer_PositionSet_Point)layer).Point.PointRadius       = 2;
                    ((Layer_PositionSet_Point)layer).Point.IsDrawPointBorder = true;
                }
                layer.EditAble = true;
                layers.Add(layer);
                layersPainterForm.Invalidate();
                flowControlerForm.SuspendAndRecordWorkerThread();
                //layers.Remove(layer);

                ///////////////////////////////////////
                //GetRandomPositionFromPositionSetRectangle getRandomPositionFromPositionSetRectangle
                //= new GetRandomPositionFromPositionSetRectangle(randomPositionSet_InFixedDistribution);

                ////对m2m_NN算法进行演示:
                ////为对象的事件添加事件响应,以进行算法演示
                //AlgorithmDemo_M2M_NN algorithmDemo_M2M_NN = new AlgorithmDemo_M2M_NN(m2m_NN, layers, flowControlerForm, layersPaintedControl.Invalidate);

                ////以下代码与非演示状态一样。
                //m2m_NN.PreProcess(randomPositionSet_InFixedDistribution);
                //m2m_NN.NearestNeighbor(layersPaintedControl.GetMouseDoubleChickedRealPosition());
                //while (true)
                //{
                //    for (int i = layers.Count - 1; i >= 0; i--)
                //    {
                //        if ((layers[i].Name != "M2MStructure") && (layers[i].Name != "PositionSetOfComparedPoint"))
                //        {
                //            layers.Remove(layers[i]);
                //        }
                //    }

                //    m2m_NN.NearestNeighbor(getRandomPositionFromPositionSetRectangle.Get());
                //}

                ////结束演示(解除事件响应的绑定)
                //algorithmDemo_M2M_NN.EndDemo();
                ///////////////////////////////////////

                //对m2m_CH算法进行演示:
                //为对象的事件添加事件响应,以进行算法演示
                //AlgorithmDemo_M2M_CH algorithmDemo_M2M_CH = new AlgorithmDemo_M2M_CH(m2m_CH, layers, flowControlerForm, layersPaintedControl.Invalidate);
                //while (true)
                //{
                //    layers.Clear();
                //    //以下代码与非演示状态一样。
                //    m2m_CH.ConvexHull(randomPositionSet_InFixedDistribution.Produce());
                //}

                ////结束演示(解除事件响应的绑定)
                //algorithmDemo_M2M_CH.EndDemo();
            }).BeginInvoke(null, null);
        }
Esempio n. 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            M2M_CD M2M_CD = new M2M_CD();

            new ConfiguratedByForm(M2M_CD);

            //以下代码必须在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);
            FlowControlerForm flowControlerForm = new FlowControlerForm();

            layersPainterForm.Show();
            flowControlerForm.Show(layersPainterForm);

            //新建或外部传入待演示对象



            //打开一个Worker线程来进行算法流程的演示(否则会阻塞UI线程以至于演示不能进行)
            IAsyncResult result = new dDemoProcess(delegate
            {
                //产生随机点集:

                /*
                 * RandomPositionSet_InFixedDistribution randomPositionSet_InFixedDistribution = new RandomPositionSet_InFixedDistribution();
                 * randomPositionSet_InFixedDistribution.PointNum = 1000;
                 * randomPositionSet_InFixedDistribution.DistributionStyle = distributionStyle.ClusterGaussianDistribution;
                 * new ConfiguratedByForm(randomPositionSet_InFixedDistribution);
                 * randomPositionSet_InFixedDistribution.Produce();
                 *
                 * //编辑点集
                 * Layer_PositionSet_Point layer = new Layer_PositionSet_Point(randomPositionSet_InFixedDistribution);
                 * layer.EditAble = true;
                 * layer.Point.PointColor = Color.Yellow;
                 * layer.Point.PointRadius = 2;
                 * layer.Point.IsDrawPointBorder = true;
                 * layers.Add(layer);
                 * layersPainterForm.Invalidate();
                 * flowControlerForm.SuspendAndRecordWorkerThread();
                 * layers.Remove(layer);
                 * */

                ///////////////////////////////////////
                //GetRandomPositionFromPositionSetRectangle getRandomPositionFromPositionSetRectangle
                //= new GetRandomPositionFromPositionSetRectangle(randomPositionSet_InFixedDistribution);

                ////对m2m_NN算法进行演示:
                ////为对象的事件添加事件响应,以进行算法演示
                //AlgorithmDemo_M2M_NN algorithmDemo_M2M_NN = new AlgorithmDemo_M2M_NN(m2m_NN, layers, flowControlerForm, layersPaintedControl.Invalidate);

                ////以下代码与非演示状态一样。
                //m2m_NN.PreProcess(randomPositionSet_InFixedDistribution);
                //m2m_NN.NearestNeighbor(layersPaintedControl.GetMouseDoubleChickedRealPosition());
                //while (true)
                //{
                //    for (int i = layers.Count - 1; i >= 0; i--)
                //    {
                //        if ((layers[i].Name != "M2MStructure") && (layers[i].Name != "PositionSetOfComparedPoint"))
                //        {
                //            layers.Remove(layers[i]);
                //        }
                //    }

                //    m2m_NN.NearestNeighbor(getRandomPositionFromPositionSetRectangle.Get());
                //}

                ////结束演示(解除事件响应的绑定)
                //algorithmDemo_M2M_NN.EndDemo();
                ///////////////////////////////////////

                //对M2M_CD算法进行演示:
                //为对象的事件添加事件响应,以进行算法演示
                PositionSetEditSet polygonSet = new PositionSetEditSet();
                IPositionSetEdit polygon      = new PositionSetEdit_ImplementByICollectionTemplate();
                polygon.AddPosition(new Position_Point(40, 40));
                polygon.AddPosition(new Position_Point(50, 10));
                polygon.AddPosition(new Position_Point(100, 70));
                IPositionSetEdit polygon2 = new PositionSetEdit_ImplementByICollectionTemplate();
                polygon2.AddPosition(new Position_Point(0, 0));
                polygon2.AddPosition(new Position_Point(20, 20));
                polygon2.AddPosition(new Position_Point(21, 12));
                IPositionSetEdit polygon3 = new PositionSetEdit_ImplementByICollectionTemplate();
                polygon3.AddPosition(new Position_Point(60, 60));
                polygon3.AddPosition(new Position_Point(62, 60));
                polygon3.AddPosition(new Position_Point(62, 56));
                polygon3.AddPosition(new Position_Point(64, 56));
                polygon3.AddPosition(new Position_Point(61, 52));
                polygon3.AddPosition(new Position_Point(58, 56));
                polygon3.AddPosition(new Position_Point(60, 56));
                polygonSet.AddPositionSet(polygon);
                polygonSet.AddPositionSet(polygon2);
                //polygonSet.AddPositionSet(polygon3);



                AlgorithmDemo_M2M_CD algorithmDemo_M2M_CD = new AlgorithmDemo_M2M_CD(M2M_CD, layers, flowControlerForm, layersPaintedControl.Invalidate);
                while (true)
                {
                    layers.Clear();
                    //以下代码与非演示状态一样。
                    //M2M_CD.ConvexHull(randomPositionSet_InFixedDistribution.Produce());
                    Layer_PositionSet_Polygon layer  = new Layer_PositionSet_Polygon(polygon);
                    Layer_PositionSet_Polygon layer2 = new Layer_PositionSet_Polygon(polygon2);
                    layers.Add(layer);
                    layers.Add(layer2);
                    M2M_CD.CollisionDetection(polygonSet, polygon3);
                }

                //结束演示(解除事件响应的绑定)
                algorithmDemo_M2M_CD.EndDemo();
            }).BeginInvoke(null, null);
        }