Пример #1
0
        internal DmtxBresLine(DmtxPixelLoc loc0, DmtxPixelLoc loc1, DmtxPixelLoc locInside)
        {
            int cp;
            DmtxPixelLoc locBeg, locEnd;

            /* Values that stay the same after initialization */
            this._loc0 = loc0;
            this._loc1 = loc1;
            this._xStep = (loc0.X < loc1.X) ? +1 : -1;
            this._yStep = (loc0.Y < loc1.Y) ? +1 : -1;
            this._xDelta = Math.Abs(loc1.X - loc0.X);
            this._yDelta = Math.Abs(loc1.Y - loc0.Y);
            this._steep = (this._yDelta > this._xDelta);

            /* Take cross product to determine outward step */
            if (this._steep)
            {
                /* Point first vector up to get correct sign */
                if (loc0.Y < loc1.Y)
                {
                    locBeg = loc0;
                    locEnd = loc1;
                }
                else
                {
                    locBeg = loc1;
                    locEnd = loc0;
                }
                cp = (((locEnd.X - locBeg.X) * (locInside.Y - locEnd.Y)) -
                      ((locEnd.Y - locBeg.Y) * (locInside.X - locEnd.X)));

                this._xOut = (cp > 0) ? +1 : -1;
                this._yOut = 0;
            }
            else
            {
                /* Point first vector left to get correct sign */
                if (loc0.X > loc1.X)
                {
                    locBeg = loc0;
                    locEnd = loc1;
                }
                else
                {
                    locBeg = loc1;
                    locEnd = loc0;
                }
                cp = (((locEnd.X - locBeg.X) * (locInside.Y - locEnd.Y)) -
                      ((locEnd.Y - locBeg.Y) * (locInside.X - locEnd.X)));

                this._xOut = 0;
                this._yOut = (cp > 0) ? +1 : -1;
            }

            /* Values that change while stepping through line */
            this._loc = loc0;
            this._travel = 0;
            this._outward = 0;
            this._error = (this._steep) ? this._yDelta / 2 : this._xDelta / 2;
        }
Пример #2
0
 internal DmtxBresLine(DmtxBresLine orig)
 {
     this._error = orig._error;
     this._loc   = new DmtxPixelLoc()
     {
         X = orig._loc.X, Y = orig._loc.Y
     };
     this._loc0 = new DmtxPixelLoc()
     {
         X = orig._loc0.X, Y = orig._loc0.Y
     };
     this._loc1 = new DmtxPixelLoc()
     {
         X = orig._loc1.X, Y = orig._loc1.Y
     };
     this._outward = orig._outward;
     this._steep   = orig._steep;
     this._travel  = orig._travel;
     this._xDelta  = orig._xDelta;
     this._xOut    = orig._xOut;
     this._xStep   = orig._xStep;
     this._yDelta  = orig._yDelta;
     this._yOut    = orig._yOut;
     this._yStep   = orig._yStep;
 }
Пример #3
0
        internal bool GetStep(DmtxPixelLoc target, ref int travel, ref int outward)
        {
            /* Determine necessary step along and outward from Bresenham line */
            if (this._steep)
            {
                travel = (this._yStep > 0) ? target.Y - this._loc.Y : this._loc.Y - target.Y;
                Step(travel, 0);
                outward = (this._xOut > 0) ? target.X - this._loc.X : this._loc.X - target.X;
                if (this._yOut != 0)
                {
                    throw new Exception("Invald yOut value for bresline step!");
                }
            }
            else
            {
                travel = (this._xStep > 0) ? target.X - this._loc.X : this._loc.X - target.X;
                Step(travel, 0);
                outward = (this._yOut > 0) ? target.Y - this._loc.Y : this._loc.Y - target.Y;
                if (this._xOut != 0)
                {
                    throw new Exception("Invald xOut value for bresline step!");
                }
            }

            return(true);
        }
Пример #4
0
        internal DmtxRange PopGridLocation(ref DmtxPixelLoc loc)
        {
            DmtxRange locStatus;

            do
            {
                locStatus = GetGridCoordinates(ref loc);

                /* Always leave grid pointing at next available location */
                this._pixelCount++;
            } while (locStatus == DmtxRange.DmtxRangeBad);

            return(locStatus);
        }
