Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpImagePoint.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 
115  inline const vpImagePoint& operator=(const vpImagePoint &ip) {
116  this->i = ip.i;
117  this->j = ip.j;
118  return *this;
119  }
120 #ifdef VISP_HAVE_CPP11_COMPATIBILITY
121 
124  inline const vpImagePoint& operator=(const vpImagePoint &&ip) {
125  this->i = std::move(ip.i);
126  this->j = std::move(ip.j);
127  return *this;
128  }
129 #endif
130 
131  vpImagePoint& operator+=(const vpImagePoint &ip);
132 
138  inline vpImagePoint& operator-=(const vpImagePoint &ip) {
139  this->i -= ip.i;
140  this->j -= ip.j;
141  return *this;
142  }
143  vpImagePoint& operator/=(const double scale);
148  inline vpImagePoint& operator*=(const double scale) {
149  this->i *= scale;
150  this->j *= scale;
151  return *this;
152  }
153 
163  inline void set_i(const double ii) { this->i = ii ; }
164 
174  inline void set_j(const double jj) { this->j = jj ; }
175 
185  inline void set_ij(const double ii, const double jj) {
186  this->i = ii ;
187  this->j = jj ;
188  }
189 
199  inline double get_i() const { return i ; }
200 
210  inline double get_j() const { return j ; }
211 
221  inline void set_u(const double u) { j = u ; }
222 
232  inline void set_v(const double v) { i = v ; }
233 
243  inline void set_uv(const double u, const double v) {
244  this->i = v ;
245  this->j = u ;
246  }
247 
257  inline double get_u() const { return j ; }
258 
268  inline double get_v() const { return i; }
269 
279  static double distance (const vpImagePoint &iP1, const vpImagePoint &iP2) {
280  return(sqrt(vpMath::sqr(iP1.get_i()-iP2.get_i())+vpMath::sqr(iP1.get_j()-iP2.get_j())));}
281 
282 
283  static vpRect getBBox(const std::vector<vpImagePoint>& ipVec);
284 
294  static double sqrDistance (const vpImagePoint &iP1, const vpImagePoint &iP2) {
295  return(vpMath::sqr(iP1.get_i()-iP2.get_i())+vpMath::sqr(iP1.get_j()-iP2.get_j()));}
296 
297 
298  bool inRectangle( const vpRect &rect ) const;
299 
300  friend VISP_EXPORT bool operator==( const vpImagePoint &ip1, const vpImagePoint &ip2 );
301  friend VISP_EXPORT bool operator!=( const vpImagePoint &ip1, const vpImagePoint &ip2 );
302  friend VISP_EXPORT vpImagePoint operator+=( const vpImagePoint &ip1, const vpImagePoint &ip2 );
303  friend VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const vpImagePoint &ip2 );
304  friend VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const int offset );
305  friend VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const unsigned int offset );
306  friend VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const double offset );
307  friend VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const vpImagePoint &ip2 );
308  friend VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const int offset );
309  friend VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const unsigned int offset );
310  friend VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const double offset );
311  friend VISP_EXPORT vpImagePoint operator*( const vpImagePoint &ip1, const double scale );
312  friend VISP_EXPORT vpImagePoint operator/( const vpImagePoint &ip1, const double scale );
313  friend VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpImagePoint& ip);
314 
315  private:
316  double i,j;
317 };
318 
319 #endif
double get_v() const
Definition: vpImagePoint.h:268
double get_i() const
Definition: vpImagePoint.h:199
double get_u() const
Definition: vpImagePoint.h:257
const vpImagePoint & operator=(const vpImagePoint &ip)
Definition: vpImagePoint.h:115
double get_j() const
Definition: vpImagePoint.h:210
vpColVector operator*(const double &x, const vpColVector &v)
void set_i(const double ii)
Definition: vpImagePoint.h:163
void set_u(const double u)
Definition: vpImagePoint.h:221
static double sqr(double x)
Definition: vpMath.h:110
const vpImagePoint & operator=(const vpImagePoint &&ip)
Definition: vpImagePoint.h:124
void set_v(const double v)
Definition: vpImagePoint.h:232
vpImagePoint(const vpImagePoint &ip)
Definition: vpImagePoint.h:108
vpImagePoint & operator-=(const vpImagePoint &ip)
Definition: vpImagePoint.h:138
void set_j(const double jj)
Definition: vpImagePoint.h:174
vpImagePoint & operator*=(const double scale)
Definition: vpImagePoint.h:148
static double sqrDistance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:294
vpImagePoint(double ii, double jj)
Definition: vpImagePoint.h:100
void set_uv(const double u, const double v)
Definition: vpImagePoint.h:243
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:88
virtual ~vpImagePoint()
Destructor.
Definition: vpImagePoint.h:110
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:279
void set_ij(const double ii, const double jj)
Definition: vpImagePoint.h:185