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 Willow Garage 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 00037 #ifndef JSK_INTERACTIVE_MARKER_POINTCLOUD_CLOPPER_H_ 00038 #define JSK_INTERACTIVE_MARKER_POINTCLOUD_CLOPPER_H_ 00039 00040 #define BOOST_PARAMETER_MAX_ARITY 7 // its a hack 00041 00042 #include <jsk_topic_tools/time_accumulator.h> 00043 00044 #include <interactive_markers/interactive_marker_server.h> 00045 #include <interactive_markers/menu_handler.h> 00046 00047 #include <sensor_msgs/PointCloud2.h> 00048 00049 #include <pcl/point_types.h> 00050 #include <pcl/point_cloud.h> 00051 #include <sensor_msgs/PointCloud2.h> 00052 00053 #include <tf/transform_listener.h> 00054 00055 #include <dynamic_reconfigure/server.h> 00056 #include <jsk_interactive_marker/PointCloudCropperConfig.h> 00057 00058 namespace jsk_interactive_marker 00059 { 00060 00061 class Cropper 00062 { 00063 public: 00064 typedef boost::shared_ptr<Cropper> Ptr; 00065 Cropper(const unsigned int nr_parameter); 00066 virtual ~Cropper(); 00067 00068 virtual void crop(const pcl::PointCloud<pcl::PointXYZ>::Ptr& input, 00069 pcl::PointCloud<pcl::PointXYZ>::Ptr output); 00070 virtual std::string getName() = 0; 00071 virtual visualization_msgs::Marker getMarker() = 0; 00072 virtual void updateParameter(const double val, const unsigned int index); 00073 // return true if the point p is inside of the cropper 00074 virtual bool isInside(const pcl::PointXYZ& p) = 0; 00075 virtual void fillInitialParameters() = 0; 00076 virtual void setPose(Eigen::Affine3f pose); 00077 virtual Eigen::Affine3f getPose(); 00078 protected: 00079 unsigned int nr_parameter_; 00080 std::vector<double> parameters_; 00081 // pose_ of the Cropper should be respected to the frame_id of pointcloud 00082 Eigen::Affine3f pose_; 00083 private: 00084 00085 }; 00086 00087 class SphereCropper: public Cropper 00088 { 00089 public: 00090 typedef boost::shared_ptr<SphereCropper> Ptr; 00091 00092 SphereCropper(); 00093 virtual ~SphereCropper(); 00094 virtual std::string getName(); 00095 virtual visualization_msgs::Marker getMarker(); 00096 virtual bool isInside(const pcl::PointXYZ& p); 00097 virtual void fillInitialParameters(); 00098 virtual double getRadius(); 00099 protected: 00100 private: 00101 00102 }; 00103 00104 class CubeCropper: public Cropper 00105 { 00106 public: 00107 typedef boost::shared_ptr<CubeCropper> Ptr; 00108 00109 CubeCropper(); 00110 virtual ~CubeCropper(); 00111 virtual std::string getName(); 00112 virtual visualization_msgs::Marker getMarker(); 00113 virtual bool isInside(const pcl::PointXYZ& p); 00114 virtual void fillInitialParameters(); 00115 virtual double getWidthX(); 00116 virtual double getWidthY(); 00117 virtual double getWidthZ(); 00118 protected: 00119 private: 00120 00121 }; 00122 00123 00124 class PointCloudCropper 00125 { 00126 public: 00127 PointCloudCropper(ros::NodeHandle& nh, ros::NodeHandle &pnh); 00128 virtual ~PointCloudCropper(); 00129 protected: 00130 typedef PointCloudCropperConfig Config; 00131 00132 typedef std::vector<interactive_markers::MenuHandler::EntryHandle> 00133 EntryHandleVector; 00134 virtual void changeCropper(Cropper::Ptr next_cropper); 00135 virtual void inputCallback(const sensor_msgs::PointCloud2::ConstPtr& msg); 00136 virtual void reInitializeInteractiveMarker(); 00137 virtual void updateInteractiveMarker( 00138 Eigen::Affine3f pose_offset = Eigen::Affine3f::Identity()); 00139 virtual void initializeInteractiveMarker( 00140 Eigen::Affine3f pose_offset = Eigen::Affine3f::Identity()); 00141 virtual void processFeedback( 00142 const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback); 00143 virtual void menuFeedback( 00144 const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback); 00145 virtual void changeCropperCallback( 00146 const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ); 00147 virtual void updateMenuCheckboxStatus(); 00148 virtual void cropAndPublish(ros::Publisher& pub); 00149 virtual void configCallback(Config &config, uint32_t level); 00150 boost::mutex mutex_; 00151 ros::Subscriber point_sub_; 00152 ros::Publisher point_pub_; 00153 ros::Publisher point_visualization_pub_; 00154 boost::shared_ptr<interactive_markers::InteractiveMarkerServer> server_; 00155 //pcl::PointCloud<pcl::PointXYZ>::Ptr latest_pointcloud_; 00156 sensor_msgs::PointCloud2::ConstPtr latest_pointcloud_; 00157 boost::shared_ptr <dynamic_reconfigure::Server<Config> > srv_; 00158 interactive_markers::MenuHandler menu_handler_; 00159 Cropper::Ptr cropper_; 00160 std::vector<Cropper::Ptr> cropper_candidates_; 00161 EntryHandleVector cropper_entries_; 00162 boost::shared_ptr<tf::TransformListener> tf_listener_; 00163 00164 private: 00165 }; 00166 } 00167 00168 #endif