euclidean_cluster_extraction_nodelet.h
Go to the documentation of this file.
00001 // -*- mode: C++ -*-
00002 /*********************************************************************
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2013, Ryohei Ueda and 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 
00036 #ifndef JSK_PCL_ROS_EUCLIDEAN_CLUSTER_EXTRACTION_NODELET_H_
00037 #define JSK_PCL_ROS_EUCLIDEAN_CLUSTER_EXTRACTION_NODELET_H_
00038 
00039 #include <ros/ros.h>
00040 #include <ros/names.h>
00041 
00042 #include <std_msgs/ColorRGBA.h>
00043 
00044 #include <dynamic_reconfigure/server.h>
00045 
00046 #include <pcl_ros/pcl_nodelet.h>
00047 
00048 #include <pcl/point_types.h>
00049 #include <pcl/impl/point_types.hpp>
00050 #include <pcl/kdtree/kdtree_flann.h>
00051 #include <pcl/segmentation/sac_segmentation.h>
00052 #include <pcl/segmentation/extract_clusters.h>
00053 #include <pcl/filters/extract_indices.h>
00054 #include <pcl/common/centroid.h>
00055 
00056 #include "jsk_recognition_msgs/ClusterPointIndices.h"
00057 #include "jsk_recognition_msgs/EuclideanSegment.h"
00058 #include "jsk_recognition_msgs/Int32Stamped.h"
00059 
00060 #include "jsk_pcl_ros/EuclideanClusteringConfig.h"
00061 #include <Eigen/StdVector>
00062 #include "jsk_recognition_utils/pcl_util.h"
00063 #include "jsk_recognition_utils/pcl_conversion_util.h"
00064 #include <jsk_topic_tools/time_accumulator.h>
00065 
00066 #include <jsk_topic_tools/diagnostic_nodelet.h>
00067 
00068 namespace jsk_pcl_ros
00069 {
00070   class EuclideanClustering : public jsk_topic_tools::DiagnosticNodelet
00071   {
00072   public:
00073     typedef jsk_pcl_ros::EuclideanClusteringConfig Config;
00074     typedef std::vector<Eigen::Vector4f,
00075                         Eigen::aligned_allocator<Eigen::Vector4f> >
00076     Vector4fVector;
00077     EuclideanClustering() : DiagnosticNodelet("EuclideanClustering") {}
00078   protected:
00079     boost::shared_ptr <dynamic_reconfigure::Server<Config> > srv_;
00080     boost::mutex mutex_;
00081    
00082     void configCallback (Config &config, uint32_t level);
00083     ros::Publisher result_pub_;
00084     ros::Subscriber sub_input_;
00085     ros::Publisher cluster_num_pub_;
00086 
00087     ros::ServiceServer service_;
00088 
00089     double tolerance;
00090     double label_tracking_tolerance;
00091     int minsize_;
00092     int maxsize_;
00093     
00094     jsk_topic_tools::TimeAccumulator segmentation_acc_;
00095     jsk_topic_tools::TimeAccumulator kdtree_acc_;
00096     jsk_recognition_utils::Counter cluster_counter_;
00097     
00098     // the list of COGs of each cluster
00099     Vector4fVector cogs_;
00100     
00101     virtual void onInit();
00102     virtual void extract(const sensor_msgs::PointCloud2ConstPtr &input);
00103     bool serviceCallback(jsk_recognition_msgs::EuclideanSegment::Request &req,
00104                          jsk_recognition_msgs::EuclideanSegment::Response &res);
00105     virtual void updateDiagnostic(diagnostic_updater::DiagnosticStatusWrapper &stat);
00106     virtual std::vector<pcl::PointIndices> pivotClusterIndices(
00107       std::vector<int>& pivot_table,
00108       std::vector<pcl::PointIndices>& cluster_indices);
00109       
00110     virtual std::vector<int> buildLabelTrackingPivotTable(
00111       double* D,
00112       Vector4fVector cogs,
00113       Vector4fVector new_cogs,
00114       double label_tracking_tolerance);
00115     
00116     virtual void computeDistanceMatrix(
00117       double* D,
00118       Vector4fVector& old_cogs,
00119       Vector4fVector& new_cogs);
00120       
00121     virtual void
00122     computeCentroidsOfClusters(Vector4fVector& ret,
00123                                pcl::PointCloud<pcl::PointXYZ>::Ptr cloud,
00124                                std::vector<pcl::PointIndices> cluster_indices);
00125 
00126     virtual void subscribe();
00127     virtual void unsubscribe();
00128   };
00129     
00130 }
00131 
00132 #endif


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Tue Jul 2 2019 19:41:43