00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00040 template<typename PointSource, typename PointTarget> void
00041 pcl::RegistrationVisualizer<PointSource, PointTarget>::startDisplay ()
00042 {
00043
00044 viewer_thread_ = boost::thread (&pcl::RegistrationVisualizer<PointSource, PointTarget>::runDisplay, this);
00045 }
00046
00048 template<typename PointSource, typename PointTarget> void
00049 pcl::RegistrationVisualizer<PointSource, PointTarget>::stopDisplay ()
00050 {
00051
00052 viewer_thread_.~thread ();
00053 }
00054
00056 template<typename PointSource, typename PointTarget> void
00057 pcl::RegistrationVisualizer<PointSource, PointTarget>::runDisplay ()
00058 {
00059
00060 viewer_
00061 = boost::shared_ptr<pcl::visualization::PCLVisualizer> (new pcl::visualization::PCLVisualizer ("3D Viewer"));
00062 viewer_->initCameraParameters ();
00063
00064
00065 pcl::visualization::PointCloudColorHandlerCustom<PointSource> cloud_source_handler_ (cloud_source_.makeShared (),
00066 255, 0, 0);
00067 pcl::visualization::PointCloudColorHandlerCustom<PointTarget> cloud_target_handler_ (cloud_target_.makeShared (),
00068 0, 0, 255);
00069 pcl::visualization::PointCloudColorHandlerCustom<PointSource> cloud_intermediate_handler_ (cloud_intermediate_.makeShared (),
00070 255, 255, 0);
00071
00072
00073 int v1 (0);
00074 viewer_->createViewPort (0.0, 0.0, 0.5, 1.0, v1);
00075 viewer_->setBackgroundColor (0, 0, 0, v1);
00076 viewer_->addText ("Initial position of source and target point clouds", 10, 50, "title v1", v1);
00077 viewer_->addText ("Blue -> target", 10, 30, 0.0, 0.0, 1.0, "legend target v1", v1);
00078 viewer_->addText ("Red -> source", 10, 10, 1.0, 0.0, 0.0, "legend source v1", v1);
00079
00080 viewer_->addPointCloud<PointSource> (cloud_source_.makeShared (), cloud_source_handler_, "cloud source v1", v1);
00081 viewer_->addPointCloud<PointTarget> (cloud_target_.makeShared (), cloud_target_handler_, "cloud target v1", v1);
00082
00083
00084 int v2 (0);
00085 viewer_->createViewPort (0.5, 0.0, 1.0, 1.0, v2);
00086 viewer_->setBackgroundColor (0.1, 0.1, 0.1, v2);
00087 std::string registration_port_title_ = "Registration using "+registration_method_name_;
00088 viewer_->addText (registration_port_title_, 10, 90, "title v2", v2);
00089
00090 viewer_->addText ("Yellow -> intermediate", 10, 50, 1.0, 1.0, 0.0, "legend intermediate v2", v2);
00091 viewer_->addText ("Blue -> target", 10, 30, 0.0, 0.0, 1.0, "legend target v2", v2);
00092 viewer_->addText ("Red -> source", 10, 10, 1.0, 0.0, 0.0, "legend source v2", v1);
00093
00094
00095 viewer_->addPointCloud<PointTarget> (cloud_target_.makeShared (), cloud_target_handler_, "cloud target v2", v2);
00096 viewer_->addPointCloud<PointSource> (cloud_intermediate_.makeShared (), cloud_intermediate_handler_,
00097 "cloud intermediate v2", v2);
00098
00099
00100 size_t correspondeces_old_size = 0;
00101
00102
00103 viewer_->addCoordinateSystem (1.0);
00104
00105
00106 std::string line_root_ = "line";
00107
00108
00109 while (!viewer_->wasStopped ())
00110 {
00111
00112 visualizer_updating_mutex_.lock ();
00113
00114
00115
00116 viewer_->removePointCloud ("cloud intermediate v2", v2);
00117
00118
00119 viewer_->addPointCloud<PointSource> (cloud_intermediate_.makeShared (), cloud_intermediate_handler_,
00120 "cloud intermediate v2", v2);
00121
00122
00123
00124 std::string line_name_;
00125
00126 for (size_t correspondence_id = 0; correspondence_id < correspondeces_old_size; ++correspondence_id)
00127 {
00128
00129 line_name_ = getIndexedName (line_root_, correspondence_id);
00130
00131
00132 viewer_->removeShape (line_name_, v2);
00133 }
00134
00135
00136 size_t correspondences_new_size = cloud_intermediate_indices_.size ();
00137
00138
00139 std::stringstream stream_;
00140 stream_ << "Random -> correspondences " << correspondences_new_size;
00141 viewer_->removeShape ("correspondences_size", 0);
00142 viewer_->addText (stream_.str(), 10, 70, 0.0, 1.0, 0.0, "correspondences_size", v2);
00143
00144
00145 if( ( 0 < maximum_displayed_correspondences_ ) &&
00146 (maximum_displayed_correspondences_ < correspondences_new_size) )
00147 correspondences_new_size = maximum_displayed_correspondences_;
00148
00149
00150 correspondeces_old_size = correspondences_new_size;
00151
00152
00153 for (size_t correspondence_id = 0; correspondence_id < correspondences_new_size; ++correspondence_id)
00154 {
00155
00156 double random_red = 255 * rand () / (RAND_MAX + 1.0);
00157 double random_green = 255 * rand () / (RAND_MAX + 1.0);
00158 double random_blue = 255 * rand () / (RAND_MAX + 1.0);
00159
00160
00161 line_name_ = getIndexedName (line_root_, correspondence_id);
00162
00163
00164 viewer_->addLine (cloud_intermediate_[cloud_intermediate_indices_[correspondence_id]],
00165 cloud_target_[cloud_target_indices_[correspondence_id]],
00166 random_red, random_green, random_blue,
00167 line_name_, v2);
00168 }
00169
00170
00171 visualizer_updating_mutex_.unlock ();
00172
00173
00174 viewer_->spinOnce (100);
00175 boost::this_thread::sleep (boost::posix_time::microseconds (100000));
00176
00177 }
00178 }
00179
00181 template<typename PointSource, typename PointTarget> void
00182 pcl::RegistrationVisualizer<PointSource, PointTarget>::updateIntermediateCloud (
00183 const pcl::PointCloud<PointSource> &cloud_src,
00184 const std::vector<int> &indices_src,
00185 const pcl::PointCloud<PointTarget> &cloud_tgt,
00186 const std::vector<int> &indices_tgt)
00187 {
00188
00189 visualizer_updating_mutex_.lock ();
00190
00191
00192
00193 if (!first_update_flag_)
00194 {
00195 first_update_flag_ = true;
00196
00197 this->cloud_source_ = cloud_src;
00198 this->cloud_target_ = cloud_tgt;
00199
00200 this->cloud_intermediate_ = cloud_src;
00201 }
00202
00203
00204 cloud_intermediate_ = cloud_src;
00205 cloud_intermediate_indices_ = indices_src;
00206
00207
00208 cloud_target_indices_ = indices_tgt;
00209
00210
00211 visualizer_updating_mutex_.unlock ();
00212 }