Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Scanline.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef __Scanline_hh__
27 #define __Scanline_hh__
28 
29 #include <bias_config.h>
30 #include "Bresenham.hh"
31 
32 namespace BIAS
33 {
34 /** @brief Class for scanning a region given by a line and
35  * a distance ca. perpendicular to the line
36  * GetNext() return on successive calls all image coordinates
37  * within +-epsilon from line given by start and end
38  * Fast implementation based on Bresenhams algorithm
39  * @ingroup g_image_other
40  * @note This is the old ScanLine2 class replacing ScanLine.
41  * @author Felix Woelk
42  * @date 01/2003
43  */
44  class Scanline : public Bresenham
45  {
46 
47  public:
48  inline Scanline();
49 
50  inline ~Scanline();
51 
52  inline Scanline(const int start[2], const int end[2], const int epsilon);
53 
54  inline Scanline(const unsigned int start[2], const unsigned int end[2],
55  const unsigned int epsilon);
56 
57  inline Scanline(const double start[2], const double end[2],
58  const double epsilon);
59 
60  inline void Init(const int start[2], const int end[2], const int epsilon);
61 
62  inline void Init(const unsigned int start[2], const unsigned int end[2],
63  const unsigned int epsilon)
64  { Init((int *)start, (int *)end, (int)epsilon); };
65 
66  inline void Init(const double start[2], const double end[2],
67  double epsilon);
68 
69  inline bool GetNext(int next[2]);
70 
71  inline bool GetNext(unsigned int next[2])
72  { return GetNext((int *)next); };
73 
74  inline bool GetNext(double next[2]);
75 
76  protected:
77  int _iEpsilon;
78  double _dDEpsilon;
81 
82  }; // class
83 
85 
87 
88  Scanline::Scanline(const int start[2], const int end[2], const int epsilon)
89  { Init(start, end, epsilon); }
90 
91  Scanline::Scanline(const unsigned int start[2], const unsigned int end[2],
92  const unsigned int epsilon)
93  { Init(start, end, epsilon); }
94 
95  Scanline::Scanline(const double start[2], const double end[2],
96  const double epsilon)
97  { Init(start, end, epsilon); }
98 
99  void Scanline::Init(const int start[2], const int end[2], const int epsilon)
100  {
101 #ifdef BIAS_DEBUG
102  if (epsilon<0){
103  BIASERR("Epsilon should be greater or equal to zero!");
104  }
105 #endif
106  Bresenham::Init(start, end);
107  _iEpsilon = epsilon;
108  _iEpsCount = -1;
109 
112  // remember
116  }
117 
118  void Scanline::Init(const double start[2], const double end[2],
119  double epsilon)
120  {
121 #ifdef BIAS_DEBUG
122  if (epsilon<0){
123  BIASERR("Epsilon should be greater or equal to zero!");
124  }
125 #endif
126  Bresenham::Init(start, end);
127  _iEpsilon = (int)floor(epsilon);
128  _dDEpsilon = epsilon - _iEpsilon;
129  _iEpsCount = -1;
133  }
134 
135  bool Scanline::GetNext(int next[2])
136  {
137 #ifdef BIAS_DEBUG
138  if (!_bInitialized)
139  BIASERR("call Init befor GetNext");
140 #endif
141  bool result=true;
142  if (_iEpsCount>=2*_iEpsilon){ // this is from bresenham
143  _iEpsCount=0;
145  _iEps += _iDy;
146  if ((_iEps << 1) >= _iDx){
148  _iEps -= _iDx;
149  }
152  result=false;
153  } else {
158  result=true;
159  }
160  } else { // just go up and down
161  _iTransformedUpDown[1]++;
163  _iEpsCount++;
164  }
165  return result;
166  }
167 
168  bool Scanline::GetNext(double next[2])
169  {
170  bool result;
171  int inext[2] = { 0, 0 };
172  result = GetNext(inext);
173  next[0]=(double)inext[0] + _dDx;
174  next[1]=(double)inext[1] + _dDy;
175 
176  return result;
177  }
178 
179 } // namespace
180 
181 #endif // __Scanline_hh__
void InverseTransform(enum TLineType &type, const T &Transformedx, const T &Transformedy, T &Originalx, T &Originaly)
executes the inverse transformation to the above
int _iTransformedCurrent[2]
Definition: Bresenham.hh:75
double _dDEpsilon
Definition: Scanline.hh:78
long int _iEps
Definition: Bresenham.hh:82
EightWaySymmetry< int > _iSym
Definition: Bresenham.hh:69
bool _bInitialized
Definition: Bresenham.hh:84
Class for scanning a region given by a line and a distance ca.
Definition: Scanline.hh:44
int _iTransformedEnd[2]
Definition: Bresenham.hh:77
int _iTransformedStart[2]
Definition: Bresenham.hh:76
void Init(const int start[2], const int end[2], const int epsilon)
Definition: Scanline.hh:99
bool GetNext(int next[2])
Definition: Scanline.hh:135
Scans a line using Bresenhams integer arithmetic algorithm.
Definition: Bresenham.hh:42
enum TLineType _eLineType
Definition: Bresenham.hh:71
void Init(const int start[2], const int end[2])
Definition: Bresenham.hh:125
void Init(const unsigned int start[2], const unsigned int end[2], const unsigned int epsilon)
Definition: Scanline.hh:62
int _iTransformedUpDown[2]
Definition: Scanline.hh:80
bool GetNext(unsigned int next[2])
Definition: Scanline.hh:71