Point Cloud Library (PCL) 1.12.1
elch.h
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 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 * $Id$
38 *
39 */
40
41#pragma once
42
43#include <pcl/registration/boost_graph.h>
44#include <pcl/registration/icp.h>
45#include <pcl/registration/registration.h>
46#include <pcl/memory.h>
47#include <pcl/pcl_base.h>
48#include <pcl/pcl_macros.h>
49#include <pcl/point_cloud.h>
50#include <pcl/point_types.h>
51
52namespace pcl {
53namespace registration {
54/** \brief @b ELCH (Explicit Loop Closing Heuristic) class
55 * \author Jochen Sprickerhof
56 * \ingroup registration
57 */
58template <typename PointT>
59class ELCH : public PCLBase<PointT> {
60public:
61 using Ptr = shared_ptr<ELCH<PointT>>;
62 using ConstPtr = shared_ptr<const ELCH<PointT>>;
63
67
68 struct Vertex {
69 Vertex() : cloud() {}
71 Eigen::Affine3f transform;
72 };
73
74 /** \brief graph structure to hold the SLAM graph */
75 using LoopGraph = boost::adjacency_list<boost::listS,
77 boost::undirectedS,
78 Vertex,
79 boost::no_property>;
80
81 using LoopGraphPtr = shared_ptr<LoopGraph>;
82
86
87 /** \brief Empty constructor. */
89 : loop_graph_(new LoopGraph)
90 , loop_start_(0)
91 , loop_end_(0)
93 , compute_loop_(true)
94 , vd_(){};
95
96 /** \brief Empty destructor */
97 ~ELCH() {}
98
99 /** \brief Add a new point cloud to the internal graph.
100 * \param[in] cloud the new point cloud
101 */
102 inline void
104 {
105 typename boost::graph_traits<LoopGraph>::vertex_descriptor vd =
106 add_vertex(*loop_graph_);
107 (*loop_graph_)[vd].cloud = cloud;
108 if (num_vertices(*loop_graph_) > 1)
109 add_edge(vd_, vd, *loop_graph_);
110 vd_ = vd;
111 }
112
113 /** \brief Getter for the internal graph. */
114 inline LoopGraphPtr
116 {
117 return (loop_graph_);
118 }
119
120 /** \brief Setter for a new internal graph.
121 * \param[in] loop_graph the new graph
122 */
123 inline void
125 {
126 loop_graph_ = loop_graph;
127 }
128
129 /** \brief Getter for the first scan of a loop. */
130 inline typename boost::graph_traits<LoopGraph>::vertex_descriptor
132 {
133 return (loop_start_);
134 }
135
136 /** \brief Setter for the first scan of a loop.
137 * \param[in] loop_start the scan that starts the loop
138 */
139 inline void
141 const typename boost::graph_traits<LoopGraph>::vertex_descriptor& loop_start)
142 {
143 loop_start_ = loop_start;
144 }
145
146 /** \brief Getter for the last scan of a loop. */
147 inline typename boost::graph_traits<LoopGraph>::vertex_descriptor
149 {
150 return (loop_end_);
151 }
152
153 /** \brief Setter for the last scan of a loop.
154 * \param[in] loop_end the scan that ends the loop
155 */
156 inline void
157 setLoopEnd(const typename boost::graph_traits<LoopGraph>::vertex_descriptor& loop_end)
158 {
159 loop_end_ = loop_end;
160 }
161
162 /** \brief Getter for the registration algorithm. */
163 inline RegistrationPtr
165 {
166 return (reg_);
167 }
168
169 /** \brief Setter for the registration algorithm.
170 * \param[in] reg the registration algorithm used to compute the transformation
171 * between the start and the end of the loop
172 */
173 inline void
175 {
176 reg_ = reg;
177 }
178
179 /** \brief Getter for the transformation between the first and the last scan. */
180 inline Eigen::Matrix4f
182 {
183 return (loop_transform_);
184 }
185
186 /** \brief Setter for the transformation between the first and the last scan.
187 * \param[in] loop_transform the transformation between the first and the last scan
188 */
189 inline void
190 setLoopTransform(const Eigen::Matrix4f& loop_transform)
191 {
192 loop_transform_ = loop_transform;
193 compute_loop_ = false;
194 }
195
196 /** \brief Computes new poses for all point clouds by closing the loop
197 * between start and end point cloud. This will transform all given point
198 * clouds for now!
199 */
200 void
201 compute();
202
203protected:
205
206 /** \brief This method should get called before starting the actual computation. */
207 virtual bool
208 initCompute();
209
210private:
211 /** \brief graph structure for the internal optimization graph */
212 using LOAGraph = boost::adjacency_list<boost::listS,
213 boost::vecS,
214 boost::undirectedS,
215 boost::no_property,
216 boost::property<boost::edge_weight_t, double>>;
217
218 /**
219 * graph balancer algorithm computes the weights
220 * @param[in] g the graph
221 * @param[in] f index of the first node
222 * @param[in] l index of the last node
223 * @param[out] weights array for the weights
224 */
225 void
226 loopOptimizerAlgorithm(LOAGraph& g, double* weights);
227
228 /** \brief The internal loop graph. */
229 LoopGraphPtr loop_graph_;
230
231 /** \brief The first scan of the loop. */
232 typename boost::graph_traits<LoopGraph>::vertex_descriptor loop_start_;
233
234 /** \brief The last scan of the loop. */
235 typename boost::graph_traits<LoopGraph>::vertex_descriptor loop_end_;
236
237 /** \brief The registration object used to close the loop. */
238 RegistrationPtr reg_;
239
240 /** \brief The transformation between that start and end of the loop. */
241 Eigen::Matrix4f loop_transform_;
242 bool compute_loop_;
243
244 /** \brief previously added node in the loop_graph_. */
245 typename boost::graph_traits<LoopGraph>::vertex_descriptor vd_;
246
247public:
249};
250} // namespace registration
251} // namespace pcl
252
253#include <pcl/registration/impl/elch.hpp>
IterativeClosestPoint provides a base implementation of the Iterative Closest Point algorithm.
Definition: icp.h:97
PCL base class.
Definition: pcl_base.h:70
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
shared_ptr< const Registration< PointT, PointT, float > > ConstPtr
Definition: registration.h:67
shared_ptr< Registration< PointT, PointT, float > > Ptr
Definition: registration.h:66
ELCH (Explicit Loop Closing Heuristic) class
Definition: elch.h:59
boost::adjacency_list< boost::listS, boost::eigen_vecS, boost::undirectedS, Vertex, boost::no_property > LoopGraph
graph structure to hold the SLAM graph
Definition: elch.h:79
typename Registration::ConstPtr RegistrationConstPtr
Definition: elch.h:85
shared_ptr< ELCH< PointT > > Ptr
Definition: elch.h:61
void setLoopTransform(const Eigen::Matrix4f &loop_transform)
Setter for the transformation between the first and the last scan.
Definition: elch.h:190
shared_ptr< const ELCH< PointT > > ConstPtr
Definition: elch.h:62
~ELCH()
Empty destructor.
Definition: elch.h:97
Eigen::Matrix4f getLoopTransform()
Getter for the transformation between the first and the last scan.
Definition: elch.h:181
void setLoopEnd(const typename boost::graph_traits< LoopGraph >::vertex_descriptor &loop_end)
Setter for the last scan of a loop.
Definition: elch.h:157
void addPointCloud(PointCloudPtr cloud)
Add a new point cloud to the internal graph.
Definition: elch.h:103
void setLoopGraph(LoopGraphPtr loop_graph)
Setter for a new internal graph.
Definition: elch.h:124
void setLoopStart(const typename boost::graph_traits< LoopGraph >::vertex_descriptor &loop_start)
Setter for the first scan of a loop.
Definition: elch.h:140
shared_ptr< LoopGraph > LoopGraphPtr
Definition: elch.h:81
void setReg(RegistrationPtr reg)
Setter for the registration algorithm.
Definition: elch.h:174
boost::graph_traits< LoopGraph >::vertex_descriptor getLoopEnd()
Getter for the last scan of a loop.
Definition: elch.h:148
typename Registration::Ptr RegistrationPtr
Definition: elch.h:84
boost::graph_traits< LoopGraph >::vertex_descriptor getLoopStart()
Getter for the first scan of a loop.
Definition: elch.h:131
ELCH()
Empty constructor.
Definition: elch.h:88
RegistrationPtr getReg()
Getter for the registration algorithm.
Definition: elch.h:164
LoopGraphPtr getLoopGraph()
Getter for the internal graph.
Definition: elch.h:115
virtual bool initCompute()
This method should get called before starting the actual computation.
Definition: elch.hpp:154
void compute()
Computes new poses for all point clouds by closing the loop between start and end point cloud.
Definition: elch.hpp:216
Defines all the PCL implemented PointT point type structures.
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
Defines functions, macros and traits for allocating and using memory.
Defines all the PCL and non-PCL macros used.
A point structure representing Euclidean xyz coordinates, and the RGB color.
Eigen::Affine3f transform
Definition: elch.h:71