Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <nav_grid_iterators/polygon_outline.h>
00036 #include <nav_grid/coordinate_conversion.h>
00037 #include <nav_2d_utils/polygons.h>
00038
00039 namespace nav_grid_iterators
00040 {
00041 PolygonOutline::PolygonOutline(const nav_grid::NavGridInfo* info, nav_2d_msgs::Polygon2D polygon, bool bresenham)
00042 : BaseIterator(info), polygon_(polygon), start_index_(0, 0), bresenham_(bresenham), side_index_(0)
00043 {
00044 if (polygon.points.size() == 0)
00045 {
00046 internal_iterator_.reset(new Line(info_, 0.0, 0.0, 0.0, 0.0, false, bresenham_));
00047 index_ = **internal_iterator_;
00048 start_index_ = index_;
00049 return;
00050 }
00051 loadSide();
00052 index_ = **internal_iterator_;
00053 start_index_ = index_;
00054 }
00055
00056 PolygonOutline::PolygonOutline(const PolygonOutline& other)
00057 : PolygonOutline(other.info_, other.index_, other.polygon_, other.bresenham_, other.side_index_)
00058 {
00059 }
00060
00061 PolygonOutline::PolygonOutline(const nav_grid::NavGridInfo* info, const nav_grid::Index& index,
00062 nav_2d_msgs::Polygon2D polygon, bool bresenham, unsigned int side_index)
00063 : BaseIterator(info, index), polygon_(polygon), start_index_(index), bresenham_(bresenham), side_index_(side_index)
00064 {
00065 loadSide();
00066 }
00067
00068 PolygonOutline& PolygonOutline::operator=(const PolygonOutline& other)
00069 {
00070 info_ = other.info_;
00071 index_ = other.index_;
00072 polygon_ = other.polygon_;
00073 bresenham_ = other.bresenham_;
00074 side_index_ = other.side_index_;
00075 loadSide();
00076 return *this;
00077 }
00078
00079 void PolygonOutline::loadSide()
00080 {
00081 while (side_index_ < polygon_.points.size())
00082 {
00083
00084 unsigned int next_index = side_index_ + 1;
00085 if (next_index == polygon_.points.size())
00086 {
00087 next_index = 0;
00088 }
00089
00090 internal_iterator_.reset(new Line(info_,
00091 polygon_.points[side_index_].x, polygon_.points[side_index_].y,
00092 polygon_.points[next_index].x, polygon_.points[next_index].y,
00093 false, bresenham_));
00094
00095 if (*internal_iterator_ != internal_iterator_->end())
00096 break;
00097 ++side_index_;
00098 }
00099 }
00100
00101 PolygonOutline PolygonOutline::begin() const
00102 {
00103 return PolygonOutline(info_, start_index_, polygon_, bresenham_, 0);
00104 }
00105
00106 PolygonOutline PolygonOutline::end() const
00107 {
00108
00109
00110 return PolygonOutline(info_, start_index_, polygon_, bresenham_, polygon_.points.size());
00111 }
00112
00113 void PolygonOutline::increment()
00114 {
00115 ++(*internal_iterator_);
00116 if (*internal_iterator_ == internal_iterator_->end())
00117 {
00118 ++side_index_;
00119 if (side_index_ == polygon_.points.size())
00120 {
00121 index_ = start_index_;
00122 return;
00123 }
00124 loadSide();
00125 }
00126 index_ = **internal_iterator_;
00127 }
00128
00129 bool PolygonOutline::fieldsEqual(const PolygonOutline& other)
00130 {
00131 return side_index_ == other.side_index_ && nav_2d_utils::equals(polygon_, other.polygon_) &&
00132 bresenham_ == other.bresenham_;
00133 }
00134
00135 }