ViSP  2.9.0
vpScanPoint.h
1 /****************************************************************************
2  *
3  * $Id: vpScanPoint.h 4649 2014-02-07 14:57:11Z 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  * 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 <sstream>
48 #include <cmath> // std::fabs
49 #include <limits> // numeric_limits
50 #include <math.h>
51 
75 class /* VISP_EXPORT */ vpScanPoint // Note that here VISP_EXPORT should not be added since this class is complete inline
76 {
77  public:
79  inline vpScanPoint() : rDist(0), hAngle(0), vAngle(0) {}
81  inline vpScanPoint(const vpScanPoint &scanpoint) : rDist(0), hAngle(0), vAngle(0) {
82  this->rDist = scanpoint.rDist;
83  this->hAngle = scanpoint.hAngle;
84  this->vAngle = scanpoint.vAngle;
85  }
92  inline vpScanPoint(double r_dist, double h_angle, double v_angle)
93  : rDist(r_dist), hAngle(h_angle), vAngle(v_angle)
94  {
95  this->rDist = r_dist;
96  this->hAngle = h_angle;
97  this->vAngle = v_angle;
98  }
100  inline virtual ~vpScanPoint() {};
107  inline void setPolar(double r_dist, double h_angle, double v_angle) {
108  this->rDist = r_dist;
109  this->hAngle = h_angle;
110  this->vAngle = v_angle;
111  }
115  inline double getRadialDist() const {
116  return ( this->rDist );
117  }
121  inline double getVAngle() const {
122  return ( this->vAngle );
123  }
127  inline double getHAngle() const {
128  return ( this->hAngle );
129  }
137  inline double getX() const {
138  return ( rDist * cos(this->hAngle) * cos(this->vAngle) );
139  }
147  inline double getY() const {
148  return ( rDist * sin(this->hAngle) );
149  }
156  inline double getZ() const {
157  return ( rDist * cos(this->hAngle) * sin(this->vAngle) );
158  }
159 
160  friend inline std::ostream &operator << (std::ostream &s, const vpScanPoint &p);
161 
167  friend inline bool operator==( const vpScanPoint &sp1,
168  const vpScanPoint &sp2 ) {
169  //return ( ( sp1.getRadialDist() == sp2.getRadialDist() )
170  // && ( sp1.getHAngle() == sp2.getHAngle() )
171  // && ( sp1.getVAngle() == sp2.getVAngle() ) );
172  double rd1 = sp1.getRadialDist();
173  double ha1 = sp1.getHAngle();
174  double va1 = sp1.getVAngle();
175  double rd2 = sp2.getRadialDist();
176  double ha2 = sp2.getHAngle();
177  double va2 = sp2.getVAngle();
178 
179  return ( ( std::fabs(rd1 - rd2) <= std::fabs(vpMath::maximum(rd1,rd2)) * std::numeric_limits<double>::epsilon() )
180  &&
181  ( std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1,ha2)) * std::numeric_limits<double>::epsilon() )
182  &&
183  ( std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1,va2)) * std::numeric_limits<double>::epsilon() ) );
184  }
185 
191  friend inline bool operator!=( const vpScanPoint &sp1,
192  const vpScanPoint &sp2 ) {
193  //return ( ( sp1.getRadialDist() != sp2.getRadialDist() )
194  // || ( sp1.getHAngle() != sp2.getHAngle() )
195  // || ( sp1.getVAngle() != sp2.getVAngle() ) );
196  double rd1 = sp1.getRadialDist();
197  double ha1 = sp1.getHAngle();
198  double va1 = sp1.getVAngle();
199  double rd2 = sp2.getRadialDist();
200  double ha2 = sp2.getHAngle();
201  double va2 = sp2.getVAngle();
202  return ( ( std::fabs(rd1 - rd2) > std::fabs(vpMath::maximum(rd1,rd2)) * std::numeric_limits<double>::epsilon() )
203  ||
204  ( std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1,ha2)) * std::numeric_limits<double>::epsilon() )
205  ||
206  ( std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1,va2)) * std::numeric_limits<double>::epsilon() ) );
207  }
208 
209  private:
210  double rDist;
211  double hAngle;
212  double vAngle;
213 };
214 
251 inline std::ostream &operator << (std::ostream &s, const vpScanPoint &p) {
252  std::ios_base::fmtflags original_flags = s.flags();
253 
254  s.precision(10);
255  s << p.getRadialDist() << " "
256  << p.getHAngle() << " "
257  << p.getVAngle() << " "
258  << p.getX() << " "
259  << p.getY() << " " << p.getZ();
260 
261  s.setf(original_flags); // restore s to standard state
262 
263  return s;
264 }
265 
266 #endif
double getZ() const
Definition: vpScanPoint.h:156
virtual ~vpScanPoint()
Definition: vpScanPoint.h:100
vpScanPoint(const vpScanPoint &scanpoint)
Definition: vpScanPoint.h:81
vpScanPoint(double r_dist, double h_angle, double v_angle)
Definition: vpScanPoint.h:92
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:137
Class that defines a single laser scanner point.
Definition: vpScanPoint.h:75
double getRadialDist() const
Definition: vpScanPoint.h:115
double getHAngle() const
Definition: vpScanPoint.h:127
friend bool operator==(const vpScanPoint &sp1, const vpScanPoint &sp2)
Definition: vpScanPoint.h:167
double getX() const
Definition: vpScanPoint.h:137
double getY() const
Definition: vpScanPoint.h:147
friend std::ostream & operator<<(std::ostream &s, const vpScanPoint &p)
Definition: vpScanPoint.h:251
void setPolar(double r_dist, double h_angle, double v_angle)
Definition: vpScanPoint.h:107
friend bool operator!=(const vpScanPoint &sp1, const vpScanPoint &sp2)
Definition: vpScanPoint.h:191
double getVAngle() const
Definition: vpScanPoint.h:121