Example #1
0
        /// <summary>
        /// Constructor for the sub grid retriever helper
        /// </summary>
        /// <param name="siteModel">The project this sub gris is being retrieved from</param>
        /// <param name="gridDataType">The type of client grid data sub grids to be returned by this retriever</param>
        /// <param name="storageProxy">The Ignite storage proxy to be used when requesting data from the persistent store</param>
        /// <param name="filter">The TRex spatial and attribute filtering description for the request</param>
        /// <param name="filterAnnex">An annex of data related to cell by cell filtering where the attributes related to that cell may change from cell to cell</param>
        /// <param name="hasOverrideSpatialCellRestriction">The spatially selected cells are masked by a rectangular restriction boundary</param>
        /// <param name="overrideSpatialCellRestriction"></param>
        /// <param name="prepareGridForCacheStorageIfNoSieving">The cell coordinate bounding box restricting cells involved in the request</param>
        /// <param name="maxNumberOfPassesToReturn">The maximum number of passes in a cell in a sub grid that will be considered when processing the request</param>
        /// <param name="areaControlSet">The skip/step area control set for selection of cells with sub grids for processing. Cells not identified by the control set will return null values.</param>
        /// <param name="populationControl">The delegate responsible for populating events depended on for processing the request.</param>
        /// <param name="pDExistenceMap">The production data existence map for the project the request relates to</param>
        /// <param name="overrides">The set of overriding machine event values to use</param>
        /// <param name="liftParams">The set of layer/lift analysis parameters to use</param>
        public ProgressiveVolumesSubGridRetriever(ISiteModel siteModel,
                                                  GridDataType gridDataType,
                                                  IStorageProxy storageProxy,
                                                  ICombinedFilter filter,
                                                  ICellPassAttributeFilterProcessingAnnex filterAnnex,
                                                  bool hasOverrideSpatialCellRestriction,
                                                  BoundingIntegerExtent2D overrideSpatialCellRestriction,
                                                  bool prepareGridForCacheStorageIfNoSieving,
                                                  int maxNumberOfPassesToReturn,
                                                  AreaControlSet areaControlSet,
                                                  IFilteredValuePopulationControl populationControl,
                                                  ISubGridTreeBitMask pDExistenceMap,
                                                  IOverrideParameters overrides,
                                                  ILiftParameters liftParams)
            : base(siteModel, gridDataType, filter, filterAnnex,
                   hasOverrideSpatialCellRestriction, overrideSpatialCellRestriction, prepareGridForCacheStorageIfNoSieving, maxNumberOfPassesToReturn,
                   storageProxy, areaControlSet, populationControl, pDExistenceMap, overrides, liftParams)
        {
            // Clear any time element from the supplied filter. Time constraints ar derived from the startDate and endDate parameters
            filter.AttributeFilter.HasTimeFilter = false;

            // Clear any instruction in the filter to extract the earliest value - this has no meaning in progressive calculations
            filter.AttributeFilter.ReturnEarliestFilteredCellPass = false;

            // Remove any first/last/highest/lowest aspect from the filter - this has no meaning in progressive calculations
            filter.AttributeFilter.HasElevationTypeFilter = false;

            // Remove any machine filtering - the intent here is to examine volume progression over time, machine breakdowns don't make sense at this point
            filter.AttributeFilter.HasMachineFilter = false;
        }
Example #2
0
        /// <summary>
        /// Given a design used as an elevation range filter aspect, retrieve the existence map for the design and
        /// includes it in the supplied overall existence map for the query
        /// </summary>
        public static bool ProcessDesignElevationsForFilter(ISiteModel siteModel, //Guid siteModelID,
                                                            ICombinedFilter filter,
                                                            ISubGridTreeBitMask overallExistenceMap)
        {
            if (filter == null)
            {
                return(true);
            }

            if (overallExistenceMap == null)
            {
                return(false);
            }

            if (filter.AttributeFilter.HasElevationRangeFilter && filter.AttributeFilter.ElevationRangeDesign.DesignID != Guid.Empty)
            {
                var designExistenceMap = DIContext.Obtain <IExistenceMaps>().GetSingleExistenceMap
                                             (siteModel.ID, Consts.EXISTENCE_MAP_DESIGN_DESCRIPTOR, filter.AttributeFilter.ElevationRangeDesign.DesignID);

                if (designExistenceMap != null)
                {
                    // Not sure this is really needed...
                    designExistenceMap.CellSize = SubGridTreeConsts.SubGridTreeDimension * siteModel.CellSize;
                    overallExistenceMap.SetOp_OR(designExistenceMap);
                }
            }

            return(true);
        }
