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