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