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 #ifndef PCL18_BACKPORTS_ACCUMULATORS_H
00039 #define PCL18_BACKPORTS_ACCUMULATORS_H
00040
00041 #ifdef BACKPORT_PCL_CENTROID
00042
00043 #include <map>
00044 #include <vector>
00045
00046 #include <boost/mpl/filter_view.hpp>
00047 #include <boost/fusion/include/mpl.hpp>
00048 #include <boost/fusion/include/for_each.hpp>
00049 #include <boost/fusion/include/as_vector.hpp>
00050 #include <boost/fusion/include/filter_if.hpp>
00051
00052 #include <pcl18_backports/point_types.h>
00053
00054 namespace pcl
00055 {
00056 namespace detail
00057 {
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 struct AccumulatorXYZ
00068 {
00069
00070 typedef pcl::traits::has_xyz<boost::mpl::_1> IsCompatible;
00071
00072
00073 Eigen::Vector3f xyz;
00074
00075 inline AccumulatorXYZ()
00076 : xyz(Eigen::Vector3f::Zero())
00077 {
00078 }
00079
00080 template <typename PointT>
00081 void add(const PointT& t)
00082 {
00083 xyz += t.getVector3fMap();
00084 }
00085
00086 template <typename PointT>
00087 void get(PointT& t, size_t n) const
00088 {
00089 t.getVector3fMap() = xyz / n;
00090 }
00091
00092 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00093 };
00094
00095 struct AccumulatorNormal
00096 {
00097
00098 typedef pcl::traits::has_normal<boost::mpl::_1> IsCompatible;
00099
00100
00101 Eigen::Vector4f normal;
00102
00103 inline AccumulatorNormal()
00104 : normal(Eigen::Vector4f::Zero())
00105 {
00106 }
00107
00108
00109
00110 template <typename PointT>
00111 void add(const PointT& t)
00112 {
00113 normal += t.getNormalVector4fMap();
00114 }
00115
00116 template <typename PointT>
00117 void get(PointT& t, size_t) const
00118 {
00119 #if EIGEN_VERSION_AT_LEAST(3, 3, 0)
00120 t.getNormalVector4fMap() = normal.normalized();
00121 #else
00122 if (normal.squaredNorm() > 0)
00123 t.getNormalVector4fMap() = normal.normalized();
00124 else
00125 t.getNormalVector4fMap() = Eigen::Vector4f::Zero();
00126 #endif
00127 }
00128
00129 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00130 };
00131
00132 struct AccumulatorCurvature
00133 {
00134
00135 typedef pcl::traits::has_curvature<boost::mpl::_1> IsCompatible;
00136
00137
00138 float curvature;
00139
00140 inline AccumulatorCurvature()
00141 : curvature(0)
00142 {
00143 }
00144
00145 template <typename PointT>
00146 void add(const PointT& t)
00147 {
00148 curvature += t.curvature;
00149 }
00150
00151 template <typename PointT>
00152 void get(PointT& t, size_t n) const
00153 {
00154 t.curvature = curvature / n;
00155 }
00156 };
00157
00158 struct AccumulatorRGBA
00159 {
00160
00161 typedef pcl::traits::has_color<boost::mpl::_1> IsCompatible;
00162
00163
00164 float r, g, b, a;
00165
00166 inline AccumulatorRGBA()
00167 : r(0)
00168 , g(0)
00169 , b(0)
00170 , a(0)
00171 {
00172 }
00173
00174 template <typename PointT>
00175 void add(const PointT& t)
00176 {
00177 r += static_cast<float>(t.r);
00178 g += static_cast<float>(t.g);
00179 b += static_cast<float>(t.b);
00180 a += static_cast<float>(t.a);
00181 }
00182
00183 template <typename PointT>
00184 void get(PointT& t, size_t n) const
00185 {
00186 t.rgba = static_cast<uint32_t>(a / n) << 24 |
00187 static_cast<uint32_t>(r / n) << 16 |
00188 static_cast<uint32_t>(g / n) << 8 |
00189 static_cast<uint32_t>(b / n);
00190 }
00191 };
00192
00193 struct AccumulatorIntensity
00194 {
00195
00196 typedef pcl::traits::has_intensity<boost::mpl::_1> IsCompatible;
00197
00198
00199 float intensity;
00200
00201 inline AccumulatorIntensity()
00202 : intensity(0)
00203 {
00204 }
00205
00206 template <typename PointT>
00207 void add(const PointT& t)
00208 {
00209 intensity += t.intensity;
00210 }
00211
00212 template <typename PointT>
00213 void get(PointT& t, size_t n) const
00214 {
00215 t.intensity = intensity / n;
00216 }
00217 };
00218
00219 struct AccumulatorLabel
00220 {
00221
00222 typedef pcl::traits::has_label<boost::mpl::_1> IsCompatible;
00223
00224
00225
00226 std::map<uint32_t, size_t> labels;
00227
00228 inline AccumulatorLabel()
00229 {
00230 }
00231
00232 template <typename PointT>
00233 void add(const PointT& t)
00234 {
00235 auto itr = labels.find(t.label);
00236 if (itr == labels.end())
00237 labels.insert(std::make_pair(t.label, 1));
00238 else
00239 ++itr->second;
00240 }
00241
00242 template <typename PointT>
00243 void get(PointT& t, size_t) const
00244 {
00245 size_t max = 0;
00246 for (const auto& label : labels)
00247 if (label.second > max)
00248 {
00249 max = label.second;
00250 t.label = label.first;
00251 }
00252 }
00253 };
00254
00255
00256
00257 template <typename Point1T, typename Point2T = Point1T>
00258 struct IsAccumulatorCompatible
00259 {
00260 template <typename AccumulatorT>
00261 struct apply : boost::mpl::and_<
00262 boost::mpl::apply<typename AccumulatorT::IsCompatible, Point1T>,
00263 boost::mpl::apply<typename AccumulatorT::IsCompatible, Point2T>>
00264 {
00265 };
00266 };
00267
00268
00269
00270 template <typename PointT>
00271 struct Accumulators
00272 {
00273 typedef
00274 typename boost::fusion::result_of::as_vector<
00275 typename boost::mpl::filter_view<
00276 boost::mpl::vector<
00277 AccumulatorXYZ, AccumulatorNormal, AccumulatorCurvature,
00278 AccumulatorRGBA, AccumulatorIntensity, AccumulatorLabel>,
00279 IsAccumulatorCompatible<PointT>>>::type
00280 type;
00281 };
00282
00283
00284
00285 template <typename PointT>
00286 struct AddPoint
00287 {
00288 const PointT& p;
00289
00290 explicit AddPoint(const PointT& point)
00291 : p(point)
00292 {
00293 }
00294
00295 template <typename AccumulatorT>
00296 void operator()(AccumulatorT& accumulator) const
00297 {
00298 accumulator.add(p);
00299 }
00300 };
00301
00302
00303
00304 template <typename PointT>
00305 struct GetPoint
00306 {
00307 PointT& p;
00308 size_t n;
00309
00310 GetPoint(PointT& point, size_t num)
00311 : p(point)
00312 , n(num)
00313 {
00314 }
00315
00316 template <typename AccumulatorT>
00317 void operator()(AccumulatorT& accumulator) const
00318 {
00319 accumulator.get(p, n);
00320 }
00321 };
00322 }
00323 }
00324
00325 #endif // BACKPORT_PCL_CENTROID
00326 #endif // PCL18_BACKPORTS_ACCUMULATORS_H