Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
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
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
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 }