예제 #1
0
파일: CField.cs 프로젝트: ja003/ForestReco2
        public float?GetHeight(EHeight pType = EHeight.Smooth)
        {
            if (pType == EHeight.Smooth && SmoothHeight != null)
            {
                return(SmoothHeight);
            }
            else if (pType == EHeight.MinZ)
            {
                return(MinZ);
            }

            return(MaxZ);
        }
예제 #2
0
파일: CField.cs 프로젝트: ja003/ForestReco2
        /// <summary>
        /// Finds closest defined fields in direction based on pDiagonal parameter.
        /// Returns average of 2 found heights considering their distance from this field.
        /// </summary>
        public float?GetAverageHeightFromClosestDefined(int pMaxSteps, bool pDiagonal, EHeight pType)
        {
            if (IsDefined())
            {
                return(GetHeight(pType));
            }

            CField closestFirst  = null;
            CField closestSecond = null;
            CField closestLeft   = GetClosestDefined(pDiagonal ? EDirection.LeftTop : EDirection.Left, pMaxSteps);
            CField closestRight  = GetClosestDefined(pDiagonal ? EDirection.RightBot : EDirection.Right, pMaxSteps);
            CField closestTop    = GetClosestDefined(pDiagonal ? EDirection.RightTop : EDirection.Top, pMaxSteps);
            CField closestBot    = GetClosestDefined(pDiagonal ? EDirection.LeftBot : EDirection.Bot, pMaxSteps);

            closestFirst  = closestLeft;
            closestSecond = closestRight;
            if ((closestFirst == null || closestSecond == null) && closestTop != null && closestBot != null)
            {
                closestFirst  = closestTop;
                closestSecond = closestBot;
            }

            if (closestFirst != null && closestSecond != null)
            {
                CField smaller = closestFirst;
                CField higher  = closestSecond;
                if (closestSecond.GetHeight(pType) < closestFirst.GetHeight(pType))
                {
                    higher  = closestFirst;
                    smaller = closestSecond;
                }
                int   totalDistance = smaller.GetStepCountTo(higher);
                float?heightDiff    = higher.GetHeight(pType) - smaller.GetHeight(pType);
                if (heightDiff != null)
                {
                    float?smallerHeight     = smaller.GetHeight();
                    float distanceToSmaller = GetStepCountTo(smaller);

                    return(smallerHeight + distanceToSmaller / totalDistance * heightDiff);
                }
            }
            else if (!HasAllNeighbours())
            {
                if (closestLeft != null)
                {
                    return(closestLeft.GetHeight(pType));
                }
                if (closestTop != null)
                {
                    return(closestTop.GetHeight(pType));
                }
                if (closestRight != null)
                {
                    return(closestRight.GetHeight(pType));
                }
                if (closestBot != null)
                {
                    return(closestBot.GetHeight(pType));
                }
            }
            if (!pDiagonal)
            {
                return(GetAverageHeightFromClosestDefined(pMaxSteps, true, pType));
            }

            return(null);
        }