-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_text.cpp
54 lines (45 loc) · 1.82 KB
/
test_text.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkLODActor.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
#include "vtkSphereSource.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
int main() {
const auto sphere_source = vtkSmartPointer<vtkSphereSource>::New();
const auto sphere_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
sphere_mapper->SetInputConnection(sphere_source->GetOutputPort());
const auto sphere_actor = vtkSmartPointer<vtkLODActor>::New();
sphere_actor->SetMapper(sphere_mapper);
const auto text_actor = vtkSmartPointer<vtkTextActor>::New();
text_actor->SetTextScaleModeToProp();
// text_actor->SetDisplayPosition(90, 50);
text_actor->SetInput("This is a sphere");
const auto coor = text_actor->GetPositionCoordinate();
coor->SetCoordinateSystemToNormalizedDisplay();
coor->SetValue(0.6, 0.1);
const auto text_property = text_actor->GetTextProperty();
text_property->SetFontSize(18);
text_property->SetFontFamilyToArial();
text_property->SetJustificationToCentered();
text_property->BoldOn();
text_property->ItalicOn();
text_property->ShadowOn();
text_property->SetColor(0, 0, 1);
const auto render = vtkSmartPointer<vtkRenderer>::New();
render->AddActor(sphere_actor);
render->AddActor2D(text_actor);
const auto render_window = vtkSmartPointer<vtkRenderWindow>::New();
render_window->AddRenderer(render);
const auto interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
const auto interactor_style
= vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
interactor->SetInteractorStyle(interactor_style);
interactor->SetRenderWindow(render_window);
interactor->Initialize();
render_window->Render();
interactor->Start();
}