00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage, Inc. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * $Id: convex_hull.h 36140 2011-02-22 05:42:48Z aaldoma $ 00035 * 00036 */ 00037 00038 #ifndef PCL_CONVEX_HULL_2D_H_ 00039 #define PCL_CONVEX_HULL_2D_H_ 00040 00041 // PCL includes 00042 #include "pcl/pcl_base.h" 00043 #include "pcl/io/io.h" 00044 00045 #include "pcl/features/normal_3d.h" 00046 #include "pcl/ModelCoefficients.h" 00047 #include "pcl/PolygonMesh.h" 00048 #include <math.h> 00049 00050 #if defined(__cplusplus) 00051 extern "C" 00052 { 00053 #endif 00054 #include <stdio.h> 00055 #include <stdlib.h> 00056 #include "qhull/qhull.h" 00057 #include "qhull/mem.h" 00058 #include "qhull/qset.h" 00059 #include "qhull/geom.h" 00060 #include "qhull/merge.h" 00061 #include "qhull/poly.h" 00062 #include "qhull/io.h" 00063 #include "qhull/stat.h" 00064 #if defined(__cplusplus) 00065 } 00066 #endif 00067 00068 namespace pcl 00069 { 00074 inline bool 00075 comparePoints2D (const std::pair<int, Eigen::Vector4f> & p1, 00076 const std::pair<int, Eigen::Vector4f> & p2) 00077 { 00078 double angle1 = atan2 (p1.second[1],p1.second[0]) + M_PI; 00079 double angle2 = atan2 (p2.second[1],p2.second[0]) + M_PI; 00080 return (angle1 > angle2); 00081 } 00082 00084 00087 template<typename PointInT> 00088 class ConvexHull : public PCLBase<PointInT> 00089 { 00090 using PCLBase<PointInT>::input_; 00091 using PCLBase<PointInT>::indices_; 00092 using PCLBase<PointInT>::initCompute; 00093 using PCLBase<PointInT>::deinitCompute; 00094 00095 public: 00096 typedef pcl::PointCloud<PointInT> PointCloud; 00097 typedef typename PointCloud::Ptr PointCloudPtr; 00098 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00099 00101 ConvexHull () {}; 00102 00107 void 00108 reconstruct (PointCloud &points, std::vector<pcl::Vertices> &polygons); 00109 00113 void 00114 reconstruct (PointCloud &output); 00115 00116 private: 00122 void 00123 performReconstruction (PointCloud &points, std::vector<pcl::Vertices> &polygons, 00124 bool fill_polygon_data = false); 00125 00126 protected: 00128 std::string 00129 getClassName () const 00130 { 00131 return ("ConvexHull"); 00132 } 00133 }; 00134 } 00135 00136 #endif //#ifndef PCL_CONVEX_HULL_2D_H_