line_segment_collector.h
Go to the documentation of this file.
00001 // -*- mode: c++ -*-
00002 /*********************************************************************
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2014, JSK Lab
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/o2r other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the JSK Lab nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *********************************************************************/
00035 
00037 // the implementation is based on
00038 // Line segment-based fast 3D plane extraction using nodding 2D laser rangender
00039 //   Su-Yong An, Lae-Kyoung Lee and Se-Young Oh,
00040 //   ,Robotica / FirstView Article / October 2014, pp 1 - 24
00042 #ifndef JSK_PCL_ROS_LINE_SEGMENT_COLLECTOR_H_
00043 #define JSK_PCL_ROS_LINE_SEGMENT_COLLECTOR_H_
00044 
00045 #include <jsk_topic_tools/diagnostic_nodelet.h>
00046 #include <jsk_recognition_msgs/ClusterPointIndices.h>
00047 #include <jsk_recognition_msgs/ModelCoefficientsArray.h>
00048 #include <sensor_msgs/JointState.h>
00049 #include "jsk_pcl_ros/line_segment_detector.h"
00050 #include <jsk_topic_tools/time_accumulator.h>
00051 #include <jsk_pcl_ros/LineSegmentCollectorConfig.h>
00052 #include <dynamic_reconfigure/server.h>
00053 #include "jsk_recognition_utils/geo_util.h"
00054 #include <jsk_recognition_msgs/PolygonArray.h>
00055 #include <jsk_recognition_msgs/TimeRange.h>
00056 
00057 namespace jsk_pcl_ros
00058 {
00059 
00060   class LineSegmentCluster
00061   {
00062   public:
00063     typedef boost::shared_ptr<LineSegmentCluster> Ptr;
00064     LineSegmentCluster();
00065     virtual ~LineSegmentCluster() { };
00066     
00068     // update delta_ by EWMA(exponentially weighted moving agerage)
00070     virtual void addLineSegmentEWMA(LineSegment::Ptr segment, const double tau);
00071     virtual Eigen::Vector3f getDelta() { return delta_; }
00072     virtual pcl::PointCloud<pcl::PointXYZ>::Ptr getPoints();
00073     virtual pcl::PointCloud<pcl::PointXYZ>::Ptr getRawPoints();
00074     virtual void removeBefore(const ros::Time& stamp);
00075     virtual bool isEmpty();
00076   protected:
00077     Eigen::Vector3f delta_;
00078     std::vector<LineSegment::Ptr> segments_;
00079     pcl::PointCloud<pcl::PointXYZ>::Ptr points_;
00080     pcl::PointCloud<pcl::PointXYZ>::Ptr raw_points_;
00081   private:
00082     
00083   };
00084   
00085   template <class T>
00086   class TimeStampedVector: public std::vector<T>
00087   {
00088   public:
00089     typedef typename std::vector<T>::iterator iterator;
00090     void removeBefore(const ros::Time& stamp)
00091     {
00092       for (iterator it = std::vector<T>::begin();
00093            it != std::vector<T>::end();) {
00094         if (((*it)->header.stamp - stamp) < ros::Duration(0.0)) {
00095           it = this->erase(it);
00096         }
00097         else {
00098           ++it;
00099         }
00100       }
00101     }
00102   protected:
00103   private:
00104   };
00105   
00106   class LineSegmentCollector: public jsk_topic_tools::DiagnosticNodelet
00107   {
00108   public:
00109     LineSegmentCollector(): DiagnosticNodelet("LineSegmentCollector") { }
00110     typedef message_filters::sync_policies::ExactTime<
00111       sensor_msgs::PointCloud2,
00112       jsk_recognition_msgs::ClusterPointIndices,
00113       jsk_recognition_msgs::ModelCoefficientsArray> SyncPolicy;
00114     enum RotateType {
00115       ROTATION_SPINDLE, ROTATION_TILT, ROTATION_TILT_TWO_WAY
00116     };
00117     typedef jsk_pcl_ros::LineSegmentCollectorConfig Config;
00118   protected:
00120     // methods
00122     virtual void onInit();
00123     virtual void collectFromBuffers(const std_msgs::Header& header,
00124                                     std::vector<LineSegment::Ptr> new_segments);
00125     virtual void collect(
00126       const sensor_msgs::PointCloud2::ConstPtr& cloud_msg,
00127       const jsk_recognition_msgs::ClusterPointIndices::ConstPtr& indices_msg,
00128       const jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr& coefficients_msg);
00129     virtual void subscribe();
00130     virtual void unsubscribe();
00131     virtual void updateDiagnostic(
00132       diagnostic_updater::DiagnosticStatusWrapper &stat);
00133     virtual void triggerCallback(
00134       const jsk_recognition_msgs::TimeRange::ConstPtr& trigger);
00135     virtual void cleanupBuffers(
00136       const ros::Time& stamp);
00137     virtual void publishBeforePlaneSegmentation(
00138       const std_msgs::Header& header,
00139       const pcl::PointCloud<pcl::PointXYZ>::Ptr cloud,
00140       const std::vector<pcl::PointIndices::Ptr>& connected_indices);
00141     virtual LineSegmentCluster::Ptr lookupNearestSegment(
00142       LineSegment::Ptr segment);
00143     virtual void publishResult(
00144       const std_msgs::Header& header,
00145       pcl::PointCloud<pcl::PointXYZ>::Ptr cloud,
00146       std::vector<pcl::ModelCoefficients::Ptr> all_coefficients,
00147       std::vector<pcl::PointIndices::Ptr> all_indices);
00148     virtual void configCallback(Config &config, uint32_t level);
00150     // ROS variables
00152     boost::mutex mutex_;
00153     boost::shared_ptr<message_filters::Synchronizer<SyncPolicy> >sync_;
00154     message_filters::Subscriber<sensor_msgs::PointCloud2> sub_input_;
00155     message_filters::Subscriber<jsk_recognition_msgs::ClusterPointIndices> sub_indices_;
00156     message_filters::Subscriber<jsk_recognition_msgs::ModelCoefficientsArray> sub_coefficients_;
00157     ros::Publisher pub_point_cloud_;
00158     ros::Publisher pub_inliers_;
00159     ros::Publisher pub_coefficients_;
00160     ros::Publisher pub_polygons_;
00161     ros::Publisher debug_pub_inliers_before_plane_;
00162     boost::shared_ptr <dynamic_reconfigure::Server<Config> > srv_;
00163     jsk_topic_tools::TimeAccumulator connect_ac_;
00164     ros::Subscriber sub_trigger_;
00165     
00167     // parameters to collect pointclouds
00169     std::string fixed_frame_id_;
00170     RotateType rotate_type_;
00171     TimeStampedVector<sensor_msgs::PointCloud2::ConstPtr> pointclouds_buffer_;
00172     TimeStampedVector<jsk_recognition_msgs::ClusterPointIndices::ConstPtr> indices_buffer_;
00173     TimeStampedVector<jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr> coefficients_buffer_;
00174     TimeStampedVector<LineSegment::Ptr> segments_buffer_;
00175     std::vector<LineSegmentCluster::Ptr> segment_clusters_;
00176     double segment_connect_normal_threshold_;
00177     double ewma_tau_;
00178     jsk_recognition_msgs::TimeRange::ConstPtr time_range_;
00180     // plane estimation
00182     double outlier_threshold_;
00183     
00184   private:
00185     
00186   };
00187 }
00188 
00189 #endif


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Sun Oct 8 2017 02:43:49