Point Cloud Library (PCL)  1.12.1-dev
correspondence_rejection_organized_boundary.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2009-2012, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  * Copyright (c) Alexandru-Eugen Ichim
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * * Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * * Redistributions in binary form must reproduce the above
18  * copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided
20  * with the distribution.
21  * * Neither the name of the copyright holder(s) nor the names of its
22  * contributors may be used to endorse or promote products derived
23  * from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #pragma once
40 
41 #include <pcl/registration/correspondence_rejection.h>
42 #include <pcl/conversions.h> // for fromPCLPointCloud2
43 #include <pcl/memory.h> // for static_pointer_cast
44 
45 namespace pcl {
46 namespace registration {
47 /**
48  * @brief The CorrespondenceRejectionOrganizedBoundary class implements a simple
49  * correspondence rejection measure. For each pair of points in correspondence, it
50  * checks whether they are on the boundary of a silhouette. This is done by counting the
51  * number of NaN dexels in a window around the points (the threshold and window size can
52  * be set by the user). \note Both the source and the target clouds need to be
53  * organized, otherwise all the correspondences will be rejected.
54  *
55  * \author Alexandru E. Ichim
56  * \ingroup registration
57  */
59 : public CorrespondenceRejector {
60 public:
61  /** @brief Empty constructor. */
63  : boundary_nans_threshold_(8), window_size_(5), depth_step_threshold_(0.025f)
64  {}
65 
66  void
67  getRemainingCorrespondences(const pcl::Correspondences& original_correspondences,
68  pcl::Correspondences& remaining_correspondences) override;
69 
70  inline void
72  {
73  boundary_nans_threshold_ = val;
74  }
75 
76  template <typename PointT>
77  inline void
79  {
80  if (!data_container_)
81  data_container_.reset(new pcl::registration::DataContainer<PointT>);
82  static_pointer_cast<pcl::registration::DataContainer<PointT>>(data_container_)
83  ->setInputSource(cloud);
84  }
85 
86  template <typename PointT>
87  inline void
89  {
90  if (!data_container_)
91  data_container_.reset(new pcl::registration::DataContainer<PointT>);
92  static_pointer_cast<pcl::registration::DataContainer<PointT>>(data_container_)
93  ->setInputTarget(cloud);
94  }
95 
96  /** \brief See if this rejector requires source points */
97  bool
98  requiresSourcePoints() const override
99  {
100  return (true);
101  }
102 
103  /** \brief Blob method for setting the source cloud */
104  void
106  {
108  fromPCLPointCloud2(*cloud2, *cloud);
109  setInputSource<PointXYZ>(cloud);
110  }
111 
112  /** \brief See if this rejector requires a target cloud */
113  bool
114  requiresTargetPoints() const override
115  {
116  return (true);
117  }
118 
119  /** \brief Method for setting the target cloud */
120  void
122  {
124  fromPCLPointCloud2(*cloud2, *cloud);
125  setInputTarget<PointXYZ>(cloud);
126  }
127 
128  virtual bool
129  updateSource(const Eigen::Matrix4d&)
130  {
131  return (true);
132  }
133 
134 protected:
135  /** \brief Apply the rejection algorithm.
136  * \param[out] correspondences the set of resultant correspondences.
137  */
138  inline void
139  applyRejection(pcl::Correspondences& correspondences) override
140  {
141  getRemainingCorrespondences(*input_correspondences_, correspondences);
142  }
143 
147 
150 };
151 } // namespace registration
152 } // namespace pcl
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
The CorrespondenceRejectionOrganizedBoundary class implements a simple correspondence rejection measu...
void setInputTarget(const typename pcl::PointCloud< PointT >::ConstPtr &cloud)
bool requiresTargetPoints() const override
See if this rejector requires a target cloud.
void setSourcePoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
Blob method for setting the source cloud.
void setTargetPoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
Method for setting the target cloud.
void setInputSource(const typename pcl::PointCloud< PointT >::ConstPtr &cloud)
void applyRejection(pcl::Correspondences &correspondences) override
Apply the rejection algorithm.
void getRemainingCorrespondences(const pcl::Correspondences &original_correspondences, pcl::Correspondences &remaining_correspondences) override
Get a list of valid correspondences after rejection from the original set of correspondences.
bool requiresSourcePoints() const override
See if this rejector requires source points.
CorrespondenceRejector represents the base class for correspondence rejection methods
DataContainer is a container for the input and target point clouds and implements the interface to co...
shared_ptr< DataContainerInterface > Ptr
Defines functions, macros and traits for allocating and using memory.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
void fromPCLPointCloud2(const pcl::PCLPointCloud2 &msg, pcl::PointCloud< PointT > &cloud, const MsgFieldMap &field_map)
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map.
Definition: conversions.h:164
#define PCL_EXPORTS
Definition: pcl_macros.h:323
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr