示例#1
0
        public bool checkCellSize()
        {
            bool   cS   = true;
            IPnt   zPnt = zRs.RasterInfo.CellSize;
            IPnt   vPnt = vRs.RasterInfo.CellSize;
            double zX   = zPnt.X;
            double zY   = zPnt.Y;
            double vX   = vPnt.X;
            double vY   = vPnt.Y;
            double ns   = vX;

            if (Math.Abs(vX - vY) > 0.0001)
            {
                if (vY < vX)
                {
                    ns = vY;
                }
                InValueRaster = rsUtil.reSampleRasterFunction(vRs, ns);
                if (rd != null)
                {
                    rd.addMessage("Value dataset cells Width and Height are not the same! Resizing the valueRaster cell width and height to " + ns.ToString() + "!");
                }
            }
            if (Math.Abs(zX - ns) > 0.0001)
            {
                InZoneRaster = rsUtil.reSampleRasterFunction(zRs, ns);
                if (rd != null)
                {
                    rd.addMessage("Zone and value dataset cells are not the same size! Resizing the zoneRaster cell width and height to match the value raster (" + vRs.RasterInfo.CellSize.X.ToString() + ":" + zRs.RasterInfo.CellSize.X.ToString() + ")!");
                }
            }
            return(cS);
        }
示例#2
0
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.

                //System.Array noDataValueArr = (System.Array)((IRasterProps)inrsBandsCoef).NoDataValue;
                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                //Console.WriteLine("After Read");
                int  pBHeight = pPixelBlock.Height;
                int  pBWidth  = pPixelBlock.Width;
                IPnt pbSize   = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)inrsBandsCoef.CreatePixelBlock(pbSize);//independent variables
                inrsBandsCoef.Read(pTlc, (IPixelBlock)outPb);
                int          pBRowIndex   = 0;
                int          pBColIndex   = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                //System.Array[] pArr = new System.Array[outPb.Planes];
                //for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                //{
                //    System.Array pixelValues = (System.Array)(outPb.get_PixelData(coefnBand));
                //    pArr[coefnBand] = pixelValues;
                //}
                System.Array pValues = (System.Array)ipPixelBlock.get_PixelData(0);//(System.Array)(td);
                for (int i = pBRowIndex; i < pBHeight; i++)
                {
                    for (int k = pBColIndex; k < pBWidth; k++)
                    {
                        double[] xVls = new double[outPb.Planes];
                        bool     ndT  = true;
                        for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                        {
                            //float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(coefnBand));
                            object pObj = outPb.GetVal(coefnBand, k, i);

                            if (pObj == null)
                            {
                                ndT = false;
                                break;
                            }
                            float pixelValue = Convert.ToSingle(pObj);
                            xVls[coefnBand] = pixelValue;
                        }
                        if (ndT)
                        {
                            int c = cluster.computNew(xVls);
                            pValues.SetValue(c, k, i);
                        }
                    }
                }
                ipPixelBlock.set_PixelData(0, pValues);
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of Cluster Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
示例#3
0
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.


                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                IRaster2     rs2 = (IRaster2)pRaster;
                double       pX, pY;
                rs2.PixelToMap(System.Convert.ToInt32(pTlc.X), System.Convert.ToInt32(pTlc.Y), out pX, out pY);
                //Console.WriteLine("After Read");
                int       pBHeight = pPixelBlock.Height;
                int       pBWidth  = pPixelBlock.Width;
                IEnvelope env      = new EnvelopeClass();
                env.PutCoords(pX, pY - pBHeight, pX + pBWidth, pY);
                updateWithMergedValues(env, ipPixelBlock);
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of merge Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
示例#4
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         // Call Read method of the Raster Function Helper object.
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         int  pBHeight = pPixelBlock.Height;
         int  pBWidth  = pPixelBlock.Width;
         IPnt pbSize   = new PntClass();
         pbSize.SetCoords(pBWidth, pBHeight);
         //IPixelBlock3 inVlsPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);
         //myFunctionHelperCoef.Read(pTlc,null,myFunctionHelperCoef.Raster, (IPixelBlock)inVlsPb);
         IPixelBlock3          outPixelBlock = (IPixelBlock3)pPixelBlock;
         System.Array          outArr        = (System.Array)outPixelBlock.get_PixelData(0);
         System.Array[]        inArr         = new System.Array[inrs.RasterInfo.BandCount];
         IRasterBandCollection rsBc          = (IRasterBandCollection)inrs;
         for (int b = 0; b < inrs.RasterInfo.BandCount; b++)
         {
             IRasterBand rsB  = rsBc.Item(b);
             IRawPixels  rPix = (IRawPixels)rsB;
             IPixelBlock pb   = rPix.CreatePixelBlock(pbSize);
             rPix.Read(pTlc, pb);
             inArr[b] = (System.Array)pb.get_SafeArray(b);
         }
         updateOutArr(outPixelBlock, inArr, outArr);
         outPixelBlock.set_PixelData(0, outArr);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
示例#5
0
        public void CanWriteMultiPoint()
        {
            Pnt3D point1 = new Pnt3D(2600001.123, 1200000.987, 432.1);
            Pnt3D point2 = new Pnt3D(2600002.234, 1200002.876, 321.98);

            IList <IPnt> multipoint = new IPnt[]
            {
                point1,
                point2
            };

            WkbGeomWriter writer = new WkbGeomWriter();

            byte[] bytes = writer.WriteMultipoint(multipoint);

            WkbGeomReader reader = new WkbGeomReader();

            List <IPnt> deserizalized = reader.ReadMultiPoint(new MemoryStream(bytes)).ToList();

            Assert.AreEqual(multipoint.Count, deserizalized.Count);

            for (int i = 0; i < multipoint.Count; i++)
            {
                Assert.IsTrue(deserizalized[i].Equals(multipoint[i]));
            }
        }
示例#6
0
        private static void ValidateForm([NotNull] IIndexedMultiPatch indexedMultiPatch,
                                         [NotNull] IEnumerable <WKSPointZ> projected)
        {
            var  pre      = new WKSPointZ();
            bool notFirst = false;
            IEnumerator <SegmentProxy> segments =
                indexedMultiPatch.GetSegments().GetEnumerator();

            foreach (WKSPointZ wksPoint in projected)
            {
                Assert.AreEqual(0, wksPoint.Z);

                if (notFirst)
                {
                    double dx     = wksPoint.X - pre.X;
                    double dy     = wksPoint.Y - pre.Y;
                    double length = Math.Sqrt(dx * dx + dy * dy);

                    Assert.IsTrue(segments.MoveNext());
                    Assert.IsNotNull(segments.Current);

                    const bool as3D          = true;
                    IPnt       start         = segments.Current.GetStart(as3D);
                    IPnt       end           = segments.Current.GetEnd(as3D);
                    double     segDx         = end.X - start.X;
                    double     segDy         = end.Y - start.Y;
                    double     segDz         = end[2] - start[2];
                    double     segmentLength = Math.Sqrt(segDx * segDx + segDy * segDy + segDz * segDz);
                    Assert.IsTrue(Math.Abs(segmentLength - length) < 1.0e-8);
                }

                pre      = wksPoint;
                notFirst = true;
            }
        }
示例#7
0
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            //try
            //{
            //System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
            myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
            int          pBHeight = pPixelBlock.Height;
            int          pBWidth = pPixelBlock.Width;
            IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
            IPnt         pbBigSize = new PntClass();
            IPnt         pbBigLoc = new PntClass();
            int          pbBigWd = pBWidth + clms - 1;
            int          pbBigHt = pBHeight + rws - 1;
            int          l, t;

            l = clms / 2;
            t = rws / 2;
            //Console.WriteLine("lt = " + (pTlc.X - l).ToString() + ":" + (pTlc.Y - t).ToString());
            pbBigSize.SetCoords(pbBigWd, pbBigHt);
            pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
            IPixelBlock3 pbBig = (IPixelBlock3)myFunctionHelperOrig.Raster.CreatePixelBlock(pbBigSize);

            myFunctionHelperOrig.Read(pbBigLoc, null, myFunctionHelperOrig.Raster, (IPixelBlock)pbBig);
            updatePixelRectangle(ipPixelBlock, pbBig);
            //}
            //catch (Exception e)
            //{
            //Console.WriteLine(e.ToString());
            //System.Windows.Forms.MessageBox.Show(e.ToString());
            //Console.WriteLine(pTlc.X.ToString() + ":" + pTlc.Y.ToString());

            //}
        }
示例#8
0
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.


                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IRaster mosRs   = (IRaster)mos;
                IPnt    pntSize = new PntClass();
                pntSize.SetCoords(pPixelBlock.Width, pPixelBlock.Height);
                IPixelBlock pb = mosRs.CreatePixelBlock(pntSize);
                mosRs.Read(pTlc, pb);
                for (int i = 0; i < pb.Planes; i++)
                {
                    pPixelBlock.set_SafeArray(i, pb.get_SafeArray(i));
                }
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of mosaic Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
示例#9
0
        private static IEnvelope GetClipBox([NotNull] IEnvelope box,
                                            [NotNull] IRaster raster)
        {
            IEnvelope result = GeometryFactory.Clone(box);

            WKSEnvelope wks;

            result.QueryWKSCoords(out wks);
            double expandX = 0;
            double expandY = 0;

            var props = raster as IRasterProps;

            if (props != null)
            {
                IPnt pnt = props.MeanCellSize();
                expandX = 2 * Math.Abs(pnt.X);
                expandY = 2 * Math.Abs(pnt.Y);
            }

            wks.XMin -= expandX;
            wks.XMax += expandX;
            wks.YMin -= expandY;
            wks.YMax += expandY;

            result.PutWKSCoords(wks);

            return(result);
        }
示例#10
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         IPixelBlock3 pPixelBlock3 = (IPixelBlock3)pPixelBlock;
         IRaster2     inRs2 = (IRaster2)inrs;
         IRaster2     outRs2 = (IRaster2)outrs;
         double       mx, my;
         outRs2.PixelToMap((int)pTlc.X, (int)pTlc.Y, out mx, out my);
         int clm, rw;
         inRs2.MapToPixel(mx, my, out clm, out rw);
         IPnt pntLoc  = new PntClass();
         pntLoc.SetCoords(clm, rw);
         IPnt pntSize = new PntClass();
         pntSize.SetCoords(pPixelBlock.Width, pPixelBlock.Height);
         IPixelBlock3 pBIn = (IPixelBlock3)inrs.CreatePixelBlock(pntSize);
         inrs.Read(pntLoc, (IPixelBlock)pBIn);
         for (int p = 0; p < pPixelBlock.Planes; p++)
         {
             pPixelBlock3.set_PixelData(p, pBIn.get_PixelData(p));
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
示例#11
0
        //public IFeatureClass createPolygons3()
        //{
        //    createFeatureClass();

        //}
        public IFeatureClass createPolygons2()
        {
            createFeatureClass();
            IRasterProps           rsProp   = (IRasterProps)inputRaster;
            int                    bndCnt   = ((IRasterBandCollection)inputRaster).Count;
            IPnt                   rsPnt    = rsProp.MeanCellSize();
            double                 cellArea = rsPnt.X * rsPnt.Y;
            double                 tCells   = minArea / cellArea;
            IFunctionRasterDataset sDset    = rsUtil.createMeanShiftFuction(inputRaster, (int)tCells);

            FunctionRasters.meanShiftFunctionDataset rFunc = (FunctionRasters.meanShiftFunctionDataset)sDset.Function;
            IRaster2               rs2   = (IRaster2)rsUtil.createRaster(sDset);
            IRasterCursor          rsCur = rs2.CreateCursorEx(null);
            IRasterDomainExtractor dExt  = new RasterDomainExtractorClass();

            do
            {
                IPixelBlock            pb     = rsCur.PixelBlock;
                IFunctionRasterDataset pbDset = rsUtil.PixelBlockToRaster(pb, rsCur.TopLeft, sDset);
                IRaster rs          = rsUtil.createRaster(pbDset);
                int     numClusters = rFunc.NumClusters;
                for (int c = 0; c < numClusters; c++)
                {
                    IFunctionRasterDataset fd  = rsUtil.calcEqualFunction(pbDset, c);
                    IFunctionRasterDataset fd2 = rsUtil.setNullValue(fd, 0);
                    IPolygon polys             = dExt.ExtractDomain(rsUtil.createRaster(fd2), true);
                }
            } while (rsCur.Next() == true);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur);



            return(outftr);
        }
