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 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 #ifndef PCL_FEATURES_IMPL_INTENSITY_SPIN_H_
00042 #define PCL_FEATURES_IMPL_INTENSITY_SPIN_H_
00043 
00044 #include <pcl/features/intensity_spin.h>
00045 
00047 template <typename PointInT, typename PointOutT> void
00048 pcl::IntensitySpinEstimation<PointInT, PointOutT>::computeIntensitySpinImage (
00049       const PointCloudIn &cloud, float radius, float sigma, 
00050       int k,
00051       const std::vector<int> &indices, 
00052       const std::vector<float> &squared_distances, 
00053       Eigen::MatrixXf &intensity_spin_image)
00054 {
00055   
00056   int nr_distance_bins = static_cast<int> (intensity_spin_image.cols ());
00057   int nr_intensity_bins = static_cast<int> (intensity_spin_image.rows ());
00058 
00059   
00060   float min_intensity = std::numeric_limits<float>::max ();
00061   float max_intensity = std::numeric_limits<float>::min ();
00062   for (int idx = 0; idx < k; ++idx)
00063   {
00064     min_intensity = (std::min) (min_intensity, cloud.points[indices[idx]].intensity);
00065     max_intensity = (std::max) (max_intensity, cloud.points[indices[idx]].intensity);
00066   }
00067 
00068   float constant = 1.0f / (2.0f * sigma_ * sigma_);
00069   
00070   intensity_spin_image.setZero ();
00071   for (int idx = 0; idx < k; ++idx)
00072   {
00073     
00074     const float eps = std::numeric_limits<float>::epsilon ();
00075     float d = static_cast<float> (nr_distance_bins) * sqrtf (squared_distances[idx]) / (radius + eps);
00076     float i = static_cast<float> (nr_intensity_bins) * 
00077               (cloud.points[indices[idx]].intensity - min_intensity) / (max_intensity - min_intensity + eps);
00078 
00079     if (sigma == 0)
00080     {
00081       
00082       int d_idx = static_cast<int> (d);
00083       int i_idx = static_cast<int> (i);
00084       intensity_spin_image (i_idx, d_idx) += 1;
00085     }
00086     else
00087     {
00088       
00089       int d_idx_min = (std::max)(static_cast<int> (floor (d - 3*sigma)), 0);
00090       int d_idx_max = (std::min)(static_cast<int> (ceil  (d + 3*sigma)), nr_distance_bins - 1);
00091       int i_idx_min = (std::max)(static_cast<int> (floor (i - 3*sigma)), 0);
00092       int i_idx_max = (std::min)(static_cast<int> (ceil  (i + 3*sigma)), nr_intensity_bins - 1);
00093    
00094       
00095       for (int i_idx = i_idx_min; i_idx <= i_idx_max; ++i_idx)  
00096       {
00097         for (int d_idx = d_idx_min; d_idx <= d_idx_max; ++d_idx)
00098         {
00099           
00100           float w = expf (-powf (d - static_cast<float> (d_idx), 2.0f) * constant - powf (i - static_cast<float> (i_idx), 2.0f) * constant);
00101           intensity_spin_image (i_idx, d_idx) += w;
00102         }
00103       }
00104     }
00105   }
00106 }
00107 
00109 template <typename PointInT, typename PointOutT> void
00110 pcl::IntensitySpinEstimation<PointInT, PointOutT>::computeFeature (PointCloudOut &output)
00111 {
00112   
00113   if (search_radius_ == 0.0)
00114   {
00115     PCL_ERROR ("[pcl::%s::computeFeature] The search radius must be set before computing the feature!\n",
00116                getClassName ().c_str ());
00117     output.width = output.height = 0;
00118     output.points.clear ();
00119     return;
00120   }
00121 
00122   
00123   if (nr_intensity_bins_ <= 0)
00124   {
00125     PCL_ERROR ("[pcl::%s::computeFeature] The number of intensity bins must be greater than zero!\n",
00126                getClassName ().c_str ());
00127     output.width = output.height = 0;
00128     output.points.clear ();
00129     return;
00130   }
00131   if (nr_distance_bins_ <= 0)
00132   {
00133     PCL_ERROR ("[pcl::%s::computeFeature] The number of distance bins must be greater than zero!\n",
00134                getClassName ().c_str ());
00135     output.width = output.height = 0;
00136     output.points.clear ();
00137     return;
00138   }
00139 
00140   Eigen::MatrixXf intensity_spin_image (nr_intensity_bins_, nr_distance_bins_);
00141   
00142   std::vector<int> nn_indices (surface_->points.size ());
00143   std::vector<float> nn_dist_sqr (surface_->points.size ());
00144  
00145   output.is_dense = true;
00146   
00147   for (size_t idx = 0; idx < indices_->size (); ++idx)
00148   {
00149     
00150     
00151     int k = tree_->radiusSearch ((*indices_)[idx], search_radius_, nn_indices, nn_dist_sqr);
00152     if (k == 0)
00153     {
00154       for (int bin = 0; bin < nr_intensity_bins_ * nr_distance_bins_; ++bin)
00155         output.points[idx].histogram[bin] = std::numeric_limits<float>::quiet_NaN ();
00156       output.is_dense = false;
00157       continue;
00158     }
00159 
00160     
00161     computeIntensitySpinImage (*surface_, static_cast<float> (search_radius_), sigma_, k, nn_indices, nn_dist_sqr, intensity_spin_image);
00162 
00163     
00164     int bin = 0;
00165     for (int bin_j = 0; bin_j < intensity_spin_image.cols (); ++bin_j)
00166       for (int bin_i = 0; bin_i < intensity_spin_image.rows (); ++bin_i)
00167         output.points[idx].histogram[bin++] = intensity_spin_image (bin_i, bin_j);
00168   }
00169 }
00170 
00171 #define PCL_INSTANTIATE_IntensitySpinEstimation(T,NT) template class PCL_EXPORTS pcl::IntensitySpinEstimation<T,NT>;
00172 
00173 #endif    // PCL_FEATURES_IMPL_INTENSITY_SPIN_H_ 
00174