Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
narf.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35 
36 #ifndef PCL_NARF_H_
37 #define PCL_NARF_H_
38 
39 #include <vector>
40 #include <Eigen/Geometry>
43 
44 namespace pcl
45 {
46  // Forward declarations
47  class RangeImage;
48  struct InterestPoint;
49 
50 #define NARF_DEFAULT_SURFACE_PATCH_PIXEL_SIZE 10
51 
59  {
60  public:
61  // =====CONSTRUCTOR & DESTRUCTOR=====
63  Narf();
65  Narf(const Narf& other);
67  ~Narf();
68 
69  // =====Operators=====
71  const Narf& operator=(const Narf& other);
72 
73  // =====STATIC=====
75  static int max_no_of_threads;
76 
78  static void
79  extractFromRangeImageAndAddToList (const RangeImage& range_image, const Eigen::Vector3f& interest_point, int descriptor_size,
80  float support_size, bool rotation_invariant, std::vector<Narf*>& feature_list);
82  static void
83  extractFromRangeImageAndAddToList (const RangeImage& range_image, float image_x, float image_y, int descriptor_size,
84  float support_size, bool rotation_invariant, std::vector<Narf*>& feature_list);
86  static void
87  extractForInterestPoints (const RangeImage& range_image, const PointCloud<InterestPoint>& interest_points,
88  int descriptor_size, float support_size, bool rotation_invariant, std::vector<Narf*>& feature_list);
90  static void
91  extractForEveryRangeImagePointAndAddToList (const RangeImage& range_image, int descriptor_size, float support_size,
92  bool rotation_invariant, std::vector<Narf*>& feature_list);
93 
94  // =====PUBLIC METHODS=====
100  bool
101  extractFromRangeImage (const RangeImage& range_image, const Eigen::Affine3f& pose, int descriptor_size, float support_size,
102  int surface_patch_world_size=NARF_DEFAULT_SURFACE_PATCH_PIXEL_SIZE);
103 
105  bool
106  extractFromRangeImage (const RangeImage& range_image, float x, float y, int descriptor_size, float support_size);
107 
109  bool
110  extractFromRangeImage (const RangeImage& range_image, const InterestPoint& interest_point, int descriptor_size, float support_size);
111 
113  bool
114  extractFromRangeImage (const RangeImage& range_image, const Eigen::Vector3f& interest_point, int descriptor_size, float support_size);
115 
118  bool
119  extractFromRangeImageWithBestRotation (const RangeImage& range_image, const Eigen::Vector3f& interest_point,
120  int descriptor_size, float support_size);
121 
122  /* Get the dominant rotations of the current descriptor
123  * \param rotations the returned rotations
124  * \param strength values describing how pronounced the corresponding rotations are
125  */
126  void
127  getRotations (std::vector<float>& rotations, std::vector<float>& strengths) const;
128 
129  /* Get the feature with a different rotation around the normal
130  * You are responsible for deleting the new features!
131  * \param range_image the source from which the feature is extracted
132  * \param rotations list of angles (in radians)
133  * \param rvps returned features
134  */
135  void
136  getRotatedVersions (const RangeImage& range_image, const std::vector<float>& rotations, std::vector<Narf*>& features) const;
137 
139  inline float
140  getDescriptorDistance (const Narf& other) const;
141 
143  inline int
144  getNoOfBeamPoints () const { return (static_cast<int> (pcl_lrint (ceil (0.5f * float (surface_patch_pixel_size_))))); }
145 
147  inline void
148  copyToNarf36 (Narf36& narf36) const;
149 
151  void
152  saveBinary (const std::string& filename) const;
154  void
155  saveBinary (std::ostream& file) const;
156 
158  void
159  loadBinary (const std::string& filename);
161  void
162  loadBinary (std::istream& file);
163 
165  bool
166  extractDescriptor (int descriptor_size);
167 
168  // =====GETTERS=====
170  inline const float*
171  getDescriptor () const { return descriptor_;}
173  inline float*
174  getDescriptor () { return descriptor_;}
176  inline const int&
177  getDescriptorSize () const { return descriptor_size_;}
179  inline int&
180  getDescriptorSize () { return descriptor_size_;}
182  inline const Eigen::Vector3f&
183  getPosition () const { return position_;}
185  inline Eigen::Vector3f&
186  getPosition () { return position_;}
188  inline const Eigen::Affine3f&
189  getTransformation () const { return transformation_;}
191  inline Eigen::Affine3f&
192  getTransformation () { return transformation_;}
194  inline const int&
195  getSurfacePatchPixelSize () const { return surface_patch_pixel_size_;}
197  inline int&
198  getSurfacePatchPixelSize () { return surface_patch_pixel_size_;}
200  inline const float&
201  getSurfacePatchWorldSize () const { return surface_patch_world_size_;}
203  inline float&
204  getSurfacePatchWorldSize () { return surface_patch_world_size_;}
206  inline const float&
207  getSurfacePatchRotation () const { return surface_patch_rotation_;}
209  inline float&
210  getSurfacePatchRotation () { return surface_patch_rotation_;}
212  inline const float*
213  getSurfacePatch () const { return surface_patch_;}
215  inline float*
216  getSurfacePatch () { return surface_patch_;}
218  inline void
219  freeSurfacePatch () { delete[] surface_patch_; surface_patch_=NULL; surface_patch_pixel_size_=0; }
220 
221  // =====SETTERS=====
223  inline void
224  setDescriptor (float* descriptor) { descriptor_ = descriptor;}
226  inline void
227  setSurfacePatch (float* surface_patch) { surface_patch_ = surface_patch;}
228 
229  // =====PUBLIC MEMBER VARIABLES=====
230 
231  // =====PUBLIC STRUCTS=====
233  {
234  typedef Narf* PointT;
235  FeaturePointRepresentation(int nr_dimensions) { this->nr_dimensions_ = nr_dimensions; }
236  virtual void copyToFloatArray (const PointT& p, float* out) const { memcpy(out, p->getDescriptor(), sizeof(*p->getDescriptor())*this->nr_dimensions_); }
237  };
238 
239  protected:
240  // =====PROTECTED METHODS=====
242  void
243  reset ();
245  void
246  deepCopy (const Narf& other);
248  float*
249  getBlurredSurfacePatch (int new_pixel_size, int blur_radius) const;
250 
252  void
253  saveHeader (std::ostream& file) const;
255  int
256  loadHeader (std::istream& file) const;
257 
258  // =====PROTECTED STATIC METHODS=====
259  static const std::string
260  getHeaderKeyword () { return "NARF"; }
261 
262  // =====PROTECTED STATIC VARIABLES=====
263  const static int VERSION = 1;
264 
265  // =====PROTECTED MEMBER VARIABLES=====
266  Eigen::Vector3f position_;
267  Eigen::Affine3f transformation_;
268  float* surface_patch_;
269  int surface_patch_pixel_size_;
270  float surface_patch_world_size_;
271  float surface_patch_rotation_;
272  float* descriptor_;
273  int descriptor_size_;
274 
275  // =====STATIC PROTECTED=====
276 
277  public:
278  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
279  };
280 #undef NARF_DEFAULT_SURFACE_PATCH_PIXEL_SIZE
281 
282 } // end namespace pcl
283 
285 
286 #endif //#ifndef PCL_NARF_H_