ViSP  2.8.0
vpImagePoint.h
1 /****************************************************************************
2  *
3  * $Id: vpImagePoint.h 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * 2D point useful for image processing
36  *
37  * Authors:
38  * Nicolas Melchior
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
43 #ifndef vpImagePoint_H
44 #define vpImagePoint_H
45 
52 #include <visp/vpConfig.h>
53 #include <visp/vpMath.h>
54 
55 #include <ostream>
56 #include <cmath> // std::fabs
57 #include <limits> // numeric_limits
58 
59 class vpHomography;
60 class vpRect;
61 
92 class VISP_EXPORT vpImagePoint
93 {
94  public:
99  inline vpImagePoint() {
100  i = 0;
101  j = 0;
102  }
107  inline vpImagePoint(double i, double j) {
108  this->i = i;
109  this->j = j;
110  }
118  inline vpImagePoint(const vpImagePoint &ip) {
119  this->i = ip.i;
120  this->j = ip.j;
121  }
123  inline virtual ~vpImagePoint() { ; }
124 
130  inline const vpImagePoint& operator=(const vpImagePoint &ip) {
131  this->i = ip.i;
132  this->j = ip.j;
133  return *this;
134  }
135 
145  inline void set_i(const double i) { this->i = i ; }
146 
156  inline void set_j(const double j) { this->j = j ; }
157 
167  inline void set_ij(const double i, const double j) {
168  this->i = i ;
169  this->j = j ;
170  }
171 
181  inline double get_i() const { return i ; }
182 
192  inline double get_j() const { return j ; }
193 
203  inline void set_u(const double u) { j = u ; }
204 
214  inline void set_v(const double v) { i = v ; }
215 
225  inline void set_uv(const double u, const double v) {
226  this->i = v ;
227  this->j = u ;
228  }
229 
239  inline double get_u() const { return j ; }
240 
250  inline double get_v() const { return i; }
251 
261  static double distance (const vpImagePoint &iP1, const vpImagePoint &iP2) {
262  return(sqrt(vpMath::sqr(iP1.get_i()-iP2.get_i())+vpMath::sqr(iP1.get_j()-iP2.get_j())));}
263 
273  static double sqrDistance (const vpImagePoint &iP1, const vpImagePoint &iP2) {
274  return(vpMath::sqr(iP1.get_i()-iP2.get_i())+vpMath::sqr(iP1.get_j()-iP2.get_j()));}
275 
276 
277  bool inRectangle( const vpRect &rect ) const;
278 
279  vpImagePoint projection(const vpHomography& aHb);
280 
281  private:
282  double i,j;
283 };
284 
291 VISP_EXPORT inline bool operator==( const vpImagePoint &ip1,
292  const vpImagePoint &ip2 ) {
293  //return ( ( ip1.get_i() == ip2.get_i() ) && ( ip1.get_j() == ip2.get_j() ) );
294 
295  double i1 = ip1.get_i();
296  double j1 = ip1.get_j();
297  double i2 = ip2.get_i();
298  double j2 = ip2.get_j();
299 
300  return (
301  ( std::fabs(i1-i2) <= std::fabs(vpMath::maximum(i1, i2))*std::numeric_limits<double>::epsilon() )
302  &&
303  ( std::fabs(j1-j2) <= std::fabs(vpMath::maximum(j1, j2))*std::numeric_limits<double>::epsilon() )
304  );
305 }
306 
314 VISP_EXPORT inline bool operator!=( const vpImagePoint &ip1,
315  const vpImagePoint &ip2 ) {
316  //return ( ( ip1.get_i() != ip2.get_i() ) || ( ip1.get_j() != ip2.get_j() ) );
317  double i1 = ip1.get_i();
318  double j1 = ip1.get_j();
319  double i2 = ip2.get_i();
320  double j2 = ip2.get_j();
321 
322  return (
323  ( std::fabs(i1-i2) > std::fabs(vpMath::maximum(i1, i2))*std::numeric_limits<double>::epsilon() )
324  ||
325  ( std::fabs(j1-j2) > std::fabs(vpMath::maximum(j1, j2))*std::numeric_limits<double>::epsilon() )
326  );
327 }
328 
336 VISP_EXPORT inline vpImagePoint operator+( const vpImagePoint &ip1,
337  const vpImagePoint &ip2 ) {
338  return ( vpImagePoint(ip1.get_i()+ip2.get_i(), ip1.get_j()+ip2.get_j()));
339 }
360 VISP_EXPORT inline vpImagePoint operator+( const vpImagePoint &ip1,
361  const int offset ) {
362  return ( vpImagePoint(ip1.get_i()+offset, ip1.get_j()+offset));
363 }
384 VISP_EXPORT inline vpImagePoint operator+( const vpImagePoint &ip1,
385  const double offset ) {
386  return ( vpImagePoint(ip1.get_i()+offset, ip1.get_j()+offset));
387 }
388 
396 VISP_EXPORT inline vpImagePoint operator-( const vpImagePoint &ip1,
397  const vpImagePoint &ip2 ) {
398  return ( vpImagePoint(ip1.get_i()-ip2.get_i(), ip1.get_j()-ip2.get_j()));
399 }
420 VISP_EXPORT inline vpImagePoint operator-( const vpImagePoint &ip1,
421  const int offset ) {
422  return ( vpImagePoint(ip1.get_i()-offset, ip1.get_j()-offset));
423 }
444 VISP_EXPORT inline vpImagePoint operator-( const vpImagePoint &ip1,
445  const double offset ) {
446  return ( vpImagePoint(ip1.get_i()-offset, ip1.get_j()-offset));
447 }
468 VISP_EXPORT inline vpImagePoint operator*( const vpImagePoint &ip1,
469  const double scale ) {
470  return ( vpImagePoint(ip1.get_i()*scale, ip1.get_j()*scale));
471 }
492 VISP_EXPORT inline vpImagePoint operator/( const vpImagePoint &ip1,
493  const double scale ) {
494  return ( vpImagePoint(ip1.get_i()/scale, ip1.get_j()/scale));
495 }
496 
529 VISP_EXPORT inline std::ostream& operator<< (std::ostream &os,
530  const vpImagePoint& ip)
531  {
532  os << ip.get_i() << ", " << ip.get_j();
533  return os;
534 }
535 
536 
537 #endif
538 
539 /*
540  * Local variables:
541  * c-basic-offset: 2
542  * End:
543  */
void set_j(const double j)
Definition: vpImagePoint.h:156
double get_v() const
Definition: vpImagePoint.h:250
VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const double offset)
Definition: vpImagePoint.h:444
VISP_EXPORT vpImagePoint operator/(const vpImagePoint &ip1, const double scale)
Definition: vpImagePoint.h:492
double get_i() const
Definition: vpImagePoint.h:181
double get_u() const
Definition: vpImagePoint.h:239
VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, const double scale)
Definition: vpImagePoint.h:468
void set_i(const double i)
Definition: vpImagePoint.h:145
VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const double offset)
Definition: vpImagePoint.h:384
const vpImagePoint & operator=(const vpImagePoint &ip)
Definition: vpImagePoint.h:130
VISP_EXPORT bool operator!=(const vpImagePoint &ip1, const vpImagePoint &ip2)
Definition: vpImagePoint.h:314
double get_j() const
Definition: vpImagePoint.h:192
VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const int offset)
Definition: vpImagePoint.h:360
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:137
This class aims to compute the homography wrt.two images.
Definition: vpHomography.h:173
void set_ij(const double i, const double j)
Definition: vpImagePoint.h:167
void set_u(const double u)
Definition: vpImagePoint.h:203
VISP_EXPORT bool operator==(const vpImagePoint &ip1, const vpImagePoint &ip2)
Definition: vpImagePoint.h:291
static double sqr(double x)
Definition: vpMath.h:106
void set_v(const double v)
Definition: vpImagePoint.h:214
VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpImagePoint &ip)
Definition: vpImagePoint.h:529
vpImagePoint(const vpImagePoint &ip)
Definition: vpImagePoint.h:118
VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const int offset)
Definition: vpImagePoint.h:420
VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const vpImagePoint &ip2)
Definition: vpImagePoint.h:396
vpImagePoint(double i, double j)
Definition: vpImagePoint.h:107
static double sqrDistance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:273
void set_uv(const double u, const double v)
Definition: vpImagePoint.h:225
Defines a rectangle in the plane.
Definition: vpRect.h:82
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
virtual ~vpImagePoint()
Destructor.
Definition: vpImagePoint.h:123
VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const vpImagePoint &ip2)
Definition: vpImagePoint.h:336
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:261