Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpImagePoint.cpp
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 #include <visp3/core/vpConfig.h>
41 #include <visp3/core/vpImagePoint.h>
42 #include <visp3/core/vpRect.h>
43 
53 bool vpImagePoint::inRectangle(const vpRect &rect) const
54 {
55  return (this->i <= rect.getBottom() && this->i >= rect.getTop() && this->j <= rect.getRight() &&
56  this->j >= rect.getLeft());
57 }
58 
88 {
89  this->i += ip.i;
90  this->j += ip.j;
91  return *this;
92 }
93 
122 {
123  this->i /= scale;
124  this->j /= scale;
125  return *this;
126 }
127 
134 VISP_EXPORT bool operator==(const vpImagePoint &ip1, const vpImagePoint &ip2)
135 {
136  // return ( ( ip1.get_i() == ip2.get_i() ) && ( ip1.get_j() == ip2.get_j() )
137  // );
138 
139  double i1 = ip1.get_i();
140  double j1 = ip1.get_j();
141  double i2 = ip2.get_i();
142  double j2 = ip2.get_j();
143 
144  return ((std::fabs(i1 - i2) <= std::fabs(vpMath::maximum(i1, i2)) * std::numeric_limits<double>::epsilon()) &&
145  (std::fabs(j1 - j2) <= std::fabs(vpMath::maximum(j1, j2)) * std::numeric_limits<double>::epsilon()));
146 }
147 
155 VISP_EXPORT bool operator!=(const vpImagePoint &ip1, const vpImagePoint &ip2)
156 {
157  // return ( ( ip1.get_i() != ip2.get_i() ) || ( ip1.get_j() != ip2.get_j() )
158  // );
159  double i1 = ip1.get_i();
160  double j1 = ip1.get_j();
161  double i2 = ip2.get_i();
162  double j2 = ip2.get_j();
163 
164  return ((std::fabs(i1 - i2) > std::fabs(vpMath::maximum(i1, i2)) * std::numeric_limits<double>::epsilon()) ||
165  (std::fabs(j1 - j2) > std::fabs(vpMath::maximum(j1, j2)) * std::numeric_limits<double>::epsilon()));
166 }
167 
175 VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const vpImagePoint &ip2)
176 {
177  return (vpImagePoint(ip1.get_i() + ip2.get_i(), ip1.get_j() + ip2.get_j()));
178 }
186 VISP_EXPORT vpImagePoint operator+=(const vpImagePoint &ip1, const vpImagePoint &ip2)
187 {
188  return (vpImagePoint(ip1.get_i() + ip2.get_i(), ip1.get_j() + ip2.get_j()));
189 }
210 VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const int offset)
211 {
212  return (vpImagePoint(ip1.get_i() + offset, ip1.get_j() + offset));
213 }
214 
235 VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const unsigned int offset)
236 {
237  return (vpImagePoint(ip1.get_i() + offset, ip1.get_j() + offset));
238 }
239 
260 VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const double offset)
261 {
262  return (vpImagePoint(ip1.get_i() + offset, ip1.get_j() + offset));
263 }
264 
273 VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const vpImagePoint &ip2)
274 {
275  return (vpImagePoint(ip1.get_i() - ip2.get_i(), ip1.get_j() - ip2.get_j()));
276 }
297 VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const int offset)
298 {
299  return (vpImagePoint(ip1.get_i() - offset, ip1.get_j() - offset));
300 }
321 VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const unsigned int offset)
322 {
323  return (vpImagePoint(ip1.get_i() - offset, ip1.get_j() - offset));
324 }
325 
346 VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const double offset)
347 {
348  return (vpImagePoint(ip1.get_i() - offset, ip1.get_j() - offset));
349 }
370 VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, const double scale)
371 {
372  return (vpImagePoint(ip1.get_i() * scale, ip1.get_j() * scale));
373 }
394 VISP_EXPORT vpImagePoint operator/(const vpImagePoint &ip1, const double scale)
395 {
396  return (vpImagePoint(ip1.get_i() / scale, ip1.get_j() / scale));
397 }
398 
431 VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpImagePoint &ip)
432 {
433  os << ip.get_i() << ", " << ip.get_j();
434  return os;
435 }
436 
442 vpRect vpImagePoint::getBBox(const std::vector<vpImagePoint> &ipVec)
443 {
444  vpRect rec(ipVec);
445 
446  return rec;
447 }
double getTop() const
Definition: vpRect.h:175
bool inRectangle(const vpRect &rect) const
friend VISP_EXPORT vpImagePoint operator/(const vpImagePoint &ip1, const double scale)
double get_i() const
Definition: vpImagePoint.h:204
static vpRect getBBox(const std::vector< vpImagePoint > &ipVec)
vpImagePoint & operator+=(const vpImagePoint &ip)
friend VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, const double scale)
double getRight() const
Definition: vpRect.h:162
friend VISP_EXPORT bool operator!=(const vpImagePoint &ip1, const vpImagePoint &ip2)
double get_j() const
Definition: vpImagePoint.h:215
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:137
double getBottom() const
Definition: vpRect.h:94
friend VISP_EXPORT bool operator==(const vpImagePoint &ip1, const vpImagePoint &ip2)
friend VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpImagePoint &ip)
friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const vpImagePoint &ip2)
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
double getLeft() const
Definition: vpRect.h:156
friend VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const vpImagePoint &ip2)
vpImagePoint & operator/=(const double scale)