Point Cloud Library (PCL)  1.10.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 <pcl/memory.h>
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. */
62  int index_query = 0;
63  /** \brief Index of the matching (target) point. Set to -1 if no correspondence found. */
64  int index_match = -1;
65  /** \brief Distance between the corresponding points, or the weight denoting the confidence in correspondence estimation */
66  union
67  {
68  float distance = std::numeric_limits<float>::max();
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 () = default;
76 
77  /** \brief Constructor. */
78  inline Correspondence (int _index_query, int _index_match, float _distance) :
79  index_query (_index_query), index_match (_index_match), distance (_distance)
80  {}
81 
83  };
84 
85  /** \brief overloaded << operator */
86  PCL_EXPORTS std::ostream& operator << (std::ostream& os, const Correspondence& c);
87 
88  using Correspondences = std::vector< pcl::Correspondence, Eigen::aligned_allocator<pcl::Correspondence> >;
91 
92  /**
93  * \brief Get the query points of correspondences that are present in
94  * one correspondence vector but not in the other, e.g., to compare
95  * correspondences before and after rejection.
96  * \param[in] correspondences_before Vector of correspondences before rejection
97  * \param[in] correspondences_after Vector of correspondences after rejection
98  * \param[out] indices Query point indices of correspondences that have been rejected
99  * \param[in] presorting_required Enable/disable internal sorting of vectors.
100  * By default (true), vectors are internally sorted before determining their difference.
101  * If the order of correspondences in \a correspondences_after is not different (has not been changed)
102  * from the order in \b correspondences_before this pre-processing step can be disabled
103  * in order to gain efficiency. In order to disable pre-sorting set \a presorting_required to false.
104  */
105  void
106  getRejectedQueryIndices (const pcl::Correspondences &correspondences_before,
107  const pcl::Correspondences &correspondences_after,
108  std::vector<int>& indices,
109  bool presorting_required = true);
110 
111  /**
112  * \brief Representation of a (possible) correspondence between two 3D points in two different coordinate frames
113  * (e.g. from feature matching)
114  * \ingroup common
115  */
117  {
118  Eigen::Vector3f point1; //!< The 3D position of the point in the first coordinate frame
119  Eigen::Vector3f point2; //!< The 3D position of the point in the second coordinate frame
120 
122  };
123  using PointCorrespondences3DVector = std::vector<PointCorrespondence3D, Eigen::aligned_allocator<PointCorrespondence3D> >;
124 
125  /**
126  * \brief Representation of a (possible) correspondence between two points (e.g. from feature matching),
127  * that encode complete 6DOF transformations.
128  * \ingroup common
129  */
131  {
132  Eigen::Affine3f transformation; //!< The transformation to go from the coordinate system
133  //!< of point2 to the coordinate system of point1
134 
136  };
137  using PointCorrespondences6DVector = std::vector<PointCorrespondence6D, Eigen::aligned_allocator<PointCorrespondence6D> >;
138 
139  /**
140  * \brief Comparator to enable us to sort a vector of PointCorrespondences according to their scores using
141  * std::sort (begin(), end(), isBetterCorrespondence);
142  * \ingroup common
143  */
144  inline bool
146  {
147  return (pc1.distance > pc2.distance);
148  }
149 }
shared_ptr< const Correspondences > CorrespondencesConstPtr
Eigen::Vector3f point1
The 3D position of the point in the first coordinate frame.
Defines functions, macros and traits for allocating and using memory.
int index_match
Index of the matching (target) point.
std::vector< PointCorrespondence6D, Eigen::aligned_allocator< PointCorrespondence6D > > PointCorrespondences6DVector
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: memory.h:65
std::ostream & operator<<(std::ostream &os, const BivariatePolynomialT< real > &p)
int index_query
Index of the query (source) point.
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.
Correspondence()=default
Standard constructor.
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:...
std::vector< PointCorrespondence3D, Eigen::aligned_allocator< PointCorrespondence3D > > PointCorrespondences3DVector
boost::shared_ptr< T > shared_ptr
Alias for boost::shared_ptr.
Definition: memory.h:81
shared_ptr< Correspondences > CorrespondencesPtr
#define PCL_EXPORTS
Definition: pcl_macros.h:276
Defines all the PCL and non-PCL macros used.
Eigen::Affine3f transformation
The transformation to go from the coordinate system.