Пример #5
0
 internal DmtxBresLine(DmtxBresLine orig)
 {
     this._error = orig._error;
     this._loc = new DmtxPixelLoc() { X = orig._loc.X, Y = orig._loc.Y };
     this._loc0 = new DmtxPixelLoc() { X = orig._loc0.X, Y = orig._loc0.Y };
     this._loc1 = new DmtxPixelLoc() { X = orig._loc1.X, Y = orig._loc1.Y };
     this._outward = orig._outward;
     this._steep = orig._steep;
     this._travel = orig._travel;
     this._xDelta = orig._xDelta;
     this._xOut = orig._xOut;
     this._xStep = orig._xStep;
     this._yDelta = orig._yDelta;
     this._yOut = orig._yOut;
     this._yStep = orig._yStep;
 }
Пример #6
0
 internal DmtxRegion(DmtxRegion src)
 {
     this._bottomAngle = src._bottomAngle;
     this._bottomKnown = src._bottomKnown;
     this._bottomLine = src._bottomLine;
     this._bottomLoc = src._bottomLoc;
     this._boundMax = src._boundMax;
     this._boundMin = src._boundMin;
     this._finalNeg = src._finalNeg;
     this._finalPos = src._finalPos;
     this._fit2raw = new DmtxMatrix3(src._fit2raw);
     this._flowBegin = src._flowBegin;
     this._jumpToNeg = src._jumpToNeg;
     this._jumpToPos = src._jumpToPos;
     this._leftAngle = src._leftAngle;
     this._leftKnown = src._leftKnown;
     this._leftLine = src._leftLine;
     this._leftLoc = src._leftLoc;
     this._locR = src._locR;
     this._locT = src._locT;
     this._mappingCols = src._mappingCols;
     this._mappingRows = src._mappingRows;
     this._offColor = src._offColor;
     this._onColor = src._onColor;
     this._polarity = src._polarity;
     this._raw2fit = new DmtxMatrix3(src._raw2fit);
     this._rightAngle = src._rightAngle;
     this._rightKnown = src._rightKnown;
     this._rightLoc = src._rightLoc;
     this._sizeIdx = src._sizeIdx;
     this._stepR = src._stepR;
     this._stepsTotal = src._stepsTotal;
     this._stepT = src._stepT;
     this._symbolCols = src._symbolCols;
     this._symbolRows = src._symbolRows;
     this._topAngle = src._topAngle;
     this._topKnown = src._topKnown;
     this._topLoc = src._topLoc;
 }
Пример #7
0
 internal DmtxRegion(DmtxRegion src)
 {
     this._bottomAngle = src._bottomAngle;
     this._bottomKnown = src._bottomKnown;
     this._bottomLine  = src._bottomLine;
     this._bottomLoc   = src._bottomLoc;
     this._boundMax    = src._boundMax;
     this._boundMin    = src._boundMin;
     this._finalNeg    = src._finalNeg;
     this._finalPos    = src._finalPos;
     this._fit2raw     = new DmtxMatrix3(src._fit2raw);
     this._flowBegin   = src._flowBegin;
     this._jumpToNeg   = src._jumpToNeg;
     this._jumpToPos   = src._jumpToPos;
     this._leftAngle   = src._leftAngle;
     this._leftKnown   = src._leftKnown;
     this._leftLine    = src._leftLine;
     this._leftLoc     = src._leftLoc;
     this._locR        = src._locR;
     this._locT        = src._locT;
     this._mappingCols = src._mappingCols;
     this._mappingRows = src._mappingRows;
     this._offColor    = src._offColor;
     this._onColor     = src._onColor;
     this._polarity    = src._polarity;
     this._raw2fit     = new DmtxMatrix3(src._raw2fit);
     this._rightAngle  = src._rightAngle;
     this._rightKnown  = src._rightKnown;
     this._rightLoc    = src._rightLoc;
     this._sizeIdx     = src._sizeIdx;
     this._stepR       = src._stepR;
     this._stepsTotal  = src._stepsTotal;
     this._stepT       = src._stepT;
     this._symbolCols  = src._symbolCols;
     this._symbolRows  = src._symbolRows;
     this._topAngle    = src._topAngle;
     this._topKnown    = src._topKnown;
     this._topLoc      = src._topLoc;
 }
