Пример #1
0
        public static GridField getGrid(GridInfo gridInfo, bool setGridBorders, KrigingConfig krigingConfig,
                                        Func <double, double> semivarianseDelegate, GridPoint[] unregularPoints,
                                        List <GridPolygon> sourceContours, List <GridPolygonArea> blankContours)
        {
            //TODO refactor blanks

            if (setGridBorders)
            {
                var maxX = Double.MinValue;
                var minX = Double.MaxValue;
                var maxY = Double.MinValue;
                var minY = Double.MaxValue;

                //TODO use Extent here
                Action <GridPoint[]> calcMinMax = array => {
                    if (array != null &&
                        array.Any())
                    {
                        foreach (var p in array)
                        {
                            if (p.X > maxX)
                            {
                                maxX = p.X;
                            }
                            if (p.X < minX)
                            {
                                minX = p.X;
                            }
                            if (p.Y > maxY)
                            {
                                maxY = p.Y;
                            }
                            if (p.Y < minY)
                            {
                                minY = p.Y;
                            }
                        }
                    }
                };

                //находим максимальные габариты контуров
                Action <GridPolygon> calcMinMaxContours = polygon => {
                    if (polygon != null)
                    {
                        if (polygon.Extent.MaxX > maxX)
                        {
                            maxX = polygon.Extent.MaxX;
                        }
                        if (polygon.Extent.MinX < minX)
                        {
                            minX = polygon.Extent.MinX;
                        }
                        if (polygon.Extent.MaxY > maxY)
                        {
                            maxY = polygon.Extent.MaxY;
                        }
                        if (polygon.Extent.MinY < minY)
                        {
                            minY = polygon.Extent.MinY;
                        }
                    }
                };

                calcMinMax(unregularPoints);

                if (sourceContours != null)
                {
                    sourceContours.ForEach(calcMinMaxContours);
                }

                if (blankContours != null)
                {
                    blankContours.ForEach(calcMinMaxContours);
                }

                gridInfo.Extent = new Extent(minX, maxX, minY, maxY);
            }

            return(KrigingInterpolator.doInterpolate(gridInfo, krigingConfig, semivarianseDelegate, unregularPoints, sourceContours, blankContours));
        }
Пример #2
0
        /// <summary>
        /// Выполнить интерполяцию Кригинга
        /// </summary>
        /// <param name="gridInfo">Информация о регулярной сетке</param>
        /// <param name="config">Конфигурация интерполятора</param>
        /// <param name="semivarianseDelegate">Вариограмма</param>
        /// <param name="irregularPoints">Массив исходных точек для интерполяции</param>
        /// <param name="sourcePolygons">Дополнительные массивы точек для интерполяции, взятые с контуров</param>
        /// <param name="blankPolygons">Контуры бланкования, в которых интерполяция не производится</param>
        /// <returns>Регулярную сетку значений</returns>
        public static GridField doInterpolate(GridInfo gridInfo, KrigingConfig config, Func<double, double> semivarianseDelegate,
            GridPoint[] irregularPoints, List<GridPolygon> sourcePolygons = null, List<GridPolygonArea> blankPolygons = null)
        {

            if (irregularPoints == null || irregularPoints.Length == 0 || config == null)
            {
                return null;
            }
            if (gridInfo == null || gridInfo.Extent.Width < gridInfo.Step || gridInfo.Extent.Height < gridInfo.Step)
            {
                return null;
            }

            /*if (sourcePolygons == null || sourcePolygons.Count == 0) {
                sourcePolygons = getSourcePoligon(gridInfo);
            }*/

            //            if (blankPolygons == null || blankPolygons.Count == 0) {
            //                blankPolygons = getBlankPoligon(gridInfo);
            //            }

            var allPoints = irregularPoints;
            if (sourcePolygons != null && sourcePolygons.Any())
            {
                var allPointsList = irregularPoints.ToList();
                foreach (var gridPolygon in sourcePolygons)
                {
                    if (gridPolygon.Line.Points != null && gridPolygon.Line.Points.Any())
                    {
                        allPointsList.AddRange(gridPolygon.Line.Points);
                    }
                }
                allPoints = allPointsList.ToArray();
            }

            var grid = new GridField(gridInfo);

            //хранилище для значений X на основании которых будем затем восстанавливать сигнал бикубическим сплайном
            var xBag = new ConcurrentBag<KeyValuePair<double, int>>();
            //хранилище для значений Y на основании которых будем затем восстанавливать сигнал бикубическим сплайном
            var yBag = new ConcurrentBag<KeyValuePair<double, int>>();


            Parallel.For(0, Environment.ProcessorCount,
                workerId => calculate(config, grid, semivarianseDelegate, workerId, allPoints, xBag, yBag, 0));


            try
            {
                alglib.spline2dinterpolant interpolant = getInterpolant(grid, xBag, yBag);
                if (blankPolygons != null && blankPolygons.Any())
                {
                    grid.fillNotCalculatedCell(blankPolygons, MASK_CELL_VALUE);
                }

                Parallel.For(0, Environment.ProcessorCount,
                    workerId => restoreGridCells(grid, interpolant, workerId));

            }
            catch (Exception e)
            {

                var t = e;
            }






            grid.fillDataNotNullable(config.NotDefinedValue);

            return grid;
        }
Пример #3
0
 public GridInfo(GridInfo other)
 {
     Extent = new Extent(other.Extent);
     Step   = other.Step;
 }
Пример #4
0
 public GridField(GridInfo info)
 {
     _info               = info;
     GridData            = new double?[info.NumberColumns, info.NumberRows];
     GridDataNotNullable = new double[info.NumberColumns, info.NumberRows];
 }