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
00040 #ifndef POSE_GRAPH_POSE_GRAPH_IMPL_H
00041 #define POSE_GRAPH_POSE_GRAPH_IMPL_H
00042
00043 #include "pose_graph.h"
00044
00045 #define BOOST_NO_HASH
00046 #include <boost/graph/adjacency_list.hpp>
00047
00048 #include <boost/graph/graph_traits.hpp>
00049
00050 namespace pose_graph {
00051
00052 using boost::listS;
00053 using boost::multisetS;
00054 using boost::undirectedS;
00055 using boost::adjacency_list;
00056 using boost::graph_traits;
00057 using std::map;
00058 using std::vector;
00059 using std::set;
00060 using std::pair;
00061
00062
00063
00064
00065
00066
00067 struct NodeInfo
00068 {
00069 NodeInfo(NodeId id) : id(id) { initial_pose_estimate.orientation.w = 1.0; }
00070 NodeInfo() : id(-1) {}
00071 NodeId id;
00072 geometry_msgs::Pose initial_pose_estimate;
00073 };
00074
00075
00076 struct EdgeInfo
00077 {
00078 EdgeInfo(EdgeId id, NodeId from, NodeId to, double length);
00079 EdgeInfo();
00080
00081
00082 const EdgeId id;
00083
00084
00085
00086
00087 const NodeId from, to;
00088
00089
00090 const double length;
00091 };
00092
00093
00094
00095 typedef Eigen3::aligned_allocator<pair<EdgeId, PoseConstraint> > Allocator;
00096 typedef map<EdgeId, PoseConstraint, std::less<EdgeId>, Allocator> PoseConstraintMap;
00097
00098
00099
00100 typedef adjacency_list<multisetS, listS, undirectedS, NodeInfo, EdgeInfo> PoseGraphAdjacencyList;
00101 typedef graph_traits<PoseGraphAdjacencyList>::edge_descriptor PoseGraphEdge;
00102 typedef graph_traits<PoseGraphAdjacencyList>::vertex_descriptor PoseGraphVertex;
00103
00104
00105
00106
00107
00108
00109
00110 class PoseGraphImpl
00111 {
00112 public:
00113
00114
00115
00116
00117
00118
00120 PoseGraphImpl ();
00121
00123 PoseGraphImpl (const PoseGraphImpl& g);
00124
00126 PoseGraphImpl& operator= (const PoseGraphImpl& g);
00127
00128
00129
00130
00131
00132
00136 NodeId addNode ();
00137
00141 void addNode (NodeId id);
00142
00149 EdgeId addEdge (NodeId from, NodeId to, const PoseConstraint& constraint);
00150
00158 void addEdge (NodeId from, NodeId to, const PoseConstraint& constraint, EdgeId id);
00159
00162 void setInitialPoseEstimate (NodeId n, const geometry_msgs::Pose& pose);
00163
00167 const geometry_msgs::Pose& getInitialPoseEstimate (NodeId n) const;
00168
00169
00170
00171
00172
00173
00175 set<NodeId> allNodes() const;
00176
00178 set<EdgeId> allEdges() const;
00179
00183 const PoseConstraint& getConstraint (EdgeId id) const;
00184
00187 double edgeLength (EdgeId id) const;
00188
00191 set<EdgeId> incidentEdges (NodeId n) const;
00192
00195 pair<NodeId, NodeId> incidentNodes (EdgeId e) const;
00196
00199 std::set<NodeId> neighbors (NodeId n) const;
00200
00202 bool nodeIdExists (NodeId id) const;
00203
00205 bool edgeIdExists (EdgeId id) const;
00206
00212 PoseGraph subgraph (const std::set<NodeId>& nodes) const;
00213
00219 geometry_msgs::Pose relativePose (NodeId n, NodeId ref) const;
00220
00223 NodeId otherNode (const NodeId n, const EdgeId e) const;
00224
00225
00226
00227
00228
00233 ShortestPathResult shortestPath(NodeId src, NodeId dest) const;
00234
00240 set<NodeId> nearbyNodes (NodeId src, double radius) const;
00241
00242
00243
00244
00245
00246
00249 void attachCloud (NodeId id, occupancy_grid_utils::LocalizedCloud::ConstPtr cloud);
00250
00254 occupancy_grid_utils::LocalizedCloud::ConstPtr getCloud (NodeId id) const;
00255
00258 bool hasCloud (NodeId id) const;
00259
00260
00261
00262
00263
00272 void attachScan (NodeId id, sensor_msgs::LaserScan::ConstPtr cloud);
00273
00280 sensor_msgs::LaserScanConstPtr getScan (NodeId id) const;
00281
00284 bool hasScan (NodeId id) const;
00285
00286
00287 private:
00288
00289
00290
00291
00292
00293
00294 typedef map<PoseGraphVertex, double> DistanceMap;
00295 typedef map<PoseGraphVertex, PoseGraphVertex> PredecessorMap;
00296 typedef pair<DistanceMap, PredecessorMap> DijkstraResult;
00297
00298
00299
00300
00301
00302
00303
00304 void initializeFrom (const PoseGraphImpl& g);
00305
00306
00307 PoseGraphVertex idVertex (NodeId id) const;
00308
00309
00310 PoseGraphEdge idEdge(EdgeId id) const;
00311
00312
00313 DijkstraResult dijkstra (const PoseGraphVertex& src) const;
00314
00315
00316 bool outsideRadius (NodeId n, double r, const DistanceMap& distances) const;
00317
00319 EdgeId shortestEdgeBetween (NodeId n1, NodeId n2) const;
00320
00321
00322
00323
00324
00325
00326 PoseGraphAdjacencyList graph_;
00327
00328
00329 NodeId next_node_id_;
00330
00331
00332 EdgeId next_edge_id_;
00333
00334
00335 map<NodeId, PoseGraphVertex> vertex_map_;
00336
00337
00338 map<EdgeId, PoseGraphEdge> edge_map_;
00339
00340
00341 PoseConstraintMap constraints_;
00342
00343
00344 map<PoseGraphVertex, occupancy_grid_utils::LocalizedCloud::ConstPtr> clouds_;
00345
00346
00347 map<PoseGraphVertex, sensor_msgs::LaserScan::ConstPtr> scans_;
00348 };
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 }
00365
00366
00367 #endif // POSE_GRAPH_POSE_GRAPH_H