//绘制文本
#include<vtkRenderer.h>
#include<vtkPolyDataMapper.h>
#include<vtkActor.h>
#include<vtkRenderWindow.h>
#include<vtkPolyDataMapper.h>
#include<vtkFollower.h>
#include<vtkVectorText.h>
#include<vtkAxes.h>
#include<vtkProperty.h>
#include<vtkNamedColors.h>
#include <vtkAppendPolyData.h>
#include<vtkRenderWindowInteractor.h>
#include<vtkAutoInit.h>
#include <vtkVectorText.h>
#include <vtkTransform.h>
#include <vtkTransformFilter.h>
#include <vtkAppendPolyData.h>
int main(int argc, char *argv[])
{
//点集合
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
//定义cells
vtkSmartPointer<vtkCellArray> verts = vtkSmartPointer<vtkCellArray>::New();
//保存标签多边形的
vtkSmartPointer<vtkAppendPolyData> appendPolyData = vtkSmartPointer<vtkAppendPolyData>::New();
vtkSmartPointer<vtkMath> math = vtkSmartPointer<vtkMath>::New();
for (int i = 0;i<500;i++) {
double x = math->Random(1, 3);
double y = math->Random(1, 3);
double z = math->Random(1, 3);
points->InsertNextPoint(x, y, z);
verts->InsertNextCell(1);
verts->InsertCellPoint(i);
vtkSmartPointer<vtkVectorText> text = vtkSmartPointer<vtkVectorText>::New();
text->SetText(std::to_string(i).c_str());
//--进行缩放
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
t->Translate(x, y, z);
t->Scale(.04, .04, .04); //NOTICE,缩放比例,注意,放在正常比例中会很小,甚至看不到
vtkSmartPointer<vtkTransformFilter> tf = vtkSmartPointer<vtkTransformFilter>::New();
tf->SetTransform(t);
//tf->SetInputData(text->GetOutput());
tf->SetInputConnection(text->GetOutputPort());
appendPolyData->AddInputConnection(tf->GetOutputPort());
}
//原始数据 显示点集合
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
polyData->SetPoints(points);
polyData->SetVerts(verts);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(polyData);
vtkSmartPointer<vtkActor> vertsActor = vtkSmartPointer<vtkActor>::New();
vertsActor->SetMapper(mapper);
vertsActor->GetProperty()->SetPointSize(5);
//显示字体
vtkSmartPointer<vtkPolyDataMapper> textMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
textMapper->SetInputConnection(appendPolyData->GetOutputPort());
//textMapper->SetInputData(appendPolyData->GetOutput());
vtkSmartPointer<vtkActor> textActor = vtkSmartPointer<vtkActor>::New();
textActor->SetMapper(textMapper);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(vertsActor);
renderer->AddActor(textActor);
renderer->SetBackground(.4, .5, .6);
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
renderWindow->SetSize(500, 500);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();
}