Visual Servoing Platform  version 3.1.0
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 modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * 2D point useful for image processing
33  *
34  * Authors:
35  * Nicolas Melchior
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
40 #ifndef vpImagePoint_H
41 #define vpImagePoint_H
42 
49 #include <visp3/core/vpConfig.h>
50 #include <visp3/core/vpMath.h>
51 
52 #include <cmath> // std::fabs
53 #include <limits> // numeric_limits
54 #include <ostream>
55 #include <vector>
56 
57 class vpRect;
58 
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 
116  {
117  this->i = ip.i;
118  this->j = ip.j;
119  return *this;
120  }
121 #ifdef VISP_HAVE_CPP11_COMPATIBILITY
122 
125  inline vpImagePoint &operator=(const vpImagePoint &&ip)
126  {
127  this->i = std::move(ip.i);
128  this->j = std::move(ip.j);
129  return *this;
130  }
131 #endif
132 
133  vpImagePoint &operator+=(const vpImagePoint &ip);
134 
141  {
142  this->i -= ip.i;
143  this->j -= ip.j;
144  return *this;
145  }
146  vpImagePoint &operator/=(const double scale);
151  inline vpImagePoint &operator*=(const double scale)
152  {
153  this->i *= scale;
154  this->j *= scale;
155  return *this;
156  }
157 
167  inline void set_i(const double ii) { this->i = ii; }
168 
178  inline void set_j(const double jj) { this->j = jj; }
179 
189  inline void set_ij(const double ii, const double jj)
190  {
191  this->i = ii;
192  this->j = jj;
193  }
194 
204  inline double get_i() const { return i; }
205 
215  inline double get_j() const { return j; }
216 
226  inline void set_u(const double u) { j = u; }
227 
237  inline void set_v(const double v) { i = v; }
238 
248  inline void set_uv(const double u, const double v)
249  {
250  this->i = v;
251  this->j = u;
252  }
253 
263  inline double get_u() const { return j; }
264 
274  inline double get_v() const { return i; }
275 
285  static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
286  {
287  return (sqrt(vpMath::sqr(iP1.get_i() - iP2.get_i()) + vpMath::sqr(iP1.get_j() - iP2.get_j())));
288  }
289 
290  static vpRect getBBox(const std::vector<vpImagePoint> &ipVec);
291 
301  static double sqrDistance(const vpImagePoint &iP1, const vpImagePoint &iP2)
302  {
303  return (vpMath::sqr(iP1.get_i() - iP2.get_i()) + vpMath::sqr(iP1.get_j() - iP2.get_j()));
304  }
305 
306  bool inRectangle(const vpRect &rect) const;
307 
308  friend VISP_EXPORT bool operator==(const vpImagePoint &ip1, const vpImagePoint &ip2);
309  friend VISP_EXPORT bool operator!=(const vpImagePoint &ip1, const vpImagePoint &ip2);
310  friend VISP_EXPORT vpImagePoint operator+=(const vpImagePoint &ip1, const vpImagePoint &ip2);
311  friend VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const vpImagePoint &ip2);
312  friend VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const int offset);
313  friend VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const unsigned int offset);
314  friend VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const double offset);
315  friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const vpImagePoint &ip2);
316  friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const int offset);
317  friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const unsigned int offset);
318  friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const double offset);
319  friend VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, const double scale);
320  friend VISP_EXPORT vpImagePoint operator/(const vpImagePoint &ip1, const double scale);
321  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpImagePoint &ip);
322 
323 private:
324  double i, j;
325 };
326 
327 #endif
double get_i() const
Definition: vpImagePoint.h:204
vpColVector operator*(const double &x, const vpColVector &v)
void set_i(const double ii)
Definition: vpImagePoint.h:167
double get_u() const
Definition: vpImagePoint.h:263
vpImagePoint & operator=(const vpImagePoint &&ip)
Definition: vpImagePoint.h:125
void set_u(const double u)
Definition: vpImagePoint.h:226
static double sqr(double x)
Definition: vpMath.h:108
double get_j() const
Definition: vpImagePoint.h:215
void set_v(const double v)
Definition: vpImagePoint.h:237
vpImagePoint(const vpImagePoint &ip)
Definition: vpImagePoint.h:108
vpImagePoint & operator-=(const vpImagePoint &ip)
Definition: vpImagePoint.h:140
vpImagePoint & operator=(const vpImagePoint &ip)
Definition: vpImagePoint.h:115
void set_j(const double jj)
Definition: vpImagePoint.h:178
vpImagePoint & operator*=(const double scale)
Definition: vpImagePoint.h:151
static double sqrDistance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:301
vpImagePoint(double ii, double jj)
Definition: vpImagePoint.h:100
void set_uv(const double u, const double v)
Definition: vpImagePoint.h:248
Defines a rectangle in the plane.
Definition: vpRect.h:78
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
double get_v() const
Definition: vpImagePoint.h:274
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:285
void set_ij(const double ii, const double jj)
Definition: vpImagePoint.h:189