openni_record_player_nodelet.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011 Willow Garage, Inc.
00005  *    Radu Bogdan Rusu <rusu@willowgarage.com>
00006  *    Suat Gedikli <gedikli@willowgarage.com>
00007  *    Patrick Mihelich <mihelich@willowgarage.com>
00008  *
00009  *  All rights reserved.
00010  *
00011  *  Redistribution and use in source and binary forms, with or without
00012  *  modification, are permitted provided that the following conditions
00013  *  are met:
00014  *
00015  *   * Redistributions of source code must retain the above copyright
00016  *     notice, this list of conditions and the following disclaimer.
00017  *   * Redistributions in binary form must reproduce the above
00018  *     copyright notice, this list of conditions and the following
00019  *     disclaimer in the documentation and/or other materials provided
00020  *     with the distribution.
00021  *   * Neither the name of Willow Garage, Inc. nor the names of its
00022  *     contributors may be used to endorse or promote products derived
00023  *     from this software without specific prior written permission.
00024  *
00025  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00026  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00027  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00028  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00029  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00030  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00031  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00032  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00033  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00034  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00035  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  *  POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  */
00039 #ifndef OPENNI_RECORD_PLAYER_NODELET_OPENNI_H_
00040 #define OPENNI_RECORD_PLAYER_NODELET_OPENNI_H_
00041 
00042 #include <nodelet/nodelet.h>
00043 #include <boost/shared_ptr.hpp>
00044 #include <dynamic_reconfigure/server.h>
00045 #include "semanticmodel/OpenNIConfig.h"
00046 #include <image_transport/image_transport.h>
00047 #include <string>
00048 #include <message_filters/synchronizer.h>
00049 #include <message_filters/subscriber.h>
00050 #include <message_filters/sync_policies/approximate_time.h>
00051 #include <Eigen/Core>
00052 #include <pcl/PointIndices.h>
00053 
00054 namespace openni_camera
00055 {
00057   class OpenNIRecordPlayerNodelet : public nodelet::Nodelet
00058   {
00059     public:
00060       virtual ~OpenNIRecordPlayerNodelet ();
00061     private:
00062       typedef semanticmodel::OpenNIConfig Config;
00063       typedef dynamic_reconfigure::Server<Config> ReconfigureServer;
00064       typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::Image> SyncPolicy;
00065       typedef message_filters::Synchronizer<SyncPolicy> Synchronizer;
00066 
00068       virtual void onInit ();
00069 
00070       void configCallback (Config &config, uint32_t level);
00071 
00072       // callback methods
00073       void imageCallback(const sensor_msgs::ImageConstPtr& img_msg);
00074       void depthCallback(const sensor_msgs::ImageConstPtr& depth_msg);
00075       void subscriberChangedEvent ();
00076 
00077       // helper methods
00078       inline bool isImageStreamRequired() const;
00079       inline bool isDepthStreamRequired() const;
00080                         
00081                         // subscribers
00082                         image_transport::Subscriber img_sub_;
00083                         image_transport::Subscriber depth_sub_;
00084 
00085       // published topics
00086       image_transport::Publisher pub_depth_image_;
00087       ros::Publisher pub_disparity_, pub_point_cloud_, pub_point_cloud_rgb_;
00088       ros::Publisher pub_rgb_cam_info_, pub_depth_cam_info_;
00090       ros::Subscriber sub_mask_indices_;
00091       // Approximate synchronization for XYZRGB point clouds.
00092       boost::shared_ptr<Synchronizer> depth_rgb_sync_;
00093 
00094                         sensor_msgs::CameraInfoPtr fillCameraInfo(const std_msgs::Header &header, unsigned int width, unsigned int height);
00095       // publish methods
00096       void publishRgbImage (const sensor_msgs::ImageConstPtr& img_msg) const;
00097       void publishGrayImage (const sensor_msgs::ImageConstPtr& img_msg) const;
00098       void publishDepthImage (const sensor_msgs::ImageConstPtr& depth_msg) const;
00099       void publishDisparity (const sensor_msgs::ImageConstPtr& depth_msg) const;
00100       void publishXYZPointCloud (const sensor_msgs::ImageConstPtr& depth_msg) const;
00101       void publishXYZRGBPointCloud (const sensor_msgs::ImageConstPtr& depth_msg, const sensor_msgs::ImageConstPtr& rgb_msg) const;
00102 
00104       void maskIndicesCb(const pcl::PointIndicesConstPtr& indices);
00105 
00107       boost::shared_ptr<ReconfigureServer> reconfigure_server_;
00108       Config config_;
00109       boost::recursive_mutex reconfigure_mutex_;
00110       //boost::mutex depth_mutex_;
00111       //boost::mutex image_mutex_;
00112 
00114       bool generate_camera_info_;
00116       bool use_indices_;
00118       std::vector<int32_t> mask_indices_;
00119     public:
00120       EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
00121   };
00122 
00123   bool OpenNIRecordPlayerNodelet::isImageStreamRequired() const
00124   {
00125     return (pub_point_cloud_rgb_.getNumSubscribers() > 0 );
00126   }
00127 
00128   bool OpenNIRecordPlayerNodelet::isDepthStreamRequired() const
00129   {
00130     return (pub_depth_image_.getNumSubscribers()     > 0 ||
00131             pub_disparity_.getNumSubscribers()       > 0 ||
00132             pub_point_cloud_.getNumSubscribers()     > 0 ||
00133             pub_point_cloud_rgb_.getNumSubscribers() > 0 );
00134   }
00135 
00136 }
00137 #endif  //#ifndef OPENNI_NODELET_RECORD_PLAYER_OPENNI_H_


semanticmodel
Author(s): Julian ("Mac") Mason
autogenerated on Thu Dec 12 2013 12:39:10