Example #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="startDate">The date at which to start calculating progressive sub grids</param>
 /// <param name="endDate">The date beyond which no further progressive sub grids will be calculated</param>
 /// <param name="interval">The time interval between successive calculations of progressive sub grids</param>
 public ComputeProgressiveVolumes_Coordinator(Guid siteModelId,
                                              ILiftParameters liftParams,
                                              VolumeComputationType volumeType,
                                              ICombinedFilter filter,
                                              DesignOffset baseDesign,
                                              DesignOffset topDesign,
                                              ICombinedFilter additionalSpatialFilter,
                                              double cutTolerance,
                                              double fillTolerance,
                                              DateTime startDate,
                                              DateTime endDate,
                                              TimeSpan interval)
 {
     SiteModelID             = siteModelId;
     VolumeType              = volumeType;
     Filter                  = filter;
     _baseDesign             = baseDesign;
     _topDesign              = topDesign;
     AdditionalSpatialFilter = additionalSpatialFilter;
     CutTolerance            = cutTolerance;
     FillTolerance           = fillTolerance;
     _liftParams             = liftParams;
     StartDate               = startDate;
     EndDate                 = endDate;
     Interval                = interval;
 }
Example #4
0
        /// <summary>
        /// Serializes content from the writer
        /// </summary>
        public override void InternalFromBinary(IBinaryRawReader reader)
        {
            base.InternalFromBinary(reader);

            var version = VersionSerializationHelper.CheckVersionByte(reader, VERSION_NUMBER);

            if (version == 1)
            {
                ProjectID  = reader.ReadGuid() ?? Guid.Empty;
                VolumeType = (VolumeComputationType)reader.ReadInt();

                BaseFilter = ReadFilter(reader);
                TopFilter  = ReadFilter(reader);

                if (reader.ReadBoolean())
                {
                    BaseDesign = new DesignOffset();
                    BaseDesign.FromBinary(reader);
                }

                if (reader.ReadBoolean())
                {
                    TopDesign = new DesignOffset();
                    TopDesign.FromBinary(reader);
                }

                AdditionalSpatialFilter = ReadFilter(reader);

                CutTolerance  = reader.ReadDouble();
                FillTolerance = reader.ReadDouble();
            }
        }
Example #5
0
 /// <summary>
 /// Constructor accepting a pair of filter to be set into the filter set
 /// Null filters are not incorporated into the resulting filter set
 /// </summary>
 public FilterSet(ICombinedFilter filter1, ICombinedFilter filter2)
 {
     Filters = filter1 == null && filter2 == null
 ? new ICombinedFilter[0]
 : filter2 == null
   ? new[] { filter1 }
   : filter1 == null
     ? new [] { filter2 }
     : new [] { filter1, filter2 };
 }
Example #6
0
        private ICombinedFilter ReadFilter(IBinaryRawReader reader)
        {
            ICombinedFilter filter = null;

            if (reader.ReadBoolean())
            {
                filter = new CombinedFilter();
                filter.FromBinary(reader);
            }

            return(filter);
        }
Example #7
0
             ITRexSpatialMemoryCacheContext[] CacheContexts) GetIntermediary(ICombinedFilter filter)
            {
                // Construct the appropriate list of surveyed surfaces
                // Obtain local reference to surveyed surface list. If it is replaced while processing the
                // list then the local reference will still be valid allowing lock free read access to the list.
                ISurveyedSurfaces filteredSurveyedSurfaces = null;
                var surveyedSurfaceList = siteModel.SurveyedSurfaces;

                if (includeSurveyedSurfaceInformation && surveyedSurfaceList?.Count > 0)
                {
                    filteredSurveyedSurfaces = DIContext.Obtain <ISurveyedSurfaces>();

                    // Filter out any surveyed surfaces which don't match current filter (if any) - realistically, this is time filters we're thinking of here
                    surveyedSurfaceList.FilterSurveyedSurfaceDetails(filter.AttributeFilter.HasTimeFilter,
                                                                     filter.AttributeFilter.StartTime, filter.AttributeFilter.EndTime,
                                                                     filter.AttributeFilter.ExcludeSurveyedSurfaces(), filteredSurveyedSurfaces,
                                                                     filter.AttributeFilter.SurveyedSurfaceExclusionList);

                    // Ensure that the filtered surveyed surfaces are in a known ordered state
                    filteredSurveyedSurfaces.SortChronologically(filter.AttributeFilter.ReturnEarliestFilteredCellPass);
                }

                var filteredSurveyedSurfacesAsArray = filteredSurveyedSurfaces?.Count > 0 ? filteredSurveyedSurfaces.Select(s => s.ID).ToArray() : new Guid[0];

                // Get a caching context for the sub grids returned by this requester, but only if the requested grid data type supports it
                ITRexSpatialMemoryCacheContext[] subGridCacheContexts = null;

                if (_enableGeneralSubGridResultCaching &&
                    ClientLeafSubGrid.SupportsAssignationFromCachedPreProcessedClientSubGrid[(int)gridDataType])
                {
                    filter.AttributeFilter.SiteModel = siteModel;
                    var contextType1 = Utilities.IntermediaryICGridDataTypeForDataType(gridDataType, true);
                    var contextType2 = Utilities.IntermediaryICGridDataTypeForDataType(gridDataType, false);

                    var context1 = SubGridCache?.LocateOrCreateContext(siteModel.ID, contextType1,
                                                                       SpatialCacheFingerprint.ConstructFingerprint(siteModel.ID, contextType1, filter, filteredSurveyedSurfacesAsArray));
                    var context2 = SubGridCache?.LocateOrCreateContext(siteModel.ID, contextType2,
                                                                       SpatialCacheFingerprint.ConstructFingerprint(siteModel.ID, contextType2, filter, filteredSurveyedSurfacesAsArray));

                    subGridCacheContexts = new[] { context1, context2 }.Where(x => x != null).ToArray();
                }

                return(gridDataType,
                       filter,
                       filteredSurveyedSurfaces,
                       _surfaceElevationPatchRequestFactory(SubGridCache, SubGridCache?.LocateOrCreateContext(siteModel.ID, GridDataType.SurveyedSurfaceHeightAndTime,
                                                                                                              SpatialCacheFingerprint.ConstructFingerprint(siteModel.ID, GridDataType.SurveyedSurfaceHeightAndTime, null,
                                                                                                                                                           filteredSurveyedSurfaces?.Select(x => x.ID).ToArray() ?? new Guid[0]))),
                       subGridCacheContexts);
            }
