Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
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
49bool 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
127VISP_EXPORT bool operator==(const vpImagePoint &ip1, const vpImagePoint &ip2)
128{
129 // return ( ( ip1.get_i() == ip2.get_i() ) && ( ip1.get_j() == ip2.get_j() )
130 // );
131
132 double i1 = ip1.get_i();
133 double j1 = ip1.get_j();
134 double i2 = ip2.get_i();
135 double j2 = ip2.get_j();
136
137 return ((std::fabs(i1 - i2) <= std::fabs(vpMath::maximum(i1, i2)) * std::numeric_limits<double>::epsilon()) &&
138 (std::fabs(j1 - j2) <= std::fabs(vpMath::maximum(j1, j2)) * std::numeric_limits<double>::epsilon()));
139}
140
146VISP_EXPORT bool operator!=(const vpImagePoint &ip1, const vpImagePoint &ip2)
147{
148 // return ( ( ip1.get_i() != ip2.get_i() ) || ( ip1.get_j() != ip2.get_j() )
149 // );
150 double i1 = ip1.get_i();
151 double j1 = ip1.get_j();
152 double i2 = ip2.get_i();
153 double j2 = ip2.get_j();
154
155 return ((std::fabs(i1 - i2) > std::fabs(vpMath::maximum(i1, i2)) * std::numeric_limits<double>::epsilon()) ||
156 (std::fabs(j1 - j2) > std::fabs(vpMath::maximum(j1, j2)) * std::numeric_limits<double>::epsilon()));
157}
158
164VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const vpImagePoint &ip2)
165{
166 return (vpImagePoint(ip1.get_i() + ip2.get_i(), ip1.get_j() + ip2.get_j()));
167}
168
174VISP_EXPORT vpImagePoint operator+=(const vpImagePoint &ip1, const vpImagePoint &ip2)
175{
176 return (vpImagePoint(ip1.get_i() + ip2.get_i(), ip1.get_j() + ip2.get_j()));
177}
178
198VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, int offset)
199{
200 return (vpImagePoint(ip1.get_i() + offset, ip1.get_j() + offset));
201}
202
222VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, unsigned int offset)
223{
224 return (vpImagePoint(ip1.get_i() + offset, ip1.get_j() + offset));
225}
226
246VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, double offset)
247{
248 return (vpImagePoint(ip1.get_i() + offset, ip1.get_j() + offset));
249}
250
257VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const vpImagePoint &ip2)
258{
259 return (vpImagePoint(ip1.get_i() - ip2.get_i(), ip1.get_j() - ip2.get_j()));
260}
261
281VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, int offset)
282{
283 return (vpImagePoint(ip1.get_i() - offset, ip1.get_j() - offset));
284}
285
305VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, unsigned int offset)
306{
307 return (vpImagePoint(ip1.get_i() - offset, ip1.get_j() - offset));
308}
309
329VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, double offset)
330{
331 return (vpImagePoint(ip1.get_i() - offset, ip1.get_j() - offset));
332}
333
353VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, double scale)
354{
355 return (vpImagePoint(ip1.get_i() * scale, ip1.get_j() * scale));
356}
357
377VISP_EXPORT vpImagePoint operator/(const vpImagePoint &ip1, double scale)
378{
379 return (vpImagePoint(ip1.get_i() / scale, ip1.get_j() / scale));
380}
381
413VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpImagePoint &ip)
414{
415 os << ip.get_i() << ", " << ip.get_j();
416 return os;
417}
418
424vpRect vpImagePoint::getBBox(const std::vector<vpImagePoint> &ipVec)
425{
426 vpRect rec(ipVec);
427
428 return rec;
429}
430
440{
441 return sqrt(vpMath::sqr(iP1.get_i() - iP2.get_i()) + vpMath::sqr(iP1.get_j() - iP2.get_j()));
442}
443
453{
454 return vpMath::sqr(iP1.get_i() - iP2.get_i()) + vpMath::sqr(iP1.get_j() - iP2.get_j());
455}
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
vpImagePoint & operator/=(double scale)
double get_j() const
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
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)
static double sqrDistance(const vpImagePoint &iP1, const vpImagePoint &iP2)
double get_i() const
static Type maximum(const Type &a, const Type &b)
Definition vpMath.h:172
static double sqr(double x)
Definition vpMath.h:124
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
vpColVector operator*(const double &x, const vpColVector &v)