Esempio n. 1
0
        public override bool PerformHeightAnnotation(SubGridTreeBitmapSubGridBits processingMap, IList filteredSurveyedSurfaces, bool returnEarliestFilteredCellPass,
                                                     IClientLeafSubGrid surfaceElevationsSource, Func <int, int, float, bool> elevationRangeFilterLambda)
        {
            if (!(surfaceElevationsSource is ClientHeightAndTimeLeafSubGrid surfaceElevations))
            {
                _log.LogError($"{nameof(ClientCellProfileLeafSubgrid)}.{nameof(PerformHeightAnnotation)} not supplied a ClientHeightAndTimeLeafSubGrid instance, but an instance of {surfaceElevationsSource?.GetType().FullName}");

                return(false);
            }

            // For all cells we wanted to request a surveyed surface elevation for,
            // update the cell elevation if a non null surveyed surface of appropriate time was computed
            // Note: The surveyed surface will return all cells in the requested sub grid, not just the ones indicated in the processing map
            // IE: It is unsafe to test for null top indicate not-filtered, use the processing map iterators to cover only those cells required
            processingMap.ForEachSetBit((x, y) =>
            {
                var surveyedSurfaceCellHeight = surfaceElevations.Cells[x, y];

                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (surveyedSurfaceCellHeight == Consts.NullHeight)
                {
                    return;
                }

                // If we got back a surveyed surface elevation...
                var surveyedSurfaceCellTime = surfaceElevations.Times[x, y];
                var prodHeight = Cells[x, y].Height;
                var prodTime   = Cells[x, y].LastPassTime.Ticks;

                // Determine if the elevation from the surveyed surface data is required based on the production data elevation being null, and
                // the relative age of the measured surveyed surface elevation compared with a non-null production data height
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (!(prodHeight == Consts.NullHeight || (returnEarliestFilteredCellPass ? surveyedSurfaceCellTime <prodTime : surveyedSurfaceCellTime> prodTime)))
                {
                    // We didn't get a surveyed surface elevation, so clear the bit in the processing map to indicate there is no surveyed surface information present for it
                    processingMap.ClearBit(x, y);
                    return;
                }

                // Check if there is an elevation range filter in effect and whether the surveyed surface elevation data matches it
                if (elevationRangeFilterLambda != null)
                {
                    if (!elevationRangeFilterLambda(x, y, surveyedSurfaceCellHeight))
                    {
                        // We didn't get a surveyed surface elevation, so clear the bit in the processing map to indicate there is no surveyed surface information present for it
                        processingMap.ClearBit(x, y);
                        return;
                    }
                }

                Cells[x, y].Height = surveyedSurfaceCellHeight;
            });

            return(true);
        }