Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EightWaySymmetry.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 #ifndef __EIGHT_WAY_SYMMETRY_HH__
26 #define __EIGHT_WAY_SYMMETRY_HH__
27 #include "bias_config.h"
28 
29 // BIAS jw: math.h defines required for non-standard symbols:
30 #define _USE_MATH_DEFINES
31 #include <math.h>
32 //#include <cmath>
33 #include <iostream>
34 
35 #include <Base/Debug/Error.hh>
36 
37 
38 
39 
40 namespace BIAS{
41 
42  /** @enum TLineType
43  * @brief direction of line if start is in coordinate origin as given by compass
44  */
46 
47  /**
48  * @brief class for transforming any point to first octant
49  * @ingroup g_image_other
50  * @author Jan Woetzel
51  */
52  template <class T>
54 
55  public:
56  /// assumes angle is between (-pi, pi] as given by atan2
57  inline enum TLineType DetermineLineType(double& angle);
58 
59  /// not tested jet
60  inline enum TLineType DetermineLineType(const T& startx, const T& starty,
61  const T& endx, const T& endy);
62 
63  /// transforms Original according to type in a way that
64  /// Transformed lies on a line with slope in [0,1)
65  inline void Transform(enum TLineType& type,
66  const T& Originalx, const T& Originaly,
67  T& Transformedx, T& Transformedy);
68 
69  /// executes the inverse transformation to the above
70  inline void InverseTransform(enum TLineType& type,
71  const T& Transformedx, const T& Transformedy,
72  T& Originalx, T& Originaly);
73 
74  inline void Transform(enum TLineType& type,
75  const T orig[2], T transf[2]);
76 
77  inline void InverseTransform(enum TLineType& type,
78  const T transf[2], T orig[2]);
79  }; // end of class
80 
81 
82 
83  // implementations:
84 
85 
86  //for old compilers 'enum TLineType'
87  template <class T> inline TLineType
89  {
90  enum TLineType type = LT_Invalid;
91 
92  if (angle >= 0 && angle <= M_PI_4)
93  type = SE_E;
94  if (angle > M_PI_4 && angle <= M_PI_2)
95  type = S_SE;
96  if (angle > M_PI_2 && angle <= 3 * M_PI_4)
97  type = SW_S;
98  if (angle > 3 * M_PI_4 && angle <= M_PI)
99  type = W_SW;
100  if (angle > -M_PI && angle <= -3 * M_PI_4)
101  type = NW_W;
102  if (angle > -3 * M_PI_4 && angle <= -M_PI_2)
103  type = N_NW;
104  if (angle > -M_PI_2 && angle <= -M_PI_4)
105  type = NE_N;
106  if (angle > -M_PI_4 && angle < 0)
107  type = E_NE;
108 
109  return type;
110  }
111 
112  template <class T> inline TLineType //for old compilers 'enum TLineType'
113  EightWaySymmetry<T>::DetermineLineType(const T& startx, const T& starty,
114  const T& endx, const T& endy)
115  {
116  enum TLineType type = LT_Invalid;
117  double dx, dy;
118  dx = (double)endx - (double)startx;
119  dy = (double)endy - (double)starty;
120 
121  if (dx>=0){
122  if (dy>=0){
123  if (dx>dy){
124  type = SE_E;
125  } else {
126  type = S_SE;
127  }
128  } else { // dx >=0 && dy < 0
129  if(dx>-dy){
130  type = E_NE;
131  } else {
132  type = NE_N;
133  }
134  }
135  } else { // dx < 0
136  if (dy>=0){
137  if (-dx>dy){
138  type = W_SW;
139  } else {
140  type = SW_S;
141  }
142  } else { // dx <0 && dy <0
143  if (dx<dy) { //(-dx>-dy){
144  type = NW_W;
145  } else {
146  type = N_NW;
147  }
148  }
149  }
150  return type;
151  }
152 
153  template <class T> inline void
154  EightWaySymmetry<T>::Transform(enum TLineType& type, const T& Originalx,
155  const T& Originaly, T& Transformedx,
156  T& Transformedy)
157  {
158  switch(type){
159  case SE_E:
160  Transformedx = Originalx;
161  Transformedy = Originaly;
162  break;
163  case S_SE:
164  Transformedx = Originaly;
165  Transformedy = Originalx;
166  break;
167  case SW_S:
168  Transformedx = Originaly;
169  Transformedy = -Originalx;
170  break;
171  case W_SW:
172  Transformedx = -Originalx;
173  Transformedy = Originaly;
174  break;
175  case NW_W:
176  Transformedx = Originalx * (-1);
177  Transformedy = Originaly * (-1);
178  break;
179  case N_NW:
180  Transformedx = -Originaly;
181  Transformedy = -Originalx;
182  break;
183  case NE_N:
184  Transformedx = -Originaly;
185  Transformedy = Originalx;
186  break;
187  case E_NE:
188  Transformedx = Originalx;
189  Transformedy = -Originaly;
190  break;
191  case LT_Invalid:
192  BIASERR("Invalid LineType, maybe wrong slope in EpipolarLine");
193  break;
194  }
195  }
196 
197 
198  template <class T> inline void
200  const T& Transformedx,
201  const T& Transformedy,
202  T& Originalx,
203  T& Originaly)
204  {
205  switch(type){
206  case SE_E:
207  Originalx = Transformedx;
208  Originaly = Transformedy;
209  break;
210  case S_SE:
211  Originalx = Transformedy;
212  Originaly = Transformedx;
213  break;
214  case SW_S:
215  Originalx = -Transformedy;
216  Originaly = Transformedx;
217  break;
218  case W_SW:
219  Originalx = -Transformedx;
220  Originaly = Transformedy;
221  break;
222  case NW_W:
223  Originalx = Transformedx * (-1);
224  Originaly = Transformedy * (-1);
225  break;
226  case N_NW:
227  Originalx = -Transformedy;
228  Originaly = -Transformedx;
229  break;
230  case NE_N:
231  Originalx = Transformedy;
232  Originaly = -Transformedx;
233  break;
234  case E_NE:
235  Originalx = Transformedx;
236  Originaly = -Transformedy;
237  break;
238  case LT_Invalid:
239  BIASERR("Invalid LineType, maybe wrong slope in EpipolarLine");
240  break;
241  }
242  }
243 
244  template <class T> inline void
246  const T orig[2], T transf[2])
247  {
248  return EightWaySymmetry<T>::Transform(type, orig[0], orig[1], transf[0],
249  transf[1]);
250  }
251 
252  template <class T> inline void
254  const T transf[2], T orig[2])
255  {
256  return
258  transf[1], orig[0], orig[1]);
259  }
260 
261 } // namespace BIAS
262 
263 #endif // __8_WAY_SYMMETRY_HH__
void InverseTransform(enum TLineType &type, const T &Transformedx, const T &Transformedy, T &Originalx, T &Originaly)
executes the inverse transformation to the above
enum TLineType DetermineLineType(double &angle)
assumes angle is between (-pi, pi] as given by atan2
class for transforming any point to first octant
void Transform(enum TLineType &type, const T &Originalx, const T &Originaly, T &Transformedx, T &Transformedy)
transforms Original according to type in a way that Transformed lies on a line with slope in [0...
TLineType
direction of line if start is in coordinate origin as given by compass