|
Point Cloud Library (PCL)
1.6.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2012, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id: convex_hull.h 5026 2012-03-12 02:51:44Z rusu $ 00037 * 00038 */ 00039 00040 #include <pcl/pcl_config.h> 00041 #ifdef HAVE_QHULL 00042 00043 #ifndef PCL_CONVEX_HULL_2D_H_ 00044 #define PCL_CONVEX_HULL_2D_H_ 00045 00046 // PCL includes 00047 #include <pcl/surface/reconstruction.h> 00048 #include <pcl/ModelCoefficients.h> 00049 #include <pcl/PolygonMesh.h> 00050 00051 namespace pcl 00052 { 00058 inline bool 00059 comparePoints2D (const std::pair<int, Eigen::Vector4f> & p1, const std::pair<int, Eigen::Vector4f> & p2) 00060 { 00061 double angle1 = atan2 (p1.second[1], p1.second[0]) + M_PI; 00062 double angle2 = atan2 (p2.second[1], p2.second[0]) + M_PI; 00063 return (angle1 > angle2); 00064 } 00065 00067 00071 template<typename PointInT> 00072 class ConvexHull : public MeshConstruction<PointInT> 00073 { 00074 protected: 00075 using PCLBase<PointInT>::input_; 00076 using PCLBase<PointInT>::indices_; 00077 using PCLBase<PointInT>::initCompute; 00078 using PCLBase<PointInT>::deinitCompute; 00079 00080 public: 00081 using MeshConstruction<PointInT>::reconstruct; 00082 00083 typedef pcl::PointCloud<PointInT> PointCloud; 00084 typedef typename PointCloud::Ptr PointCloudPtr; 00085 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00086 00088 ConvexHull () : compute_area_ (false), total_area_ (0), total_volume_ (0), dimension_ (0), 00089 projection_angle_thresh_ (cos (0.174532925) ), qhull_flags ("qhull "), 00090 x_axis_ (1.0, 0.0, 0.0), y_axis_ (0.0, 1.0, 0.0), z_axis_ (0.0, 0.0, 1.0) 00091 { 00092 }; 00093 00100 void 00101 reconstruct (PointCloud &points, 00102 std::vector<pcl::Vertices> &polygons); 00103 00107 void 00108 reconstruct (PointCloud &output); 00109 00114 void 00115 setComputeAreaVolume (bool value) 00116 { 00117 compute_area_ = value; 00118 if (compute_area_) 00119 qhull_flags = std::string ("qhull FA"); 00120 else 00121 qhull_flags = std::string ("qhull "); 00122 } 00123 00125 double 00126 getTotalArea () const 00127 { 00128 return (total_area_); 00129 } 00130 00134 double 00135 getTotalVolume () const 00136 { 00137 return (total_volume_); 00138 } 00139 00143 void 00144 setDimension (int dimension) 00145 { 00146 if ((dimension == 2) || (dimension == 3)) 00147 dimension_ = dimension; 00148 else 00149 PCL_ERROR ("[pcl::%s::setDimension] Invalid input dimension specified!\n", getClassName ().c_str ()); 00150 } 00151 00153 inline int 00154 getDimension () const 00155 { 00156 return (dimension_); 00157 } 00158 00159 protected: 00167 void 00168 performReconstruction (PointCloud &points, 00169 std::vector<pcl::Vertices> &polygons, 00170 bool fill_polygon_data = false); 00171 00179 void 00180 performReconstruction2D (PointCloud &points, 00181 std::vector<pcl::Vertices> &polygons, 00182 bool fill_polygon_data = false); 00183 00191 void 00192 performReconstruction3D (PointCloud &points, 00193 std::vector<pcl::Vertices> &polygons, 00194 bool fill_polygon_data = false); 00195 00200 virtual void 00201 performReconstruction (PolygonMesh &output); 00202 00207 virtual void 00208 performReconstruction (std::vector<pcl::Vertices> &polygons); 00209 00211 void 00212 calculateInputDimension (); 00213 00215 std::string 00216 getClassName () const 00217 { 00218 return ("ConvexHull"); 00219 } 00220 00221 /* \brief True if we should compute the area and volume of the convex hull. */ 00222 bool compute_area_; 00223 00224 /* \brief The area of the convex hull. */ 00225 double total_area_; 00226 00227 /* \brief The volume of the convex hull (only for 3D hulls, zero for 2D). */ 00228 double total_volume_; 00229 00231 int dimension_; 00232 00234 double projection_angle_thresh_; 00235 00237 std::string qhull_flags; 00238 00239 /* \brief x-axis - for checking valid projections. */ 00240 const Eigen::Vector3f x_axis_; 00241 00242 /* \brief y-axis - for checking valid projections. */ 00243 const Eigen::Vector3f y_axis_; 00244 00245 /* \brief z-axis - for checking valid projections. */ 00246 const Eigen::Vector3f z_axis_; 00247 00248 public: 00249 EIGEN_MAKE_ALIGNED_OPERATOR_NEW 00250 }; 00251 } 00252 00253 #endif //#ifndef PCL_CONVEX_HULL_2D_H_ 00254 #endif
1.7.6.1