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