26 #ifndef _HomgPoint2D_hh_
27 #define _HomgPoint2D_hh_
28 #include "bias_config.h"
32 # define rint(x) (floor(x+0.5))
35 #include <Base/Debug/Error.hh>
37 #include <Base/Math/Vector3.hh>
38 #include <Base/Math/Vector.hh>
39 #include <Base/Math/Vector2.hh>
40 #include <Base/Math/Matrix3x3.hh>
41 #include <Base/Common/CompareFloatingPoint.hh>
46 #define HOMGPOINT2D_TYPE double
48 #define HOMGPOINT2D_TYPE_EPS 1E-12
50 #define HOMGPOINT2D_TYPE_INF std::numeric_limits<double>::infinity()
71 LOC_LOWER, LOC_undef};
74 BottomRight, Center, Infinity, InvalidPosition };
80 :
Vector3 < HOMGPOINT2D_TYPE > () {};
91 :
Vector3 <HOMGPOINT2D_TYPE> (p) {};
97 :
Vector3 <HOMGPOINT2D_TYPE> (scalar) {};
103 :
Vector3 <HOMGPOINT2D_TYPE> (pv) {};
126 const HOMGPOINT2D_TYPE & y)
136 const HOMGPOINT2D_TYPE & y,
137 const HOMGPOINT2D_TYPE & w)
138 { data_[0] = x; data_[1] = y; data_[2] = w; };
140 inline HOMGPOINT2D_TYPE
GetW()
const {
return data_[2]; };
159 inline HomgPoint2D & operator= (
const HOMGPOINT2D_TYPE & scalar) {
166 {
return (data_[2]>-HOMGPOINT2D_TYPE_EPS &&
167 data_[2]<HOMGPOINT2D_TYPE_EPS); };
174 inline void Set(
const HOMGPOINT2D_TYPE & x,
const HOMGPOINT2D_TYPE & y)
177 inline void Set(
const HOMGPOINT2D_TYPE& x,
const HOMGPOINT2D_TYPE& y,
178 const HOMGPOINT2D_TYPE& z)
183 if (vec.
size() != 3){
184 BIASERR(
"The vector for initialization of Vector3 has not length 3");
203 return data_[2]<1+HOMGPOINT2D_TYPE_EPS &&
204 data_[2]>1-HOMGPOINT2D_TYPE_EPS;
209 return Equal(NormL2(), 1.0, HOMGPOINT2D_TYPE_EPS);
217 register const HOMGPOINT2D_TYPE w = data_[2];
218 if (data_[2]>-HOMGPOINT2D_TYPE_EPS &&
219 data_[2]<HOMGPOINT2D_TYPE_EPS) {
246 dest.
GetData()[0] = GetEuclideanX();
247 dest.
GetData()[1] = GetEuclideanY();
258 this->GetEuclidean(dest);
264 this->GetEuclidean(dest);
267 return this->GetEuclidean();
277 BIASASSERT(!((GetW() > -HOMGPOINT2D_TYPE_EPS) &&
278 (GetW() < HOMGPOINT2D_TYPE_EPS)));
280 return ((*
this)[0] / GetW());
284 BIASASSERT(!((GetW() > -HOMGPOINT2D_TYPE_EPS) &&
285 (GetW() < HOMGPOINT2D_TYPE_EPS)));
287 return ((*
this)[1] / GetW());
292 return this->GetEuclideanX();
295 return this->GetEuclideanY();
298 inline HOMGPOINT2D_TYPE Distance(
const HomgPoint2D& point)
const;
299 inline HOMGPOINT2D_TYPE DistanceSquared(
const HomgPoint2D& point)
const;
311 return ((data_[2]*arg[1] == data_[1]*arg[2])
312 && (data_[2]*arg[0] == data_[0]*arg[2])
313 && (data_[1]*arg[0] == data_[0]*arg[1]));
321 {
return !(*
this == arg); };
324 inline bool GetImageCoo(
unsigned int width,
unsigned int height,
325 unsigned int coo[2]);
327 inline enum EPosition
328 DeterminePosition(
unsigned int width,
unsigned int height);
333 inline enum EPosition
334 DeterminePosition(
const double& minx,
const double& miny,
335 const double& maxx,
const double& maxy);
342 inline bool IsInROIHomogenized(
const HOMGPOINT2D_TYPE& xmin,
343 const HOMGPOINT2D_TYPE& ymin,
344 const HOMGPOINT2D_TYPE& xmax,
345 const HOMGPOINT2D_TYPE& ymax)
const;
349 inline bool IsInROI(
const HOMGPOINT2D_TYPE& xmin,
350 const HOMGPOINT2D_TYPE& ymin,
351 const HOMGPOINT2D_TYPE& xmax,
352 const HOMGPOINT2D_TYPE& ymax)
const;
356 BIASGeometryBase_EXPORT std::ostream&
operator<<(std::ostream& os,
369 if ((
data_[2]>-HOMGPOINT2D_TYPE_EPS &&
data_[2]<HOMGPOINT2D_TYPE_EPS) ||
370 (point[2]>-HOMGPOINT2D_TYPE_EPS && point[2]<HOMGPOINT2D_TYPE_EPS)) {
371 return HOMGPOINT2D_TYPE_INF;
373 return sqrt(pow(
data_[0]/
data_[2] - point[0]/point[2],2) +
374 pow(
data_[1]/
data_[2] - point[1]/point[2],2));
379 if ((
data_[2]>-HOMGPOINT2D_TYPE_EPS &&
data_[2]<HOMGPOINT2D_TYPE_EPS) ||
380 (point[2]>-HOMGPOINT2D_TYPE_EPS && point[2]<HOMGPOINT2D_TYPE_EPS)) {
381 return HOMGPOINT2D_TYPE_INF;
383 return pow(
data_[0]/
data_[2] - point[0]/point[2],2) +
393 if (
data_[0] >= 0.0 &&
data_[0] < (width -1) &&
396 coo[0] = (
unsigned int)rint(
data_[0]);
397 coo[1] = (
unsigned int)rint(
data_[1]);
409 const double& maxx,
const double& maxy)
418 (*this)[0]/=(*this)[2];
419 (*this)[1]/=(*this)[2];
422 if ((*
this)[0] < minx) {
424 }
else if ((*
this)[0] > maxx) {
428 if ((*
this)[1] < miny) {
430 }
else if ((*
this)[1] > maxy) {
447 BIASERR(
"no valid ypos");
464 BIASERR(
"no valid ypos");
481 BIASERR(
"no valid ypos");
487 BIASERR(
"no valid xpos");
495 const HOMGPOINT2D_TYPE& ymin,
496 const HOMGPOINT2D_TYPE& xmax,
497 const HOMGPOINT2D_TYPE& ymax)
const {
500 BIASERR(
"Supplied unhomogenized point to IsInROIHomogenized(). "
501 <<
"Lucky you! Without BIAS_DEBUG enabled, you do not get this "
502 <<
"warning and there would be a really wrong result here! "
503 <<
"Fix your code and try again. Goodbye.");
507 return (
data_[0]>=xmin) && (
data_[0]<=xmax) &&
513 const HOMGPOINT2D_TYPE& ymin,
514 const HOMGPOINT2D_TYPE& xmax,
515 const HOMGPOINT2D_TYPE& ymax)
const {
void Set(const Vector< HOMGPOINT2D_TYPE > &vec)
Sets this form elements of Vector<T>.
HomgPoint2D(const HOMGPOINT2D_TYPE &x, const HOMGPOINT2D_TYPE &y)
constructor using euclidic coordinates, setting the 3rd HomgPoint2D component to 1 ...
void Set(const T *pv)
copy the array of vectorsize beginning at *T to this->data_
const T * GetData() const
get the data pointer the member function itself is const (before {..}) because it doesn't change the ...
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
HOMGPOINT2D_TYPE data_[VECTOR3_SIZE]
HomgPoint2D()
default constructor
enum EPosition DeterminePosition(unsigned int width, unsigned int height)
class for column vectors with arbitrary size
HOMGPOINT2D_TYPE Distance(const HomgPoint2D &point) const
bool IsInROI(const HOMGPOINT2D_TYPE &xmin, const HOMGPOINT2D_TYPE &ymin, const HOMGPOINT2D_TYPE &xmax, const HOMGPOINT2D_TYPE &ymax) const
determines if point is within rectangular RegionOfInterest
HOMGPOINT2D_TYPE GetW() const
void GetEuclidean(Vector2< HOMGPOINT2D_TYPE > &dest) const
calculate affine coordinates of this and write them to dest affine coordinates are projective coordin...
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
HomgPoint2D(const HOMGPOINT2D_TYPE *pv)
assignment with an array of values which is copied into this ones class members
HOMGPOINT2D_TYPE GetEuclidianY() const
HOMGPOINT2D_TYPE GetEuclidianX() const
const T * GetData() const
get the data pointer the member function itself is const (before {..}) because it doesn't change the ...
bool GetImageCoo(unsigned int width, unsigned int height, unsigned int coo[2])
return image coordinates for drawing , coo[0]=x, coo[1]=y
HomgPoint2D(const HomgPoint2D &p)
constructor
class Vector2 contains a Vector of dim.
bool IsAtInfinity() const
Vector2< HOMGPOINT2D_TYPE > GetEuclidian() const
HomgPoint2D & operator=(const Vector3< HOMGPOINT2D_TYPE > &vec)
assignment operator set the elements of this HomgPoint to the element of vec
HomgPoint2D(char *s)
constructor with element assignment
bool IsNormalized() const
void GetEuclidian(Vector2< HOMGPOINT2D_TYPE > &dest) const
HomgPoint2D(const Vector3< double > &vec)
constructor from Vector3
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
class Vector3 contains a Vector of fixed dim.
void Set(const HOMGPOINT2D_TYPE &x, const HOMGPOINT2D_TYPE &y, const HOMGPOINT2D_TYPE &z)
bool Equal(const T left, const T right, const T eps)
comparison function for floating point values See http://www.boost.org/libs/test/doc/components/test_...
bool operator==(const HomgPoint2D &arg) const
Comparison operator 'equal'.
Vector2< HOMGPOINT2D_TYPE > GetEuclidean() const
return the euclidean coordinates of this homg 2D point Only possible for w !=0 because w==0 describes...
HomgPoint2D(const HOMGPOINT2D_TYPE &x, const HOMGPOINT2D_TYPE &y, const HOMGPOINT2D_TYPE &w)
constructor
HomgPoint2D(const Vector2< HOMGPOINT2D_TYPE > &vec)
constructor
bool IsInROIHomogenized(const HOMGPOINT2D_TYPE &xmin, const HOMGPOINT2D_TYPE &ymin, const HOMGPOINT2D_TYPE &xmax, const HOMGPOINT2D_TYPE &ymax) const
determines if point is within rectangular RegionOfInterest
HomgPoint2D(const HOMGPOINT2D_TYPE &scalar)
assignment with a constant value for all elements
void Set(const Vector2< HOMGPOINT2D_TYPE > &vec)
set from Vector2
HOMGPOINT2D_TYPE GetEuclideanX() const
return the euclidean coordinates Only possible for w !=0 because w==0 describes points of infinity wh...
void Set(const HOMGPOINT2D_TYPE &x, const HOMGPOINT2D_TYPE &y)
set elementwise with given 2 euclidean scalar values.
bool IsHomogenized() const
HOMGPOINT2D_TYPE DistanceSquared(const HomgPoint2D &point) const
HOMGPOINT2D_TYPE GetEuclideanY() const