Visual Servoing Platform  version 3.0.0
vpScanPoint.h
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  * Single laser scanner point.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 #ifndef vpScanPoint_h
38 #define vpScanPoint_h
39 
40 #include <visp3/core/vpMath.h>
41 
42 #include <ostream>
43 #include <sstream>
44 #include <cmath> // std::fabs
45 #include <limits> // numeric_limits
46 #include <math.h>
47 
72 class /* VISP_EXPORT */ vpScanPoint // Note that here VISP_EXPORT should not be added since this class is complete inline
73 {
74  public:
76  inline vpScanPoint() : rDist(0), hAngle(0), vAngle(0) {}
78  inline vpScanPoint(const vpScanPoint &scanpoint) : rDist(0), hAngle(0), vAngle(0) {
79  this->rDist = scanpoint.rDist;
80  this->hAngle = scanpoint.hAngle;
81  this->vAngle = scanpoint.vAngle;
82  }
89  inline vpScanPoint(double r_dist, double h_angle, double v_angle)
90  : rDist(r_dist), hAngle(h_angle), vAngle(v_angle)
91  {
92  this->rDist = r_dist;
93  this->hAngle = h_angle;
94  this->vAngle = v_angle;
95  }
97  inline virtual ~vpScanPoint() {};
104  inline void setPolar(double r_dist, double h_angle, double v_angle) {
105  this->rDist = r_dist;
106  this->hAngle = h_angle;
107  this->vAngle = v_angle;
108  }
112  inline double getRadialDist() const {
113  return ( this->rDist );
114  }
118  inline double getVAngle() const {
119  return ( this->vAngle );
120  }
124  inline double getHAngle() const {
125  return ( this->hAngle );
126  }
134  inline double getX() const {
135  return ( rDist * cos(this->hAngle) * cos(this->vAngle) );
136  }
144  inline double getY() const {
145  return ( rDist * sin(this->hAngle) );
146  }
153  inline double getZ() const {
154  return ( rDist * cos(this->hAngle) * sin(this->vAngle) );
155  }
156 
157  friend inline std::ostream &operator << (std::ostream &s, const vpScanPoint &p);
158 
164  friend inline bool operator==( const vpScanPoint &sp1,
165  const vpScanPoint &sp2 ) {
166  //return ( ( sp1.getRadialDist() == sp2.getRadialDist() )
167  // && ( sp1.getHAngle() == sp2.getHAngle() )
168  // && ( sp1.getVAngle() == sp2.getVAngle() ) );
169  double rd1 = sp1.getRadialDist();
170  double ha1 = sp1.getHAngle();
171  double va1 = sp1.getVAngle();
172  double rd2 = sp2.getRadialDist();
173  double ha2 = sp2.getHAngle();
174  double va2 = sp2.getVAngle();
175 
176  return ( ( std::fabs(rd1 - rd2) <= std::fabs(vpMath::maximum(rd1,rd2)) * std::numeric_limits<double>::epsilon() )
177  &&
178  ( std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1,ha2)) * std::numeric_limits<double>::epsilon() )
179  &&
180  ( std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1,va2)) * std::numeric_limits<double>::epsilon() ) );
181  }
182 
188  friend inline bool operator!=( const vpScanPoint &sp1,
189  const vpScanPoint &sp2 ) {
190  //return ( ( sp1.getRadialDist() != sp2.getRadialDist() )
191  // || ( sp1.getHAngle() != sp2.getHAngle() )
192  // || ( sp1.getVAngle() != sp2.getVAngle() ) );
193  double rd1 = sp1.getRadialDist();
194  double ha1 = sp1.getHAngle();
195  double va1 = sp1.getVAngle();
196  double rd2 = sp2.getRadialDist();
197  double ha2 = sp2.getHAngle();
198  double va2 = sp2.getVAngle();
199  return ( ( std::fabs(rd1 - rd2) > std::fabs(vpMath::maximum(rd1,rd2)) * std::numeric_limits<double>::epsilon() )
200  ||
201  ( std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1,ha2)) * std::numeric_limits<double>::epsilon() )
202  ||
203  ( std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1,va2)) * std::numeric_limits<double>::epsilon() ) );
204  }
205 
206  private:
207  double rDist;
208  double hAngle;
209  double vAngle;
210 };
211 
248 inline std::ostream &operator << (std::ostream &s, const vpScanPoint &p) {
249  std::ios_base::fmtflags original_flags = s.flags();
250 
251  s.precision(10);
252  s << p.getRadialDist() << " "
253  << p.getHAngle() << " "
254  << p.getVAngle() << " "
255  << p.getX() << " "
256  << p.getY() << " " << p.getZ();
257 
258  s.setf(original_flags); // restore s to standard state
259 
260  return s;
261 }
262 
263 #endif
double getZ() const
Definition: vpScanPoint.h:153
virtual ~vpScanPoint()
Definition: vpScanPoint.h:97
vpScanPoint(const vpScanPoint &scanpoint)
Definition: vpScanPoint.h:78
vpScanPoint(double r_dist, double h_angle, double v_angle)
Definition: vpScanPoint.h:89
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:141
Class that defines a single laser scanner point.
Definition: vpScanPoint.h:72
double getRadialDist() const
Definition: vpScanPoint.h:112
double getHAngle() const
Definition: vpScanPoint.h:124
friend bool operator==(const vpScanPoint &sp1, const vpScanPoint &sp2)
Definition: vpScanPoint.h:164
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:267
double getX() const
Definition: vpScanPoint.h:134
double getY() const
Definition: vpScanPoint.h:144
friend std::ostream & operator<<(std::ostream &s, const vpScanPoint &p)
Definition: vpScanPoint.h:248
void setPolar(double r_dist, double h_angle, double v_angle)
Definition: vpScanPoint.h:104
friend bool operator!=(const vpScanPoint &sp1, const vpScanPoint &sp2)
Definition: vpScanPoint.h:188
double getVAngle() const
Definition: vpScanPoint.h:118