Example #8
0
 /// <summary>
 /// Constructor for the sub grid retriever helper
 /// </summary>
 /// <param name="siteModel">The project this sub gris is being retrieved from</param>
 /// <param name="gridDataType">The type of client grid data sub grids to be returned by this retriever</param>
 /// <param name="storageProxy">The Ignite storage proxy to be used when requesting data from the persistent store</param>
 /// <param name="filter">The TRex spatial and attribute filtering description for the request</param>
 /// <param name="filterAnnex">An annex of data related to cell by cell filtering where the attributes related to that cell may change from cell to cell</param>
 /// <param name="hasOverrideSpatialCellRestriction">The spatially selected cells are masked by a rectangular restriction boundary</param>
 /// <param name="overrideSpatialCellRestriction"></param>
 /// <param name="prepareGridForCacheStorageIfNoSieving">The cell coordinate bounding box restricting cells involved in the request</param>
 /// <param name="maxNumberOfPassesToReturn">The maximum number of passes in a cell in a sub grid that will be considered when processing the request</param>
 /// <param name="areaControlSet">The skip/step area control set for selection of cells with sub grids for processing. Cells not identified by the control set will return null values.</param>
 /// <param name="populationControl">The delegate responsible for populating events depended on for processing the request.</param>
 /// <param name="pDExistenceMap">The production data existence map for the project the request relates to</param>
 /// <param name="overrides">The set of overriding machine event values to use</param>
 /// <param name="liftParams">The set of layer/lift analysis parameters to use</param>
 public SubGridRetriever(ISiteModel siteModel,
                         GridDataType gridDataType,
                         IStorageProxy storageProxy,
                         ICombinedFilter filter,
                         ICellPassAttributeFilterProcessingAnnex filterAnnex,
                         bool hasOverrideSpatialCellRestriction,
                         BoundingIntegerExtent2D overrideSpatialCellRestriction,
                         bool prepareGridForCacheStorageIfNoSieving,
                         int maxNumberOfPassesToReturn,
                         AreaControlSet areaControlSet,
                         IFilteredValuePopulationControl populationControl,
                         ISubGridTreeBitMask pDExistenceMap,
                         IOverrideParameters overrides,
                         ILiftParameters liftParams)
     : base(siteModel, gridDataType, filter, filterAnnex,
            hasOverrideSpatialCellRestriction, overrideSpatialCellRestriction, prepareGridForCacheStorageIfNoSieving, maxNumberOfPassesToReturn,
            storageProxy, areaControlSet, populationControl, pDExistenceMap, overrides, liftParams)
 {
 }
