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 #ifndef PCL_FEATURES_IMPL_INTENSITY_SPIN_H_
00041 #define PCL_FEATURES_IMPL_INTENSITY_SPIN_H_
00042
00043 #include <pcl/features/intensity_spin.h>
00044
00046 template <typename PointInT, typename PointOutT> void
00047 pcl::IntensitySpinEstimation<PointInT, PointOutT>::computeIntensitySpinImage (
00048 const PointCloudIn &cloud, float radius, float sigma,
00049 int k,
00050 const std::vector<int> &indices,
00051 const std::vector<float> &squared_distances,
00052 Eigen::MatrixXf &intensity_spin_image)
00053 {
00054
00055 int nr_distance_bins = static_cast<int> (intensity_spin_image.cols ());
00056 int nr_intensity_bins = static_cast<int> (intensity_spin_image.rows ());
00057
00058
00059 float min_intensity = std::numeric_limits<float>::max ();
00060 float max_intensity = std::numeric_limits<float>::min ();
00061 for (int idx = 0; idx < k; ++idx)
00062 {
00063 min_intensity = (std::min) (min_intensity, cloud.points[indices[idx]].intensity);
00064 max_intensity = (std::max) (max_intensity, cloud.points[indices[idx]].intensity);
00065 }
00066
00067 float constant = 1.0f / (2.0f * sigma_ * sigma_);
00068
00069 intensity_spin_image.setZero ();
00070 for (int idx = 0; idx < k; ++idx)
00071 {
00072
00073 const float eps = std::numeric_limits<float>::epsilon ();
00074 float d = static_cast<float> (nr_distance_bins) * sqrtf (squared_distances[idx]) / (radius + eps);
00075 float i = static_cast<float> (nr_intensity_bins) *
00076 (cloud.points[indices[idx]].intensity - min_intensity) / (max_intensity - min_intensity + eps);
00077
00078 if (sigma == 0)
00079 {
00080
00081 int d_idx = static_cast<int> (d);
00082 int i_idx = static_cast<int> (i);
00083 intensity_spin_image (i_idx, d_idx) += 1;
00084 }
00085 else
00086 {
00087
00088 int d_idx_min = (std::max)(static_cast<int> (floor (d - 3*sigma)), 0);
00089 int d_idx_max = (std::min)(static_cast<int> (ceil (d + 3*sigma)), nr_distance_bins - 1);
00090 int i_idx_min = (std::max)(static_cast<int> (floor (i - 3*sigma)), 0);
00091 int i_idx_max = (std::min)(static_cast<int> (ceil (i + 3*sigma)), nr_intensity_bins - 1);
00092
00093
00094 for (int i_idx = i_idx_min; i_idx <= i_idx_max; ++i_idx)
00095 {
00096 for (int d_idx = d_idx_min; d_idx <= d_idx_max; ++d_idx)
00097 {
00098
00099 float w = expf (-powf (d - static_cast<float> (d_idx), 2.0f) * constant - powf (i - static_cast<float> (i_idx), 2.0f) * constant);
00100 intensity_spin_image (i_idx, d_idx) += w;
00101 }
00102 }
00103 }
00104 }
00105 }
00106
00108 template <typename PointInT, typename PointOutT> void
00109 pcl::IntensitySpinEstimation<PointInT, PointOutT>::computeFeature (PointCloudOut &output)
00110 {
00111
00112 if (search_radius_ == 0.0)
00113 {
00114 PCL_ERROR ("[pcl::%s::computeFeature] The search radius must be set before computing the feature!\n",
00115 getClassName ().c_str ());
00116 output.width = output.height = 0;
00117 output.points.clear ();
00118 return;
00119 }
00120
00121
00122 if (nr_intensity_bins_ <= 0)
00123 {
00124 PCL_ERROR ("[pcl::%s::computeFeature] The number of intensity bins must be greater than zero!\n",
00125 getClassName ().c_str ());
00126 output.width = output.height = 0;
00127 output.points.clear ();
00128 return;
00129 }
00130 if (nr_distance_bins_ <= 0)
00131 {
00132 PCL_ERROR ("[pcl::%s::computeFeature] The number of distance bins must be greater than zero!\n",
00133 getClassName ().c_str ());
00134 output.width = output.height = 0;
00135 output.points.clear ();
00136 return;
00137 }
00138
00139 Eigen::MatrixXf intensity_spin_image (nr_intensity_bins_, nr_distance_bins_);
00140
00141 std::vector<int> nn_indices (surface_->points.size ());
00142 std::vector<float> nn_dist_sqr (surface_->points.size ());
00143
00144 output.is_dense = true;
00145
00146 for (size_t idx = 0; idx < indices_->size (); ++idx)
00147 {
00148
00149
00150 int k = tree_->radiusSearch ((*indices_)[idx], search_radius_, nn_indices, nn_dist_sqr);
00151 if (k == 0)
00152 {
00153 for (int bin = 0; bin < nr_intensity_bins_ * nr_distance_bins_; ++bin)
00154 output.points[idx].histogram[bin] = std::numeric_limits<float>::quiet_NaN ();
00155 output.is_dense = false;
00156 continue;
00157 }
00158
00159
00160 computeIntensitySpinImage (*surface_, static_cast<float> (search_radius_), sigma_, k, nn_indices, nn_dist_sqr, intensity_spin_image);
00161
00162
00163 int bin = 0;
00164 for (int bin_j = 0; bin_j < intensity_spin_image.cols (); ++bin_j)
00165 for (int bin_i = 0; bin_i < intensity_spin_image.rows (); ++bin_i)
00166 output.points[idx].histogram[bin++] = intensity_spin_image (bin_i, bin_j);
00167 }
00168 }
00169
00171 template <typename PointInT> void
00172 pcl::IntensitySpinEstimation<PointInT, Eigen::MatrixXf>::computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &output)
00173 {
00174
00175 {
00176
00177 if (search_radius_ == 0.0)
00178 {
00179 PCL_ERROR ("[pcl::%s::computeFeature] The search radius must be set before computing the feature!\n",
00180 getClassName ().c_str ());
00181 output.width = output.height = 0;
00182 output.points.resize (0, 0);
00183 return;
00184 }
00185
00186
00187 if (nr_intensity_bins_ <= 0)
00188 {
00189 PCL_ERROR ("[pcl::%s::computeFeature] The number of intensity bins must be greater than zero!\n",
00190 getClassName ().c_str ());
00191 output.width = output.height = 0;
00192 output.points.resize (0, 0);
00193 return;
00194 }
00195 if (nr_distance_bins_ <= 0)
00196 {
00197 PCL_ERROR ("[pcl::%s::computeFeature] The number of distance bins must be greater than zero!\n",
00198 getClassName ().c_str ());
00199 output.width = output.height = 0;
00200 output.points.resize (0, 0);
00201 return;
00202 }
00203 }
00204
00205 output.points.resize (indices_->size (), nr_intensity_bins_ * nr_distance_bins_);
00206 Eigen::MatrixXf intensity_spin_image (nr_intensity_bins_, nr_distance_bins_);
00207
00208 std::vector<int> nn_indices;
00209 std::vector<float> nn_dist_sqr;
00210
00211 output.is_dense = true;
00212
00213 for (size_t idx = 0; idx < indices_->size (); ++idx)
00214 {
00215
00216 int k = tree_->radiusSearch ((*indices_)[idx], search_radius_, nn_indices, nn_dist_sqr);
00217 if (k == 0)
00218 {
00219 output.points.row (idx).setConstant (std::numeric_limits<float>::quiet_NaN ());
00220 output.is_dense = false;
00221 continue;
00222 }
00223
00224
00225 this->computeIntensitySpinImage (*surface_, static_cast<float> (search_radius_), sigma_, k, nn_indices, nn_dist_sqr, intensity_spin_image);
00226
00227
00228 int bin = 0;
00229 for (int bin_j = 0; bin_j < intensity_spin_image.cols (); ++bin_j)
00230 for (int bin_i = 0; bin_i < intensity_spin_image.rows (); ++bin_i)
00231 output.points (idx, bin++) = intensity_spin_image (bin_i, bin_j);
00232 }
00233 }
00234
00235
00236 #define PCL_INSTANTIATE_IntensitySpinEstimation(T,NT) template class PCL_EXPORTS pcl::IntensitySpinEstimation<T,NT>;
00237
00238 #endif // PCL_FEATURES_IMPL_INTENSITY_SPIN_H_
00239