Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
BresenhamCircleEighth.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 __BresenhamCircleEighth_hh__
27 #define __BresenhamCircleEighth_hh__
28 #include "bias_config.h"
29 
30 namespace BIAS {
31 
32  /**
33  * @brief Just like BresenhamCircle but only computes 1/8 of the circle.
34  * @relates BresenhamCircle
35  * @ingroup g_image_other
36  * @author Felix Woelk, clean-up + refactoring by Robert Wulff 02/2010
37  */
39 
40  public:
41 
42  /**
43  * @brief Default constructor. You have to call Init() by yourself before
44  * calling GetNext().
45  */
47  }
48 
49 
50  /**
51  * @brief Constructor.
52  *
53  * @param center
54  * the center for this BresenhamCircleEighth
55  * @param radius
56  * the radius for this BresenhamCircleEighth
57  */
58  inline BresenhamCircleEighth(int center[2], int radius) {
59  Init(center, radius);
60  }
61 
62 
63  /**
64  * @brief Destructor.
65  */
67  }
68 
69 
70  /**
71  * @brief Initialises this BresenhamCircleEighth with new center and radius.
72  *
73  * @param center
74  * the new center for this BresenhamCircleEighth
75  *
76  * @param radius
77  * the new radius for this BresenhamCircleEighth
78  */
79  inline void Init(int center[2], int radius) {
80  center_[0] = center[0];
81  center_[1] = center[1];
82  radius_ = radius;
83 
84  current_[0] = 0;
85  current_[1] = radius_;
86 
87  d_ = 1 - radius_;
88  deltaE_ = 3;
89  deltaSE_ = -2 * radius_ + 5;
90 
91  // let GetNext return the starting point first
92  current_[0]--;
93  if (d_ >= 0) {
94  current_[1]++;
95  }
96 #ifdef BIAS_DEBUG
97  initialized_ = true;
98 #endif
99  }
100 
101 
102  /**
103  * @brief Returns the coordinate of the next point on the 1/8 circle.
104  *
105  * Can be called in a while loop:
106  *
107  * int nextCoords[2];
108  * while (bresCircEighth.GetNext(nextCoords)){
109  * // draw nextCoords in image
110  * }
111  *
112  * @param next
113  * the returned coordinate of the next point on the 1/8 circle
114  *
115  * @return true if there are still points left on the 1/8 circle or
116  * false if the 1/8 circle is finished
117  */
118  inline bool GetNext(int next[2]) {
119 #ifdef BIAS_DEBUG
120  if (!initialized_)
121  BIASERR("call Init before GetNext");
122 #endif
123 
124  bool result = true;
125 
126  if (current_[1] > current_[0]){
127  if (d_ < 0){
128  d_ += deltaE_;
129  deltaE_ += 2;
130  deltaSE_ += 2;
131  } else {
132  d_ += deltaSE_;
133  deltaE_ += 2;
134  deltaSE_ += 4;
135  current_[1]--;
136  }
137 
138  current_[0]++;
139  next[0] = current_[0] + center_[0];
140  next[1] = current_[1] + center_[1];
141  } else {
142 #ifdef BIAS_DEBUG
143  initialized_ = false;
144 #endif
145  result = false;
146  }
147  return result;
148  }
149 
150 
151  protected:
152 
153  int center_[2]; // center coo
154  int radius_;
155  int current_[2];
156  int d_;
157  int deltaE_;
158  int deltaSE_;
159 
160 #ifdef BIAS_DEBUG
162 #endif
163  };
164 
165 } // namespace
166 
167 #endif // __BresenhamCircleEighth_hh__
void Init(int center[2], int radius)
Initialises this BresenhamCircleEighth with new center and radius.
BresenhamCircleEighth()
Default constructor.
bool GetNext(int next[2])
Returns the coordinate of the next point on the 1/8 circle.
BresenhamCircleEighth(int center[2], int radius)
Constructor.
Just like BresenhamCircle but only computes 1/8 of the circle.