Example #9
0
        protected SubGridRetrieverBase(ISiteModel siteModel,
                                       GridDataType gridDataType,
                                       ICombinedFilter filter,
                                       ICellPassAttributeFilterProcessingAnnex filterAnnex,
                                       bool hasOverrideSpatialCellRestriction,
                                       BoundingIntegerExtent2D overrideSpatialCellRestriction,
                                       bool prepareGridForCacheStorageIfNoSieving,
                                       int maxNumberOfPassesToReturn,
                                       IStorageProxy storageProxy,
                                       AreaControlSet areaControlSet,
                                       IFilteredValuePopulationControl populationControl,
                                       ISubGridTreeBitMask pDExistenceMap,
                                       IOverrideParameters overrides,
                                       ILiftParameters liftParams)
        {
            _segmentIterator  = null;
            _cellPassIterator = null;

            _siteModel    = siteModel;
            _gridDataType = gridDataType;
            _filter       = filter;
            _filterAnnex  = filterAnnex;
            _hasOverrideSpatialCellRestriction     = hasOverrideSpatialCellRestriction;
            _overrideSpatialCellRestriction        = overrideSpatialCellRestriction;
            _prepareGridForCacheStorageIfNoSieving = prepareGridForCacheStorageIfNoSieving;
            _maxNumberOfPassesToReturn             = maxNumberOfPassesToReturn;
            _storageProxy      = storageProxy;
            _populationControl = populationControl;
            _areaControlSet    = areaControlSet;
            _pdExistenceMap    = pDExistenceMap;
            _overrides         = overrides;
            _liftParams        = liftParams;

            // Create and configure the assignment context which is used to contain a filtered pass and
            // its attendant machine events and target values prior to assignment to the client sub grid.
            _assignmentContext = new FilteredValueAssignmentContext {
                Overrides = overrides, LiftParams = liftParams
            };

            _filter.AttributeFilter.SiteModel = siteModel;

            _canUseGlobalLatestCells = _filter.AttributeFilter.LastRecordedCellPassSatisfiesFilter;
        }
Example #10
0
        public static bool ConstructSubGridCellFilterMask(ILeafSubGrid SubGridAsLeaf,
                                                          ISiteModel SiteModel,
                                                          ICombinedFilter Filter,
                                                          SubGridTreeBitmapSubGridBits CellOverrideMask,
                                                          bool AHasOverrideSpatialCellRestriction,
                                                          BoundingIntegerExtent2D AOverrideSpatialCellRestriction,
                                                          SubGridTreeBitmapSubGridBits PDMask,
                                                          SubGridTreeBitmapSubGridBits FilterMask)
        {
            ConstructSubgridSpatialAndPositionalMask(SubGridAsLeaf, SiteModel, Filter,
                                                     AHasOverrideSpatialCellRestriction, AOverrideSpatialCellRestriction,
                                                     PDMask, FilterMask);

            // Apply any override mask supplied by the caller. If all bits are required in the override,
            // then a filled mask should be supplied...
            PDMask.AndWith(CellOverrideMask);

            // If the filter contains a design mask filter then compute this and AND it with the
            // mask calculated in the step above to derive the final required filter mask
            if (Filter != null && Filter.SpatialFilter.HasAlignmentDesignMask())
            {
                if (Filter.SpatialFilter.AlignmentFence.IsNull()) // Should have been done in ASNode but if not
                {
                    throw new ArgumentException($"Spatial filter does not contained pre-prepared alignment fence for design {Filter.SpatialFilter.AlignmentDesignMaskDesignUID}");
                }

                // Go over set bits and determine if they are in Design fence boundary
                FilterMask.ForEachSetBit((X, Y) =>
                {
                    SiteModel.Grid.GetCellCenterPosition(SubGridAsLeaf.OriginX + X, SubGridAsLeaf.OriginY + Y, out var CX, out var CY);
                    if (!Filter.SpatialFilter.AlignmentFence.IncludesPoint(CX, CY))
                    {
                        FilterMask.ClearBit(X, Y); // remove interest as its not in design boundary
                    }
                });
            }

            PDMask.AndWith(FilterMask);

            return(true);
        }
Example #11
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ComputeSimpleVolumes_Coordinator(Guid siteModelID,
                                         ILiftParameters liftParams,
                                         VolumeComputationType volumeType,
                                         ICombinedFilter baseFilter,
                                         ICombinedFilter topFilter,
                                         DesignOffset baseDesign,
                                         DesignOffset topDesign,
                                         ICombinedFilter additionalSpatialFilter,
                                         double cutTolerance,
                                         double fillTolerance)
 {
     SiteModelID             = siteModelID;
     VolumeType              = volumeType;
     BaseFilter              = baseFilter;
     TopFilter               = topFilter;
     BaseDesign              = baseDesign;
     TopDesign               = topDesign;
     AdditionalSpatialFilter = additionalSpatialFilter;
     CutTolerance            = cutTolerance;
     FillTolerance           = fillTolerance;
     LiftParams              = liftParams;
 }
