Visual Servoing Platform  version 3.1.0
vpScanPoint.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Single laser scanner point.
33  *
34  * Authors:
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 #ifndef vpScanPoint_h
39 #define vpScanPoint_h
40 
41 #include <visp3/core/vpMath.h>
42 
43 #include <cmath> // std::fabs
44 #include <limits> // numeric_limits
45 #include <math.h>
46 #include <ostream>
47 #include <sstream>
48 
73 class /* VISP_EXPORT */ vpScanPoint // Note that here VISP_EXPORT should not
74  // be added since this class is complete
75  // 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  {
83  this->rDist = scanpoint.rDist;
84  this->hAngle = scanpoint.hAngle;
85  this->vAngle = scanpoint.vAngle;
86  }
93  inline vpScanPoint(double r_dist, double h_angle, double v_angle) : 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  {
109  this->rDist = r_dist;
110  this->hAngle = h_angle;
111  this->vAngle = v_angle;
112  }
116  inline double getRadialDist() const { return (this->rDist); }
120  inline double getVAngle() const { return (this->vAngle); }
124  inline double getHAngle() const { return (this->hAngle); }
132  inline double getX() const { return (rDist * cos(this->hAngle) * cos(this->vAngle)); }
140  inline double getY() const { return (rDist * sin(this->hAngle)); }
147  inline double getZ() const { return (rDist * cos(this->hAngle) * sin(this->vAngle)); }
148 
149  friend inline std::ostream &operator<<(std::ostream &s, const vpScanPoint &p);
150 
156  friend inline bool operator==(const vpScanPoint &sp1, const vpScanPoint &sp2)
157  {
158  // return ( ( sp1.getRadialDist() == sp2.getRadialDist() )
159  // && ( sp1.getHAngle() == sp2.getHAngle() )
160  // && ( sp1.getVAngle() == sp2.getVAngle() ) );
161  double rd1 = sp1.getRadialDist();
162  double ha1 = sp1.getHAngle();
163  double va1 = sp1.getVAngle();
164  double rd2 = sp2.getRadialDist();
165  double ha2 = sp2.getHAngle();
166  double va2 = sp2.getVAngle();
167 
168  return ((std::fabs(rd1 - rd2) <= std::fabs(vpMath::maximum(rd1, rd2)) * std::numeric_limits<double>::epsilon()) &&
169  (std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1, ha2)) * std::numeric_limits<double>::epsilon()) &&
170  (std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1, va2)) * std::numeric_limits<double>::epsilon()));
171  }
172 
178  friend inline bool operator!=(const vpScanPoint &sp1, const vpScanPoint &sp2)
179  {
180  // return ( ( sp1.getRadialDist() != sp2.getRadialDist() )
181  // || ( sp1.getHAngle() != sp2.getHAngle() )
182  // || ( sp1.getVAngle() != sp2.getVAngle() ) );
183  double rd1 = sp1.getRadialDist();
184  double ha1 = sp1.getHAngle();
185  double va1 = sp1.getVAngle();
186  double rd2 = sp2.getRadialDist();
187  double ha2 = sp2.getHAngle();
188  double va2 = sp2.getVAngle();
189  return ((std::fabs(rd1 - rd2) > std::fabs(vpMath::maximum(rd1, rd2)) * std::numeric_limits<double>::epsilon()) ||
190  (std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1, ha2)) * std::numeric_limits<double>::epsilon()) ||
191  (std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1, va2)) * std::numeric_limits<double>::epsilon()));
192  }
193 
194 private:
195  double rDist;
196  double hAngle;
197  double vAngle;
198 };
199 
237 inline std::ostream &operator<<(std::ostream &s, const vpScanPoint &p)
238 {
239  std::ios_base::fmtflags original_flags = s.flags();
240 
241  s.precision(10);
242  s << p.getRadialDist() << " " << p.getHAngle() << " " << p.getVAngle() << " " << p.getX() << " " << p.getY() << " "
243  << p.getZ();
244 
245  s.setf(original_flags); // restore s to standard state
246 
247  return s;
248 }
249 
250 #endif
double getRadialDist() const
Definition: vpScanPoint.h:116
double getHAngle() const
Definition: vpScanPoint.h:124
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:93
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:137
double getZ() const
Definition: vpScanPoint.h:147
Class that defines a single laser scanner point.
Definition: vpScanPoint.h:73
friend std::ostream & operator<<(std::ostream &s, const vpScanPoint &p)
Definition: vpScanPoint.h:237
friend bool operator==(const vpScanPoint &sp1, const vpScanPoint &sp2)
Definition: vpScanPoint.h:156
double getVAngle() const
Definition: vpScanPoint.h:120
double getX() const
Definition: vpScanPoint.h:132
void setPolar(double r_dist, double h_angle, double v_angle)
Definition: vpScanPoint.h:107
double getY() const
Definition: vpScanPoint.h:140
friend bool operator!=(const vpScanPoint &sp1, const vpScanPoint &sp2)
Definition: vpScanPoint.h:178