|
Point Cloud Library (PCL)
1.5.1
|
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 4702 2012-02-23 09:39:33Z gedikli $ 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 () : 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 compute_area_ = false; 00093 }; 00094 00101 void 00102 reconstruct (PointCloud &points, 00103 std::vector<pcl::Vertices> &polygons); 00104 00108 void 00109 reconstruct (PointCloud &output); 00110 00115 void 00116 setComputeAreaVolume (bool value) 00117 { 00118 compute_area_ = value; 00119 if (compute_area_) 00120 qhull_flags = std::string ("qhull FA"); 00121 else 00122 qhull_flags = std::string ("qhull "); 00123 } 00124 00126 double 00127 getTotalArea () const 00128 { 00129 return (total_area_); 00130 } 00131 00135 double 00136 getTotalVolume () const 00137 { 00138 return (total_volume_); 00139 } 00140 00144 void 00145 setDimension (int dimension) 00146 { 00147 if ((dimension == 2) || (dimension == 3)) 00148 dimension_ = dimension; 00149 else 00150 PCL_ERROR ("[pcl::%s::setDimension] Invalid input dimension specified!\n", getClassName ().c_str ()); 00151 } 00152 00154 inline int 00155 getDimension () const 00156 { 00157 return (dimension_); 00158 } 00159 00160 protected: 00168 void 00169 performReconstruction (PointCloud &points, 00170 std::vector<pcl::Vertices> &polygons, 00171 bool fill_polygon_data = false); 00172 00180 void 00181 performReconstruction2D (PointCloud &points, 00182 std::vector<pcl::Vertices> &polygons, 00183 bool fill_polygon_data = false); 00184 00192 void 00193 performReconstruction3D (PointCloud &points, 00194 std::vector<pcl::Vertices> &polygons, 00195 bool fill_polygon_data = false); 00196 00201 virtual void 00202 performReconstruction (PolygonMesh &output); 00203 00208 virtual void 00209 performReconstruction (std::vector<pcl::Vertices> &polygons); 00210 00212 void 00213 calculateInputDimension (); 00214 00216 std::string 00217 getClassName () const 00218 { 00219 return ("ConvexHull"); 00220 } 00221 00222 /* \brief True if we should compute the area and volume of the convex hull. */ 00223 bool compute_area_; 00224 00225 /* \brief The area of the convex hull. */ 00226 double total_area_; 00227 00228 /* \brief The volume of the convex hull (only for 3D hulls, zero for 2D). */ 00229 double total_volume_; 00230 00232 int dimension_; 00233 00235 double projection_angle_thresh_; 00236 00238 std::string qhull_flags; 00239 00240 /* \brief x-axis - for checking valid projections. */ 00241 const Eigen::Vector3f x_axis_; 00242 00243 /* \brief y-axis - for checking valid projections. */ 00244 const Eigen::Vector3f y_axis_; 00245 00246 /* \brief z-axis - for checking valid projections. */ 00247 const Eigen::Vector3f z_axis_; 00248 00249 public: 00250 EIGEN_MAKE_ALIGNED_OPERATOR_NEW 00251 }; 00252 } 00253 00254 #endif //#ifndef PCL_CONVEX_HULL_2D_H_ 00255 #endif
1.8.0