ShapeReconstructionNode.h
Go to the documentation of this file.
00001 /*
00002  * ShapeReconstructionNode.h
00003  *
00004  *      Author: roberto
00005  *
00006  * This is a modified implementation of the method for online estimation of kinematic structures described in our paper
00007  * "Online Interactive Perception of Articulated Objects with Multi-Level Recursive Estimation Based on Task-Specific Priors"
00008  * (Martín-Martín and Brock, 2014) and the extension to segment, reconstruct and track shapes introduced in our paper
00009  * "An Integrated Approach to Visual Perception of Articulated Objects" (Martín-Martín, Höfer and Brock, 2016)
00010  * This implementation can be used to reproduce the results of the paper and to be applied to new research.
00011  * The implementation allows also to be extended to perceive different information/models or to use additional sources of information.
00012  * A detail explanation of the method and the system can be found in our paper.
00013  *
00014  * If you are using this implementation in your research, please consider citing our work:
00015  *
00016 @inproceedings{martinmartin_ip_iros_2014,
00017 Title = {Online Interactive Perception of Articulated Objects with Multi-Level Recursive Estimation Based on Task-Specific Priors},
00018 Author = {Roberto {Mart\'in-Mart\'in} and Oliver Brock},
00019 Booktitle = {Proceedings of the IEEE/RSJ International Conference on Intelligent Robots and Systems},
00020 Pages = {2494-2501},
00021 Year = {2014},
00022 Location = {Chicago, Illinois, USA},
00023 Note = {http://www.robotics.tu-berlin.de/fileadmin/fg170/Publikationen_pdf/martinmartin_ip_iros_2014.pdf},
00024 Url = {http://www.robotics.tu-berlin.de/fileadmin/fg170/Publikationen_pdf/martinmartin_ip_iros_2014.pdf},
00025 Projectname = {Interactive Perception}
00026 }
00027 
00028 @inproceedings{martinmartin_hoefer_iros_2016,
00029 Title = {An Integrated Approach to Visual Perception of Articulated Objects},
00030 Author = {Roberto {Mart\'{i}n-Mart\'{i}n} and Sebastian H\"ofer and Oliver Brock},
00031 Booktitle = {Proceedings of the IEEE International Conference on Robotics and Automation},
00032 Pages = {5091 - 5097},
00033 Year = {2016},
00034 Doi = {10.1109/ICRA.2016.7487714},
00035 Location = {Stockholm, Sweden},
00036 Month = {05},
00037 Note = {http://www.redaktion.tu-berlin.de/fileadmin/fg170/Publikationen_pdf/martin_hoefer_15_iros_sr_opt.pdf},
00038 Url = {http://www.redaktion.tu-berlin.de/fileadmin/fg170/Publikationen_pdf/martin_hoefer_15_iros_sr_opt.pdf},
00039 Url2 = {http://ieeexplore.ieee.org/xpl/articleDetails.jsp?tp=&arnumber=7487714},
00040 Projectname = {Interactive Perception}
00041 }
00042  * If you have questions or suggestions, contact us:
00043  * roberto.martinmartin@tu-berlin.de
00044  *
00045  * Enjoy!
00046  */
00047 
00048 #ifndef SHAPE_RECONSTRUCTION_NODE_H_
00049 #define SHAPE_RECONSTRUCTION_NODE_H_
00050 
00051 #include <ros/ros.h>
00052 #include <ros/callback_queue.h>
00053 #include <ros/subscriber.h>
00054 #include <image_transport/image_transport.h>
00055 #include <message_filters/subscriber.h>
00056 #include <message_filters/time_synchronizer.h>
00057 #include <message_filters/sync_policies/approximate_time.h>
00058 #include <sensor_msgs/PointCloud2.h>
00059 #include <sensor_msgs/Image.h>
00060 #include <std_msgs/Empty.h>
00061 
00062 #include <rosbag/bag.h>
00063 #include <tf/tf.h>
00064 
00065 #include "shape_reconstruction/ShapeReconstructionNode.h"
00066 #include "shape_reconstruction/ShapeReconstruction.h"
00067 
00068 #include <boost/thread.hpp>
00069 
00070 #include <omip_common/OMIPTypeDefs.h>
00071 
00072 // Dynamic reconfigure includes.
00073 #include <dynamic_reconfigure/server.h>
00074 
00075 #include <shape_reconstruction/generate_meshes.h>
00076 
00077 #include <pcl_conversions/pcl_conversions.h>
00078 
00079 #include <omip_common/OMIPTypeDefs.h>
00080 
00081 //ROS and OpenCV
00082 #include <opencv2/core/core.hpp>
00083 #include <camera_info_manager/camera_info_manager.h>
00084 
00085 #include <pcl/range_image/range_image_planar.h>
00086 #include <pcl/filters/extract_indices.h>
00087 #include <pcl/common/transforms.h>
00088 #include <pcl/search/search.h>
00089 #include <pcl/search/organized.h>
00090 #include <pcl/search/kdtree.h>
00091 #include <pcl/filters/extract_indices.h>
00092 #include <pcl/filters/voxel_grid.h>
00093 #include <pcl/kdtree/kdtree_flann.h>
00094 
00095 #include <omip_common/OMIPUtils.h>
00096 
00097 #include <pcl/filters/radius_outlier_removal.h>
00098 
00099 #include <pcl/filters/approximate_voxel_grid.h>
00100 
00101 #include <pcl/features/normal_3d_omp.h>
00102 #include <pcl/point_types.h>
00103 #include <pcl/io/pcd_io.h>
00104 #include <pcl/kdtree/kdtree_flann.h>
00105 #include <pcl/features/normal_3d.h>
00106 #include <pcl/surface/gp3.h>
00107 #include <pcl/io/vtk_lib_io.h>
00108 
00109 #include <pcl/segmentation/supervoxel_clustering.h>
00110 
00111 #include <boost/circular_buffer.hpp>
00112 
00113 #include "shape_reconstruction/SRUtils.h"
00114 
00115 #include <omip_msgs/ShapeModels.h>
00116 
00117 namespace omip
00118 {
00119 
00120 class ShapeReconstructionNode
00121 {
00122     // Policies to synchorize point clouds, and the RBP from the RBT
00123     typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::PointCloud2, omip::rbt_state_t> SRSyncPolicy;
00124 
00125     // Policies to synchorize point clouds, and the RBP and clustered features from the RBT
00126     typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::PointCloud2, omip::rbt_state_t, rbt_measurement_ros_t> SRSyncPolicyWithClusteredFeatures;
00127 
00128     typedef std::map<omip::RB_id_t, omip::ShapeReconstructionPtr > shape_reconstructors_map_t;
00129 
00130 public:
00131 
00135     ShapeReconstructionNode();
00136 
00140     virtual ~ShapeReconstructionNode();
00141 
00142     virtual void measurementCallbackWithClusteredFeatures(const sensor_msgs::PointCloud2ConstPtr &pc_msg,
00143                                                                            const boost::shared_ptr<omip::rbt_state_t const> &poses_and_vels,
00144                                                                            const sensor_msgs::PointCloud2ConstPtr &features_pc);
00145 
00146     virtual void CameraInfoCallback(const sensor_msgs::CameraInfoConstPtr &ci_msg);
00147 
00148     virtual void ReadRosBag();
00149 
00150     virtual bool generateMeshes(shape_reconstruction::generate_meshes::Request& request, shape_reconstruction::generate_meshes::Response& response);
00151 
00152     virtual void setSVVoxelResolution(double voxel_resolution) {
00153         _voxel_resolution = voxel_resolution;
00154     }
00155 
00156     virtual void setSVSeedResolution(double seed_resolution) {
00157         _seed_resolution = seed_resolution;
00158     }
00159 
00160     virtual void setSVColorImportance(double color_importance) {
00161         _color_importance = color_importance;
00162     }
00163 
00164     virtual void setSVSpatialImportance(double spatial_importance) {
00165         _spatial_importance = spatial_importance;
00166     }
00167 
00168     virtual void setSVNormalImportance(double normal_importance) {
00169         _normal_importance = normal_importance;
00170     }
00171 
00172     virtual void setSVVisualization(bool visualization_sv) {
00173         _visualization_sv = visualization_sv;
00174     }
00175 
00176     virtual bool isActive() const {
00177         return _active;
00178     }
00179 
00180     virtual void TrackerQuitCallback(const std_msgs::EmptyConstPtr &empty);
00181 
00182 protected:
00183 
00184     virtual void _CollectAndPublishShapeModels();
00185 
00186     virtual void _GenerateMesh(const omip::SRPointCloud::Ptr& pc_source, std::string shape_file_prefix);
00187 
00188     virtual void _InitResultRosbag();
00189 
00190     virtual void _AdvanceFeatureTracker();
00191 
00192     virtual void _EstimateSupervoxels();
00193 
00194     omip::ShapeReconstructionPtr _createNewShapeReconstruction();
00195 
00196     bool                                                                        _active;
00197 
00198     int                                                                         _frame_ctr;
00199     std::map<omip::RB_id_t,omip::ShapeReconstructionPtr >                       _rb_shapes;
00200     // maximum number of rigid bodies to be tracked (default: 100)
00201     int                                                                         _max_rb;
00202 
00203     double                                                                      _processing_interval;
00204 
00205     bool                                                                        _detect_static_environment;
00206     bool                                                                        _publish_shapes_in_each_frame;
00207     bool                                                                        _refine_shapes_in_each_frame;
00208     ros::Time                                                                   _previous_measurement_time;
00209     ros::Time                                                                   _current_measurement_time;
00210     ros::NodeHandle                                                             _node_handle;
00211     ros::Publisher                                                              _rbshapes_combined_publisher;
00212 
00213     ros::Publisher                                                              _static_environment_ext_d_and_c_pub;
00214     ros::Publisher                                                              _advance_feature_tracker_pub;
00215     ros::Subscriber                                                             _node_quit_subscriber;
00216     message_filters::Subscriber<sensor_msgs::PointCloud2>                       _rgbd_pc_subscriber;
00217     message_filters::Subscriber<omip::rbt_state_t>                              _poses_and_vels_subscriber;
00218     message_filters::Subscriber<sensor_msgs::PointCloud2>                           _clustered_feats_subscriber;
00219     message_filters::Synchronizer<SRSyncPolicy>*                                _synchronizer;
00220     message_filters::Synchronizer<SRSyncPolicyWithClusteredFeatures>*           _synchronizer_with_clustered_feats;
00221     ros::ServiceServer                                                          _mesh_generator_srv;
00222 
00223     SRPointCloud::Ptr                                                           _current_pc;
00224     SRPointCloud::Ptr _current_pc_down;
00225     SRPointCloud::Ptr                                                           _current_pc_without_nans;
00226 
00227     std::vector<int> _not_nan_indices;
00228 
00229     SRPointCloud::Ptr                                                           _static_env_ext_d_and_c_in_current_frame;
00230     pcl::search::Search<omip::SRPoint>::Ptr                                     _set_knn_ptr;
00231     // Triangular mesh generation
00232     pcl::NormalEstimationOMP<omip::SRPoint, pcl::Normal>::Ptr                   _se_normal_estimator_ptr;
00233     pcl::PointCloud<pcl::Normal>::Ptr                                           _se_estimated_normals_pc_ptr;
00234     pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr                                _se_position_color_and_normals_pc_ptr;
00235     pcl::search::KdTree<omip::SRPoint>::Ptr                                     _se_tree_for_normal_estimation_ptr;
00236     pcl::search::KdTree<pcl::PointXYZRGBNormal>::Ptr                            _se_tree_for_triangulation_ptr;
00237     pcl::GreedyProjectionTriangulation<pcl::PointXYZRGBNormal>::Ptr             _se_greedy_projection_triangulator_ptr;
00238     pcl::PolygonMesh::Ptr                                                       _se_triangulated_mesh_ptr;
00239     vtkSmartPointer<vtkPolyData>                                                _se_polygon_data_ptr;
00240     vtkSmartPointer<vtkSTLWriter>                                               _se_polygon_writer_ptr;
00241 
00242     bool                                                                        _record_result_bag;
00243     std::string                                                                 _result_bag_path;
00244     rosbag::Bag                                                                 _result_bag;
00245     rosbag::Bag                                                                 _video_bag;
00246     bool                                                                        _result_bag_open;
00247 
00248     bool                                                                        _manually_advance_after_processing;
00249 
00250     // Supervoxels
00251     double                                                               _voxel_resolution;
00252     double                                                               _seed_resolution;
00253     double                                                               _color_importance;
00254     double                                                               _spatial_importance;
00255     double                                                               _normal_importance;
00256     boost::shared_ptr<pcl::SupervoxelClustering<SRPoint> >              _supervoxelizer;
00257     std::map <uint32_t, pcl::Supervoxel<SRPoint>::Ptr >                 _supervoxel_clusters;
00258 
00259     bool                                                                _visualization_sv;
00260     bool                                                                _sv_estimated;
00261     bool                                                                _estimate_sv;
00262 
00263     ros::Publisher                                                              _shape_models_ext_d_and_c_pub;
00264 
00265     ros::Subscriber                                                             _ci_sub;
00266     sensor_msgs::CameraInfo                                                     _ci;
00267 
00268     pcl::PointCloud<pcl::PointXYZL>::Ptr                                        _clustered_feats;
00269 
00270     pcl::ExtractIndices<pcl::PointXYZL>                                                _extractor_cf;
00271 
00272     template<class T>
00273     bool getROSParameter(std::string param_name, T & param_container)
00274     {
00275         if (!(this->_node_handle.getParam(param_name, param_container)))
00276         {
00277             ROS_ERROR_NAMED("ShapeReconstructionNode.getROSParameter", "The parameter %s can not be found.", param_name.c_str());
00278             throw(std::string("[ShapeReconstructionNode.getROSParameter] The parameter can not be found. Parameter name: ") + param_name);
00279             return false;
00280         }
00281         else
00282             return true;
00283     }
00284 };
00285 }
00286 
00287 #endif /* FEATURE_TRACKER_NODE_H_ */
00288 


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:35:22