Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpImagePoint.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Authors:
34  * Nicolas Melchior
35  * Fabien Spindler
36  *
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() &&
56  this->i >= rect.getTop() &&
57  this->j <= rect.getRight() &&
58  this->j >= rect.getLeft());
59 }
60 
89  this->i += ip.i;
90  this->j += ip.j;
91  return *this;
92 }
93 
121  this->i /= scale;
122  this->j /= scale;
123  return *this;
124 }
125 
132 VISP_EXPORT bool operator==( const vpImagePoint &ip1, const vpImagePoint &ip2 ) {
133  //return ( ( ip1.get_i() == ip2.get_i() ) && ( ip1.get_j() == ip2.get_j() ) );
134 
135  double i1 = ip1.get_i();
136  double j1 = ip1.get_j();
137  double i2 = ip2.get_i();
138  double j2 = ip2.get_j();
139 
140  return (
141  ( std::fabs(i1-i2) <= std::fabs(vpMath::maximum(i1, i2))*std::numeric_limits<double>::epsilon() )
142  &&
143  ( std::fabs(j1-j2) <= std::fabs(vpMath::maximum(j1, j2))*std::numeric_limits<double>::epsilon() )
144  );
145 }
146 
154 VISP_EXPORT bool operator!=( const vpImagePoint &ip1, const vpImagePoint &ip2 ) {
155  //return ( ( ip1.get_i() != ip2.get_i() ) || ( ip1.get_j() != ip2.get_j() ) );
156  double i1 = ip1.get_i();
157  double j1 = ip1.get_j();
158  double i2 = ip2.get_i();
159  double j2 = ip2.get_j();
160 
161  return (
162  ( std::fabs(i1-i2) > std::fabs(vpMath::maximum(i1, i2))*std::numeric_limits<double>::epsilon() )
163  ||
164  ( std::fabs(j1-j2) > std::fabs(vpMath::maximum(j1, j2))*std::numeric_limits<double>::epsilon() )
165  );
166 }
167 
175 VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const vpImagePoint &ip2 ) {
176  return ( vpImagePoint(ip1.get_i()+ip2.get_i(), ip1.get_j()+ip2.get_j()));
177 }
185 VISP_EXPORT vpImagePoint operator+=( const vpImagePoint &ip1, const vpImagePoint &ip2 ) {
186  return ( vpImagePoint(ip1.get_i()+ip2.get_i(), ip1.get_j()+ip2.get_j()));
187 }
208 VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const int offset ) {
209  return ( vpImagePoint(ip1.get_i()+offset, ip1.get_j()+offset));
210 }
211 
232 VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const unsigned int offset ) {
233  return ( vpImagePoint(ip1.get_i()+offset, ip1.get_j()+offset));
234 }
235 
256 VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const double offset ) {
257  return ( vpImagePoint(ip1.get_i()+offset, ip1.get_j()+offset));
258 }
259 
267 VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const vpImagePoint &ip2 ) {
268  return ( vpImagePoint(ip1.get_i()-ip2.get_i(), ip1.get_j()-ip2.get_j()));
269 }
290 VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const int offset ) {
291  return ( vpImagePoint(ip1.get_i()-offset, ip1.get_j()-offset));
292 }
313 VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const unsigned int offset ) {
314  return ( vpImagePoint(ip1.get_i()-offset, ip1.get_j()-offset));
315 }
316 
337 VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const double offset ) {
338  return ( vpImagePoint(ip1.get_i()-offset, ip1.get_j()-offset));
339 }
360 VISP_EXPORT vpImagePoint operator*( const vpImagePoint &ip1, const double scale ) {
361  return ( vpImagePoint(ip1.get_i()*scale, ip1.get_j()*scale));
362 }
383 VISP_EXPORT vpImagePoint operator/( const vpImagePoint &ip1, const double scale ) {
384  return ( vpImagePoint(ip1.get_i()/scale, ip1.get_j()/scale));
385 }
386 
419 VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpImagePoint& ip)
420 {
421  os << ip.get_i() << ", " << ip.get_j();
422  return os;
423 }
424 
430 vpRect vpImagePoint::getBBox(const std::vector<vpImagePoint>& ipVec)
431 {
432  vpRect rec(ipVec);
433 
434  return rec;
435 }
double getTop() const
Definition: vpRect.h:178
bool inRectangle(const vpRect &rect) const
double get_i() const
Definition: vpImagePoint.h:199
static vpRect getBBox(const std::vector< vpImagePoint > &ipVec)
vpColVector operator*(const double &x, const vpColVector &v)
vpImagePoint & operator+=(const vpImagePoint &ip)
double getRight() const
Definition: vpRect.h:165
double get_j() const
Definition: vpImagePoint.h:210
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:140
double getBottom() const
Definition: vpRect.h:100
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:267
Defines a rectangle in the plane.
Definition: vpRect.h:82
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:159
vpImagePoint & operator/=(const double scale)