Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
correspondence_rejection_features.hpp
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-2011, 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  *
37  */
38 #ifndef PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_FEATURES_HPP_
39 #define PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_FEATURES_HPP_
40 
42 void
44  const pcl::Correspondences& original_correspondences,
45  pcl::Correspondences& remaining_correspondences)
46 {
47  unsigned int number_valid_correspondences = 0;
48  remaining_correspondences.resize (original_correspondences.size ());
49  // For each set of features, go over each correspondence from input_correspondences_
50  for (size_t i = 0; i < input_correspondences_->size (); ++i)
51  {
52  // Go over the map of features
53  for (FeaturesMap::const_iterator it = features_map_.begin (); it != features_map_.end (); ++it)
54  {
55  // Check if the score in feature space is above the given threshold
56  // (assume that the number of feature correspondenecs is the same as the number of point correspondences)
57  if (!it->second->isCorrespondenceValid (static_cast<int> (i)))
58  break;
59 
60  remaining_correspondences[number_valid_correspondences] = original_correspondences[i];
61  ++number_valid_correspondences;
62  }
63  }
64  remaining_correspondences.resize (number_valid_correspondences);
65 }
66 
68 template <typename FeatureT> inline void
70  const typename pcl::PointCloud<FeatureT>::ConstPtr &source_feature, const std::string &key)
71 {
72  if (features_map_.count (key) == 0)
73  features_map_[key].reset (new FeatureContainer<FeatureT>);
74  boost::static_pointer_cast<FeatureContainer<FeatureT> > (features_map_[key])->setSourceFeature (source_feature);
75 }
76 
78 template <typename FeatureT> inline typename pcl::PointCloud<FeatureT>::ConstPtr
80 {
81  if (features_map_.count (key) == 0)
82  return (boost::shared_ptr<pcl::PointCloud<const FeatureT> > ());
83  else
84  return (boost::static_pointer_cast<FeatureContainer<FeatureT> > (features_map_[key])->getSourceFeature ());
85 }
86 
88 template <typename FeatureT> inline void
90  const typename pcl::PointCloud<FeatureT>::ConstPtr &target_feature, const std::string &key)
91 {
92  if (features_map_.count (key) == 0)
93  features_map_[key].reset (new FeatureContainer<FeatureT>);
94  boost::static_pointer_cast<FeatureContainer<FeatureT> > (features_map_[key])->setTargetFeature (target_feature);
95 }
96 
98 template <typename FeatureT> inline typename pcl::PointCloud<FeatureT>::ConstPtr
100 {
101  typedef pcl::PointCloud<FeatureT> FeatureCloud;
102  typedef typename FeatureCloud::ConstPtr FeatureCloudConstPtr;
103 
104  if (features_map_.count (key) == 0)
105  return (boost::shared_ptr<const pcl::PointCloud<FeatureT> > ());
106  else
107  return (boost::static_pointer_cast<FeatureContainer<FeatureT> > (features_map_[key])->getTargetFeature ());
108 }
109 
111 template <typename FeatureT> inline void
113  double thresh, const std::string &key)
114 {
115  if (features_map_.count (key) == 0)
116  features_map_[key].reset (new FeatureContainer<FeatureT>);
117  boost::static_pointer_cast<FeatureContainer<FeatureT> > (features_map_[key])->setDistanceThreshold (thresh);
118 }
119 
121 inline bool
123 {
124  if (features_map_.empty ())
125  return (false);
126  FeaturesMap::const_iterator feature_itr;
127  for (feature_itr = features_map_.begin (); feature_itr != features_map_.end (); ++feature_itr)
128  if (!feature_itr->second->isValid ())
129  return (false);
130  return (true);
131 }
132 
134 template <typename FeatureT> inline void
137  const std::string &key)
138 {
139  if (features_map_.count (key) == 0)
140  features_map_[key].reset (new FeatureContainer<FeatureT>);
141  boost::static_pointer_cast<FeatureContainer<FeatureT> > (features_map_[key])->setFeatureRepresentation (fr);
142 }
143 
144 
145 #endif /* PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_FEATURES_HPP_ */