iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Normals.H
Go to the documentation of this file.
1 /*! @file
2  @author Shane Grant
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 #ifdef NRT_HAVE_CLOUD
36 #ifndef INCLUDE_NRT_POINTCLOUD2_FEATURES_NORMALS_H
37 #define INCLUDE_NRT_POINTCLOUD2_FEATURES_NORMALS_H
38 
43 
44 namespace nrt
45 {
46  //! A class for computing 3d point normals
47  /*! This class will compute 3d point normals for some point cloud
48  and add them as PointNormals to the set of fields for that cloud.
49 
50  Point normals are computed by solving for the plane parameters for a set of
51  points around each point in the cloud or cloud subset. The normal of this
52  plane fit to these points will describe the local surface normal of the points.
53  A curvature estimate is also calculated, based upon the degree to which the
54  local plane varies along the normal direction. */
55  class Normals : public FeatureBase
56  {
57  public:
58  //! Create a new Normals object
59  /* @param method The search method to use
60  @param searchParam For radius search, the radius in meters. For KNN, the number of neighbors to use (will be cast to int)
61  @param twoPass Whether to use the more numerically stable two-pass covariance calculation, or a faster but less stable one pass version
62  @param viewPoint The viewpoint from which to calculate normals
63  @param searchEpsilon Accuracy of nearest neighbor search */
64  Normals( PointCloudSearchMethod method,
65  double searchParam,
66  bool twoPass = false,
67  PointCloud2::Geometry const & viewPoint = PointCloud2::Geometry(),
68  double searchEpsilon = 0.0 );
69 
70  //! Virtual destruction
71  virtual ~Normals();
72 
73  //! Finds normals for all points in the input
74  /*! This will add the field PointNormals to the output point cloud */
75  virtual PointCloud2 computeFeatures( PointCloud2 const input );
76 
77  //! Finds normals for all points in the subset
78  /*! This will add the field PointNormals to the output point cloud */
79  virtual PointCloud2 computeFeatures( PointCloud2 const input, Indices const subset );
80 
81  //! Computes plane parameters and variation for an entire point cloud
82  /*! @param[in] input The point cloud to use
83  @param[in] twoPass Whether to use the slower but more stable two pass covariance calculation, or the
84  faster but less stable one pass version.
85  @param[in,out] planeParameters If not empty, holds the plane parameters for ax + by + cz + d = 0 (abcd).
86  @param[in,out] variation If not empty, stores the ratio of each eigenvalue over the sum of all eigenvalues.
87  @param[in,out] eigenVectors If not empty, stores the eigen vectors for the plane fit to the cloud */
88  static void computePointNormal( PointCloud2 const input,
89  bool twoPass = false,
90  Optional<PointCloud2::Vector4 &> planeParameters = OptionalEmpty,
91  Optional<PointCloud2::Vector3 &> variation = OptionalEmpty,
92  Optional<PointCloud2::Matrix3 &> eigenVectors = OptionalEmpty );
93 
94  //! Computes plane parameters and variation for a point cloud subset
95  /*! @param[in] input The point cloud to use
96  @param[in] subset The subset of points to consider
97  @param[in] twoPass Whether to use the slower but more stable two pass covariance calculation, or the
98  faster but less stable one pass version.
99  @param[in,out] planeParameters If not empty, holds the plane parameters for ax + by + cz + d = 0 (abcd).
100  @param[in,out] variation If not empty, stores the ratio of each eigenvalue over the sum of all eigenvalues.
101  @param[in,out] eigenVectors If not empty, stores the eigen vectors for the plane fit to the subset */
102  static void computePointNormal( PointCloud2 const input,
103  Indices const subset,
104  bool twoPass = false,
105  Optional<PointCloud2::Vector4 &> planeParameters = OptionalEmpty,
106  Optional<PointCloud2::Vector3 &> variation = OptionalEmpty,
107  Optional<PointCloud2::Matrix3 &> eigenVectors = OptionalEmpty );
108 
109  //! Adjusts a normal according to some viewpoint location
110  /*! @param[in] point The location of the normal
111  @param[in] viewpoint The viewing location from which to adjust the normal
112  @param[in,out] normal The normal, which will be flipped such that it always faces towards the viewpoint */
113  static void faceNormalToViewPoint( PointCloud2::Geometry const & point,
114  PointCloud2::Geometry const & viewpoint,
115  PointCloud2::Vector4 & normal );
116 
117  protected:
118  //! Does the actual work for computing features with radius search
120  PointCloud2::Iterator<PointNormal> && end, Search && search );
121 
122  //! Does the actual work for computing features with knn search
124  PointCloud2::Iterator<PointNormal> && end, Search && search );
125 
126  private:
127  PointCloudSearchMethod itsSearchMethod;
128  double itsSearchParam;
129  bool itsUseTwoPassCovariance;
130  double itsSearchEpsilon;
131  PointCloud2::Geometry itsViewPoint;
132  };
133 } // namespace nrt
134 
135 #endif // INCLUDE_NRT_POINTCLOUD2_FEATURES_FEATUREBASE_H
136 #endif // NRT_HAVE_CLOUD