Exemple #1
0
        /// <summary>
        /// Add a new design to a site model
        /// </summary>
        public IDesign Add(Guid siteModelId, DesignDescriptor designDescriptor, BoundingWorldExtent3D extents, ISubGridTreeBitMask existenceMap)
        {
            if (extents == null)
            {
                throw new ArgumentNullException(nameof(extents));
            }

            if (existenceMap == null)
            {
                throw new ArgumentNullException(nameof(existenceMap));
            }

            // Add the design to the designs list
            var designs = Load(siteModelId);
            var result  = designs.AddDesignDetails(designDescriptor.DesignID, designDescriptor, extents);

            // Store the existence map into the cache
            using var stream = existenceMap.ToStream();
            var fileName = BaseExistenceMapRequest.CacheKeyString(ExistenceMaps.Interfaces.Consts.EXISTENCE_MAP_DESIGN_DESCRIPTOR, designDescriptor.DesignID);

            if (_writeStorageProxy.WriteStreamToPersistentStore(siteModelId, fileName,
                                                                FileSystemStreamType.DesignTopologyExistenceMap, stream, existenceMap) != FileSystemErrorStatus.OK)
            {
                _log.LogError("Failed to write existence map to persistent store for key {fileName}");
                return(null);
            }

            // Store performs Commit() operation
            Store(siteModelId, designs);

            return(result);
        }
Exemple #2
0
        /*
         *  /// <summary>
         *  /// Add a new design to a sitemodel
         *  /// </summary>
         *  /// <param name="SiteModelID"></param>
         *  /// <param name="designDescriptor"></param>
         *  public void Add(long SiteModelID, DesignDescriptor designDescriptor, BoundingWorldExtent3D extents)
         *  {
         *      mutableNonSpatialCache.Invoke(CacheKey(SiteModelID),
         *                                    new AddDesignProcessor(),
         *                                    new Design(SiteModelID, designDescriptor, extents));
         *  }
         */

        /// <summary>
        /// Add a new design to a sitemodel
        /// </summary>
        /// <param name="SiteModelID"></param>
        /// <param name="designDescriptor"></param>
        /// <param name="extents"></param>
        /// <param name="DesignID"></param>
        public void AddDirect(Guid SiteModelID, DesignDescriptor designDescriptor, BoundingWorldExtent3D extents, out Guid DesignID)
        {
            // This should be done under a lock on the cache key. For now, we will live with the race condition...

            INonSpatialAffinityKey cacheKey = VSS.TRex.Designs.Storage.Designs.CacheKey(SiteModelID);

            DesignID = Guid.NewGuid();

            // Get the designs, creating it if it does not exist
            IDesigns designList = new TRex.Designs.Storage.Designs();

            try
            {
                designList.FromBytes(MutableNonSpatialCache.Get(cacheKey));
            }
            catch (KeyNotFoundException)
            {
                // Swallow exception, the list will be empty
            }

            // Add the new design, generating a random ID from a GUID
            designList.AddDesignDetails(DesignID, designDescriptor, extents);

            // Put the list back into the cache with the new entry
            MutableNonSpatialCache.Put(cacheKey, designList.ToBytes());
        }
Exemple #3
0
        public void Shrink()
        {
            var bound = new BoundingWorldExtent3D(0, 0, 100, 100, 0, 10);

            bound.Shrink(1, 1);

            bound.MinX.Should().Be(1);
            bound.MinY.Should().Be(1);
            bound.MaxX.Should().Be(99);
            bound.MaxY.Should().Be(99);
            bound.MinZ.Should().Be(0);
            bound.MaxZ.Should().Be(10);

            bound.Shrink(1);
            bound.MinZ.Should().Be(1);
            bound.MaxZ.Should().Be(9);

            bound.Shrink(-1, -1);

            bound.MinX.Should().Be(0);
            bound.MinY.Should().Be(0);
            bound.MaxX.Should().Be(100);
            bound.MaxY.Should().Be(100);
            bound.MinZ.Should().Be(1);
            bound.MaxZ.Should().Be(9);

            bound.Shrink(-1);
            bound.MinZ.Should().Be(0);
            bound.MaxZ.Should().Be(10);
        }
