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 
00032 
00033 
00034 
00035 #ifndef JSK_PCL_ROS_KINFU_H_
00036 #define JSK_PCL_ROS_KINFU_H_
00037 
00038 #include <pcl/console/parse.h>
00039 #include <pcl/gpu/kinfu_large_scale/kinfu.h>
00040 #include <pcl/gpu/kinfu_large_scale/marching_cubes.h>
00041 #include <pcl/gpu/kinfu_large_scale/raycaster.h>
00042 #include <pcl/gpu/containers/initialization.h>
00043 #include <pcl/surface/texture_mapping.h>
00044 #include <pcl/point_cloud.h>
00045 #include <pcl/point_types.h>
00046 #include <pcl/common/angles.h>
00047 
00048 #include <dynamic_reconfigure/server.h>
00049 #include <message_filters/subscriber.h>
00050 #include <message_filters/sync_policies/exact_time.h>
00051 #include <message_filters/sync_policies/approximate_time.h>
00052 #include <jsk_topic_tools/connection_based_nodelet.h>
00053 #include <jsk_recognition_utils/pcl_conversion_util.h>
00054 #include <pcl_conversions/pcl_conversions.h>
00055 #include <std_srvs/Empty.h>
00056 #include <sensor_msgs/Image.h>
00057 #include <sensor_msgs/PointCloud2.h>
00058 #include <jsk_rviz_plugins/OverlayText.h>
00059 #include <jsk_pcl_ros/tf_listener_singleton.h>
00060 #include <tf/transform_broadcaster.h>
00061 
00062 #include "jsk_pcl_ros/KinfuConfig.h"
00063 
00064 
00065 namespace pcl
00066 {
00067   namespace gpu
00068   {
00069     namespace kinfuLS
00070     {
00071       void paint3DView (const KinfuTracker::View& rgb24, KinfuTracker::View& view, float colors_weight = 0.5f);
00072     }
00073   }
00074 }
00075 
00076 namespace jsk_pcl_ros
00077 {
00078   class Kinfu: public jsk_topic_tools::ConnectionBasedNodelet
00079   {
00080   public:
00081     typedef message_filters::sync_policies::ExactTime<
00082       sensor_msgs::CameraInfo, sensor_msgs::Image> SyncPolicy;
00083     typedef message_filters::sync_policies::ApproximateTime<
00084       sensor_msgs::CameraInfo, sensor_msgs::Image, sensor_msgs::Image> SyncPolicyWithColor;
00085     typedef jsk_pcl_ros::KinfuConfig Config;
00086 
00087     Kinfu(): ConnectionBasedNodelet(), frame_idx_(0) {}
00088     ~Kinfu() {}
00089   protected:
00090     virtual void onInit();
00091     virtual void subscribe();
00092     virtual void unsubscribe();
00093 
00094     void initKinfu(const sensor_msgs::CameraInfo::ConstPtr& caminfo_msg);
00095     void update(const sensor_msgs::CameraInfo::ConstPtr& caminfo_msg,
00096                 const sensor_msgs::Image::ConstPtr& depth_msg);
00097     void update(const sensor_msgs::CameraInfo::ConstPtr& caminfo_msg,
00098                 const sensor_msgs::Image::ConstPtr& depth_msg,
00099                 const sensor_msgs::Image::ConstPtr& rgb_msg);
00100     bool resetCallback(std_srvs::Empty::Request& req, std_srvs::Empty::Response& res);
00101 
00102     boost::shared_ptr <dynamic_reconfigure::Server<Config> > srv_;
00103     virtual void configCallback(Config &config, uint32_t level);
00104 
00105     pcl::PolygonMesh createPolygonMesh();
00106     pcl::PolygonMesh createPolygonMesh(const jsk_recognition_msgs::BoundingBox& box_msg,
00107                                        const std::string& ground_frame_id);
00108     pcl::TextureMesh convertToTextureMesh(const pcl::PolygonMesh& triangles,
00109                                           const std::vector<cv::Mat> textures,
00110                                           pcl::texture_mapping::CameraVector cameras);
00111     bool saveMeshCallback(std_srvs::Empty::Request& req, std_srvs::Empty::Response& res);
00112     bool saveMeshWithContextCallback(
00113       jsk_recognition_msgs::SaveMesh::Request& req, jsk_recognition_msgs::SaveMesh::Response& res);
00114 
00115     boost::shared_ptr<pcl::gpu::kinfuLS::KinfuTracker> kinfu_;
00116     pcl::gpu::kinfuLS::MarchingCubes::Ptr marching_cubes_;
00117     pcl::gpu::kinfuLS::KinfuTracker::View colors_device_;
00118     pcl::gpu::kinfuLS::RayCaster::Ptr raycaster_;
00119     std::vector<cv::Mat> textures_;
00120     pcl::texture_mapping::CameraVector cameras_;
00121 
00122     int device_;
00123     bool auto_reset_;
00124     bool integrate_color_;
00125     bool slam_;
00126     std::string fixed_frame_id_;
00127     int n_textures_;
00128 
00129     int frame_idx_;
00130     std::string save_dir_;
00131 
00132     boost::mutex mutex_;
00133 
00134     boost::shared_ptr<tf::TransformListener> tf_listener_;
00135     Eigen::Affine3f odom_init_to_kinfu_origin_;
00136 
00137     message_filters::Subscriber<sensor_msgs::CameraInfo> sub_camera_info_;
00138     message_filters::Subscriber<sensor_msgs::Image> sub_depth_;
00139     message_filters::Subscriber<sensor_msgs::Image> sub_color_;
00140     boost::shared_ptr<message_filters::Synchronizer<SyncPolicy> > sync_;
00141     boost::shared_ptr<message_filters::Synchronizer<SyncPolicyWithColor> > sync_with_color_;
00142 
00143     ros::Publisher pub_camera_pose_;
00144     ros::Publisher pub_cloud_;
00145     ros::Publisher pub_depth_;
00146     ros::Publisher pub_rendered_image_;
00147     ros::Publisher pub_status_;
00148 
00149     tf::TransformBroadcaster tf_broadcaster_;
00150 
00151     ros::ServiceServer srv_reset_;
00152     ros::ServiceServer srv_save_mesh_;
00153     ros::ServiceServer srv_save_mesh_with_context_;
00154 
00155   private:
00156   };
00157 
00158 }  
00159 
00160 #endif  // JSK_PCL_ROS_KINFU_H_