Visual Servoing Platform  version 3.0.0
vpImagePoint.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 }
231 VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const double offset ) {
232  return ( vpImagePoint(ip1.get_i()+offset, ip1.get_j()+offset));
233 }
234 
242 VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const vpImagePoint &ip2 ) {
243  return ( vpImagePoint(ip1.get_i()-ip2.get_i(), ip1.get_j()-ip2.get_j()));
244 }
265 VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const int offset ) {
266  return ( vpImagePoint(ip1.get_i()-offset, ip1.get_j()-offset));
267 }
288 VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const double offset ) {
289  return ( vpImagePoint(ip1.get_i()-offset, ip1.get_j()-offset));
290 }
311 VISP_EXPORT vpImagePoint operator*( const vpImagePoint &ip1, const double scale ) {
312  return ( vpImagePoint(ip1.get_i()*scale, ip1.get_j()*scale));
313 }
334 VISP_EXPORT vpImagePoint operator/( const vpImagePoint &ip1, const double scale ) {
335  return ( vpImagePoint(ip1.get_i()/scale, ip1.get_j()/scale));
336 }
337 
370 VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpImagePoint& ip)
371 {
372  os << ip.get_i() << ", " << ip.get_j();
373  return os;
374 }
375 
381 vpRect vpImagePoint::getBBox(const std::vector<vpImagePoint>& ipVec)
382 {
383  vpRect rec(ipVec);
384 
385  return rec;
386 }
double getTop() const
Definition: vpRect.h:176
bool inRectangle(const vpRect &rect) const
double get_i() const
Definition: vpImagePoint.h:190
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:163
double get_j() const
Definition: vpImagePoint.h:201
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:141
double getBottom() const
Definition: vpRect.h:99
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:267
Defines a rectangle in the plane.
Definition: vpRect.h:81
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:157
vpImagePoint & operator/=(const double scale)