Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
elch.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id: elch.h 5026 2012-03-12 02:51:44Z rusu $
37  *
38  */
39 
40 #ifndef PCL_ELCH_H_
41 #define PCL_ELCH_H_
42 
43 #include <boost/graph/adjacency_list.hpp>
44 #include <boost/graph/graph_traits.hpp>
45 #include <boost/shared_ptr.hpp>
46 
47 #include <Eigen/Geometry>
48 
49 #include <pcl/pcl_base.h>
50 #include <pcl/point_types.h>
51 #include <pcl/point_cloud.h>
53 #include <pcl/registration/icp.h>
54 
55 namespace pcl
56 {
57  namespace registration
58  {
63  template <typename PointT>
64  class ELCH : public PCLBase<PointT>
65  {
66  public:
67  typedef boost::shared_ptr< ELCH<PointT> > Ptr;
68  typedef boost::shared_ptr< const ELCH<PointT> > ConstPtr;
69 
71  typedef typename PointCloud::Ptr PointCloudPtr;
73 
74  struct Vertex
75  {
76  Vertex () : cloud () {}
78  };
79 
81  typedef boost::adjacency_list<
82  boost::listS, boost::vecS, boost::undirectedS,
83  Vertex,
84  boost::no_property>
86 
87  typedef boost::shared_ptr< LoopGraph > LoopGraphPtr;
88 
92 
94  ELCH () :
95  loop_graph_ (new LoopGraph),
96  loop_start_ (0),
97  loop_end_ (0),
98  reg_ (new pcl::IterativeClosestPoint<PointT, PointT>),
99  loop_transform_ (),
100  compute_loop_ (true),
101  vd_ ()
102  {};
103 
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 
118  inline LoopGraphPtr
120  {
121  return (loop_graph_);
122  }
123 
127  inline void
129  {
130  loop_graph_ = loop_graph;
131  }
132 
134  inline typename boost::graph_traits<LoopGraph>::vertex_descriptor
136  {
137  return (loop_start_);
138  }
139 
143  inline void
144  setLoopStart (const typename boost::graph_traits<LoopGraph>::vertex_descriptor &loop_start)
145  {
146  loop_start_ = loop_start;
147  }
148 
150  inline typename boost::graph_traits<LoopGraph>::vertex_descriptor
152  {
153  return (loop_end_);
154  }
155 
159  inline void
160  setLoopEnd (const typename boost::graph_traits<LoopGraph>::vertex_descriptor &loop_end)
161  {
162  loop_end_ = loop_end;
163  }
164 
166  inline RegistrationPtr
168  {
169  return (reg_);
170  }
171 
175  inline void
177  {
178  reg_ = reg;
179  }
180 
182  inline Eigen::Matrix4f
184  {
185  return (loop_transform_);
186  }
187 
191  inline void
192  setLoopTransform (const Eigen::Matrix4f &loop_transform)
193  {
194  loop_transform_ = loop_transform;
195  compute_loop_ = false;
196  }
197 
202  void
203  compute ();
204 
205  protected:
207 
209  virtual bool
210  initCompute ();
211 
212  private:
214  typedef boost::adjacency_list<
215  boost::listS, boost::vecS, boost::undirectedS,
216  boost::no_property,
217  boost::property< boost::edge_weight_t, double > >
218  LOAGraph;
219 
227  void
228  loopOptimizerAlgorithm (LOAGraph &g, double *weights);
229 
231  LoopGraphPtr loop_graph_;
232 
234  typename boost::graph_traits<LoopGraph>::vertex_descriptor loop_start_;
235 
237  typename boost::graph_traits<LoopGraph>::vertex_descriptor loop_end_;
238 
240  RegistrationPtr reg_;
241 
243  Eigen::Matrix4f loop_transform_;
244  bool compute_loop_;
245 
247  typename boost::graph_traits<LoopGraph>::vertex_descriptor vd_;
248 
249  public:
250  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
251  };
252  }
253 }
254 
256 
257 #endif // PCL_ELCH_H_