pose_graph_impl.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
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  * Graph-related typedefs
00064  ************************************************************/
00065 
00066 // Data structure containing info about a node in the pose graph
00067 struct NodeInfo
00068 {
00069   NodeInfo(NodeId id) : id(id) { initial_pose_estimate.orientation.w = 1.0; }
00070   NodeInfo() : id(-1) {} // Only used temporarily by boost graph operations
00071   NodeId id;
00072   geometry_msgs::Pose initial_pose_estimate;
00073 };
00074 
00075 // Data structure containing info about an edge in the pose graph
00076 struct EdgeInfo
00077 {
00078   EdgeInfo(EdgeId id, NodeId from, NodeId to, double length);
00079   EdgeInfo(); // Only used temporarily by boost graph operations
00080 
00081   // Unique id for this edge
00082   const EdgeId id;
00083 
00084   // Edges are undirected in the underlying graph, but we distinguish
00085   // between the from and to node ids here.  The constraint attached
00086   // to an edge specifies the pose of the to node in terms of the from node.
00087   const NodeId from, to;
00088 
00089   // Expectation of length of edge (given Gaussian pose constraint)
00090   const double length;
00091 };
00092 
00093 
00094 // Map from edge id to pose constraint
00095 typedef Eigen3::aligned_allocator<pair<EdgeId, PoseConstraint> > Allocator;
00096 typedef map<EdgeId, PoseConstraint, std::less<EdgeId>, Allocator> PoseConstraintMap;
00097 
00098 
00099 // boost graph and related types
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  * Main implementation data structure
00107  ************************************************************/
00108 
00109 
00110 class PoseGraphImpl
00111 {
00112 public:
00113 
00114 
00115   /****************************************
00116    * Creation
00117    ****************************************/
00118   
00120   PoseGraphImpl ();
00121 
00123   PoseGraphImpl (const PoseGraphImpl& g);
00124 
00126   PoseGraphImpl& operator= (const PoseGraphImpl& g);
00127   
00128   
00129   /****************************************
00130    * Basic graph modification ops
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    * Basic const ops
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    * Graph search
00227    ****************************************/
00228 
00233   ShortestPathResult shortestPath(NodeId src, NodeId dest) const;
00234 
00240   set<NodeId> nearbyNodes (NodeId src, double radius) const;
00241 
00242 
00243   /****************************************
00244    * Point clouds attached to nodes
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    * Laser scans attached to nodes
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    * Typedefs
00292    ******************************/
00293 
00294   typedef map<PoseGraphVertex, double> DistanceMap;
00295   typedef map<PoseGraphVertex, PoseGraphVertex> PredecessorMap;
00296   typedef pair<DistanceMap, PredecessorMap> DijkstraResult;
00297 
00298   
00299   /******************************
00300    * Private methods
00301    ******************************/
00302 
00303   // Initialization, used in copy constructor and assignment
00304   void initializeFrom (const PoseGraphImpl& g);
00305 
00306   // Gets vertex corresponding to a node id
00307   PoseGraphVertex idVertex (NodeId id) const;
00308 
00309   // Gets edge corresponding to an edge id
00310   PoseGraphEdge idEdge(EdgeId id) const;
00311 
00312   // Wraps call to dijkstra_shortest_paths
00313   DijkstraResult dijkstra (const PoseGraphVertex& src) const;
00314 
00315   // Checks if a node's distance in a distance map is above a threshold
00316   bool outsideRadius (NodeId n, double r, const DistanceMap& distances) const;
00317 
00319   EdgeId shortestEdgeBetween (NodeId n1, NodeId n2) const;
00320 
00321   /******************************
00322    * Fields
00323    ******************************/
00324 
00325   // The underlying boost graph 
00326   PoseGraphAdjacencyList graph_;
00327 
00328   // Id that will be used for the next new node
00329   NodeId next_node_id_;
00330 
00331   // Id that will be used for the next new edge
00332   EdgeId next_edge_id_;
00333 
00334   // Map from NodeId to Vertex
00335   map<NodeId, PoseGraphVertex> vertex_map_;
00336 
00337   // Map from EdgeId to Edge
00338   map<EdgeId, PoseGraphEdge> edge_map_;
00339 
00340   // Map from EdgeId to PoseConstraint
00341   PoseConstraintMap constraints_;
00342 
00343   // Map from vertex to point cloud
00344   map<PoseGraphVertex, occupancy_grid_utils::LocalizedCloud::ConstPtr> clouds_;
00345 
00346   // Map from vertex to laser scan
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 } //namespace pose_graph
00365 
00366 
00367 #endif // POSE_GRAPH_POSE_GRAPH_H


pose_graph
Author(s): Bhaskara Marthi
autogenerated on Tue Jan 7 2014 11:17:15