示例#12
0
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            double vl         = 0;
            float  pixelValue = 0f;

            try
            {
                System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IPixelBlock3 pb3 = (IPixelBlock3)pPixelBlock;
                #region Load log object
                for (int nBand = 0; nBand < pPixelBlock.Planes; nBand++)
                {
                    float        noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(nBand));
                    System.Array dArr        = (System.Array)pb3.get_PixelData(nBand);
                    for (int r = 0; r < pPixelBlock.Height; r++)
                    {
                        for (int c = 0; c < pPixelBlock.Width; c++)
                        {
                            vl = System.Convert.ToDouble(dArr.GetValue(c, r));
                            if (rasterUtil.isNullData(System.Convert.ToSingle(vl), noDataValue))
                            {
                                continue;
                            }
                            pixelValue = System.Convert.ToSingle(getFunctionValue(vl));
                            dArr.SetValue(pixelValue, c, r);
                        }
                    }
                    pb3.set_PixelData(nBand, dArr);
                    //unsafe
                    //{
                    //    System.Array dArr = (System.Array)pb3.get_PixelData(nBand);
                    //    int lng = dArr.Length;
                    //    fixed (float* dValue = (float[,])dArr)
                    //    {
                    //        for (int i = 0; i < lng; i++)
                    //        {
                    //            pixelValue = *(dValue + i);
                    //            if (rasterUtil.isNullData(pixelValue, noDataValue))
                    //            {
                    //                continue;
                    //            }
                    //            pixelValue = System.Convert.ToSingle(getFunctionValue(pixelValue));
                    //            *(dValue + i) = pixelValue;

                    //        }
                    //        pb3.set_PixelData(nBand, dArr);
                    //    }
                    //}
                }
                #endregion
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method math Function. " + exc.Message, exc);
                throw myExc;
            }
        }
示例#13
0
 public AngleEndError([NotNull] SegmentsSubpart segmentsSubpart,
                      [NotNull] IPnt at,
                      [NotNull] IPnt otherEnd)
 {
     SegmentsSubpart = segmentsSubpart;
     At       = at;
     OtherEnd = otherEnd;
 }
示例#14
0
        public void GetCoordinates(int pointIndex, out double x, out double y, out double z)
        {
            IPnt point = GetPoint(pointIndex);

            x = point.X;
            y = point.Y;
            z = point[2];
        }
示例#15
0
 private static void Populate(SpatialHashSearcher <int> spatialSearcher,
                              IPointList pointList)
 {
     for (var i = 0; i < pointList.PointCount; i++)
     {
         IPnt pnt = pointList.GetPoint(i);
         spatialSearcher.Add(i, pnt.X, pnt.Y, pnt.X, pnt.Y);
     }
 }
示例#16
0
        public static IBox GetExpanded([NotNull] IBox box,
                                       double expansionDistance)
        {
            IPnt min = box.Min;
            IPnt max = box.Max;

            return(new Box(
                       new Pnt2D(min.X - expansionDistance, min.Y - expansionDistance),
                       new Pnt2D(max.X + expansionDistance, max.Y + expansionDistance)));
        }
示例#17
0
        /// <summary>
        /// Returns - larger 0 for testPoint left of the line from lineStart to lineEnd
        ///         - 0 for testPoint on the line
        ///         - smaller 0 for test point right of the line
        /// </summary>
        /// <param name="testPoint"></param>
        /// <returns></returns>
        public double IsLeftXY([NotNull] IPnt testPoint)
        {
            double vX = testPoint.X - StartPoint.X;
            double vY = testPoint.Y - StartPoint.Y;

            double perpProduct =
                PerpProduct(DirectionVector.X, DirectionVector.Y, vX, vY);

            return(perpProduct);
        }
示例#18
0
        public byte[] WritePoint([NotNull] IPnt point, Ordinates ordinates = Ordinates.Xyz)
        {
            MemoryStream memoryStream = InitializeWriter();

            WriteWkbType(WkbGeometryType.Point, ordinates);

            WritePointCore(point, ordinates);

            return(memoryStream.ToArray());
        }
示例#19
0
        /// <summary>
        /// Show the extent of input layer in the control.
        /// </summary>
        /// <param name="rasterLayer"></param>
        private void ShowExtent(IRasterLayer rasterLayer)
        {
            IRasterProps rasterProps = (IRasterProps)rasterLayer.Raster;

            leftCoorTextBox.Text = rasterProps.Extent.XMin.ToString();
            buttomCoorTextBox.Text = rasterProps.Extent.YMin.ToString();

            IPnt pixelSize = rasterProps.MeanCellSize();
            pixelSizeTextBox.Text = pixelSize.Y.ToString();
        }
示例#20
0
        private void UpdateBounds([NotNull] IPnt point,
                                  int pointIndex,
                                  [NotNull] IList <Line3D> currentSegments,
                                  [CanBeNull] Pnt3D previouslyAdded)
        {
            if (point.X < XMin)
            {
                XMin = point.X;
            }

            if (point.X > XMax)
            {
                XMax = point.X;
            }

            if (point.Y < YMin)
            {
                YMin = point.Y;
                RightMostBottomIndex = pointIndex;
            }
            else if (!(point.Y > YMin))
            {
                Pnt3D currentRightMostLowestPnt;
                if (currentSegments.Count == RightMostBottomIndex)
                {
                    if (previouslyAdded != null)
                    {
                        currentRightMostLowestPnt = Assert.NotNull(previouslyAdded);
                    }
                    else
                    {
                        currentRightMostLowestPnt =
                            currentSegments[currentSegments.Count - 1].EndPoint;
                    }
                }
                else
                {
                    currentRightMostLowestPnt =
                        currentSegments[RightMostBottomIndex].StartPoint;
                }

                if (point.X > currentRightMostLowestPnt.X)
                {
                    // equally low, but more to the right
                    RightMostBottomIndex = pointIndex;
                }
            }

            if (point.Y > YMax)
            {
                YMax = point.Y;
            }

            _boundingBox = null;
        }
示例#21
0
        private void setInRs()
        {
            IEnvelope env = new EnvelopeClass();
            double    mx, my;
            IRaster2  rs       = (IRaster2)rsUtil.createRaster(valueraster);
            IPnt      cellSize = valueraster.RasterInfo.CellSize;

            rs.PixelToMap((int)topleft.X, (int)topleft.Y, out mx, out my);
            env.PutCoords(mx, my - (cellSize.Y * vpixelBlock.Height), mx + (cellSize.X * vpixelBlock.Width), my);
            inrs = rsUtil.constantRasterFunction((IRaster)rs, env, 0, cellSize);
        }
示例#22
0
        public double Dist2([NotNull] IPnt point, int dimension)
        {
            double dDist2 = 0;

            for (var i = 0; i < dimension; i++)
            {
                double d = this[i] - point[i];
                dDist2 += d * d;
            }

            return(dDist2);
        }
示例#23
0
        private static double GetDistanceSquaredXY([NotNull] IPnt point1, IPnt point2)
        {
            double dx = point2.X - point1.X;

            double result = dx * dx;

            double dy = point2.Y - point1.Y;

            result += dy * dy;

            return(result);
        }
示例#24
0
        public override IPnt GetPointAt(double fraction, bool as3D)
        {
            WKSPointZ from = FromPoint;
            WKSPointZ to   = ToPoint;

            Pnt p0 = GetPoint(from, as3D);
            Pnt p1 = GetPoint(to, as3D);

            IPnt at = p0 + fraction * (p1 - p0);

            return(at);
        }
示例#25
0
        public IEnumerable <SegmentProxy> GetSegments(IBox box)
        {
            IPnt min = box.Min;
            IPnt max = box.Max;

            _qEnv.Value.PutCoords(min.X, min.Y, max.X, max.Y);
            IEnumSegment enumSegs = _segments.IndexedEnumSegments[_qEnv.Value];

            var enumerable = new SegmentEnumerable(enumSegs);

            return(enumerable);
        }
