Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
edge_aware_plane_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: extract_clusters.h 5027 2012-03-12 03:10:45Z rusu $
37  *
38  */
39 
40 #ifndef PCL_SEGMENTATION_EDGE_AWARE_PLANE_COMPARATOR_H_
41 #define PCL_SEGMENTATION_EDGE_AWARE_PLANE_COMPARATOR_H_
42 
44 #include <boost/make_shared.hpp>
45 
46 namespace pcl
47 {
54  template<typename PointT, typename PointNT>
56  {
57  public:
60 
62  typedef typename PointCloudN::Ptr PointCloudNPtr;
64 
65  typedef boost::shared_ptr<EdgeAwarePlaneComparator<PointT, PointNT> > Ptr;
66  typedef boost::shared_ptr<const EdgeAwarePlaneComparator<PointT, PointNT> > ConstPtr;
67 
73 
76  {
77  }
78 
82  EdgeAwarePlaneComparator (const float *distance_map) :
83  distance_map_ (distance_map)
84  {
85  }
86 
88  virtual
90  {
91  }
92 
97  inline void
98  setDistanceMap (const float *distance_map)
99  {
100  distance_map_ = distance_map;
101  }
102 
104  const float*
105  getDistanceMap () const
106  {
107  return (distance_map_);
108  }
109 
110  protected:
115  bool
116  compare (int idx1, int idx2) const
117  {
118  float dx = input_->points[idx1].x - input_->points[idx2].x;
119  float dy = input_->points[idx1].y - input_->points[idx2].y;
120  float dz = input_->points[idx1].z - input_->points[idx2].z;
121  float dist = sqrtf (dx*dx + dy*dy + dz*dz);
122 
123  bool normal_ok = (normals_->points[idx1].getNormalVector3fMap ().dot (normals_->points[idx2].getNormalVector3fMap () ) > angular_threshold_ );
124  bool dist_ok = (dist < distance_threshold_);
125 
126  bool curvature_ok = normals_->points[idx1].curvature < 0.04;
127  bool plane_d_ok = fabs ((*plane_coeff_d_)[idx1] - (*plane_coeff_d_)[idx2]) < 0.04;
128 
129  if (distance_map_[idx1] < 5) // 5 pixels
130  curvature_ok = false;
131 
132  return (dist_ok && normal_ok && curvature_ok && plane_d_ok);
133  }
134 
135  protected:
136  const float* distance_map_;
137  };
138 }
139 
140 #endif // PCL_SEGMENTATION_PLANE_COEFFICIENT_COMPARATOR_H_