Visual Servoing Platform  version 3.0.0
vpImagePoint.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * 2D point useful for image processing
32  *
33  * Authors:
34  * Nicolas Melchior
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
39 #ifndef vpImagePoint_H
40 #define vpImagePoint_H
41 
48 #include <visp3/core/vpConfig.h>
49 #include <visp3/core/vpMath.h>
50 
51 #include <ostream>
52 #include <cmath> // std::fabs
53 #include <limits> // numeric_limits
54 #include <vector>
55 
56 class vpRect;
57 
88 class VISP_EXPORT vpImagePoint
89 {
90  public:
95  inline vpImagePoint() : i(0), j(0) {}
100  inline vpImagePoint(double ii, double jj) : i(ii), j(jj) {}
108  inline vpImagePoint(const vpImagePoint &ip) : i(ip.i), j(ip.j) {}
110  inline virtual ~vpImagePoint() { ; }
111 
117  inline const vpImagePoint& operator=(const vpImagePoint &ip) {
118  this->i = ip.i;
119  this->j = ip.j;
120  return *this;
121  }
122  vpImagePoint& operator+=(const vpImagePoint &ip);
123 
129  inline vpImagePoint& operator-=(const vpImagePoint &ip) {
130  this->i -= ip.i;
131  this->j -= ip.j;
132  return *this;
133  }
134  vpImagePoint& operator/=(const double scale);
139  inline vpImagePoint& operator*=(const double scale) {
140  this->i *= scale;
141  this->j *= scale;
142  return *this;
143  }
144 
154  inline void set_i(const double ii) { this->i = ii ; }
155 
165  inline void set_j(const double jj) { this->j = jj ; }
166 
176  inline void set_ij(const double ii, const double jj) {
177  this->i = ii ;
178  this->j = jj ;
179  }
180 
190  inline double get_i() const { return i ; }
191 
201  inline double get_j() const { return j ; }
202 
212  inline void set_u(const double u) { j = u ; }
213 
223  inline void set_v(const double v) { i = v ; }
224 
234  inline void set_uv(const double u, const double v) {
235  this->i = v ;
236  this->j = u ;
237  }
238 
248  inline double get_u() const { return j ; }
249 
259  inline double get_v() const { return i; }
260 
270  static double distance (const vpImagePoint &iP1, const vpImagePoint &iP2) {
271  return(sqrt(vpMath::sqr(iP1.get_i()-iP2.get_i())+vpMath::sqr(iP1.get_j()-iP2.get_j())));}
272 
273 
274  static vpRect getBBox(const std::vector<vpImagePoint>& ipVec);
275 
285  static double sqrDistance (const vpImagePoint &iP1, const vpImagePoint &iP2) {
286  return(vpMath::sqr(iP1.get_i()-iP2.get_i())+vpMath::sqr(iP1.get_j()-iP2.get_j()));}
287 
288 
289  bool inRectangle( const vpRect &rect ) const;
290 
291  friend VISP_EXPORT bool operator==( const vpImagePoint &ip1, const vpImagePoint &ip2 );
292  friend VISP_EXPORT bool operator!=( const vpImagePoint &ip1, const vpImagePoint &ip2 );
293  friend VISP_EXPORT vpImagePoint 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 int offset );
296  friend VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const double offset );
297  friend VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const vpImagePoint &ip2 );
298  friend VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const int offset );
299  friend VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const double offset );
300  friend VISP_EXPORT vpImagePoint operator*( const vpImagePoint &ip1, const double scale );
301  friend VISP_EXPORT vpImagePoint operator/( const vpImagePoint &ip1, const double scale );
302  friend VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpImagePoint& ip);
303 
304  private:
305  double i,j;
306 };
307 
308 #endif
double get_v() const
Definition: vpImagePoint.h:259
double get_i() const
Definition: vpImagePoint.h:190
double get_u() const
Definition: vpImagePoint.h:248
const vpImagePoint & operator=(const vpImagePoint &ip)
Definition: vpImagePoint.h:117
double get_j() const
Definition: vpImagePoint.h:201
vpColVector operator*(const double &x, const vpColVector &v)
void set_i(const double ii)
Definition: vpImagePoint.h:154
void set_u(const double u)
Definition: vpImagePoint.h:212
static double sqr(double x)
Definition: vpMath.h:110
void set_v(const double v)
Definition: vpImagePoint.h:223
vpImagePoint(const vpImagePoint &ip)
Definition: vpImagePoint.h:108
vpImagePoint & operator-=(const vpImagePoint &ip)
Definition: vpImagePoint.h:129
void set_j(const double jj)
Definition: vpImagePoint.h:165
vpImagePoint & operator*=(const double scale)
Definition: vpImagePoint.h:139
static double sqrDistance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:285
vpImagePoint(double ii, double jj)
Definition: vpImagePoint.h:100
void set_uv(const double u, const double v)
Definition: vpImagePoint.h:234
Defines a rectangle in the plane.
Definition: vpRect.h:81
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
virtual ~vpImagePoint()
Destructor.
Definition: vpImagePoint.h:110
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:270
void set_ij(const double ii, const double jj)
Definition: vpImagePoint.h:176