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

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

vs2017+vtk9.1

实现代码:

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

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

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

	//创建一个矩形  通过对角线两顶点确定一个矩形
	int leftTopX = 80;
	int leftTopY = 50;
	int rightBottomX = 100;
	int rightBottomY = 30;
	QVector vector;
	vector.append(leftTopX);
	vector.append(leftTopY);
	vector.append(rightBottomX);
	vector.append(rightBottomY);
	vtkSmartPointer actor = vtkSmartPointer::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 vtk91test::addRectangle2D(QVector vector, int width, vtkStdString color)
{
	//使用两个点确定一个矩形
	vtkSmartPointer lineSource = vtkSmartPointer::New();
	vtkSmartPointer points = vtkSmartPointer::New();
	vtkSmartPointer colors = vtkSmartPointer::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 mapper =
		vtkSmartPointer::New();
	mapper->SetInputConnection(lineSource->GetOutputPort());
	vtkSmartPointer actor = vtkSmartPointer::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;
}

实验结果:

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

 

你可能感兴趣的:(vtk,vs2017+Qt5,c++,qt)