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 #ifndef PCL_FILTERS_IMPL_STATISTICAL_OUTLIER_REMOVAL_H_
00041 #define PCL_FILTERS_IMPL_STATISTICAL_OUTLIER_REMOVAL_H_
00042
00043 #include <pcl/filters/statistical_outlier_removal.h>
00044 #include <pcl/common/io.h>
00045
00047 template <typename PointT> void
00048 pcl::StatisticalOutlierRemoval<PointT>::applyFilter (PointCloud &output)
00049 {
00050 std::vector<int> indices;
00051 if (keep_organized_)
00052 {
00053 bool temp = extract_removed_indices_;
00054 extract_removed_indices_ = true;
00055 applyFilterIndices (indices);
00056 extract_removed_indices_ = temp;
00057
00058 output = *input_;
00059 for (int rii = 0; rii < static_cast<int> (removed_indices_->size ()); ++rii)
00060 output.points[(*removed_indices_)[rii]].x = output.points[(*removed_indices_)[rii]].y = output.points[(*removed_indices_)[rii]].z = user_filter_value_;
00061 if (!pcl_isfinite (user_filter_value_))
00062 output.is_dense = false;
00063 }
00064 else
00065 {
00066 applyFilterIndices (indices);
00067 copyPointCloud (*input_, indices, output);
00068 }
00069 }
00070
00072 template <typename PointT> void
00073 pcl::StatisticalOutlierRemoval<PointT>::applyFilterIndices (std::vector<int> &indices)
00074 {
00075
00076 if (!searcher_)
00077 {
00078 if (input_->isOrganized ())
00079 searcher_.reset (new pcl::search::OrganizedNeighbor<PointT> ());
00080 else
00081 searcher_.reset (new pcl::search::KdTree<PointT> (false));
00082 }
00083 searcher_->setInputCloud (input_);
00084
00085
00086 std::vector<int> nn_indices (mean_k_);
00087 std::vector<float> nn_dists (mean_k_);
00088 std::vector<float> distances (indices_->size ());
00089 indices.resize (indices_->size ());
00090 removed_indices_->resize (indices_->size ());
00091 int oii = 0, rii = 0;
00092
00093
00094 for (int iii = 0; iii < static_cast<int> (indices_->size ()); ++iii)
00095 {
00096 if (!pcl_isfinite (input_->points[(*indices_)[iii]].x) ||
00097 !pcl_isfinite (input_->points[(*indices_)[iii]].y) ||
00098 !pcl_isfinite (input_->points[(*indices_)[iii]].z))
00099 {
00100 distances[iii] = 0.0;
00101 continue;
00102 }
00103
00104
00105 if (searcher_->nearestKSearch ((*indices_)[iii], mean_k_ + 1, nn_indices, nn_dists) == 0)
00106 {
00107 distances[iii] = 0.0;
00108 PCL_WARN ("[pcl::%s::applyFilter] Searching for the closest %d neighbors failed.\n", getClassName ().c_str (), mean_k_);
00109 continue;
00110 }
00111
00112
00113 double dist_sum = 0.0;
00114 for (int k = 1; k < mean_k_ + 1; ++k)
00115 dist_sum += sqrt (nn_dists[k]);
00116 distances[iii] = static_cast<float> (dist_sum / mean_k_);
00117 }
00118
00119
00120 double mean, stddev;
00121 getMeanStd (distances, mean, stddev);
00122 double distance_threshold = mean + std_mul_ * stddev;
00123
00124
00125 for (int iii = 0; iii < static_cast<int> (indices_->size ()); ++iii)
00126 {
00127
00128
00129 if ((!negative_ && distances[iii] > distance_threshold) || (negative_ && distances[iii] <= distance_threshold))
00130 {
00131 if (extract_removed_indices_)
00132 (*removed_indices_)[rii++] = (*indices_)[iii];
00133 continue;
00134 }
00135
00136
00137 indices[oii++] = (*indices_)[iii];
00138 }
00139
00140
00141 indices.resize (oii);
00142 removed_indices_->resize (rii);
00143 }
00144
00145 #define PCL_INSTANTIATE_StatisticalOutlierRemoval(T) template class PCL_EXPORTS pcl::StatisticalOutlierRemoval<T>;
00146
00147 #endif // PCL_FILTERS_IMPL_STATISTICAL_OUTLIER_REMOVAL_H_
00148