7 #include <vtkTextActor.h> 8 #include <vtkTextProperty.h> 9 #include <vtkTextMapper.h> 11 #include "imstkVTKTextRenderDelegate.h" 12 #include "imstkTextVisualModel.h" 17 VTKTextRenderDelegate::init()
19 auto textVisualModel = std::dynamic_pointer_cast<TextVisualModel>(
m_visualModel);
21 m_textMapper = vtkSmartPointer<vtkTextMapper>::New();
22 m_textMapper->SetInput(textVisualModel->getText().c_str());
25 vtkTextProperty* txtprop = m_textMapper->GetTextProperty();
26 txtprop->SetFontSize(textVisualModel->getFontSize());
27 txtprop->SetFontFamilyToArial();
28 txtprop->SetBackgroundColor(180, 180, 180);
29 txtprop->SetBackgroundOpacity(0.75);
31 const Color& fontColor = textVisualModel->getTextColor();
32 txtprop->SetColor(fontColor.r, fontColor.g, fontColor.b);
33 txtprop->SetJustificationToCentered();
34 txtprop->SetVerticalJustificationToCentered();
37 m_textActor = vtkSmartPointer<vtkActor2D>::New();
38 m_textActor->SetMapper(m_textMapper);
39 m_textActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedDisplay();
40 m_textActor->GetPositionCoordinate()->SetValue(0.5, 0.5);
43 TextVisualModel::DisplayPosition position = textVisualModel->getPosition();
46 case TextVisualModel::DisplayPosition::CenterCenter:
50 case TextVisualModel::DisplayPosition::UpperLeft:
51 txtprop->SetJustificationToLeft();
52 txtprop->SetVerticalJustificationToTop();
53 m_textActor->GetPositionCoordinate()->SetValue(0.01, 0.95);
56 case TextVisualModel::DisplayPosition::UpperRight:
57 txtprop->SetJustificationToRight();
58 txtprop->SetVerticalJustificationToTop();
59 m_textActor->GetPositionCoordinate()->SetValue(0.95, 0.95);
62 case TextVisualModel::DisplayPosition::LowerRight:
63 txtprop->SetJustificationToRight();
64 txtprop->SetVerticalJustificationToBottom();
65 m_textActor->GetPositionCoordinate()->SetValue(0.95, 0.05);
68 case TextVisualModel::DisplayPosition::LowerLeft:
69 txtprop->SetJustificationToLeft();
70 txtprop->SetVerticalJustificationToBottom();
71 m_textActor->GetPositionCoordinate()->SetValue(0.05, 0.05);
75 m_mapper = m_textMapper;
76 m_actor = m_textActor;
87 if (textVisualModel->getText() != std::string(m_textMapper->GetInput()))
89 m_textMapper->SetInput(textVisualModel->getText().c_str());
92 m_textActor->SetVisibility(textVisualModel->getVisibility());
void updateRenderProperties() override
Updates the actor and mapper properties from the currently set VisualModel.
std::shared_ptr< VisualModel > m_visualModel
imstk visual model (contains data (geometry) and render specification (render material)) ...
void processEvents() override
Plot text and track updates to TextVisualModel.
Renders text to the screen.