00001 00004 /***************************************************************************** 00005 ** Includes 00006 *****************************************************************************/ 00007 00008 #include <cost_map_core/iterators/costmap_iterator.hpp> 00009 #include <grid_map_core/GridMapMath.hpp> 00010 00011 00012 namespace cost_map { 00013 00014 CostMapIterator::CostMapIterator(const cost_map::CostMap& gridMap) 00015 { 00016 size_ = gridMap.getSize(); 00017 startIndex_ = gridMap.getStartIndex(); 00018 endIndex_ = startIndex_ + gridMap.getSize() - Eigen::Array2i::Ones(); 00019 grid_map::boundIndexToRange(endIndex_, size_); 00020 index_ = startIndex_; 00021 isPastEnd_ = false; 00022 } 00023 00024 CostMapIterator::CostMapIterator(const CostMapIterator* other) 00025 { 00026 size_ = other->size_; 00027 startIndex_ = other->startIndex_; 00028 endIndex_ = other->endIndex_; 00029 index_ = other->index_; 00030 isPastEnd_ = other->isPastEnd_; 00031 } 00032 00033 CostMapIterator& CostMapIterator::operator =(const CostMapIterator& other) 00034 { 00035 size_ = other.size_; 00036 startIndex_ = other.startIndex_; 00037 endIndex_ = other.endIndex_; 00038 index_ = other.index_; 00039 isPastEnd_ = other.isPastEnd_; 00040 return *this; 00041 } 00042 00043 bool CostMapIterator::operator !=(const CostMapIterator& other) const 00044 { 00045 return (index_ != other.index_).any(); 00046 } 00047 00048 const Index& CostMapIterator::operator *() const 00049 { 00050 return index_; 00051 } 00052 00053 const Index CostMapIterator::getUnwrappedIndex() const 00054 { 00055 return grid_map::getIndexFromBufferIndex(index_, size_, startIndex_); 00056 } 00057 00058 CostMapIterator& CostMapIterator::operator ++() 00059 { 00060 isPastEnd_ = !grid_map::incrementIndex(index_, size_, startIndex_); 00061 return *this; 00062 } 00063 00064 CostMapIterator CostMapIterator::end() const 00065 { 00066 CostMapIterator res(this); 00067 res.index_ = endIndex_; 00068 return res; 00069 } 00070 00071 bool CostMapIterator::isPastEnd() const 00072 { 00073 return isPastEnd_; 00074 } 00075 00076 } /* namespace cost_map */