From 9ddd35adadbfa6a6fe17e8fe4c23c81db1640ff5 Mon Sep 17 00:00:00 2001 From: Rasmus Diederichsen Date: Wed, 24 May 2023 11:28:17 +0200 Subject: [PATCH 1/2] make coordinate system unpickable --- visualization/src/pcl_visualizer.cpp | 30 +++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp index f2eb40e4ff7..c3517bf9de7 100644 --- a/visualization/src/pcl_visualizer.cpp +++ b/visualization/src/pcl_visualizer.cpp @@ -698,6 +698,7 @@ pcl::visualization::PCLVisualizer::addCoordinateSystem (double scale, const std: vtkSmartPointer axes_actor = vtkSmartPointer::New (); axes_actor->SetMapper (axes_mapper); + axes_actor->SetPickable(false); // Save the ID and actor pair to the global actor map (*coordinate_actor_map_) [id] = axes_actor; @@ -740,6 +741,7 @@ pcl::visualization::PCLVisualizer::addCoordinateSystem (double scale, float x, f vtkSmartPointer axes_actor = vtkSmartPointer::New (); axes_actor->SetMapper (axes_mapper); axes_actor->SetPosition (x, y, z); + axes_actor->SetPickable(false); // Save the ID and actor pair to the global actor map (*coordinate_actor_map_) [id] = axes_actor; @@ -1408,7 +1410,7 @@ pcl::visualization::PCLVisualizer::setPointCloudRenderingProperties ( // Check if the mapper has scalars if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()) break; - + // Check that scalars are not unisgned char (i.e. check if a LUT is used to colormap scalars assuming vtk ColorMode is Default) if (actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->IsA ("vtkUnsignedCharArray")) break; @@ -1419,7 +1421,7 @@ pcl::visualization::PCLVisualizer::setPointCloudRenderingProperties ( PCL_WARN ("[setPointCloudRenderingProperties] Range max must be greater than range min!\n"); return (false); } - + // Update LUT actor->GetMapper ()->GetLookupTable ()->SetRange (val1, val2); actor->GetMapper()->UseLookupTableScalarRangeOn (); @@ -1571,7 +1573,7 @@ pcl::visualization::PCLVisualizer::setPointCloudRenderingProperties ( // Check if the mapper has scalars if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()) break; - + // Check that scalars are not unisgned char (i.e. check if a LUT is used to colormap scalars assuming vtk ColorMode is Default) if (actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->IsA ("vtkUnsignedCharArray")) break; @@ -1579,7 +1581,7 @@ pcl::visualization::PCLVisualizer::setPointCloudRenderingProperties ( // Get range limits from existing LUT double *range; range = actor->GetMapper ()->GetLookupTable ()->GetRange (); - + actor->GetMapper ()->ScalarVisibilityOn (); actor->GetMapper ()->SetScalarRange (range[0], range[1]); vtkSmartPointer table; @@ -1595,7 +1597,7 @@ pcl::visualization::PCLVisualizer::setPointCloudRenderingProperties ( // Check if the mapper has scalars if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()) break; - + // Check that scalars are not unisgned char (i.e. check if a LUT is used to colormap scalars assuming vtk ColorMode is Default) if (actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->IsA ("vtkUnsignedCharArray")) break; @@ -1725,7 +1727,7 @@ pcl::visualization::PCLVisualizer::setShapeRenderingProperties ( // Check if the mapper has scalars if (!actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()) break; - + // Check that scalars are not unisgned char (i.e. check if a LUT is used to colormap scalars assuming vtk ColorMode is Default) if (actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->IsA ("vtkUnsignedCharArray")) break; @@ -1736,7 +1738,7 @@ pcl::visualization::PCLVisualizer::setShapeRenderingProperties ( PCL_WARN ("[setShapeRenderingProperties] Range max must be greater than range min!\n"); return (false); } - + // Update LUT actor->GetMapper ()->GetLookupTable ()->SetRange (val1, val2); actor->GetMapper()->UseLookupTableScalarRangeOn (); @@ -1869,11 +1871,11 @@ pcl::visualization::PCLVisualizer::setShapeRenderingProperties ( // Check that scalars are not unisgned char (i.e. check if a LUT is used to colormap scalars assuming vtk ColorMode is Default) if (actor->GetMapper ()->GetInput ()->GetPointData ()->GetScalars ()->IsA ("vtkUnsignedCharArray")) break; - + // Get range limits from existing LUT double *range; range = actor->GetMapper ()->GetLookupTable ()->GetRange (); - + actor->GetMapper ()->ScalarVisibilityOn (); actor->GetMapper ()->SetScalarRange (range[0], range[1]); vtkSmartPointer table; @@ -3013,7 +3015,7 @@ pcl::visualization::PCLVisualizer::addPolygonMesh (const pcl::PolygonMesh &poly_ pcl::fromPCLPointCloud2 (poly_mesh.cloud, *point_cloud); poly_points->SetNumberOfPoints (point_cloud->size ()); - for (std::size_t i = 0; i < point_cloud->size (); ++i) + for (std::size_t i = 0; i < point_cloud->size (); ++i) { const pcl::PointXYZ& p = (*point_cloud)[i]; poly_points->InsertPoint (i, p.x, p.y, p.z); @@ -3183,7 +3185,7 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh ( // Update the cells cells = vtkSmartPointer::New (); - + const auto idx = details::fillCells(lookup, verts, cells, max_size_of_polygon); cells->GetData ()->SetNumberOfValues (idx); @@ -3427,7 +3429,7 @@ pcl::visualization::PCLVisualizer::addTextureMesh (const pcl::TextureMesh &mesh, mapper->MapDataArrayToMultiTextureAttribute(tu, this_coordinates_name.c_str(), vtkDataObject::FIELD_ASSOCIATION_POINTS); - + polydata->GetPointData ()->AddArray (coordinates); actor->GetProperty ()->SetTexture (tu, texture); ++tex_id; @@ -4346,7 +4348,7 @@ pcl::visualization::PCLVisualizer::close () void pcl::visualization::PCLVisualizer::removeCorrespondences ( const std::string &id, int viewport) -{ +{ removeShape (id, viewport); } @@ -4579,7 +4581,7 @@ pcl::visualization::PCLVisualizer::getUniqueCameraFile (int argc, char **argv) p_file_indices = pcl::console::parse_file_extension_argument (argc, argv, ".pcd"); if (!p_file_indices.empty ()) { - boost::uuids::detail::sha1 sha1; + boost::uuids::detail::sha1 sha1; bool valid = false; // Calculate sha1 using canonical paths From 7c6c2ce5a0861b8eb4aee6bc3d726df1576ea409 Mon Sep 17 00:00:00 2001 From: Rasmus Diederichsen Date: Tue, 9 Dec 2025 20:27:35 +0100 Subject: [PATCH 2/2] add pickable option to addCoordinateSystem and make coordinate actors gettable --- tools/pcd_viewer.cpp | 16 ++++++++-------- .../include/pcl/visualization/pcl_visualizer.h | 15 ++++++++++++--- visualization/src/pcl_visualizer.cpp | 16 ++++++++++++---- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/tools/pcd_viewer.cpp b/tools/pcd_viewer.cpp index 6084d82a7ed..3be3b5582b7 100644 --- a/tools/pcd_viewer.cpp +++ b/tools/pcd_viewer.cpp @@ -93,7 +93,7 @@ isOnly2DImage (const pcl::PCLPointField &field) return (true); return (false); } - + void printHelp (int, char **argv) { @@ -219,7 +219,7 @@ pp_callback (const pcl::visualization::PointPickingEvent& event, void* cookie) event.getPoint (pos.x, pos.y, pos.z); p->addText3D (idx_string, pos, 0.0005, 1.0, 1.0, 1.0, idx_string); } - + } /* ---[ */ @@ -286,7 +286,7 @@ main (int argc, char** argv) bool use_vbos = false; pcl::console::parse_argument (argc, argv, "-vbo_rendering", use_vbos); - if (use_vbos) + if (use_vbos) print_highlight ("Vertex Buffer Object (VBO) visualization enabled.\n"); bool useEDLRendering = false; @@ -295,7 +295,7 @@ main (int argc, char** argv) print_highlight("EDL visualization enabled.\n"); bool use_pp = pcl::console::find_switch (argc, argv, "-use_point_picking"); - if (use_pp) + if (use_pp) print_highlight ("Point picking enabled.\n"); bool use_ap = pcl::console::find_switch(argc, argv, "-use_area_picking"); @@ -311,7 +311,7 @@ main (int argc, char** argv) if (!use_vbos) { pcl::console::parse_argument (argc, argv, "-immediate_rendering", use_immediate_rendering); - if (use_immediate_rendering) + if (use_immediate_rendering) print_highlight ("Using immediate mode rendering.\n"); } @@ -486,7 +486,7 @@ main (int argc, char** argv) { print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : "); print_value ("%u", cloud->width * cloud->height); print_info (" points]\n"); print_info ("Available dimensions: "); print_value ("%s\n", pcl::getFieldsList (*cloud).c_str ()); - + std::string name = "PCD Viewer :: " + std::string(argv[p_file_indices.at (i)]); pcl::visualization::ImageViewer::Ptr img (new pcl::visualization::ImageViewer (name)); pcl::PointCloud rgb_cloud; @@ -719,7 +719,7 @@ main (int argc, char** argv) float ax_x = 0.0, ax_y = 0.0, ax_z = 0.0; pcl::console::parse_3x_arguments (argc, argv, "-ax_pos", ax_x, ax_y, ax_z); // Draw XYZ axes if command-line enabled - p->addCoordinateSystem (axes, ax_x, ax_y, ax_z, "global"); + p->addCoordinateSystem (axes, ax_x, ax_y, ax_z, "global", 0, false); } // Clean up the memory used by the binary blob @@ -747,7 +747,7 @@ main (int argc, char** argv) } img->spinOnce (); } - + if (p) { if (p->wasStopped ()) diff --git a/visualization/include/pcl/visualization/pcl_visualizer.h b/visualization/include/pcl/visualization/pcl_visualizer.h index 27318ab0b54..05379a3348f 100644 --- a/visualization/include/pcl/visualization/pcl_visualizer.h +++ b/visualization/include/pcl/visualization/pcl_visualizer.h @@ -308,9 +308,10 @@ namespace pcl * \param[in] scale the scale of the axes (default: 1) * \param[in] id the coordinate system object id (default: reference) * \param[in] viewport the view port where the 3D axes should be added (default: all) + * \param[in] pickable Whether the resulting vtk actors are pickable, i.e. they may attract the view when using 'f' for fly-to-point */ void - addCoordinateSystem (double scale = 1.0, const std::string& id = "reference", int viewport = 0); + addCoordinateSystem (double scale = 1.0, const std::string& id = "reference", int viewport = 0, bool pickable = true); /** \brief Adds 3D axes describing a coordinate system to screen at x, y, z * \param[in] scale the scale of the axes (default: 1) @@ -319,9 +320,10 @@ namespace pcl * \param[in] z the Z position of the axes * \param[in] id the coordinate system object id (default: reference) * \param[in] viewport the view port where the 3D axes should be added (default: all) + * \param[in] pickable Whether the resulting vtk actors are pickable, i.e. they may attract the view when using 'f' for fly-to-point */ void - addCoordinateSystem (double scale, float x, float y, float z, const std::string &id = "reference", int viewport = 0); + addCoordinateSystem (double scale, float x, float y, float z, const std::string &id = "reference", int viewport = 0, bool pickable = true); /** \brief Adds 3D axes describing a coordinate system to screen at x, y, z, Roll,Pitch,Yaw * @@ -1714,7 +1716,7 @@ namespace pcl * @brief Eye-Dome Lighting makes dark areas to improve depth perception * See https://www.kitware.com/eye-dome-lighting-a-non-photorealistic-shading-technique/ * It is applied to all actors, including texts. - * @param viewport + * @param viewport */ void enableEDLRendering(int viewport = 0); @@ -1942,6 +1944,13 @@ namespace pcl return (shape_actor_map_); } + /** \brief Return a pointer to the CoordinateActorMap this visualizer uses. */ + CoordinateActorMapPtr + getCoordinateActorMap () + { + return (coordinate_actor_map_); + } + /** \brief Set the position in screen coordinates. * \param[in] x where to move the window to (X) * \param[in] y where to move the window to (Y) diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp index 87e2d80b749..01f9e70d8ba 100644 --- a/visualization/src/pcl_visualizer.cpp +++ b/visualization/src/pcl_visualizer.cpp @@ -658,7 +658,7 @@ pcl::visualization::PCLVisualizer::removeOrientationMarkerWidgetAxes () ///////////////////////////////////////////////////////////////////////////////////////////// void -pcl::visualization::PCLVisualizer::addCoordinateSystem (double scale, const std::string &id, int viewport) +pcl::visualization::PCLVisualizer::addCoordinateSystem (double scale, const std::string &id, int viewport, bool pickable) { if (scale <= 0.0) scale = 1.0; @@ -690,7 +690,11 @@ pcl::visualization::PCLVisualizer::addCoordinateSystem (double scale, const std: vtkSmartPointer axes_actor = vtkSmartPointer::New (); axes_actor->SetMapper (axes_mapper); - axes_actor->SetPickable(false); + + if (!pickable) + { + axes_actor->SetPickable(false); + } // Save the ID and actor pair to the global actor map (*coordinate_actor_map_) [id] = axes_actor; @@ -700,7 +704,7 @@ pcl::visualization::PCLVisualizer::addCoordinateSystem (double scale, const std: ///////////////////////////////////////////////////////////////////////////////////////////// void -pcl::visualization::PCLVisualizer::addCoordinateSystem (double scale, float x, float y, float z, const std::string& id, int viewport) +pcl::visualization::PCLVisualizer::addCoordinateSystem (double scale, float x, float y, float z, const std::string& id, int viewport, bool pickable) { if (scale <= 0.0) scale = 1.0; @@ -733,7 +737,11 @@ pcl::visualization::PCLVisualizer::addCoordinateSystem (double scale, float x, f vtkSmartPointer axes_actor = vtkSmartPointer::New (); axes_actor->SetMapper (axes_mapper); axes_actor->SetPosition (x, y, z); - axes_actor->SetPickable(false); + + if (!pickable) + { + axes_actor->SetPickable(false); + } // Save the ID and actor pair to the global actor map (*coordinate_actor_map_) [id] = axes_actor;