Example #12
0
        /// <summary>
        /// Given a filter compute which of the surfaces in the list match any given time aspect
        /// of the filter, and the overall existence map of the surveyed surfaces that match the filter.
        /// ComparisonList denotes a possibly pre-filtered set of surfaces for another filter; if this is the same as the
        /// filtered set of surfaces then the overall existence map for those surfaces will not be computed as it is
        /// assumed to be the same.
        /// </summary>
        public bool ProcessSurveyedSurfacesForFilter(Guid siteModelId,
                                                     ICombinedFilter filter,
                                                     ISurveyedSurfaces comparisonList,
                                                     ISurveyedSurfaces filteredSurveyedSurfaces,
                                                     ISubGridTreeBitMask overallExistenceMap)
        {
            // Filter out any surveyed surfaces which don't match current filter (if any) - realistically, this is time filters we're thinking of here
            FilterSurveyedSurfaceDetails(filter.AttributeFilter.HasTimeFilter,
                                         filter.AttributeFilter.StartTime, filter.AttributeFilter.EndTime,
                                         filter.AttributeFilter.ExcludeSurveyedSurfaces(),
                                         filteredSurveyedSurfaces,
                                         filter.AttributeFilter.SurveyedSurfaceExclusionList);

            if (filteredSurveyedSurfaces != null)
            {
                if (filteredSurveyedSurfaces.IsSameAs(comparisonList))
                {
                    return(true);
                }

                if (filteredSurveyedSurfaces.Count > 0)
                {
                    var surveyedSurfaceExistenceMap = GetExistenceMaps().GetCombinedExistenceMap(siteModelId,
                                                                                                 filteredSurveyedSurfaces.Select(x => new Tuple <long, Guid>(Consts.EXISTENCE_SURVEYED_SURFACE_DESCRIPTOR, x.ID)).ToArray());

                    if (overallExistenceMap == null)
                    {
                        return(false);
                    }

                    overallExistenceMap.SetOp_OR(surveyedSurfaceExistenceMap);
                }
            }

            return(true);
        }
Example #13
0
        public static void ConstructSubgridSpatialAndPositionalMask(ILeafSubGrid SubGridAsLeaf,
                                                                    ISiteModel SiteModel,
                                                                    ICombinedFilter Filter,
                                                                    bool AHasOverrideSpatialCellRestriction,
                                                                    BoundingIntegerExtent2D AOverrideSpatialCellRestriction,
                                                                    SubGridTreeBitmapSubGridBits PDMask,
                                                                    SubGridTreeBitmapSubGridBits FilterMask)
        {
            if (Filter == null || !Filter.SpatialFilter.HasSpatialOrPositionalFilters)
            {
                PDMask.Fill();
                FilterMask.Fill();
                return;
            }

            var originX = SubGridAsLeaf.OriginX;
            var originY = SubGridAsLeaf.OriginY;

            var cellSize = SiteModel.CellSize;

            // Get the world location of the origin position
            SiteModel.Grid.GetCellCenterPosition(originX, originY, out var OX, out var OY);

            var SpatialFilter = Filter.SpatialFilter;

            // Attempt to satisfy the calculation below on the basis of the sub grid wholly residing in the override and filter spatial restrictions
            if (SpatialFilter.Fence.IncludesExtent(new BoundingWorldExtent3D(OX, OY,
                                                                             OX + cellSize * SubGridTreeConsts.SubGridTreeDimension,
                                                                             OY + cellSize * SubGridTreeConsts.SubGridTreeDimension)))
            {
                // The extent of the sub grid is wholly contained in the filter, therefore there is no need to iterate though all the cells
                // individually...

                FilterMask.Fill();

                // ... unless there is an override spatial cell restriction that does not enclose the extent of the sub grid
                if (AHasOverrideSpatialCellRestriction &&
                    !AOverrideSpatialCellRestriction.Encloses(new BoundingIntegerExtent2D((int)originX, (int)originY,
                                                                                          (int)originX + SubGridTreeConsts.SubGridTreeDimension,
                                                                                          (int)originY + SubGridTreeConsts.SubGridTreeDimension)))
                {
                    for (byte I = 0; I < SubGridTreeConsts.SubGridTreeDimension; I++)
                    {
                        for (byte J = 0; J < SubGridTreeConsts.SubGridTreeDimension; J++)
                        {
                            if (!AOverrideSpatialCellRestriction.Includes(originX + I, originY + J))
                            {
                                FilterMask.ClearBit(I, J);
                            }
                        }
                    }
                }
            }
            else
            {
                // Perform the calculation the long hand way
                // ... Idea: Invert row and column order of calculation below to get and set bits based on an entire column of bits

                FilterMask.Clear();

                // Construct the filter mask based on the spatial and location (square/circle/polygonal) filtering
                double CX = OX;

                for (byte I = 0; I < SubGridTreeConsts.SubGridTreeDimension; I++)
                {
                    int    OriginXPlusI = originX + I;
                    double CY           = OY; // Set to the first row in the column about to be processed

                    for (byte J = 0; J < SubGridTreeConsts.SubGridTreeDimension; J++)
                    {
                        if (AHasOverrideSpatialCellRestriction && !AOverrideSpatialCellRestriction.Includes((int)OriginXPlusI, (int)(originY + J)))
                        {
                            // Do nothing
                        }
                        else
                        {
                            // SiteModel.Grid.GetCellCenterPosition(OriginXPlusI, originY + J, out CX, out CY);
                            if (SpatialFilter.IsCellInSelection(CX, CY))
                            {
                                FilterMask.SetBit(I, J);
                            }
                        }

                        CY += cellSize; // Move to next row
                    }

                    CX += cellSize; // Move to next column
                }
            }
        }
