circle_iterator.cpp
Go to the documentation of this file.
1 
4 /*****************************************************************************
5 ** Includes
6 *****************************************************************************/
7 
10 
11 
12 using namespace std;
13 
14 namespace cost_map {
15 
16 CircleIterator::CircleIterator(const CostMap& gridMap, const Position& center, const double radius)
17  : center_(center),
18  radius_(radius)
19 {
20  radiusSquare_ = pow(radius_, 2);
21  mapLength_ = gridMap.getLength();
22  mapPosition_ = gridMap.getPosition();
23  resolution_ = gridMap.getResolution();
24  bufferSize_ = gridMap.getSize();
25  bufferStartIndex_ = gridMap.getStartIndex();
26  Index submapStartIndex;
27  Index submapBufferSize;
28  findSubmapParameters(center, radius, submapStartIndex, submapBufferSize);
29  internalIterator_ = std::shared_ptr<SubmapIterator>(new SubmapIterator(gridMap, submapStartIndex, submapBufferSize));
30  if(!isInside()) ++(*this);
31 }
32 
34 {
35  center_ = other.center_;
36  radius_ = other.radius_;
39  mapLength_ = other.mapLength_;
40  mapPosition_ = other.mapPosition_;
41  resolution_ = other.resolution_;
42  bufferSize_ = other.bufferSize_;
44  return *this;
45 }
46 
48 {
49  return (internalIterator_ != other.internalIterator_);
50 }
51 
53 {
54  return *(*internalIterator_);
55 }
56 
58 {
59  ++(*internalIterator_);
60  if (internalIterator_->isPastEnd()) return *this;
61 
62  for ( ; !internalIterator_->isPastEnd(); ++(*internalIterator_)) {
63  if (isInside()) break;
64  }
65 
66  return *this;
67 }
68 
70 {
71  return internalIterator_->isPastEnd();
72 }
73 
75 {
76  Position position;
78  double squareNorm = (position - center_).array().square().sum();
79  return (squareNorm <= radiusSquare_);
80 }
81 
82 void CircleIterator::findSubmapParameters(const Position& center, const double radius,
83  Index& startIndex, Size& bufferSize) const
84 {
85  Position topLeft = center.array() + radius;
86  Position bottomRight = center.array() - radius;
90  Index endIndex;
92  bufferSize = endIndex - startIndex + Index::Ones();
93 }
94 
95 } /* namespace cost_map */
96 
const Length & getLength() const
const Size & getSize() const
double getResolution() const
Length mapLength_
Map information needed to get position from iterator.
const Index & operator*() const
grid_map::Size Size
Definition: common.hpp:46
bool getIndexFromPosition(Index &index, const Position &position, const Length &mapLength, const Position &mapPosition, const double &resolution, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
CircleIterator & operator++()
double radiusSquare_
Square of the radius for efficiency.
void findSubmapParameters(const Position &center, const double radius, Index &startIndex, Size &bufferSize) const
std::shared_ptr< SubmapIterator > internalIterator_
Grid submap iterator.
bool getPosition(const Index &index, Position &position) const
grid_map::Index Index
Definition: common.hpp:45
Position center_
Position of the circle center;.
grid_map::Position Position
Definition: common.hpp:41
bool getPositionFromIndex(Position &position, const Index &index, const Length &mapLength, const Position &mapPosition, const double &resolution, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
bool operator!=(const CircleIterator &other) const
const Index & getStartIndex() const
void boundPositionToRange(Position &position, const Length &mapLength, const Position &mapPosition)
CircleIterator & operator=(const CircleIterator &other)
double radius_
Radius of the circle.


cost_map_core
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:03:40