00001 // Copyright (C) 2010-2011 Institut de Robotica i Informatica Industrial, CSIC-UPC. 00002 // Author 00003 // All rights reserved. 00004 // 00005 // This file is part of iri-ros-pkg 00006 // iri-ros-pkg is free software: you can redistribute it and/or modify 00007 // it under the terms of the GNU Lesser General Public License as published by 00008 // the Free Software Foundation, either version 3 of the License, or 00009 // at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public License 00017 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 // 00019 // IMPORTANT NOTE: This code has been generated through a script from the 00020 // iri_ros_scripts. Please do NOT delete any comments to guarantee the correctness 00021 // of the scripts. ROS topics can be easly add by using those scripts. Please 00022 // refer to the IRI wiki page for more information: 00023 // http://wikiri.upc.es/index.php/Robotics_Lab 00024 00025 #ifndef _zyonz_image_based_leaf_probing_alg_h_ 00026 #define _zyonz_image_based_leaf_probing_alg_h_ 00027 00028 #include <zyonz_image_based_leaf_probing/ZyonzImageBasedLeafProbingConfig.h> 00029 #include "mutex.h" 00030 #include "image.h" 00031 #include "misc.h" 00032 #include "pcl_ros/point_cloud.h" 00033 #include "pcl/point_types.h" 00034 #include "pcl/io/pcd_io.h" 00035 #include <cv_bridge/cv_bridge.h> 00036 #include <geometry_msgs/PoseArray.h> 00037 #include <geometry_msgs/PoseStamped.h> 00038 #include <zyonz_msgs/ProbingSteps.h> 00039 #include <tf/transform_listener.h> 00040 00041 //include zyonz_image_based_leaf_probing_alg main library 00042 00048 class ZyonzImageBasedLeafProbingAlgorithm 00049 { 00050 protected: 00057 CMutex alg_mutex_; 00058 00059 // private attributes and methods 00060 private: 00061 pcl::PointCloud<pcl::PointXYZRGB> pcl_xyzrgb_; 00062 cv_bridge::CvImagePtr seg_cv_ptr_; 00063 cv_bridge::CvImagePtr confidence_cv_ptr_; 00064 tf::TransformListener tf_listener_; 00065 00066 float sigma_; 00067 float k_; 00068 size_t min_size_; 00069 00070 image<rgb> *leaf_confidence_; 00071 double *goal_parameters_; 00072 Eigen::Vector3f probing_point_; 00073 zyonz_msgs::ProbingSteps probing_step_; 00074 00075 public: 00082 typedef zyonz_image_based_leaf_probing::ZyonzImageBasedLeafProbingConfig Config; 00083 00090 Config config_; 00091 00100 ZyonzImageBasedLeafProbingAlgorithm(void); 00101 00107 void lock(void) { alg_mutex_.enter(); }; 00108 00114 void unlock(void) { alg_mutex_.exit(); }; 00115 00123 bool try_enter(void) { return alg_mutex_.try_enter(); }; 00124 00136 void config_update(Config& new_cfg, uint32_t level=0); 00137 00138 // here define all zyonz_image_based_leaf_probing_alg interface methods to retrieve and set 00139 // the driver parameters 00140 00141 void set_sigma(float new_sigma); 00142 void set_k(float new_k); 00143 void set_min_size(int new_min_size); 00144 00145 float get_sigma(); 00146 float get_k(); 00147 int get_min_size(); 00148 cv_bridge::CvImagePtr get_seg_image(); 00149 cv_bridge::CvImagePtr get_confidence_image(); 00150 Eigen::Vector3f get_probing_point(); 00151 zyonz_msgs::ProbingSteps get_probing_step(); 00152 void find_probing_pose(const Eigen::Vector3f probing_point, const Eigen::Vector3f x_vector, const Eigen::Vector3f normal_vector, Eigen::Quaternionf &probing_pose); 00153 void find_probing_pose_by_PCA(const int label, int ** clusters, const image<rgb> *pc, Eigen::Quaternionf &probing_pose, Eigen::Vector3f &normal_vector); 00154 00155 00162 ~ZyonzImageBasedLeafProbingAlgorithm(void); 00163 00164 bool get_leaf_probing_point(const sensor_msgs::PointCloud2::ConstPtr &msg); 00165 00166 00167 }; 00168 00169 #endif