Visual Servoing Platform  version 3.6.1 under development (2024-04-28)
vpImagePoint.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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 *****************************************************************************/
35 
36 #include <visp3/core/vpConfig.h>
37 #include <visp3/core/vpImagePoint.h>
38 #include <visp3/core/vpMath.h>
39 #include <visp3/core/vpRect.h>
40 
49 bool vpImagePoint::inRectangle(const vpRect &rect) const
50 {
51  return ((this->i <= rect.getBottom()) && (this->i >= rect.getTop()) && (this->j <= rect.getRight()) &&
52  (this->j >= rect.getLeft()));
53 }
54 
83 {
84  this->i += ip.i;
85  this->j += ip.j;
86  return *this;
87 }
88 
116 {
117  this->i /= scale;
118  this->j /= scale;
119  return *this;
120 }
121 
127 VISP_EXPORT bool operator==(const vpImagePoint &ip1, const vpImagePoint &ip2)
128 {
129  // --comment: return ip1 dot get_i() eq ip2 dot get_i() and ip1 dot get_j() eq ip2 dot get_j()
130 
131  double i1 = ip1.get_i();
132  double j1 = ip1.get_j();
133  double i2 = ip2.get_i();
134  double j2 = ip2.get_j();
135 
136  return ((std::fabs(i1 - i2) <= (std::fabs(vpMath::maximum(i1, i2)) * std::numeric_limits<double>::epsilon())) &&
137  (std::fabs(j1 - j2) <= (std::fabs(vpMath::maximum(j1, j2)) * std::numeric_limits<double>::epsilon())));
138 }
139 
145 VISP_EXPORT bool operator!=(const vpImagePoint &ip1, const vpImagePoint &ip2)
146 {
147  // --comment: return ip1 dot get_i() diff ip2 dot get_i() or ip1 dot get_j() diff ip2 dot get_j()
148  double i1 = ip1.get_i();
149  double j1 = ip1.get_j();
150  double i2 = ip2.get_i();
151  double j2 = ip2.get_j();
152 
153  return ((std::fabs(i1 - i2) > (std::fabs(vpMath::maximum(i1, i2)) * std::numeric_limits<double>::epsilon())) ||
154  (std::fabs(j1 - j2) > (std::fabs(vpMath::maximum(j1, j2)) * std::numeric_limits<double>::epsilon())));
155 }
156 
162 VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const vpImagePoint &ip2)
163 {
164  return (vpImagePoint(ip1.get_i() + ip2.get_i(), ip1.get_j() + ip2.get_j()));
165 }
166 
172 VISP_EXPORT vpImagePoint operator+=(const vpImagePoint &ip1, const vpImagePoint &ip2)
173 {
174  return (vpImagePoint(ip1.get_i() + ip2.get_i(), ip1.get_j() + ip2.get_j()));
175 }
176 
196 VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, int offset)
197 {
198  return (vpImagePoint(ip1.get_i() + offset, ip1.get_j() + offset));
199 }
200 
220 VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, unsigned int offset)
221 {
222  return (vpImagePoint(ip1.get_i() + offset, ip1.get_j() + offset));
223 }
224 
244 VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, double offset)
245 {
246  return (vpImagePoint(ip1.get_i() + offset, ip1.get_j() + offset));
247 }
248 
255 VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const vpImagePoint &ip2)
256 {
257  return (vpImagePoint(ip1.get_i() - ip2.get_i(), ip1.get_j() - ip2.get_j()));
258 }
259 
279 VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, int offset)
280 {
281  return (vpImagePoint(ip1.get_i() - offset, ip1.get_j() - offset));
282 }
283 
303 VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, unsigned int offset)
304 {
305  return (vpImagePoint(ip1.get_i() - offset, ip1.get_j() - offset));
306 }
307 
327 VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, double offset)
328 {
329  return (vpImagePoint(ip1.get_i() - offset, ip1.get_j() - offset));
330 }
331 
351 VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, double scale)
352 {
353  return (vpImagePoint(ip1.get_i() * scale, ip1.get_j() * scale));
354 }
355 
375 VISP_EXPORT vpImagePoint operator/(const vpImagePoint &ip1, double scale)
376 {
377  return (vpImagePoint(ip1.get_i() / scale, ip1.get_j() / scale));
378 }
379 
411 VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpImagePoint &ip)
412 {
413  os << ip.get_i() << ", " << ip.get_j();
414  return os;
415 }
416 
422 vpRect vpImagePoint::getBBox(const std::vector<vpImagePoint> &ipVec)
423 {
424  vpRect rec(ipVec);
425 
426  return rec;
427 }
428 
437 double vpImagePoint::distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
438 {
439  return sqrt(vpMath::sqr(iP1.get_i() - iP2.get_i()) + vpMath::sqr(iP1.get_j() - iP2.get_j()));
440 }
441 
451 {
452  return vpMath::sqr(iP1.get_i() - iP2.get_i()) + vpMath::sqr(iP1.get_j() - iP2.get_j());
453 }
bool operator==(const vpArray2D< double > &A) const
Definition: vpArray2D.h:1264
bool operator!=(const vpArray2D< Type > &A) const
Definition: vpArray2D.h:1300
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:600
vpColVector operator*(const double &x, const vpColVector &v)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
vpImagePoint & operator/=(double scale)
double get_j() const
Definition: vpImagePoint.h:125
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
bool inRectangle(const vpRect &rect) const
vpImagePoint & operator+=(const vpImagePoint &ip)
VISP_EXPORT vpImagePoint operator+=(const vpImagePoint &ip1, const vpImagePoint &ip2)
VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const vpImagePoint &ip2)
static vpRect getBBox(const std::vector< vpImagePoint > &ipVec)
VISP_EXPORT vpImagePoint operator/(const vpImagePoint &ip1, double scale)
static double sqrDistance(const vpImagePoint &iP1, const vpImagePoint &iP2)
VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const vpImagePoint &ip2)
double get_i() const
Definition: vpImagePoint.h:114
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:252
static double sqr(double x)
Definition: vpMath.h:201
Defines a rectangle in the plane.
Definition: vpRect.h:76
double getLeft() const
Definition: vpRect.h:170
double getRight() const
Definition: vpRect.h:176
double getBottom() const
Definition: vpRect.h:94
double getTop() const
Definition: vpRect.h:189