Exemple #4
0
        public void Set()
        {
            var bound = new BoundingWorldExtent3D();

            bound.Set(0, 1, 100, 102);
            bound.Should().BeEquivalentTo(new BoundingWorldExtent3D(0, 1, 100, 102, 0, 0));
        }
Exemple #5
0
        public void Offset()
        {
            var bound = new BoundingWorldExtent3D(0, 0, 100, 100, 0, 0);

            bound.Offset(1, 1);

            bound.MinX.Should().Be(1);
            bound.MinY.Should().Be(1);
            bound.MaxX.Should().Be(101);
            bound.MaxY.Should().Be(101);
            bound.MinZ.Should().Be(0);
            bound.MaxZ.Should().Be(0);

            bound.Offset(1);
            bound.MinZ.Should().Be(1);
            bound.MaxZ.Should().Be(1);

            bound.Offset(-1, -1);

            bound.MinX.Should().Be(0);
            bound.MinY.Should().Be(0);
            bound.MaxX.Should().Be(100);
            bound.MaxY.Should().Be(100);
            bound.MinZ.Should().Be(1);
            bound.MaxZ.Should().Be(1);

            bound.Offset(-1);
            bound.MinZ.Should().Be(0);
            bound.MaxZ.Should().Be(0);
        }
Exemple #6
0
        public void Intersect_BoundingExtent(double minX, double minY, double maxX, double maxY, double r_minX, double r_minY, double r_maxX, double r_maxY, bool valid)
        {
            BoundingWorldExtent3D bound = new BoundingWorldExtent3D(0, 0, 100, 100);

            void Check()
            {
                if (valid)
                {
                    bound.MinX.Should().Be(r_minX);
                    bound.MinY.Should().Be(r_minY);
                    bound.MaxX.Should().Be(r_maxX);
                    bound.MaxY.Should().Be(r_maxY);
                }
            }

            // Check variant #1
            var bound2 = new BoundingWorldExtent3D(minX, minY, maxX, maxY);

            bound.Intersect(bound2);
            bound.IsValidPlanExtent.Should().Be(valid);

            Check();

            // Check variant #2
            bound = new BoundingWorldExtent3D(0, 0, 100, 100);

            bound.Intersect(minX, minY, maxX, maxY);
            bound.IsValidPlanExtent.Should().Be(valid);

            Check();
        }
Exemple #7
0
        public void Creation()
        {
            var bound = new BoundingWorldExtent3D();

            bound.IsValidHeightExtent.Should().Be(true);
            bound.IsValidPlanExtent.Should().Be(true);
        }
Exemple #8
0
 /// <summary>
 /// Applies spatial filter restrictions to the extents required to request data for.
 /// </summary>
 public void ApplyFilterAndSubsetBoundariesToExtents(BoundingWorldExtent3D extents)
 {
     foreach (var filter in Filters)
     {
         filter?.SpatialFilter?.CalculateIntersectionWithExtents(extents);
     }
 }
Exemple #9
0
        public void ScalePlan()
        {
            var bound = new BoundingWorldExtent3D(1, 1, 2, 2, 0, 0);

            bound.ScalePlan(2.0);
            bound.Should().BeEquivalentTo(new BoundingWorldExtent3D(0.5, 0.5, 2.5, 2.5, 0, 0));
        }
Exemple #10
0
        public override void InternalFromBinary(IBinaryRawReader reader)
        {
            base.InternalFromBinary(reader);

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

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

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

                AsAtDate = DateTime.SpecifyKind(new DateTime(reader.ReadLong()), DateTimeKind.Utc);

                if (reader.ReadBoolean())
                {
                    (Extents = new BoundingWorldExtent3D()).FromBinary(reader);
                }

                if (reader.ReadBoolean())
                {
                    (ExistenceMap = new SubGridTreeSubGridExistenceBitMask()).FromBytes(reader.ReadByteArray());
                }
            }
        }
