Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
registration_visualizer.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $Id$
35  *
36  */
37 
38 #ifndef PCL_REGISTRATION_VISUALIZER_H_
39 #define PCL_REGISTRATION_VISUALIZER_H_
40 
41 // boost
42 #include <boost/thread.hpp>
43 #include <boost/function.hpp>
44 #include <boost/bind.hpp>
45 
46 // PCL
49 
50 namespace pcl
51 {
59  template<typename PointSource, typename PointTarget>
61  {
62 
63  public:
66  viewer_ (),
67  viewer_thread_ (),
68  registration_method_name_ (),
69  update_visualizer_ (),
70  first_update_flag_ (),
71  cloud_source_ (),
72  cloud_target_ (),
73  visualizer_updating_mutex_ (),
74  cloud_intermediate_ (),
75  cloud_intermediate_indices_ (),
76  cloud_target_indices_ (),
77  maximum_displayed_correspondences_ (0)
78  {}
79 
87  bool
89  {
90  // Update the name of the registration method to be desplayed
91  registration_method_name_ = registration.getClassName();
92 
93  // Create the local callback function and bind it to the local function resposable for updating
94  // the local buffers
96  this, _1, _2, _3, _4);
97 
98  // Register the local callback function to the registration algorithm callback function
99  registration.registerVisualizationCallback (this->update_visualizer_);
100 
101  // Flag that no visualizer update was done. It indicates to visualizer update function to copy
102  // the registration input source and the target point clouds in the next call.
103  visualizer_updating_mutex_.lock ();
104 
105  first_update_flag_ = false;
106 
107  visualizer_updating_mutex_.unlock ();
108 
109  return true;
110  }
111 
114  void
115  startDisplay ();
116 
119  void
120  stopDisplay ();
121 
129  void
130  updateIntermediateCloud (const pcl::PointCloud<PointSource> &cloud_src, const std::vector<int> &indices_src,
131  const pcl::PointCloud<PointTarget> &cloud_tgt, const std::vector<int> &indices_tgt);
132 
134  inline void
135  setMaximumDisplayedCorrespondences (const int maximum_displayed_correspondences)
136  {
137  // This method is usualy called form other thread than visualizer thread
138  // therefore same visualizer_updating_mutex_ will be used
139 
140  // Lock maximum_displayed_correspondences_
141  visualizer_updating_mutex_.lock ();
142 
143  // Update maximum_displayed_correspondences_
144  maximum_displayed_correspondences_ = maximum_displayed_correspondences;
145 
146  // Unlock maximum_displayed_correspondences_
147  visualizer_updating_mutex_.unlock();
148  }
149 
151  inline size_t
153  {
154  return maximum_displayed_correspondences_;
155  }
156 
157  private:
159  void
160  runDisplay ();
161 
163  inline std::string
164  getIndexedName (std::string &root_name, size_t &id)
165  {
166  std::stringstream id_stream_;
167  id_stream_ << id;
168  std::string indexed_name_ = root_name + id_stream_.str ();
169  return indexed_name_;
170  }
171 
173  boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer_;
174 
176  boost::thread viewer_thread_;
177 
179  std::string registration_method_name_;
180 
182  boost::function<void
183  (const pcl::PointCloud<PointSource> &cloud_src, const std::vector<int> &indices_src, const pcl::PointCloud<
184  PointTarget> &cloud_tgt, const std::vector<int> &indices_tgt)> update_visualizer_;
185 
187  bool first_update_flag_;
188 
190  pcl::PointCloud<PointSource> cloud_source_;
191 
193  pcl::PointCloud<PointTarget> cloud_target_;
194 
196  boost::mutex visualizer_updating_mutex_;
197 
199  pcl::PointCloud<PointSource> cloud_intermediate_;
200 
202  std::vector<int> cloud_intermediate_indices_;
203 
205  std::vector<int> cloud_target_indices_;
206 
208  size_t maximum_displayed_correspondences_;
209 
210  };
211 }
212 
214 
215 #endif //#ifndef PCL_REGISTRATION_VISUALIZER_H_