MRPT  1.9.9
CSinCosLookUpTableFor2DScans.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 "obs-precomp.h" // Precompiled headers
11 
14 
15 using namespace std;
16 using namespace mrpt::obs;
17 
18 /** Return two vectors with the cos and the sin of the angles for each of the
19  * rays in a scan, computing them only the first time and returning a cached
20  * copy the rest.
21  */
23  CSinCosLookUpTableFor2DScans::getSinCosForScan(
24  const CObservation2DRangeScan& scan) const
25 {
26  T2DScanProperties scan_prop;
27  scan.getScanProperties(scan_prop);
28  return getSinCosForScan(scan_prop);
29 }
30 
31 /** Return two vectors with the cos and the sin of the angles for each of the
32  * rays in a scan, computing them only the first time and returning a cached
33  * copy the rest.
34  */
36  CSinCosLookUpTableFor2DScans::getSinCosForScan(
37  const T2DScanProperties& scan_prop) const
38 {
39  auto it = m_cache.find(scan_prop);
40  if (it != m_cache.end())
41  { // Found in the cache:
42  return it->second;
43  }
44  else
45  {
46  // If there're too many LUTs, something is wrong, so just free the
47  // memory:
48  // (If you someday find someone with TWENTY *different* laser scanner
49  // models,
50  // please, accept my apologies... but send me a photo of them all!!
51  // ;-)
52  if (m_cache.size() > 20) m_cache.clear();
53 
54  // Compute and insert in the cache:
55  TSinCosValues& new_entry = m_cache[scan_prop];
56 
57  // Make sure the allocated memory at least have room for 4 extra
58  // double's at the end,
59  // for the case we use these buffers for SSE2 optimized code. If the
60  // final values are uninitialized it doesn't matter.
61  new_entry.ccos.resize(scan_prop.nRays + 4);
62  new_entry.csin.resize(scan_prop.nRays + 4);
63 
64  ASSERT_(scan_prop.nRays >= 2);
65  if (scan_prop.nRays > 0)
66  {
67  double Ang =
68  (scan_prop.rightToLeft ? -0.5 : +0.5) * scan_prop.aperture;
69  const double dA = (scan_prop.rightToLeft ? 1.0 : -1.0) *
70  (scan_prop.aperture / (scan_prop.nRays - 1));
71 
72  for (size_t i = 0; i < scan_prop.nRays; i++)
73  {
74  new_entry.ccos[i] = cos(Ang);
75  new_entry.csin[i] = sin(Ang);
76  Ang += dA;
77  }
78  }
79  // return them:
80  return new_entry;
81  }
82 }
void getScanProperties(T2DScanProperties &p) const
Fill out a T2DScanProperties structure with the parameters of this scan.
STL namespace.
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
Auxiliary struct that holds all the relevant geometry information about a 2D scan.
This namespace contains representation of robot actions and observations.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
A pair of vectors with the cos and sin values.
void resize(std::size_t N, bool zeroNewElements=false)
bool rightToLeft
Angles storage order: true=counterclockwise; false=clockwise.



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