ViSP  2.9.0
vpImagePoint.cpp
1 /****************************************************************************
2  *
3  * $Id: vpImagePoint.cpp 4640 2014-02-05 12:41:38Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * 2D point useful for image processing
36  *
37  * Authors:
38  * Nicolas Melchior
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
43 
44 #include <visp/vpConfig.h>
45 #include <visp/vpImagePoint.h>
46 #include <visp/vpRect.h>
47 #include <visp/vpHomography.h>
48 
58 bool vpImagePoint::inRectangle( const vpRect &rect ) const
59 {
60  return ( this->i <= rect.getBottom() &&
61  this->i >= rect.getTop() &&
62  this->j <= rect.getRight() &&
63  this->j >= rect.getLeft());
64 }
65 
75 {
76  vpImagePoint ap;
77 
78  double i_a = aHb[0][0] * i + aHb[0][1] * j + aHb[0][2];
79  double j_a = aHb[1][0] * i + aHb[1][1] * j + aHb[1][2];
80  double k_a = aHb[2][0] * i + aHb[2][1] * j + aHb[2][2];
81 
82  if(std::fabs(k_a) > std::numeric_limits<double>::epsilon()){
83  ap.set_i(i_a / k_a);
84  ap.set_j(j_a / k_a);
85  }
86 
87  return ap;
88 }
89 
118  this->i += ip.i;
119  this->j += ip.j;
120  return *this;
121 }
122 
150  this->i /= scale;
151  this->j /= scale;
152  return *this;
153 }
154 
161 VISP_EXPORT bool operator==( const vpImagePoint &ip1, const vpImagePoint &ip2 ) {
162  //return ( ( ip1.get_i() == ip2.get_i() ) && ( ip1.get_j() == ip2.get_j() ) );
163 
164  double i1 = ip1.get_i();
165  double j1 = ip1.get_j();
166  double i2 = ip2.get_i();
167  double j2 = ip2.get_j();
168 
169  return (
170  ( std::fabs(i1-i2) <= std::fabs(vpMath::maximum(i1, i2))*std::numeric_limits<double>::epsilon() )
171  &&
172  ( std::fabs(j1-j2) <= std::fabs(vpMath::maximum(j1, j2))*std::numeric_limits<double>::epsilon() )
173  );
174 }
175 
183 VISP_EXPORT bool operator!=( const vpImagePoint &ip1, const vpImagePoint &ip2 ) {
184  //return ( ( ip1.get_i() != ip2.get_i() ) || ( ip1.get_j() != ip2.get_j() ) );
185  double i1 = ip1.get_i();
186  double j1 = ip1.get_j();
187  double i2 = ip2.get_i();
188  double j2 = ip2.get_j();
189 
190  return (
191  ( std::fabs(i1-i2) > std::fabs(vpMath::maximum(i1, i2))*std::numeric_limits<double>::epsilon() )
192  ||
193  ( std::fabs(j1-j2) > std::fabs(vpMath::maximum(j1, j2))*std::numeric_limits<double>::epsilon() )
194  );
195 }
196 
204 VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const vpImagePoint &ip2 ) {
205  return ( vpImagePoint(ip1.get_i()+ip2.get_i(), ip1.get_j()+ip2.get_j()));
206 }
214 VISP_EXPORT vpImagePoint operator+=( const vpImagePoint &ip1, const vpImagePoint &ip2 ) {
215  return ( vpImagePoint(ip1.get_i()+ip2.get_i(), ip1.get_j()+ip2.get_j()));
216 }
237 VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const int offset ) {
238  return ( vpImagePoint(ip1.get_i()+offset, ip1.get_j()+offset));
239 }
260 VISP_EXPORT vpImagePoint operator+( const vpImagePoint &ip1, const double offset ) {
261  return ( vpImagePoint(ip1.get_i()+offset, ip1.get_j()+offset));
262 }
263 
271 VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const vpImagePoint &ip2 ) {
272  return ( vpImagePoint(ip1.get_i()-ip2.get_i(), ip1.get_j()-ip2.get_j()));
273 }
294 VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const int offset ) {
295  return ( vpImagePoint(ip1.get_i()-offset, ip1.get_j()-offset));
296 }
317 VISP_EXPORT vpImagePoint operator-( const vpImagePoint &ip1, const double offset ) {
318  return ( vpImagePoint(ip1.get_i()-offset, ip1.get_j()-offset));
319 }
340 VISP_EXPORT vpImagePoint operator*( const vpImagePoint &ip1, const double scale ) {
341  return ( vpImagePoint(ip1.get_i()*scale, ip1.get_j()*scale));
342 }
363 VISP_EXPORT vpImagePoint operator/( const vpImagePoint &ip1, const double scale ) {
364  return ( vpImagePoint(ip1.get_i()/scale, ip1.get_j()/scale));
365 }
366 
399 VISP_EXPORT std::ostream& operator<< (std::ostream &os, const vpImagePoint& ip)
400  {
401  os << ip.get_i() << ", " << ip.get_j();
402  return os;
403 }
double getTop() const
Definition: vpRect.h:174
bool inRectangle(const vpRect &rect) const
double get_i() const
Definition: vpImagePoint.h:194
vpImagePoint & operator+=(const vpImagePoint &ip)
double getRight() const
Definition: vpRect.h:167
double get_j() const
Definition: vpImagePoint.h:205
vpColVector operator*(const double &x, const vpColVector &B)
multiplication by a scalar Ci = x*Bi
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:137
This class aims to compute the homography wrt.two images.
Definition: vpHomography.h:178
double getBottom() const
Definition: vpRect.h:103
void set_i(const double ii)
Definition: vpImagePoint.h:158
void set_j(const double jj)
Definition: vpImagePoint.h:169
vpImagePoint projection(const vpHomography &aHb)
Defines a rectangle in the plane.
Definition: vpRect.h:85
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
double getLeft() const
Definition: vpRect.h:161
vpImagePoint & operator/=(const double scale)