Example #14
0
        /// <summary>
        /// Constructs a string representing the fingerprint of a request required spatial data. The fingerprint is designed to identify a context within
        /// which cached general sub grid results may be stored and accessed during query processing.
        /// </summary>
        /// <param name="projectUid">The Guid identifying the project within the fingerprint</param>
        /// <param name="gridDataType">The type of data being requested in the query</param>
        /// <param name="filter">The set of filters that govern the query</param>
        /// <param name="includedSurveyedSurfaces">The list of surveyed surfaces included in the query, expressed as a an array of GUIDs</param>
        /// <returns>A string representing the uniqueness of this spatial cache element</returns>
        public static string ConstructFingerprint(Guid projectUid, GridDataType gridDataType, ICombinedFilter filter, Guid[] includedSurveyedSurfaces)
        {
            var sb = new StringBuilder();

            sb.Append(projectUid).Append('-').Append(gridDataType);

            if (filter != null)
            {
                sb.Append('-').Append(filter.AttributeFilter.SpatialCacheFingerprint());
            }

            if (includedSurveyedSurfaces.Length > 0)
            {
                includedSurveyedSurfaces.ForEach(x => sb.Append(x));
            }

            return(sb.ToString());
        }
Example #15
0
 /// <summary>
 /// Constructor accepting a single filters to be set into the filter set
 /// Null filters are not incorporated into the resulting filter set
 /// </summary>
 public FilterSet(ICombinedFilter filter)
 {
     Filters = filter != null ? new [] { filter } : new ICombinedFilter[0];
 }
Example #16
0
        /*
         * private IExistenceMaps existenceMaps = null;
         * private IExistenceMaps GetExistenceMaps() => existenceMaps ??= DIContext.Obtain<IExistenceMaps>());
         */

        /// <summary>
        /// Prepare a filter for use by performing any necessary coordinate conversions and requesting any
        /// supplemental information such as alignment design boundary calculations.
        /// </summary>
        public static RequestErrorStatus PrepareFilterForUse(ICombinedFilter filter, Guid dataModelId)
        {
            // Fence DesignBoundary = null;
            var result = RequestErrorStatus.OK;

            if (filter == null)
            {
                return(result);
            }

            if (filter.SpatialFilter != null)
            {
                if (!filter.SpatialFilter.CoordsAreGrid)
                {
                    var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(dataModelId);

                    XYZ[] llhCoords;
                    // If the filter has a spatial or positional context, then convert the LLH values in the
                    // spatial context into the NEE values consistent with the data model.
                    if (filter.SpatialFilter.IsSpatial)
                    {
                        llhCoords = new XYZ[filter.SpatialFilter.Fence.NumVertices];

                        // Note: Lat/Lons in filter fence boundaries are supplied to us in decimal degrees, not radians
                        for (var fencePointIdx = 0; fencePointIdx < filter.SpatialFilter.Fence.NumVertices; fencePointIdx++)
                        {
                            llhCoords[fencePointIdx] = new XYZ(MathUtilities.DegreesToRadians(filter.SpatialFilter.Fence[fencePointIdx].X), MathUtilities.DegreesToRadians(filter.SpatialFilter.Fence[fencePointIdx].Y), 0);
                        }

                        XYZ[] neeCoords;

                        try
                        {
                            neeCoords = DIContext
                                        .Obtain <ICoreXWrapper>()
                                        .LLHToNEE(siteModel.CSIB(), llhCoords.ToCoreX_XYZ(), InputAs.Radians)
                                        .ToTRex_XYZ();
                        }
                        catch (Exception e)
                        {
                            return(RequestErrorStatus.FailedToConvertClientWGSCoords);
                        }


                        for (var fencePointIdx = 0; fencePointIdx < filter.SpatialFilter.Fence.NumVertices; fencePointIdx++)
                        {
                            filter.SpatialFilter.Fence[fencePointIdx].X = neeCoords[fencePointIdx].X;
                            filter.SpatialFilter.Fence[fencePointIdx].Y = neeCoords[fencePointIdx].Y;
                        }

                        // Ensure that the bounding rectangle for the filter fence correctly encloses the newly calculated grid coordinates
                        filter.SpatialFilter.Fence.UpdateExtents();
                    }

                    if (filter.SpatialFilter.IsPositional)
                    {
                        // Note: Lat/Lons in positions are supplied to us in decimal degrees, not radians
                        llhCoords = new[] { new XYZ(MathUtilities.DegreesToRadians(filter.SpatialFilter.PositionX), MathUtilities.DegreesToRadians(filter.SpatialFilter.PositionY), 0) };

                        XYZ[] neeCoords;

                        try
                        {
                            neeCoords = DIContext
                                        .Obtain <ICoreXWrapper>()
                                        .LLHToNEE(siteModel.CSIB(), llhCoords.ToCoreX_XYZ(), InputAs.Radians)
                                        .ToTRex_XYZ();
                        }
                        catch
                        {
                            return(RequestErrorStatus.FailedToConvertClientWGSCoords);
                        }

                        filter.SpatialFilter.PositionX = neeCoords[0].X;
                        filter.SpatialFilter.PositionY = neeCoords[0].Y;
                    }

                    filter.SpatialFilter.CoordsAreGrid = true;
                }

                // Ensure that the bounding rectangle for the filter fence correctly encloses the newly calculated grid coordinates
                filter.SpatialFilter?.Fence.UpdateExtents();

                // Is there an alignment file to look up? If so, only do it if there not an already existing alignment fence boundary
                if (filter.SpatialFilter.HasAlignmentDesignMask() && !(filter.SpatialFilter.AlignmentFence?.HasVertices ?? true))
                {
                    var boundaryRequest = new AlignmentDesignFilterBoundaryRequest();

                    var boundaryResult = boundaryRequest.Execute
                                             (new AlignmentDesignFilterBoundaryArgument
                    {
                        ProjectID       = dataModelId,
                        ReferenceDesign = new DesignOffset(filter.SpatialFilter.AlignmentDesignMaskDesignUID, 0),
                        StartStation    = filter.SpatialFilter.StartStation ?? Common.Consts.NullDouble,
                        EndStation      = filter.SpatialFilter.EndStation ?? Common.Consts.NullDouble,
                        LeftOffset      = filter.SpatialFilter.LeftOffset ?? Common.Consts.NullDouble,
                        RightOffset     = filter.SpatialFilter.RightOffset ?? Common.Consts.NullDouble,
                        Filters         = new FilterSet(new CombinedFilter())
                    });

                    if (boundaryResult.RequestResult != DesignProfilerRequestResult.OK)
                    {
                        _log.LogError($"{nameof(PrepareFilterForUse)}: Failed to get boundary for alignment design ID:{filter.SpatialFilter.AlignmentDesignMaskDesignUID}");

                        return(RequestErrorStatus.NoResultReturned);
                    }

                    filter.SpatialFilter.AlignmentFence = boundaryResult.Boundary;
                }

                // Is there a surface design to look up
                if (filter.SpatialFilter.HasSurfaceDesignMask())
                {
                    // Todo: Not yet supported (or demonstrated that it's needed as this should be taken care of in the larger scale determination of the sub grids that need to be queried).

                    /* If the filter needs to retain a reference to the existence map, then do this...
                     * Filter.SpatialFilter.DesignMaskExistenceMap = GetExistenceMaps().GetSingleExistenceMap(ProjectUid, EXISTENCE_MAP_DESIGN_DESCRIPTOR, Filter.SpatialFilter.SurfaceDesignMaskDesignUid);
                     *
                     * if (Filter.SpatialFilter.DesignMaskExistenceMap == null)
                     * {
                     * Log.LogError($"PrepareFilterForUse: Failed to get existence map for surface design ID:{Filter.SpatialFilter.SurfaceDesignMaskDesignUid}");
                     * }
                     */
                }
            }

            return(result);
        }
