Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
vpImagePoint.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
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/=(double scale);
151  inline vpImagePoint &operator*=(double scale)
152  {
153  this->i *= scale;
154  this->j *= scale;
155  return *this;
156  }
157 
167  inline void set_i(double ii) { this->i = ii; }
168 
178  inline void set_j(double jj) { this->j = jj; }
179 
189  inline void set_ij(double ii, 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(double u) { j = u; }
227 
237  inline void set_v(double v) { i = v; }
238 
248  inline void set_uv(double u, 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, int offset);
313  friend VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, unsigned int offset);
314  friend VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, double offset);
315  friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const vpImagePoint &ip2);
316  friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, int offset);
317  friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, unsigned int offset);
318  friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, double offset);
319  friend VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, double scale);
320  friend VISP_EXPORT vpImagePoint operator/(const vpImagePoint &ip1, 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
void set_u(double u)
Definition: vpImagePoint.h:226
void set_uv(double u, double v)
Definition: vpImagePoint.h:248
vpImagePoint & operator*=(double scale)
Definition: vpImagePoint.h:151
vpColVector operator*(const double &x, const vpColVector &v)
double get_u() const
Definition: vpImagePoint.h:263
void set_i(double ii)
Definition: vpImagePoint.h:167
vpImagePoint & operator=(const vpImagePoint &&ip)
Definition: vpImagePoint.h:125
static double sqr(double x)
Definition: vpMath.h:114
double get_j() const
Definition: vpImagePoint.h:215
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(double jj)
Definition: vpImagePoint.h:178
void set_v(double v)
Definition: vpImagePoint.h:237
void set_ij(double ii, double jj)
Definition: vpImagePoint.h:189
static double sqrDistance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:301
vpImagePoint(double ii, double jj)
Definition: vpImagePoint.h:100
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