| 214 | } |
| 215 | |
| 216 | void IteratorsDemo::demoSlidingWindowIterator() |
| 217 | { |
| 218 | ROS_INFO("Running sliding window iterator demo."); |
| 219 | demoPolygonIterator(true); |
| 220 | publish(); |
| 221 | const size_t windowSize = 3; |
| 222 | const grid_map::SlidingWindowIterator::EdgeHandling edgeHandling = grid_map::SlidingWindowIterator::EdgeHandling::CROP; |
| 223 | map_.add("copy", map_["type"]); |
| 224 | |
| 225 | for (grid_map::SlidingWindowIterator iterator(map_, "copy", edgeHandling, windowSize); |
| 226 | !iterator.isPastEnd(); ++iterator) { |
| 227 | map_.at("type", *iterator) = iterator.getData().meanOfFinites(); // Blurring. |
| 228 | publish(); |
| 229 | |
| 230 | // Visualize sliding window as polygon. |
| 231 | grid_map::Polygon polygon; |
| 232 | Position center; |
| 233 | map_.getPosition(*iterator, center); |
| 234 | const Length windowHalfLength(Length::Constant(0.5 * (double) windowSize * map_.getResolution())); |
| 235 | polygon.addVertex(center + (Eigen::Array2d(-1.0,-1.0) * windowHalfLength).matrix()); |
| 236 | polygon.addVertex(center + (Eigen::Array2d(-1.0, 1.0) * windowHalfLength).matrix()); |
| 237 | polygon.addVertex(center + (Eigen::Array2d( 1.0, 1.0) * windowHalfLength).matrix()); |
| 238 | polygon.addVertex(center + (Eigen::Array2d( 1.0,-1.0) * windowHalfLength).matrix()); |
| 239 | polygon.setFrameId(map_.getFrameId()); |
| 240 | geometry_msgs::PolygonStamped message; |
| 241 | grid_map::PolygonRosConverter::toMessage(polygon, message); |
| 242 | polygonPublisher_.publish(message); |
| 243 | |
| 244 | ros::Duration duration(0.02); |
| 245 | duration.sleep(); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | void IteratorsDemo::publish() |
| 250 | { |
nothing calls this directly
no test coverage detected