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 #ifndef SPHEREUNIFORMSAMPLING_H_
00037 #define SPHEREUNIFORMSAMPLING_H_
00038
00039 #include <vector>
00040 #include <cmath>
00041 #include <Eigen/Dense>
00042 #include <ros/ros.h>
00043 #include <pcl/point_cloud.h>
00044 #include <pcl/point_types.h>
00045
00046 typedef std::pair<unsigned int, unsigned int> Pair2ui;
00047
00048 class SphereUniformSampling {
00049 public:
00050 class NormalEntry{
00051 public:
00052 NormalEntry(const unsigned int i, const unsigned int j, const unsigned int phi_resolution);
00053
00054 float getWeight() const{return mWeight;}
00055 const Eigen::Vector3f& getNormal() const{return mNormal;}
00056 void getAngles(float& phi, float& theta) const{phi=mPhi; theta=mTheta;}
00057 const std::list<int>& getPoints() const{return mPoints;}
00058 const std::list<float>& getWeights() const{return mWeights;}
00059
00060 void addIndex(std::list<int>::iterator& points_it, std::list<float>::iterator& weights_it, const int idx, const float w);
00061 void deletePointNWeight(const std::list<int>::iterator points_it, const std::list<float>::iterator weights_it);
00062 void deleteEntry(){mWeight = 0.f; mPoints.clear(); mWeights.clear();}
00063
00064 private:
00065 static void getNormalFromAngles(Eigen::Vector3f& normal, const float phi, const float theta);
00066
00067 float mWeight;
00068 Eigen::Vector3f mNormal;
00069 float mPhi, mTheta;
00070 std::list<int> mPoints;
00071 std::list<float> mWeights;
00072 };
00073
00074 SphereUniformSampling(unsigned int phi_resolution, bool halfSphereFlip = false);
00075
00076 static void getHistogramIndicesFromAngles(unsigned int& i, unsigned int& j, const float phi, const float theta, const unsigned int phi_resolution);
00077 static void getAnglesFromHistogramIndices(float& phi, float& theta, const unsigned int i, const unsigned int j, const unsigned int phi_resolution);
00078
00079 Eigen::Vector3f getNormal(const unsigned int i, const unsigned int j) const{if ((i<mData.size())&&(j<mData[i].size())) return mData[i][j].getNormal(); return Eigen::Vector3f(0, 0, 0);}
00080 void getPointsAngle(std::list<int>& points, const float phi, const float theta, const float max_angle) const;
00081 void getPoints(std::vector<int>& points, const unsigned int i, const unsigned int j, std::vector<float>* weights = NULL) const;
00082 float getMaximumAngle(float& phi, float& theta, const float max_angle) const;
00083 float getMaximumIndices(unsigned int& idx_i, unsigned int& idx_j, const float max_angle) const;
00084 float getMaximum(unsigned int& imax, unsigned int& jmax) const;
00085 void getAllAngleNeighbors(std::vector<Pair2ui>& neighbors, const float phi, const float theta, const float max_angle) const;
00086 void getAllAngleNeighbors(std::vector<Pair2ui>& neighbors, const Eigen::Vector3f& pointNormal, const float max_angle) const;
00087 void getHistogramAsPointCloud(pcl::PointCloud<pcl::PointXYZRGB>& histogramCloud, const float scale, const Eigen::Vector3f& translation) const;
00088
00089
00090
00091 void addPointNoNeighbors(std::list<int>::iterator& points_it, std::list<float>::iterator& weights_it, const unsigned int i, const unsigned int j, const int index, const float weight = 1.f);
00092 void deletePointsAtAngle(const float phi, const float theta, const float max_angle);
00093 void deletePointNWeightAt(const std::list<int>::iterator points_it, const std::list<float>::iterator weights_it, const unsigned int i, const unsigned int j);
00094
00095 private:
00096 float getWeightAngle(const float phi, const float theta, const float max_angle) const;
00097 float getPlanarAngle(const float phi1, const float theta1, const float phi2, const float theta2) const;
00098
00099 void deleteEntry(unsigned int i, unsigned int j);
00100
00101 unsigned int mPhi_resolution;
00102 bool mHalfSphereFlip;
00103 std::vector<std::vector<NormalEntry> > mData;
00104 std::vector<float> mRatioToNextData;
00105 };
00106
00107 #endif