PolygonIterator.cpp
Go to the documentation of this file.
1 /*
2  * PolygonIterator.hpp
3  *
4  * Created on: Sep 19, 2014
5  * Author: Péter Fankhauser
6  * Institute: ETH Zurich, ANYbotics
7  */
8 
9 #include <memory>
10 
13 
14 namespace grid_map {
15 
17  : polygon_(polygon)
18 {
19  mapLength_ = gridMap.getLength();
20  mapPosition_ = gridMap.getPosition();
21  resolution_ = gridMap.getResolution();
22  bufferSize_ = gridMap.getSize();
23  bufferStartIndex_ = gridMap.getStartIndex();
24  Index submapStartIndex;
25  Size submapBufferSize;
26  findSubmapParameters(polygon, submapStartIndex, submapBufferSize);
27  internalIterator_ = std::make_shared<SubmapIterator>(gridMap, submapStartIndex, submapBufferSize);
28  if (!isInside()) {
29  ++(*this);
30  }
31 }
32 
34 {
35  return (internalIterator_ != other.internalIterator_);
36 }
37 
39 {
40  return *(*internalIterator_);
41 }
42 
44 {
45  ++(*internalIterator_);
46  if (internalIterator_->isPastEnd()) {
47  return *this;
48  }
49 
50  for (; !internalIterator_->isPastEnd(); ++(*internalIterator_)) {
51  if (isInside()) {
52  break;
53  }
54  }
55 
56  return *this;
57 }
58 
60 {
61  return internalIterator_->isPastEnd();
62 }
63 
65 {
66  Position position;
68  return polygon_.isInside(position);
69 }
70 
71 void PolygonIterator::findSubmapParameters(const grid_map::Polygon& /*polygon*/, Index& startIndex, Size& bufferSize) const
72 {
73  Position topLeft = polygon_.getVertices()[0];
74  Position bottomRight = topLeft;
75  for (const auto& vertex : polygon_.getVertices()) {
76  topLeft = topLeft.array().max(vertex.array());
77  bottomRight = bottomRight.array().min(vertex.array());
78  }
82  Index endIndex;
84  bufferSize = getSubmapSizeFromCornerIndices(startIndex, endIndex, bufferSize_, bufferStartIndex_);
85 }
86 
87 } /* namespace grid_map */
88 
PolygonIterator(const grid_map::GridMap &gridMap, const grid_map::Polygon &polygon)
grid_map::Polygon polygon_
Polygon to iterate on.
PolygonIterator & operator++()
const Index & getStartIndex() const
Definition: GridMap.cpp:669
const Size & getSize() const
Definition: GridMap.cpp:661
std::shared_ptr< SubmapIterator > internalIterator_
Grid submap iterator.
bool operator!=(const PolygonIterator &other) const
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
bool isInside(const Position &point) const
Definition: Polygon.cpp:30
void findSubmapParameters(const grid_map::Polygon &polygon, Index &startIndex, Size &bufferSize) 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())
Length mapLength_
Map information needed to get position from iterator.
void boundPositionToRange(Position &position, const Length &mapLength, const Position &mapPosition)
const Index & operator*() const
bool getPosition(const Index &index, Position &position) const
Definition: GridMap.cpp:232
const std::vector< Position > & getVertices() const
Definition: Polygon.cpp:64
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