private void FindFrcpt2AndTocpt2Grid(List <CAtBd> pSgAtBdLt, List <CAtBd> pBSAtBdLt, CParameterThreshold ParameterThreshold)
        {
            //SgCptLt for pSgAtBdLt
            List <CPoint> SgCptLt = new List <CPoint>(pSgAtBdLt.Count * 2);

            foreach (CAtBd pAtBd in pSgAtBdLt)
            {
                CPoint cpt0 = pAtBd.CptLt[0];
                cpt0.BelongedObject = pAtBd;
                CPoint cptlast = pAtBd.CptLt[pAtBd.CptLt.Count - 1];
                cptlast.BelongedObject = pAtBd;
                SgCptLt.Add(cpt0);
                SgCptLt.Add(cptlast);
            }

            //BSCptLt for pBSAtBdLt
            int intCount = 0;

            foreach (CAtBd pAtBd in pBSAtBdLt)
            {
                intCount += pAtBd.CptLt.Count;
            }
            List <CPoint> BSCptLt = new List <CPoint>(intCount);

            foreach (CAtBd pAtBd in pBSAtBdLt)
            {
                foreach (CPoint cpt in pAtBd.CptLt)
                {
                    //cpt.BelongedObject = pAtBd;
                    BSCptLt.Add(cpt);
                }
            }

            //LookingForNeighboursByGrids
            var CorrCptsLt = CGeoFunc.LookingForNeighboursByGrids(SgCptLt, BSCptLt, CConstants.dblVerySmallCoord);

            //FindFrcpt2AndTocpt2
            foreach (CCorrCpts CorrCpt in CorrCptsLt)
            {
                CorrCpt.FrCpt.isTraversed = false;
            }
            foreach (CCorrCpts CorrCpt in CorrCptsLt)
            {
                CPoint frcpt = CorrCpt.FrCpt;
                if (frcpt.isTraversed == false)  //we only need one
                {
                    CAtBd pAtBd = frcpt.BelongedObject as CAtBd;
                    if (frcpt.ID == 0)
                    {
                        pAtBd.Frcpt2 = CorrCpt.ToCpt;
                    }
                    else
                    {
                        pAtBd.Tocpt2 = CorrCpt.ToCpt;
                    }
                    frcpt.isTraversed = true;
                }
            }
        }
        //public void SubPolylineMatchLA(CPolyline CFrPolyline, CVirtualPolyline CFrVtPl, CPolyline CToPolyline, CVirtualPolyline CToVtPl, CParameterThreshold ParameterThreshold, ref C5.LinkedList<CCorrSegment> CorrespondSegmentLk)
        //{
        //    List<CPoint> frcptlt = CFrPolyline.CptLt;
        //    List<CPoint> tocptlt = CToPolyline.CptLt;

        //    //如果其中一个线段没有孩子,则直接匹配并结束
        //    if (CFrVtPl.CLeftPolyline == null || CToVtPl.CLeftPolyline == null)
        //    {
        //        List<CPoint> frsubcptlt = new List<CPoint>();
        //        for (int i = CFrVtPl.intFrID; i <= CFrVtPl.intToID; i++)
        //        {
        //            frsubcptlt.Add(frcptlt[i]);
        //        }
        //        CPolyline frsubcpl = new CPolyline(CFrVtPl.intFrID, frsubcptlt);

        //        List<CPoint> tosubcptlt = new List<CPoint>();
        //        for (int i = CToVtPl.intFrID; i <= CToVtPl.intToID; i++)
        //        {
        //            tosubcptlt.Add(tocptlt[i]);
        //        }
        //        CPolyline tosubcpl = new CPolyline(CFrVtPl.intFrID, tosubcptlt);

        //        CCorrSegment CorrespondSegment = new CCorrSegment(frsubcpl, tosubcpl);
        //        CorrespondSegmentLk.Add(CorrespondSegment);
        //        return;
        //    }

        //    double dblRatioLL = frcptlt[CFrVtPl.CLeftPolyline.intFrID].DistanceTo(frcptlt[CFrVtPl.CLeftPolyline.intToID]) / tocptlt[CToVtPl.CLeftPolyline.intFrID].DistanceTo(tocptlt[CToVtPl.CLeftPolyline.intToID]);
        //    double dblRatioRR = frcptlt[CFrVtPl.CRightPolyline.intFrID].DistanceTo(frcptlt[CFrVtPl.CRightPolyline.intToID]) / tocptlt[CToVtPl.CRightPolyline.intFrID].DistanceTo(tocptlt[CToVtPl.CRightPolyline.intToID]);

        //    double dblFrDiffLLX = frcptlt[CFrVtPl.CLeftPolyline.intToID].X - frcptlt[CFrVtPl.CLeftPolyline.intFrID].X;
        //    double dblFrDiffLLY = frcptlt[CFrVtPl.CLeftPolyline.intToID].Y - frcptlt[CFrVtPl.CLeftPolyline.intFrID].Y;
        //    double dblToDiffLLX = tocptlt[CToVtPl.CLeftPolyline.intToID].X - tocptlt[CToVtPl.CLeftPolyline.intFrID].X;
        //    double dblToDiffLLY = tocptlt[CToVtPl.CLeftPolyline.intToID].Y - tocptlt[CToVtPl.CLeftPolyline.intFrID].Y;
        //    double dblAngleDiffLL = CGeoFunc.CalAngle_Counterclockwise(dblFrDiffLLX, dblFrDiffLLY, dblToDiffLLX, dblToDiffLLY);

        //    double dblFrDiffRRX = frcptlt[CFrVtPl.CRightPolyline.intToID].X - frcptlt[CFrVtPl.CRightPolyline.intFrID].X;
        //    double dblFrDiffRRY = frcptlt[CFrVtPl.CRightPolyline.intToID].Y - frcptlt[CFrVtPl.CRightPolyline.intFrID].Y;
        //    double dblToDiffRRX = tocptlt[CToVtPl.CRightPolyline.intToID].X - tocptlt[CToVtPl.CRightPolyline.intFrID].X;
        //    double dblToDiffRRY = tocptlt[CToVtPl.CRightPolyline.intToID].Y - tocptlt[CToVtPl.CRightPolyline.intFrID].Y;
        //    double dblAngleDiffRR = CGeoFunc.CalAngle_Counterclockwise(dblFrDiffRRX, dblFrDiffRRY, dblToDiffRRX, dblToDiffRRY);

        //    if ((dblRatioLL >= ParameterThreshold.dblDLengthBound) && (dblRatioLL <= ParameterThreshold.dblULengthBound) &&
        //        (dblRatioRR >= ParameterThreshold.dblDLengthBound) && (dblRatioRR <= ParameterThreshold.dblULengthBound) &&
        //        (Math.Abs(dblAngleDiffLL) <= ParameterThreshold.dblAngleBound) && (dblAngleDiffRR <= ParameterThreshold.dblAngleBound))
        //    {
        //        //相应线段长度相近
        //        SubPolylineMatchLA(CFrPolyline, CFrVtPl.CLeftPolyline, CToPolyline, CToVtPl.CLeftPolyline, ParameterThreshold, ref CorrespondSegmentLk);
        //        SubPolylineMatchLA(CFrPolyline, CFrVtPl.CRightPolyline, CToPolyline, CToVtPl.CRightPolyline, ParameterThreshold, ref CorrespondSegmentLk);
        //    }
        //    else
        //    {
        //        List<CPoint> frsubcptlt = new List<CPoint>();
        //        for (int i = CFrVtPl.intFrID; i <= CFrVtPl.intToID; i++)
        //        {
        //            frsubcptlt.Add(frcptlt[i]);
        //        }
        //        CPolyline frsubcpl = new CPolyline(CFrVtPl.intFrID, frsubcptlt);

        //        List<CPoint> tosubcptlt = new List<CPoint>();
        //        for (int i = CToVtPl.intFrID; i <= CToVtPl.intToID; i++)
        //        {
        //            tosubcptlt.Add(tocptlt[i]);
        //        }
        //        CPolyline tosubcpl = new CPolyline(CFrVtPl.intFrID, tosubcptlt);


        //        CCorrSegment CorrespondSegment = new CCorrSegment(frsubcpl, tosubcpl);
        //        CorrespondSegmentLk.Add(CorrespondSegment);
        //        return;
        //    }
        //}

        #region Display
        public void DisplayAtBd(double dblProp)
        {
            CParameterInitialize pParameterInitialize = _ParameterInitialize;
            CParameterResult     pParameterResult     = _ParameterResult;

            if (dblProp < 0 || dblProp > 1)
            {
                MessageBox.Show("请输入正确参数!");
                return;
            }

            double dblLargerScale  = pParameterInitialize.dblLargerScale;
            double dblSmallerScale = pParameterInitialize.dblSmallerScale;
            double dblTargetScale  = Math.Pow(dblLargerScale, 1 - dblProp) * Math.Pow(dblSmallerScale, dblProp);
            double dblIgnorableDis = 0.0001 * dblTargetScale / 111319.490793;
            //double dblIgnorableDis = 0.0001 * dblTargetScale / 100000000000;
            //
            long             lngTime3           = System.Environment.TickCount;
            List <CPolyline> normaldisplaycpllt = new List <CPolyline>(pParameterResult.CBSAtBdLt.Count);

            for (int i = 0; i < pParameterResult.CBSAtBdLt.Count; i++)
            {
                CPolyline cpl = CGeoFunc.GetTargetcpl(i, pParameterResult.CBSAtBdLt[i].CResultPtLt, dblProp);
                normaldisplaycpllt.Add(cpl);
            }
            pParameterResult.DisplayCPlLt = normaldisplaycpllt;
            long lngInterpolateTime = System.Environment.TickCount - lngTime3;

            //the polylines should be faded out
            List <CPolyline> fadeddisplaycpllt = new List <CPolyline>(pParameterResult.CSgAtBdLt.Count);

            for (int i = 0; i < pParameterResult.CSgAtBdLt.Count; i++)
            {
                CAtBd pAtBd = pParameterResult.CSgAtBdLt[i];
                //List<CPoint> newcptlt = _pDPSimplify.DPCplMorph(pAtBd as CPolyline, dblProp).CptLt;
                List <CPoint> newcptlt = new List <CPoint>();

                //the first point
                if (pAtBd.Frcpt2 == null)
                {
                    newcptlt[0] = pAtBd.CptLt[0];
                }
                else
                {
                    newcptlt[0] = CGeoFunc.GetInbetweenCpt(pAtBd.Frcpt2, pAtBd.Frcpt2.CorrespondingPtLt[0], dblProp, 0);
                    int dblBSCplID = pAtBd.Frcpt2.BelongedCpl.ID;
                    DWIntersect(normaldisplaycpllt[dblBSCplID], ref newcptlt, dblIgnorableDis);
                }

                //the last point
                if (pAtBd.Tocpt2 == null)
                {
                    newcptlt[newcptlt.Count - 1] = pAtBd.CptLt[pAtBd.CptLt.Count - 1];
                }
                else
                {
                    CPoint cptlast = CGeoFunc.GetInbetweenCpt(pAtBd.Tocpt2, pAtBd.Tocpt2.CorrespondingPtLt[0], dblProp, pAtBd.CptLt.Count - 1);
                    newcptlt[newcptlt.Count - 1] = cptlast;
                    CHelpFunc.ReverseCptLt(ref newcptlt);
                    int dblBSCplID = pAtBd.Tocpt2.BelongedCpl.ID;
                    DWIntersect(normaldisplaycpllt[dblBSCplID], ref newcptlt, dblIgnorableDis);
                    CHelpFunc.ReverseCptLt(ref newcptlt);
                }

                CPolyline newcpl = new CPolyline(i, newcptlt);
                fadeddisplaycpllt.Add(newcpl);
            }
            pParameterResult.FadedDisplayCPlLt = fadeddisplaycpllt;

            //// 清除绘画痕迹
            //IMapControl4 m_mapControl = _ParameterInitialize.m_mapControl;
            //IGraphicsContainer pGra = m_mapControl.Map as IGraphicsContainer;
            //pGra.DeleteAllElements();
            for (int i = 0; i < normaldisplaycpllt.Count; i++)
            {
                normaldisplaycpllt[i].SetPolyline();
            }
            for (int i = 0; i < fadeddisplaycpllt.Count; i++)
            {
                fadeddisplaycpllt[i].SetPolyline();
            }

            ////check
            //List<CPolyline> TopCheckCpllt = new List<CPolyline>(normaldisplaycpllt.Count + fadeddisplaycpllt.Count);
            //TopCheckCpllt.AddRange(normaldisplaycpllt);
            //TopCheckCpllt.AddRange(fadeddisplaycpllt);
            //SCG.LinkedList<CCorrSegment> pCorrCplLk;
            //SCG.LinkedList<CPolyline> pSelfIntersectCplLk;
            //bool isCross = CGeoFunc.CheckCross(TopCheckCpllt, out pCorrCplLk);
            //bool isSelfIntersect = CGeoFunc.CheckSelfIntersect(TopCheckCpllt, out pSelfIntersectCplLk);

            //CHelpFunc.SaveCPlLt(normaldisplaycpllt, "City" + pParameterInitialize.strSaveFolder + "_" + dblProp.ToString(), pParameterInitialize.pWorkspace, pParameterInitialize.m_mapControl);
            //int intColor = Convert.ToInt16(dblProp * 255);
            //CHelpFunc.SaveCPlLt(fadeddisplaycpllt, CEnumScale.Single + pParameterInitialize.strSaveFolder + "_" + dblProp.ToString(), pParameterInitialize.pWorkspace, pParameterInitialize.m_mapControl, intColor, intColor, intColor, 1);

            //CEnvelope pEnvelopeIpe = new CEnvelope(0, 0, 600, 600);
            //CHelpFunc.SaveToIpe(normaldisplaycpllt,  "Ipe" + "_" + dblProp.ToString(), pParameterInitialize.pBSFLayer.AreaOfInterest, pEnvelopeIpe, pParameterInitialize, 0, 0, 0, "normal", true);
            //CHelpFunc.SaveToIpe(fadeddisplaycpllt, "Ipe" + "_" + dblProp.ToString(), pParameterInitialize.pBSFLayer.AreaOfInterest, pEnvelopeIpe, pParameterInitialize, intColor, intColor, intColor, "normal", true);



            //for (int i = 0; i < normaldisplaycpllt.Count; i++)
            //{
            //    CHelpFunc.ViewPolylineByRGB(m_mapControl, normaldisplaycpllt[i], 0, 0, 0, 1);
            //}

            //
            //for (int i = 0; i < fadeddisplaycpllt.Count; i++)
            //{
            //    CHelpFunc.ViewPolylineByRGB(m_mapControl, fadeddisplaycpllt[i], intColor, intColor, intColor, 1);
            //}
            //m_mapControl.ActiveView.Refresh();   //由于在下一步“ViewPolyline”中有刷新的命令,此语句可省略
        }
 public CCorrAtBds(CAtBd fBSAtBd, CAtBd fSSAtBd)
 {
     _pBSAtBd = fBSAtBd;
     _pSSAtBd = fSSAtBd;
 }