text3D widget implementation
This commit is contained in:
parent
e185900270
commit
5813a3a99d
@ -121,6 +121,15 @@ namespace temp_viz
|
||||
GridWidget(Vec2i dimensions, Vec2d spacing, const Color &color = Color::white());
|
||||
};
|
||||
|
||||
class CV_EXPORTS Text3DWidget : public Widget3D
|
||||
{
|
||||
public:
|
||||
Text3DWidget(const String &text, const Point3f &position, double text_scale = 1.0, const Color &color = Color::white());
|
||||
|
||||
void setText(const String &text);
|
||||
String getText() const;
|
||||
};
|
||||
|
||||
class CV_EXPORTS TextWidget : public Widget2D
|
||||
{
|
||||
public:
|
||||
@ -161,6 +170,7 @@ namespace temp_viz
|
||||
template<> CV_EXPORTS CoordinateSystemWidget Widget::cast<CoordinateSystemWidget>();
|
||||
template<> CV_EXPORTS PolyLineWidget Widget::cast<PolyLineWidget>();
|
||||
template<> CV_EXPORTS GridWidget Widget::cast<GridWidget>();
|
||||
template<> CV_EXPORTS Text3DWidget Widget::cast<Text3DWidget>();
|
||||
template<> CV_EXPORTS TextWidget Widget::cast<TextWidget>();
|
||||
template<> CV_EXPORTS CloudWidget Widget::cast<CloudWidget>();
|
||||
template<> CV_EXPORTS CloudNormalsWidget Widget::cast<CloudNormalsWidget>();
|
||||
|
@ -450,6 +450,59 @@ template<> temp_viz::GridWidget temp_viz::Widget::cast<temp_viz::GridWidget>()
|
||||
return static_cast<GridWidget&>(widget);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// text3D widget implementation
|
||||
|
||||
temp_viz::Text3DWidget::Text3DWidget(const String &text, const Point3f &position, double text_scale, const Color &color)
|
||||
{
|
||||
vtkSmartPointer<vtkVectorText> textSource = vtkSmartPointer<vtkVectorText>::New ();
|
||||
textSource->SetText (text.c_str());
|
||||
textSource->Update ();
|
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New ();
|
||||
mapper->SetInputConnection (textSource->GetOutputPort ());
|
||||
|
||||
vtkSmartPointer<vtkFollower> actor = vtkSmartPointer<vtkFollower>::New ();
|
||||
actor->SetMapper (mapper);
|
||||
actor->SetPosition (position.x, position.y, position.z);
|
||||
actor->SetScale (text_scale);
|
||||
|
||||
WidgetAccessor::setProp(*this, actor);
|
||||
setColor(color);
|
||||
}
|
||||
|
||||
void temp_viz::Text3DWidget::setText(const String &text)
|
||||
{
|
||||
vtkFollower *actor = vtkFollower::SafeDownCast(WidgetAccessor::getProp(*this));
|
||||
CV_Assert(actor);
|
||||
|
||||
// Update text source
|
||||
vtkPolyDataMapper *mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper());
|
||||
vtkVectorText * textSource = vtkVectorText::SafeDownCast(mapper->GetInputConnection(0,0)->GetProducer());
|
||||
CV_Assert(textSource);
|
||||
|
||||
textSource->SetText(text.c_str());
|
||||
textSource->Update();
|
||||
}
|
||||
|
||||
temp_viz::String temp_viz::Text3DWidget::getText() const
|
||||
{
|
||||
vtkFollower *actor = vtkFollower::SafeDownCast(WidgetAccessor::getProp(*this));
|
||||
CV_Assert(actor);
|
||||
|
||||
vtkPolyDataMapper *mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper());
|
||||
vtkVectorText * textSource = vtkVectorText::SafeDownCast(mapper->GetInputConnection(0,0)->GetProducer());
|
||||
CV_Assert(textSource);
|
||||
|
||||
return textSource->GetText();
|
||||
}
|
||||
|
||||
template<> temp_viz::Text3DWidget temp_viz::Widget::cast<temp_viz::Text3DWidget>()
|
||||
{
|
||||
Widget3D widget = this->cast<Widget3D>();
|
||||
return static_cast<Text3DWidget&>(widget);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// text widget implementation
|
||||
|
||||
|
@ -142,6 +142,9 @@ TEST(Viz_viz3d, accuracy)
|
||||
temp_viz::GridWidget gw(temp_viz::Vec2i(10,10), temp_viz::Vec2d(0.1,0.1));
|
||||
v.showWidget("grid", gw);
|
||||
lw = v.getWidget("grid").cast<temp_viz::LineWidget>();
|
||||
|
||||
temp_viz::Text3DWidget t3w("OpenCV", cv::Point3f(0.0, 2.0, 0.0), 1.0, temp_viz::Color(255,255,0));
|
||||
v.showWidget("txt3d", t3w);
|
||||
// float grid_x_angle = 0.0;
|
||||
|
||||
while(!v.wasStopped())
|
||||
|
Loading…
x
Reference in New Issue
Block a user