public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add ToolAddControlPoints.OnMouseDown implementation
            object       Miss    = Type.Missing;
            IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2;

            if (pMapCtr != null)
            {
                IGeoReference pGR      = pRasterLayer as IGeoReference;
                IPoint        mapPoint = pMapCtr.ToMapPoint(X, Y);
                m_NewLineFeedback.Display = pMapCtr.ActiveView.ScreenDisplay;
                if (FirstPoint == true)//起始点
                {
                    IPointCollection pPCFrom;
                    IPointCollection pPCTo = new MultipointClass();
                    pPCTo.AddPoint(mapPoint, ref Miss, ref Miss);
                    pPCFrom = pGR.PointsTransform(pPCTo, false);
                    //for (int i = 0; i < OriginPoints.PointCount; i++)
                    //{
                    //    pPCFrom.AddPoint(OriginPoints.get_Point(i));
                    //}
                    //pPCFrom.AddPoint(mapPoint);

                    m_NewLineFeedback.Start(mapPoint);
                    // OriginPoints.AddPoint(mapPoint);
                    IPoint pt = pPCFrom.get_Point(0);
                    OriginPoints.AddPoint(pt);
                    FirstPoint = false;
                }
                else//目标点
                {
                    TargetPoints.AddPoint(mapPoint);
                    FirstPoint = true;
                    m_NewLineFeedback.Stop();
                    // IPointCollection pPC = pGR.PointsTransform(TargetPoints, false);
                    //IPointCollection pPC = OriginPoints;
                    //IPoint pt1, pt2;
                    //pt1 = pPC.get_Point(0);
                    //pt2 = TargetPoints.get_Point(0);
                    //if (pPC.PointCount == 1)
                    //{
                    //    //IPoint pt1,pt2;
                    //    //pt1 = pPC.get_Point(0);
                    //    //pt2 = TargetPoints.get_Point(0);
                    //    pGR.Shift(pt2.X - pt1.X, pt2.Y - pt1.Y);

                    //}
                    //else
                    //if (pPC.PointCount ==2 )
                    //{
                    //    pGR.TwoPointsAdjust(pPC, TargetPoints);
                    //}
                    //else
                    //{
                    //    pGR.Warp(pPC, TargetPoints, m_FrmLinkTableRaster.WarpType);
                    //}
                    //m_FrmLinkTableRaster.AddControlPoints(OriginPoints.get_Point(OriginPoints.PointCount -1)
                    //    ,TargetPoints.get_Point(TargetPoints.PointCount -1));
                    m_FrmLinkTableRaster.pRasterLayer = pRasterLayer;
                    m_FrmLinkTableRaster.pMapCtr      = pMapCtr;
                    m_FrmLinkTableRaster.RefreshControlAllPoints();
                }

                TransformedOriginPoints = pGR.PointsTransform(OriginPoints, true);

                // pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add CmdRasterRegister.OnClick implementation
            IMapControl3 pMapCtrl = null;

            if (m_hookHelper.Hook is IToolbarControl)
            {
                if (((IToolbarControl)m_hookHelper.Hook).Buddy is IMapControl3)
                {
                    pMapCtrl = (IMapControl3)((IToolbarControl)m_hookHelper.Hook).Buddy;
                }
            }
            //In case the container is MapControl
            else if (m_hookHelper.Hook is IMapControl3)
            {
                pMapCtrl = (IMapControl3)m_hookHelper.Hook;
            }
            else
            {
                return;
            }

            System.GC.Collect();
            FrmSiftMatching frmSiftMatching = new FrmSiftMatching(pMapCtrl, pRasterLayer);

            if (frmSiftMatching.ShowDialog() == DialogResult.OK)
            {
                ClsSiftMatching pSiftMatching = new ClsSiftMatching();
                double[]        dbMatchPts;
                int             nCount = 0;
                if (pSiftMatching.siftMatching(frmSiftMatching.m_pSiftMatchPara, out dbMatchPts, out nCount))
                {
                    IRaster2     pLeftRaster    = frmSiftMatching.m_pRasterLeft;
                    IRasterProps pLeftProps     = pLeftRaster as IRasterProps;
                    IPoint       pLeftLowerLeft = pLeftProps.Extent.LowerLeft;

                    IRaster2     pRightRaster    = frmSiftMatching.m_pRasterRight;
                    IRasterProps pRightProps     = pRightRaster as IRasterProps;
                    IPoint       pRightLowerLeft = pRightProps.Extent.LowerLeft;

                    //SIFT匹配出来的都是影像坐标,应该先转换成MAPCTRL单位为准
                    for (int i = 0; i < nCount; i++)
                    {
                        int x = (int)dbMatchPts[4 * i];
                        int y = (int)(dbMatchPts[4 * i + 1]);
                        //y = (int)(-1*dbMatchPts[4 * i + 1]);
                        pLeftRaster.PixelToMap(x, y, out dbMatchPts[4 * i], out dbMatchPts[4 * i + 1]);

                        x = (int)dbMatchPts[4 * i + 2];
                        y = (int)(dbMatchPts[4 * i + 3]);
                        //y = (int)(-1*dbMatchPts[4 * i + 3]);
                        pRightRaster.PixelToMap(x, y, out dbMatchPts[4 * i + 2], out dbMatchPts[4 * i + 3]);

                        #region 废弃代码
                        //int x = (int)dbMatchPts[4 * i];
                        //int y = (int)(dbMatchPts[4 * i + 1]);
                        //dbMatchPts[4 * i] = x * pLeftProps.MeanCellSize().X + pLeftLowerLeft.X;
                        //dbMatchPts[4 * i + 1] = y * pLeftProps.MeanCellSize().Y + pLeftLowerLeft.Y;

                        //x = (int)dbMatchPts[4 * i + 2];
                        //y = (int)(dbMatchPts[4 * i + 3]);
                        //dbMatchPts[4 * i + 2] = x * pRightProps.MeanCellSize().X + pRightLowerLeft.X;
                        //dbMatchPts[4 * i + 3] = y * pRightProps.MeanCellSize().Y + pRightLowerLeft.Y;
                        //IPoint ptFrom = pMapCtrl.ToMapPoint(Convert.ToInt32(dbMatchPts[4 * i + 0]), Convert.ToInt32(dbMatchPts[4 * i + 1]));
                        //IPoint ptTo = pMapCtrl.ToMapPoint(Convert.ToInt32(dbMatchPts[4 * i + 2]), Convert.ToInt32(dbMatchPts[4 * i + 3]));

                        //dbMatchPts[4 * i + 0] = ptFrom.X;
                        //dbMatchPts[4 * i + 1] = ptFrom.Y;
                        //dbMatchPts[4 * i + 2] = ptTo.X;
                        //dbMatchPts[4 * i + 3] = ptTo.Y;
                        #endregion
                    }
                    pSiftMatching.outputMatchPointsToFile("d:\\b.txt", dbMatchPts, nCount);

                    //添加到控制点中
                    m_FrmLink.DelAllPoints();
                    for (int i = 0; i < nCount; i++)
                    {
                        IPoint ptOrg = new ESRI.ArcGIS.Geometry.PointClass();
                        ptOrg.PutCoords(dbMatchPts[4 * i], dbMatchPts[4 * i + 1]);
                        m_FrmLink.OriginPoints.AddPoint(ptOrg);

                        IPoint ptTarget = new ESRI.ArcGIS.Geometry.PointClass();
                        ptTarget.PutCoords(dbMatchPts[4 * i + 2], dbMatchPts[4 * i + 3]);
                        m_FrmLink.TargetPoints.AddPoint(ptTarget);
                    }
                    m_FrmLink.RefreshControlAllPoints();
                    m_FrmLink.Show();
                    pMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                    //MessageBox.Show("匹配成功!");
                }
                else
                {
                    MessageBox.Show("匹配失败!");
                }

                //把临时创建的文件删除
                try
                {
                    string szLeftFilename  = frmSiftMatching.m_pSiftMatchPara.szLeftFilename;
                    string szRightFilename = frmSiftMatching.m_pSiftMatchPara.szRightFilename;
                    if (System.IO.File.Exists(szLeftFilename))
                    {
                        System.IO.File.Delete(szLeftFilename);
                    }

                    if (System.IO.File.Exists(szRightFilename))
                    {
                        System.IO.File.Delete(szRightFilename);
                    }
                }
                catch (System.Exception ex)
                {
                    return;
                }
            }
        }