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

Method pp_callback

apps/src/pcd_select_object_plane.cpp:435–524  ·  view source on GitHub ↗

//////////////////////////////////////////////////////////////////// * \brief Point picking callback. This gets called when the user selects * a 3D point on screen (in the PCLVisualizer window) using Shift+click. * * \param[in] event the event that triggered the call */

Source from the content-addressed store, hash-verified

433 * \param[in] event the event that triggered the call
434 */
435 void
436 pp_callback(const visualization::PointPickingEvent& event, void*)
437 {
438 // Check to see if we got a valid point. Early exit.
439 int idx = event.getPointIndex();
440 if (idx == -1)
441 return;
442
443 pcl::Indices indices(1);
444 std::vector<float> distances(1);
445
446 // Get the point that was picked
447 PointT picked_pt;
448 event.getPoint(picked_pt.x, picked_pt.y, picked_pt.z);
449
450 print_info(stderr,
451 "Picked point with index %d, and coordinates %f, %f, %f.\n",
452 idx,
453 picked_pt.x,
454 picked_pt.y,
455 picked_pt.z);
456
457 // Add a sphere to it in the PCLVisualizer window
458 const std::string sphere_name = "sphere_" + std::to_string(idx);
459 cloud_viewer_->addSphere(picked_pt, 0.01, 1.0, 0.0, 0.0, sphere_name);
460
461 // Because VTK/OpenGL stores data without NaN, we lose the 1-1 correspondence, so we
462 // must search for the real point
463 search_->nearestKSearch(picked_pt, 1, indices, distances);
464
465 // Add some marker to the image
466 if (image_viewer_) {
467 // Get the [u, v] in pixel coordinates for the ImageViewer. Remember that 0,0 is
468 // bottom left.
469 std::uint32_t width = search_->getInputCloud()->width,
470 height = search_->getInputCloud()->height;
471 int v = height - indices[0] / width, u = indices[0] % width;
472
473 image_viewer_->addCircle(u, v, 5, 1.0, 0.0, 0.0, "circles", 1.0);
474 image_viewer_->addFilledRectangle(
475 u - 5, u + 5, v - 5, v + 5, 0.0, 1.0, 0.0, "boxes", 0.5);
476 image_viewer_->markPoint(
477 u, v, visualization::red_color, visualization::blue_color, 10);
478 }
479
480 // Segment the region that we're interested in, by employing a two step process:
481 // * first, segment all the planes in the scene, and find the one closest to our
482 // picked point
483 // * then, use euclidean clustering to find the object that we clicked on and
484 // return it
485 PlanarRegion<PointT> region;
486 segment(picked_pt, indices[0], region, object_);
487
488 // If no region could be determined, exit
489 if (region.getContour().empty()) {
490 PCL_ERROR("No planar region detected. Please select another point or relax the "
491 "thresholds and continue.\n");
492 return;

Callers

nothing calls this directly

Calls 15

addFilledRectangleMethod · 0.80
markPointMethod · 0.80
addPlanarPolygonMethod · 0.80
updatePointCloudMethod · 0.80
removeLayerMethod · 0.80
addMaskMethod · 0.80
getPointIndexMethod · 0.45
getPointMethod · 0.45
addSphereMethod · 0.45
nearestKSearchMethod · 0.45
getInputCloudMethod · 0.45

Tested by

no test coverage detected