Go to the documentation of this file.00001
00059 #ifndef SAV_GOL_SMOOTHING_FILTER_H_
00060 #define SAV_GOL_SMOOTHING_FILTER_H_
00061
00062 #include <pcl/point_types.h>
00063 #include <Eigen/LU>
00064
00065 template <typename PointInT, typename PointOutT>
00066 class SavGolSmoothingFilter
00067 {
00068 public:
00069
00070 typedef pcl::PointCloud<PointInT> PointCloudIn;
00071 typedef typename PointCloudIn::Ptr PointCloudInPtr;
00072 typedef typename PointCloudIn::ConstPtr PointCloudInConstPtr;
00073
00074 typedef pcl::PointCloud<PointOutT> PointCloudOut;
00075
00076 public:
00077 SavGolSmoothingFilter () : high_th_(5.0)
00078 { };
00079
00080 inline void
00081 setInputCloud(const PointCloudInConstPtr &cloud)
00082 {
00083 input_ = cloud;
00084 }
00085
00086 inline void
00087 setFilterCoefficients(int size, int order)
00088 {
00089 int n_coef = 0;
00090 for (int j=0;j<=order;j++) for (int i=0;i<=(order-j);i++) n_coef++;
00091 double sum, fac;
00092
00093 Eigen::MatrixXd A2, C, A = Eigen::MatrixXd::Zero(size*size,n_coef);
00094 std::vector<double> coef;
00095 size_ = size;
00096 r_ = (size-1)/2;
00097
00098 int d = 0;
00099 for (int y = -(size-1)/2; y <= (size-1)/2; y++)
00100 {
00101 for (int x = -(size-1)/2; x <= (size-1)/2; x++)
00102 {
00103 int a = 0;
00104 for (int j = 0; j <= order; j++)
00105 {
00106 for (int i = 0; i <= (order - j); i++)
00107 {
00108 A(d,a) = pow(x,i)*pow(y,j);
00109 a++;
00110 }
00111 }
00112 d++;
00113 }
00114 }
00115
00116 A2 = A.transpose() * A;
00117 C = A2.inverse() * A.transpose();
00118
00119 int mm;
00120 for(mm=0;mm<size*size;mm++)
00121 {
00122
00123 coef.push_back(C(0,mm));
00124 }
00125 coef_ = coef;
00126 return;
00127 }
00128
00129 inline void
00130 getFilterCoefficients(std::vector<double> &coef)
00131 {
00132 coef = coef_;
00133 }
00134
00135 inline void
00136 setDistanceThreshold(float threshold)
00137 {
00138 high_th_ = threshold;
00139 }
00140
00141 bool
00142 smoothPoint(int index, float &z);
00143
00144 void
00145 reconstruct(PointCloudOut &output, std::vector<size_t> &ignored_indices);
00146
00147 void
00148 reconstruct2ndPass(std::vector<size_t> &indices,
00149 PointCloudOut &output);
00150
00151
00152 private:
00153
00154 std::vector<double> coef_;
00155 int size_;
00156 int r_;
00157 PointCloudInConstPtr input_;
00158 float high_th_;
00159
00160 };
00161
00162 #endif // SAV_GOL_SMOOTHING_FILTER_H_