50 #ifndef RTREE_PLANNER_HPP_ 51 #define RTREE_PLANNER_HPP_ 55 #include <boost/random/mersenne_twister.hpp> 57 #include <boost/graph/adjacency_list.hpp> 58 #include <boost/graph/breadth_first_search.hpp> 59 #include <boost/graph/adjacency_list.hpp> 60 #include <boost/graph/dijkstra_shortest_paths.hpp> 62 #include <boost/pending/indirect_cmp.hpp> 63 #include <boost/range/irange.hpp> 64 #include <boost/range/numeric.hpp> 65 #include <boost/range/algorithm/transform.hpp> 66 #include <boost/range/algorithm/fill.hpp> 69 #include <boost/geometry.hpp> 70 #include <boost/geometry/algorithms/distance.hpp> 71 #include <boost/geometry/geometries/register/point.hpp> 72 #include <boost/geometry/geometries/point.hpp> 73 #include <boost/geometry/geometries/box.hpp> 74 #include <boost/geometry/geometries/polygon.hpp> 75 #include <boost/geometry/algorithms/correct.hpp> 76 #include <boost/geometry/geometries/adapted/boost_array.hpp> 77 #include <boost/geometry/geometries/register/linestring.hpp> 78 #include <boost/geometry/index/rtree.hpp> 80 #include <boost/math/special_functions/fpclassify.hpp> 81 #include <boost/math/constants/constants.hpp> 82 #include <boost/math/special_functions/sign.hpp> 85 namespace bgi = boost::geometry::index;
87 BOOST_GEOMETRY_REGISTER_BOOST_ARRAY_CS(cs::cartesian)
95 template <
typename Po
int>
100 boost::geometry::assign_zero(location);
112 template <
typename Line>
116 : length(
boost::geometry::length(line))
121 inline Line
const&
line()
const 135 typedef bg::model::box<point_type>
box;
141 typedef boost::adjacency_list
143 boost::vecS, boost::vecS, boost::undirectedS
152 typedef std::pair<point_type, vertex_descriptor_type>
rtree_value;
153 typedef boost::geometry::index::rtree<rtree_value,bgi::rstar<16, 4> >
knn_rtree_type;
158 BOOST_GEOMETRY_REGISTER_LINESTRING(std::vector<plan::ArmPos>)
165 T signedPI = boost::math::copysign(boost::math::constants::pi<T>(),rad);
167 rad = std::fmod(rad+signedPI,(boost::math::constants::two_pi<T>())) - signedPI;
180 return (Left + Right*Right);
184 namespace boost {
namespace geometry {
191 boost::transform(p1,p2,diff.begin(),std::minus<plan::ArmPos::value_type>());
192 boost::transform(diff,diff.begin(),&normalizeRadiansPiToMinusPi<plan::ArmPos::value_type>);
200 template<
typename Box>
205 boost::transform(normAP,bg::get<bg::min_corner>(box),mindiff.begin(),std::minus<plan::ArmPos::value_type>());
206 boost::transform(mindiff,mindiff.begin(),&normalizeRadiansPiToMinusPi<plan::ArmPos::value_type>);
208 boost::transform(normAP,bg::get<bg::max_corner>(box),maxdiff.begin(),std::minus<plan::ArmPos::value_type>());
209 boost::transform(maxdiff,maxdiff.begin(),&normalizeRadiansPiToMinusPi<plan::ArmPos::value_type>);
211 plan::ArmPos::value_type final_distance = 0.0;
212 for(
int i = 0; i < armpos.size(); ++i){
213 if(mindiff[i] >= 0.0 && maxdiff[i] <= 0.0)
continue;
214 plan::ArmPos::value_type min_dist = std::min(std::abs(mindiff[i]),std::abs(maxdiff[i]));
215 final_distance+=min_dist*min_dist;
218 return final_distance;
227 template <
typename Graph,
typename Route>
229 typename boost::graph_traits<Graph>::vertex_descriptor vertex1,
230 typename boost::graph_traits<Graph>::vertex_descriptor vertex2,
235 typename boost::graph_traits<Graph>::edge_descriptor,
237 > opt_edge = boost::edge(vertex1, vertex2, graph);
244 typename boost::geometry::point_type<plan::edge_type>::type
245 >
const& vertex_prop = graph[vertex2];
248 if (boost::geometry::equals(*bg::segment_view<plan::edge_type>(edge_prop.
line()).begin(), vertex_prop.location))
250 std::copy(bg::segment_view<plan::edge_type>(edge_prop.
line()).begin(), bg::segment_view<plan::edge_type>(edge_prop.
line()).end(),
251 std::back_inserter(route));
255 std::reverse_copy(bg::segment_view<plan::edge_type>(edge_prop.
line()).begin(), bg::segment_view<plan::edge_type>(edge_prop.
line()).end(),
256 std::back_inserter(route));
264 template <
typename Graph,
typename Route>
266 std::vector<
typename boost::graph_traits<Graph>::vertex_descriptor>
const& predecessors,
267 typename boost::graph_traits<Graph>::vertex_descriptor vertex1,
268 typename boost::graph_traits<Graph>::vertex_descriptor vertex2,
271 typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_type;
272 vertex_type pred = predecessors[vertex2];
275 while (pred != vertex1)
278 pred = predecessors[pred];
boost::array< double, 6 > ArmPos
bg::model::box< point_type > box
bg_vertex_property< point_type > vertex_property_type
T operator()(const T &Left, const T &Right) const
OutputIterator copy(std::string model, OutputIterator it, grl::revolute_joint_velocity_open_chain_state_constraint_tag)
copy vector of joint velocity limits in radians/s
boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, bg_vertex_property< point_type >, bg_edge_property< line_type > > graph_type
T normalizeRadiansPiToMinusPi(T rad)
bg_vertex_property(Point const &loc)
boost::geometry::index::rtree< rtree_value, bgi::rstar< 16, 4 > > knn_rtree_type
void add_edge_to_route(Graph const &graph, typename boost::graph_traits< Graph >::vertex_descriptor vertex1, typename boost::graph_traits< Graph >::vertex_descriptor vertex2, Route &route)
bg_edge_property< edge_type > edge_property_type
std::pair< point_type, vertex_descriptor_type > rtree_value
double comparable_distance(plan::ArmPos const &armpos, Box const &box)
distance between a a point and an axis aligned "box" on the surface of an n-torus ...
Line const & line() const
bg_edge_property(Line const &line)
bg::model::segment< point_type > line_type
void build_route(Graph const &graph, std::vector< typename boost::graph_traits< Graph >::vertex_descriptor > const &predecessors, typename boost::graph_traits< Graph >::vertex_descriptor vertex1, typename boost::graph_traits< Graph >::vertex_descriptor vertex2, Route &route)
boost::graph_traits< graph_type >::vertex_descriptor vertex_descriptor_type