SphereUniformSampling.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013, Fraunhofer FKIE
00003  *
00004  * Authors: Bastian Gaspers
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  * * Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * * Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * * Neither the name of the Fraunhofer FKIE nor the names of its
00015  *   contributors may be used to endorse or promote products derived from
00016  *   this software without specific prior written permission.
00017  *
00018  * This file is part of the StructureColoring ROS package.
00019  *
00020  * The StructureColoring ROS package is free software:
00021  * you can redistribute it and/or modify it under the terms of the
00022  * GNU Lesser General Public License as published by the Free
00023  * Software Foundation, either version 3 of the License, or
00024  * (at your option) any later version.
00025  *
00026  * The StructureColoring ROS package is distributed in the hope that it will be useful,
00027  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00028  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00029  * GNU Lesser General Public License for more details.
00030  *
00031  * You should have received a copy of the GNU Lesser General Public License
00032  * along with The StructureColoring ROS package.
00033  * If not, see <http://www.gnu.org/licenses/>.
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 //      void addPoint(const float phi, const float theta, const int index, const float max_angle_tolerance = 0.f, const float weight = 1.f);
00090 //      void addPoint(const Eigen::Vector3f pointNormal, const int index, const float max_angle_tolerance = 0.f, const float weight = 1.f);
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 /* SPHEREUNIFORMSAMPLING_H_ */


structure_coloring_fkie
Author(s): Bastian Gaspers
autogenerated on Sun Jan 5 2014 11:38:09