004-四视图增加文字显示

263 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

头图

这篇文章中就要给我的四视图增加文字显示了,这个东西就是在我摄像机上面的,不会随着图像变化而变化,感觉这个是不是就是在3D中的那种HUD呢。

1 效果展示2 vtkTextActor3 实现代码3.1 头文件3.2 源文件实现3.2.1 新建变量,赋值,设置属性3.2.2 加入到渲染器中☞ 源码

1 效果展示

如下图所示,在每个图的左上角和左下角有文字显示,左上角显示的病人的基本信息,左下角显示的是当前切面。

动画

2 vtkTextActor

实现文字显示,主要将用到vtkTextActor,这里还是把参考链接附上

vtk.org/doc/nightly…

image-20210726170048283

回家截图

3 实现代码

3.1 头文件

既然用到了vtkTextActor那就就要包含他的头文件了,后面需要设置颜色啥的,所以需要我们顺便把属性头文件也包含了。如下

 #include "vtkTextActor.h"
 #include "vtkTextProperty.h"

新建变量

 vtkSmartPointer<vtkTextActor> textActor[4];
 vtkSmartPointer<vtkTextActor> peopleInforTextActor[4];

3.2 源文件实现

3.2.1 新建变量,赋值,设置属性

 for (auto i=0;i<4;i++)
 {
     textActor[i] = vtkSmartPointer<vtkTextActor>::New();
     textActor[i]->SetDisplayPosition(5, 5);
     textActor[i]->GetTextProperty()->SetFontSize(14);
     textActor[i]->GetTextProperty()->SetFontFamily(VTK_FONT_FILE);
     textActor[i]->GetTextProperty()->SetFontFile(QString("./Fonts/simhei.ttf").toUtf8());
 }
 textActor[0]->SetInput(QString::fromUtf8("矢状").toUtf8());
 textActor[0]->GetTextProperty()->SetColor(0, 1, 0);
 textActor[1]->SetInput(QString::fromUtf8("冠状").toUtf8());
 textActor[1]->GetTextProperty()->SetColor(0, 0, 1);
 textActor[2]->SetInput(QString::fromUtf8("轴向").toUtf8());
 textActor[2]->GetTextProperty()->SetColor(1, 0, 0);
 textActor[3]->SetInput(QString::fromUtf8("3D").toUtf8());
 textActor[3]->GetTextProperty()->SetColor(1, 1, 0);
 for (auto i=0;i<4;i++)
 {
     peopleInforTextActor[i] = vtkSmartPointer<vtkTextActor>::New();
     peopleInforTextActor[i]->GetTextProperty()->SetFontSize(14);
     peopleInforTextActor[i]->GetTextProperty()->SetFontFamily(VTK_FONT_FILE);
     peopleInforTextActor[i]->GetTextProperty()->SetFontFile(QString("./Fonts/simhei.ttf").toUtf8());
     peopleInforTextActor[i]->SetInput(reader->GetPatientName());
 }
 peopleInforTextActor[0]->GetTextProperty()->SetColor(0, 1, 0);
 peopleInforTextActor[0]->SetDisplayPosition(5,ui->widget_1->height()-20);
 peopleInforTextActor[1]->GetTextProperty()->SetColor(0, 0, 1);
 peopleInforTextActor[1]->SetDisplayPosition(5,ui->widget_2->height()-20);
 peopleInforTextActor[2]->GetTextProperty()->SetColor(1, 0, 0);
 peopleInforTextActor[2]->SetDisplayPosition(5,ui->widget_3->height()-20);
 peopleInforTextActor[3]->GetTextProperty()->SetColor(1, 1, 0);
 peopleInforTextActor[3]->SetDisplayPosition(5,ui->widget_4->height()-20);

3.2.2 加入到渲染器中

我这里有两种,如下:

 riw[i]->GetRenderer()->AddActor(textActor[i]);
 riw[i]->GetRenderer()->AddActor(peopleInforTextActor[i]);
 ren->AddActor(textActor[3]);
 ren->AddActor(peopleInforTextActor[3]);

详细内容见源码

☞ 源码

源码链接:github.com/DreamLife-J…

使用方法:☟☟☟

源码