Пример #8
0
        internal DmtxBresLine(DmtxPixelLoc loc0, DmtxPixelLoc loc1, DmtxPixelLoc locInside)
        {
            int          cp;
            DmtxPixelLoc locBeg, locEnd;


            /* Values that stay the same after initialization */
            this._loc0   = loc0;
            this._loc1   = loc1;
            this._xStep  = (loc0.X < loc1.X) ? +1 : -1;
            this._yStep  = (loc0.Y < loc1.Y) ? +1 : -1;
            this._xDelta = Math.Abs(loc1.X - loc0.X);
            this._yDelta = Math.Abs(loc1.Y - loc0.Y);
            this._steep  = (this._yDelta > this._xDelta);

            /* Take cross product to determine outward step */
            if (this._steep)
            {
                /* Point first vector up to get correct sign */
                if (loc0.Y < loc1.Y)
                {
                    locBeg = loc0;
                    locEnd = loc1;
                }
                else
                {
                    locBeg = loc1;
                    locEnd = loc0;
                }
                cp = (((locEnd.X - locBeg.X) * (locInside.Y - locEnd.Y)) -
                      ((locEnd.Y - locBeg.Y) * (locInside.X - locEnd.X)));

                this._xOut = (cp > 0) ? +1 : -1;
                this._yOut = 0;
            }
            else
            {
                /* Point first vector left to get correct sign */
                if (loc0.X > loc1.X)
                {
                    locBeg = loc0;
                    locEnd = loc1;
                }
                else
                {
                    locBeg = loc1;
                    locEnd = loc0;
                }
                cp = (((locEnd.X - locBeg.X) * (locInside.Y - locEnd.Y)) -
                      ((locEnd.Y - locBeg.Y) * (locInside.X - locEnd.X)));

                this._xOut = 0;
                this._yOut = (cp > 0) ? +1 : -1;
            }

            /* Values that change while stepping through line */
            this._loc     = loc0;
            this._travel  = 0;
            this._outward = 0;
            this._error   = (this._steep) ? this._yDelta / 2 : this._xDelta / 2;
        }
Пример #9
0
        internal bool Step(int travel, int outward)
        {
            int i;

            if (Math.Abs(travel) >= 2)
            {
                throw new ArgumentException("Invalid value for 'travel' in BaseLineStep!");
            }

            /* Perform forward step */
            if (travel > 0)
            {
                this._travel++;
                if (this._steep)
                {
                    this._loc = new DmtxPixelLoc()
                    {
                        X = this._loc.X, Y = this._loc.Y + this._yStep
                    };
                    this._error -= this._xDelta;
                    if (this._error < 0)
                    {
                        this._loc = new DmtxPixelLoc()
                        {
                            X = this._loc.X + this._xStep, Y = this._loc.Y
                        };
                        this._error += this._yDelta;
                    }
                }
                else
                {
                    this._loc = new DmtxPixelLoc()
                    {
                        X = this._loc.X + this._xStep, Y = this._loc.Y
                    };
                    this._error -= this._yDelta;
                    if (this._error < 0)
                    {
                        this._loc = new DmtxPixelLoc()
                        {
                            X = this._loc.X, Y = this._loc.Y + this._yStep
                        };
                        this._error += this._xDelta;
                    }
                }
            }
            else if (travel < 0)
            {
                this._travel--;
                if (this._steep)
                {
                    this._loc = new DmtxPixelLoc()
                    {
                        X = this._loc.X, Y = this._loc.Y - this._yStep
                    };
                    this._error += this._xDelta;
                    if (this.Error >= this.YDelta)
                    {
                        this._loc = new DmtxPixelLoc()
                        {
                            X = this._loc.X - this._xStep, Y = this._loc.Y
                        };
                        this._error -= this._yDelta;
                    }
                }
                else
                {
                    this._loc = new DmtxPixelLoc()
                    {
                        X = this._loc.X - this._xStep, Y = this._loc.Y
                    };
                    this._error += this._yDelta;
                    if (this._error >= this._xDelta)
                    {
                        this._loc = new DmtxPixelLoc()
                        {
                            X = this._loc.X, Y = this._loc.Y - this._yStep
                        };
                        this._error -= this._xDelta;
                    }
                }
            }

            for (i = 0; i < outward; i++)
            {
                /* Outward steps */
                this._outward++;
                this._loc = new DmtxPixelLoc()
                {
                    X = this._loc.X + this._xOut, Y = this._loc.Y + this._yOut
                };
            }

            return(true);
        }