Exemple #11
0
        public void ProcessElevationInformationForSubGrid_DefinedBaseWithNullTopHeights()
        {
            const double cellSize = SubGridTreeConsts.DefaultCellSize;
            const double cellArea = cellSize * cellSize;

            var state       = new ProgressiveVolumeAggregationState(cellSize);
            var baseHeights = NullHeights();
            var topHeights  = NullHeights();

            TRex.SubGridTrees.Core.Utilities.SubGridUtilities.SubGridDimensionalIterator((x, y) => baseHeights[x, y] = 0.0f);

            state.ProcessElevationInformationForSubGrid(SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.DefaultIndexOriginOffset,
                                                        baseHeights, topHeights);

            state.Finalise();

            state.CutFillVolume.CutVolume.Should().Be(0.0);
            state.CutFillVolume.FillVolume.Should().Be(0.0);

            state.CoverageArea.Should().Be(0.0 * cellArea);
            state.CutArea.Should().Be(0.0 * cellArea);
            state.FillArea.Should().Be(0.0 * cellArea);
            state.TotalArea.Should().Be(SubGridTreeConsts.CellsPerSubGrid * cellArea);
            state.BoundingExtents.Should().BeEquivalentTo(BoundingWorldExtent3D.Inverted());
        }
Exemple #12
0
        public void SiteModelStatisticsExecutor_EmptySiteModel()
        {
            var siteModel = DITAGFileAndSubGridRequestsWithIgniteFixture.NewEmptyModel();

            var request = new ProjectStatisticsTRexRequest(siteModel.ID, null);

            request.Validate();

            var executor = RequestExecutorContainer
                           .Build <SiteModelStatisticsExecutor>(DIContext.Obtain <IConfigurationStore>(),
                                                                DIContext.Obtain <ILoggerFactory>(),
                                                                DIContext.Obtain <IServiceExceptionHandler>());
            var result = executor.Process(request) as ProjectStatisticsResult;

            result.Code.Should().Be(ContractExecutionStatesEnum.ExecutedSuccessfully);
            result.cellSize.Should().Be(SubGridTreeConsts.DefaultCellSize);
            result.startTime.Should().Be(Consts.MAX_DATETIME_AS_UTC);
            result.endTime.Should().Be(Consts.MIN_DATETIME_AS_UTC);
            result.extents.MinX.Should().Be(BoundingWorldExtent3D.Inverted().MinX);
            result.extents.MaxX.Should().Be(BoundingWorldExtent3D.Inverted().MaxX);
            result.extents.MinY.Should().Be(BoundingWorldExtent3D.Inverted().MinY);
            result.extents.MaxY.Should().Be(BoundingWorldExtent3D.Inverted().MaxY);
            result.extents.MinZ.Should().Be(BoundingWorldExtent3D.Inverted().MinZ);
            result.extents.MaxZ.Should().Be(BoundingWorldExtent3D.Inverted().MaxZ);
            result.indexOriginOffset.Should().Be((int)SubGridTreeConsts.DefaultIndexOriginOffset);

            var expectedJson = "{\"startTime\":\"9999-12-31T23:59:59.9999999\",\"endTime\":\"0001-01-01T00:00:00\",\"cellSize\":0.34,\"indexOriginOffset\":536870912,\"extents\":{\"maxX\":-1E+100,\"maxY\":-1E+100,\"maxZ\":-1E+100,\"minX\":1E+100,\"minY\":1E+100,\"minZ\":1E+100},\"Code\":0,\"Message\":\"success\"}";
            var json         = JsonConvert.SerializeObject(result);

            json.Should().Be(expectedJson);
        }
Exemple #13
0
        /// <summary>
        /// Serializes content from the writer
        /// </summary>
        public override void InternalFromBinary(IBinaryRawReader reader)
        {
            base.InternalFromBinary(reader);

            var messageVersion = VersionSerializationHelper.CheckVersionsByte(reader, VERSION_NUMBERS);

            if (messageVersion >= 1)
            {
                Mode = (DisplayMode)reader.ReadInt();

                if (reader.ReadBoolean())
                {
                    Palette = TileRenderRequestArgumentPaletteFactory.GetPalette(Mode);
                    Palette.FromBinary(reader);
                }

                if (reader.ReadBoolean())
                {
                    Extents = new BoundingWorldExtent3D();
                    Extents.FromBinary(reader);
                }

                CoordsAreGrid = reader.ReadBoolean();
                PixelsX       = (ushort)reader.ReadInt();
                PixelsY       = (ushort)reader.ReadInt();
            }

            if (messageVersion >= 2)
            {
                VolumeType = (VolumeComputationType)reader.ReadByte();
            }
        }
