Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cpl"></param>
        /// <param name="pVtPl"></param>
        /// <param name="newBaseLine"></param>
        /// <param name="newcptlt"></param>
        /// <param name="dblPropotion"></param>
        /// <remarks>Notice that this function gets the vertices without the first and last ones</remarks>
        private void RecursivelyMovePt(CPolyline cpl, CVirtualPolyline pVtPl,
                                       ref CEdge newBaseLine, ref List <CPoint> newcptlt, double dblPropotion)
        {
            if (pVtPl.CLeftPolyline != null)
            {
                CEdge  newLeftBaseLine  = new CEdge();
                CEdge  newRightBaseLine = new CEdge();
                CPoint newcpt           = new CPoint();

                if (cpl.CptLt[pVtPl.intMaxDisID].isMoveable == false)
                {
                    newcpt           = cpl.CptLt[pVtPl.intMaxDisID];
                    newLeftBaseLine  = new CEdge(newBaseLine.FrCpt, newcpt);
                    newRightBaseLine = new CEdge(newcpt, newBaseLine.ToCpt);
                }
                else
                {
                    newBaseLine.SetAxisAngle();
                    newcpt = newBaseLine.QueryMovedPt(pVtPl.dblRatioforMovePt, pVtPl.dblLengthforMovePt,
                                                      pVtPl.dblAngleDiffforMovePt, dblPropotion, cpl.CptLt[pVtPl.intMaxDisID].ID);
                    newLeftBaseLine  = new CEdge(newBaseLine.FrCpt, newcpt);
                    newRightBaseLine = new CEdge(newcpt, newBaseLine.ToCpt);
                }

                RecursivelyMovePt(cpl, pVtPl.CLeftPolyline, ref newLeftBaseLine, ref newcptlt, dblPropotion);
                newcptlt.Add(newcpt);
                RecursivelyMovePt(cpl, pVtPl.CRightPolyline, ref newRightBaseLine, ref newcptlt, dblPropotion);
            }
            //newBaseLine.SetEmpty2();
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cpl"></param>
        /// <param name="pVtPl"></param>
        /// <param name="newBaseLine"></param>
        /// <param name="newcptlt"></param>
        /// <param name="dblPropotion"></param>
        /// <remarks>Notice that this function gets the vertices without the first and last vertices</remarks>
        public void GetNewCptLt(CPolyline cpl, CVirtualPolyline pVtPl, ref List <CPoint> newcptlt, double dblTDis)
        {
            if (pVtPl.dblMaxDis < dblTDis)
            {
                return;
            }

            List <CPoint>            dcptlt  = cpl.CptLt;
            Stack <CVirtualPolyline> pVtPlSk = new Stack <CVirtualPolyline>();

            var currentVtpl = pVtPl;

            do
            {
                if (currentVtpl.dblMaxDis >= dblTDis)  //this implies that there are at least three vertices on currentVtpl
                {
                    pVtPlSk.Push(currentVtpl);
                    currentVtpl = currentVtpl.CLeftPolyline;
                }
                else
                {
                    currentVtpl = pVtPlSk.Pop();
                    newcptlt.Add(dcptlt[currentVtpl.intMaxDisID]);

                    currentVtpl = currentVtpl.CRightPolyline;
                    if (currentVtpl.dblMaxDis >= dblTDis)
                    {
                        pVtPlSk.Push(currentVtpl);
                        currentVtpl = currentVtpl.CLeftPolyline;
                    }
                }
            } while (pVtPlSk.Count > 0);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Recursively Collect MaxDis (height) of the points to their base lines
        /// </summary>
        /// <remarks>if the height of a point is smaller than the height of a lower-level height,
        /// the larger lower-level will be used</remarks>
        private List <double> CollectMaxDis(CVirtualPolyline pVtPl)
        {
            int intCount    = pVtPl.intToID - pVtPl.intFrID - 1;
            var dblMaxDisLt = new List <double>(intCount);  //we don't need to consider the MaxDis of the two ends of the polyline

            if (intCount == 0)
            {
                return(dblMaxDisLt);
            }
            else if (intCount < 0)
            {
                throw new ArgumentOutOfRangeException("intCount cannot be negative!");
            }


            Stack <CVirtualPolyline> pVtPlSk = new Stack <CVirtualPolyline>();
            var currentVtpl = pVtPl;

            do
            {
                if (currentVtpl.dblMaxDis >= 0)  //this implies that there are at least three vertices on currentVtpl
                {
                    pVtPlSk.Push(currentVtpl);
                    currentVtpl = currentVtpl.CLeftPolyline;
                }
                else
                {
                    currentVtpl = pVtPlSk.Pop();

                    //get the max distance by considering lower-level
                    //double dblMaxDis = Math.Max(currentVtpl.dblMaxDis,
                    //Math.Max(currentVtpl.CLeftPolyline.dblMaxDisLargerThanChildren,
                    //currentVtpl.CRightPolyline.dblMaxDisLargerThanChildren));
                    //currentVtpl.dblMaxDisLargerThanChildren = dblMaxDis;

                    double dblMaxDis = currentVtpl.dblMaxDis;
                    dblMaxDisLt.Add(dblMaxDis);

                    currentVtpl = currentVtpl.CRightPolyline;
                    if (currentVtpl.dblMaxDis >= 0)
                    {
                        pVtPlSk.Push(currentVtpl);
                        currentVtpl = currentVtpl.CLeftPolyline;
                    }
                }
            } while (pVtPlSk.Count > 0);

            if (intCount != dblMaxDisLt.Count)
            {
                throw new ArgumentException("they should be the same!");
            }

            return(dblMaxDisLt);
        }
Exemplo n.º 4
0
        public void ConfirmMoveInfo(CPolyline cpl, CVirtualPolyline pVtPl, double dblTDis)
        {
            List <CPoint> cptlt = cpl.CptLt;

            cptlt[0].isMoveable = false;
            cptlt[cptlt.Count - 1].isMoveable = false;
            for (int j = 1; j < cptlt.Count - 1; j++)
            {
                cptlt[j].isMoveable = true;
            }
            RecursivelyConfirmMoveInfo(cpl, cpl.pVirtualPolyline, dblTDis);
        }
Exemplo n.º 5
0
        public void RecursivelyMovePt(CPolyline cpl, CVirtualPolyline pVtPl, ref CEdge newBaseLine, ref List <CPoint> newcptlt, double dblPropotion)
        {
            if (pVtPl.CLeftPolyline != null)
            {
                CPoint newcpt = new CPoint();
                Calcpt(ref newcpt, ref newBaseLine, pVtPl, dblPropotion, cpl);

                var newLeftBaseLine  = new CEdge(newBaseLine.FrCpt, newcpt);
                var newRightBaseLine = new CEdge(newcpt, newBaseLine.ToCpt);

                RecursivelyMovePt(cpl, pVtPl.CLeftPolyline, ref newLeftBaseLine, ref newcptlt, dblPropotion);
                newcptlt.Add(newcpt);
                RecursivelyMovePt(cpl, pVtPl.CRightPolyline, ref newRightBaseLine, ref newcptlt, dblPropotion);
            }
        }
Exemplo n.º 6
0
        private void RecursivelyConfirmMoveInfo(CPolyline cpl, CVirtualPolyline pVtPl, double dblTDis)
        {
            if (pVtPl.CLeftPolyline == null)
            {
                return;
            }

            if (pVtPl.dblMaxDis >= dblTDis)
            {
                cpl.CptLt[pVtPl.intMaxDisID].isMoveable = false;
                RecursivelyConfirmMoveInfo(cpl, pVtPl.CLeftPolyline, dblTDis);
                RecursivelyConfirmMoveInfo(cpl, pVtPl.CRightPolyline, dblTDis);
            }
            else
            {
                SubRecursivelyConfirmMoveInfo(cpl, pVtPl, dblTDis);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// find the farthest point for each contructured baseline
        /// </summary>
        /// <param name="dcpl"></param>
        /// <param name="pVtPl"></param>
        public void DivideCplByDP(CPolyline dcpl, CVirtualPolyline pVtPl)
        {
            List <CPoint>            dcptlt  = dcpl.CptLt;
            Stack <CVirtualPolyline> pVtPlSk = new Stack <CVirtualPolyline>();

            pVtPlSk.Push(pVtPl);

            do
            {
                var subVtPl = pVtPlSk.Pop();
                if ((subVtPl.intToID - subVtPl.intFrID >= 2))
                {
                    double dblMaxDis   = -1;
                    int    intMaxDisID = -1;
                    double dblFromDis  = 0;
                    subVtPl.SetBaseLine(dcptlt[subVtPl.intFrID], dcptlt[subVtPl.intToID]);
                    subVtPl.pBaseLine.SetSlope();
                    subVtPl.pBaseLine.SetDenominatorForDis();
                    for (int i = subVtPl.intFrID + 1; i < subVtPl.intToID; i++)
                    {
                        //throw new ArgumentException("make sure you have set length for pBaseLine!");
                        dblFromDis = subVtPl.pBaseLine.QueryPtHeight(dcptlt[i]);
                        if (dblFromDis > dblMaxDis)
                        {
                            dblMaxDis   = dblFromDis;
                            intMaxDisID = i;
                        }
                    }

                    subVtPl.intMaxDisID = intMaxDisID;
                    subVtPl.dblMaxDis   = dblMaxDis;
                    subVtPl.DivideByID(intMaxDisID);
                    pVtPlSk.Push(subVtPl.CRightPolyline);
                    pVtPlSk.Push(subVtPl.CLeftPolyline);

                    subVtPl.pBaseLine = null; //to use as little memory as possible
                }
            } while (pVtPlSk.Count > 0);
        }
Exemplo n.º 8
0
        public void Calcpt(ref CPoint newcpt, ref CEdge newBaseLine, CVirtualPolyline pVtPl, double dblPropotion, CPolyline cpl)
        {
            newcpt.X = newBaseLine.FrCpt.X + (newBaseLine.ToCpt.X - newBaseLine.FrCpt.X) * pVtPl.Ratio;
            newcpt.Y = newBaseLine.FrCpt.Y + (newBaseLine.ToCpt.Y - newBaseLine.FrCpt.Y) * pVtPl.Ratio;
            double dblStartAngel = CGeoFunc.CalAxisAngle(newcpt, newBaseLine.ToCpt);
            double dblEndAngel   = dblStartAngel + pVtPl.Angel;

            if (dblEndAngel < 0)
            {
                dblEndAngel = dblEndAngel + 2 * Math.PI;
            }
            if (dblEndAngel > 2 * Math.PI)
            {
                dblEndAngel = dblEndAngel - 2 * Math.PI;
            }
            double dblTan = Math.Abs(Math.Tan(dblEndAngel));

            if (dblEndAngel > 0 && dblEndAngel < Math.PI / 2)
            {
                newcpt.X = newcpt.X + dblPropotion * pVtPl.dblMaxDis1 / Math.Pow(1 + dblTan * dblTan, 0.5);
                newcpt.Y = newcpt.Y + dblPropotion * pVtPl.dblMaxDis1 * dblTan / Math.Pow(1 + dblTan * dblTan, 0.5);
            }
            if (dblEndAngel > Math.PI / 2 && dblEndAngel < Math.PI)
            {
                newcpt.X = newcpt.X - dblPropotion * pVtPl.dblMaxDis1 / Math.Pow(1 + dblTan * dblTan, 0.5);
                newcpt.Y = newcpt.Y + dblPropotion * pVtPl.dblMaxDis1 * dblTan / Math.Pow(1 + dblTan * dblTan, 0.5);
            }
            if (dblEndAngel > Math.PI && dblEndAngel < 3 * Math.PI / 2)
            {
                newcpt.X = newcpt.X - dblPropotion * pVtPl.dblMaxDis1 / Math.Pow(1 + dblTan * dblTan, 0.5);
                newcpt.Y = newcpt.Y - dblPropotion * pVtPl.dblMaxDis1 * dblTan / Math.Pow(1 + dblTan * dblTan, 0.5);
            }
            if (dblEndAngel > 3 * Math.PI / 2 && dblEndAngel < 2 * Math.PI)
            {
                newcpt.X = newcpt.X + dblPropotion * pVtPl.dblMaxDis1 / Math.Pow(1 + dblTan * dblTan, 0.5);
                newcpt.Y = newcpt.Y - dblPropotion * pVtPl.dblMaxDis1 * dblTan / Math.Pow(1 + dblTan * dblTan, 0.5);
            }
        }
Exemplo n.º 9
0
        private void SubRecursivelyConfirmMoveInfo(CPolyline cpl, CVirtualPolyline pVtPl, double dblTDis)
        {
            if (pVtPl.CLeftPolyline == null)
            {
                return;
            }

            cpl.CptLt[pVtPl.intMaxDisID].isMoveable = true;
            CPoint frcpt = cpl.CptLt[pVtPl.intFrID];
            CPoint tocpt = cpl.CptLt[pVtPl.intToID];
            CPoint cpt   = cpl.CptLt[pVtPl.intMaxDisID];

            double dblPreDis   = frcpt.DistanceTo(cpt);
            double dblSucDis   = tocpt.DistanceTo(cpt);
            double dblTotalDis = dblPreDis + dblSucDis;
            double dblRatio    = 0;

            if (dblTotalDis != 0)
            {
                dblRatio = dblPreDis / dblTotalDis;
            }

            //double dblTargetX = (1 - dblRatio) * frcpt.X + dblRatio * tocpt.X;
            //double dblTargetY = (1 - dblRatio) * frcpt.Y + dblRatio * tocpt.Y;
            //CPoint targetcpt = new CPoint(-1, dblTargetX,dblTargetY);
            CPoint targetcpt = CGeoFunc.GetInbetweenCpt(frcpt, tocpt, dblRatio);

            pVtPl.dblRatioforMovePt     = dblRatio;
            pVtPl.dblLengthforMovePt    = CGeoFunc.CalDis(targetcpt, cpt);
            pVtPl.dblAngleDiffforMovePt = CGeoFunc.CalAngle_Counterclockwise(cpt, targetcpt, tocpt);
            //pVtPl.dblDifffromMovePtX = cpt.X - dblTargetX;
            //pVtPl.dblDifffromMovePtY = cpt.Y - dblTargetY;

            SubRecursivelyConfirmMoveInfo(cpl, pVtPl.CLeftPolyline, dblTDis);
            SubRecursivelyConfirmMoveInfo(cpl, pVtPl.CRightPolyline, dblTDis);
        }
Exemplo n.º 10
0
        private void RecursivelyGetNewCptLtPG(CPolyline cpl, CVirtualPolyline pVtPl,
                                              ref List <CPoint> newcptlt, double dblTDis, int intDepth)
        {
            if (pVtPl.CLeftPolyline == null)
            {
                return;
            }

            if (intDepth <= 0)
            {
                GetNewCptLt(cpl, pVtPl, ref newcptlt, dblTDis);

                //if (pVtPl.dblMaxDis >= dblTDis)
                //{
                //    GetNewCptLt(cpl, pVtPl.CLeftPolyline, ref newcptlt, dblTDis);
                //    newcptlt.Add(cpl.CptLt[pVtPl.intMaxDisID]);
                //    GetNewCptLt(cpl, pVtPl.CRightPolyline, ref newcptlt, dblTDis);
                //}
            }
            else   //at least keep 3 vertices for a polyline
            {
                intDepth--;
                if (pVtPl.CLeftPolyline.dblMaxDis >= pVtPl.CRightPolyline.dblMaxDis)
                {
                    RecursivelyGetNewCptLtPG(cpl, pVtPl.CLeftPolyline, ref newcptlt, dblTDis, intDepth);
                    newcptlt.Add(cpl.CptLt[pVtPl.intMaxDisID]);
                    GetNewCptLt(cpl, pVtPl.CRightPolyline, ref newcptlt, dblTDis);
                }
                else
                {
                    GetNewCptLt(cpl, pVtPl.CLeftPolyline, ref newcptlt, dblTDis);
                    newcptlt.Add(cpl.CptLt[pVtPl.intMaxDisID]);
                    RecursivelyGetNewCptLtPG(cpl, pVtPl.CRightPolyline, ref newcptlt, dblTDis, intDepth);
                }
            }
        }