Пример #10
0
        internal bool Step(int travel, int outward)
        {
            int i;

            if (Math.Abs(travel) >= 2)
            {
                throw new ArgumentException("Invalid value for 'travel' in BaseLineStep!");
            }

            /* Perform forward step */
            if (travel > 0)
            {
                this._travel++;
                if (this._steep)
                {
                    this._loc = new DmtxPixelLoc() { X = this._loc.X, Y = this._loc.Y + this._yStep };
                    this._error -= this._xDelta;
                    if (this._error < 0)
                    {
                        this._loc = new DmtxPixelLoc() { X = this._loc.X + this._xStep, Y = this._loc.Y };
                        this._error += this._yDelta;
                    }
                }
                else
                {
                    this._loc = new DmtxPixelLoc() { X = this._loc.X + this._xStep, Y = this._loc.Y };
                    this._error -= this._yDelta;
                    if (this._error < 0)
                    {
                        this._loc = new DmtxPixelLoc() { X = this._loc.X, Y = this._loc.Y + this._yStep };
                        this._error += this._xDelta;
                    }
                }
            }
            else if (travel < 0)
            {
                this._travel--;
                if (this._steep)
                {
                    this._loc = new DmtxPixelLoc() { X = this._loc.X, Y = this._loc.Y - this._yStep };
                    this._error += this._xDelta;
                    if (this.Error >= this.YDelta)
                    {
                        this._loc = new DmtxPixelLoc() { X = this._loc.X - this._xStep, Y = this._loc.Y };
                        this._error -= this._yDelta;
                    }
                }
                else
                {
                    this._loc = new DmtxPixelLoc() { X = this._loc.X - this._xStep, Y = this._loc.Y };
                    this._error += this._yDelta;
                    if (this._error >= this._xDelta)
                    {
                        this._loc = new DmtxPixelLoc() { X = this._loc.X, Y = this._loc.Y - this._yStep };
                        this._error -= this._xDelta;
                    }
                }
            }

            for (i = 0; i < outward; i++)
            {
                /* Outward steps */
                this._outward++;
                this._loc = new DmtxPixelLoc() { X = this._loc.X + this._xOut, Y = this._loc.Y + this._yOut };
            }

            return true;
        }
Пример #11
0
        internal bool GetStep(DmtxPixelLoc target, ref int travel, ref int outward)
        {
            /* Determine necessary step along and outward from Bresenham line */
            if (this._steep)
            {
                travel = (this._yStep > 0) ? target.Y - this._loc.Y : this._loc.Y - target.Y;
                Step(travel, 0);
                outward = (this._xOut > 0) ? target.X - this._loc.X : this._loc.X - target.X;
                if (this._yOut != 0)
                {
                    throw new Exception("Invald yOut value for bresline step!");
                }
            }
            else
            {
                travel = (this._xStep > 0) ? target.X - this._loc.X : this._loc.X - target.X;
                Step(travel, 0);
                outward = (this._yOut > 0) ? target.Y - this._loc.Y : this._loc.Y - target.Y;
                if (this._xOut != 0)
                {
                    throw new Exception("Invald xOut value for bresline step!");
                }
            }

            return true;
        }
