Example #1
0
 public void Dispose()
 {
     _visitedPixels.Dispose();
     _visitedPixels = null;
     _seeds.Clear();
     _seeds = null;
 }
Example #2
0
        public ContourLine[] Generate(IRasterBand raster, double[] contourValues, int[] aoi, Action <int, string> tracker)
        {
            Size oSize = new Size(raster.Width, raster.Height);
            bool isNewRaster = false;
            int  offsetRow = 0, offsetCol = 0;

            if (aoi != null && aoi.Length > 0)
            {
                //感兴趣区域不采样
                _sample = 1;
                Rectangle rect = AOIHelper.ComputeAOIRect(aoi, oSize);
                offsetRow   = rect.Top;
                offsetCol   = rect.Left;
                raster      = GetAOIRaster(raster, aoi, rect, oSize);
                isNewRaster = true;
            }
            _raster         = raster;
            _width          = raster.Width / _sample;
            _height         = raster.Height / _sample;
            _gridWidth      = _width - 1;
            _gridHeight     = _height - 1;
            _triWidth       = _gridWidth * 2;
            _contourValues  = contourValues;
            _triangleCount  = 2 * _gridWidth * _gridHeight;
            _triangleIsUsed = new StatusRecorder(_triangleCount);
            _edgeCount      = _gridWidth * _height + _gridHeight * _width + _gridWidth * _gridHeight;
            _edgeIsUsed     = new StatusRecorder(_edgeCount);
            try
            {
                if (tracker != null)
                {
                    tracker(0, "正在准备数据...");
                }
                ReadBandValues();
                if (tracker != null)
                {
                    tracker(10, "正在提取边界三角形...");
                }
                GetBorderTriangles();
                if (tracker != null)
                {
                    tracker(12, "正在生成等值线...");
                }
                _contourLines = new List <ContourLine>();
                GenerateContours(tracker);
                if (tracker != null)
                {
                    tracker(100, "等值线生成完毕!");
                }
            }
            finally
            {
                if (isNewRaster)
                {
                    OffsetToFull(_contourLines, offsetRow, offsetCol);
                    raster.Dispose();
                }
            }
            return(_contourLines != null && _contourLines.Count > 0 ? _contourLines.ToArray() : null);
        }
Example #3
0
        public ContourLine[] Generate(int width, int height, double[] contourValues, Action <int, string> tracker)
        {
            bool isNewRaster = false;
            int  offsetRow = 0, offsetCol = 0;

            _width          = width;
            _height         = height;
            _gridWidth      = _width - 1;
            _gridHeight     = _height - 1;
            _triWidth       = _gridWidth * 2;
            _contourValues  = contourValues;
            _triangleCount  = 2 * _gridWidth * _gridHeight;
            _triangleIsUsed = new StatusRecorder(_triangleCount);
            _edgeCount      = _gridWidth * _height + _gridHeight * _width + _gridWidth * _gridHeight;
            _edgeIsUsed     = new StatusRecorder(_edgeCount);

            try
            {
                if (tracker != null)
                {
                    tracker(10, "正在提取边界三角形...");
                }
                GetBorderTriangles();
                if (tracker != null)
                {
                    tracker(12, "正在生成等值线...");
                }
                _contourLines = new List <ContourLine>();
                GenerateContours(tracker);
                if (tracker != null)
                {
                    tracker(100, "等值线生成完毕!");
                }
            }
            finally
            {
                if (isNewRaster)
                {
                    OffsetToFull(_contourLines, offsetRow, offsetCol);
                }
            }
            return(_contourLines != null && _contourLines.Count > 0 ? _contourLines.ToArray() : null);
        }
Example #4
0
 private unsafe void DoMagicWand(BitmapData pdata, Point startPoint, byte tolerance, bool isContinued,
                                 Action <int, int, int> segmentAction, Action regionAction)
 {
     CheckArgBandFillFields(pdata, tolerance, startPoint);
     _visitedPixels = new StatusRecorder(_width * pdata.Height);
     if (isContinued)
     {
         _seeds.Enqueue(startPoint.Y * _width + startPoint.X);
         FloodFill(segmentAction);
         if (regionAction != null)
         {
             regionAction();
         }
     }
     else
     {
         int   count = _width * _height;
         byte *ptr;
         for (int i = 0; i < count; i++)
         {
             if (_visitedPixels.IsTrue(i))
             {
                 continue;
             }
             ptr = (byte *)_scan0 + (i / _width) * _stride + (i % _width) * _pixelWidth;
             if (ColorIsMatched(ptr))
             {
                 _seeds.Enqueue(i);
                 FloodFill(segmentAction);
                 if (regionAction != null)
                 {
                     regionAction();
                 }
             }
             else
             {
                 _visitedPixels.SetStatus(i, true);
             }
         }
     }
 }
Example #5
0
        public static int[] Reversal(int[] aoi, Size size)
        {
            int            count    = size.Width * size.Height;
            StatusRecorder status   = new StatusRecorder(count);
            int            aoiCount = aoi.Length;

            for (int i = 0; i < aoiCount; i++)
            {
                status.SetStatus(aoi[i], true);
            }
            List <int> retAOI = new List <int>(count - aoiCount);

            for (int i = 0; i < count; i++)
            {
                if (!status.IsTrue(i))
                {
                    retAOI.Add(i);
                }
            }
            return(retAOI.Count > 0 ? retAOI.ToArray() : null);
        }