Пример #1
0
        /// <summary>
        /// Performs the donkey work of the elevation patch calculation
        /// </summary>
        /// <returns>The computed elevation of the given design at the spot location, or NullDouble if the location does not lie on the design</returns>
        private double Calc(ISiteModelBase siteModel, DesignOffset referenceDesign, double spotX, double spotY,
                            out DesignProfilerRequestResult calcResult)
        {
            calcResult = DesignProfilerRequestResult.UnknownError;

            var design = _designs.Lock(referenceDesign.DesignID, siteModel, SubGridTreeConsts.DefaultCellSize, out var lockResult);

            if (design == null)
            {
                _log.LogWarning($"Failed to read design file for design {referenceDesign.DesignID}");
                calcResult = DesignProfilerRequestResult.FailedToLoadDesignFile;
                return(Common.Consts.NullDouble);
            }

            try
            {
                var hint = -1;
                if (design.InterpolateHeight(ref hint, spotX, spotY, referenceDesign.Offset, out var z))
                {
                    calcResult = DesignProfilerRequestResult.OK;
                }
                else
                {
                    calcResult = DesignProfilerRequestResult.NoElevationsInRequestedPatch;
                    z          = Common.Consts.NullDouble;
                }

                return(z);
            }
Пример #2
0
        /// <summary>
        /// Performs execution business logic for this executor
        /// </summary>
        public (double StartStation, double EndStation) Execute(ISiteModelBase siteModel, Guid referenceDesignUid)
        {
            try
            {
                if (siteModel == null)
                {
                    return(double.MaxValue, double.MinValue);
                }
                var design = DIContext.ObtainRequired <IDesignFiles>().Lock(referenceDesignUid, siteModel, siteModel.CellSize, out var lockResult);

                if (design == null)
                {
                    Log.LogWarning($"Failed to read file for design {referenceDesignUid}");
                    return(double.MaxValue, double.MinValue);
                }

                if (design is SVLAlignmentDesign svlDesign)
                {
                    return(svlDesign.GetStationRange());
                }

                throw new TRexException($"Design {design.FileName} is not an alignment design");
            }
            catch (Exception e)
            {
                Log.LogError(e, $"Failed to compute alignment design station station range. Site Model ID: {siteModel.ID} design ID: {referenceDesignUid}");
                return(double.MaxValue, double.MinValue);
            }
        }
Пример #3
0
        /// <summary>
        /// Calculates a filter mask for a designated sub grid on this design
        /// </summary>
        public (SubGridTreeBitmapSubGridBits filterMask, DesignProfilerRequestResult errorCode) GetFilterMaskViaLocalCompute(
            ISiteModelBase siteModel,
            SubGridCellAddress originCellAddress,
            double cellSize)
        {
            // Calculate an elevation patch for the requested location and convert it into a bitmask detailing which cells have non-null values
            var patch = _designElevationCalculator.Execute(siteModel, new DesignOffset(DesignDescriptor.DesignID, 0),
                                                           cellSize, originCellAddress.X, originCellAddress.Y, out var calcResult);

            if (patch == null)
            {
                _log.LogWarning($"Request for design elevation patch that does not exist: Project: {siteModel.ID}, design {DesignDescriptor.DesignID}, location {originCellAddress.X}:{originCellAddress.Y}, calcResult: {calcResult}");
                return(null, calcResult); // Requestors should not ask for sub grids that don't exist in the design.
            }

            var mask       = new SubGridTreeBitmapSubGridBits(SubGridBitsCreationOptions.Unfilled);
            var patchCells = patch.Cells;

            for (byte i = 0; i < SubGridTreeConsts.SubGridTreeDimension; i++)
            {
                for (byte j = 0; j < SubGridTreeConsts.SubGridTreeDimension; j++)
                {
                    if (patchCells[i, j].Equals(Common.Consts.NullHeight))
                    {
                        mask[i, j] = true;
                    }
                }
            }

            return(mask, calcResult);
        }
Пример #4
0
        /// <summary>
        /// Calculates an elevation sub grid for a designated sub grid on this design
        /// </summary>
        public (IClientHeightLeafSubGrid designHeights, DesignProfilerRequestResult errorCode) GetDesignHeightsViaLocalCompute(
            ISiteModelBase siteModel,
            double offset,
            SubGridCellAddress originCellAddress,
            double cellSize)
        {
            var heightsResult = _designElevationCalculator.Execute(siteModel, new DesignOffset(DesignDescriptor.DesignID, offset),
                                                                   cellSize, originCellAddress.X, originCellAddress.Y, out var calcResult);

            return(heightsResult, calcResult);
        }
Пример #5
0
        /// <summary>
        /// Performs execution business logic for this executor
        /// </summary>
        public IClientHeightLeafSubGrid Execute(ISiteModelBase siteModel, DesignOffset referenceDesign, double cellSize, int originX, int originY, out DesignProfilerRequestResult calcResult)
        {
            // Perform the design elevation patch calculation
            try
            {
                /* Test code to force all sub grids to have 0 elevations from a design
                 * ClientHeightLeafSubGrid test = new ClientHeightLeafSubGrid(null, null, 6, 0.34, SubGridTreeConsts.DefaultIndexOriginOffset);
                 * test.SetToZeroHeight();
                 * return test;
                 */

                // Calculate the patch of elevations and return it
                return(Calc(siteModel, referenceDesign, cellSize, originX, originY, out calcResult));
            }
            finally
            {
                //if Debug_PerformDPServiceRequestHighRateLogging then
                //Log.LogInformation($"#Out# {nameof(CalculateDesignElevationPatch)}.Execute #Result# {calcResult}");
            }
        }
Пример #6
0
        /// <summary>
        /// Performs the donkey work of the elevation patch calculation
        /// </summary>
        private IClientHeightLeafSubGrid Calc(ISiteModelBase siteModel, DesignOffset referenceDesign, double cellSize, int originX, int originY,
                                              out DesignProfilerRequestResult calcResult)
        {
            calcResult = DesignProfilerRequestResult.UnknownError;

            if (_isTraceLoggingEnabled)
            {
                _log.LogTrace("About to lock design");
            }

            var design = Designs.Lock(referenceDesign.DesignID, siteModel, cellSize, out var lockResult);

            if (design == null)
            {
                _log.LogWarning($"Failed to read design file for design {referenceDesign.DesignID}");

                calcResult = lockResult == DesignLoadResult.DesignDoesNotExist
                ? DesignProfilerRequestResult.DesignDoesNotExist
                : DesignProfilerRequestResult.FailedToLoadDesignFile;

                return(null);
            }

            try
            {
                if (_isTraceLoggingEnabled)
                {
                    _log.LogTrace("Computing sub grid elevation patch");
                }

                // Check to see if this sub grid has any design surface underlying it
                // from which to calculate an elevation patch. If not, don't bother...
                if (!design.HasElevationDataForSubGridPatch(originX >> SubGridTreeConsts.SubGridIndexBitsPerLevel,
                                                            originY >> SubGridTreeConsts.SubGridIndexBitsPerLevel))
                {
                    calcResult = DesignProfilerRequestResult.NoElevationsInRequestedPatch;
                    return(null);
                }

                var result = new ClientHeightLeafSubGrid(null, null, SubGridTreeConsts.SubGridTreeLevels, cellSize, SubGridTreeConsts.DefaultIndexOriginOffset);

                result.SetAbsoluteOriginPosition(originX & ~SubGridTreeConsts.SubGridLocalKeyMask,
                                                 originY & ~SubGridTreeConsts.SubGridLocalKeyMask);
                result.CalculateWorldOrigin(out var worldOriginX, out var worldOriginY);

                calcResult = design.InterpolateHeights(result.Cells, worldOriginX, worldOriginY, cellSize, referenceDesign.Offset)
                  ? DesignProfilerRequestResult.OK
                  : DesignProfilerRequestResult.NoElevationsInRequestedPatch;

                if (_isTraceLoggingEnabled)
                {
                    _log.LogTrace("Computed sub grid elevation patch");
                }

                return(result);
            }
            finally
            {
                if (_isTraceLoggingEnabled)
                {
                    _log.LogTrace("Unlocking design");
                }

                Designs.UnLock(referenceDesign.DesignID, design);

                if (_isTraceLoggingEnabled)
                {
                    _log.LogTrace("Completed calculating design elevations");
                }
            }
        }