Example #1
0
        /// <summary>
        /// If given tree point is included in one of points on this branch
        /// </summary>
        public bool Contains(Vector3 pPoint, float pToleranceMultiply)
        {
            float treePointExtent = tree.peak.treePointExtent * pToleranceMultiply;
            int   approxIndex     = GetAproxIndexOfPoint(pPoint, treePointExtent);

            //which direction on branch should we search
            int dir = 1;             //actually to be sure we need to check both directions...final treepoints doesnt have to be neccessarily Y-ordered
            //if (TreePoints[approxIndex].Y < pPoint.Y) { dir = -1; }
            CTreePoint pointOnBranch = TreePoints[approxIndex];
            bool       isPointOnBranchWithinRange = Math.Abs(pointOnBranch.Z - pPoint.Z) < treePointExtent + 1;

            for (int i = approxIndex; isPointOnBranchWithinRange && i > 0 && i < TreePoints.Count; i += dir)
            {
                pointOnBranch = TreePoints[i];
                if (pointOnBranch.Includes(pPoint, pToleranceMultiply))
                {
                    return(true);
                }
                isPointOnBranchWithinRange = Math.Abs(pointOnBranch.Z - pPoint.Z) < treePointExtent + 1;
            }

            dir           = -1;
            pointOnBranch = TreePoints[approxIndex];
            isPointOnBranchWithinRange = Math.Abs(pointOnBranch.Z - pPoint.Z) < treePointExtent + 1;
            for (int i = approxIndex; isPointOnBranchWithinRange && i > 0 && i < TreePoints.Count; i += dir)
            {
                pointOnBranch = TreePoints[i];
                if (pointOnBranch.Includes(pPoint, pToleranceMultiply))
                {
                    return(true);
                }
                isPointOnBranchWithinRange = Math.Abs(pointOnBranch.Z - pPoint.Z) < treePointExtent + 1;
            }

            return(false);
        }
Example #2
0
        public void AddPoint(Vector3 pPoint)
        {
            if (CTreeManager.DEBUG)
            {
                CDebug.WriteLine("--- AddPoint " + pPoint.ToString("#+0.00#;-0.00") + " to " + this);
            }

            RefreshFurthestPoint(pPoint);
            OnAddPoint(pPoint);

            int insertAtIndex = 0;

            //find appropriate insert at index
            if (TreePoints.Count > 0)
            {
                for (int i = TreePoints.Count - 1; i >= -1; i--)
                {
                    insertAtIndex = i + 1;
                    if (insertAtIndex == 0)
                    {
                        break;
                    }
                    CTreePoint pointOnBranch = TreePoints[i];
                    if (pointOnBranch.Includes(pPoint))
                    {
                        pointOnBranch.AddPoint(pPoint);
                        //boundaries of points are changed, check if the order has to be changed

                        if (i > 0)
                        {
                            CTreePoint previousPoint = TreePoints[i - 1];
                            //if(previousPoint.Contains(pointOnBranch.Center))
                            if (pointOnBranch.Z > previousPoint.Z)
                            {
                                TreePoints.RemoveAt(i);
                                TreePoints.Insert(i - 1, pointOnBranch);
                            }
                        }
                        if (i < TreePoints.Count - 1)
                        {
                            CTreePoint nextPoint = TreePoints[i + 1];
                            if (pointOnBranch.Z < nextPoint.Z)
                            {
                                TreePoints.RemoveAt(i);
                                TreePoints.Insert(i + 1, pointOnBranch);
                            }
                        }
                        CheckAddedPoint();
                        return;
                    }
                    if (pPoint.Z < pointOnBranch.Z)
                    {
                        if (i == TreePoints.Count - 1 || TreePoints[i + 1].Z <= pPoint.Z)
                        {
                            break;
                        }
                    }
                }
            }

            CTreePoint newPoint = new CTreePoint(pPoint, tree.treePointExtent);

            TreePoints.Insert(insertAtIndex, newPoint);

            CheckAddedPoint();

            if (CTreeManager.DEBUG)
            {
                CDebug.WriteLine("---- new point");
            }
        }