MIRA
DistanceLUT.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
49 #ifndef _MIRA_DISTANCELUT_H_
50 #define _MIRA_DISTANCELUT_H_
51 
52 #ifndef Q_MOC_RUN
53 #include <boost/thread/mutex.hpp>
54 #endif
55 
56 #include <utils/Singleton.h>
57 #include <geometry/Point.h>
58 #include <geometry/Rect.h>
59 
60 namespace mira {
61 
63 
64 
122 class MIRA_BASE_EXPORT DistanceLUT : public LazySingleton<DistanceLUT>
123 {
124 public:
129  DistanceLUT();
130 
132  ~DistanceLUT();
133 
134 public:
138  struct CellDist {
139  float minDist, maxDist;
140  };
141 
142  typedef const CellDist* iterator;
143 
144 #if BOOST_VERSION < 105300
145  // If the shared_ptr type is not an array it calls delete instead of delete[] => memory leak
146  typedef boost::shared_ptr<CellDist> CellDistArrayPtr;
147 #else
148  typedef boost::shared_ptr<CellDist[]> CellDistArrayPtr;
149 #endif
150 
158  class Region
159  {
160  protected:
161  friend class DistanceLUT;
162 
169  Region(CellDistArrayPtr array, CellDist* data, int stride, const Rect2i& region) :
170  mArrayPtr(array), mData(data), mStride(stride), mRegion(region) {}
171 
172  public:
173 
175  const Rect2i& getRect() const { return mRegion; }
176 
178  int getXmin() const { return mRegion.minCorner.x(); }
179 
181  int getXmax() const { return mRegion.maxCorner.x(); }
182 
184  int getYmin() const { return mRegion.minCorner.y(); }
185 
187  int getYmax() const { return mRegion.maxCorner.y(); }
188 
190  int getWidth() const { return mRegion.width(); }
191 
193  int getHeight() const { return mRegion.height(); }
194 
195  public:
196 
202  iterator getIterator(int x, int y) const {
203  return mData + y*mStride + x;
204  }
205 
210  iterator begin(int y) const {
211  return mData + y*mStride + getXmin();
212  }
213 
218  iterator end(int y) const {
219  return mData + y*mStride + getXmax()+1;
220  }
221 
222  private:
224  CellDistArrayPtr mArrayPtr;
226  CellDist* mData;
228  int mStride;
230  const Rect2i mRegion;
231  };
232 
243  void ensureRegion(const Rect2i& region);
244 
254  Region getRegion(const Point2f& d, const Rect2i& region);
255 
256 private:
257 
264  void createLUT(int width, int subdivisions);
265 
267  void freeLUT();
268 
274  void computeLUT(int width, int subdivisions);
275 
276 private:
278  int mWidth;
280  int mSubdivisions;
282  int mLayers;
284  int mSize;
286  std::vector<CellDistArrayPtr> mLUT;
287 
288  boost::mutex mMutex;
289 };
290 
292 }
293 
294 #endif
This class creates a look up table (LUT) to calculate the minimum and maximum Euclidean distance betw...
Definition: DistanceLUT.h:122
A struct to store the minimal and maximal distance of the cell towards the center point...
Definition: DistanceLUT.h:138
boost::shared_ptr< CellDist > CellDistArrayPtr
Definition: DistanceLUT.h:146
int getXmin() const
Returns the minimum x-boundary.
Definition: DistanceLUT.h:178
iterator begin(int y) const
Returns line iterator starting in the specified line.
Definition: DistanceLUT.h:210
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Class for 2D, 3D and N-dimensional points.
Provided for convenience.
Definition: Singleton.h:564
int getXmax() const
Returns the maximum x-boundary.
Definition: DistanceLUT.h:181
int getYmax() const
Returns the maximum y-boundary.
Definition: DistanceLUT.h:187
const CellDist * iterator
the class&#39;s iterator type
Definition: DistanceLUT.h:142
float minDist
Definition: DistanceLUT.h:139
int getWidth() const
Returns the region&#39;s width.
Definition: DistanceLUT.h:190
A singleton class that can be freely configured using policies that control the creation, instantiation, lifetime and thread-safety.
Region(CellDistArrayPtr array, CellDist *data, int stride, const Rect2i &region)
The constructor of the region.
Definition: DistanceLUT.h:169
Provides multidimensional rectangle templates.
Provides a view on a portion of the Distance LUT and can be obtained by calling DistanceLUT::getRegio...
Definition: DistanceLUT.h:158
const Rect2i & getRect() const
Returns a Rect containing the boundaries of this region.
Definition: DistanceLUT.h:175
int getYmin() const
Returns the minimum y-boundary.
Definition: DistanceLUT.h:184
iterator end(int y) const
Returns end iterator for the specified line.
Definition: DistanceLUT.h:218
int getHeight() const
Returns the region&#39;s height.
Definition: DistanceLUT.h:193
#define MIRA_BASE_EXPORT
This is required because on windows there is a macro defined called ERROR.
Definition: Platform.h:153
iterator getIterator(int x, int y) const
Returns an iterator to the given cell.
Definition: DistanceLUT.h:202