Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plane_coefficient_comparator.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id: plane_coefficient_comparator.h 5494 2012-04-04 02:12:25Z rusu $
37  *
38  */
39 
40 #ifndef PCL_SEGMENTATION_PLANE_COEFFICIENT_COMPARATOR_H_
41 #define PCL_SEGMENTATION_PLANE_COEFFICIENT_COMPARATOR_H_
42 
43 #include <pcl/common/angles.h>
45 #include <boost/make_shared.hpp>
46 
47 namespace pcl
48 {
54  template<typename PointT, typename PointNT>
55  class PlaneCoefficientComparator: public Comparator<PointT>
56  {
57  public:
60 
62  typedef typename PointCloudN::Ptr PointCloudNPtr;
64 
65  typedef boost::shared_ptr<PlaneCoefficientComparator<PointT, PointNT> > Ptr;
66  typedef boost::shared_ptr<const PlaneCoefficientComparator<PointT, PointNT> > ConstPtr;
67 
69 
72  : normals_ ()
73  , plane_coeff_d_ ()
74  , angular_threshold_ (pcl::deg2rad (2.0f))
75  , distance_threshold_ (0.02f)
76  , depth_dependent_ (true)
77  , z_axis_ (Eigen::Vector3f (0.0, 0.0, 1.0) )
78  {
79  }
80 
84  PlaneCoefficientComparator (boost::shared_ptr<std::vector<float> >& plane_coeff_d)
85  : normals_ ()
86  , plane_coeff_d_ (plane_coeff_d)
87  , angular_threshold_ (pcl::deg2rad (2.0f))
88  , distance_threshold_ (0.02f)
89  , depth_dependent_ (true)
90  , z_axis_ (Eigen::Vector3f (0.0f, 0.0f, 1.0f) )
91  {
92  }
93 
95  virtual
97  {
98  }
99 
100  virtual void
102  {
103  input_ = cloud;
104  }
105 
109  inline void
111  {
112  normals_ = normals;
113  }
114 
116  inline PointCloudNConstPtr
118  {
119  return (normals_);
120  }
121 
125  void
126  setPlaneCoeffD (boost::shared_ptr<std::vector<float> >& plane_coeff_d)
127  {
128  plane_coeff_d_ = plane_coeff_d;
129  }
130 
134  void
135  setPlaneCoeffD (std::vector<float>& plane_coeff_d)
136  {
137  plane_coeff_d_ = boost::make_shared<std::vector<float> >(plane_coeff_d);
138  }
139 
141  const std::vector<float>&
142  getPlaneCoeffD () const
143  {
144  return (plane_coeff_d_);
145  }
146 
150  virtual void
151  setAngularThreshold (float angular_threshold)
152  {
153  angular_threshold_ = cosf (angular_threshold);
154  }
155 
157  inline float
159  {
160  return (acosf (angular_threshold_) );
161  }
162 
167  void
168  setDistanceThreshold (float distance_threshold,
169  bool depth_dependent = false)
170  {
171  distance_threshold_ = distance_threshold;
172  depth_dependent_ = depth_dependent;
173  }
174 
176  inline float
178  {
179  return (distance_threshold_);
180  }
181 
187  virtual bool
188  compare (int idx1, int idx2) const
189  {
190  float threshold = distance_threshold_;
191  if (depth_dependent_)
192  {
193  Eigen::Vector3f vec = input_->points[idx1].getVector3fMap ();
194 
195  float z = vec.dot (z_axis_);
196  threshold *= z * z;
197  }
198  return ( (fabs ((*plane_coeff_d_)[idx1] - (*plane_coeff_d_)[idx2]) < threshold)
199  && (normals_->points[idx1].getNormalVector3fMap ().dot (normals_->points[idx2].getNormalVector3fMap () ) > angular_threshold_ ) );
200  }
201 
202  protected:
203  PointCloudNConstPtr normals_;
204  boost::shared_ptr<std::vector<float> > plane_coeff_d_;
205  float angular_threshold_;
206  float distance_threshold_;
207  bool depth_dependent_;
208  Eigen::Vector3f z_axis_;
209 
210  public:
211  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
212  };
213 }
214 
215 #endif // PCL_SEGMENTATION_PLANE_COEFFICIENT_COMPARATOR_H_