Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _finddd_alg_h_
00026 #define _finddd_alg_h_
00027
00028 #include <iri_finddd/FindddConfig.h>
00029 #include "mutex.h"
00030 #include <sensor_msgs/PointCloud2.h>
00031 #include <iri_perception_msgs/DescriptorSet.h>
00032 #include <pcl_ros/point_cloud.h>
00033 #include <pcl/point_types.h>
00034 #include <pcl/ros/conversions.h>
00035 #include <pcl/features/normal_3d.h>
00036 #include <pcl/features/integral_image_normal.h>
00037 #include <cmath>
00038 #include <vector>
00039 #include <sstream>
00040 #include <time.h>
00041 #include <iostream>
00042 #include <fstream>
00043
00044
00045 #include <pcl/io/pcd_io.h>
00046
00047 template <class T>
00048 inline std::string to_string (const T& t)
00049 {
00050 std::stringstream ss;
00051 ss << t;
00052 return ss.str();
00053 }
00054
00055
00056
00062 class FindddAlgorithm
00063 {
00064 protected:
00071 CMutex alg_mutex_;
00072
00073
00074 uint nt_;
00075
00076
00077 std::vector<float> orient_bin_centers_x_;
00078 std::vector<float> orient_bin_centers_y_;
00079 std::vector<float> orient_bin_centers_z_;
00080 std::vector<int> desc_compute_positionsX_;
00081 std::vector<int> desc_compute_positionsY_;
00082 float radius_inf_;
00083 uint desc_num_orient_bins_;
00084 uint desc_num_side_spatial_bins_;
00085 uint desc_num_total_bins_;
00086 uint desc_patch_radius_;
00087 std::string centroids_file_;
00088 std::string positions_file_;
00089 uint normalize_desc_;
00090 uint use_soft_voting_;
00091
00092
00093 uint sample_each_;
00094 uint margin_;
00095
00096 public:
00103 typedef iri_finddd::FindddConfig Config;
00104
00111 Config config_;
00112
00121 FindddAlgorithm(void);
00122
00128 void lock(void) { alg_mutex_.enter(); };
00129
00135 void unlock(void) { alg_mutex_.exit(); };
00136
00144 bool try_enter(void) { return alg_mutex_.try_enter(); };
00145
00157 void config_update(Config& new_cfg, uint32_t level=0);
00158
00159
00160
00161
00169 inline int compute_total_bins()
00170 {
00171
00172
00173 this->desc_num_total_bins_ = this->desc_num_side_spatial_bins_ * this->desc_num_side_spatial_bins_ * this->orient_bin_centers_x_.size();
00174
00175 return this->desc_num_total_bins_;
00176 }
00177
00185 inline int set_num_side_spatial_bins(int nb)
00186 {
00187 this->desc_num_side_spatial_bins_ = nb;
00188 this->compute_total_bins();
00189 return this->desc_num_side_spatial_bins_;
00190 }
00191
00192
00200 inline int set_desc_patch_radius(int r)
00201 {
00202 this->desc_patch_radius_ = r;
00203 this->margin_ = this->desc_patch_radius_;
00204 return this->desc_patch_radius_;
00205 }
00206
00214 inline int set_sample_each(int s)
00215 {
00216 this->sample_each_ = s;
00217 return this->sample_each_;
00218 }
00219
00226 inline void set_centroids_file(std::string new_centroids_file)
00227 {
00228 this->centroids_file_ = new_centroids_file;
00229 this->update_centroids();
00230 }
00231
00232 inline void update_centroids()
00233 {
00234 std::ifstream ifs(this->centroids_file_.c_str(), std::ifstream::in);
00235 if(!ifs.is_open())
00236 {
00237 ROS_ERROR("FINDDD: Incorrect number of centers loaded from file %s", this->centroids_file_.c_str());
00238 }
00239
00240 this->orient_bin_centers_x_.clear();
00241 this->orient_bin_centers_y_.clear();
00242 this->orient_bin_centers_z_.clear();
00243
00244 while (ifs.good())
00245 {
00246 float x,y,z;
00247 ifs >> x;
00248 ifs >> y;
00249 ifs >> z;
00250
00251 if(ifs.good())
00252 {
00253 this->orient_bin_centers_x_.push_back(x);
00254 this->orient_bin_centers_y_.push_back(y);
00255 this->orient_bin_centers_z_.push_back(z);
00256 }
00257 }
00258 ifs.close();
00259 this->desc_num_orient_bins_ = this->orient_bin_centers_x_.size();
00260 ROS_INFO("Loaded %d centers\n", this->desc_num_orient_bins_);
00261 this->compute_total_bins();
00262 this->compute_radius_inf();
00263 }
00264
00272 inline void set_positions_file(std::string new_positions_file)
00273 {
00274 this->positions_file_ = new_positions_file;
00275
00276 this->desc_compute_positionsX_.clear();
00277 this->desc_compute_positionsY_.clear();
00278
00279 if(this->positions_file_=="")
00280 {
00281 ROS_INFO("Generating positions with 'sample_each' param.");
00282 return;
00283 }
00284
00285 std::ifstream ifs(this->positions_file_.c_str(), std::ifstream::in);
00286 if(!ifs.is_open())
00287 {
00288 ROS_ERROR("FINDDD: Incorrect descriptor positions file %s", this->positions_file_.c_str());
00289 }
00290
00291 while (ifs.good())
00292 {
00293 int x,y;
00294 ifs >> x;
00295 ifs >> y;
00296 this->desc_compute_positionsX_.push_back(x);
00297 this->desc_compute_positionsY_.push_back(y);
00298 }
00299 ifs.close();
00300 ROS_INFO("Loaded %d positions\n", this->desc_compute_positionsX_.size());
00301 }
00302
00309 inline void compute_radius_inf()
00310 {
00311
00312 float x = this->orient_bin_centers_x_[0];
00313 float y = this->orient_bin_centers_y_[0];
00314 float z = this->orient_bin_centers_z_[0];
00315 this->radius_inf_ = 9999999999;
00316 for(int i=1; i<this->orient_bin_centers_x_.size(); i++)
00317 {
00318 float dist = sqrt(pow(x-this->orient_bin_centers_x_[i],2) +
00319 pow(y-this->orient_bin_centers_y_[i],2) +
00320 pow(z-this->orient_bin_centers_z_[i],2));
00321 if(dist<this->radius_inf_)
00322 this->radius_inf_ = dist;
00323 }
00324 ROS_INFO("Using ratio_inf_ = %f", this->radius_inf_);
00325 }
00326
00332
00333 void compute_ndescs_integral_spatial_interpolation(pcl::PointCloud<pcl::PointXYZ>& cloud, iri_perception_msgs::DescriptorSet &descriptor_set);
00334
00341 ~FindddAlgorithm(void);
00342 };
00343
00344 #endif