Point Cloud Library (PCL)  1.9.1-dev
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 
39 #pragma once
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 #include <pcl/pcl_macros.h>
50 
51 namespace pcl
52 {
53  /** \brief Correspondence represents a match between two entities (e.g., points, descriptors, etc). This is
54  * represented via the indices of a \a source point and a \a target point, and the distance between them.
55  *
56  * \author Dirk Holz, Radu B. Rusu, Bastian Steder
57  * \ingroup common
58  */
60  {
61  /** \brief Index of the query (source) point. */
63  /** \brief Index of the matching (target) point. Set to -1 if no correspondence found. */
65  /** \brief Distance between the corresponding points, or the weight denoting the confidence in correspondence estimation */
66  union
67  {
68  float distance;
69  float weight;
70  };
71 
72  /** \brief Standard constructor.
73  * Sets \ref index_query to 0, \ref index_match to -1, and \ref distance to FLT_MAX.
74  */
75  inline Correspondence () : index_query (0), index_match (-1),
76  distance (std::numeric_limits<float>::max ())
77  {}
78 
79  /** \brief Constructor. */
80  inline Correspondence (int _index_query, int _index_match, float _distance) :
81  index_query (_index_query), index_match (_index_match), distance (_distance)
82  {}
83 
84  /** \brief Empty destructor. */
85  virtual ~Correspondence () {}
86 
88  };
89 
90  /** \brief overloaded << operator */
91  PCL_EXPORTS std::ostream& operator << (std::ostream& os, const Correspondence& c);
92 
93  using Correspondences = std::vector< pcl::Correspondence, Eigen::aligned_allocator<pcl::Correspondence> >;
94  using CorrespondencesPtr = boost::shared_ptr<Correspondences>;
95  using CorrespondencesConstPtr = boost::shared_ptr<const Correspondences >;
96 
97  /**
98  * \brief Get the query points of correspondences that are present in
99  * one correspondence vector but not in the other, e.g., to compare
100  * correspondences before and after rejection.
101  * \param[in] correspondences_before Vector of correspondences before rejection
102  * \param[in] correspondences_after Vector of correspondences after rejection
103  * \param[out] indices Query point indices of correspondences that have been rejected
104  * \param[in] presorting_required Enable/disable internal sorting of vectors.
105  * By default (true), vectors are internally sorted before determining their difference.
106  * If the order of correspondences in \a correspondences_after is not different (has not been changed)
107  * from the order in \b correspondences_before this pre-processing step can be disabled
108  * in order to gain efficiency. In order to disable pre-sorting set \a presorting_required to false.
109  */
110  void
111  getRejectedQueryIndices (const pcl::Correspondences &correspondences_before,
112  const pcl::Correspondences &correspondences_after,
113  std::vector<int>& indices,
114  bool presorting_required = true);
115 
116  /**
117  * \brief Representation of a (possible) correspondence between two 3D points in two different coordinate frames
118  * (e.g. from feature matching)
119  * \ingroup common
120  */
122  {
123  Eigen::Vector3f point1; //!< The 3D position of the point in the first coordinate frame
124  Eigen::Vector3f point2; //!< The 3D position of the point in the second coordinate frame
125 
126  /** \brief Empty constructor. */
127  PointCorrespondence3D () : point1 (), point2 () {}
128 
129  /** \brief Empty destructor. */
131 
133  };
134  using PointCorrespondences3DVector = std::vector<PointCorrespondence3D, Eigen::aligned_allocator<PointCorrespondence3D> >;
135 
136  /**
137  * \brief Representation of a (possible) correspondence between two points (e.g. from feature matching),
138  * that encode complete 6DOF transformations.
139  * \ingroup common
140  */
142  {
143  Eigen::Affine3f transformation; //!< The transformation to go from the coordinate system
144  //!< of point2 to the coordinate system of point1
145  /** \brief Empty destructor. */
147 
149  };
150  using PointCorrespondences6DVector = std::vector<PointCorrespondence6D, Eigen::aligned_allocator<PointCorrespondence6D> >;
151 
152  /**
153  * \brief Comparator to enable us to sort a vector of PointCorrespondences according to their scores using
154  * std::sort (begin(), end(), isBetterCorrespondence);
155  * \ingroup common
156  */
157  inline bool
159  {
160  return (pc1.distance > pc2.distance);
161  }
162 }
Eigen::Vector3f point1
The 3D position of the point in the first coordinate frame.
int index_match
Index of the matching (target) point.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
PointCorrespondence3D()
Empty constructor.
std::vector< PointCorrespondence6D, Eigen::aligned_allocator< PointCorrespondence6D > > PointCorrespondences6DVector
virtual ~PointCorrespondence3D()
Empty destructor.
Correspondence(int _index_query, int _index_match, float _distance)
Constructor.
Correspondence represents a match between two entities (e.g., points, descriptors, etc).
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: pcl_macros.h:344
std::ostream & operator<<(std::ostream &os, const BivariatePolynomialT< real > &p)
int index_query
Index of the query (source) point.
Correspondence()
Standard constructor.
virtual ~PointCorrespondence6D()
Empty destructor.
boost::shared_ptr< const Correspondences > CorrespondencesConstPtr
Representation of a (possible) correspondence between two 3D points in two different coordinate frame...
Representation of a (possible) correspondence between two points (e.g.
Eigen::Vector3f point2
The 3D position of the point in the second coordinate frame.
void getRejectedQueryIndices(const pcl::Correspondences &correspondences_before, const pcl::Correspondences &correspondences_after, std::vector< int > &indices, bool presorting_required=true)
Get the query points of correspondences that are present in one correspondence vector but not in the ...
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
bool isBetterCorrespondence(const Correspondence &pc1, const Correspondence &pc2)
Comparator to enable us to sort a vector of PointCorrespondences according to their scores using std:...
boost::shared_ptr< Correspondences > CorrespondencesPtr
std::vector< PointCorrespondence3D, Eigen::aligned_allocator< PointCorrespondence3D > > PointCorrespondences3DVector
virtual ~Correspondence()
Empty destructor.
Eigen::Affine3f transformation
The transformation to go from the coordinate system.