ViSP  2.8.0
vpScanPoint.h
1 /****************************************************************************
2  *
3  * $Id: vpScanPoint.h 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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 <cmath> // std::fabs
48 #include <limits> // numeric_limits
49 #include <math.h>
50 
74 class /* VISP_EXPORT */ vpScanPoint // Note that here VISP_EXPORT should not be added since this class is complete inline
75 {
76  public:
78  inline vpScanPoint() {
79  this->rDist = 0;
80  this->hAngle = 0;
81  this->vAngle = 0;
82  }
84  inline vpScanPoint(const vpScanPoint &scanpoint) {
85  this->rDist = scanpoint.rDist;
86  this->hAngle = scanpoint.hAngle;
87  this->vAngle = scanpoint.vAngle;
88  }
95  inline vpScanPoint(double rDist, double hAngle, double vAngle) {
96  this->rDist = rDist;
97  this->hAngle = hAngle;
98  this->vAngle = vAngle;
99  }
101  inline virtual ~vpScanPoint() {};
108  inline void setPolar(double rDist, double hAngle, double vAngle) {
109  this->rDist = rDist;
110  this->hAngle = hAngle;
111  this->vAngle = vAngle;
112  }
116  inline double getRadialDist() const {
117  return ( this->rDist );
118  }
122  inline double getVAngle() const {
123  return ( this->vAngle );
124  }
128  inline double getHAngle() const {
129  return ( this->hAngle );
130  }
138  inline double getX() const {
139  return ( rDist * cos(this->hAngle) * cos(this->vAngle) );
140  }
148  inline double getY() const {
149  return ( rDist * sin(this->hAngle) );
150  }
157  inline double getZ() const {
158  return ( rDist * cos(this->hAngle) * sin(this->vAngle) );
159  }
160 
161  friend inline std::ostream &operator << (std::ostream &s, const vpScanPoint &p);
162 
168  friend inline bool operator==( const vpScanPoint &sp1,
169  const vpScanPoint &sp2 ) {
170  //return ( ( sp1.getRadialDist() == sp2.getRadialDist() )
171  // && ( sp1.getHAngle() == sp2.getHAngle() )
172  // && ( sp1.getVAngle() == sp2.getVAngle() ) );
173  double rd1 = sp1.getRadialDist();
174  double ha1 = sp1.getHAngle();
175  double va1 = sp1.getVAngle();
176  double rd2 = sp2.getRadialDist();
177  double ha2 = sp2.getHAngle();
178  double va2 = sp2.getVAngle();
179 
180  return ( ( std::fabs(rd1 - rd2) <= std::fabs(vpMath::maximum(rd1,rd2)) * std::numeric_limits<double>::epsilon() )
181  &&
182  ( std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1,ha2)) * std::numeric_limits<double>::epsilon() )
183  &&
184  ( std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1,va2)) * std::numeric_limits<double>::epsilon() ) );
185  }
186 
192  friend inline bool operator!=( const vpScanPoint &sp1,
193  const vpScanPoint &sp2 ) {
194  //return ( ( sp1.getRadialDist() != sp2.getRadialDist() )
195  // || ( sp1.getHAngle() != sp2.getHAngle() )
196  // || ( sp1.getVAngle() != sp2.getVAngle() ) );
197  double rd1 = sp1.getRadialDist();
198  double ha1 = sp1.getHAngle();
199  double va1 = sp1.getVAngle();
200  double rd2 = sp2.getRadialDist();
201  double ha2 = sp2.getHAngle();
202  double va2 = sp2.getVAngle();
203  return ( ( std::fabs(rd1 - rd2) > std::fabs(vpMath::maximum(rd1,rd2)) * std::numeric_limits<double>::epsilon() )
204  ||
205  ( std::fabs(ha1 - ha2) <= std::fabs(vpMath::maximum(ha1,ha2)) * std::numeric_limits<double>::epsilon() )
206  ||
207  ( std::fabs(va1 - va2) <= std::fabs(vpMath::maximum(va1,va2)) * std::numeric_limits<double>::epsilon() ) );
208  }
209 
210  private:
211  double rDist;
212  double hAngle;
213  double vAngle;
214 };
215 
252 inline std::ostream &operator << (std::ostream &s, const vpScanPoint &p) {
253  s.precision(10);
254  s << p.getRadialDist() << " "
255  << p.getHAngle() << " "
256  << p.getVAngle() << " "
257  << p.getX() << " "
258  << p.getY() << " " << p.getZ();
259  return s;
260  }
261 
262 #endif
double getZ() const
Definition: vpScanPoint.h:157
virtual ~vpScanPoint()
Definition: vpScanPoint.h:101
vpScanPoint(const vpScanPoint &scanpoint)
Definition: vpScanPoint.h:84
static Type maximum(const Type &a, const Type &b)
Definition: vpMath.h:137
Class that defines a single laser scanner point.
Definition: vpScanPoint.h:74
double getRadialDist() const
Definition: vpScanPoint.h:116
double getHAngle() const
Definition: vpScanPoint.h:128
friend bool operator==(const vpScanPoint &sp1, const vpScanPoint &sp2)
Definition: vpScanPoint.h:168
VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpImagePoint &ip)
Definition: vpImagePoint.h:529
double getX() const
Definition: vpScanPoint.h:138
double getY() const
Definition: vpScanPoint.h:148
vpScanPoint(double rDist, double hAngle, double vAngle)
Definition: vpScanPoint.h:95
void setPolar(double rDist, double hAngle, double vAngle)
Definition: vpScanPoint.h:108
friend std::ostream & operator<<(std::ostream &s, const vpScanPoint &p)
Definition: vpScanPoint.h:252
friend bool operator!=(const vpScanPoint &sp1, const vpScanPoint &sp2)
Definition: vpScanPoint.h:192
double getVAngle() const
Definition: vpScanPoint.h:122