Point Cloud Library (PCL)  1.3.1
spin_image.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2009, 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  *
00035  */
00036 
00037 #ifndef PCL_SPIN_IMAGE_H_
00038 #define PCL_SPIN_IMAGE_H_
00039 
00040 #include <pcl/point_types.h>
00041 #include <pcl/features/feature.h>
00042 
00043 namespace pcl
00044 {
00073   template <typename PointInT, typename PointNT, typename PointOutT>
00074   class SpinImageEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
00075   {
00076     public:
00077       using Feature<PointInT, PointOutT>::feature_name_;
00078       using Feature<PointInT, PointOutT>::getClassName;
00079       using Feature<PointInT, PointOutT>::indices_;
00080       using Feature<PointInT, PointOutT>::search_radius_;
00081       using Feature<PointInT, PointOutT>::surface_;
00082       using Feature<PointInT, PointOutT>::fake_surface_;
00083       using FeatureFromNormals<PointInT, PointNT, PointOutT>::normals_;
00084       using PCLBase<PointInT>::input_;
00085 
00086       typedef typename Feature<PointInT, PointOutT>::PointCloudOut PointCloudOut;
00087 
00088       typedef typename pcl::PointCloud<PointNT> PointCloudN;
00089       typedef typename PointCloudN::Ptr PointCloudNPtr;
00090       typedef typename PointCloudN::ConstPtr PointCloudNConstPtr;
00091 
00092       typedef typename pcl::PointCloud<PointInT> PointCloudIn;
00093       typedef typename PointCloudIn::Ptr PointCloudInPtr;
00094       typedef typename PointCloudIn::ConstPtr PointCloudInConstPtr;
00095       
00105       SpinImageEstimation (unsigned int image_width = 8,
00106                            double support_angle_cos = 0.0,   // when 0, this is bogus, so not applied
00107                            unsigned int min_pts_neighb = 0);
00108 
00113       void 
00114       setImageWidth (unsigned int bin_count)
00115       {
00116         image_width_ = bin_count;
00117       }
00118 
00125       void 
00126       setSupportAngle (double support_angle_cos)
00127       {
00128         if (0.0 > support_angle_cos || support_angle_cos > 1.0)  // may be permit negative cosine?
00129         {
00130           throw PCLException ("Cosine of support angle should be between 0 and 1",
00131             "spin_image.h", "setSupportAngle");
00132         }
00133 
00134         support_angle_cos_ = support_angle_cos;
00135       }
00136 
00142       void 
00143       setMinPointCountInNeighbourhood (unsigned int min_pts_neighb)
00144       {
00145         min_pts_neighb_ = min_pts_neighb;
00146       }
00147 
00148 
00156       void 
00157       setInputWithNormals (const PointCloudInConstPtr& input, 
00158                            const PointCloudNConstPtr& normals)
00159       {
00160         setInputCloud (input);
00161         input_normals_ = normals;
00162       }
00163 
00173       void 
00174       setSearchSurfaceWithNormals (const PointCloudInConstPtr& surface, 
00175                                    const PointCloudNConstPtr& normals)
00176       {
00177         setSearchSurface (surface);
00178         setInputNormals (normals);
00179       }
00180 
00186       void 
00187       setRotationAxis (const PointNT& axis)
00188       {
00189         rotation_axis_ = axis;
00190         use_custom_axis_ = true;
00191         use_custom_axes_cloud_ = false;
00192       }
00193 
00200       void 
00201       setInputRotationAxes (const PointCloudNConstPtr& axes)
00202       {
00203         rotation_axes_cloud_ = axes;
00204 
00205         use_custom_axes_cloud_ = true;
00206         use_custom_axis_ = false;
00207       }
00208 
00212       void 
00213       useNormalsAsRotationAxis () 
00214       { 
00215         use_custom_axis_ = false; 
00216         use_custom_axes_cloud_ = false;
00217       }
00218 
00230       void 
00231       setAngularDomain (bool is_angular = true) { is_angular_ = is_angular; }
00232 
00240       void 
00241       setRadialStructure (bool is_radial = true) { is_radial_ = is_radial; }
00242 
00243     protected:
00248       virtual void 
00249       computeFeature (PointCloudOut &output); 
00250 
00255       virtual bool
00256       initCompute ();
00257 
00258 
00259     private:
00265       Eigen::ArrayXXd 
00266       computeSiForPoint (int index) const;
00267 
00268       PointCloudNConstPtr input_normals_;
00269       PointCloudNConstPtr rotation_axes_cloud_;
00270       
00271       bool is_angular_;
00272 
00273       PointNT rotation_axis_;
00274       bool use_custom_axis_;
00275       bool use_custom_axes_cloud_;
00276 
00277       bool is_radial_;
00278 
00279       unsigned int image_width_;
00280       double support_angle_cos_;
00281       unsigned int min_pts_neighb_;
00282 
00283 
00284       static const double PI;
00285   
00291       static int round (double dubl)
00292       {
00293         assert (fabs (dubl) < (std::numeric_limits<int>::max) ());   // check that this is small enough
00294     
00295         return int(::floor (dubl) + ((dubl >= 0) ? 0.5 : -0.5));
00296       }
00297   };
00298 }
00299 
00300 #endif  //#ifndef PCL_SPIN_IMAGE_H_
00301 
00302 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines