Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CheckUtils.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 __CheckUtils_hh__
26 #define __CheckUtils_hh__
27 
28 #include <Base/Math/Vector2.hh>
29 #include <Base/Geometry/HomgPoint2D.hh>
30 #include <cmath>
31 
32 namespace BIAS {
33 
34  class CheckUtils {
35  public:
36 
37  template<class T>
38  static bool InImageDisc(const unsigned int& width,
39  const unsigned int& height,
40  const Vector2<T>& pt) {
41  const T w = static_cast<T>(width-1);
42  const T h = static_cast<T>(height-1);
43  return (pt[0] >= 0 && pt[1] >= 0 &&
44  pt[0] <= w && pt[1] <= h);
45  }
46 
47  static bool InImageDisc(const unsigned int& width,
48  const unsigned int& height,
49  const HomgPoint2D& pt) {
50  const double w = static_cast<double>(width-1);
51  const double h = static_cast<double>(height-1);
52  return (pt[0] >= 0 && pt[1] >= 0 &&
53  pt[0] <= w && pt[1] <= h &&
54  pt[2]==1.0);
55  }
56 
57  template<class T>
58  static bool InImageDisc(const unsigned int& width,
59  const unsigned int& height,
60  const T x,
61  const T y) {
62  const T w = static_cast<T>(width-1);
63  const T h = static_cast<T>(height-1);
64  return (x >= 0 && y >= 0 &&
65  x <= w && y <= h);
66  }
67 
68 
69  /** Returns integer coordinate range for the window around pt
70  * which is in the image, pt also has to lie within the image
71  * \param hwSize is the window's half win size.
72  * \param xMin minimal VALID x coordintate in the window
73  * \param xMax maximal VALID x coordintate in the window
74  * \param yMin minimal VALID y coordintate in the window
75  * \param yMax maximal VALID y coordintate in the window
76  * \returns false if no valid window region was detected or if pt is not in the image.
77  **/
78  static bool GetIntegerWindow(const unsigned int& width,
79  const unsigned int& height,
80  const HomgPoint2D& pt,
81  const unsigned int hwSize,
82  unsigned int& xMin,
83  unsigned int& xMax,
84  unsigned int& yMin,
85  unsigned int& yMax) {
86 
87  //center point has to be in image
88  if(!InImageDisc(width, height, pt)) return false;
89 
90 
91  const double w = static_cast<double>(width-1);
92  const double h = static_cast<double>(height-1);
93  float hw = static_cast<float>(hwSize);
94 
95  float xMinTmp = float(std::max(rint(pt[0])-hw, 0.0));
96  float yMinTmp = float(std::max(rint(pt[1])-hw, 0.0));
97  float xMaxTmp = float(std::min(rint(pt[0])+hw, w));
98  float yMaxTmp = float(std::min(rint(pt[1])+hw, h));
99 
100  if(xMaxTmp < xMinTmp || yMaxTmp < yMinTmp) return false;
101 
102  xMin = static_cast<unsigned int>(xMinTmp);
103  yMin = static_cast<unsigned int>(yMinTmp);
104  xMax = static_cast<unsigned int>(xMaxTmp);
105  yMax = static_cast<unsigned int>(yMaxTmp);
106 
107  return true;
108 
109  }
110 
111 
112  };
113 
114 }//end of namespace
115 
116 
117 #endif
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
static bool InImageDisc(const unsigned int &width, const unsigned int &height, const Vector2< T > &pt)
Definition: CheckUtils.hh:38
static bool InImageDisc(const unsigned int &width, const unsigned int &height, const T x, const T y)
Definition: CheckUtils.hh:58
class Vector2 contains a Vector of dim.
Definition: Vector2.hh:79
static bool GetIntegerWindow(const unsigned int &width, const unsigned int &height, const HomgPoint2D &pt, const unsigned int hwSize, unsigned int &xMin, unsigned int &xMax, unsigned int &yMin, unsigned int &yMax)
Returns integer coordinate range for the window around pt which is in the image, pt also has to lie w...
Definition: CheckUtils.hh:78
static bool InImageDisc(const unsigned int &width, const unsigned int &height, const HomgPoint2D &pt)
Definition: CheckUtils.hh:47