|
Point Cloud Library (PCL)
1.6.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage, Inc. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * $Id$ 00035 * 00036 */ 00037 00038 #ifndef PCL_REGISTRATION_VISUALIZER_H_ 00039 #define PCL_REGISTRATION_VISUALIZER_H_ 00040 00041 // boost 00042 #include <boost/thread.hpp> 00043 #include <boost/function.hpp> 00044 #include <boost/bind.hpp> 00045 00046 // PCL 00047 #include <pcl/registration/registration.h> 00048 #include <pcl/visualization/pcl_visualizer.h> 00049 00050 namespace pcl 00051 { 00059 template<typename PointSource, typename PointTarget> 00060 class RegistrationVisualizer 00061 { 00062 00063 public: 00065 RegistrationVisualizer () : 00066 viewer_ (), 00067 viewer_thread_ (), 00068 registration_method_name_ (), 00069 update_visualizer_ (), 00070 first_update_flag_ (), 00071 cloud_source_ (), 00072 cloud_target_ (), 00073 visualizer_updating_mutex_ (), 00074 cloud_intermediate_ (), 00075 cloud_intermediate_indices_ (), 00076 cloud_target_indices_ (), 00077 maximum_displayed_correspondences_ (0) 00078 {} 00079 00087 bool 00088 setRegistration (pcl::Registration<PointSource, PointTarget> ®istration) 00089 { 00090 // Update the name of the registration method to be desplayed 00091 registration_method_name_ = registration.getClassName(); 00092 00093 // Create the local callback function and bind it to the local function resposable for updating 00094 // the local buffers 00095 update_visualizer_ = boost::bind (&RegistrationVisualizer<PointSource, PointTarget>::updateIntermediateCloud, 00096 this, _1, _2, _3, _4); 00097 00098 // Register the local callback function to the registration algorithm callback function 00099 registration.registerVisualizationCallback (this->update_visualizer_); 00100 00101 // Flag that no visualizer update was done. It indicates to visualizer update function to copy 00102 // the registration input source and the target point clouds in the next call. 00103 visualizer_updating_mutex_.lock (); 00104 00105 first_update_flag_ = false; 00106 00107 visualizer_updating_mutex_.unlock (); 00108 00109 return true; 00110 } 00111 00114 void 00115 startDisplay (); 00116 00119 void 00120 stopDisplay (); 00121 00129 void 00130 updateIntermediateCloud (const pcl::PointCloud<PointSource> &cloud_src, const std::vector<int> &indices_src, 00131 const pcl::PointCloud<PointTarget> &cloud_tgt, const std::vector<int> &indices_tgt); 00132 00134 inline void 00135 setMaximumDisplayedCorrespondences (const int maximum_displayed_correspondences) 00136 { 00137 // This method is usualy called form other thread than visualizer thread 00138 // therefore same visualizer_updating_mutex_ will be used 00139 00140 // Lock maximum_displayed_correspondences_ 00141 visualizer_updating_mutex_.lock (); 00142 00143 // Update maximum_displayed_correspondences_ 00144 maximum_displayed_correspondences_ = maximum_displayed_correspondences; 00145 00146 // Unlock maximum_displayed_correspondences_ 00147 visualizer_updating_mutex_.unlock(); 00148 } 00149 00151 inline size_t 00152 getMaximumDisplayedCorrespondences() 00153 { 00154 return maximum_displayed_correspondences_; 00155 } 00156 00157 private: 00159 void 00160 runDisplay (); 00161 00163 inline std::string 00164 getIndexedName (std::string &root_name, size_t &id) 00165 { 00166 std::stringstream id_stream_; 00167 id_stream_ << id; 00168 std::string indexed_name_ = root_name + id_stream_.str (); 00169 return indexed_name_; 00170 } 00171 00173 boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer_; 00174 00176 boost::thread viewer_thread_; 00177 00179 std::string registration_method_name_; 00180 00182 boost::function<void 00183 (const pcl::PointCloud<PointSource> &cloud_src, const std::vector<int> &indices_src, const pcl::PointCloud< 00184 PointTarget> &cloud_tgt, const std::vector<int> &indices_tgt)> update_visualizer_; 00185 00187 bool first_update_flag_; 00188 00190 pcl::PointCloud<PointSource> cloud_source_; 00191 00193 pcl::PointCloud<PointTarget> cloud_target_; 00194 00196 boost::mutex visualizer_updating_mutex_; 00197 00199 pcl::PointCloud<PointSource> cloud_intermediate_; 00200 00202 std::vector<int> cloud_intermediate_indices_; 00203 00205 std::vector<int> cloud_target_indices_; 00206 00208 size_t maximum_displayed_correspondences_; 00209 00210 }; 00211 } 00212 00213 #include <pcl/visualization/impl/registration_visualizer.hpp> 00214 00215 #endif //#ifndef PCL_REGISTRATION_VISUALIZER_H_
1.7.6.1