Main MRPT website > C++ reference for MRPT 1.5.9
CSinCosLookUpTableFor2DScans.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://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 using namespace mrpt::utils;
18 
19 /** Return two vectors with the cos and the sin of the angles for each of the
20  * rays in a scan, computing them only the first time and returning a cached copy the rest.
21  */
22 const CSinCosLookUpTableFor2DScans::TSinCosValues & CSinCosLookUpTableFor2DScans::getSinCosForScan(const CObservation2DRangeScan &scan) const
23 {
24  T2DScanProperties scan_prop;
25  scan.getScanProperties(scan_prop);
26  return getSinCosForScan(scan_prop);
27 }
28 
29 /** Return two vectors with the cos and the sin of the angles for each of the
30  * rays in a scan, computing them only the first time and returning a cached copy the rest.
31  */
32 const CSinCosLookUpTableFor2DScans::TSinCosValues & CSinCosLookUpTableFor2DScans::getSinCosForScan(const T2DScanProperties &scan_prop) const
33 {
34  mrpt::synch::CCriticalSectionLocker lck(&m_cache_cs);
35 
37  if (it!=m_cache.end())
38  { // Found in the cache:
39  return it->second;
40  }
41  else
42  {
43  // If there're too many LUTs, something is wrong, so just free the memory:
44  // (If you someday find someone with TWENTY *different* laser scanner models,
45  // please, accept my apologies... but send me a photo of them all!! ;-)
46  if ( m_cache.size()>20 ) m_cache.clear();
47 
48  // Compute and insert in the cache:
49  TSinCosValues &new_entry = m_cache[scan_prop];
50 
51  // Make sure the allocated memory at least have room for 4 extra double's at the end,
52  // for the case we use these buffers for SSE2 optimized code. If the final values are uninitialized it doesn't matter.
53  new_entry.ccos.resize(scan_prop.nRays+4);
54  new_entry.csin.resize(scan_prop.nRays+4);
55 
56  ASSERT_(scan_prop.nRays>=2)
57  if (scan_prop.nRays>0)
58  {
59  double Ang = (scan_prop.rightToLeft ? -0.5:+0.5) *scan_prop.aperture;
60  const double dA = (scan_prop.rightToLeft ? 1.0:-1.0) * (scan_prop.aperture / (scan_prop.nRays-1));
61 
62  for (size_t i=0;i<scan_prop.nRays;i++)
63  {
64  new_entry.ccos[i] = cos( Ang );
65  new_entry.csin[i] = sin( Ang );
66  Ang+=dA;
67  }
68  }
69  // return them:
70  return new_entry;
71  }
72 }
73 
A class acquiring a CCriticalSection at its constructor, and releasing it at destructor.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
void getScanProperties(T2DScanProperties &p) const
Fill out a T2DScanProperties structure with the parameters of this scan.
STL namespace.
const Scalar * const_iterator
Definition: eigen_plugins.h:24
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...
#define ASSERT_(f)
bool rightToLeft
Angles storage order: true=counterclockwise; false=clockwise.



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020