keyframe_mapper.h
Go to the documentation of this file.
00001 
00024 #ifndef CCNY_RGBD_KEYFRAME_MAPPER_H
00025 #define CCNY_RGBD_KEYFRAME_MAPPER_H
00026 
00027 #include <iostream>
00028 #include <fstream>
00029 #include <ros/ros.h>
00030 #include <ros/publisher.h>
00031 #include <pcl/point_cloud.h>
00032 #include <pcl_ros/point_cloud.h>
00033 #include <pcl_ros/transforms.h>
00034 #include <pcl/filters/passthrough.h>
00035 #include <tf/transform_listener.h>
00036 #include <visualization_msgs/Marker.h>
00037 #include <boost/regex.hpp>
00038 #include <boost/filesystem.hpp>
00039 #include <octomap/octomap.h>
00040 #include <octomap/OcTree.h>
00041 #include <octomap/ColorOcTree.h>
00042 #include <rgbdtools/rgbdtools.h>
00043 
00044 #include "ccny_rgbd/types.h"
00045 #include "ccny_rgbd/util.h"
00046 #include "ccny_rgbd/GenerateGraph.h"
00047 #include "ccny_rgbd/SolveGraph.h"
00048 #include "ccny_rgbd/AddManualKeyframe.h"
00049 #include "ccny_rgbd/PublishKeyframe.h"
00050 #include "ccny_rgbd/PublishKeyframes.h"
00051 #include "ccny_rgbd/Save.h"
00052 #include "ccny_rgbd/Load.h"
00053 
00054 namespace ccny_rgbd {
00055 
00069 class KeyframeMapper
00070 {
00071   public:
00072 
00077     KeyframeMapper(const ros::NodeHandle& nh, 
00078                    const ros::NodeHandle& nh_private);
00079     
00082     virtual ~KeyframeMapper();
00083 
00086     void initParams();
00087 
00102     bool publishKeyframesSrvCallback(
00103       PublishKeyframes::Request& request,
00104       PublishKeyframes::Response& response);
00105 
00110     bool publishKeyframeSrvCallback(
00111       PublishKeyframe::Request& request,
00112       PublishKeyframe::Response& response);
00113 
00119     bool saveKeyframesSrvCallback(
00120       Save::Request& request,
00121       Save::Response& response);
00122 
00131     bool savePcdMapSrvCallback(
00132       Save::Request& request,
00133       Save::Response& response);
00134     
00143     bool saveOctomapSrvCallback(
00144       Save::Request& request,
00145       Save::Response& response);
00146     
00152     bool loadKeyframesSrvCallback(
00153       Load::Request& request,
00154       Load::Response& response);
00155 
00158     bool addManualKeyframeSrvCallback(
00159       AddManualKeyframe::Request& request,
00160       AddManualKeyframe::Response& response);
00161     
00165      bool generateGraphSrvCallback(
00166       GenerateGraph::Request& request,
00167       GenerateGraph::Response& response);
00168 
00174     bool solveGraphSrvCallback(
00175       SolveGraph::Request& request,
00176       SolveGraph::Response& response);
00177     
00178   protected:
00179 
00180     ros::NodeHandle nh_;          
00181     ros::NodeHandle nh_private_;  
00182     
00183     std::string fixed_frame_;     
00184     
00185     int queue_size_;  
00186     
00187     double max_range_;  
00188     double max_stdev_;  
00189 
00190     rgbdtools::KeyframeVector keyframes_;    
00191     
00198     virtual void RGBDCallback(const ImageMsg::ConstPtr& rgb_msg,
00199                               const ImageMsg::ConstPtr& depth_msg,
00200                               const CameraInfoMsg::ConstPtr& info_msg);
00201 
00202   private:
00203 
00204     ros::Publisher keyframes_pub_;    
00205     ros::Publisher poses_pub_;        
00206     ros::Publisher kf_assoc_pub_;     
00207     ros::Publisher path_pub_;         
00208     
00210     ros::ServiceServer generate_graph_service_;
00211     
00213     ros::ServiceServer solve_graph_service_;   
00214     
00216     ros::ServiceServer pub_keyframe_service_;
00217     
00219     ros::ServiceServer pub_keyframes_service_;
00220     
00222     ros::ServiceServer save_kf_service_;
00223     
00225     ros::ServiceServer save_pcd_map_service_;
00226     
00228     ros::ServiceServer save_octomap_service_;
00229     
00231     ros::ServiceServer load_kf_service_;
00232     
00234     ros::ServiceServer add_manual_keyframe_service_;
00235 
00236     tf::TransformListener tf_listener_; 
00237 
00239     boost::shared_ptr<ImageTransport> rgb_it_;
00240     
00242     boost::shared_ptr<ImageTransport> depth_it_;
00243     
00245     boost::shared_ptr<RGBDSynchronizer3> sync_;
00246           
00248     ImageSubFilter      sub_rgb_;
00249     
00251     ImageSubFilter      sub_depth_;  
00252    
00254     CameraInfoSubFilter sub_info_;
00255     
00256     // params
00257     double pcd_map_res_; 
00258     double octomap_res_;  
00259     double kf_dist_eps_;  
00260     double kf_angle_eps_; 
00261     bool octomap_with_color_; 
00262     double max_map_z_;   
00263           
00264     // state vars
00265     bool manual_add_;   
00266 
00267     int rgbd_frame_index_;
00268 
00269     rgbdtools::KeyframeGraphDetector graph_detector_;  
00270     rgbdtools::KeyframeGraphSolverG2O graph_solver_;    
00271     rgbdtools::KeyframeGraphSolverISAM solver_;
00272     rgbdtools::KeyframeAssociationVector associations_; 
00273     
00274     PathMsg path_msg_;    
00275     
00283     bool processFrame(const rgbdtools::RGBDFrame& frame, const AffineTransform& pose);
00284     
00290     void addKeyframe(const rgbdtools::RGBDFrame& frame, const AffineTransform& pose);
00291 
00295     void publishKeyframeData(int i);
00296     
00300     void publishKeyframePose(int i);
00301         
00304     void publishKeyframeAssociations();
00305     
00308     void publishKeyframePoses();
00309     
00312     void publishPath();
00313     
00319     bool savePcdMap(const std::string& path);
00320            
00324     void buildPcdMap(PointCloudT& map_cloud);
00325     void buildFullCloud(PointCloudT& map_cloud);
00326 
00332     bool saveOctomap(const std::string& path);
00333     
00337     void buildOctomap(octomap::OcTree& tree);
00338     
00342     void buildColorOctomap(octomap::ColorOcTree& tree);
00343         
00348     static inline octomap::pose6d poseTfToOctomap(
00349       const tf::Pose& poseTf)
00350     {
00351       return octomap::pose6d(
00352               pointTfToOctomap(poseTf.getOrigin()),
00353               quaternionTfToOctomap(poseTf.getRotation()));
00354     }
00355    
00360     static inline octomap::point3d pointTfToOctomap(
00361       const tf::Point& ptTf)
00362     {
00363       return octomap::point3d(ptTf.x(), ptTf.y(), ptTf.z());
00364     }
00365    
00370     static inline octomath::Quaternion quaternionTfToOctomap(
00371       const tf::Quaternion& qTf)
00372     {
00373       return octomath::Quaternion(qTf.w(), qTf.x(), qTf.y(), qTf.z());
00374     }
00375     
00376     bool savePath(const std::string& filepath);
00377     bool savePathTUMFormat(const std::string& filepath);
00378     
00379     bool loadPath(const std::string& filepath);
00380     
00381     void updatePathFromKeyframePoses();
00382 };
00383 
00384 } // namespace ccny_rgbd
00385 
00386 #endif // CCNY_RGBD_KEYFRAME_MAPPER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


ccny_rgbd
Author(s): Ivan Dryanovski
autogenerated on Tue Aug 27 2013 10:34:02