Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpImagePoint.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2023 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#ifndef _vpImagePoint_h_
35#define _vpImagePoint_h_
36
43#include <visp3/core/vpConfig.h>
44
45#include <cmath> // std::fabs
46#include <limits> // numeric_limits
47#include <ostream>
48#include <vector>
49
50class vpRect;
51
81class VISP_EXPORT vpImagePoint
82{
83public:
88 inline vpImagePoint() : i(0), j(0) {}
93 inline vpImagePoint(double ii, double jj) : i(ii), j(jj) {}
101 inline vpImagePoint(const vpImagePoint &ip) : i(ip.i), j(ip.j) {}
103 inline virtual ~vpImagePoint() {}
104
114 inline double get_i() const { return i; }
115
125 inline double get_j() const { return j; }
126
136 inline double get_u() const { return j; }
137
147 inline double get_v() const { return i; }
148
149 bool inRectangle(const vpRect &rect) const;
150
162 inline bool inSegment(const vpImagePoint &start, const vpImagePoint &end) const
163 {
164 return ((end.get_j() >= start.get_j() && end.get_j() >= this->j && this->j >= start.get_j()) ||
165 (end.get_j() <= start.get_j() && end.get_j() <= this->j && this->j <= start.get_j())) &&
166 ((end.get_i() >= start.get_i() && end.get_i() >= this->i && this->i >= start.get_i()) ||
167 (end.get_i() <= start.get_i() && end.get_i() <= this->i && this->i <= start.get_i()));
168 }
169
215 inline vpImagePoint nextInSegment(const vpImagePoint &start, const vpImagePoint &end) const
216 {
217 const double line_slope = (end.get_i() - start.get_i()) / (end.get_j() - start.get_j());
218 if (fabs(end.get_j() - this->j) > fabs(end.get_i() - this->i)) {
219 double j_ = (end.get_j() > this->j ? this->j + 1 : this->j - 1);
220#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
221 return {end.get_i() - line_slope * (end.get_j() - j_), j_};
222#else
223 return vpImagePoint(end.get_i() - line_slope * (end.get_j() - j_), j_);
224#endif
225 } else {
226 double i_ = (end.get_i() > this->i ? this->i + 1 : this->i - 1);
227#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
228 return {i_, end.get_j() - ((end.get_i() - i_) / line_slope)};
229#else
230 return vpImagePoint(i_, end.get_j() - ((end.get_i() - i_) / line_slope));
231#endif
232 }
233 }
234
239 {
240 this->i = ip.i;
241 this->j = ip.j;
242 return *this;
243 }
244#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
248 inline vpImagePoint &operator=(const vpImagePoint &&ip) noexcept
249 {
250 this->i = ip.i;
251 this->j = ip.j;
252 return *this;
253 }
254#endif
255
256 vpImagePoint &operator+=(const vpImagePoint &ip);
257
264 {
265 this->i -= ip.i;
266 this->j -= ip.j;
267 return *this;
268 }
269 vpImagePoint &operator/=(double scale);
270
275 inline vpImagePoint &operator*=(double scale)
276 {
277 this->i *= scale;
278 this->j *= scale;
279 return *this;
280 }
281
291 inline void set_i(double ii) { this->i = ii; }
292
302 inline void set_j(double jj) { this->j = jj; }
303
313 inline void set_ij(double ii, double jj)
314 {
315 this->i = ii;
316 this->j = jj;
317 }
318
328 inline void set_u(double u) { j = u; }
329
339 inline void set_v(double v) { i = v; }
340
350 inline void set_uv(double u, double v)
351 {
352 this->i = v;
353 this->j = u;
354 }
355
356 static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2);
357 static vpRect getBBox(const std::vector<vpImagePoint> &ipVec);
358 static double sqrDistance(const vpImagePoint &iP1, const vpImagePoint &iP2);
359
360 friend VISP_EXPORT bool operator==(const vpImagePoint &ip1, const vpImagePoint &ip2);
361 friend VISP_EXPORT bool operator!=(const vpImagePoint &ip1, const vpImagePoint &ip2);
362 friend VISP_EXPORT vpImagePoint operator+=(const vpImagePoint &ip1, const vpImagePoint &ip2);
363 friend VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, const vpImagePoint &ip2);
364 friend VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, int offset);
365 friend VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, unsigned int offset);
366 friend VISP_EXPORT vpImagePoint operator+(const vpImagePoint &ip1, double offset);
367 friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, const vpImagePoint &ip2);
368 friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, int offset);
369 friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, unsigned int offset);
370 friend VISP_EXPORT vpImagePoint operator-(const vpImagePoint &ip1, double offset);
371 friend VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, double scale);
372 friend VISP_EXPORT vpImagePoint operator/(const vpImagePoint &ip1, double scale);
373 friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpImagePoint &ip);
374
375private:
376 double i, j;
377};
378
379#endif
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
vpImagePoint & operator-=(const vpImagePoint &ip)
vpImagePoint & operator*=(double scale)
void set_j(double jj)
vpImagePoint & operator=(const vpImagePoint &ip)
double get_j() const
vpImagePoint(double ii, double jj)
void set_ij(double ii, double jj)
virtual ~vpImagePoint()
Destructor.
void set_i(double ii)
vpImagePoint nextInSegment(const vpImagePoint &start, const vpImagePoint &end) const
double get_u() const
void set_u(double u)
void set_uv(double u, double v)
vpImagePoint & operator=(const vpImagePoint &&ip) noexcept
vpImagePoint(const vpImagePoint &ip)
void set_v(double v)
bool inSegment(const vpImagePoint &start, const vpImagePoint &end) const
double get_i() const
double get_v() const
Defines a rectangle in the plane.
Definition vpRect.h:76
vpColVector operator*(const double &x, const vpColVector &v)