Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
range_image_border_extractor.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 #ifndef PCL_RANGE_IMAGE_BORDER_EXTRACTOR_H_
36 #define PCL_RANGE_IMAGE_BORDER_EXTRACTOR_H_
37 
38 #include <pcl/point_types.h>
39 #include <pcl/features/feature.h>
40 
41 #if defined BUILD_Maintainer && defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ > 3
42 #pragma GCC diagnostic ignored "-Weffc++"
43 #endif
44 namespace pcl
45 {
46  // FORWARD DECLARATIONS:
47  class RangeImage;
48  template <typename PointType>
49  class PointCloud;
50 
56  class PCL_EXPORTS RangeImageBorderExtractor : public Feature<PointWithRange,BorderDescription>
57  {
58  public:
59  // =====TYPEDEFS=====
61 
62  // =====PUBLIC STRUCTS=====
64  struct LocalSurface
65  {
67  normal (), neighborhood_mean (), eigen_values (), normal_no_jumps (),
68  neighborhood_mean_no_jumps (), eigen_values_no_jumps (), max_neighbor_distance_squared () {}
69 
70  Eigen::Vector3f normal;
71  Eigen::Vector3f neighborhood_mean;
72  Eigen::Vector3f eigen_values;
73  Eigen::Vector3f normal_no_jumps;
74  Eigen::Vector3f neighborhood_mean_no_jumps;
75  Eigen::Vector3f eigen_values_no_jumps;
77  };
78 
81  {
82  ShadowBorderIndices () : left (-1), right (-1), top (-1), bottom (-1) {}
83  int left, right, top, bottom;
84  };
85 
87  struct Parameters
88  {
89  Parameters () : max_no_of_threads(1), pixel_radius_borders (3), pixel_radius_plane_extraction (2), pixel_radius_border_direction (2),
90  minimum_border_probability (0.8f), pixel_radius_principal_curvature (2) {}
97  };
98 
99  // =====STATIC METHODS=====
103  static inline float
104  getObstacleBorderAngle (const BorderTraits& border_traits);
105 
106  // =====CONSTRUCTOR & DESTRUCTOR=====
108  RangeImageBorderExtractor (const RangeImage* range_image=NULL);
111 
112  // =====METHODS=====
116  void
117  setRangeImage (const RangeImage* range_image);
118 
120  void
121  clearData ();
122 
126  float*
127  getAnglesImageForBorderDirections ();
128 
132  float*
133  getAnglesImageForSurfaceChangeDirections ();
134 
136  void
137  compute (PointCloudOut& output);
138 
139  // =====GETTER=====
140  Parameters&
141  getParameters () { return (parameters_); }
142 
143  bool
144  hasRangeImage () const { return range_image_ != NULL; }
145 
146  const RangeImage&
147  getRangeImage () const { return *range_image_; }
148 
149  float*
150  getBorderScoresLeft () { extractBorderScoreImages (); return border_scores_left_; }
151 
152  float*
153  getBorderScoresRight () { extractBorderScoreImages (); return border_scores_right_; }
154 
155  float*
156  getBorderScoresTop () { extractBorderScoreImages (); return border_scores_top_; }
157 
158  float*
159  getBorderScoresBottom () { extractBorderScoreImages (); return border_scores_bottom_; }
160 
161  LocalSurface**
162  getSurfaceStructure () { extractLocalSurfaceStructure (); return surface_structure_; }
163 
165  getBorderDescriptions () { classifyBorders (); return *border_descriptions_; }
166 
167  ShadowBorderIndices**
168  getShadowBorderInformations () { findAndEvaluateShadowBorders (); return shadow_border_informations_; }
169 
170  Eigen::Vector3f**
171  getBorderDirections () { calculateBorderDirections (); return border_directions_; }
172 
173  float*
174  getSurfaceChangeScores () { calculateSurfaceChanges (); return surface_change_scores_; }
175 
176  Eigen::Vector3f*
177  getSurfaceChangeDirections () { calculateSurfaceChanges (); return surface_change_directions_; }
178 
179 
180  protected:
181  // =====PROTECTED MEMBER VARIABLES=====
182  Parameters parameters_;
183  const RangeImage* range_image_;
184  int range_image_size_during_extraction_;
185  float* border_scores_left_, * border_scores_right_, * border_scores_top_, * border_scores_bottom_;
186  LocalSurface** surface_structure_;
187  PointCloudOut* border_descriptions_;
188  ShadowBorderIndices** shadow_border_informations_;
189  Eigen::Vector3f** border_directions_;
190 
191  float* surface_change_scores_;
192  Eigen::Vector3f* surface_change_directions_;
193 
194 
195  // =====PROTECTED METHODS=====
205  inline float
206  getNeighborDistanceChangeScore (const LocalSurface& local_surface, int x, int y,
207  int offset_x, int offset_y, int pixel_radius=1) const;
208 
217  inline float
218  getNormalBasedBorderScore (const LocalSurface& local_surface, int x, int y,
219  int offset_x, int offset_y) const;
220 
231  inline bool
232  changeScoreAccordingToShadowBorderValue (int x, int y, int offset_x, int offset_y, float* border_scores,
233  float* border_scores_other_direction, int& shadow_border_idx) const;
234 
241  inline float
242  updatedScoreAccordingToNeighborValues (int x, int y, const float* border_scores) const;
243 
248  float*
249  updatedScoresAccordingToNeighborValues (const float* border_scores) const;
250 
252  void
253  updateScoresAccordingToNeighborValues ();
254 
265  inline bool
266  checkPotentialBorder (int x, int y, int offset_x, int offset_y, float* border_scores_left,
267  float* border_scores_right, int& shadow_border_idx) const;
268 
278  inline bool
279  checkIfMaximum (int x, int y, int offset_x, int offset_y, float* border_scores, int shadow_border_idx) const;
280 
282  void
283  findAndEvaluateShadowBorders ();
284 
286  void
287  extractLocalSurfaceStructure ();
288 
292  void
293  extractBorderScoreImages ();
294 
298  void
299  classifyBorders ();
300 
306  inline void
307  calculateBorderDirection (int x, int y);
308 
312  void
313  calculateBorderDirections ();
314 
322  inline bool
323  get3dDirection (const BorderDescription& border_description, Eigen::Vector3f& direction,
324  const LocalSurface* local_surface=NULL);
325 
334  inline bool
335  calculateMainPrincipalCurvature (int x, int y, int radius, float& magnitude,
336  Eigen::Vector3f& main_direction) const;
337 
340  void
341  calculateSurfaceChanges ();
342 
344  void
345  blurSurfaceChanges ();
346 
348  virtual void
349  computeFeature (PointCloudOut &output);
350 
351  private:
355  void
356  computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf>&) {}
357  };
358 } // namespace end
359 #if defined BUILD_Maintainer && defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ > 3
360 #pragma GCC diagnostic warning "-Weffc++"
361 #endif
362 
363 #include <pcl/features/impl/range_image_border_extractor.hpp> // Definitions of templated and inline functions
364 
365 #endif //#ifndef PCL_RANGE_IMAGE_BORDER_EXTRACTOR_H_