NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
correspondence_rejection_surface_normal2.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) 2012-, Open Perception, 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 the copyright holder(s) 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$
37  *
38  */
39 #ifndef PCL_REGISTRATION_CORRESPONDENCE_REJECTION_SURFACE_NORMAL2_H_ // NOLINT
40 #define PCL_REGISTRATION_CORRESPONDENCE_REJECTION_SURFACE_NORMAL2_H_ // NOLINT
41 
42 #include <pcl/registration/correspondence_rejection.h>
43 #include <pcl/point_cloud.h>
44 
45 namespace pcl {
46 namespace registration {
47 // TODO(rsoussan): This fixes a bug in PCL for setSourceNormals, where PCL hardcodes the normal type to pcl::Normal
48 // when it should use NormalT. Switch back to PCL implementation when this is fixed. Additionally this should be
49 // either fixed in setTargetNormals or requiresTargetNormals should return false (ideally the second, and
50 // requires*Points should also be false).
62 template <typename PointWithNormalT>
63 class PCL_EXPORTS CorrespondenceRejectorSurfaceNormal2 : public CorrespondenceRejector {
64  using CorrespondenceRejector::getClassName;
65  using CorrespondenceRejector::input_correspondences_;
66  using CorrespondenceRejector::rejection_name_;
67 
68  public:
69  typedef boost::shared_ptr<CorrespondenceRejectorSurfaceNormal2> Ptr;
70  typedef boost::shared_ptr<const CorrespondenceRejectorSurfaceNormal2> ConstPtr;
71 
73  CorrespondenceRejectorSurfaceNormal2() : threshold_(1.0), data_container_() {
74  rejection_name_ = "CorrespondenceRejectorSurfaceNormal2";
75  }
76 
81  // void
82  // getRemainingCorrespondences (const pcl::Correspondences& original_correspondences,
83  // pcl::Correspondences& remaining_correspondences);
84 
88  inline void setThreshold(double threshold) { threshold_ = threshold; }
89 
91  inline double getThreshold() const { return threshold_; }
92 
93  void getRemainingCorrespondences(const pcl::Correspondences& original_correspondences,
94  pcl::Correspondences& remaining_correspondences) {
95  if (!data_container_) {
96  PCL_ERROR("[pcl::registratin::%s::getRemainingCorrespondences] DataContainer object is not initialized!\n",
97  getClassName().c_str());
98  return;
99  }
100 
101  unsigned int number_valid_correspondences = 0;
102  remaining_correspondences.resize(original_correspondences.size());
103 
104  // Test each correspondence
105  for (size_t i = 0; i < original_correspondences.size(); ++i) {
106  // TODO(rsoussan): Abs val?
107  if (std::abs(boost::static_pointer_cast<DataContainer<PointWithNormalT, PointWithNormalT> >(data_container_)
108  ->getCorrespondenceScoreFromNormals(original_correspondences[i])) > threshold_) {
109  remaining_correspondences[number_valid_correspondences++] = original_correspondences[i];
110  }
111  }
112  remaining_correspondences.resize(number_valid_correspondences);
113  }
114 
116  inline void initializeDataContainer() {
117  data_container_.reset(new DataContainer<PointWithNormalT, PointWithNormalT>);
118  }
119 
123  inline void setInputCloud(const typename pcl::PointCloud<PointWithNormalT>::ConstPtr& input) {
124  PCL_WARN("[pcl::registration::%s::setInputCloud] setInputCloud is deprecated. Please use setInputSource instead.\n",
125  getClassName().c_str());
126  if (!data_container_) {
127  PCL_ERROR(
128  "[pcl::registration::%s::setInputCloud] Initialize the data container object by calling intializeDataContainer "
129  "() before using this function.\n",
130  getClassName().c_str());
131  return;
132  }
133  boost::static_pointer_cast<DataContainer<PointWithNormalT> >(data_container_)->setInputSource(input);
134  }
135 
139  inline void setInputSource(const typename pcl::PointCloud<PointWithNormalT>::ConstPtr& input) {
140  if (!data_container_) {
141  PCL_ERROR(
142  "[pcl::registration::%s::setInputCloud] Initialize the data container object by calling intializeDataContainer "
143  "() before using this function.\n",
144  getClassName().c_str());
145  return;
146  }
147  boost::static_pointer_cast<DataContainer<PointWithNormalT> >(data_container_)->setInputSource(input);
148  }
149 
151  inline typename pcl::PointCloud<PointWithNormalT>::ConstPtr getInputSource() const {
152  if (!data_container_) {
153  PCL_ERROR(
154  "[pcl::registration::%s::getInputSource] Initialize the data container object by calling "
155  "intializeDataContainer () before using this function.\n",
156  getClassName().c_str());
157  return;
158  }
159  return (boost::static_pointer_cast<DataContainer<PointWithNormalT> >(data_container_)->getInputSource());
160  }
161 
165  inline void setInputTarget(const typename pcl::PointCloud<PointWithNormalT>::ConstPtr& target) {
166  if (!data_container_) {
167  PCL_ERROR(
168  "[pcl::registration::%s::setInputTarget] Initialize the data container object by calling "
169  "intializeDataContainer () before using this function.\n",
170  getClassName().c_str());
171  return;
172  }
173  boost::static_pointer_cast<DataContainer<PointWithNormalT> >(data_container_)->setInputTarget(target);
174  }
175 
183  inline void setSearchMethodTarget(const boost::shared_ptr<pcl::search::KdTree<PointWithNormalT> >& tree,
184  bool force_no_recompute = false) {
185  boost::static_pointer_cast<DataContainer<PointWithNormalT> >(data_container_)
186  ->setSearchMethodTarget(tree, force_no_recompute);
187  }
188 
190  inline typename pcl::PointCloud<PointWithNormalT>::ConstPtr getInputTarget() const {
191  if (!data_container_) {
192  PCL_ERROR(
193  "[pcl::registration::%s::getInputTarget] Initialize the data container object by calling "
194  "intializeDataContainer () before using this function.\n",
195  getClassName().c_str());
196  return;
197  }
198  return (boost::static_pointer_cast<DataContainer<PointWithNormalT> >(data_container_)->getInputTarget());
199  }
200 
204  inline void setInputNormals(const typename pcl::PointCloud<PointWithNormalT>::ConstPtr& normals) {
205  if (!data_container_) {
206  PCL_ERROR(
207  "[pcl::registration::%s::setInputNormals] Initialize the data container object by calling "
208  "intializeDataContainer () before using this function.\n",
209  getClassName().c_str());
210  return;
211  }
212  boost::static_pointer_cast<DataContainer<PointWithNormalT, PointWithNormalT> >(data_container_)
213  ->setInputNormals(normals);
214  }
215 
217  inline typename pcl::PointCloud<PointWithNormalT>::Ptr getInputNormals() const {
218  if (!data_container_) {
219  PCL_ERROR(
220  "[pcl::registration::%s::getInputNormals] Initialize the data container object by calling "
221  "intializeDataContainer () before using this function.\n",
222  getClassName().c_str());
223  return;
224  }
225  return (boost::static_pointer_cast<DataContainer<PointWithNormalT, PointWithNormalT> >(data_container_)
226  ->getInputNormals());
227  }
228 
232  inline void setTargetNormals(const typename pcl::PointCloud<PointWithNormalT>::ConstPtr& normals) {
233  if (!data_container_) {
234  PCL_ERROR(
235  "[pcl::registration::%s::setTargetNormals] Initialize the data container object by calling "
236  "intializeDataContainer () before using this function.\n",
237  getClassName().c_str());
238  return;
239  }
240  boost::static_pointer_cast<DataContainer<PointWithNormalT, PointWithNormalT> >(data_container_)
241  ->setTargetNormals(normals);
242  }
243 
245  inline typename pcl::PointCloud<PointWithNormalT>::Ptr getTargetNormals() const {
246  if (!data_container_) {
247  PCL_ERROR(
248  "[pcl::registration::%s::getTargetNormals] Initialize the data container object by calling "
249  "intializeDataContainer () before using this function.\n",
250  getClassName().c_str());
251  return;
252  }
253  return (boost::static_pointer_cast<DataContainer<PointWithNormalT, PointWithNormalT> >(data_container_)
254  ->getTargetNormals());
255  }
256 
258  bool requiresSourcePoints() const { return (false); }
259 
261  void setSourcePoints(pcl::PCLPointCloud2::ConstPtr cloud2) {
262  if (!data_container_) initializeDataContainer();
263  typename PointCloud<PointWithNormalT>::Ptr cloud(new PointCloud<PointWithNormalT>);
264  fromPCLPointCloud2(*cloud2, *cloud);
265  setInputSource(cloud);
266  }
267 
269  bool requiresTargetPoints() const { return (false); }
270 
272  void setTargetPoints(pcl::PCLPointCloud2::ConstPtr cloud2) {
273  if (!data_container_) initializeDataContainer();
274  typename PointCloud<PointWithNormalT>::Ptr cloud(new PointCloud<PointWithNormalT>);
275  fromPCLPointCloud2(*cloud2, *cloud);
276  setInputTarget(cloud);
277  }
278 
280  bool requiresSourceNormals() const { return (true); }
281 
283  void setSourceNormals(pcl::PCLPointCloud2::ConstPtr cloud2) {
284  if (!data_container_) initializeDataContainer();
285  typename PointCloud<PointWithNormalT>::Ptr cloud(new PointCloud<PointWithNormalT>);
286  fromPCLPointCloud2(*cloud2, *cloud);
287  setInputNormals(cloud);
288  }
289 
291  bool requiresTargetNormals() const { return (false); }
292 
294  void setTargetNormals(pcl::PCLPointCloud2::ConstPtr cloud2) {
295  if (!data_container_) initializeDataContainer();
296  typename PointCloud<PointWithNormalT>::Ptr cloud(new PointCloud<PointWithNormalT>);
297  fromPCLPointCloud2(*cloud2, *cloud);
298  setTargetNormals(cloud);
299  }
300 
301  protected:
305  inline void applyRejection(pcl::Correspondences& correspondences) {
306  getRemainingCorrespondences(*input_correspondences_, correspondences);
307  }
308 
310  double threshold_;
311 
312  typedef boost::shared_ptr<DataContainerInterface> DataContainerPtr;
315 };
316 } // namespace registration
317 } // namespace pcl
318 
319 #endif // NOLINT
pcl
Definition: correspondence_rejection_surface_normal2.h:45
pcl::registration::CorrespondenceRejectorSurfaceNormal2::setInputNormals
void setInputNormals(const typename pcl::PointCloud< PointWithNormalT >::ConstPtr &normals)
Set the normals computed on the input point cloud.
Definition: correspondence_rejection_surface_normal2.h:204
pcl::registration::CorrespondenceRejectorSurfaceNormal2::getInputTarget
pcl::PointCloud< PointWithNormalT >::ConstPtr getInputTarget() const
Get the target input point cloud.
Definition: correspondence_rejection_surface_normal2.h:190
pcl::registration::CorrespondenceRejectorSurfaceNormal2::setTargetPoints
void setTargetPoints(pcl::PCLPointCloud2::ConstPtr cloud2)
Method for setting the target cloud.
Definition: correspondence_rejection_surface_normal2.h:272
pcl::registration::CorrespondenceRejectorSurfaceNormal2::DataContainerPtr
boost::shared_ptr< DataContainerInterface > DataContainerPtr
Definition: correspondence_rejection_surface_normal2.h:312
pcl::registration::CorrespondenceRejectorSurfaceNormal2::Ptr
boost::shared_ptr< CorrespondenceRejectorSurfaceNormal2 > Ptr
Definition: correspondence_rejection_surface_normal2.h:69
pcl::registration::CorrespondenceRejectorSurfaceNormal2::getInputNormals
pcl::PointCloud< PointWithNormalT >::Ptr getInputNormals() const
Get the normals computed on the input point cloud.
Definition: correspondence_rejection_surface_normal2.h:217
pcl::registration::CorrespondenceRejectorSurfaceNormal2::setInputCloud
void setInputCloud(const typename pcl::PointCloud< PointWithNormalT >::ConstPtr &input)
Provide a source point cloud dataset (must contain XYZ data!), used to compute the correspondence dis...
Definition: correspondence_rejection_surface_normal2.h:123
pcl::registration::CorrespondenceRejectorSurfaceNormal2::setTargetNormals
void setTargetNormals(pcl::PCLPointCloud2::ConstPtr cloud2)
Method for setting the target normals.
Definition: correspondence_rejection_surface_normal2.h:294
pcl::registration::CorrespondenceRejectorSurfaceNormal2::setInputTarget
void setInputTarget(const typename pcl::PointCloud< PointWithNormalT >::ConstPtr &target)
Provide a target point cloud dataset (must contain XYZ data!), used to compute the correspondence dis...
Definition: correspondence_rejection_surface_normal2.h:165
pcl::registration::CorrespondenceRejectorSurfaceNormal2::applyRejection
void applyRejection(pcl::Correspondences &correspondences)
Apply the rejection algorithm.
Definition: correspondence_rejection_surface_normal2.h:305
pcl::registration::CorrespondenceRejectorSurfaceNormal2::getRemainingCorrespondences
void getRemainingCorrespondences(const pcl::Correspondences &original_correspondences, pcl::Correspondences &remaining_correspondences)
Definition: correspondence_rejection_surface_normal2.h:93
pcl::registration::CorrespondenceRejectorSurfaceNormal2::setSearchMethodTarget
void setSearchMethodTarget(const boost::shared_ptr< pcl::search::KdTree< PointWithNormalT > > &tree, bool force_no_recompute=false)
Provide a pointer to the search object used to find correspondences in the target cloud.
Definition: correspondence_rejection_surface_normal2.h:183
pcl::registration::CorrespondenceRejectorSurfaceNormal2::setSourceNormals
void setSourceNormals(pcl::PCLPointCloud2::ConstPtr cloud2)
Blob method for setting the source normals.
Definition: correspondence_rejection_surface_normal2.h:283
pcl::registration::CorrespondenceRejectorSurfaceNormal2::getTargetNormals
pcl::PointCloud< PointWithNormalT >::Ptr getTargetNormals() const
Get the normals computed on the target point cloud.
Definition: correspondence_rejection_surface_normal2.h:245
pcl::registration::CorrespondenceRejectorSurfaceNormal2::setSourcePoints
void setSourcePoints(pcl::PCLPointCloud2::ConstPtr cloud2)
Blob method for setting the source cloud.
Definition: correspondence_rejection_surface_normal2.h:261
pcl::registration::CorrespondenceRejectorSurfaceNormal2::data_container_
DataContainerPtr data_container_
A pointer to the DataContainer object containing the input and target point clouds.
Definition: correspondence_rejection_surface_normal2.h:314
pcl::registration::CorrespondenceRejectorSurfaceNormal2::setThreshold
void setThreshold(double threshold)
Get a list of valid correspondences after rejection from the original set of correspondences.
Definition: correspondence_rejection_surface_normal2.h:88
pcl::registration::CorrespondenceRejectorSurfaceNormal2::requiresTargetPoints
bool requiresTargetPoints() const
See if this rejector requires a target cloud.
Definition: correspondence_rejection_surface_normal2.h:269
pcl::registration::CorrespondenceRejectorSurfaceNormal2::initializeDataContainer
void initializeDataContainer()
Initialize the data container object for the point type and the normal type.
Definition: correspondence_rejection_surface_normal2.h:116
pcl::registration::CorrespondenceRejectorSurfaceNormal2::threshold_
double threshold_
The median distance threshold between two correspondent points in source <-> target.
Definition: correspondence_rejection_surface_normal2.h:310
pcl::registration::CorrespondenceRejectorSurfaceNormal2::getThreshold
double getThreshold() const
Get the thresholding angle between the normals for correspondence rejection.
Definition: correspondence_rejection_surface_normal2.h:91
pcl::registration::CorrespondenceRejectorSurfaceNormal2::setTargetNormals
void setTargetNormals(const typename pcl::PointCloud< PointWithNormalT >::ConstPtr &normals)
Set the normals computed on the target point cloud.
Definition: correspondence_rejection_surface_normal2.h:232
pcl::registration::CorrespondenceRejectorSurfaceNormal2::requiresSourceNormals
bool requiresSourceNormals() const
See if this rejector requires source normals.
Definition: correspondence_rejection_surface_normal2.h:280
pcl::registration::CorrespondenceRejectorSurfaceNormal2::requiresTargetNormals
bool requiresTargetNormals() const
See if this rejector requires target normals.
Definition: correspondence_rejection_surface_normal2.h:291
pcl::registration::CorrespondenceRejectorSurfaceNormal2::CorrespondenceRejectorSurfaceNormal2
CorrespondenceRejectorSurfaceNormal2()
Empty constructor. Sets the threshold to 1.0.
Definition: correspondence_rejection_surface_normal2.h:73
pcl::registration::CorrespondenceRejectorSurfaceNormal2::getInputSource
pcl::PointCloud< PointWithNormalT >::ConstPtr getInputSource() const
Get the target input point cloud.
Definition: correspondence_rejection_surface_normal2.h:151
pcl::registration::CorrespondenceRejectorSurfaceNormal2
Definition: correspondence_rejection_surface_normal2.h:63
pcl::registration::CorrespondenceRejectorSurfaceNormal2::setInputSource
void setInputSource(const typename pcl::PointCloud< PointWithNormalT >::ConstPtr &input)
Provide a source point cloud dataset (must contain XYZ data!), used to compute the correspondence dis...
Definition: correspondence_rejection_surface_normal2.h:139
pcl::registration::CorrespondenceRejectorSurfaceNormal2::ConstPtr
boost::shared_ptr< const CorrespondenceRejectorSurfaceNormal2 > ConstPtr
Definition: correspondence_rejection_surface_normal2.h:70
pcl::registration::CorrespondenceRejectorSurfaceNormal2::requiresSourcePoints
bool requiresSourcePoints() const
See if this rejector requires source points.
Definition: correspondence_rejection_surface_normal2.h:258