diff --git a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp index 0953c2835e8..2d8e95f901c 100644 --- a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp +++ b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp @@ -715,6 +715,53 @@ pcl::visualization::PCLVisualizer::addText3D ( return (true); } +////////////////////////////////////////////////// +template bool +pcl::visualization::PCLVisualizer::addText3D ( + const std::string &text, + const PointT& position, + double orientation[3], + double textScale, + double r, + double g, + double b, + const std::string &id, + int viewport) +{ + std::string tid; + if (id.empty ()) + tid = text; + else + tid = id; + + if (contains (tid)) + { + PCL_WARN ("[addText3D] The id <%s> already exists! Please choose a different id and retry.\n", id.c_str ()); + return (false); + } + + vtkSmartPointer textSource = vtkSmartPointer::New (); + textSource->SetText (text.c_str()); + textSource->Update (); + + vtkSmartPointer textMapper = vtkSmartPointer::New (); + textMapper->SetInputConnection (textSource->GetOutputPort ()); + + vtkSmartPointer textActor = vtkSmartPointer::New (); + textActor->SetMapper (textMapper); + textActor->SetPosition (position.x, position.y, position.z); + textActor->SetScale (textScale); + textActor->GetProperty ()->SetColor (r, g, b); + textActor->SetOrientation (orientation); + + addActorToRenderer (textActor, viewport); + + // Save the pointer/ID pair to the global actor map. If we are saving multiple vtkFollowers + (*shape_actor_map_)[tid] = textActor; + + return (true); +} + ////////////////////////////////////////////////////////////////////////////////////////////// template bool pcl::visualization::PCLVisualizer::addPointCloudNormals ( diff --git a/visualization/include/pcl/visualization/pcl_visualizer.h b/visualization/include/pcl/visualization/pcl_visualizer.h index 4a9c8b9b753..434524013ae 100644 --- a/visualization/include/pcl/visualization/pcl_visualizer.h +++ b/visualization/include/pcl/visualization/pcl_visualizer.h @@ -599,6 +599,28 @@ namespace pcl double r = 1.0, double g = 1.0, double b = 1.0, const std::string &id = "", int viewport = 0); + /** \brief Add a 3d text to the scene + * \param[in] text the text to add + * \param[in] position the world position where the text should be added + * \param[in] orientation the angles of rotation of the text around X, Y and Z axis, + in this order. The way the rotations are effectively done is the + Z-X-Y intrinsic rotations: + https://en.wikipedia.org/wiki/Euler_angles#Definition_by_intrinsic_rotations + * \param[in] textScale the scale of the text to render + * \param[in] r the red color value + * \param[in] g the green color value + * \param[in] b the blue color value + * \param[in] id the text object id (default: equal to the "text" parameter) + * \param[in] viewport the view port (default: all) + */ + template bool + addText3D (const std::string &text, + const PointT &position, + double orientation[3], + double textScale = 1.0, + double r = 1.0, double g = 1.0, double b = 1.0, + const std::string &id = "", int viewport = 0); + /** \brief Check if the cloud, shape, or coordinate with the given id was already added to this visualizer. * \param[in] id the id of the cloud, shape, or coordinate to check * \return true if a cloud, shape, or coordinate with the specified id was found