Visual Servoing Platform  version 3.6.1 under development (2024-05-21)
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 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
147  vpScanPoint &operator=(const vpScanPoint &) = default;
148 #endif
149 
150  friend inline std::ostream &operator<<(std::ostream &s, const vpScanPoint &p);
151 
157  friend inline bool operator==(const vpScanPoint &sp1, const vpScanPoint &sp2)
158  {
159  double rd1 = sp1.getRadialDist();
160  double ha1 = sp1.getHAngle();
161  double va1 = sp1.getVAngle();
162  double rd2 = sp2.getRadialDist();
163  double ha2 = sp2.getHAngle();
164  double va2 = sp2.getVAngle();
165 
166  return ((std::fabs(rd1 - rd2) <= std::fabs(vpMath::maximum(rd1, rd2)) * std::numeric_limits<double>::epsilon()) &&
167  (std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1, ha2)) * std::numeric_limits<double>::epsilon()) &&
168  (std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1, va2)) * std::numeric_limits<double>::epsilon()));
169  }
170 
176  friend inline bool operator!=(const vpScanPoint &sp1, const vpScanPoint &sp2)
177  {
178  // return ( ( sp1.getRadialDist() != sp2.getRadialDist() )
179  // || ( sp1.getHAngle() != sp2.getHAngle() )
180  // || ( sp1.getVAngle() != sp2.getVAngle() ) );
181  double rd1 = sp1.getRadialDist();
182  double ha1 = sp1.getHAngle();
183  double va1 = sp1.getVAngle();
184  double rd2 = sp2.getRadialDist();
185  double ha2 = sp2.getHAngle();
186  double va2 = sp2.getVAngle();
187  return ((std::fabs(rd1 - rd2) > std::fabs(vpMath::maximum(rd1, rd2)) * std::numeric_limits<double>::epsilon()) ||
188  (std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1, ha2)) * std::numeric_limits<double>::epsilon()) ||
189  (std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1, va2)) * std::numeric_limits<double>::epsilon()));
190  }
191 
192 private:
193  double rDist;
194  double hAngle;
195  double vAngle;
196 };
197 
235 inline std::ostream &operator<<(std::ostream &s, const vpScanPoint &p)
236 {
237  std::ios_base::fmtflags original_flags = s.flags();
238 
239  s.precision(10);
240  s << p.getRadialDist() << " " << p.getHAngle() << " " << p.getVAngle() << " " << p.getX() << " " << p.getY() << " "
241  << p.getZ();
242 
243  s.setf(original_flags); // restore s to standard state
244 
245  return s;
246 }
247 
248 #endif
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:603
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:176
friend std::ostream & operator<<(std::ostream &s, const vpScanPoint &p)
Definition: vpScanPoint.h:235
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:157