spiral_iterator.cpp
Go to the documentation of this file.
1 /*
2  * SpiralIterator.hpp
3  *
4  * Created on: Jul 7, 2015
5  * Author: Martin Wermelinger
6  * Institute: ETH Zurich, Autonomous Systems Lab
7  */
8 
11 #include <cmath>
12 
13 using namespace std;
14 
15 namespace cost_map {
16 
17 SpiralIterator::SpiralIterator(const cost_map::CostMap& gridMap, const Eigen::Vector2d& center,
18  const double radius)
19  : center_(center),
20  radius_(radius),
21  distance_(0)
22 {
24  mapLength_ = gridMap.getLength();
25  mapPosition_ = gridMap.getPosition();
26  resolution_ = gridMap.getResolution();
27  bufferSize_ = gridMap.getSize();
28  gridMap.getIndex(center_, indexCenter_);
29  nRings_ = std::ceil(radius_ / resolution_);
31  else generateRing();
32 }
33 
35 {
36  center_ = other.center_;
37  indexCenter_ = other.indexCenter_;
38  radius_ = other.radius_;
40  nRings_ = other.nRings_;
41  distance_ = other.distance_;
42  pointsRing_ = other.pointsRing_;
43  mapLength_ = other.mapLength_;
44  mapPosition_ = other.mapPosition_;
45  resolution_ = other.resolution_;
46  bufferSize_ = other.bufferSize_;
47  return *this;
48 }
49 
51 {
52  return (pointsRing_.back() != pointsRing_.back()).any();
53 }
54 
55 const Eigen::Array2i& SpiralIterator::operator *() const
56 {
57  return pointsRing_.back();
58 }
59 
61 {
62  pointsRing_.pop_back();
63  if (pointsRing_.empty() && !isPastEnd()) generateRing();
64  return *this;
65 }
66 
68 {
69  return (distance_ == nRings_ && pointsRing_.empty());
70 }
71 
72 bool SpiralIterator::isInside(const Index index) const
73 {
74  Eigen::Vector2d position;
76  double squareNorm = (position - center_).array().square().sum();
77  return (squareNorm <= radiusSquare_);
78 }
79 
81 {
82  distance_++;
83  Index point(distance_, 0);
84  Index pointInMap;
85  Index normal;
86  do {
87  pointInMap.x() = point.x() + indexCenter_.x();
88  pointInMap.y() = point.y() + indexCenter_.y();
89  if (grid_map::checkIfIndexInRange(pointInMap, bufferSize_)) {
90  if (distance_ == nRings_ || distance_ == nRings_ - 1) {
91  if (isInside(pointInMap))
92  pointsRing_.push_back(pointInMap);
93  } else {
94  pointsRing_.push_back(pointInMap);
95  }
96  }
97  normal.x() = -signum(point.y());
98  normal.y() = signum(point.x());
99  if (normal.x() != 0
100  && (int) Vector(point.x() + normal.x(), point.y()).norm() == distance_)
101  point.x() += normal.x();
102  else if (normal.y() != 0
103  && (int) Vector(point.x(), point.y() + normal.y()).norm() == distance_)
104  point.y() += normal.y();
105  else {
106  point.x() += normal.x();
107  point.y() += normal.y();
108  }
109  } while (point.x() != distance_ || point.y() != 0);
110 }
111 
113 {
114  Index radius = *(*this) - indexCenter_;
115  return radius.matrix().norm() * resolution_;
116 }
117 
118 } /* namespace cost_map */
119 
Position center_
Position of the circle center;.
SpiralIterator & operator=(const SpiralIterator &other)
const Length & getLength() const
const Size & getSize() const
std::vector< Index > pointsRing_
bool isInside(const Index index) const
Length mapLength_
Map information needed to get position from iterator.
double getResolution() const
bool operator!=(const SpiralIterator &other) const
const Eigen::Array2i & operator*() const
grid_map::Vector Vector
Definition: common.hpp:42
double radius_
Radius of the circle.
double radiusSquare_
Square of the radius for efficiency.
bool getPosition(const Index &index, Position &position) const
double getCurrentRadius() const
grid_map::Index Index
Definition: common.hpp:45
unsigned int nRings_
Number of rings into the circle is divided.
bool checkIfIndexInRange(const Index &index, const Size &bufferSize)
bool getPositionFromIndex(Position &position, const Index &index, const Length &mapLength, const Position &mapPosition, const double &resolution, const Size &bufferSize, const Index &bufferStartIndex=Index::Zero())
SpiralIterator & operator++()
int signum(const int val)
bool getIndex(const Position &position, Index &index) const


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