MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / pp_callback

Function pp_callback

tools/pcd_viewer.cpp:169–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167}
168
169void
170pp_callback (const pcl::visualization::PointPickingEvent& event, void* cookie)
171{
172 int idx = event.getPointIndex ();
173 if (idx == -1)
174 return;
175
176 if (!cloud)
177 {
178 cloud = *reinterpret_cast<pcl::PCLPointCloud2::Ptr*> (cookie);
179 xyzcloud.reset (new pcl::PointCloud<pcl::PointXYZ>);
180 pcl::fromPCLPointCloud2 (*cloud, *xyzcloud);
181 search.setInputCloud (xyzcloud);
182 }
183 // Return the correct index in the cloud instead of the index on the screen
184 pcl::Indices indices (1);
185 std::vector<float> distances (1);
186
187 // Because VTK/OpenGL stores data without NaN, we lose the 1-1 correspondence, so we must search for the real point
188 pcl::PointXYZ picked_pt;
189 event.getPoint (picked_pt.x, picked_pt.y, picked_pt.z);
190 search.nearestKSearch (picked_pt, 1, indices, distances);
191
192 PCL_INFO ("Point index picked: %d (real: %d) - [%f, %f, %f]\n", idx, indices[0], picked_pt.x, picked_pt.y, picked_pt.z);
193
194 idx = indices[0];
195 // If two points were selected, draw an arrow between them
196 pcl::PointXYZ p1, p2;
197 if (event.getPoints (p1.x, p1.y, p1.z, p2.x, p2.y, p2.z) && p)
198 {
199 std::stringstream ss;
200 ss << p1 << p2;
201 p->addArrow<pcl::PointXYZ, pcl::PointXYZ> (p1, p2, 1.0, 1.0, 1.0, ss.str ());
202 return;
203 }
204
205 // Else, if a single point has been selected
206 const std::string idx_string = std::to_string(idx);
207 // Get the cloud's fields
208 for (std::size_t i = 0; i < cloud->fields.size (); ++i)
209 {
210 if (!isMultiDimensionalFeatureField (cloud->fields[i]))
211 continue;
212 PCL_INFO ("Multidimensional field found: %s\n", cloud->fields[i].name.c_str ());
213 ph_global.addFeatureHistogram (*cloud, cloud->fields[i].name, idx, idx_string);
214 ph_global.renderOnce ();
215 }
216 if (p)
217 {
218 pcl::PointXYZ pos;
219 event.getPoint (pos.x, pos.y, pos.z);
220 p->addText3D<pcl::PointXYZ> (idx_string, pos, 0.0005, 1.0, 1.0, 1.0, idx_string);
221 }
222
223}
224
225/* ---[ */
226int

Callers

nothing calls this directly

Calls 11

fromPCLPointCloud2Function · 0.85
strMethod · 0.80
renderOnceMethod · 0.80
getPointIndexMethod · 0.45
resetMethod · 0.45
setInputCloudMethod · 0.45
getPointMethod · 0.45
nearestKSearchMethod · 0.45
sizeMethod · 0.45
addFeatureHistogramMethod · 0.45

Tested by

no test coverage detected