Visual Servoing Platform  version 3.6.1 under development (2023-12-07)
vpScanPoint.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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 *****************************************************************************/
35 #ifndef vpScanPoint_h
36 #define vpScanPoint_h
37 
38 #include <visp3/core/vpMath.h>
39 
40 #include <cmath> // std::fabs
41 #include <limits> // numeric_limits
42 #include <math.h>
43 #include <ostream>
44 #include <sstream>
45 
70 class /* VISP_EXPORT */ vpScanPoint // Note that here VISP_EXPORT should not
71  // be added since this class is complete
72  // 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  {
80  this->rDist = scanpoint.rDist;
81  this->hAngle = scanpoint.hAngle;
82  this->vAngle = scanpoint.vAngle;
83  }
90  inline vpScanPoint(double r_dist, double h_angle, double v_angle) : 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  {
106  this->rDist = r_dist;
107  this->hAngle = h_angle;
108  this->vAngle = v_angle;
109  }
113  inline double getRadialDist() const { return (this->rDist); }
117  inline double getVAngle() const { return (this->vAngle); }
121  inline double getHAngle() const { return (this->hAngle); }
129  inline double getX() const { return (rDist * cos(this->hAngle) * cos(this->vAngle)); }
137  inline double getY() const { return (rDist * sin(this->hAngle)); }
144  inline double getZ() const { return (rDist * cos(this->hAngle) * sin(this->vAngle)); }
145 
146  vpScanPoint &operator=(const vpScanPoint &) = default;
147 
148  friend inline std::ostream &operator<<(std::ostream &s, const vpScanPoint &p);
149 
155  friend inline bool operator==(const vpScanPoint &sp1, const vpScanPoint &sp2)
156  {
157  double rd1 = sp1.getRadialDist();
158  double ha1 = sp1.getHAngle();
159  double va1 = sp1.getVAngle();
160  double rd2 = sp2.getRadialDist();
161  double ha2 = sp2.getHAngle();
162  double va2 = sp2.getVAngle();
163 
164  return ((std::fabs(rd1 - rd2) <= std::fabs(vpMath::maximum(rd1, rd2)) * std::numeric_limits<double>::epsilon()) &&
165  (std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1, ha2)) * std::numeric_limits<double>::epsilon()) &&
166  (std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1, va2)) * std::numeric_limits<double>::epsilon()));
167  }
168 
174  friend inline bool operator!=(const vpScanPoint &sp1, const vpScanPoint &sp2)
175  {
176  // return ( ( sp1.getRadialDist() != sp2.getRadialDist() )
177  // || ( sp1.getHAngle() != sp2.getHAngle() )
178  // || ( sp1.getVAngle() != sp2.getVAngle() ) );
179  double rd1 = sp1.getRadialDist();
180  double ha1 = sp1.getHAngle();
181  double va1 = sp1.getVAngle();
182  double rd2 = sp2.getRadialDist();
183  double ha2 = sp2.getHAngle();
184  double va2 = sp2.getVAngle();
185  return ((std::fabs(rd1 - rd2) > std::fabs(vpMath::maximum(rd1, rd2)) * std::numeric_limits<double>::epsilon()) ||
186  (std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1, ha2)) * std::numeric_limits<double>::epsilon()) ||
187  (std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1, va2)) * std::numeric_limits<double>::epsilon()));
188  }
189 
190 private:
191  double rDist;
192  double hAngle;
193  double vAngle;
194 };
195 
233 inline std::ostream &operator<<(std::ostream &s, const vpScanPoint &p)
234 {
235  std::ios_base::fmtflags original_flags = s.flags();
236 
237  s.precision(10);
238  s << p.getRadialDist() << " " << p.getHAngle() << " " << p.getVAngle() << " " << p.getX() << " " << p.getY() << " "
239  << p.getZ();
240 
241  s.setf(original_flags); // restore s to standard state
242 
243  return s;
244 }
245 
246 #endif
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:504
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:252
Class that defines a single laser scanner point.
Definition: vpScanPoint.h:73
double getX() const
Definition: vpScanPoint.h:129
virtual ~vpScanPoint()
Definition: vpScanPoint.h:97
friend bool operator!=(const vpScanPoint &sp1, const vpScanPoint &sp2)
Definition: vpScanPoint.h:174
friend std::ostream & operator<<(std::ostream &s, const vpScanPoint &p)
Definition: vpScanPoint.h:233
vpScanPoint & operator=(const vpScanPoint &)=default
vpScanPoint(double r_dist, double h_angle, double v_angle)
Definition: vpScanPoint.h:90
double getVAngle() const
Definition: vpScanPoint.h:117
double getZ() const
Definition: vpScanPoint.h:144
void setPolar(double r_dist, double h_angle, double v_angle)
Definition: vpScanPoint.h:104
double getY() const
Definition: vpScanPoint.h:137
vpScanPoint(const vpScanPoint &scanpoint)
Definition: vpScanPoint.h:78
double getRadialDist() const
Definition: vpScanPoint.h:113
double getHAngle() const
Definition: vpScanPoint.h:121
friend bool operator==(const vpScanPoint &sp1, const vpScanPoint &sp2)
Definition: vpScanPoint.h:155