Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpImagePoint.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 https://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
34#include <visp3/core/vpConfig.h>
35#include <visp3/core/vpImagePoint.h>
36#include <visp3/core/vpMath.h>
37#include <visp3/core/vpRect.h>
38
39#include <limits> // numeric_limits
40
50bool vpImagePoint::inRectangle(const vpRect &rect) const
51{
52 return ((this->i <= rect.getBottom()) && (this->i >= rect.getTop()) && (this->j <= rect.getRight()) &&
53 (this->j >= rect.getLeft()));
54}
55
87{
88 this->i += ip.i;
89 this->j += ip.j;
90 return *this;
91}
92
123{
124 this->i /= scale;
125 this->j /= scale;
126 return *this;
127}
128
134VISP_EXPORT bool operator==(const vpImagePoint &ip1, const vpImagePoint &ip2)
135{
136 // --comment: return ip1 dot get_i() eq ip2 dot get_i() and ip1 dot get_j() eq ip2 dot get_j()
137
138 double i1 = ip1.get_i();
139 double j1 = ip1.get_j();
140 double i2 = ip2.get_i();
141 double j2 = ip2.get_j();
142
143 return ((std::fabs(i1 - i2) <= (std::fabs(vpMath::maximum(i1, i2)) * std::numeric_limits<double>::epsilon())) &&
144 (std::fabs(j1 - j2) <= (std::fabs(vpMath::maximum(j1, j2)) * std::numeric_limits<double>::epsilon())));
145}
146
152VISP_EXPORT bool operator!=(const vpImagePoint &ip1, const vpImagePoint &ip2)
153{
154// --comment: return ip1 dot get_i() diff ip2 dot get_i() or ip1 dot get_j() diff ip2 dot get_j()
155 double i1 = ip1.get_i();
156 double j1 = ip1.get_j();
157 double i2 = ip2.get_i();
158 double j2 = ip2.get_j();
159
160 return ((std::fabs(i1 - i2) > (std::fabs(vpMath::maximum(i1, i2)) * std::numeric_limits<double>::epsilon())) ||
161 (std::fabs(j1 - j2) > (std::fabs(vpMath::maximum(j1, j2)) * std::numeric_limits<double>::epsilon())));
162}
163
169VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const vpImagePoint &ip2)
170{
171 return (vpImagePoint(ip1.get_i() + ip2.get_i(), ip1.get_j() + ip2.get_j()));
172}
173
179VISP_EXPORT vpImagePoint operator+=(const vpImagePoint &ip1, const vpImagePoint &ip2)
180{
181 return (vpImagePoint(ip1.get_i() + ip2.get_i(), ip1.get_j() + ip2.get_j()));
182}
183
207VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, int offset)
208{
209 return (vpImagePoint(ip1.get_i() + offset, ip1.get_j() + offset));
210}
211
235VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, unsigned int offset)
236{
237 return (vpImagePoint(ip1.get_i() + offset, ip1.get_j() + offset));
238}
239
263VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, double offset)
264{
265 return (vpImagePoint(ip1.get_i() + offset, ip1.get_j() + offset));
266}
267
274VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const vpImagePoint &ip2)
275{
276 return (vpImagePoint(ip1.get_i() - ip2.get_i(), ip1.get_j() - ip2.get_j()));
277}
278
302VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, int offset)
303{
304 return (vpImagePoint(ip1.get_i() - offset, ip1.get_j() - offset));
305}
306
330VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, unsigned int offset)
331{
332 return (vpImagePoint(ip1.get_i() - offset, ip1.get_j() - offset));
333}
334
358VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, double offset)
359{
360 return (vpImagePoint(ip1.get_i() - offset, ip1.get_j() - offset));
361}
362
386VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, double scale)
387{
388 return (vpImagePoint(ip1.get_i() * scale, ip1.get_j() * scale));
389}
390
414VISP_EXPORT vpImagePoint operator/(const vpImagePoint &ip1, double scale)
415{
416 return (vpImagePoint(ip1.get_i() / scale, ip1.get_j() / scale));
417}
418
455VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpImagePoint &ip)
456{
457 os << ip.get_i() << ", " << ip.get_j();
458 return os;
459}
460
466vpRect vpImagePoint::getBBox(const std::vector<vpImagePoint> &ipVec)
467{
468 vpRect rec(ipVec);
469
470 return rec;
471}
472
482{
483 return sqrt(vpMath::sqr(iP1.get_i() - iP2.get_i()) + vpMath::sqr(iP1.get_j() - iP2.get_j()));
484}
485
495{
496 return vpMath::sqr(iP1.get_i() - iP2.get_i()) + vpMath::sqr(iP1.get_j() - iP2.get_j());
497}
498END_VISP_NAMESPACE
friend VISP_EXPORT bool operator!=(const vpImagePoint &ip1, const vpImagePoint &ip2)
vpImagePoint & operator/=(double scale)
double get_j() const
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
friend VISP_EXPORT bool operator==(const vpImagePoint &ip1, const vpImagePoint &ip2)
vpImagePoint & operator+=(const vpImagePoint &ip)
bool inRectangle(const vpRect &rect) const
friend VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const vpImagePoint &ip2)
static vpRect getBBox(const std::vector< vpImagePoint > &ipVec)
friend VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, double scale)
friend VISP_EXPORT vpImagePoint operator/(const vpImagePoint &ip1, double scale)
friend VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpImagePoint &ip)
static double sqrDistance(const vpImagePoint &iP1, const vpImagePoint &iP2)
friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const vpImagePoint &ip2)
double get_i() const
static Type maximum(const Type &a, const Type &b)
Definition vpMath.h:257
static double sqr(double x)
Definition vpMath.h:203
Defines a rectangle in the plane.
Definition vpRect.h:79
double getLeft() const
Definition vpRect.h:173
double getRight() const
Definition vpRect.h:179
double getBottom() const
Definition vpRect.h:97
double getTop() const
Definition vpRect.h:192