Exemple #14
0
        /// <summary>
        /// Computes a tight bounding extent around the elevation values stored in the sub grid tree
        /// </summary>
        private static BoundingWorldExtent3D DataStoreExtents(ISubGridTree dataStore)
        {
            var computedGridExtent = BoundingWorldExtent3D.Inverted();

            dataStore.ScanAllSubGrids(subGrid =>
            {
                var items = ((GenericLeafSubGrid <float>)subGrid).Items;
                SubGridUtilities.SubGridDimensionalIterator((x, y) =>
                {
                    var elev = items[x, y];
                    if (elev != Common.Consts.NullHeight)
                    {
                        computedGridExtent.Include(subGrid.OriginX + x, subGrid.OriginY + y, elev);
                    }
                });

                return(true);
            });

            if (computedGridExtent.IsValidPlanExtent)
            {
                computedGridExtent.Offset(-SubGridTreeConsts.DefaultIndexOriginOffset, -SubGridTreeConsts.DefaultIndexOriginOffset);
            }

            // Convert the grid rectangle to a world rectangle, padding out the 3D bound by a small margin to avoid edge effects in calculations
            var computedWorldExtent = new BoundingWorldExtent3D
                                          ((computedGridExtent.MinX - 1.01) * dataStore.CellSize,
                                          (computedGridExtent.MinY - 1.01) * dataStore.CellSize,
                                          (computedGridExtent.MaxX + 1.01) * dataStore.CellSize,
                                          (computedGridExtent.MaxY + 1.01) * dataStore.CellSize,
                                          computedGridExtent.MinZ - 0.01, computedGridExtent.MaxZ + 0.01);

            return(computedWorldExtent);
        }
Exemple #15
0
 public ISurveyedSurface NewInstance(Guid iD,
                                     DesignDescriptor designDescriptor,
                                     DateTime asAtDate,
                                     BoundingWorldExtent3D extents)
 {
     return(new SurveyedSurface(iD, designDescriptor, asAtDate, extents));
 }
Exemple #16
0
        /// <summary>
        /// Performs execution business logic for this executor
        /// </summary>
        public IDesign Execute(Guid projectUid, DesignDescriptor designDescriptor, BoundingWorldExtent3D extents, ISubGridTreeBitMask existenceMap)
        {
            try
            {
                var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(projectUid, false);

                if (siteModel == null)
                {
                    _log.LogError($"Site model {projectUid} not found");
                    return(null);
                }

                var design = DIContext.Obtain <IDesignManager>().Add(projectUid, designDescriptor, extents, existenceMap);

                if (design == null)
                {
                    _log.LogError($"Failed to add design file {designDescriptor} to project {projectUid}");
                }

                return(design);
            }
            catch (Exception e)
            {
                _log.LogError(e, "Execute: Exception: ");
                return(null);
            }
        }
Exemple #17
0
        public void Size_XYZ()
        {
            var bound = new BoundingWorldExtent3D(0, 1, 100, 100, 10, 20);

            bound.SizeX.Should().Be(100);
            bound.SizeY.Should().Be(99);
            bound.SizeZ.Should().Be(10);
        }
Exemple #18
0
        public void Creation_FromSource()
        {
            var bound = new BoundingWorldExtent3D(1, 1, 100, 100);

            var bound2 = new BoundingWorldExtent3D(bound);

            bound2.Should().BeEquivalentTo(bound);
        }
Exemple #19
0
 /// <summary>
 /// Constructor accepting full design state
 /// </summary>
 public Design(Guid iD,
               DesignDescriptor designDescriptor,
               BoundingWorldExtent3D extents)
 {
     ID = iD;
     DesignDescriptor = designDescriptor;
     _extents         = extents;
 }
Exemple #20
0
        public void Center_XYZ()
        {
            var bound = new BoundingWorldExtent3D(0, 1, 100, 100, 10, 20);

            bound.CenterX.Should().Be(50);
            bound.CenterY.Should().Be(50.5);
            bound.CenterZ.Should().Be(15);
        }
