Point Cloud Library (PCL)  1.10.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/pcl_macros.h>
44 #include <pcl/pcl_base.h>
45 #include <pcl/point_types.h>
46 #include <pcl/point_cloud.h>
47 #include <pcl/registration/registration.h>
48 #include <pcl/registration/boost.h>
49 #include <pcl/registration/eigen.h>
50 #include <pcl/registration/icp.h>
51 #include <pcl/registration/boost_graph.h>
52 
53 namespace pcl
54 {
55  namespace registration
56  {
57  /** \brief @b ELCH (Explicit Loop Closing Heuristic) class
58  * \author Jochen Sprickerhof
59  * \ingroup registration
60  */
61  template <typename PointT>
62  class ELCH : public PCLBase<PointT>
63  {
64  public:
67 
69  using PointCloudPtr = typename PointCloud::Ptr;
71 
72  struct Vertex
73  {
74  Vertex () : cloud () {}
76  Eigen::Affine3f transform;
77  };
78 
79  /** \brief graph structure to hold the SLAM graph */
80  using LoopGraph = boost::adjacency_list<
81  boost::listS, boost::eigen_vecS, boost::undirectedS,
82  Vertex,
83  boost::no_property>;
84 
86 
90 
91  /** \brief Empty constructor. */
92  ELCH () :
93  loop_graph_ (new LoopGraph),
94  loop_start_ (0),
95  loop_end_ (0),
96  reg_ (new pcl::IterativeClosestPoint<PointT, PointT>),
97  compute_loop_ (true),
98  vd_ ()
99  {};
100 
101  /** \brief Empty destructor */
102  ~ELCH () {}
103 
104  /** \brief Add a new point cloud to the internal graph.
105  * \param[in] cloud the new point cloud
106  */
107  inline void
109  {
110  typename boost::graph_traits<LoopGraph>::vertex_descriptor vd = add_vertex (*loop_graph_);
111  (*loop_graph_)[vd].cloud = cloud;
112  if (num_vertices (*loop_graph_) > 1)
113  add_edge (vd_, vd, *loop_graph_);
114  vd_ = vd;
115  }
116 
117  /** \brief Getter for the internal graph. */
118  inline LoopGraphPtr
120  {
121  return (loop_graph_);
122  }
123 
124  /** \brief Setter for a new internal graph.
125  * \param[in] loop_graph the new graph
126  */
127  inline void
129  {
130  loop_graph_ = loop_graph;
131  }
132 
133  /** \brief Getter for the first scan of a loop. */
134  inline typename boost::graph_traits<LoopGraph>::vertex_descriptor
136  {
137  return (loop_start_);
138  }
139 
140  /** \brief Setter for the first scan of a loop.
141  * \param[in] loop_start the scan that starts the loop
142  */
143  inline void
144  setLoopStart (const typename boost::graph_traits<LoopGraph>::vertex_descriptor &loop_start)
145  {
146  loop_start_ = loop_start;
147  }
148 
149  /** \brief Getter for the last scan of a loop. */
150  inline typename boost::graph_traits<LoopGraph>::vertex_descriptor
152  {
153  return (loop_end_);
154  }
155 
156  /** \brief Setter for the last scan of a loop.
157  * \param[in] loop_end the scan that ends the loop
158  */
159  inline void
160  setLoopEnd (const typename boost::graph_traits<LoopGraph>::vertex_descriptor &loop_end)
161  {
162  loop_end_ = loop_end;
163  }
164 
165  /** \brief Getter for the registration algorithm. */
166  inline RegistrationPtr
168  {
169  return (reg_);
170  }
171 
172  /** \brief Setter for the registration algorithm.
173  * \param[in] reg the registration algorithm used to compute the transformation between the start and the end of the loop
174  */
175  inline void
177  {
178  reg_ = reg;
179  }
180 
181  /** \brief Getter for the transformation between the first and the last scan. */
182  inline Eigen::Matrix4f
184  {
185  return (loop_transform_);
186  }
187 
188  /** \brief Setter for the transformation between the first and the last scan.
189  * \param[in] loop_transform the transformation between the first and the last scan
190  */
191  inline void
192  setLoopTransform (const Eigen::Matrix4f &loop_transform)
193  {
194  loop_transform_ = loop_transform;
195  compute_loop_ = false;
196  }
197 
198  /** \brief Computes new poses for all point clouds by closing the loop
199  * between start and end point cloud. This will transform all given point
200  * clouds for now!
201  */
202  void
203  compute ();
204 
205  protected:
207 
208  /** \brief This method should get called before starting the actual computation. */
209  virtual bool
210  initCompute ();
211 
212  private:
213  /** \brief graph structure for the internal optimization graph */
214  using LOAGraph = boost::adjacency_list<
215  boost::listS, boost::vecS, 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  }
252 }
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:108
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:144
pcl::Registration< PointT, PointT >::Ptr
shared_ptr< Registration< PointT, PointT, float > > Ptr
Definition: registration.h:70
boost::eigen_vecS
Definition: boost_graph.h:49
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl::registration::ELCH::RegistrationPtr
typename Registration::Ptr RegistrationPtr
Definition: elch.h:88
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
point_types.h
pcl::registration::ELCH::ConstPtr
shared_ptr< const ELCH< PointT > > ConstPtr
Definition: elch.h:66
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:135
pcl::registration::ELCH::RegistrationConstPtr
typename Registration::ConstPtr RegistrationConstPtr
Definition: elch.h:89
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:217
pcl::registration::ELCH::setReg
void setReg(RegistrationPtr reg)
Setter for the registration algorithm.
Definition: elch.h:176
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:160
pcl::registration::ELCH::getLoopGraph
LoopGraphPtr getLoopGraph()
Getter for the internal graph.
Definition: elch.h:119
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:192
pcl::IterativeClosestPoint
IterativeClosestPoint provides a base implementation of the Iterative Closest Point algorithm.
Definition: icp.h:95
pcl::registration::ELCH::Vertex
Definition: elch.h:72
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:69
pcl::registration::ELCH::Ptr
shared_ptr< ELCH< PointT > > Ptr
Definition: elch.h:65
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: projection_matrix.h:52
pcl::registration::ELCH::Vertex::cloud
PointCloudPtr cloud
Definition: elch.h:75
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:620
pcl::registration::ELCH::Vertex::Vertex
Vertex()
Definition: elch.h:74
pcl::registration::ELCH::setLoopGraph
void setLoopGraph(LoopGraphPtr loop_graph)
Setter for a new internal graph.
Definition: elch.h:128
pcl::registration::ELCH
ELCH (Explicit Loop Closing Heuristic) class
Definition: elch.h:62
pcl::registration::ELCH::initCompute
virtual bool initCompute()
This method should get called before starting the actual computation.
Definition: elch.hpp:157
PCL_MAKE_ALIGNED_OPERATOR_NEW
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: pcl_macros.h:389
pcl::registration::ELCH::LoopGraphPtr
shared_ptr< LoopGraph > LoopGraphPtr
Definition: elch.h:85
pcl::registration::ELCH::getLoopTransform
Eigen::Matrix4f getLoopTransform()
Getter for the transformation between the first and the last scan.
Definition: elch.h:183
pcl::registration::ELCH::Vertex::transform
Eigen::Affine3f transform
Definition: elch.h:76
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:415
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:83
pcl::registration::ELCH::ELCH
ELCH()
Empty constructor.
Definition: elch.h:92
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:416
pcl::registration::ELCH::getReg
RegistrationPtr getReg()
Getter for the registration algorithm.
Definition: elch.h:167
pcl::Registration< PointT, PointT >::ConstPtr
shared_ptr< const Registration< PointT, PointT, float > > ConstPtr
Definition: registration.h:71
pcl::registration::ELCH::~ELCH
~ELCH()
Empty destructor.
Definition: elch.h:102
pcl::registration::ELCH::getLoopEnd
boost::graph_traits< LoopGraph >::vertex_descriptor getLoopEnd()
Getter for the last scan of a loop.
Definition: elch.h:151
pcl::shared_ptr
boost::shared_ptr< T > shared_ptr
Alias for boost::shared_ptr.
Definition: pcl_macros.h:108