EllipseIterator.cpp
Go to the documentation of this file.
1 /*
2  * EllipseIterator.hpp
3  *
4  * Created on: Dec 2, 2015
5  * Author: Péter Fankhauser
6  * Institute: ETH Zurich, ANYbotics
7  */
8 
11 
12 #include <cmath>
13 #include <Eigen/Geometry>
14 
15 namespace grid_map {
16 
17 EllipseIterator::EllipseIterator(const GridMap& gridMap, const Position& center, const Length& length, const double rotation)
18  : center_(center)
19 {
20  semiAxisSquare_ = (0.5 * length).square();
21  double sinRotation = std::sin(rotation);
22  double cosRotation = std::cos(rotation);
23  transformMatrix_ << cosRotation, sinRotation, sinRotation, -cosRotation;
24  mapLength_ = gridMap.getLength();
25  mapPosition_ = gridMap.getPosition();
26  resolution_ = gridMap.getResolution();
27  bufferSize_ = gridMap.getSize();
28  bufferStartIndex_ = gridMap.getStartIndex();
29  Index submapStartIndex;
30  Index submapBufferSize;
31  findSubmapParameters(center, length, rotation, submapStartIndex, submapBufferSize);
32  internalIterator_ = std::make_shared<SubmapIterator>(gridMap, submapStartIndex, submapBufferSize);
33  if (!isInside()) {
34  ++(*this);
35  }
36 }
37 
39 {
40  return (internalIterator_ != other.internalIterator_);
41 }
42 
43 const Eigen::Array2i& EllipseIterator::operator *() const
44 {
45  return *(*internalIterator_);
46 }
47 
49 {
50  ++(*internalIterator_);
51  if (internalIterator_->isPastEnd()) {
52  return *this;
53  }
54 
55  for ( ; !internalIterator_->isPastEnd(); ++(*internalIterator_)) {
56  if (isInside()) {
57  break;
58  }
59  }
60 
61  return *this;
62 }
63 
65 {
66  return internalIterator_->isPastEnd();
67 }
68 
70 {
71  return internalIterator_->getSubmapSize();
72 }
73 
75 {
76  Position position;
78  double value = ((transformMatrix_ * (position - center_)).array().square() / semiAxisSquare_).sum();
79  return (value <= 1);
80 }
81 
82 void EllipseIterator::findSubmapParameters(const Position& center, const Length& length, const double rotation,
83  Index& startIndex, Size& bufferSize) const
84 {
85  const Eigen::Rotation2Dd rotationMatrix(rotation);
86  Eigen::Vector2d u = rotationMatrix * Eigen::Vector2d(length(0), 0.0);
87  Eigen::Vector2d v = rotationMatrix * Eigen::Vector2d(0.0, length(1));
88  const Length boundingBoxHalfLength = (u.cwiseAbs2() + v.cwiseAbs2()).array().sqrt();
89  Position topLeft = center.array() + boundingBoxHalfLength;
90  Position bottomRight = center.array() - boundingBoxHalfLength;
94  Index endIndex;
96  bufferSize = getSubmapSizeFromCornerIndices(startIndex, endIndex, bufferSize_, bufferStartIndex_);
97 }
98 
99 } /* namespace grid_map */
100 
Length mapLength_
Map information needed to get position from iterator.
const Index & operator*() const
void findSubmapParameters(const Position &center, const Length &length, double rotation, Index &startIndex, Size &bufferSize) const
const Index & getStartIndex() const
Definition: GridMap.cpp:669
Position center_
Position of the circle center;.
const Size & getSize() const
Definition: GridMap.cpp:661
EllipseIterator & operator++()
EllipseIterator(const GridMap &gridMap, const Position &center, const Length &length, double rotation=0.0)
double getResolution() const
Definition: GridMap.cpp:657
Eigen::Matrix2d transformMatrix_
Sine and cosine values of the rotation angle as transformation matrix.
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)
std::shared_ptr< SubmapIterator > internalIterator_
Grid submap iterator. // TODO Think of using unique_ptr instead.
Eigen::Vector2d Position
Definition: TypeDefs.hpp:18
const Size & getSubmapSize() const
Eigen::Array2i Index
Definition: TypeDefs.hpp:22
Eigen::Array2i Size
Definition: TypeDefs.hpp:23
bool operator!=(const EllipseIterator &other) const
Eigen::Array2d Length
Definition: TypeDefs.hpp:24
Eigen::Array2d semiAxisSquare_
Square length of the semi axis.
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)
bool getPosition(const Index &index, Position &position) const
Definition: GridMap.cpp:232
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