GridMapCacheArray.h
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2011, Stefan Kohlbrecher, TU Darmstadt
3 // All rights reserved.
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Simulation, Systems Optimization and Robotics
13 // group, TU Darmstadt nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
29 #ifndef __GridMapCacheArray_h_
30 #define __GridMapCacheArray_h_
31 
32 #include <Eigen/Core>
33 
35 {
36 public:
37  float val;
38  int index;
39 };
40 
45 {
46 public:
47 
52  : cacheArray(0)
53  , arrayDimensions(-1,-1)
54  {
55  currCacheIndex = 0;
56  }
57 
62  {
63  deleteCacheArray();
64  }
65 
69  void resetCache()
70  {
71  currCacheIndex++;
72  }
73 
80  bool containsCachedData(int index, float& val)
81  {
82  const CachedMapElement& elem (cacheArray[index]);
83 
84  if (elem.index == currCacheIndex) {
85  val = elem.val;
86  return true;
87  } else {
88  return false;
89  }
90  }
91 
97  void cacheData(int index, float val)
98  {
99  CachedMapElement& elem (cacheArray[index]);
100  elem.index = currCacheIndex;
101  elem.val = val;
102  }
103 
108  void setMapSize(const Eigen::Vector2i& newDimensions)
109  {
110  setArraySize(newDimensions);
111  }
112 
113 protected:
114 
119  void createCacheArray(const Eigen::Vector2i& newDimensions)
120  {
121  arrayDimensions = newDimensions;
122 
123  int sizeX = arrayDimensions[0];
124  int sizeY = arrayDimensions[1];
125 
126  int size = sizeX * sizeY;
127 
128  cacheArray = new CachedMapElement [size];
129 
130  for (int x = 0; x < size; ++x) {
131  cacheArray[x].index = -1;
132  }
133  }
134 
139  {
140  delete[] cacheArray;
141  }
142 
146  void setArraySize(const Eigen::Vector2i& newDimensions)
147  {
148  if (this->arrayDimensions != newDimensions) {
149  if (cacheArray != 0) {
150  deleteCacheArray();
151  cacheArray = 0;
152  }
153  createCacheArray(newDimensions);
154  }
155  }
156 
157 protected:
158 
161 
162  Eigen::Vector2i arrayDimensions;
163 
164 };
165 
166 
167 #endif
bool containsCachedData(int index, float &val)
Eigen::Vector2i arrayDimensions
The size of the array.
int currCacheIndex
The cache iteration index value.
TFSIMD_FORCE_INLINE const tfScalar & x() const
void setArraySize(const Eigen::Vector2i &newDimensions)
void cacheData(int index, float val)
void setMapSize(const Eigen::Vector2i &newDimensions)
void createCacheArray(const Eigen::Vector2i &newDimensions)
CachedMapElement * cacheArray
Array used for caching data.


hector_mapping
Author(s): Stefan Kohlbrecher
autogenerated on Sun Nov 3 2019 03:18:33