Exemple #1
0
        public void Test_GenericSubGridTree_NullCellValue_long()
        {
            var tree1 = new GenericSubGridTree_Long(SubGridTreeConsts.SubGridTreeLevels, 1.0);

            Assert.Equal(0, tree1.NullCellValue);

            var tree2 = new GenericSubGridTree <long, GenericLeafSubGrid <long> >(SubGridTreeConsts.SubGridTreeLevels, 1.0);

            Assert.Equal(0, tree2.NullCellValue);
        }
Exemple #2
0
        public void Test_GenericSubGridTree_NullCellValue_Double()
        {
            var tree1 = new GenericSubGridTree_Float(SubGridTreeConsts.SubGridTreeLevels, 1.0);

            Assert.Equal(0, tree1.NullCellValue);

            var tree2 = new GenericSubGridTree <double, GenericLeafSubGrid <double> >(SubGridTreeConsts.SubGridTreeLevels, 1.0);

            Assert.Equal(0, tree2.NullCellValue);
        }
Exemple #3
0
        public void Test_GenericSubGridTree_NullCellValue_Int()
        {
            var tree1 = new GenericSubGridTree_Int(SubGridTreeConsts.SubGridTreeLevels, 1.0);

            Assert.Equal(0, tree1.NullCellValue);

            var tree2 = new GenericSubGridTree <int, GenericLeafSubGrid <int> >(SubGridTreeConsts.SubGridTreeLevels, 1.0);

            Assert.Equal(0, tree2.NullCellValue);
        }
Exemple #4
0
        private GenericSubGridTree <float, GenericLeafSubGrid_Float> ConstructSingleSubGridElevationSubGridTreeAtOrigin(float elevation)
        {
            var tree = new GenericSubGridTree <float, GenericLeafSubGrid_Float>();

            var subGrid = tree.ConstructPathToCell(SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.DefaultIndexOriginOffset,
                                                   SubGridPathConstructionType.CreateLeaf) as GenericLeafSubGrid <float>;

            DataSmoothingTestUtilities.ConstructElevationSubGrid(subGrid, elevation);

            return(tree);
        }
Exemple #5
0
        public static GenericSubGridTree <float, GenericLeafSubGrid <float> > ConstructSingleSubGridElevationSubGridTreeAtOrigin(float elevation)
        {
            var tree = new GenericSubGridTree <float, GenericLeafSubGrid <float> >();

            var subGrid = tree.ConstructPathToCell(SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.DefaultIndexOriginOffset,
                                                   SubGridPathConstructionType.CreateLeaf) as GenericLeafSubGrid <float>;

            ConstructElevationSubGrid(subGrid, elevation);

            return(tree);
        }
Exemple #6
0
        public GenericSubGridTree <TV, GenericLeafSubGrid <TV> > Smooth(GenericSubGridTree <TV, GenericLeafSubGrid <TV> > source)
        {
            var result    = new GenericSubGridTree <TV, GenericLeafSubGrid <TV> >(source.NumLevels, source.CellSize);
            var convolver = _convolverFactory(_accumulator, _contextSize);

            source.ScanAllSubGrids(leaf =>
            {
                var smoothedLeaf = result.ConstructPathToCell(leaf.OriginX, leaf.OriginY, SubGridPathConstructionType.CreateLeaf) as GenericLeafSubGrid <float>;
                _convolutionTools.Convolve(leaf as GenericLeafSubGrid <TV>, smoothedLeaf as GenericLeafSubGrid <TV>, convolver);
                return(true);
            });

            return(result);
        }
Exemple #7
0
        public void Test_GenericSubGridTree_NullCellValue_Bool()
        {
            var tree1 = new GenericSubGridTree_Bool(SubGridTreeConsts.SubGridTreeLevels, 1.0);

            Assert.False(tree1.NullCellValue);

            var tree2 = new GenericSubGridTree <long, GenericLeafSubGrid <long> > (SubGridTreeConsts.SubGridTreeLevels, 1.0);

            Assert.Equal(0, tree2.NullCellValue);

            var tree3 = new GenericSubGridTree <object, GenericLeafSubGrid <object> >(SubGridTreeConsts.SubGridTreeLevels, 1.0);

            Assert.Null(tree3.NullCellValue);
        }
