MRPT  2.0.1
CAtan2LookUpTable.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
12 #include <map>
13 
14 namespace mrpt::math
15 {
16 /** A look-up-table (LUT) of atan values for any (x,y) value in a
17  * square/rectangular grid of predefined resolution
18  *
19  * \sa mrpt::math::CAtan2LookUpTableMultiRes,
20  * mrpt::obs::CSinCosLookUpTableFor2DScans
21  * \ingroup mrpt_math_grp
22  */
24 {
25  public:
26  CAtan2LookUpTable() noexcept;
28  double xmin, double xmax, double ymin, double ymax,
29  double resolution) noexcept;
30  void resize(
31  double xmin, double xmax, double ymin, double ymax,
32  double resolution) noexcept;
33 
34  /** Returns the precomputed value for atan2(y,x). \return false if out of
35  * grid bounds. */
36  bool atan2(double y, double x, double& out_atan2) const noexcept
37  {
38  const double* cp = m_grid.cellByPos(x, y);
39  if (!cp) return false;
40  out_atan2 = *cp;
41  return true;
42  }
43 
44  /** Returns the precomputed value for atan2() of the corresponding cell
45  * with indices (ix,iy). \return false if out of grid bounds. */
46  bool atan2ByIndex(unsigned int iy, unsigned int ix, double& out_atan2) const
47  noexcept
48  {
49  const double* cp = m_grid.cellByIndex(ix, iy);
50  if (!cp) return false;
51  out_atan2 = *cp;
52  return true;
53  }
54 
55  double getXMin() const { return m_grid.getXMin(); }
56  double getXMax() const { return m_grid.getXMax(); }
57  double getYMin() const { return m_grid.getYMin(); }
58  double getYMax() const { return m_grid.getYMax(); }
59  double getResolution() const { return m_grid.getResolution(); }
60  size_t getSizeX() const { return m_grid.getSizeX(); }
61  size_t getSizeY() const { return m_grid.getSizeY(); }
62 
63  private:
65 };
66 
67 /** Like CAtan2LookUpTable but with a multiresolution grid for increasingly
68  * better accuracy in points nearer to the origin.
69  * Example of usage:
70  * \code
71  * mrpt::math::CAtan2LookUpTableMultiRes atan2lut;
72  * std::map<double,double> res2extension;
73  * res2extension[0.001] = 0.5; // 0.1 cm resolution up to 0.5 m
74  * res2extension[0.01] = 1.0; // 1 cm resolution up to 1 m
75  * res2extension[0.02] = 3.0; // 2 cm resolution up to 3 m
76  * res2extension[0.05] = 7.5; // 5 cm resolution up to 7.5 m
77  * res2extension[0.10] = 12.0; // 10 cm resolution up to 12 m
78  * atan2lut.resize(res2extension);
79  * \endcode
80  * \ingroup mrpt_math_grp
81  */
83 {
84  public:
85  CAtan2LookUpTableMultiRes() = default;
86  /** See CAtan2LookUpTableMultiRes for a discussion of the parameters */
88  const std::map<double, double>& lst_resolutions2extensions) noexcept;
89  /** See CAtan2LookUpTableMultiRes for a discussion of the parameters */
90  void resize(
91  const std::map<double, double>& lst_resolutions2extensions) noexcept;
92 
93  /** Returns the precomputed value for atan2(y,x). \return false if out of
94  * grid bounds. */
95  bool atan2(double y, double x, double& out_atan2) const noexcept;
96 
97  private:
98  /** Maps from maximum (X,Y) coordinates to LUT for [-L,L]x[-L,L] square
99  * area. */
100  std::map<double, mrpt::containers::CDynamicGrid<double>> m_grids;
101 };
102 
103 } // namespace mrpt::math
double getYMax() const
Returns the "y" coordinate of bottom side of grid map.
Definition: CDynamicGrid.h:252
mrpt::containers::CDynamicGrid< double > m_grid
double getResolution() const
Returns the resolution of the grid map.
Definition: CDynamicGrid.h:254
double getYMin() const
Returns the "y" coordinate of top side of grid map.
Definition: CDynamicGrid.h:250
void resize(const std::map< double, double > &lst_resolutions2extensions) noexcept
See CAtan2LookUpTableMultiRes for a discussion of the parameters.
A look-up-table (LUT) of atan values for any (x,y) value in a square/rectangular grid of predefined r...
bool atan2(double y, double x, double &out_atan2) const noexcept
Returns the precomputed value for atan2(y,x).
This base provides a set of functions for maths stuff.
double getXMin() const
Returns the "x" coordinate of left side of grid map.
Definition: CDynamicGrid.h:246
std::map< double, mrpt::containers::CDynamicGrid< double > > m_grids
Maps from maximum (X,Y) coordinates to LUT for [-L,L]x[-L,L] square area.
T * cellByPos(double x, double y)
Returns a pointer to the contents of a cell given by its coordinates, or nullptr if it is out of the ...
Definition: CDynamicGrid.h:201
Like CAtan2LookUpTable but with a multiresolution grid for increasingly better accuracy in points nea...
bool atan2ByIndex(unsigned int iy, unsigned int ix, double &out_atan2) const noexcept
Returns the precomputed value for atan2() of the corresponding cell with indices (ix,iy).
T * cellByIndex(unsigned int cx, unsigned int cy)
Returns a pointer to the contents of a cell given by its cell indexes, or nullptr if it is out of the...
Definition: CDynamicGrid.h:222
size_t getSizeX() const
Returns the horizontal size of grid map in cells count.
Definition: CDynamicGrid.h:242
bool atan2(double y, double x, double &out_atan2) const noexcept
Returns the precomputed value for atan2(y,x).
void resize(double xmin, double xmax, double ymin, double ymax, double resolution) noexcept
size_t getSizeY() const
Returns the vertical size of grid map in cells count.
Definition: CDynamicGrid.h:244
double getXMax() const
Returns the "x" coordinate of right side of grid map.
Definition: CDynamicGrid.h:248



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020