示例#26
0
        private static bool IsEqual([NotNull] IPnt p1, [NotNull] IPnt p2)
        {
            for (var i = 0; i < 3; i++)
            {
                if (Math.Abs(p1[i] - p2[i]) > double.Epsilon)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#27
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         int          pBHeight = pPixelBlock.Height;
         int          pBWidth = pPixelBlock.Width;
         IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
         IPnt         pbBigSize = new PntClass();
         IPnt         pbBigLoc = new PntClass();
         int          pbBigWd = pBWidth + clms;
         int          pbBigHt = pBHeight + rws;
         int          l, t;
         l = (clms - 1) / 2;
         t = (rws - 1) / 2;
         //Console.WriteLine("lt = " + (pTlc.X - l).ToString() + ":" + (pTlc.Y - t).ToString());
         pbBigSize.SetCoords(pbBigWd, pbBigHt);
         pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
         IPixelBlock3 pbBig = (IPixelBlock3)myFunctionHelperOrig.Raster.CreatePixelBlock(pbBigSize);
         myFunctionHelperOrig.Read(pbBigLoc, null, myFunctionHelperOrig.Raster, (IPixelBlock)pbBig);
         for (int nBand = 0; nBand < pbBig.Planes; nBand++)
         {
             System.Array pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
             rstPixelType rsp         = ipPixelBlock.get_PixelType(nBand);
             //System.Array pixelValuesBig = (System.Array)(pbBig.get_PixelData(nBand));
             for (int r = 0; r < pBHeight; r++)
             {
                 for (int c = 0; c < pBWidth; c++)
                 {
                     object objVl = ipPixelBlock.GetVal(nBand, c, r);
                     if (objVl == null)
                     {
                         continue;
                     }
                     else
                     {
                         float  outVl = System.Convert.ToSingle(getTransformedValue(pbBig, c + l, r + t, nBand));
                         object newVl = rasterUtil.getSafeValue(outVl, rsp);
                         //Console.WriteLine(outVl.ToString());
                         pixelValues.SetValue(newVl, c, r);
                     }
                 }
             }
             ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
示例#28
0
        /// <summary>
        /// Creates a random raster given a template raster (defined extent and cell size)
        /// </summary>
        /// <param name="templateRasterPath">full path location of the template raster</param>
        /// <param name="outRasterPath">the full path location of the output random raster</param>
        /// <returns>geoprocessing messages</returns>
        public string createRandomRaster(string templateRasterPath, string outRasterPath)
        {
            ESRI.ArcGIS.SpatialAnalystTools.CreateRandomRaster cRndRst = new CreateRandomRaster();
            string         bnd     = "";
            IRasterDataset rDset   = rsUtil.openRasterDataset(templateRasterPath, out bnd);
            IRaster        rst     = rsUtil.createRaster(rDset);
            IRasterProps   rstProp = (IRasterProps)rst;
            IPnt           pnt     = rstProp.MeanCellSize();

            cRndRst.cell_size  = pnt.X;
            cRndRst.out_raster = outRasterPath;
            return(getMessages(gpExecute(cRndRst)));
        }
示例#29
0
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster.
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         getTransformedValue(ref pPixelBlock);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
示例#30
0
        public static Pnt Create([NotNull] IPnt point)
        {
            int dimension = point.Dimension;

            Pnt p = Create(dimension);

            for (var i = 0; i < dimension; i++)
            {
                p[i] = point[i];
            }

            return(p);
        }
 public void Bind(object pArgument)
 {
     if (pArgument is PixelBlockToRasterFunctionArguments)
     {
         PixelBlockToRasterFunctionArguments args = (PixelBlockToRasterFunctionArguments)pArgument;
         inrs = args.InRaster;
         vPb = (IPixelBlock3)args.ValuePixelBlock;
         tlLoc = args.TopLeft;
         myFunctionHelper.Bind(inrs);
         myRasterInfo = myFunctionHelper.RasterInfo;
         myPixeltype = myRasterInfo.PixelType;
         myValidFlag = true;
     }
     else
     {
         throw new System.Exception("Incorrect arguments object. Expected: PixelBlockToRasterArguments");
     }
 }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Create a new pixel block to read the input data into.
                // This is done because the pPixelBlock represents the output
                // pixel block which is different from the input. 
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pBlockSize = new Pnt();
                pBlockSize.X = pBWidth;
                pBlockSize.Y = pBHeight;
                IPixelBlock inputPixelBlock = new PixelBlock();
                ((IPixelBlock4)inputPixelBlock).Create(myInpNumBands, pBWidth, pBHeight, myInpPixeltype);

                // Call Read method of the Raster Function Helper object to read the input pixels into
                // the inputPixelBlock.
                myFunctionHelper.Read(pTlc, null, pRaster, inputPixelBlock);

                System.Array inpPixelValues1;
                System.Array inpPixelValues2;
                System.Array outPixelValues;
                int index1 = Convert.ToInt16(myBandIndices[0]) - 1; ; // Get NIR band index specified by user.
                int index2 = Convert.ToInt16(myBandIndices[1]) - 1; ; // Get Red Band index specified by user.

                // Get the correct bands from the input.
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)inputPixelBlock;
                inpPixelValues1 = (System.Array)(ipPixelBlock.get_PixelData(index1));
                inpPixelValues2 = (System.Array)(ipPixelBlock.get_PixelData(index2));
                outPixelValues = (System.Array)(((IPixelBlock3)pPixelBlock).get_PixelData(0));
                int i = 0;
                int k = 0;
                double pixelValue = 0.0;
                double nirValue = 0.0;
                double irValue = 0.0;
                // Perform the NDVI computation and store the result in the output pixel block.
                for (i = 0; i < pBHeight; i++)
                {
                    for (k = 0; k < pBWidth; k++)
                    {
                        nirValue = Convert.ToDouble(inpPixelValues1.GetValue(k, i));
                        irValue = Convert.ToDouble(inpPixelValues2.GetValue(k, i));
                        // Check if input is not NoData.
                        if ((Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(index1, k, i)) == 1) &&
                            Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(index2, k, i)) == 1)
                        {
                            // NDVI[k] = (NIR[k]-Red[k])/(NIR[k]+Red[k]);
                            if ((nirValue + irValue) != 0) // Check for division by 0.
                            {
                                pixelValue = (nirValue - irValue) / (nirValue + irValue);
                                if (pixelValue < -1.0 || pixelValue > 1.0)
                                    pixelValue = 0.0;
                            }
                            else
                                pixelValue = 0.0;
                        }
                        outPixelValues.SetValue((float)(pixelValue), k, i);
                    }
                }
                // Set the output pixel values on the output pixel block.
                ((IPixelBlock3)pPixelBlock).set_PixelData(0, outPixelValues);
                // Copy over the NoData mask from the input and set it on the output.
                ((IPixelBlock3)pPixelBlock).set_NoDataMask(0, ((IPixelBlock3)inputPixelBlock).get_NoDataMask(0));
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception(
                    "Exception caught in Read method: " + exc.Message, exc);
                throw myExc;
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IPixelBlock3 pPixelBlock3 = (IPixelBlock3)pPixelBlock;
                IRaster2 inRs2 = (IRaster2)inrs;
                IRaster2 outRs2 = (IRaster2)outrs;
                double mx,my;
                outRs2.PixelToMap((int)pTlc.X,(int)pTlc.Y,out mx, out my);
                int clm,rw;
                inRs2.MapToPixel(mx,my,out clm,out rw);
                IPnt pntLoc = new PntClass();
                pntLoc.SetCoords(clm,rw);
                IPnt pntSize = new PntClass();
                pntSize.SetCoords(pPixelBlock.Width,pPixelBlock.Height);
                IPixelBlock3 pBIn = (IPixelBlock3)inrs.CreatePixelBlock(pntSize);
                inrs.Read(pntLoc,(IPixelBlock)pBIn);
                for (int p = 0; p < pPixelBlock.Planes; p++)
                {
                    pPixelBlock3.set_PixelData(p, pBIn.get_PixelData(p));
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster. 
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     //double vl = 0;
     //float pixelValue = 0f;
     try
     {
         //System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
         // Call Read method of the Raster Function Helper object.
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         IPixelBlock3 pb3 = (IPixelBlock3)pPixelBlock;
         #region Load log object
         for (int nBand = 0; nBand < pPixelBlock.Planes; nBand++)
         {
             //float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(nBand));
             System.Array dArr = (System.Array)pb3.get_PixelData(nBand);
             rstPixelType pbT = pb3.get_PixelType(nBand);
             for (int r = 0; r < pPixelBlock.Height; r++)
             {
                 for (int c = 0; c < pPixelBlock.Width; c++)
                 {
                     object objVl = pb3.GetVal(nBand,c, r);
                     if (objVl == null)
                     {
                         continue;
                     }
                     else
                     {
                         //vl = System.Convert.ToSingle(objVl);
                         //pixelValue = (float)getFunctionValue(vl);
                         double objVl2 = getFunctionValue(System.Convert.ToDouble(objVl));
                         object newVl = rasterUtil.getSafeValue(objVl2, pbT);
                         dArr.SetValue(newVl, c, r);
                     }
                 }
             }
             pb3.set_PixelData(nBand, dArr);
         }
         #endregion
     }
     catch (Exception exc)
     {
         System.Exception myExc = new System.Exception("Exception caught in Read method math Function. " + exc.Message, exc);
         throw myExc;
     }
 }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The watermark image is then blended to the bottom right corner of the pixel block. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            BitmapData wMBitmapData = null;
            double pixelValue = 0.0;
            int wmRow = 0;
            int wmCol = 0;
            try
            {
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);

                int wMBandOffset = 0;

                #region Reference Raster Properties
                // Get the pixel type of the reference raster to see if 
                // it is compatible (8 bit).
                IRasterProps referenceProps = (IRasterProps)pRaster;
                if (referenceProps.PixelType != rstPixelType.PT_UCHAR &&
                    referenceProps.PixelType != rstPixelType.PT_CHAR)
                {
                    throw new System.Exception(
                        "Function can only be applied to 8bit data.");
                }

                #endregion

                #region Load watermark image object
                // Create new image object for the watermark image.
                myWatermarkImage = new Bitmap(myWatermarkImagePath);
                // Read number of bands of the watermark image.
                if (myWatermarkImage.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
                    wMBandOffset = 4;
                else
                {
                    if (myWatermarkImage.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)
                        wMBandOffset = 3;
                    else
                    {
                        throw new System.Exception(
                            "Invalid bitmap. Please provide one with 8bits per band in ARGB or RGB format.");
                    }
                }
                #endregion

                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                int wMHeight = myWatermarkImage.Height;
                int wMWidth = myWatermarkImage.Width;
                int wMRowIndex = 0;
                int wMColIndex = 0;
                int pBRowIndex = 0;
                int pBColIndex = 0;
                int endRow = 0;
                int endCol = 0;
                bool waterStartCol = false;
                bool waterStartRow = false;

                // Calculate the row/column values that specify where to start the blending.
                #region Calculate Indices
                /// If the number of rows of the pixelblock are more than the watermark image
                endRow = pBHeight;
                if (pBHeight >= wMHeight)
                {
                    /// Set the row index to start blending in the pixelblock.
                    switch (myWatermarkLocation)
                    {
                        case esriWatermarkLocation.esriWatermarkTopLeft:
                            {
                                pBRowIndex = 0;
                                endRow = pBRowIndex + wMHeight;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkTopRight:
                            {
                                pBRowIndex = 0;
                                endRow = pBRowIndex + wMHeight;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkCenter:
                            {
                                pBRowIndex = (pBHeight / 2) - (wMHeight / 2);
                                endRow = pBRowIndex + wMHeight;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkBottomLeft:
                            {
                                pBRowIndex = pBHeight - wMHeight;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkBottomRight:
                            {
                                pBRowIndex = pBHeight - wMHeight;
                                break;
                            }
                        default:
                            break;
                    }

                    if (myWatermarkLocation == esriWatermarkLocation.esriWatermarkCenter)
                    {
                        pBRowIndex = (pBHeight / 2) - (wMHeight / 2);
                        endRow = pBRowIndex + wMHeight;
                    }
                }
                else /// If the number of rows of the watermark image is more than that of the pixelblock.
                {
                    /// Set the row index to start blending in the watermark image.
                    wMRowIndex = (wMHeight - pBHeight);
                    waterStartRow = true;
                }

                /// If the number of cols of the pixelblock are more than the watermark image
                endCol = pBWidth;
                if (pBWidth >= wMWidth)
                {
                    /// Set the col index to start blending in the pixelblock.
                    /// Set the row index to start blending in the pixelblock.
                    switch (myWatermarkLocation)
                    {
                        case esriWatermarkLocation.esriWatermarkTopLeft:
                            {
                                pBColIndex = 0;
                                endCol = pBColIndex + wMWidth;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkTopRight:
                            {
                                pBColIndex = pBWidth - wMWidth;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkCenter:
                            {
                                pBColIndex = (pBWidth / 2) - (wMWidth / 2);
                                endCol = pBColIndex + wMWidth;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkBottomLeft:
                            {
                                pBColIndex = 0;
                                endCol = pBColIndex + wMWidth;
                                break;
                            }
                        case esriWatermarkLocation.esriWatermarkBottomRight:
                            {
                                pBColIndex = pBWidth - wMWidth;
                                break;
                            }
                        default:
                            break;
                    }
                }
                else /// If the number of cols of the watermark image is more than that of the pixelblock.
                {
                    /// Set the col index to start blending in the watermark image.
                    wMColIndex = (wMWidth - pBWidth);
                    waterStartCol = true;
                }
                #endregion

                #region Prepare Watermark Image for reading
                // Get the pixels from the watermark image using the lockbits function.
                wMBitmapData = myWatermarkImage.LockBits(new Rectangle(0, 0, wMWidth, wMHeight),
                    ImageLockMode.ReadOnly, myWatermarkImage.PixelFormat);

                System.IntPtr wMScan0 = wMBitmapData.Scan0;
                int wMStride = wMBitmapData.Stride;
                #endregion

                // The unsafe keyword is used so that pointers can be used to access pixels
                // from the watermark image.
                unsafe
                {
                    int wMPaddingOffset = wMStride - (myWatermarkImage.Width * wMBandOffset);

                    // Start filling from the correct row, col in the pixelblock 
                    // using the indices calculated above
                    System.Array pixelValues;
                    if (pPixelBlock.Planes == 3)
                    {
                        if (wMBandOffset == 4) // To check for transparency in WM Image
                        {
                            #region 3 Band PixelBlock
                            for (int nBand = 0; nBand < pPixelBlock.Planes; ++nBand)
                            {
                                byte* wMStartByte = (byte*)(void*)wMScan0;

                                /// If the number of rows of the watermark image are more than the request.
                                if (waterStartRow) /// Skip to the correct row in the watermark image.
                                    wMStartByte += (wMStride * wMRowIndex);

                                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                                pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                                for (int i = pBRowIndex; i < endRow; i++, ++wmRow)
                                {
                                    /// If the number of cols of the watermark image are more than the request.
                                    if (waterStartCol) /// Skip to the correct column in the watermark image.                                
                                        wMStartByte += (wMColIndex * wMBandOffset);

                                    for (int k = pBColIndex; k < endCol; k++, ++wmCol)
                                    {
                                        pixelValue = Convert.ToDouble(pixelValues.GetValue(k, i));
                                        if (Convert.ToDouble(wMStartByte[3]) != 0.0 &&
                                            Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(nBand, k, i)) == 1)
                                        {
                                            // Blend the pixelValue from the PixelBlock with the corresponding
                                            // pixel from the watermark image.
                                            pixelValue = ((1 - blendValue) * pixelValue) + (blendValue *
                                                Convert.ToDouble(wMStartByte[2 - nBand]));
                                        }
                                        pixelValues.SetValue(Convert.ToByte(pixelValue), k, i);

                                        wMStartByte += wMBandOffset;
                                    }
                                    wMStartByte += wMPaddingOffset;
                                }
                                ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                            }
                            #endregion
                        }
                        else
                        {
                            #region 3 Band PixelBlock
                            for (int nBand = 0; nBand < pPixelBlock.Planes; ++nBand)
                            {
                                byte* wMStartByte = (byte*)(void*)wMScan0;

                                /// If the number of rows of the watermark image are more than the request.
                                if (waterStartRow) /// Skip to the correct row in the watermark image.
                                    wMStartByte += (wMStride * wMRowIndex);

                                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                                pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                                for (int i = pBRowIndex; i < endRow; i++, ++wmRow)
                                {
                                    /// If the number of cols of the watermark image are more than the request.
                                    if (waterStartCol) /// Skip to the correct column in the watermark image.                                
                                        wMStartByte += (wMColIndex * wMBandOffset);

                                    for (int k = pBColIndex; k < endCol; k++, ++wmCol)
                                    {
                                        pixelValue = Convert.ToDouble(pixelValues.GetValue(k, i));
                                        if (Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(nBand, k, i)) == 1)
                                        {
                                            // Blend the pixelValue from the PixelBlock with the corresponding
                                            // pixel from the watermark image.
                                            pixelValue = ((1 - blendValue) * pixelValue) + (blendValue *
                                                Convert.ToDouble(wMStartByte[2 - nBand]));
                                        }
                                        pixelValues.SetValue(Convert.ToByte(pixelValue), k, i);

                                        wMStartByte += wMBandOffset;
                                    }
                                    wMStartByte += wMPaddingOffset;
                                }
                                ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        if (wMBandOffset == 4) // To check for transparency in WM Image
                        {
                            #region Not 3 Band PixelBlock
                            for (int nBand = 0; nBand < pPixelBlock.Planes; ++nBand)
                            {
                                byte* wMStartByte = (byte*)(void*)wMScan0;

                                /// If the number of rows of the watermark image are more than the request.
                                if (waterStartRow) /// Skip to the correct row in the watermark image.
                                    wMStartByte += (wMStride * wMRowIndex);

                                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                                pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                                int nooftimes = 0;
                                int noofskips = 0;
                                for (int i = pBRowIndex; i < endRow; i++, ++wmRow)
                                {
                                    /// If the number of cols of the watermark image are more than the request.
                                    if (waterStartCol) /// Skip to the correct column in the watermark image.                                
                                        wMStartByte += (wMColIndex * wMBandOffset);

                                    for (int k = pBColIndex; k < endCol; k++, ++wmCol)
                                    {
                                        pixelValue = Convert.ToDouble(pixelValues.GetValue(k, i));
                                        if (Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(nBand, k, i)) == 1)
                                        //Convert.ToDouble(wMStartByte[3]) != 0.0 &&
                                        {
                                            // Calculate the average value of the pixels of the watermark image
                                            double avgValue = (Convert.ToDouble(wMStartByte[0]) +
                                                               Convert.ToDouble(wMStartByte[1]) +
                                                               Convert.ToDouble(wMStartByte[2])) / 3;

                                            // and blend it with the pixelValue from the PixelBlock.
                                            pixelValue = ((1 - blendValue) * pixelValue) +
                                                         (blendValue * avgValue);
                                        }
                                        pixelValues.SetValue(Convert.ToByte(pixelValue), k, i);

                                        ++nooftimes;
                                        noofskips += wMBandOffset;
                                        wMStartByte += wMBandOffset;
                                    }
                                    wMStartByte += wMPaddingOffset;
                                }
                                ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                            }
                            #endregion
                        }
                        else
                        {
                            #region Not 3 Band PixelBlock
                            for (int nBand = 0; nBand < pPixelBlock.Planes; ++nBand)
                            {
                                byte* wMStartByte = (byte*)(void*)wMScan0;

                                /// If the number of rows of the watermark image are more than the request.
                                if (waterStartRow) /// Skip to the correct row in the watermark image.
                                    wMStartByte += (wMStride * wMRowIndex);

                                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                                pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                                int nooftimes = 0;
                                int noofskips = 0;
                                for (int i = pBRowIndex; i < endRow; i++, ++wmRow)
                                {
                                    /// If the number of cols of the watermark image are more than the request.
                                    if (waterStartCol) /// Skip to the correct column in the watermark image.                                
                                        wMStartByte += (wMColIndex * wMBandOffset);

                                    for (int k = pBColIndex; k < endCol; k++, ++wmCol)
                                    {
                                        pixelValue = Convert.ToDouble(pixelValues.GetValue(k, i));
                                        if (Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(nBand, k, i)) == 1)
                                        {
                                            // Calculate the average value of the pixels of the watermark image
                                            double avgValue = (Convert.ToDouble(wMStartByte[0]) +
                                                               Convert.ToDouble(wMStartByte[1]) +
                                                               Convert.ToDouble(wMStartByte[2])) / 3;

                                            // and blend it with the pixelValue from the PixelBlock.
                                            pixelValue = ((1 - blendValue) * pixelValue) +
                                                         (blendValue * avgValue);
                                        }
                                        pixelValues.SetValue(Convert.ToByte(pixelValue), k, i);

                                        ++nooftimes;
                                        noofskips += wMBandOffset;
                                        wMStartByte += wMBandOffset;
                                    }
                                    wMStartByte += wMPaddingOffset;
                                }
                                ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                            }
                            #endregion
                        }
                    }
                }

                #region Cleanup
                myWatermarkImage.UnlockBits(wMBitmapData);
                myWatermarkImage.Dispose();
                myWatermarkImage = null;
                wMBitmapData = null;
                wMScan0 = (System.IntPtr)null;
                wMStride = 0;
                #endregion
            }
            catch (Exception exc)
            {
                #region Cleanup
                if (wMBitmapData != null)
                    myWatermarkImage.UnlockBits(wMBitmapData);
                wMBitmapData = null;
                if (myWatermarkImage != null)
                    myWatermarkImage.Dispose();
                myWatermarkImage = null;
                #endregion

                System.Exception myExc = new System.Exception(
                    "Exception caught in Read method of Watermark Function. " + exc.Message, exc);
                throw myExc;
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);
                myFunctionHelperCoef.Read(pTlc,null,myFunctionHelperCoef.Raster, (IPixelBlock)outPb);
                int pBRowIndex = 0;
                int pBColIndex = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array outArr = (System.Array)ipPixelBlock.get_PixelData(0);
                rstPixelType pty = ipPixelBlock.get_PixelType(0);
                double[] vArr = new double[outPb.Planes];
                for (int i = pBRowIndex; i < pBHeight; i++)
                {
                    for (int k = pBColIndex; k < pBWidth; k++)
                    {
                        bool checkVl = true;
                        for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                        {
                            object vlObj = outPb.GetVal(0,k,i);
                            if(vlObj==null)
                            {
                                checkVl = false;
                                break;
                            }
                            vArr[coefnBand] = System.Convert.ToDouble(vlObj);
                        }
                        if(checkVl)
                        {
                            double tVl = lda.computeNew(vArr);
                            object newVl = rasterUtil.getSafeValue(tVl, pty);
                            outArr.SetValue(System.Convert.ToSingle(tVl), k, i);
                        }

                    }
                }
                ipPixelBlock.set_PixelData(0, outArr);
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of GLM Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.

                //System.Array noDataValueArr = (System.Array)((IRasterProps)inrsBandsCoef).NoDataValue;
                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                //Console.WriteLine("After Read");
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);//independent variables
                myFunctionHelperCoef.Read(pTlc, null,myFunctionHelperCoef.Raster,(IPixelBlock)outPb);
                int pBRowIndex = 0;
                int pBColIndex = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                //System.Array[] pArr = new System.Array[outPb.Planes];
                //for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                //{
                //    System.Array pixelValues = (System.Array)(outPb.get_PixelData(coefnBand));
                //    pArr[coefnBand] = pixelValues;
                //}
                System.Array pValues = (System.Array)ipPixelBlock.get_PixelData(0);//(System.Array)(td);
                rstPixelType pTyp = ipPixelBlock.get_PixelType(0);
                for (int i = pBRowIndex; i < pBHeight; i++)
                {
                    for (int k = pBColIndex; k < pBWidth; k++)
                    {
                        double[] xVls = new double[outPb.Planes];
                        bool ndT = true;
                        for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                        {
                            //float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(coefnBand));
                            object pObj = outPb.GetVal(coefnBand, k, i);

                            if (pObj == null)
                            {
                                ndT = false;
                                break;
                            }
                            double pixelValue = Convert.ToDouble(pObj);
                            xVls[coefnBand] = pixelValue;
                        }
                        if (ndT)
                        {
                            int c = cluster.computNew(xVls);
                            object newVl = rasterUtil.getSafeValue(c, pTyp);
                            pValues.SetValue(newVl, k, i);
                        }

                    }
                }
                ipPixelBlock.set_PixelData(0, pValues);

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of Cluster Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                switch (landType)
                {
                    #region Area
                    case rasterUtil.landscapeType.AREA:
                        switch (inop)
                        {
                            case rasterUtil.focalType.MAX:
                                neighborhoodHelperLandscapeMaxAreaRectangle nHMax = new neighborhoodHelperLandscapeMaxAreaRectangle();
                                nHMax.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef,inWindow);
                                break;
                            case rasterUtil.focalType.MIN:
                                neighborhoodHelperLandscapeMinAreaRectangle nHMin = new neighborhoodHelperLandscapeMinAreaRectangle();
                                nHMin.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.SUM:
                                neighborhoodHelperLandscapeSumAreaRectangle nHSum = new neighborhoodHelperLandscapeSumAreaRectangle();
                                nHSum.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MEAN:
                                neighborhoodHelperLandscapeMeanAreaRectangle nHMean = new neighborhoodHelperLandscapeMeanAreaRectangle();
                                nHMean.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MODE:
                                neighborhoodHelperLandscapeModeAreaRectangle nHMode = new neighborhoodHelperLandscapeModeAreaRectangle();
                                nHMode.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MEDIAN:
                                neighborhoodHelperLandscapeMedianAreaRectangle nHMed = new neighborhoodHelperLandscapeMedianAreaRectangle();
                                nHMed.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.VARIANCE:
                                neighborhoodHelperLandscapeVarianceAreaRectangle nHVar = new neighborhoodHelperLandscapeVarianceAreaRectangle();
                                nHVar.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.STD:
                                neighborhoodHelperLandscapeStdAreaRectangle nHSTD = new neighborhoodHelperLandscapeStdAreaRectangle();
                                nHSTD.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.UNIQUE:
                                neighborhoodHelperLandscapeUniqueAreaRectangle nHUniq = new neighborhoodHelperLandscapeUniqueAreaRectangle();
                                nHUniq.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.ENTROPY:
                                neighborhoodHelperLandscapeEntropyAreaRectangle nHEnt = new neighborhoodHelperLandscapeEntropyAreaRectangle();
                                nHEnt.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            default:
                                neighborhoodHelperLandscapeProbabilityAreaRectangle nHProb = new neighborhoodHelperLandscapeProbabilityAreaRectangle();
                                nHProb.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                        }
                        break;
                    #endregion
                    #region edge
                    case rasterUtil.landscapeType.EDGE:
                        switch (inop)
                        {
                            case rasterUtil.focalType.MAX:
                                neighborhoodHelperLandscapeMaxEdgeRectangle nHMax = new neighborhoodHelperLandscapeMaxEdgeRectangle();
                                nHMax.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MIN:
                                neighborhoodHelperLandscapeMinEdgeRectangle nHMin = new neighborhoodHelperLandscapeMinEdgeRectangle();
                                nHMin.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.SUM:
                                neighborhoodHelperLandscapeSumEdgeRectangle nHSum = new neighborhoodHelperLandscapeSumEdgeRectangle();
                                nHSum.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MEAN:
                                neighborhoodHelperLandscapeMeanEdgeRectangle nHMean = new neighborhoodHelperLandscapeMeanEdgeRectangle();
                                nHMean.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MODE:
                                neighborhoodHelperLandscapeModeEdgeRectangle nHMode = new neighborhoodHelperLandscapeModeEdgeRectangle();
                                nHMode.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MEDIAN:
                                neighborhoodHelperLandscapeMedianEdgeRectangle nHMed = new neighborhoodHelperLandscapeMedianEdgeRectangle();
                                nHMed.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.VARIANCE:
                                neighborhoodHelperLandscapeVarianceEdgeRectangle nHVar = new neighborhoodHelperLandscapeVarianceEdgeRectangle();
                                nHVar.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.STD:
                                neighborhoodHelperLandscapeStdEdgeRectangle nHSTD = new neighborhoodHelperLandscapeStdEdgeRectangle();
                                nHSTD.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.UNIQUE:
                                neighborhoodHelperLandscapeUniqueEdgeRectangle nHUniq = new neighborhoodHelperLandscapeUniqueEdgeRectangle();
                                nHUniq.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.ENTROPY:
                                neighborhoodHelperLandscapeEntropyEdgeRectangle nHEnt = new neighborhoodHelperLandscapeEntropyEdgeRectangle();
                                nHEnt.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            default:
                                neighborhoodHelperLandscapeProbabilityEdgeRectangle nHProb = new neighborhoodHelperLandscapeProbabilityEdgeRectangle();
                                nHProb.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                        }
                        break;
                    #endregion
                    #region ratio
                    case rasterUtil.landscapeType.RATIO:
                        switch (inop)
                        {
                            case rasterUtil.focalType.MAX:
                                neighborhoodHelperLandscapeMaxRatioRectangle nHMax = new neighborhoodHelperLandscapeMaxRatioRectangle();
                                nHMax.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MIN:
                                neighborhoodHelperLandscapeMinRatioRectangle nHMin = new neighborhoodHelperLandscapeMinRatioRectangle();
                                nHMin.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.SUM:

                                neighborhoodHelperLandscapeSumRatioRectangle nHSum = new neighborhoodHelperLandscapeSumRatioRectangle();
                                nHSum.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MEAN:
                                neighborhoodHelperLandscapeMeanRatioRectangle nHMean = new neighborhoodHelperLandscapeMeanRatioRectangle();
                                nHMean.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MODE:
                                neighborhoodHelperLandscapeModeRatioRectangle nHMode = new neighborhoodHelperLandscapeModeRatioRectangle();
                                nHMode.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.MEDIAN:
                                neighborhoodHelperLandscapeMedianRatioRectangle nHMed = new neighborhoodHelperLandscapeMedianRatioRectangle();
                                nHMed.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.VARIANCE:
                                neighborhoodHelperLandscapeVarianceRatioRectangle nHVar = new neighborhoodHelperLandscapeVarianceRatioRectangle();
                                nHVar.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.STD:
                                neighborhoodHelperLandscapeStdRatioRectangle nHSTD = new neighborhoodHelperLandscapeStdRatioRectangle();
                                nHSTD.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.UNIQUE:
                                neighborhoodHelperLandscapeUniqueRatioRectangle nHUniq = new neighborhoodHelperLandscapeUniqueRatioRectangle();
                                nHUniq.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            case rasterUtil.focalType.ENTROPY:
                                neighborhoodHelperLandscapeEntropyRatioRectangle nHEnt = new neighborhoodHelperLandscapeEntropyRatioRectangle();
                                nHEnt.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                            default:
                                neighborhoodHelperLandscapeProbabilityRatioRectangle nHProb = new neighborhoodHelperLandscapeProbabilityRatioRectangle();
                                nHProb.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                                break;
                        }
                        break;
                    #endregion
                    default:
                        neighborhoodHelperLandscapeUniqueRegionsRectangle nHReg = new neighborhoodHelperLandscapeUniqueRegionsRectangle();
                        nHReg.Read(pTlc, pRaster, pPixelBlock, clms, rws, myFunctionHelperCoef, inWindow);
                        break;

                }

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of landscape Function. " + exc.Message, exc);
                throw myExc;
            }
        }
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster. 
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         int pBHeight = pPixelBlock.Height;
         int pBWidth = pPixelBlock.Width;
         IPnt pbSize = new PntClass();
         pbSize.SetCoords(pBWidth, pBHeight);
         IPixelBlock3 inputPb = (IPixelBlock3)myFunctionHelperInput.Raster.CreatePixelBlock(pbSize);//independent variables
         myFunctionHelperInput.Read(pTlc, null, myFunctionHelperInput.Raster, (IPixelBlock)inputPb);
         IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
         System.Array pixelValues = (System.Array)ipPixelBlock.get_PixelData(0);
         createRegions(inputPb, pixelValues);
         ipPixelBlock.set_PixelData(0,pixelValues);
     }
     catch (Exception exc)
     {
         System.Exception myExc = new System.Exception("Exception caught in Read method of the Region Group function Function. " + exc.Message, exc);
         Console.WriteLine(exc.ToString());
     }
 }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.

                System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                float noDataVl = System.Convert.ToSingle(noDataValueArr.GetValue(0));
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                noDataValueArr = (System.Array)((IRasterProps)inrsBandsCoef).NoDataValue;//inrsBandsCoef
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);
                myFunctionHelper.Read(pTlc, null, myFunctionHelperCoef.Raster, (IPixelBlock)outPb);
                int pBRowIndex = 0;
                int pBColIndex = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array[] pArr = new System.Array[outPb.Planes];
                for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                {
                    System.Array pixelValues = (System.Array)(outPb.get_PixelData(coefnBand));
                    pArr[coefnBand] = pixelValues;
                }
                for (int nBand = 0; nBand < pPixelBlock.Planes; nBand++)
                {
                    System.Array outArr = (System.Array)ipPixelBlock.get_PixelData(nBand);
                    rstPixelType pty = ipPixelBlock.get_PixelType(nBand);
                    for (int i = pBRowIndex; i < pBHeight; i++)
                    {
                        for (int k = pBColIndex; k < pBWidth; k++)
                        {

                            float[] IntSlpArr = slopes[nBand];
                            double sumVls = IntSlpArr[0];
                            for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                            {
                                double noDataValue = System.Convert.ToDouble(noDataValueArr.GetValue(coefnBand));
                                double pixelValue = Convert.ToDouble(pArr[coefnBand].GetValue(k, i));
                                if (rasterUtil.isNullData(pixelValue, noDataValue))
                                {
                                    sumVls = noDataVl;
                                    break;
                                }

                                double slp = System.Convert.ToDouble(IntSlpArr[coefnBand + 1]);
                                sumVls += pixelValue * slp;
                            }
                            if (sumVls < censored) sumVls = censored;
                            object newVl = rasterUtil.getSafeValue(sumVls, pty);
                            outArr.SetValue(newVl, k, i);
                        }
                    }
                    ipPixelBlock.set_PixelData(nBand, outArr);
                }
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of Tobit Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            //try
            //{
                //System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                IPnt pbBigSize = new PntClass();
                IPnt pbBigLoc = new PntClass();
                int pbBigWd = pBWidth + clms - 1;
                int pbBigHt = pBHeight + rws - 1;
                int l, t;
                l = clms / 2;
                t = rws / 2;
                //Console.WriteLine("lt = " + (pTlc.X - l).ToString() + ":" + (pTlc.Y - t).ToString());
                pbBigSize.SetCoords(pbBigWd, pbBigHt);
                pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
                IPixelBlock3 pbBig = (IPixelBlock3)myFunctionHelperOrig.Raster.CreatePixelBlock(pbBigSize);
                myFunctionHelperOrig.Read(pbBigLoc, null, myFunctionHelperOrig.Raster, (IPixelBlock)pbBig);
                updatePixelRectangle(ipPixelBlock, pbBig);
            //}
            //catch (Exception e)
            //{
                //Console.WriteLine(e.ToString());
                //System.Windows.Forms.MessageBox.Show(e.ToString());
                //Console.WriteLine(pTlc.X.ToString() + ":" + pTlc.Y.ToString());

            //}
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The watermark image is then blended to the bottom right corner of the pixel block. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            BitmapData wMBitmapData = null;
            double pixelValue = 0.0;
            int wmRow = 0;
            int wmCol = 0;
            try
            {
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);

                int wMBandOffset = 0;

                #region Reference Raster Properties
                // Get the pixel type of the reference raster to see if
                // it is compatible (8 bit).
                IRasterProps referenceProps = (IRasterProps)pRaster;
                if (referenceProps.PixelType != rstPixelType.PT_UCHAR &&
                    referenceProps.PixelType != rstPixelType.PT_CHAR)
                {
                    throw new System.Exception(
                        "Function can only be applied to 8bit data.");
                }

                #endregion

                #region Load watermark image object
                // Create new image object for the watermark image.
                myWatermarkImage = new Bitmap(myWatermarkImagePath);
                // Read number of bands of the watermark image.
                if (myWatermarkImage.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
                    wMBandOffset = 4;
                else
                {
                    if (myWatermarkImage.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)
                        wMBandOffset = 3;
                    else
                    {
                        throw new System.Exception(
                            "Invalid bitmap. Please provide one with 8bits per band in ARGB or RGB format.");
                    }
                }
                #endregion

                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                int wMHeight = myWatermarkImage.Height;
                int wMWidth = myWatermarkImage.Width;
                int x_gap = xgap;
                int y_gap = ygap;

                #region Prepare Watermark Image for reading
                // Get the pixels from the watermark image using the lockbits function.
                wMBitmapData = myWatermarkImage.LockBits(new Rectangle(0, 0, wMWidth, wMHeight),
                    ImageLockMode.ReadOnly, myWatermarkImage.PixelFormat);

                System.IntPtr wMScan0 = wMBitmapData.Scan0;
                int wMStride = wMBitmapData.Stride;
                #endregion

                // The unsafe keyword is used so that pointers can be used to access pixels
                // from the watermark image.
                unsafe
                {
                    int wMPaddingOffset = wMStride - (wMWidth * wMBandOffset);

                    // Start filling from the correct row, col in the pixelblock
                    // using the indices calculated above
                    System.Array pixelValues;
                    if (pPixelBlock.Planes == 3)
                    {
                        if (wMBandOffset == 4) // To check for transparency in WM Image
                        {
                            #region 3 Band PixelBlock
                            for (int nBand = 0; nBand < pPixelBlock.Planes; ++nBand)
                            {
                                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                                pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                                byte* wMStartByte = (byte*)(void*)wMScan0;
                                wmRow = 0;
                                for (int i = 0; i < pBHeight; i++)
                                {
                                    wmCol = 0;
                                    byte* wMColStartByte = wMStartByte;
                                    for (int k = 0; k < pBWidth; k++)
                                    {
                                        pixelValue = Convert.ToDouble(pixelValues.GetValue(k, i));
                                        if (Convert.ToDouble(wMStartByte[3]) != 0.0 &&
                                            Convert.ToByte(ipPixelBlock.GetNoDataMaskVal(nBand, k, i)) == 1)
                                        {
                                            // Blend the pixelValue from the PixelBlock with the corresponding
                                            // pixel from the watermark image.
                                            pixelValue = ((1 - blendValue) * pixelValue) + (blendValue *
                                                Convert.ToDouble(wMStartByte[2 - nBand]));
                                            pixelValues.SetValue(Convert.ToByte(pixelValue), k, i);
                                        }

                                        if (wmCol == wMWidth - 1)
                                        {
                                            wmCol = 0;
                                            wMStartByte = wMColStartByte;
                                            k += x_gap;
                                        }
                                        else
                                        {
                                            ++wmCol;
                                            wMStartByte += wMBandOffset;
                                        }
                                    }
                                    wMStartByte = wMColStartByte + wMWidth * wMBandOffset;
                                    if (wmRow == wMHeight - 1)
                                    {
                                        wmRow = 0;
                                        wMStartByte = (byte*)(void*)wMScan0;
                                        i += y_gap;
                                    }
                                    else
                                    {
                                        ++wmRow;
                                        wMStartByte += wMPaddingOffset;

                                    }

                                }
                                ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                            }
                            #endregion
                        }
                    }
                }

                #region Cleanup
                myWatermarkImage.UnlockBits(wMBitmapData);
                myWatermarkImage.Dispose();
                myWatermarkImage = null;
                wMBitmapData = null;
                wMScan0 = (System.IntPtr)null;
                wMStride = 0;
                #endregion
            }
            catch (Exception exc)
            {
                #region Cleanup
                if (wMBitmapData != null)
                    myWatermarkImage.UnlockBits(wMBitmapData);
                wMBitmapData = null;
                if (myWatermarkImage != null)
                    myWatermarkImage.Dispose();
                myWatermarkImage = null;
                #endregion

                System.Exception myExc = new System.Exception(
                    "Exception caught in Read method of Watermark Function. " + exc.Message, exc);
                throw myExc;
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.

                //System.Array noDataValueArr = (System.Array)((IRasterProps)inrsBandsCoef).NoDataValue;
                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                //Console.WriteLine("After Read");
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);//independent variables
                myFunctionHelperCoef.Read(pTlc, null,myFunctionHelperCoef.Raster,(IPixelBlock)outPb);
                int pBRowIndex = 0;
                int pBColIndex = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array[] pArr = new System.Array[ipPixelBlock.Planes];
                for (int coefnBand = 0; coefnBand < ipPixelBlock.Planes; coefnBand++)
                {
                    System.Array pixelValues = (System.Array)(pPixelBlock.get_SafeArray(coefnBand));
                    pArr[coefnBand] = pixelValues;
                }
                for (int i = pBRowIndex; i < pBHeight; i++)
                {
                    for (int k = pBColIndex; k < pBWidth; k++)
                    {
                        object pObj = outPb.GetVal(0, k, i);

                        if (pObj == null)
                        {
                            continue;
                        }
                        else
                        {
                            string pixelValue = pObj.ToString();
                            double[] c;
                            if (tDic.TryGetValue(pixelValue, out c))
                            {
                                for (int v = 0; v < pArr.Length; v++)
                                {
                                    rstPixelType pty = pPixelBlock.get_PixelType(v);
                                    float vl = System.Convert.ToSingle(c[v]);
                                    object newVl = rasterUtil.getSafeValue(vl, pty);
                                    pArr[v].SetValue(newVl, k, i);
                                }
                            }
                            else
                            {
                                for (int v = 0; v < pArr.Length; v++)
                                {
                                    pArr.SetValue(0, k, i);
                                }
                            }
                        }

                    }
                }
                for (int i = 0; i < pArr.Length; i++)
                {
                    ipPixelBlock.set_PixelData(i, pArr[i]);
                }

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of TTest Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array[] inArr = new System.Array[inrsBands.RasterInfo.BandCount];
                IRasterBandCollection rsBc = (IRasterBandCollection)inrsBands;
                for (int p = 0; p < inArr.Length; p++)
                {
                    IRasterBand rsB = rsBc.Item(p);
                    IRawPixels rP = (IRawPixels)rsB;
                    IPixelBlock pb = rP.CreatePixelBlock(pbSize);
                    IPixelBlock3 pb3 = (IPixelBlock3)pb;
                    rP.Read(pTlc,pb);
                    inArr[p] = (System.Array)pb3.get_PixelData(0);
                }
                System.Array outArr = (System.Array)pPixelBlock.get_SafeArray(0);
                rstPixelType rsPt = pPixelBlock.get_PixelType(0);
                for (int r = 0; r < ipPixelBlock.Height; r++)
                {
                    for (int c = 0; c < ipPixelBlock.Width; c++)
                    {
                        object outVlObj = ipPixelBlock.GetVal(0, c, r);
                        if (outVlObj != null)
                        {
                            float outVl;
                            if (getOutPutVl(inArr, c, r, out outVl))
                            {
                                object newVl = rasterUtil.getSafeValue(outVl, rsPt);//convertVl(outVl,rsPt);
                                outArr.SetValue(newVl, c, r);
                            }
                        }
                    }
                }
                ipPixelBlock.set_PixelData(0, outArr);

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of localMean Function. " + exc.Message, exc);
                Console.Write(exc.ToString());
                throw myExc;
            }
        }
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock, int clms, int rws, IRasterFunctionHelper orig, rasterUtil.windowType wd)
        {
            try
            {
                if (wd == rasterUtil.windowType.RECTANGLE)
                {
                    try
                    {
                       int pBHeight = pPixelBlock.Height;
                        int pBWidth = pPixelBlock.Width;
                        IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                        IPnt pbBigSize = new PntClass();
                        IPnt pbBigLoc = new PntClass();
                        int l, t;
                        l = clms / 2;
                        t = rws / 2;
                        int pbBigWd = pBWidth + clms;// -1;
                        int pbBigHt = pBHeight + rws;// -1;
                        pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
                        pbBigSize.SetCoords(pbBigWd, pbBigHt);
                        IPixelBlock3 pbBig = (IPixelBlock3)orig.Raster.CreatePixelBlock(pbBigSize);
                        orig.Read(pbBigLoc, null,orig.Raster, (IPixelBlock)pbBig);

                        object[,] clmsValues = new object[pBWidth, pBHeight];
                        for (int nBand = 0; nBand < pbBig.Planes; nBand++)
                        {
                            float[,] pixelValues = (float[,])(ipPixelBlock.get_PixelData(nBand));
                            float[,] pixelValuesBig = (float[,])(pbBig.get_PixelData(nBand));
                            for (int r = 0; r < pBHeight; r++)//coordinates in terms of the small pixel block
                            {
                                int er = r + rws;
                                for (int c = 0; c < pBWidth; c++)
                                {
                                    int ec = c + clms;

                                    Dictionary<int, int[]> uDic = findUniqueRegions.getUniqueRegions(pixelValuesBig, ec,er,clms,rws,c,r,(float)rasterUtil.getNoDataValue(rstPixelType.PT_FLOAT)); //key(int) = cell value value(int[2] = number of cells and number of edges)
                                    float uniqueMax = findUniqueRegionsValue(uDic);

                                    pixelValues.SetValue(uniqueMax, c, r);
                                }
                            }
                            try
                            {
                                ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        System.Exception myExc = new System.Exception("Exception caught in neighborhood landscape base rectangle helper Function. " + e.Message, e);
                        throw myExc;
                    }
                }
                else
                {

                    try
                    {
                        List<int[]> iter = new List<int[]>();
                        int[,] circleWindow = rasterUtil.createFocalWidow(clms, clms, wd,out iter);
                        System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                        int pBHeight = pPixelBlock.Height;
                        int pBWidth = pPixelBlock.Width;
                        IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                        IPnt pbBigSize = new PntClass();
                        IPnt pbBigLoc = new PntClass();
                        int pbBigWd = pBWidth + clms;
                        int pbBigHt = pBHeight + rws;
                        int l, t;
                        l = clms / 2;
                        t = rws / 2;
                        pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
                        pbBigSize.SetCoords(pbBigWd, pbBigHt);
                        IPixelBlock3 pbBig = (IPixelBlock3)orig.Raster.CreatePixelBlock(pbBigSize);
                        orig.Read(pbBigLoc,null,orig.Raster, (IPixelBlock)pbBig);
                        object[,] clmsValues = new object[pBWidth, pBHeight];
                        for (int nBand = 0; nBand < pbBig.Planes; nBand++)
                        {
                            float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(nBand));
                            float[,] pixelValues = (float[,])(ipPixelBlock.get_PixelData(nBand));
                            float[,] pixelValuesBig = (float[,])(pbBig.get_PixelData(nBand));
                            for (int r = 0; r < pBHeight; r++)
                            {
                                int er = r + rws;
                                for (int c = 0; c < pBWidth; c++)
                                {
                                    int ec = c + clms;

                                    Dictionary<int, int[]> uDic = findUniqueRegions.getUniqueRegions(pixelValuesBig, ec, er,clms,rws,c,r, noDataValue, circleWindow); //key(int) = cell value value(int[2] = number of cells and number of edges)
                                    float uniqueMax = findUniqueRegionsValue(uDic);

                                    try
                                    {
                                        pixelValues.SetValue(uniqueMax, c, r);
                                    }
                                    catch
                                    {
                                        pixelValues.SetValue(noDataValue, c, r);
                                    }
                                }
                            }
                            ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                        }
                    }
                    catch (Exception e)
                    {
                        System.Exception myExc = new System.Exception("Exception caught in neighborhood landscape base circle helper Function. " + e.Message, e);
                        throw myExc;
                    }
                }
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in neighborhood landscape base helper Function. " + exc.Message, exc);
                throw myExc;
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);//independent variables
                myFunctionHelperCoef.Read(pTlc,null,myFunctionHelperCoef.Raster, (IPixelBlock)outPb);
                int pBRowIndex = 0;
                int pBColIndex = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array[] cArr = new System.Array[ipPixelBlock.Planes];
                for (int outBand = 0; outBand < ipPixelBlock.Planes; outBand++)
                {
                    System.Array pixelValues = (System.Array)ipPixelBlock.get_PixelData(outBand);//(System.Array)(td);
                    cArr[outBand] = pixelValues;
                }

                for (int i = pBRowIndex; i < pBHeight; i++)
                {
                    for (int k = pBColIndex; k < pBWidth; k++)
                    {
                        bool ndT = true;
                        for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                        {
                            object pObj = outPb.GetVal(coefnBand, k, i);
                            if (pObj==null)
                            {
                                ndT = false;
                                break;
                            }
                            double pixelValue = Convert.ToDouble(pObj);
                            xVls[coefnBand] = pixelValue;
                        }
                        if (ndT)
                        {
                            try
                            {
                                double[] pp = lm.computNew(xVls);
                                for (int p = 0; p < pp.Length; p++)
                                {
                                    double pVl = pp[p];
                                    object spVl = rasterUtil.getSafeValue(pVl,ipPixelBlock.get_PixelType(p));
                                    cArr[p].SetValue(spVl, k, i);
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.ToString());
                                for (int p = 0; p < ipPixelBlock.Planes; p++)
                                {
                                    cArr[p].SetValue(0, k, i);
                                }
                            }
                        }
                        else
                        {
                            for (int p = 0; p < ipPixelBlock.Planes; p++)
                            {
                                cArr[p].SetValue(0, k, i);
                            }
                        }

                    }
                }
                for(int i=0;i<ipPixelBlock.Planes;i++)
                {
                    ipPixelBlock.set_PixelData(i,cArr[i]);
                }
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of Regression Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                //IPixelBlock3 inVlsPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);
                //myFunctionHelperCoef.Read(pTlc,null,myFunctionHelperCoef.Raster, (IPixelBlock)inVlsPb);
                IPixelBlock3 outPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array outArr = (System.Array)outPixelBlock.get_PixelData(0);
                System.Array[] inArr = new System.Array[inrs.RasterInfo.BandCount];
                IRasterBandCollection rsBc = (IRasterBandCollection)inrs;
                for (int b = 0; b < inrs.RasterInfo.BandCount; b++)
                {
                    IRasterBand rsB = rsBc.Item(b);
                    IRawPixels rPix = (IRawPixels)rsB;
                    IPixelBlock pb = rPix.CreatePixelBlock(pbSize);
                    rPix.Read(pTlc,pb);
                    inArr[b] = (System.Array)pb.get_SafeArray(b);
                }
                updateOutArr(outPixelBlock, inArr, outArr);
                outPixelBlock.set_PixelData(0, outArr);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster. 
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         IPnt pntSize = new PntClass();
         pntSize.SetCoords(pPixelBlock.Width,pPixelBlock.Height);
         IPixelBlock3 pb3 = (IPixelBlock3)pPixelBlock;
         for (int nBand = 0; nBand < pPixelBlock.Planes; nBand++)
         {
             //float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(nBand));
             object dArr = vPb.get_PixelData(nBand);
             pb3.set_PixelData(nBand,dArr);
         }
     }
     catch (Exception exc)
     {
         System.Exception myExc = new System.Exception("Exception caught in Read method PixelBlock To Raster Function. " + exc.Message, exc);
         throw myExc;
     }
 }
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster. 
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         IPnt pntSize = new PntClass();
         pntSize.SetCoords(pPixelBlock.Width, pPixelBlock.Height);
         IPixelBlock vPb = myFunctionHelper2.Raster.CreatePixelBlock(pntSize);
         myFunctionHelper2.Read(pTlc, null, myFunctionHelper2.Raster, vPb);
         IPixelBlock3 pb3 = (IPixelBlock3)pPixelBlock;
         object intArr = calcMeanShift((IPixelBlock3)vPb,pb3);
         pb3.set_PixelData(0, intArr);
     }
     catch (Exception exc)
     {
         System.Exception myExc = new System.Exception("Exception caught in Read method Mean-shift Function. " + exc.Message, exc);
         throw myExc;
     }
 }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array[] outArr = new System.Array[bndCnt];
                int pbHeight = ipPixelBlock.Height;
                int pbWidth = ipPixelBlock.Width;
                for (int p = 0; p < ipPixelBlock.Planes; p++)
                {
                    outArr[p] = (System.Array)ipPixelBlock.get_PixelData(p);
                }

                for (int r = 0; r < pbHeight; r++)
                {
                    for (int c = 0; c < pbWidth; c++)
                    {
                        object vlObj = ipPixelBlock.GetVal(0,c,r);
                        if (vlObj!=null)
                        {
                            float vl = System.Convert.ToSingle(vlObj);
                            getOutPutVl(ipPixelBlock, outArr, vl, c, r);
                        }

                    }
                }
                for (int p = 0; p < ipPixelBlock.Planes; p++)
                {
                    ipPixelBlock.set_PixelData(p, outArr[p]);
                }

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of localMean Function. " + exc.Message, exc);
                throw myExc;
            }
        }
 private void middleRowColumn(IPnt loc)
 {
     double x = loc.X;
     double y = loc.Y;
     string outLocStr = x.ToString() + ":" + y.ToString();
     IPnt readLoc = new PntClass();
     readLoc.SetCoords(x - 1, y - 1);
     IRasterEdit regRsE = (IRasterEdit)OutRaster;
     IPnt writePbSize = new PntClass();
     writePbSize.SetCoords(pbwidth, pbheight);
     IPnt readPbSize = new PntClass();
     readPbSize.SetCoords(pbwidth + 2, pbheight + 2);
     IPixelBlock pb = inRs.CreatePixelBlock(readPbSize);
     IPixelBlock pb2 = OutRaster.CreatePixelBlock(writePbSize);
     System.Array[] inOutArr;
     System.Array inArr = null;
     System.Array outArr = null;
     if (outArrDic.TryGetValue(outLocStr, out inOutArr))
     {
         inArr = inOutArr[0];
         outArr = inOutArr[1];
     }
     else
     {
         OutRaster.Read(loc, pb2);
         inRs.Read(readLoc, pb);
         OutRaster.Read(loc, pb2);
         inArr = (System.Array)pb.get_SafeArray(0);
         outArr = (System.Array)pb2.get_SafeArray(0);
         outArrDic[outLocStr] = new System.Array[] { inArr, outArr };
     }
     int height = pb2.Height;
     int width = pb2.Width;
     for (int c = 0; c < width; c++)
     {
         int ic = c + 1;
         for (int r = 0; r < height; r++)
         {
             List<string> cr = new List<string>();
             cr.Add(c.ToString()+":"+r.ToString());
             int ir = r + 1;
             int inVl = System.Convert.ToInt32(inArr.GetValue(ic, ir));
             //Console.WriteLine("Invalue = " + inVl.ToString());
             if ((inVl == noDataVl) || (inVl == (noDataVl - 1)))
             {
                 Console.WriteLine("Invalue = " + inVl.ToString());
                 continue;
             }
             else
             {
                 int outVl32 = System.Convert.ToInt32(outArr.GetValue(c, r));
                 if (outVl32 == noDataVl2)
                 {
                     rCnt = 0;
                     rPerm = 0;
                     outArr.SetValue(counter, c, r);
                     List<int>[] nextArray = { new List<int>(), new List<int>(), new List<int>(), new List<int>() };//determines if the next pixel block must be queried {left,top,right,bottom}
                     while (cr.Count > 0)
                     {
                         rCnt++;
                         rPerm += findRegion(inVl, counter, noDataVl2, inArr, outArr, cr, nextArray);
                     }
                     for (int i = 0; i < nextArray.Length; i++)
                     {
                         List<int> pbNextLst = nextArray[i];
                         if (pbNextLst.Count > 0)
                         {
                             int[] startClms = new int[pbNextLst.Count];
                             int[] startRws = new int[pbNextLst.Count];
                             IPnt newLoc = new PntClass();
                             double nClP = loc.X;
                             double nRwP = loc.Y;
                             switch (i)
                             {
                                 case 0:
                                     nClP = nClP - pbwidth;
                                     startRws = pbNextLst.ToArray();
                                     int stcl = pbwidth - 1;
                                     for (int k = 0; k < startRws.Length; k++)
                                     {
                                         startClms[k] = stcl;
                                     }
                                     break;
                                 case 1:
                                     nRwP = nRwP - pbheight;
                                     startClms = pbNextLst.ToArray();//rws=pbHeight-1
                                     int strw = pbheight - 1;
                                     for (int k = 0; k < startClms.Length; k++)
                                     {
                                         startRws[k] = strw;
                                     }
                                     break;
                                 case 2:
                                     nClP = nClP + pbwidth;
                                     startRws = pbNextLst.ToArray();//clms=0;
                                     break;
                                 default:
                                     nRwP = nRwP + pbheight;
                                     startClms = pbNextLst.ToArray();//rws = 0;
                                     break;
                             }
                             if ((nClP >= 0 && nRwP >= 0 & nClP <= rsProps2.Width && nRwP <= rsProps2.Height))
                             {
                                 newLoc.SetCoords(nClP, nRwP);
                                 middleRowColumn(newLoc, startRws, startClms);
                             }
                         }
                     }
                     IRow row = vatTable.CreateRow();
                     row.set_Value(valueIndex, counter);
                     row.set_Value(countIndex, rCnt);
                     row.set_Value(permIndex, rPerm);
                     row.Store();
                     counter++;
                 }
                 else
                 {
                 }
             }
         }
     }
     pb2.set_SafeArray(0, (System.Array)outArr);
     regRsE.Write(loc, pb2);
     outArrDic.Remove(outLocStr);
 }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.

                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IRaster mosRs = (IRaster)mos;
                IPnt pntSize = new PntClass();
                pntSize.SetCoords(pPixelBlock.Width, pPixelBlock.Height);
                IPixelBlock pb = mosRs.CreatePixelBlock(pntSize);
                mosRs.Read(pTlc, pb);
                for (int i = 0; i < pb.Planes; i++)
                {
                    pPixelBlock.set_SafeArray(i, pb.get_SafeArray(i));
                }

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of mosaic Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster. 
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         pFilt.Filter(pPixelBlock);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
     finally
     {
     }
 }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                //System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                IPnt pbBigSize = new PntClass();
                IPnt pbBigLoc = new PntClass();
                int pbBigWd = pBWidth + clms;
                int pbBigHt = pBHeight + rws;
                int l, t;
                l = clms / 2;
                t = rws / 2;
                pbBigSize.SetCoords(pbBigWd, pbBigHt);
                pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
                IPixelBlock3 pbBig = (IPixelBlock3)myFunctionHelperOrig.Raster.CreatePixelBlock(pbBigSize);
                myFunctionHelperOrig.Read(pbBigLoc,null,myFunctionHelperOrig.Raster, (IPixelBlock)pbBig);
                noDataValue = float.MinValue;//System.Convert.ToSingle(noDataValueArr.GetValue(0));
                for (int nBand = 0; nBand < ipPixelBlock.Planes; nBand++)
                {
                    rstPixelType pbt = ipPixelBlock.get_PixelType(nBand);
                    System.Array pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                    for (int r = 0; r < pBHeight; r++)
                    {
                        for (int c = 0; c < pBWidth; c++)
                        {
                            object inVlobj = ipPixelBlock.GetVal(nBand, c, r);
                            if (inVlobj==null)
                            {
                                continue;
                            }
                            else
                            {
                                updateGLCMDic(pbBig, c, r, nBand);
                                float outVl = System.Convert.ToSingle(getTransformedValue(countDic));
                                object newVl = rasterUtil.getSafeValue(outVl, pbt);
                                pixelValues.SetValue(newVl,c,r);
                            }
                        }

                    }
                    ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                // Call Read method of the Raster Function Helper object.

                //Console.WriteLine("Before Read");
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                IRaster2 rs2 = (IRaster2)pRaster;
                double pX,pY;
                rs2.PixelToMap(System.Convert.ToInt32(pTlc.X), System.Convert.ToInt32(pTlc.Y), out pX, out pY);
                //Console.WriteLine("After Read");
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IEnvelope env = new EnvelopeClass();
                env.PutCoords(pX, pY - pBHeight, pX + pBWidth, pY);
                updateWithMergedValues(env,ipPixelBlock);

            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of merge Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                IPnt pbBigSize = new PntClass();
                IPnt pbBigLoc = new PntClass();
                int pbBigWd = pBWidth + clms;
                int pbBigHt = pBHeight + rws;
                int l, t;
                l = (clms-1) / 2;
                t = (rws-1) / 2;
                //Console.WriteLine("lt = " + (pTlc.X - l).ToString() + ":" + (pTlc.Y - t).ToString());
                pbBigSize.SetCoords(pbBigWd, pbBigHt);
                pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
                IPixelBlock3 pbBig = (IPixelBlock3)myFunctionHelperOrig.Raster.CreatePixelBlock(pbBigSize);
                myFunctionHelperOrig.Read(pbBigLoc, null, myFunctionHelperOrig.Raster, (IPixelBlock)pbBig);
                for (int nBand = 0; nBand < pbBig.Planes; nBand++)
                {

                    System.Array pixelValues = (System.Array)(ipPixelBlock.get_PixelData(nBand));
                    rstPixelType rsp = ipPixelBlock.get_PixelType(nBand);
                    //System.Array pixelValuesBig = (System.Array)(pbBig.get_PixelData(nBand));
                    for (int r = 0; r < pBHeight; r++)
                    {
                        for (int c = 0; c < pBWidth; c++)
                        {
                            object objVl = ipPixelBlock.GetVal(nBand,c, r);
                            if (objVl==null)
                            {
                                continue;
                            }
                            else
                            {
                                float outVl = System.Convert.ToSingle(getTransformedValue(pbBig, c+l, r+t,nBand));
                                object newVl = rasterUtil.getSafeValue(outVl, rsp);
                                //Console.WriteLine(outVl.ToString());
                                pixelValues.SetValue(newVl,c, r);
                            }
                        }

                    }
                    ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);

                }

            }
            catch(Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampeling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            try
            {
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                int pBHeight = pPixelBlock.Height;
                int pBWidth = pPixelBlock.Width;
                IPnt pbSize = new PntClass();
                pbSize.SetCoords(pBWidth, pBHeight);
                IPixelBlock3 outPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);//independent variables
                myFunctionHelperCoef.Read(pTlc,null,myFunctionHelperCoef.Raster, (IPixelBlock)outPb);
                int pBRowIndex = 0;
                int pBColIndex = 0;
                IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                System.Array[] cArr = new System.Array[ipPixelBlock.Planes];
                for (int outBand = 0; outBand < ipPixelBlock.Planes; outBand++)
                {
                    System.Array pixelValues = (System.Array)ipPixelBlock.get_PixelData(outBand);
                    cArr[outBand] = pixelValues;
                }
                for (int i = pBRowIndex; i < pBHeight; i++)
                {
                    for (int k = pBColIndex; k < pBWidth; k++)
                    {
                        double[] expArr = new double[slopes.Length];
                        double sumExp = 0;
                        int catCnts = 0;
                        bool noDataCheck = true;
                        foreach (double[] IntSlpArr in slopes)
                        {
                            double sumVls = IntSlpArr[0];
                            for (int coefnBand = 0; coefnBand < outPb.Planes; coefnBand++)
                            {
                                object coefnVlObj = outPb.GetVal(coefnBand, k, i);
                                //Console.WriteLine("Slope X value = " + pixelValue.ToString());
                                if (coefnVlObj==null)
                                {
                                    noDataCheck = false;
                                    break;
                                }
                                double slp = IntSlpArr[coefnBand + 1];
                                //Console.WriteLine("x = " + pixelValue.ToString() + " slope = " + slp.ToString());
                                sumVls += System.Convert.ToDouble(coefnVlObj) * slp;
                            }
                            if (noDataCheck)
                            {
                                double expSum = Math.Exp(sumVls);
                                expArr[catCnts] = expSum;
                                sumExp += expSum;
                                catCnts += 1;
                                //Console.WriteLine("sumVls = " + sumVls.ToString());
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (noDataCheck)
                        {
                            sumExp += 1;
                            double sumProb = 0;
                            catCnts = 1;
                            foreach (double expVl in expArr)
                            {
                                rstPixelType pTy = ipPixelBlock.get_PixelType(catCnts);
                                double prob = expVl / sumExp;
                                //Console.WriteLine("Probability = " + prob.ToString());
                                sumProb += prob;
                                object newVl = rasterUtil.getSafeValue(prob, pTy);
                                cArr[catCnts].SetValue(newVl, k, i);
                                //Console.WriteLine("Probability = " + cArr[catCnts].GetValue(k,i).ToString());
                                catCnts += 1;

                            }
                            rstPixelType pTy2 = ipPixelBlock.get_PixelType(0);
                            double lProb = 1 - sumProb;
                            object newVl2 = rasterUtil.getSafeValue(lProb, pTy2);
                            cArr[0].SetValue(newVl2, k, i);//base category
                        }
                        else
                        {
                            for (int b = 0; b < ipPixelBlock.Planes; b++)
                            {
                                cArr[b].SetValue(0, k, i);
                            }

                        }
                    }
                }
                for(int i=0;i<ipPixelBlock.Planes;i++)
                {
                    ipPixelBlock.set_PixelData(i,cArr[i]);
                }
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method of Regression Function. " + exc.Message, exc);
                Console.WriteLine(exc.ToString());
            }
        }
 /// <summary>
 /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
 /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
 /// The log raster is the natural log of the raster. 
 /// </summary>
 /// <param name="pTlc">Point to start the reading from in the Raster</param>
 /// <param name="pRaster">Reference Raster for the PixelBlock</param>
 /// <param name="pPixelBlock">PixelBlock to be filled in</param>
 public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
 {
     try
     {
         myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
         #region Load log object
         int pBHeight = pPixelBlock.Height;
         int pBWidth = pPixelBlock.Width;
         Pnt pbSize = new PntClass();
         pbSize.SetCoords(pPixelBlock.Width,pPixelBlock.Height);
         IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
         System.Array outPutArr = (System.Array)ipPixelBlock.get_PixelData(0);
         IPixelBlock3 CoefPb = (IPixelBlock3)myFunctionHelperCoef.Raster.CreatePixelBlock(pbSize);
         myFunctionHelperCoef.Read(pTlc, null, myFunctionHelperCoef.Raster, (IPixelBlock)CoefPb);
         for (int r = 0; r < ipPixelBlock.Height; r++)
         {
             for (int c = 0; c < ipPixelBlock.Width; c++)
             {
                 object vlObj = CoefPb.GetVal(0, c, r);
                 if (vlObj != null)
                 {
                     if ((float)vlObj > 0)
                     {
                         vlObj = CoefPb.GetVal(1, c, r);
                     }
                     else
                     {
                         vlObj = CoefPb.GetVal(2, c, r);
                     }
                     if (vlObj != null)
                     {
                         outPutArr.SetValue(vlObj, c, r);
                     }
                 }
             }
         }
         ipPixelBlock.set_PixelData(0,outPutArr);
         #endregion
     }
     catch (Exception exc)
     {
         System.Exception myExc = new System.Exception("Exception caught in Read method of con Function. " + exc.Message, exc);
         throw myExc;
     }
 }
        /// <summary>
        /// Read pixels from the input Raster and fill the PixelBlock provided with processed pixels.
        /// The RasterFunctionHelper object is used to handle pixel type conversion and resampling.
        /// The log raster is the natural log of the raster. 
        /// </summary>
        /// <param name="pTlc">Point to start the reading from in the Raster</param>
        /// <param name="pRaster">Reference Raster for the PixelBlock</param>
        /// <param name="pPixelBlock">PixelBlock to be filled in</param>
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock)
        {
            double vl = 0;
            float pixelValue = 0f;
            try
            {
                System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                // Call Read method of the Raster Function Helper object.
                myFunctionHelper.Read(pTlc, null, pRaster, pPixelBlock);
                IPixelBlock3 pb3 = (IPixelBlock3)pPixelBlock;
                #region Load log object
                for (int nBand = 0; nBand < pPixelBlock.Planes; nBand++)
                {
                    float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(nBand));
                    System.Array dArr = (System.Array)pb3.get_PixelData(nBand);
                    for (int r = 0; r < pPixelBlock.Height; r++)
                    {
                        for (int c = 0; c < pPixelBlock.Width; c++)
                        {
                            vl = System.Convert.ToDouble(dArr.GetValue(c, r));
                            if (rasterUtil.isNullData(System.Convert.ToSingle(vl), noDataValue))
                            {
                                continue;
                            }
                            pixelValue = System.Convert.ToSingle(getFunctionValue(vl));
                            dArr.SetValue(pixelValue, c, r);
                        }
                    }
                    pb3.set_PixelData(nBand, dArr);
                    //unsafe
                    //{
                    //    System.Array dArr = (System.Array)pb3.get_PixelData(nBand);
                    //    int lng = dArr.Length;
                    //    fixed (float* dValue = (float[,])dArr)
                    //    {
                    //        for (int i = 0; i < lng; i++)
                    //        {
                    //            pixelValue = *(dValue + i);
                    //            if (rasterUtil.isNullData(pixelValue, noDataValue))
                    //            {
                    //                continue;
                    //            }
                    //            pixelValue = System.Convert.ToSingle(getFunctionValue(pixelValue));
                    //            *(dValue + i) = pixelValue;

                    //        }
                    //        pb3.set_PixelData(nBand, dArr);
                    //    }
                    //}

                }
                #endregion
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in Read method math Function. " + exc.Message, exc);
                throw myExc;
            }
        }
示例#60
0
文件: Pixel.cs 项目: nazzal88/ares
 /// <summary>
 /// Initialize a new instance of Pixel class.
 /// </summary>
 /// <param name="pnt"></param>
 public Pixel(IPnt pnt)
 {
     this.position = new Position((int)pnt.X, (int)pnt.Y);
 }