CircleIterator.cpp
Go to the documentation of this file.
1 /*
2  * CircleIterator.hpp
3  *
4  * Created on: Nov 13, 2014
5  * Author: Péter Fankhauser
6  * Institute: ETH Zurich, ANYbotics
7  */
8 
10 
11 #include <memory>
13 
14 namespace grid_map {
15 
16 CircleIterator::CircleIterator(const GridMap& 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::make_shared<SubmapIterator>(gridMap, submapStartIndex, submapBufferSize);
30  if(!isInside()) {
31  ++(*this);
32  }
33 }
34 
36 {
37  return (internalIterator_ != other.internalIterator_);
38 }
39 
41 {
42  return *(*internalIterator_);
43 }
44 
46 {
47  ++(*internalIterator_);
48  if (internalIterator_->isPastEnd()) {
49  return *this;
50  }
51 
52  for ( ; !internalIterator_->isPastEnd(); ++(*internalIterator_)) {
53  if (isInside()) {
54  break;
55  }
56  }
57 
58  return *this;
59 }
60 
62 {
63  return internalIterator_->isPastEnd();
64 }
65 
67 {
68  Position position;
70  double squareNorm = (position - center_).array().square().sum();
71  return (squareNorm <= radiusSquare_);
72 }
73 
74 void CircleIterator::findSubmapParameters(const Position& center, const double radius,
75  Index& startIndex, Size& bufferSize) const
76 {
77  Position topLeft = center.array() + radius;
78  Position bottomRight = center.array() - radius;
82  Index endIndex;
84  bufferSize = getSubmapSizeFromCornerIndices(startIndex, endIndex, bufferSize_, bufferStartIndex_);
85 }
86 
87 } /* namespace grid_map */
88 
double radiusSquare_
Square of the radius (for efficiency).
void findSubmapParameters(const Position &center, double radius, Index &startIndex, Size &bufferSize) const
double radius_
Radius of the circle.
Position center_
Position of the circle center;.
const Index & getStartIndex() const
Definition: GridMap.cpp:669
const Size & getSize() const
Definition: GridMap.cpp:661
CircleIterator & operator++()
double getResolution() const
Definition: GridMap.cpp:657
bool getIndexFromPosition(Index &index, const Position &position, const Length &mapLength, const Position &mapPosition, const double &resolution, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
Size getSubmapSizeFromCornerIndices(const Index &topLeftIndex, const Index &bottomRightIndex, const Size &bufferSize, const Index &bufferStartIndex)
Eigen::Vector2d Position
Definition: TypeDefs.hpp:18
Eigen::Array2i Index
Definition: TypeDefs.hpp:22
Eigen::Array2i Size
Definition: TypeDefs.hpp:23
CircleIterator(const GridMap &gridMap, const Position &center, double radius)
bool operator!=(const CircleIterator &other) const
bool getPositionFromIndex(Position &position, const Index &index, const Length &mapLength, const Position &mapPosition, const double &resolution, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
void boundPositionToRange(Position &position, const Length &mapLength, const Position &mapPosition)
Length mapLength_
Map information needed to get position from iterator.
const Index & operator*() const
bool getPosition(const Index &index, Position &position) const
Definition: GridMap.cpp:232
std::shared_ptr< SubmapIterator > internalIterator_
Grid submap iterator. // TODO Think of using unique_ptr instead.
const Length & getLength() const
Definition: GridMap.cpp:649


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Wed Jul 5 2023 02:23:35