Exemple #21
0
        public void SetDecimationExtents(BoundingWorldExtent3D value)
        {
            DecimationExtents = value;

            //Debug.Assert(DataStore != null, "Cannot set decimation extents without a data store");

            // Convert the world coordinate range into the grid cell range that it covers
            DataStore.CalculateRegionGridCoverage(value, out GridCalcExtents);
        }
Exemple #22
0
        public void GetLimits(BoundingWorldExtent3D boundingExtent)
        {
            boundingExtent.SetInverted();

            foreach (var vertex in this)
            {
                vertex.AdjustLimits(boundingExtent);
            }
        }
Exemple #23
0
        public void Center_LargestPlanDimension()
        {
            var bound = new BoundingWorldExtent3D();

            bound.LargestPlanDimension.Should().Be(0);

            bound = new BoundingWorldExtent3D(0, 1, 100, 100);
            bound.LargestPlanDimension.Should().Be(100);
        }
Exemple #24
0
        public void Include_2D()
        {
            var bound = new BoundingWorldExtent3D(0, 0, 0, 0, 0, 0);

            bound.Include(10, 11);
            bound.Should().BeEquivalentTo(new BoundingWorldExtent3D(0, 0, 10, 11, 0, 0));

            bound.Include(-10, -11);
            bound.Should().BeEquivalentTo(new BoundingWorldExtent3D(-10, -11, 10, 11, 0, 0));
        }
Exemple #25
0
 private void CheckResponseContainsNullValues(SimpleVolumesResponse response)
 {
     response.Should().NotBeNull();
     response.Cut.Should().BeNull();
     response.Fill.Should().BeNull();
     response.CutArea.Should().BeNull();
     response.FillArea.Should().BeNull();
     response.TotalCoverageArea.Should().BeNull();
     response.BoundingExtentGrid.Should().BeEquivalentTo(BoundingWorldExtent3D.Null());
 }
Exemple #26
0
        public void Assign()
        {
            var bound = new BoundingWorldExtent3D(1, 1, 100, 100);

            var bound2 = new BoundingWorldExtent3D();

            bound2.Assign(bound);

            bound2.Should().BeEquivalentTo(bound);
        }
Exemple #27
0
 /// <summary>
 /// Constructor accepting full surveyed surface state
 /// </summary>
 /// <param name="iD">The unique identifier for the surveyed surface in this site model</param>
 /// <param name="designDescriptor"></param>
 /// <param name="asAtDate"></param>
 /// <param name="extents"></param>
 public SurveyedSurface(Guid iD,
                        DesignDescriptor designDescriptor,
                        DateTime asAtDate,
                        BoundingWorldExtent3D extents)
 {
     ID = iD;
     DesignDescriptor = designDescriptor;
     AsAtDate         = asAtDate;
     _extents         = extents;
 }
Exemple #28
0
 /// <summary>
 /// Converts BoundingWorldExtent3D data into BoundingBox3DGrid data.
 /// </summary>
 public static BoundingBox3DGrid ConvertExtents(BoundingWorldExtent3D extents)
 {
     return(new BoundingBox3DGrid(
                extents.MinX,
                extents.MinY,
                extents.MinZ,
                extents.MaxX,
                extents.MaxY,
                extents.MaxZ));
 }
Exemple #29
0
        public void MaximalPlanCoverage()
        {
            var bound = new BoundingWorldExtent3D();

            bound.IsMaximalPlanConverage.Should().BeFalse();

            bound.SetMaximalCoverage();

            bound.IsMaximalPlanConverage.Should().BeTrue();
        }
Exemple #30
0
        public void Test_SubGridTree_GetCellExtents()
        {
            ISubGridTree tree = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());

            // Get a cell at the origin of the world coordinate system and test its extents given a 1m cell size
            BoundingWorldExtent3D extent = tree.GetCellExtents(tree.IndexOriginOffset, tree.IndexOriginOffset);

            Assert.True(Math.Abs(extent.MinX) < 0.001 && Math.Abs(extent.MinY) < 0.001 &&
                        (Math.Abs(extent.MinX) - 1.0) < 0.001 && (Math.Abs(extent.MinY) - 1.0) < 0.001,
                        "Cell extents for (IndexOriginOffset, IndexOriginOffset) <> (0.0, 0.0 -> 1.0, 1.0) as expected");
        }