Example #17
0
 private void WriteFilter(IBinaryRawWriter writer, ICombinedFilter filter)
 {
     writer.WriteBoolean(filter != null);
     filter?.ToBinary(writer);
 }
Example #18
0
        public ISubGridRetriever Instance(ISubGridsRequestArgument subGridsRequestArgument,
                                          ISiteModel siteModel,
                                          GridDataType gridDataType,
                                          IStorageProxy storageProxy,
                                          ICombinedFilter filter,
                                          ICellPassAttributeFilterProcessingAnnex filterAnnex,
                                          bool hasOverrideSpatialCellRestriction,
                                          BoundingIntegerExtent2D overrideSpatialCellRestriction,
                                          int maxNumberOfPassesToReturn,
                                          AreaControlSet areaControlSet,
                                          IFilteredValuePopulationControl populationControl,
                                          ISubGridTreeBitMask pdExistenceMap,
                                          ITRexSpatialMemoryCacheContext[] subGridCacheContexts,
                                          IOverrideParameters overrides,
                                          ILiftParameters liftParams)
        {
            if (gridDataType == GridDataType.ProgressiveVolumes)
            {
                var retriever = new ProgressiveVolumesSubGridRetriever(siteModel,
                                                                       gridDataType,
                                                                       storageProxy,
                                                                       filter,
                                                                       filterAnnex,
                                                                       hasOverrideSpatialCellRestriction,
                                                                       overrideSpatialCellRestriction,
                                                                       subGridCacheContexts != null,
                                                                       maxNumberOfPassesToReturn,
                                                                       areaControlSet,
                                                                       populationControl,
                                                                       pdExistenceMap,
                                                                       overrides,
                                                                       liftParams);

                if (subGridsRequestArgument is IProgressiveVolumesSubGridsRequestArgument argument)
                {
                    retriever.StartDate = argument.StartDate;
                    retriever.EndDate   = argument.EndDate;
                    retriever.Interval  = argument.Interval;
                }
                else
                {
                    throw new ArgumentException($"Argument passed to sub grid retriever factory for progressive volumes retriever construction is not an expected type: {subGridsRequestArgument.GetType()}");
                }

                return(retriever);
            }
            else
            {
                var retriever = new SubGridRetriever(siteModel,
                                                     gridDataType,
                                                     storageProxy,
                                                     filter,
                                                     filterAnnex,
                                                     hasOverrideSpatialCellRestriction,
                                                     overrideSpatialCellRestriction,
                                                     subGridCacheContexts != null,
                                                     maxNumberOfPassesToReturn,
                                                     areaControlSet,
                                                     populationControl,
                                                     pdExistenceMap,
                                                     overrides,
                                                     liftParams);

                return(retriever);
            }
        }
