/usr/include/ompl/datastructures/GridN.h is in libompl-dev 0.13.0+git20130920.01d0ca4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | /*********************************************************************
* Software License Agreement (BSD License)
*
* Copyright (c) 2010, Rice University
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Rice University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/
/* Author: Ioan Sucan */
#ifndef OMPL_DATASTRUCTURES_GRID_N_
#define OMPL_DATASTRUCTURES_GRID_N_
#include "ompl/datastructures/Grid.h"
namespace ompl
{
/** \brief Representation of a grid where cells keep track of how many neighbors they have */
template <typename _T>
class GridN : public Grid<_T>
{
public:
/// Datatype for cell in base class
typedef typename Grid<_T>::Cell BaseCell;
/// Datatype for array of cells in base class
typedef typename Grid<_T>::CellArray BaseCellArray;
/// Datatype for cell coordinates
typedef typename Grid<_T>::Coord Coord;
/// Definition of a cell in this grid
struct Cell : public BaseCell
{
/// The number of neighbors
unsigned int neighbors;
/// A flag indicating whether this cell is on the border or not
bool border;
Cell(void) : BaseCell(), neighbors(0), border(true)
{
}
virtual ~Cell(void)
{
}
};
/// The datatype for arrays of cells
typedef std::vector<Cell*> CellArray;
/// The constructor takes the dimension of the grid as argument
explicit
GridN(unsigned int dimension) : Grid<_T>(dimension)
{
hasBounds_ = false;
overrideCellNeighborsLimit_ = false;
setDimension(dimension);
}
virtual ~GridN(void)
{
}
/// Update the dimension of the grid; this should not be done
/// unless the grid is empty
void setDimension(unsigned int dimension)
{
assert(Grid<_T>::empty() == true);
Grid<_T>::dimension_ = dimension;
Grid<_T>::maxNeighbors_ = 2 * dimension;
if (!overrideCellNeighborsLimit_)
interiorCellNeighborsLimit_ = Grid<_T>::maxNeighbors_;
}
/// If bounds for the grid need to be considered, we can set them here.
/// When the number of neighbors are counted, whether the
/// Space is bounded matters, in the sense that if a cell is on
/// the boundary, we know some of its neighbors cannot exist.
/// In order to allow such a cell to reflect the fact it has
/// Achieved its maximal number of neighbors, the boundary is
/// counted as the number of neighbors it prevents from
/// existing.
void setBounds(const Coord &low, const Coord &up)
{
lowBound_ = low;
upBound_ = up;
hasBounds_ = true;
}
/// Set the limit of neighboring cells to determine when a cell becomes interior
/// by default, this is 2 * dimension of grid
void setInteriorCellNeighborLimit(unsigned int count)
{
interiorCellNeighborsLimit_ = count;
assert(interiorCellNeighborsLimit_ > 0);
overrideCellNeighborsLimit_ = true;
}
/// Get the cell at a specified coordinate
Cell* getCell(const Coord &coord) const
{
return static_cast<Cell*>(Grid<_T>::getCell(coord));
}
/// Get the list of neighbors for a given cell
void neighbors(const Cell* cell, CellArray& list) const
{
Coord test = cell->coord;
neighbors(test, list);
}
/// Get the list of neighbors for a given coordinate
void neighbors(const Coord& coord, CellArray& list) const
{
Coord test = coord;
neighbors(test, list);
}
/// Get the list of neighbors for a given coordinate
void neighbors(Coord& coord, CellArray& list) const
{
BaseCellArray baselist;
Grid<_T>::neighbors(coord, baselist);
list.reserve(list.size() + baselist.size());
for (unsigned int i = 0 ; i < baselist.size() ; ++i)
list.push_back(static_cast<Cell*>(baselist[i]));
}
/// Instantiate a new cell at given coordinates;
/// Optionally return the list of future neighbors. Note:
/// this call only creates the cell, but does not add it to
/// the grid. It however updates the neighbor count for
/// neighboring cells
virtual BaseCell* createCell(const Coord& coord, BaseCellArray *nbh = NULL)
{
Cell *cell = new Cell();
cell->coord = coord;
BaseCellArray *list = nbh ? nbh : new BaseCellArray();
Grid<_T>::neighbors(cell->coord, *list);
for (typename BaseCellArray::iterator cl = list->begin() ; cl != list->end() ; ++cl)
{
Cell* c = static_cast<Cell*>(*cl);
c->neighbors++;
if (c->border && c->neighbors >= interiorCellNeighborsLimit_)
c->border = false;
}
cell->neighbors = numberOfBoundaryDimensions(cell->coord) + list->size();
if (cell->border && cell->neighbors >= interiorCellNeighborsLimit_)
cell->border = false;
if (!nbh)
delete list;
return cell;
}
/// Remove a cell from the grid. If the cell has not been
/// Added to the grid, only update the neighbor list
virtual bool remove(BaseCell *cell)
{
if (cell)
{
BaseCellArray *list = new BaseCellArray();
Grid<_T>::neighbors(cell->coord, *list);
for (typename BaseCellArray::iterator cl = list->begin() ; cl != list->end() ; ++cl)
{
Cell* c = static_cast<Cell*>(*cl);
c->neighbors--;
if (!c->border && c->neighbors < interiorCellNeighborsLimit_)
c->border = true;
}
delete list;
typename Grid<_T>::CoordHash::iterator pos = Grid<_T>::hash_.find(&cell->coord);
if (pos != Grid<_T>::hash_.end())
{
Grid<_T>::hash_.erase(pos);
return true;
}
}
return false;
}
/// Get the set of instantiated cells in the grid
void getCells(CellArray &cells) const
{
for (typename Grid<_T>::CoordHash::const_iterator i = Grid<_T>::hash_.begin() ;
i != Grid<_T>::hash_.end() ; ++i)
cells.push_back(static_cast<Cell*>(i->second));
}
protected:
/// Compute how many sides of a coordinate touch the boundaries of the grid
unsigned int numberOfBoundaryDimensions(const Coord &coord) const
{
unsigned int result = 0;
if (hasBounds_)
{
for (unsigned int i = 0 ; i < Grid<_T>::dimension_ ; ++i)
if (coord[i] == lowBound_[i] || coord[i] == upBound_[i])
result++;
}
return result;
}
/// Flag indicating whether bounds are in effect for this grid
bool hasBounds_;
/// If bounds are set, this defines the lower corner cell
Coord lowBound_;
/// If bounds are set, this defines the upper corner cell
Coord upBound_;
/// By default, cells are considered on the border if 2n
/// neighbors are created, for a space of dimension n.
/// this value is overridden and set in this member variable
unsigned int interiorCellNeighborsLimit_;
/// Flag indicating whether the neighbor count used to determine whether
/// a cell is on the border or not
bool overrideCellNeighborsLimit_;
};
}
#endif
|