ViSP  2.6.2
vpScanPoint.h
1 /****************************************************************************
2  *
3  * $Id: vpScanPoint.h 3530 2012-01-03 10:52:12Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2012 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  * Single laser scanner point.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 #ifndef vpScanPoint_h
42 #define vpScanPoint_h
43 
44 #include <visp/vpMath.h>
45 
46 #include <ostream>
47 #include <cmath> // std::fabs
48 #include <limits> // numeric_limits
49 #include <math.h>
50 
74 class /* VISP_EXPORT */ vpScanPoint // Note that here VISP_EXPORT should not be added since this class is complete inline
75 {
76  public:
78  inline vpScanPoint() {
79  this->rDist = 0;
80  this->hAngle = 0;
81  this->vAngle = 0;
82  }
84  inline vpScanPoint(const vpScanPoint &scanpoint) {
85  this->rDist = scanpoint.rDist;
86  this->hAngle = scanpoint.hAngle;
87  this->vAngle = scanpoint.vAngle;
88  }
95  inline vpScanPoint(double rDist, double hAngle, double vAngle) {
96  this->rDist = rDist;
97  this->hAngle = hAngle;
98  this->vAngle = vAngle;
99  }
101  inline virtual ~vpScanPoint() {};
108  inline void setPolar(double rDist, double hAngle, double vAngle) {
109  this->rDist = rDist;
110  this->hAngle = hAngle;
111  this->vAngle = vAngle;
112  }
116  inline double getRadialDist() const {
117  return ( this->rDist );
118  }
122  inline double getVAngle() const {
123  return ( this->vAngle );
124  }
128  inline double getHAngle() const {
129  return ( this->hAngle );
130  }
138  inline double getX() const {
139  return ( rDist * cos(this->hAngle) * cos(this->vAngle) );
140  }
148  inline double getY() const {
149  return ( rDist * sin(this->hAngle) );
150  }
157  inline double getZ() const {
158  return ( rDist * cos(this->hAngle) * sin(this->vAngle) );
159  }
160 
196  friend inline std::ostream &operator << (std::ostream &s,
197  const vpScanPoint &p) {
198  s.precision(10);
199  s << p.getRadialDist() << " "
200  << p.getHAngle() << " "
201  << p.getVAngle() << " "
202  << p.getX() << " "
203  << p.getY() << " " << p.getZ();
204  return s;
205  }
211  friend inline bool operator==( const vpScanPoint &sp1,
212  const vpScanPoint &sp2 ) {
213  //return ( ( sp1.getRadialDist() == sp2.getRadialDist() )
214  // && ( sp1.getHAngle() == sp2.getHAngle() )
215  // && ( sp1.getVAngle() == sp2.getVAngle() ) );
216  double rd1 = sp1.getRadialDist();
217  double ha1 = sp1.getHAngle();
218  double va1 = sp1.getVAngle();
219  double rd2 = sp2.getRadialDist();
220  double ha2 = sp2.getHAngle();
221  double va2 = sp2.getVAngle();
222 
223  return ( ( std::fabs(rd1 - rd2) <= std::fabs(vpMath::maximum(rd1,rd2)) * std::numeric_limits<double>::epsilon() )
224  &&
225  ( std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1,ha2)) * std::numeric_limits<double>::epsilon() )
226  &&
227  ( std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1,va2)) * std::numeric_limits<double>::epsilon() ) );
228  }
229 
235  friend inline bool operator!=( const vpScanPoint &sp1,
236  const vpScanPoint &sp2 ) {
237  //return ( ( sp1.getRadialDist() != sp2.getRadialDist() )
238  // || ( sp1.getHAngle() != sp2.getHAngle() )
239  // || ( sp1.getVAngle() != sp2.getVAngle() ) );
240  double rd1 = sp1.getRadialDist();
241  double ha1 = sp1.getHAngle();
242  double va1 = sp1.getVAngle();
243  double rd2 = sp2.getRadialDist();
244  double ha2 = sp2.getHAngle();
245  double va2 = sp2.getVAngle();
246  return ( ( std::fabs(rd1 - rd2) > std::fabs(vpMath::maximum(rd1,rd2)) * std::numeric_limits<double>::epsilon() )
247  ||
248  ( std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1,ha2)) * std::numeric_limits<double>::epsilon() )
249  ||
250  ( std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1,va2)) * std::numeric_limits<double>::epsilon() ) );
251  }
252 
253  private:
254  double rDist;
255  double hAngle;
256  double vAngle;
257 };
258 
259 #endif
double getZ() const
Definition: vpScanPoint.h:157
virtual ~vpScanPoint()
Definition: vpScanPoint.h:101
vpScanPoint(const vpScanPoint &scanpoint)
Definition: vpScanPoint.h:84
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:137
Class that defines a single laser scanner point.
Definition: vpScanPoint.h:74
double getRadialDist() const
Definition: vpScanPoint.h:116
double getHAngle() const
Definition: vpScanPoint.h:128
friend bool operator==(const vpScanPoint &sp1, const vpScanPoint &sp2)
Definition: vpScanPoint.h:211
double getX() const
Definition: vpScanPoint.h:138
double getY() const
Definition: vpScanPoint.h:148
vpScanPoint(double rDist, double hAngle, double vAngle)
Definition: vpScanPoint.h:95
void setPolar(double rDist, double hAngle, double vAngle)
Definition: vpScanPoint.h:108
friend std::ostream & operator<<(std::ostream &s, const vpScanPoint &p)
Definition: vpScanPoint.h:196
friend bool operator!=(const vpScanPoint &sp1, const vpScanPoint &sp2)
Definition: vpScanPoint.h:235
double getVAngle() const
Definition: vpScanPoint.h:122