Point Cloud Library (PCL)  1.7.1
correspondence.h
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  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 #ifndef PCL_COMMON_CORRESPONDENCE_H_
39 #define PCL_COMMON_CORRESPONDENCE_H_
40 
41 #ifdef __GNUC__
42 #pragma GCC system_header
43 #endif
44 
45 #include <boost/shared_ptr.hpp>
46 #include <Eigen/StdVector>
47 #include <Eigen/Geometry>
48 #include <pcl/pcl_exports.h>
49 
50 namespace pcl
51 {
52  /** \brief Correspondence represents a match between two entities (e.g., points, descriptors, etc). This is
53  * represesented via the indices of a \a source point and a \a target point, and the distance between them.
54  *
55  * \author Dirk Holz, Radu B. Rusu, Bastian Steder
56  * \ingroup common
57  */
59  {
60  /** \brief Index of the query (source) point. */
62  /** \brief Index of the matching (target) point. Set to -1 if no correspondence found. */
64  /** \brief Distance between the corresponding points, or the weight denoting the confidence in correspondence estimation */
65  union
66  {
67  float distance;
68  float weight;
69  };
70 
71  /** \brief Standard constructor.
72  * Sets \ref index_query to 0, \ref index_match to -1, and \ref distance to FLT_MAX.
73  */
74  inline Correspondence () : index_query (0), index_match (-1),
75  distance (std::numeric_limits<float>::max ())
76  {}
77 
78  /** \brief Constructor. */
79  inline Correspondence (int _index_query, int _index_match, float _distance) :
80  index_query (_index_query), index_match (_index_match), distance (_distance)
81  {}
82 
83  /** \brief Empty destructor. */
84  virtual ~Correspondence () {}
85 
86  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
87  };
88 
89  /** \brief overloaded << operator */
90  PCL_EXPORTS std::ostream& operator << (std::ostream& os, const Correspondence& c);
91 
92  typedef std::vector< pcl::Correspondence, Eigen::aligned_allocator<pcl::Correspondence> > Correspondences;
93  typedef boost::shared_ptr<Correspondences> CorrespondencesPtr;
94  typedef boost::shared_ptr<const Correspondences > CorrespondencesConstPtr;
95 
96  /**
97  * \brief Get the query points of correspondences that are present in
98  * one correspondence vector but not in the other, e.g., to compare
99  * correspondences before and after rejection.
100  * \param[in] correspondences_before Vector of correspondences before rejection
101  * \param[in] correspondences_after Vector of correspondences after rejection
102  * \param[out] indices Query point indices of correspondences that have been rejected
103  * \param[in] presorting_required Enable/disable internal sorting of vectors.
104  * By default (true), vectors are internally sorted before determining their difference.
105  * If the order of correspondences in \a correspondences_after is not different (has not been changed)
106  * from the order in \b correspondences_before this pre-processing step can be disabled
107  * in order to gain efficiency. In order to disable pre-sorting set \a presorting_requered to false.
108  */
109  void
110  getRejectedQueryIndices (const pcl::Correspondences &correspondences_before,
111  const pcl::Correspondences &correspondences_after,
112  std::vector<int>& indices,
113  bool presorting_required = true);
114 
115  /**
116  * \brief Representation of a (possible) correspondence between two 3D points in two different coordinate frames
117  * (e.g. from feature matching)
118  * \ingroup common
119  */
121  {
122  Eigen::Vector3f point1; //!< The 3D position of the point in the first coordinate frame
123  Eigen::Vector3f point2; //!< The 3D position of the point in the second coordinate frame
124 
125  /** \brief Empty constructor. */
127 
128  /** \brief Empty destructor. */
130 
131  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
132  };
133  typedef std::vector<PointCorrespondence3D, Eigen::aligned_allocator<PointCorrespondence3D> > PointCorrespondences3DVector;
134 
135  /**
136  * \brief Representation of a (possible) correspondence between two points (e.g. from feature matching),
137  * that encode complete 6DOF transoformations.
138  * \ingroup common
139  */
141  {
142  Eigen::Affine3f transformation; //!< The transformation to go from the coordinate system
143  //!< of point2 to the coordinate system of point1
144  /** \brief Empty destructor. */
146 
147  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
148  };
149  typedef std::vector<PointCorrespondence6D, Eigen::aligned_allocator<PointCorrespondence6D> > PointCorrespondences6DVector;
150 
151  /**
152  * \brief Comparator to enable us to sort a vector of PointCorrespondences according to their scores using
153  * std::sort (begin(), end(), isBetterCorrespondence);
154  * \ingroup common
155  */
156  inline bool
158  {
159  return (pc1.distance > pc2.distance);
160  }
161 }
162 
163 #endif /* PCL_COMMON_CORRESPONDENCE_H_ */