narf_descriptor.cpp
Go to the documentation of this file.
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 
00037 #include <iostream>
00038 using std::cout;
00039 using std::cerr;
00040 
00041 #include <pcl/features/narf_descriptor.h>
00042 #include <pcl/features/narf.h>
00043 #include <pcl/range_image/range_image.h>
00044 
00045 namespace pcl 
00046 {
00048 NarfDescriptor::NarfDescriptor (const RangeImage* range_image, const std::vector<int>* indices) : 
00049   BaseClass (), range_image_ (), parameters_ ()
00050 {
00051   setRangeImage (range_image, indices);
00052 }
00053 
00055 NarfDescriptor::~NarfDescriptor ()
00056 {
00057 }
00058 
00060 void 
00061 NarfDescriptor::setRangeImage (const RangeImage* range_image, const std::vector<int>* indices)
00062 {
00063   range_image_ = range_image;
00064   if (indices != NULL)
00065   {
00066     IndicesPtr indicesptr (new std::vector<int> (*indices));
00067     setIndices (indicesptr);
00068   }
00069 }
00070 
00072 void 
00073 NarfDescriptor::computeFeature(NarfDescriptor::PointCloudOut& output)
00074 {
00075   //std::cout << __PRETTY_FUNCTION__ << " called.\n";
00076   
00077   output.points.clear();
00078   
00079   if (range_image_==NULL)
00080   {
00081     std::cerr << __PRETTY_FUNCTION__
00082               << ": RangeImage is not set. Sorry, the NARF descriptor calculation works on range images, not on normal point clouds."
00083               << " Use setRangeImage(...).\n\n";
00084     output.width = output.height = 0;
00085     output.points.clear ();
00086     return;
00087   }
00088   if (parameters_.support_size <= 0.0f)
00089   {
00090     std::cerr << __PRETTY_FUNCTION__
00091               << ": support size is not set. Use getParameters().support_size = ...\n\n";
00092     output.width = output.height = 0;
00093     output.points.clear ();
00094     return;
00095   }
00096   std::vector<Narf*> feature_list;
00097   if (indices_)
00098   {
00099     for (size_t indices_idx=0; indices_idx<indices_->size(); ++indices_idx)
00100     {
00101       int point_index = (*indices_)[indices_idx];
00102       int y=point_index/range_image_->width, x=point_index - y*range_image_->width;
00103       Narf::extractFromRangeImageAndAddToList(*range_image_, static_cast<float> (x), static_cast<float> (y), 36, parameters_.support_size,
00104                                               parameters_.rotation_invariant, feature_list);
00105     }
00106   }
00107   else
00108   {
00109     for (unsigned int y=0; y<range_image_->height; ++y)
00110     {
00111       for (unsigned int x=0; x<range_image_->width; ++x)
00112       {
00113         Narf::extractFromRangeImageAndAddToList(*range_image_, static_cast<float> (x), static_cast<float> (y), 36, parameters_.support_size,
00114                                                 parameters_.rotation_invariant, feature_list);
00115       }
00116     }
00117   }
00118   
00119   // Copy to NARF36 struct
00120   output.points.resize(feature_list.size());
00121   for (unsigned int i=0; i<feature_list.size(); ++i)
00122   {
00123     feature_list[i]->copyToNarf36(output.points[i]);
00124   }
00125   
00126   // Cleanup
00127   for (size_t i=0; i<feature_list.size(); ++i)
00128     delete feature_list[i];
00129 }
00130 
00132 void 
00133 NarfDescriptor::compute(NarfDescriptor::PointCloudOut& output)
00134 {
00135   computeFeature(output);
00136 }
00137 }  // namespace end


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:15:46