Exemple #8
0
        /// <summary>
        /// Executor that implements creation of the TIN surface
        /// </summary>
        public async Task <bool> ExecuteAsync()
        {
            Log.LogInformation($"Performing Execute for DataModel:{_dataModelId}");

            try
            {
                var requestDescriptor = Guid.NewGuid();
                var siteModel         = DIContext.Obtain <ISiteModels>().GetSiteModel(_dataModelId);

                if (siteModel == null)
                {
                    Log.LogError($"Failed to obtain site model for {_dataModelId}");
                    return(false);
                }

                var datastore = new GenericSubGridTree <float, GenericLeafSubGrid <float> >(siteModel.Grid.NumLevels, siteModel.CellSize);

                // Provide the processor with a customised request analyser configured to return a set of sub grids. These sub grids
                // are the feed stock for the generated TIN surface
                using (var processor = DIContext.Obtain <IPipelineProcessorFactory>().NewInstanceNoBuild <SubGridsRequestArgument>(
                           requestDescriptor,
                           _dataModelId,
                           GridDataFromModeConverter.Convert(DisplayMode.Height),
                           SurfaceSubGridsResponse,
                           _filters,
                           new DesignOffset(),
                           DIContext.Obtain <Func <PipelineProcessorTaskStyle, ITRexTask> >()(PipelineProcessorTaskStyle.SurfaceExport),
                           DIContext.Obtain <Func <PipelineProcessorPipelineStyle, ISubGridPipelineBase> >()(PipelineProcessorPipelineStyle.DefaultProgressive),
                           DIContext.Obtain <IRequestAnalyser>(),
                           Rendering.Utilities.DisplayModeRequireSurveyedSurfaceInformation(DisplayMode.Height) && Rendering.Utilities.FilterRequireSurveyedSurfaceInformation(_filters),
                           false, //Rendering.Utilities.RequestRequiresAccessToDesignFileExistenceMap(DisplayMode.Height),
                           BoundingIntegerExtent2D.Inverted(),
                           _liftParams))
                {
                    // Set the surface TRexTask parameters for progressive processing
                    processor.Task.TRexNodeID = RequestingTRexNodeID;

                    if (!processor.Build())
                    {
                        Log.LogError($"Failed to build pipeline processor for request to model {_dataModelId}");
                        return(false);
                    }

                    processor.Process();

                    if (SurfaceSubGridsResponse.ResultStatus != RequestErrorStatus.OK)
                    {
                        Log.LogError($"Sub grids response status not OK: {SurfaceSubGridsResponse.ResultStatus}");
                        return(false);
                    }

                    // Create the TIN decimator and populate it with the retrieved sub grids
                    foreach (var subGrid in ((SurfaceTask)processor.Task).SurfaceSubgrids)
                    {
                        if (!(datastore.ConstructPathToCell(subGrid.OriginX, subGrid.OriginY, SubGridPathConstructionType.CreatePathToLeaf) is INodeSubGrid newGridNode))
                        {
                            Log.LogError($"Result from data store ConstructPathToCell({subGrid.OriginX}, {subGrid.OriginY}) was null. Aborting...");
                            return(false);
                        }

                        subGrid.Owner = datastore;
                        newGridNode.GetSubGridCellIndex(subGrid.OriginX, subGrid.OriginY, out var subGridIndexX, out var subGridIndexY);
                        newGridNode.SetSubGrid(subGridIndexX, subGridIndexY, subGrid);
                    }
                }

                // Obtain the surface export data smoother and apply it to the tree of queried data before passing it to the decimation engine
                var dataSmoother = DIContext.Obtain <Func <DataSmootherOperation, IDataSmoother> >()(DataSmootherOperation.SurfaceExport) as ITreeDataSmoother <float>;

                datastore = dataSmoother?.Smooth(datastore) ?? datastore;

                var extents = DataStoreExtents(datastore);

                // Make sure we don't export too large an area due to data way outside project extents
                if (extents.Area > Common.Consts.MaxExportAreaM2)
                {
                    // First try and use project boundary extents as our data boundary
                    var canExport = siteModel.SiteModelExtent.Area > 0 && siteModel.SiteModelExtent.Area < Common.Consts.MaxExportAreaM2;
                    if (canExport)
                    {
                        // still use min max height extents
                        Log.LogInformation($"Invalid Plan Extent. Data area too large {extents.Area}. Switching to project extents");
                        extents.MinX = siteModel.SiteModelExtent.MinX;
                        extents.MinY = siteModel.SiteModelExtent.MinY;
                        extents.MaxX = siteModel.SiteModelExtent.MaxX;
                        extents.MaxY = siteModel.SiteModelExtent.MaxY;
                    }
                    else
                    {
                        Log.LogError($"Invalid Plan Extent. Data area too large {extents.Area}.");
                        return(false);
                    }
                }

                // Decimate the elevations into a grid
                var decimator = new GridToTINDecimator(datastore)
                {
                    Tolerance = _tolerance
                };
                decimator.SetDecimationExtents(extents);

                if (!decimator.BuildMesh())
                {
                    Log.LogError($"Decimator returned false with error code: {decimator.BuildMeshFaultCode}");
                    return(false);
                }

                // A decimated TIN has been successfully constructed...  Return it!
                SurfaceSubGridsResponse.TIN = decimator.GetTIN();
            }
            catch (Exception e)
            {
                Log.LogError(e, "ExecutePipeline raised Exception:");
                return(false);
            }

            return(true);
        }
Exemple #9
0
        public void Test_GenericSubGridTree_NullCellValue_Object()
        {
            var tree3 = new GenericSubGridTree <object, GenericLeafSubGrid <object> >(SubGridTreeConsts.SubGridTreeLevels, 1.0);

            Assert.Null(tree3.NullCellValue);
        }
Exemple #10
0
        public GridToTINDecimator(GenericSubGridTree <float, GenericLeafSubGrid <float> > dataStore)
        {
            DataStore = dataStore ?? throw new TRexTINException("No data store provided to decimator");

            CreateDecimationState();
        }