Example #19
0
        /// <summary>
        /// Constructor that accepts the common parameters around a set of sub grids the requester will be asked to process
        /// and initializes the requester state ready to start processing individual sub grid requests.
        /// </summary>
        public void Initialize(ISubGridsRequestArgument subGridsRequestArgument,
                               ISiteModel siteModel,
                               GridDataType gridDataType,
                               IStorageProxy storageProxy,
                               ICombinedFilter filter,
                               bool hasOverrideSpatialCellRestriction,
                               BoundingIntegerExtent2D overrideSpatialCellRestriction,
                               int maxNumberOfPassesToReturn,
                               AreaControlSet areaControlSet,
                               IFilteredValuePopulationControl populationControl,
                               ISubGridTreeBitMask pdExistenceMap,
                               ITRexSpatialMemoryCache subGridCache,
                               ITRexSpatialMemoryCacheContext[] subGridCacheContexts,
                               ISurveyedSurfaces filteredSurveyedSurfaces,
                               ISurfaceElevationPatchRequest surfaceElevationPatchRequest,
                               IOverrideParameters overrides,
                               ILiftParameters liftParams)
        {
            _siteModel    = siteModel;
            _gridDataType = gridDataType;
            _filter       = filter;

            _hasOverrideSpatialCellRestriction = hasOverrideSpatialCellRestriction;
            _overrideSpatialCellRestriction    = overrideSpatialCellRestriction;

            _retriever = DIContext.Obtain <ISubGridRetrieverFactory>().Instance(subGridsRequestArgument,
                                                                                siteModel,
                                                                                gridDataType,
                                                                                storageProxy,
                                                                                filter,
                                                                                _filterAnnex,
                                                                                hasOverrideSpatialCellRestriction,
                                                                                overrideSpatialCellRestriction,
                                                                                maxNumberOfPassesToReturn,
                                                                                areaControlSet,
                                                                                populationControl,
                                                                                pdExistenceMap,
                                                                                subGridCacheContexts,
                                                                                overrides,
                                                                                liftParams);

            _returnEarliestFilteredCellPass = _filter.AttributeFilter.ReturnEarliestFilteredCellPass;
            _processingMap = new SubGridTreeBitmapSubGridBits(SubGridBitsCreationOptions.Unfilled);

            _surfaceElevationPatchRequest = surfaceElevationPatchRequest;

            _subGridCache         = subGridCache;
            _subGridCacheContexts = subGridCacheContexts;

            _surveyedSurfacePatchType = _filter.AttributeFilter.ReturnEarliestFilteredCellPass ? SurveyedSurfacePatchType.EarliestSingleElevation : SurveyedSurfacePatchType.LatestSingleElevation;

            _filteredSurveyedSurfaces = filteredSurveyedSurfaces;
            _filteredSurveyedSurfaces?.SortChronologically(_surveyedSurfacePatchType == SurveyedSurfacePatchType.LatestSingleElevation);
            _filteredSurveyedSurfacesAsGuidArray = _filteredSurveyedSurfaces?.Select(x => x.ID).ToArray() ?? new Guid[0];

            var elevRangeDesignFilter = _filter.AttributeFilter.ElevationRangeDesign;

            if (elevRangeDesignFilter.DesignID != Guid.Empty)
            {
                var design = _siteModel.Designs.Locate(elevRangeDesignFilter.DesignID);
                if (design == null)
                {
                    _log.LogError($"ElevationRangeDesign {elevRangeDesignFilter.DesignID} is unknown in project {siteModel.ID}");
                }
                else
                {
                    _elevationRangeDesign = new DesignWrapper(elevRangeDesignFilter, design);
                }
            }

            if (_filter.SpatialFilter.IsDesignMask)
            {
                _surfaceDesignMaskDesign = _siteModel.Designs.Locate(_filter.SpatialFilter.SurfaceDesignMaskDesignUid);
            }

            _filter.AttributeFilter.SiteModel = _siteModel;
        }