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 _CylinderPatch_h_
00037 #define _CylinderPatch_h_
00038
00039 #include "pcl/point_types.h"
00040 #include "pcl/point_cloud.h"
00041 #include <vector>
00042 #include <limits.h>
00043 #include <Eigen/Dense>
00044 #include <Eigen/StdVector>
00045 #include <opencv2/core/core.hpp>
00046 #include <boost/shared_ptr.hpp>
00047 #include <list>
00048 #include <structureColoring/structures/Cylinder3D.h>
00049
00050 class CylinderPatch : public Cylinder3D{
00051 public:
00052 typedef boost::shared_ptr<CylinderPatch> CylinderPatchPtr;
00053 typedef boost::shared_ptr<const CylinderPatch> CylinderPatchConstPtr;
00054 typedef std::list<CylinderPatchPtr> CylinderPatches;
00055
00056 typedef std::vector<int> PointIndices;
00057 typedef pcl::PointXYZ PointT;
00058 typedef pcl::PointXYZRGB ColoredPointT;
00059 typedef pcl::PointXYZI IntensityPointT;
00060 typedef pcl::PointCloud<PointT> PointCloud;
00061 typedef pcl::PointCloud<ColoredPointT> ColoredPointCloud;
00062 typedef pcl::PointCloud<IntensityPointT> IntensityPointCloud;
00063 typedef std::pair<unsigned int, unsigned int> Pair2ui;
00064 typedef Eigen::Vector3f Vec3;
00065 typedef Eigen::Matrix3f Mat3;
00066 typedef std::vector<Vec3, Eigen::aligned_allocator<Vec3> > Points;
00067
00068
00069 CylinderPatch() :
00070 Cylinder3D(), mCylinderId(0), mTextureMap(NULL), mHeightMap(NULL),
00071 mNormalMap(NULL) {
00072 }
00073
00074 template<typename PointCloudType>
00075 CylinderPatch(const PointIndices& inliers, const PointCloudType& pointCloud, const Vec3& pointOnAxis,
00076 const Vec3& axisDirection, const float radius, const float distThreshold) :
00077 Cylinder3D(pointOnAxis, axisDirection, radius), mDistThreshold(distThreshold), mPointIndices(inliers),
00078 mCylinderId(0), mTextureMap(NULL), mHeightMap(NULL), mNormalMap(NULL) {
00079 computeTransformation();
00080 initialize(inliers, pointCloud);
00081 }
00082
00083 template<typename PointCloudType>
00084 CylinderPatch(const PointIndices& inliers, const PointCloudType& pointCloud, const Vec3& pointOnAxis,
00085 const Vec3& axisDirection, const float radius, const Vec3& rotationAxis, const float rotationAngle, const float distThreshold) :
00086 Cylinder3D(pointOnAxis, axisDirection, radius, rotationAxis, rotationAngle),
00087 mDistThreshold(distThreshold), mPointIndices(inliers), mCylinderId(0), mTextureMap(NULL), mHeightMap(NULL), mNormalMap(NULL) {
00088 setTransformation(rotationAngle, rotationAxis);
00089 initialize(inliers, pointCloud);
00090 }
00091
00092 virtual ~CylinderPatch(){
00093 if (mTextureMap) delete mTextureMap;
00094 if (mHeightMap) delete mHeightMap;
00095 if (mNormalMap) delete mNormalMap;
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 void setId(const size_t& id){mCylinderId = id;}
00108
00109
00110 const Points& getBBVertices() const {return mBBVertices;}
00111
00112
00113
00114 float getAxisMin() const {return mAxisMin;}
00115 float getAxisMax() const {return mAxisMax;}
00116 void getAxisLimits(float& min,float& max) const {min = mAxisMin; max = mAxisMax;}
00117 const float& getHeight()const{return mHeight;}
00118 const Vec3& getTopPoint()const{return mTopPoint;}
00119 const Vec3& getMidPoint()const{return mMidPoint;}
00120
00121
00122
00123
00124 const PointIndices& getInliers()const{return mPointIndices;}
00125 const size_t& getId()const{return mCylinderId;}
00126
00127 const cv::Mat* getTextureMap() const {
00128 return mTextureMap;
00129 }
00130 const cv::Mat* getHeightMap() const {
00131 return mHeightMap;
00132 }
00133 const cv::Mat* getNormalMap() const {
00134 return mNormalMap;
00135 }
00136
00137
00138 bool checkDistance(const Vec3& point) const{
00139 return Cylinder3D::checkDistance(point, mDistThreshold);
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 bool checkHeight(const Vec3& point, const float& heightDev){
00155 Vec3 transformedPoint;
00156 transformToCylinder(transformedPoint, point);
00157 if( transformedPoint.z() < mAxisMax + heightDev * mHeight && transformedPoint.z() > mAxisMin - heightDev * mHeight) return true;
00158 return false;
00159 }
00160
00161 template<typename PointCloudType>
00162 void addPoints(const PointIndices& pointIndices, const PointCloudType& pointCloud){
00163 mPointIndices.reserve(mPointIndices.size() + pointIndices.size());
00164 for(PointIndices::const_iterator pi_it = pointIndices.begin();pi_it != pointIndices.end(); ++pi_it){
00165 mPointIndices.push_back(*pi_it);
00166 }
00167 this->addToHeight(pointIndices, pointCloud);
00168
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 private:
00187
00188
00189
00190
00191
00195 void setTransformation(const float rotationAngle, const Vec3& rotationAxis);
00196
00197 template<typename PointCloudType>
00198 void initialize(const PointIndices& pointIndices, const PointCloudType& pointCloud);
00199
00200 template<typename PointCloudType>
00201 void addToHeight(const PointIndices& pointIndices, const PointCloudType& pointCloud);
00202
00203 void computeOrientedBoundingBox();
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 float mAxisMin, mAxisMax;
00214 float mHeight;
00215 Vec3 mTopPoint;
00216 Vec3 mMidPoint;
00217
00218 float mDistThreshold;
00219
00220 PointIndices mPointIndices;
00221 Points mBBVertices;
00222 size_t mCylinderId;
00223
00224 cv::Mat* mTextureMap;
00225 cv::Mat* mHeightMap;
00226 cv::Mat* mNormalMap;
00227 };
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 template<typename PointCloudType>
00246 void CylinderPatch::initialize(const PointIndices& pointIndices, const PointCloudType& pointCloud){
00247
00248 mAxisMin = std::numeric_limits<float>::max();
00249 mAxisMax = -std::numeric_limits<float>::max();
00250 for(PointIndices::const_iterator pit = pointIndices.begin(); pit != pointIndices.end(); ++pit){
00251 Vec3 p;
00252 transformToCylinder(p, pointCloud.points[*pit].getVector3fMap());
00253
00254 if (p.z() < mAxisMin) mAxisMin = p.z();
00255 if (p.z() > mAxisMax) mAxisMax = p.z();
00256 }
00257 mHeight = fabs(mAxisMax - mAxisMin);
00258 Vec3 tp(0.f, 0.f, mAxisMax);
00259 Vec3 mp(0.f, 0.f, (mAxisMax + mAxisMin) * 0.5f);
00260 transformToXYZCoords(mMidPoint, mp);
00261 transformToXYZCoords(mTopPoint, tp);
00262
00263 computeOrientedBoundingBox();
00264 }
00265
00266 template<typename PointCloudType>
00267 void CylinderPatch::addToHeight(const PointIndices& pointIndices, const PointCloudType& pointCloud){
00268 for(PointIndices::const_iterator pit = pointIndices.begin(); pit != pointIndices.end(); ++pit){
00269 Vec3 p;
00270 transformToCylinder(p, pointCloud.points[*pit].getVector3fMap());
00271
00272 if (p.z() < mAxisMin){
00273 mAxisMin = p.z();
00274 }
00275 if (p.z() > mAxisMax){
00276 mAxisMax = p.z();
00277 }
00278 }
00279 mHeight = fabs(mAxisMax - mAxisMin);
00280 Vec3 tp(0.f, 0.f, mAxisMax);
00281 Vec3 mp(0.f, 0.f, (mAxisMax + mAxisMin) * 0.5f);
00282 transformToXYZCoords(mMidPoint, mp);
00283 transformToXYZCoords(mTopPoint, tp);
00284
00285 computeOrientedBoundingBox();
00286 }
00287
00288 #endif