MRPT  1.9.9
CAtan2LookUpTable.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, 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 
10 #include "math-precomp.h" // Precompiled headers
11 
13 #include <cmath>
14 #include <vector>
15 
16 using namespace mrpt::math;
17 
19 {
20  this->resize(-1.0, 1.0, -1.0, 1.0, 0.5);
21 }
23  double xmin, double xmax, double ymin, double ymax,
24  double resolution) noexcept
25 {
26  this->resize(xmin, xmax, ymin, ymax, resolution);
27 }
28 
30  double xmin, double xmax, double ymin, double ymax,
31  double resolution) noexcept
32 {
33  const double def = .0;
34  if (m_grid.getResolution() == resolution)
35  m_grid.resize(xmin, xmax, ymin, ymax, def, .0);
36  else
37  m_grid.setSize(xmin, xmax, ymin, ymax, resolution, &def);
38 
39  const size_t nx = m_grid.getSizeX(), ny = m_grid.getSizeY();
40 
41  std::vector<double> idx2x(nx), idx2y(ny);
42 
43  for (size_t ix = 0; ix < nx; ix++) idx2x[ix] = m_grid.idx2x(ix);
44  for (size_t iy = 0; iy < ny; iy++) idx2y[iy] = m_grid.idx2y(iy);
45 
46  for (size_t ix = 0; ix < nx; ix++)
47  {
48  const double x = idx2x[ix];
49  for (size_t iy = 0; iy < ny; iy++)
50  {
51  const double y = idx2y[iy];
52  double* cp = m_grid.cellByIndex(ix, iy);
53  if (cp) *cp = ::atan2(y, x);
54  }
55  }
56 }
57 
58 bool CAtan2LookUpTable::atan2(double y, double x, double& out_atan2) const
59  noexcept
60 {
61  const double* cp = m_grid.cellByPos(x, y);
62  if (!cp) return false;
63  out_atan2 = *cp;
64  return true;
65 }
66 
68  const std::map<double, double>& lst_resolutions2extensions) noexcept
69 {
70  resize(lst_resolutions2extensions);
71 }
73  const std::map<double, double>& lst_resolutions2extensions) noexcept
74 {
75  m_grids.clear();
76 
77  for (const auto& it : lst_resolutions2extensions)
78  {
79  const double res = it.first;
80  const double exten = it.second;
81 
82  mrpt::containers::CDynamicGrid<double>& dg = m_grids[exten] =
84  -exten, exten, -exten, exten, res);
85 
86  const size_t nx = dg.getSizeX(), ny = dg.getSizeY();
87  std::vector<double> idx2x(nx), idx2y(ny);
88 
89  for (size_t ix = 0; ix < nx; ix++) idx2x[ix] = dg.idx2x(ix);
90  for (size_t iy = 0; iy < ny; iy++) idx2y[iy] = dg.idx2y(iy);
91 
92  for (size_t ix = 0; ix < nx; ix++)
93  {
94  const double x = idx2x[ix];
95  for (size_t iy = 0; iy < ny; iy++)
96  {
97  const double y = idx2y[iy];
98  double* cp = dg.cellByIndex(ix, iy);
99  if (cp) *cp = ::atan2(y, x);
100  }
101  }
102  }
103 }
104 
106  double y, double x, double& out_atan2) const noexcept
107 {
108  for (const auto& it : m_grids)
109  {
110  const double exten = it.first;
111  const mrpt::containers::CDynamicGrid<double>& dg = it.second;
112 
113  if (std::abs(x) > exten || std::abs(y) > exten) continue;
114 
115  const double* cp = dg.cellByPos(x, y);
116  if (!cp) continue;
117  out_atan2 = *cp;
118  return true;
119  }
120  return false;
121 }
double idx2x(int cx) const
Transform a cell index into a coordinate value of the cell central point.
Definition: CDynamicGrid.h:279
void resize(const std::map< double, double > &lst_resolutions2extensions) noexcept
See CAtan2LookUpTableMultiRes for a discussion of the parameters.
double idx2y(int cy) const
Definition: CDynamicGrid.h:283
This base provides a set of functions for maths stuff.
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
bool atan2(double y, double x, double &out_atan2) const noexcept
Returns the precomputed value for atan2(y,x).
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
GLfloat GLfloat GLfloat GLfloat nx
Definition: glext.h:6389
GLenum GLint GLint y
Definition: glext.h:3542
GLuint res
Definition: glext.h:7385
GLenum GLint x
Definition: glext.h:3542
GLfloat ny
Definition: glext.h:6385



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019