ViSP  2.9.0
vpImagePoint.h
1 /****************************************************************************
2  *
3  * $Id: vpImagePoint.h 4649 2014-02-07 14:57:11Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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() : i(0), j(0) {}
104  inline vpImagePoint(double ii, double jj) : i(ii), j(jj) {}
112  inline vpImagePoint(const vpImagePoint &ip) : i(ip.i), j(ip.j) {}
114  inline virtual ~vpImagePoint() { ; }
115 
121  inline const vpImagePoint& operator=(const vpImagePoint &ip) {
122  this->i = ip.i;
123  this->j = ip.j;
124  return *this;
125  }
126  vpImagePoint& operator+=(const vpImagePoint &ip);
127 
133  inline vpImagePoint& operator-=(const vpImagePoint &ip) {
134  this->i -= ip.i;
135  this->j -= ip.j;
136  return *this;
137  }
138  vpImagePoint& operator/=(const double scale);
143  inline vpImagePoint& operator*=(const double scale) {
144  this->i *= scale;
145  this->j *= scale;
146  return *this;
147  }
148 
158  inline void set_i(const double ii) { this->i = ii ; }
159 
169  inline void set_j(const double jj) { this->j = jj ; }
170 
180  inline void set_ij(const double ii, const double jj) {
181  this->i = ii ;
182  this->j = jj ;
183  }
184 
194  inline double get_i() const { return i ; }
195 
205  inline double get_j() const { return j ; }
206 
216  inline void set_u(const double u) { j = u ; }
217 
227  inline void set_v(const double v) { i = v ; }
228 
238  inline void set_uv(const double u, const double v) {
239  this->i = v ;
240  this->j = u ;
241  }
242 
252  inline double get_u() const { return j ; }
253 
263  inline double get_v() const { return i; }
264 
274  static double distance (const vpImagePoint &iP1, const vpImagePoint &iP2) {
275  return(sqrt(vpMath::sqr(iP1.get_i()-iP2.get_i())+vpMath::sqr(iP1.get_j()-iP2.get_j())));}
276 
286  static double sqrDistance (const vpImagePoint &iP1, const vpImagePoint &iP2) {
287  return(vpMath::sqr(iP1.get_i()-iP2.get_i())+vpMath::sqr(iP1.get_j()-iP2.get_j()));}
288 
289 
290  bool inRectangle( const vpRect &rect ) const;
291 
292  friend VISP_EXPORT bool operator==( const vpImagePoint &ip1, const vpImagePoint &ip2 );
293  friend VISP_EXPORT bool operator!=( const vpImagePoint &ip1, const vpImagePoint &ip2 );
294  friend VISP_EXPORT vpImagePoint operator+=( const vpImagePoint &ip1, const vpImagePoint &ip2 );
295  friend VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const vpImagePoint &ip2 );
296  friend VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const int offset );
297  friend VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const double offset );
298  friend VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const vpImagePoint &ip2 );
299  friend VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const int offset );
300  friend VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const double offset );
301  friend VISP_EXPORT vpImagePoint operator*( const vpImagePoint &ip1, const double scale );
302  friend VISP_EXPORT vpImagePoint operator/( const vpImagePoint &ip1, const double scale );
303  friend VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpImagePoint& ip);
304 
305  vpImagePoint projection(const vpHomography& aHb);
306 
307  private:
308  double i,j;
309 };
310 
311 #endif
double get_v() const
Definition: vpImagePoint.h:263
double get_i() const
Definition: vpImagePoint.h:194
double get_u() const
Definition: vpImagePoint.h:252
const vpImagePoint & operator=(const vpImagePoint &ip)
Definition: vpImagePoint.h:121
double get_j() const
Definition: vpImagePoint.h:205
This class aims to compute the homography wrt.two images.
Definition: vpHomography.h:178
void set_i(const double ii)
Definition: vpImagePoint.h:158
void set_u(const double u)
Definition: vpImagePoint.h:216
static double sqr(double x)
Definition: vpMath.h:106
void set_v(const double v)
Definition: vpImagePoint.h:227
vpImagePoint(const vpImagePoint &ip)
Definition: vpImagePoint.h:112
vpImagePoint & operator-=(const vpImagePoint &ip)
Definition: vpImagePoint.h:133
void set_j(const double jj)
Definition: vpImagePoint.h:169
vpImagePoint & operator*=(const double scale)
Definition: vpImagePoint.h:143
static double sqrDistance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:286
vpImagePoint(double ii, double jj)
Definition: vpImagePoint.h:104
void set_uv(const double u, const double v)
Definition: vpImagePoint.h:238
Defines a rectangle in the plane.
Definition: vpRect.h:85
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:114
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:274
void set_ij(const double ii, const double jj)
Definition: vpImagePoint.h:180