Пример #12
0
        private DmtxRange GetGridCoordinates(ref DmtxPixelLoc locRef)
        {
            /* Initially pixelCount may fall beyond acceptable limits. Update grid
             * state before testing coordinates */

            /* Jump to next cross pattern horizontally if current column is done */
            if (this._pixelCount >= this._pixelTotal)
            {
                this._pixelCount = 0;
                this._xCenter   += this._jumpSize;
            }

            /* Jump to next cross pattern vertically if current row is done */
            if (this._xCenter > this._maxExtent)
            {
                this._xCenter  = this._startPos;
                this._yCenter += this._jumpSize;
            }

            /* Increment level when vertical step goes too far */
            if (this._yCenter > this._maxExtent)
            {
                this._total  *= 4;
                this._extent /= 2;
                SetDerivedFields();
            }

            if (this._extent == 0 || this._extent < this._minExtent)
            {
                locRef.X = locRef.Y = -1;
                return(DmtxRange.DmtxRangeEnd);
            }

            int count = this._pixelCount;

            if (count >= this._pixelTotal)
            {
                throw new Exception("Scangrid is beyong image limits!");
            }

            DmtxPixelLoc loc = new DmtxPixelLoc();

            if (count == this._pixelTotal - 1)
            {
                /* center pixel */
                loc.X = this._xCenter;
                loc.Y = this._yCenter;
            }
            else
            {
                int half    = this._pixelTotal / 2;
                int quarter = half / 2;

                /* horizontal portion */
                if (count < half)
                {
                    loc.X = this._xCenter + ((count < quarter) ? (count - quarter) : (half - count));
                    loc.Y = this._yCenter;
                }
                /* vertical portion */
                else
                {
                    count -= half;
                    loc.X  = this._xCenter;
                    loc.Y  = this._yCenter + ((count < quarter) ? (count - quarter) : (half - count));
                }
            }

            loc.X += this._xOffset;
            loc.Y += this._yOffset;

            locRef.X = loc.X;
            locRef.Y = loc.Y;

            if (loc.X < this._xMin || loc.X > this._xMax ||
                loc.Y < this._yMin || loc.Y > this._yMax)
            {
                return(DmtxRange.DmtxRangeBad);
            }

            return(DmtxRange.DmtxRangeGood);
        }
Пример #13
0
        private DmtxRange GetGridCoordinates(ref DmtxPixelLoc locRef)
        {
            /* Initially pixelCount may fall beyond acceptable limits. Update grid
             * state before testing coordinates */

            /* Jump to next cross pattern horizontally if current column is done */
            if (this._pixelCount >= this._pixelTotal)
            {
                this._pixelCount = 0;
                this._xCenter += this._jumpSize;
            }

            /* Jump to next cross pattern vertically if current row is done */
            if (this._xCenter > this._maxExtent)
            {
                this._xCenter = this._startPos;
                this._yCenter += this._jumpSize;
            }

            /* Increment level when vertical step goes too far */
            if (this._yCenter > this._maxExtent)
            {
                this._total *= 4;
                this._extent /= 2;
                SetDerivedFields();
            }

            if (this._extent == 0 || this._extent < this._minExtent)
            {
                locRef.X = locRef.Y = -1;
                return DmtxRange.DmtxRangeEnd;
            }

            int count = this._pixelCount;

            if (count >= this._pixelTotal)
            {
                throw new Exception("Scangrid is beyong image limits!");
            }

            DmtxPixelLoc loc = new DmtxPixelLoc();
            if (count == this._pixelTotal - 1)
            {
                /* center pixel */
                loc.X = this._xCenter;
                loc.Y = this._yCenter;
            }
            else
            {
                int half = this._pixelTotal / 2;
                int quarter = half / 2;

                /* horizontal portion */
                if (count < half)
                {
                    loc.X = this._xCenter + ((count < quarter) ? (count - quarter) : (half - count));
                    loc.Y = this._yCenter;
                }
                /* vertical portion */
                else
                {
                    count -= half;
                    loc.X = this._xCenter;
                    loc.Y = this._yCenter + ((count < quarter) ? (count - quarter) : (half - count));
                }
            }

            loc.X += this._xOffset;
            loc.Y += this._yOffset;

            locRef.X = loc.X;
            locRef.Y = loc.Y;

            if (loc.X < this._xMin || loc.X > this._xMax ||
                  loc.Y < this._yMin || loc.Y > this._yMax)
            {
                return DmtxRange.DmtxRangeBad;
            }

            return DmtxRange.DmtxRangeGood;
        }
Пример #14
0
        internal DmtxRange PopGridLocation(ref DmtxPixelLoc loc)
        {
            DmtxRange locStatus;

            do
            {
                locStatus = GetGridCoordinates(ref loc);

                /* Always leave grid pointing at next available location */
                this._pixelCount++;

            } while (locStatus == DmtxRange.DmtxRangeBad);

            return locStatus;
        }