normal_descriptor_alg.h
Go to the documentation of this file.
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 _normal_descriptor_alg_h_
00026 #define _normal_descriptor_alg_h_
00027 
00028 #include <normal_descriptor_node/NormalDescriptorConfig.h>
00029 #include "mutex.h"
00030 #include <sensor_msgs/PointCloud2.h>
00031 #include <normal_descriptor_node/ndesc_pc.h>
00032 //#include <pcl_ros/point_cloud.h>
00033 //#include <pcl/point_types.h>
00034 //#include <pcl/conversions.h>
00035 #include <pcl_conversions/pcl_conversions.h>
00036 #include <pcl/features/normal_3d.h>
00037 #include <cmath>
00038 #include <vector>
00039 #include <sstream>
00040 
00041 template <class T>
00042 inline std::string to_string (const T& t)
00043 {
00044   std::stringstream ss;
00045   ss << t;
00046   return ss.str();
00047 }
00048 
00049 
00050 //include normal_descriptor_alg main library
00051 
00057 class NormalDescriptorAlgorithm
00058 {
00059   protected:
00066     CMutex alg_mutex_;
00067 
00068     // private attributes and methods
00069     // [num threads]
00070     uint nt_;
00071 
00072     // [descriptor attributes]
00073     uint desc_num_orient_bins_;
00074     std::vector<float> orient_bin_boundsX_;
00075     std::vector<float> orient_bin_boundsY_;
00076     uint desc_num_side_spatial_bins_;
00077     uint desc_num_total_bins_;
00078     uint desc_patch_radius_;
00079     
00080     // [descriptor sampling attributes]
00081     uint sample_each_;
00082     uint margin_;
00083 
00084 
00085     /* /\** */
00086     /*  * \brief compute descriptor */
00087     /*  * */
00088     /*  * Main descriptor computation function. Computes descriptor at */
00089     /*  * position (u,v) with parameters from the object instance. */
00090     /*  *\/ */
00091     /* normal_descriptor_node::ndesc */
00092     /*   compute_descriptor(const pcl::PointCloud<pcl::PointXYZ> &cloud,  */
00093     /*                   pcl::PointCloud<pcl::PointXY> &pcl_spherical,  */
00094     /*                   uint u, uint v); */
00095     
00096     /* /\** */
00097     /*  * \brief compute descriptor with spatial bins */
00098     /*  * */
00099     /*  * Main descriptor computation function using spatial */
00100     /*  * bins. Computes descriptor at position (u,v) with parameters */
00101     /*  * from the object instance. */
00102     /*  *\/ */
00103     /* normal_descriptor_node::ndesc */
00104     /*   compute_descriptor_spatial(pcl::PointCloud<pcl::PointXYZ> &cloud, */
00105     /*                           pcl::PointCloud<pcl::PointXY> &pcl_spherical,  */
00106     /*                           uint u, uint v); */
00107 
00117     void
00118       compute_spherical_coords(pcl::PointCloud<pcl::Normal> &pcl_normal, 
00119                                pcl::PointCloud<pcl::PointXY> &pcl_spherical);
00120 
00121   public:
00128     typedef normal_descriptor_node::NormalDescriptorConfig Config;
00129 
00136     Config config_;
00137 
00146     NormalDescriptorAlgorithm();
00147 
00153     void lock(void) { alg_mutex_.enter(); };
00154 
00160     void unlock(void) { alg_mutex_.exit(); };
00161 
00169     bool try_enter(void) { return alg_mutex_.try_enter(); };
00170 
00182     void config_update(const Config& new_cfg, uint32_t level=0);
00183 
00184     // here define all normal_descriptor_alg interface methods to retrieve and set
00185     // the driver parameters
00193     inline int compute_total_bins()
00194     {
00195       this->desc_num_total_bins_ = this->desc_num_orient_bins_ * this->desc_num_orient_bins_ * 
00196         this->desc_num_side_spatial_bins_ * this->desc_num_side_spatial_bins_;
00197       return this->desc_num_total_bins_;
00198     }
00199 
00207     inline int set_num_side_spatial_bins(int nb)
00208     {
00209       this->desc_num_side_spatial_bins_ = nb;
00210       this->compute_total_bins();
00211       return this->desc_num_side_spatial_bins_;
00212     }
00213 
00221     inline uint set_num_orientation_bins(uint nb)
00222     {
00223       this->desc_num_orient_bins_ = nb;
00224       this->orient_bin_boundsX_.resize(this->desc_num_orient_bins_);
00225       this->orient_bin_boundsY_.resize(this->desc_num_orient_bins_);
00226       //angle Y (phi)
00227       float increment_bound  = 2*M_PI/this->desc_num_orient_bins_;
00228       this->orient_bin_boundsY_[0]   = -M_PI + increment_bound;
00229       for(uint i=1; i<this->desc_num_orient_bins_; i++)
00230       {
00231           this->orient_bin_boundsY_[i] = this->orient_bin_boundsY_[i-1]+increment_bound;
00232       }
00233       //angle X (theta)
00234       increment_bound  = M_PI/(2*this->desc_num_orient_bins_);  //we are only concerned with things above 45deg
00235       this->orient_bin_boundsX_[0]   = M_PI/2.0+increment_bound;
00236       for(uint i=1; i<this->desc_num_orient_bins_; i++)
00237       {
00238           this->orient_bin_boundsX_[i] = this->orient_bin_boundsX_[i-1]+increment_bound;
00239       }
00240 
00241       this->compute_total_bins();
00242       return this->desc_num_orient_bins_;
00243     }
00244 
00252     inline int set_desc_patch_radius(int r)
00253     {
00254       this->desc_patch_radius_ = r;
00255       this->margin_ = this->desc_patch_radius_;
00256       return this->desc_patch_radius_;
00257     }
00258 
00266     inline int set_sample_each(int s)
00267     {
00268       this->sample_each_ = s;
00269       return this->sample_each_;
00270     }
00271 
00272     // [descriptor computation]
00273 
00274 /*     /\** */
00275 /*      * \brief compute all descriptors of image */
00276 /*      * */
00277 /*      * Main interface to compute normal descriptors from a point cloud */
00278 /*      *\/ */
00279 /* //    normal_descriptor_node::ndesc_pc compute_ndescs(const sensor_msgs::PointCloud2::ConstPtr& msg); */
00280 /*     normal_descriptor_node::ndesc_pc compute_ndescs(pcl::PointCloud<pcl::PointXYZ>& pcl_xyzrgb); */
00281 
00282     /* /\** */
00283     /*  * \brief compute all descriptors of image using an integral image */
00284     /*  * */
00285     /*  * Main interface to compute normal descriptors from a point cloud */
00286     /*  * (DEPREACTED) */
00287     /*  * */
00288     /*  *\/ */
00289     /* normal_descriptor_node::ndesc_pc compute_ndescs_integral(pcl::PointCloud<pcl::PointXYZ>& cloud); */
00290 
00296     void compute_ndescs_integral_spatial(pcl::PointCloud<pcl::PointXYZ>& cloud, normal_descriptor_node::ndesc_pc &ndesc_pc_msg);
00297 
00298     //Needs to be adapted for rotation invariant!!
00299     normal_descriptor_node::ndesc compute_descriptor_one_spatial_rot_inv(pcl::PointCloud<pcl::PointXYZ> &cloud, pcl::PointCloud<pcl::PointXY> &pcl_spherical, uint u, uint v);
00300     void compute_descriptor_spatial_rot_inv(pcl::PointCloud<pcl::PointXYZ> &cloud, normal_descriptor_node::ndesc_pc &ndesc_pc_msg);
00301 
00307     //normal_descriptor_node::heat_map compute_wrinkled_map(const normal_descriptor_node::ndesc_pc &ndesc_pc_msg);
00308 
00315     ~NormalDescriptorAlgorithm();
00316 };
00317 
00318 #endif


normal_descriptor_node
Author(s): Arnau Ramisa
autogenerated on Fri Dec 6 2013 20:19:55