VTK+VS在二维图像上添加矩形标注----肺结节检测可视化

在肺结节检测可视化中不但需要在三维的图像中显示标注信息,在要在二维切片式显示标注信息。

vs2017+vtk9.1

实现代码:

原图显示及矩形框标注调用:

void vtk91test::test4()
{
	vtkMetaImageReader* reader = vtkMetaImageReader::New();
	reader->SetFileName("1.mhd");
	reader->Update();
	//vtkImageViewer2在构造函数中实例化的有vtkRenderer和vtkRenderWindow,只需要配置vtkRenderWindowInteractor即可
	vtkSmartPointer<vtkImageViewer2> imageViewer = vtkSmartPointer<vtkImageViewer2>::New();
	imageViewer->SetInputData(reader->GetOutput());

	vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
		vtkSmartPointer<vtkRenderWindowInteractor>::New();
	imageViewer->SetupInteractor(renderWindowInteractor);

	//创建一个矩形  通过对角线两顶点确定一个矩形
	int leftTopX = 80;
	int leftTopY = 50;
	int rightBottomX = 100;
	int rightBottomY = 30;
	QVector<int> vector;
	vector.append(leftTopX);
	vector.append(leftTopY);
	vector.append(rightBottomX);
	vector.append(rightBottomY);
	vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
	actor = addRectangle2D(vector, 1, "Red");
	imageViewer->GetRenderer()->AddActor(actor); 

	imageViewer->SetColorLevel(500);//设置窗位为500
	imageViewer->SetColorWindow(2000);//设置窗宽为2000
	imageViewer->SetSlice(40);//设置切片索引
	imageViewer->SetSliceOrientationToXY();//设置切片方向
	imageViewer->Render();

	imageViewer->SetSize(640, 480);
	imageViewer->GetRenderWindow()->SetWindowName("DisplayImageExample");
	renderWindowInteractor->Start();

	qDebug() << "test4==========================";

}

创建矩形标注框代码:

vtkSmartPointer<vtkActor> vtk91test::addRectangle2D(QVector<int> vector, int width, vtkStdString color)
{
	//使用两个点确定一个矩形
	vtkSmartPointer<vtkLineSource> lineSource = vtkSmartPointer<vtkLineSource>::New();
	vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
	vtkSmartPointer<vtkNamedColors> colors = vtkSmartPointer<vtkNamedColors>::New();

	double p0[3] = { vector.at(0), vector.at(3), 0.0 };
	double p1[3] = { vector.at(2), vector.at(3), 0.0 };
	double p2[3] = { vector.at(2), vector.at(1), 0.0 };
	double p3[3] = { vector.at(0), vector.at(1), 0.0 };
	//一定要闭合起来
	points->InsertNextPoint(p0);
	points->InsertNextPoint(p1);
	points->InsertNextPoint(p2);
	points->InsertNextPoint(p3);
	points->InsertNextPoint(p0);

	lineSource->SetPoints(points);
	lineSource->Update();
	vtkSmartPointer<vtkPolyDataMapper> mapper =
		vtkSmartPointer<vtkPolyDataMapper>::New();
	mapper->SetInputConnection(lineSource->GetOutputPort());
	vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
	actor->SetMapper(mapper);
	actor->SetPosition(1, 1, 1);
	actor->SetScale(1.05);
	actor->GetProperty()->SetColor(colors->GetColor3d(color).GetData());
	actor->GetProperty()->SetLineWidth(width);
	return actor;
}

实验结果:

 

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值