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