Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions visualization/include/pcl/visualization/image_viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,31 @@ namespace pcl
addLine (unsigned int x_min, unsigned int y_min, unsigned int x_max, unsigned int y_max,
const std::string &layer_id = "line", double opacity = 1.0);

/** \brief Add a 2D text with a given color
* \param[in] x the X coordinate
* \param[in] y the Y coordinate
* \param[in] text the text string to be displayed
* \param[in] r the red channel of the color that the line should be rendered with (0.0 -> 1.0)
* \param[in] g the green channel of the color that the line should be rendered with (0.0 -> 1.0)
* \param[in] b the blue channel of the color that the line should be rendered with (0.0 -> 1.0)
* \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
* \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
*/
bool
addText (unsigned int x, unsigned int y, const std::string& text,
double r, double g, double b,
const std::string &layer_id = "line", double opacity = 1.0);

/** \brief Add a 2D text with a given color
* \param[in] x the X coordinate
* \param[in] y the Y coordinate
* \param[in] text the text string to be displayed
* \param[in] layer_id the 2D layer ID where we want the extra information to be drawn.
* \param[in] opacity the opacity of the layer: 0 for invisible, 1 for opaque. (default: 1.0)
*/
bool
addText (unsigned int x, unsigned int y, const std::string& text,
const std::string &layer_id = "line", double opacity = 1.0);

/** \brief Add a generic 2D mask to an image
* \param[in] image the organized point cloud dataset containing the image data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ namespace pcl
static Polygon *New();
virtual bool Paint (vtkContext2D *painter);
};

struct PCL_EXPORTS Text : public PCLContextItem
{
vtkTypeMacro (Text, PCLContextItem);
static Text *New ();
virtual bool Paint (vtkContext2D *painter);
virtual void set (float x, float y, const std::string& _text);
std::string text;
};
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions visualization/src/image_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,47 @@ pcl::visualization::ImageViewer::addLine (unsigned int x_min, unsigned int y_min
return (addLine (x_min, y_min, x_max, y_max, 0.0, 1.0, 0.0, layer_id, opacity));
}

//////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::visualization::ImageViewer::addText (unsigned int x, unsigned int y,
const std::string& text_string,
double r, double g, double b,
const std::string &layer_id, double opacity)
{
// Check to see if this ID entry already exists (has it been already added to the visualizer?)
LayerMap::iterator am_it = std::find_if (layer_map_.begin (), layer_map_.end (), LayerComparator (layer_id));
if (am_it == layer_map_.end ())
{
PCL_DEBUG ("[pcl::visualization::ImageViewer::addText] No layer with ID='%s' found. Creating new one...\n", layer_id.c_str ());
am_it = createLayer (layer_id, getSize ()[0] - 1, getSize ()[1] - 1, opacity, false);
#if ((VTK_MAJOR_VERSION == 5) && (VTKOR_VERSION > 10))
interactor_style_->adjustCamera (ren_);
#endif
}

vtkSmartPointer<context_items::Text> text = vtkSmartPointer<context_items::Text>::New ();
text->setColors (static_cast<unsigned char> (255.0 * r),
static_cast<unsigned char> (255.0 * g),
static_cast<unsigned char> (255.0 * b));
text->setOpacity (opacity);
#if ((VTK_MAJOR_VERSION == 5) && (VTKOR_VERSION > 10))
text->set (static_cast<float> (x), static_cast<float> (y), text_string);
#else
text->set (static_cast<float> (x), static_cast<float> (getSize ()[1] - y), text_string);
#endif
am_it->actor->GetScene ()->AddItem (text);

return (true);
}

//////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::visualization::ImageViewer::addText (unsigned int x, unsigned int y, const std::string& text,
const std::string &layer_id, double opacity)
{
return (addText (x, y, text, 0.0, 1.0, 0.0, layer_id, opacity));
}

//////////////////////////////////////////////////////////////////////////////////////////
void
pcl::visualization::ImageViewer::markPoint (
Expand Down
27 changes: 26 additions & 1 deletion visualization/src/vtk/pcl_context_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <vtkImageData.h>
#include <vtkPen.h>
#include <vtkBrush.h>
#include <vtkTextProperty.h>

#include <pcl/visualization/vtk/pcl_context_item.h>

Expand All @@ -61,6 +62,7 @@ namespace pcl
vtkStandardNewMacro (FilledRectangle);
vtkStandardNewMacro (Points);
vtkStandardNewMacro (Polygon);
vtkStandardNewMacro (Text);
}
}
}
Expand Down Expand Up @@ -122,6 +124,15 @@ pcl::visualization::context_items::Line::set (float start_x, float start_y, floa
params[0] = start_x; params[1] = start_y; params[2] = end_x; params[3] = end_y;
}

///////////////////////////////////////////////////////////////////////////////////////////
void
pcl::visualization::context_items::Text::set (float x, float y, const std::string& _text)
{
params.resize (2);
params[0] = x; params[1] = y;
text = _text;
}

///////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::visualization::context_items::Circle::Paint (vtkContext2D *painter)
Expand Down Expand Up @@ -207,9 +218,23 @@ pcl::visualization::context_items::Points::Paint (vtkContext2D *painter)
return (true);
}

///////////////////////////////////////////////////////////////////////////////////////////
bool
pcl::visualization::context_items::Text::Paint (vtkContext2D *painter)
{
vtkTextProperty *text_property = painter->GetTextProp ();
text_property->SetColor (255.0 * colors[0], 255.0 * colors[1], 255.0 * colors[2]);
text_property->SetFontFamilyToArial ();
text_property->SetFontSize (10);
text_property->SetJustificationToLeft ();
text_property->BoldOff ();
text_property->ShadowOff ();
painter->DrawString (params[0], params[1], text.c_str ());
return (true);
}

///////////////////////////////////////////////////////////////////////////////////////////
pcl::visualization::PCLContextImageItem::PCLContextImageItem ()
{
image = vtkSmartPointer<vtkImageData>::New ();
}