Point Cloud Library (PCL)  1.14.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/pcl_base.h>
46 #include <pcl/memory.h>
47 #include <pcl/types.h>
48 #include <Eigen/StdVector>
49 #include <Eigen/Geometry>
50 #include <pcl/pcl_exports.h>
51 
52 namespace pcl
53 {
54  /** \brief Correspondence represents a match between two entities (e.g., points, descriptors, etc). This is
55  * represented via the indices of a \a source point and a \a target point, and the distance between them.
56  *
57  * \author Dirk Holz, Radu B. Rusu, Bastian Steder
58  * \ingroup common
59  */
61  {
62  /** \brief Index of the query (source) point. */
64  /** \brief Index of the matching (target) point. Set to -1 if no correspondence found. */
66  /** \brief Distance between the corresponding points, or the weight denoting the confidence in correspondence estimation */
67  union
68  {
69  float distance = std::numeric_limits<float>::max();
70  float weight;
71  };
72 
73  /** \brief Standard constructor.
74  * Sets \ref index_query to 0, \ref index_match to -1, and \ref distance to std::numeric_limits<float>::max().
75  */
76  inline Correspondence () = default;
77 
78  /** \brief Constructor. */
79  inline Correspondence (index_t _index_query, index_t _index_match, float _distance) :
80  index_query (_index_query), index_match (_index_match), distance (_distance)
81  {}
82 
84  };
85 
86  /** \brief overloaded << operator */
87  PCL_EXPORTS std::ostream& operator << (std::ostream& os, const Correspondence& c);
88 
89  using Correspondences = std::vector< pcl::Correspondence, Eigen::aligned_allocator<pcl::Correspondence> >;
90  using CorrespondencesPtr = shared_ptr<Correspondences>;
91  using CorrespondencesConstPtr = shared_ptr<const Correspondences >;
92 
93  /**
94  * \brief Get the query points of correspondences that are present in
95  * one correspondence vector but not in the other, e.g., to compare
96  * correspondences before and after rejection.
97  * \param[in] correspondences_before Vector of correspondences before rejection
98  * \param[in] correspondences_after Vector of correspondences after rejection
99  * \param[out] indices Query point indices of correspondences that have been rejected
100  * \param[in] presorting_required Enable/disable internal sorting of vectors.
101  * By default (true), vectors are internally sorted before determining their difference.
102  * If the order of correspondences in \a correspondences_after is not different (has not been changed)
103  * from the order in \b correspondences_before this pre-processing step can be disabled
104  * in order to gain efficiency. In order to disable pre-sorting set \a presorting_required to false.
105  */
106  void
107  getRejectedQueryIndices (const pcl::Correspondences &correspondences_before,
108  const pcl::Correspondences &correspondences_after,
109  Indices& indices,
110  bool presorting_required = true);
111 
112  /**
113  * \brief Representation of a (possible) correspondence between two 3D points in two different coordinate frames
114  * (e.g. from feature matching)
115  * \ingroup common
116  */
118  {
119  Eigen::Vector3f point1; //!< The 3D position of the point in the first coordinate frame
120  Eigen::Vector3f point2; //!< The 3D position of the point in the second coordinate frame
121 
123  };
124  using PointCorrespondences3DVector = std::vector<PointCorrespondence3D, Eigen::aligned_allocator<PointCorrespondence3D> >;
125 
126  /**
127  * \brief Representation of a (possible) correspondence between two points (e.g. from feature matching),
128  * that encode complete 6DOF transformations.
129  * \ingroup common
130  */
132  {
133  Eigen::Affine3f transformation; //!< The transformation to go from the coordinate system
134  //!< of point2 to the coordinate system of point1
135 
137  };
138  using PointCorrespondences6DVector = std::vector<PointCorrespondence6D, Eigen::aligned_allocator<PointCorrespondence6D> >;
139 
140  /**
141  * \brief Comparator to enable us to sort a vector of PointCorrespondences according to their scores using
142  * std::sort (begin(), end(), isBetterCorrespondence);
143  * \ingroup common
144  */
145  inline bool
147  {
148  return (pc1.distance > pc2.distance);
149  }
150 }
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
bool isBetterCorrespondence(const Correspondence &pc1, const Correspondence &pc2)
Comparator to enable us to sort a vector of PointCorrespondences according to their scores using std:...
Defines functions, macros and traits for allocating and using memory.
shared_ptr< Correspondences > CorrespondencesPtr
shared_ptr< const Correspondences > CorrespondencesConstPtr
static constexpr index_t UNAVAILABLE
Definition: pcl_base.h:62
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
Definition: types.h:112
std::ostream & operator<<(std::ostream &os, const BivariatePolynomialT< real > &p)
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
std::vector< PointCorrespondence3D, Eigen::aligned_allocator< PointCorrespondence3D > > PointCorrespondences3DVector
void getRejectedQueryIndices(const pcl::Correspondences &correspondences_before, const pcl::Correspondences &correspondences_after, Indices &indices, bool presorting_required=true)
Get the query points of correspondences that are present in one correspondence vector but not in the ...
std::vector< PointCorrespondence6D, Eigen::aligned_allocator< PointCorrespondence6D > > PointCorrespondences6DVector
#define PCL_EXPORTS
Definition: pcl_macros.h:323
Correspondence represents a match between two entities (e.g., points, descriptors,...
Correspondence(index_t _index_query, index_t _index_match, float _distance)
Constructor.
index_t index_query
Index of the query (source) point.
index_t index_match
Index of the matching (target) point.
Correspondence()=default
Standard constructor.
Representation of a (possible) correspondence between two 3D points in two different coordinate frame...
Eigen::Vector3f point1
The 3D position of the point in the first coordinate frame.
Eigen::Vector3f point2
The 3D position of the point in the second coordinate frame.
Representation of a (possible) correspondence between two points (e.g.
Eigen::Affine3f transformation
The transformation to go from the coordinate system.
Defines basic non-point types used by PCL.