Ejemplo n.º 1
0
        public void ReadLeftSide(RawOutline pathW, bool topDown)
        {
            //read once
            if (_leftSideChecked)
            {
                throw new System.NotSupportedException();
            }

            _leftSideChecked = true;

            if (topDown)
            {
                int count = _spanList.Count;

                RawOutline.BeginLoadSegmentPoints(pathW);
                for (int i = 0; i < count; ++i)
                {
                    HSpan span = _spanList[i];
                    pathW.AppendPoint(span.startX, span.y);
                }
                RawOutline.EndLoadSegmentPoints(pathW);
            }
            else
            {
                RawOutline.BeginLoadSegmentPoints(pathW);
                for (int i = _spanList.Count - 1; i >= 0; --i)
                {
                    HSpan span = _spanList[i];
                    pathW.AppendPoint(span.startX, span.y);
                }
                RawOutline.EndLoadSegmentPoints(pathW);
            }
        }
Ejemplo n.º 2
0
        public static void Simplify(this RawOutline rgnOutline, float tolerance = 0.5f, bool heighQualityEnable = false)
        {
            int j = rgnOutline._contours.Count;

            for (int i = 0; i < j; ++i)
            {
                RawContour   contour          = rgnOutline._contours[i];
                List <Point> simplifiedPoints = new List <Point>(contour._xyCoords.Count);
                PixelFarm.CpuBlit.VertexProcessing.SimplificationHelpers.Simplify(
                    contour._xyCoords,
                    (p1, p2) => p1 == p2,
                    p => p.X,
                    p => p.Y,
                    simplifiedPoints,
                    tolerance,
                    heighQualityEnable);
                //replace current raw contour with the new one
#if DEBUG
                System.Diagnostics.Debug.WriteLine("simplification before:" + contour._xyCoords.Count + ",after" + simplifiedPoints.Count);
#endif

                //create a new raw contour,
                //but you can replace internal data of the old contour too,
                RawContour newContour = new RawContour();
                newContour.IsOutside = contour.IsOutside;
                foreach (Point point in simplifiedPoints)
                {
                    newContour.AddPoint(point);
                }
                rgnOutline._contours[i] = newContour;
            }
        }
Ejemplo n.º 3
0
        void TraceOutlineCcw(Remaining toReadNext, RawOutline output, bool outside)
        {
            output.BeginContour(outside);
            //if we starts on left-side of the column
            ColumnWalkerCcw ccw = new ColumnWalkerCcw(_verticalGroupList);

            ccw.Bind(output);
            //-------------------------------
            for (; ;)
            {
                switch (toReadNext.unreadSide)
                {
                default:
                    throw new System.NotSupportedException();

                case ReadSide.Left:
                    ccw.Bind(toReadNext.column);
                    ccw.ReadLeftSide();
                    break;

                case ReadSide.Right:
                    ccw.Bind(toReadNext.column);
                    ccw.ReadRightSide();
                    break;

                case ReadSide.None:
                    //complete
                    output.EndContour();
                    return;
                }
                toReadNext = ccw.FindReadNextColumn();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// trace outline counter-clockwise
        /// </summary>
        /// <param name="output"></param>
        void TraceOutline(HSpan[] sortedHSpans, RawOutline output)
        {
            if (sortedHSpans == null)
            {
                return;
            }
            //
            var sep = new VerticalGroupSeparator(_verticalGroupList);

            sep.Separate(sortedHSpans);

            int vertGroupCount = _verticalGroupList.Count;

            if (vertGroupCount == 0)
            {
                return;
            }

            _verticalGroupList.EvaluateCorners();


            List <Remaining> incompleteReadList = new List <Remaining>();

            TraceOutlineCcw(new Remaining(_verticalGroupList.GetGroup(0).GetColumn(0), ReadSide.Left), output, true);

TRACE_AGAIN:            //**

            //check if the shape have hole(s)
            _verticalGroupList.CollectIncompleteColumns(incompleteReadList);

            if (incompleteReadList.Count > 0)
            {
                //this should be a hole
                Remaining incompleteRead = incompleteReadList[0];
                switch (incompleteRead.unreadSide)
                {
                //?should not occur
                case ReadSide.LeftAndRight:
                {
                    TraceOutlineCcw(new Remaining(incompleteRead.column, ReadSide.Left), output, false);
                    incompleteReadList.Clear();

                    goto TRACE_AGAIN;
                }

                case ReadSide.Left:
                case ReadSide.Right:
                {
                    TraceOutlineCcw(incompleteRead, output, false);
                    incompleteReadList.Clear();
                    goto TRACE_AGAIN;
                }
                }
            }
            else
            {
                //complete all
            }
        }
Ejemplo n.º 5
0
 public ColumnWalkerCcw(VerticalGroupList verticalGroupList)
 {
     _pathWriter            = null;
     _latestReadOnRightSide = false;
     _vertGroupList         = verticalGroupList;
     _vertGroupCount        = verticalGroupList.Count;
     _currentCol            = null;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// reconstruct regionOutline from internal region data
        /// </summary>
        /// <param name="rgnOutline"></param>
        public static void ReconstructOutline(this ReconstructedRegionData rgnData, RawOutline rgnOutline)
        {
            var outlineTracer = new OutlineTracer();

            outlineTracer.TraceOutline(rgnData, rgnOutline);
        }
Ejemplo n.º 7
0
 internal static void EndLoadSegmentPoints(RawOutline rawPath) => rawPath.OnEndLoadSegmentPoints();
Ejemplo n.º 8
0
 internal static void BeginLoadSegmentPoints(RawOutline rawPath) => rawPath.OnBeginLoadSegmentPoints();
Ejemplo n.º 9
0
 public void TraceOutline(ReconstructedRegionData rgnData, RawOutline output)
 {
     TraceOutline(rgnData.HSpans, output);
 }
Ejemplo n.º 10
0
 public void Bind(RawOutline pathW)
 {
     _pathWriter = pathW;
 }