ViSP  2.10.0
vpImagePoint.h
1 /****************************************************************************
2  *
3  * $Id: vpImagePoint.h 5175 2015-01-15 17:06:07Z nmeriaux $
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 #include <vector>
59 
60 class vpHomography;
61 class vpRect;
62 
93 class VISP_EXPORT vpImagePoint
94 {
95  public:
100  inline vpImagePoint() : i(0), j(0) {}
105  inline vpImagePoint(double ii, double jj) : i(ii), j(jj) {}
113  inline vpImagePoint(const vpImagePoint &ip) : i(ip.i), j(ip.j) {}
115  inline virtual ~vpImagePoint() { ; }
116 
122  inline const vpImagePoint& operator=(const vpImagePoint &ip) {
123  this->i = ip.i;
124  this->j = ip.j;
125  return *this;
126  }
127  vpImagePoint& operator+=(const vpImagePoint &ip);
128 
134  inline vpImagePoint& operator-=(const vpImagePoint &ip) {
135  this->i -= ip.i;
136  this->j -= ip.j;
137  return *this;
138  }
139  vpImagePoint& operator/=(const double scale);
144  inline vpImagePoint& operator*=(const double scale) {
145  this->i *= scale;
146  this->j *= scale;
147  return *this;
148  }
149 
159  inline void set_i(const double ii) { this->i = ii ; }
160 
170  inline void set_j(const double jj) { this->j = jj ; }
171 
181  inline void set_ij(const double ii, const double jj) {
182  this->i = ii ;
183  this->j = jj ;
184  }
185 
195  inline double get_i() const { return i ; }
196 
206  inline double get_j() const { return j ; }
207 
217  inline void set_u(const double u) { j = u ; }
218 
228  inline void set_v(const double v) { i = v ; }
229 
239  inline void set_uv(const double u, const double v) {
240  this->i = v ;
241  this->j = u ;
242  }
243 
253  inline double get_u() const { return j ; }
254 
264  inline double get_v() const { return i; }
265 
275  static double distance (const vpImagePoint &iP1, const vpImagePoint &iP2) {
276  return(sqrt(vpMath::sqr(iP1.get_i()-iP2.get_i())+vpMath::sqr(iP1.get_j()-iP2.get_j())));}
277 
278 
279  static vpRect getBBox(const std::vector<vpImagePoint>& ipVec);
280 
290  static double sqrDistance (const vpImagePoint &iP1, const vpImagePoint &iP2) {
291  return(vpMath::sqr(iP1.get_i()-iP2.get_i())+vpMath::sqr(iP1.get_j()-iP2.get_j()));}
292 
293 
294  bool inRectangle( const vpRect &rect ) const;
295 
296  friend VISP_EXPORT bool operator==( const vpImagePoint &ip1, const vpImagePoint &ip2 );
297  friend VISP_EXPORT bool operator!=( const vpImagePoint &ip1, const vpImagePoint &ip2 );
298  friend VISP_EXPORT vpImagePoint operator+=( const vpImagePoint &ip1, const vpImagePoint &ip2 );
299  friend VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const vpImagePoint &ip2 );
300  friend VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const int offset );
301  friend VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const double offset );
302  friend VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const vpImagePoint &ip2 );
303  friend VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const int offset );
304  friend VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const double offset );
305  friend VISP_EXPORT vpImagePoint operator*( const vpImagePoint &ip1, const double scale );
306  friend VISP_EXPORT vpImagePoint operator/( const vpImagePoint &ip1, const double scale );
307  friend VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpImagePoint& ip);
308 
309  vpImagePoint projection(const vpHomography& aHb);
310 
311  private:
312  double i,j;
313 };
314 
315 #endif
double get_v() const
Definition: vpImagePoint.h:264
double get_i() const
Definition: vpImagePoint.h:195
double get_u() const
Definition: vpImagePoint.h:253
const vpImagePoint & operator=(const vpImagePoint &ip)
Definition: vpImagePoint.h:122
double get_j() const
Definition: vpImagePoint.h:206
This class aims to compute the homography wrt.two images.
Definition: vpHomography.h:178
void set_i(const double ii)
Definition: vpImagePoint.h:159
void set_u(const double u)
Definition: vpImagePoint.h:217
static double sqr(double x)
Definition: vpMath.h:106
void set_v(const double v)
Definition: vpImagePoint.h:228
vpImagePoint(const vpImagePoint &ip)
Definition: vpImagePoint.h:113
vpImagePoint & operator-=(const vpImagePoint &ip)
Definition: vpImagePoint.h:134
void set_j(const double jj)
Definition: vpImagePoint.h:170
vpImagePoint & operator*=(const double scale)
Definition: vpImagePoint.h:144
static double sqrDistance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:290
vpImagePoint(double ii, double jj)
Definition: vpImagePoint.h:105
void set_uv(const double u, const double v)
Definition: vpImagePoint.h:239
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:93
virtual ~vpImagePoint()
Destructor.
Definition: vpImagePoint.h:115
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:275
void set_ij(const double ii, const double jj)
Definition: vpImagePoint.h:181