47 template<
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void
55 template<
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void
59 if(viewer_thread_.joinable())
60 viewer_thread_.join();
61 viewer_thread_.~thread ();
65 template<
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void
71 viewer_->initCameraParameters ();
83 viewer_->createViewPort (0.0, 0.0, 0.5, 1.0, v1);
84 viewer_->setBackgroundColor (0, 0, 0, v1);
85 viewer_->addText (
"Initial position of source and target point clouds", 10, 50,
"title v1", v1);
86 viewer_->addText (
"Blue -> target", 10, 30, 0.0, 0.0, 1.0,
"legend target v1", v1);
87 viewer_->addText (
"Red -> source", 10, 10, 1.0, 0.0, 0.0,
"legend source v1", v1);
89 viewer_->addPointCloud<PointSource> (cloud_source_.makeShared (), cloud_source_handler_,
"cloud source v1", v1);
90 viewer_->addPointCloud<PointTarget> (cloud_target_.makeShared (), cloud_target_handler_,
"cloud target v1", v1);
94 viewer_->createViewPort (0.5, 0.0, 1.0, 1.0, v2);
95 viewer_->setBackgroundColor (0.1, 0.1, 0.1, v2);
96 std::string registration_port_title_ =
"Registration using "+registration_method_name_;
97 viewer_->addText (registration_port_title_, 10, 90,
"title v2", v2);
99 viewer_->addText (
"Yellow -> intermediate", 10, 50, 1.0, 1.0, 0.0,
"legend intermediate v2", v2);
100 viewer_->addText (
"Blue -> target", 10, 30, 0.0, 0.0, 1.0,
"legend target v2", v2);
101 viewer_->addText (
"Red -> source", 10, 10, 1.0, 0.0, 0.0,
"legend source v2", v1);
104 viewer_->addPointCloud<PointTarget> (cloud_target_.makeShared (), cloud_target_handler_,
"cloud target v2", v2);
105 viewer_->addPointCloud<PointSource> (cloud_intermediate_.makeShared (), cloud_intermediate_handler_,
106 "cloud intermediate v2", v2);
109 std::size_t correspondeces_old_size = 0;
112 viewer_->addCoordinateSystem (1.0,
"global");
115 std::string line_root_ =
"line";
118 while (!viewer_->wasStopped ())
121 visualizer_updating_mutex_.lock ();
125 viewer_->removePointCloud (
"cloud intermediate v2", v2);
128 viewer_->addPointCloud<PointSource> (cloud_intermediate_.makeShared (), cloud_intermediate_handler_,
129 "cloud intermediate v2", v2);
133 std::string line_name_;
135 for (std::size_t correspondence_id = 0; correspondence_id < correspondeces_old_size; ++correspondence_id)
138 line_name_ = getIndexedName (line_root_, correspondence_id);
141 viewer_->removeShape (line_name_, v2);
145 std::size_t correspondences_new_size = cloud_intermediate_indices_.size ();
148 const std::string correspondences_text =
"Random -> correspondences " + std::to_string(correspondences_new_size);
149 viewer_->removeShape (
"correspondences_size", 0);
150 viewer_->addText (correspondences_text, 10, 70, 0.0, 1.0, 0.0,
"correspondences_size", v2);
153 if( ( 0 < maximum_displayed_correspondences_ ) &&
154 (maximum_displayed_correspondences_ < correspondences_new_size) )
155 correspondences_new_size = maximum_displayed_correspondences_;
158 correspondeces_old_size = correspondences_new_size;
161 for (std::size_t correspondence_id = 0; correspondence_id < correspondences_new_size; ++correspondence_id)
164 double random_red = 255 * rand () / (RAND_MAX + 1.0);
165 double random_green = 255 * rand () / (RAND_MAX + 1.0);
166 double random_blue = 255 * rand () / (RAND_MAX + 1.0);
169 line_name_ = getIndexedName (line_root_, correspondence_id);
172 viewer_->addLine (cloud_intermediate_[cloud_intermediate_indices_[correspondence_id]],
173 cloud_target_[cloud_target_indices_[correspondence_id]],
174 random_red, random_green, random_blue,
179 visualizer_updating_mutex_.unlock ();
182 viewer_->spinOnce (100);
183 using namespace std::chrono_literals;
184 std::this_thread::sleep_for(100ms);
189 template<
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void
197 visualizer_updating_mutex_.lock ();
201 if (!first_update_flag_)
203 first_update_flag_ =
true;
205 this->cloud_source_ = cloud_src;
206 this->cloud_target_ = cloud_tgt;
208 this->cloud_intermediate_ = cloud_src;
212 cloud_intermediate_ = cloud_src;
213 cloud_intermediate_indices_ = indices_src;
216 cloud_target_indices_ = indices_tgt;
219 visualizer_updating_mutex_.unlock ();
RegistrationVisualizer represents the base class for rendering the intermediate positions occupied by...
void stopDisplay()
Stop the viewer thread.
void startDisplay()
Start the viewer thread.
void updateIntermediateCloud(const pcl::PointCloud< PointSource > &cloud_src, const pcl::Indices &indices_src, const pcl::PointCloud< PointTarget > &cloud_tgt, const pcl::Indices &indices_tgt)
Updates visualizer local buffers cloud_intermediate, cloud_intermediate_indices, cloud_target_indices...
PCL Visualizer main class.
shared_ptr< PCLVisualizer > Ptr
Handler for predefined user colors.
IndicesAllocator<> Indices
Type used for indices in PCL.