0
点赞
收藏
分享

微信扫一扫

VTK 标注类Widget 文字标注 vtkCaptionWidget


目录

Part1: 简介

Part2: 效果

 Part3: example

Part1: 简介

vtkCaptionWidget:用一个带线框及箭头的文本信息来标注某一对象;

在可视化程序中,经常会对某个对象做一些标注说明;

如,在医学图像诊断中,常常会手动标注出被诊断为肿瘤的区域或者其他病变区域,并用文字进行标注。

Part2: 效果

vtkCaptionWidget 如下表所示

VTK 标注类Widget 文字标注 vtkCaptionWidget_VTK

 也可以给它加个中心点;

VTK 标注类Widget 文字标注 vtkCaptionWidget_#include_02

 Part3: example

#include "vtkSmartPointer.h"
#include "vtkObjectFactory.h"
#include "vtkRenderWindow.h"
#include "vtkGenericRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkActor.h"

#include "vtkDICOMImageReader.h"
#include "vtkImageViewer2.h"
#include "vtkInteractorStyleImage.h"

/
#include <vtkCamera.h>
#include <vtkCoordinate.h>
 
#include <vtkImageActor.h>
#include <vtkImageData.h>
#include <vtkImageMapper3D.h>
#include <vtkImageMapToWindowLevelColors.h>
#include <vtkImageStack.h>
#include <vtkObjectFactory.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRendererCollection.h>

#include <vtkDataSet.h>
#include <vtkRendererCollection.h>


#include <vtkPointData.h>
#include <vtkDataArray.h>
#include <vtkRenderWindowInteractor.h>
 

#include <vtkCaptionWidget.h>
#include <vtkCaptionActor2D.h>///
#include <vtkCaptionRepresentation.h>
#include <vtkTextActor.h>
#include <vtkTextProperty.h>

#include <vtkPointPicker.h>
#include <vtkRendererCollection.h>

int main(int argc, char* argv[])
{

	auto reader = vtkSmartPointer<vtkDICOMImageReader>::New();
	reader->SetDirectoryName("D:/dicom");
	reader->Update();

	auto imageViewer = vtkSmartPointer<vtkImageViewer2>::New();
	imageViewer->SetInputConnection(reader->GetOutputPort());

	auto interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
	interactor->SetRenderWindow(imageViewer->GetRenderWindow());
	imageViewer->SetupInteractor(interactor);
	imageViewer->SetSize(400, 400);
	imageViewer->SetColorLevel(211);
	imageViewer->SetColorWindow(2470);
	imageViewer->SetSliceOrientationToXY();
	imageViewer->GetRenderer()->SetBackground(0, 0, 0);


	vtkSmartPointer<vtkCaptionWidget> captionWidget =
		vtkSmartPointer<vtkCaptionWidget>::New();
	captionWidget->SetInteractor(interactor);

	captionWidget->GetCaptionActor2D();

	vtkSmartPointer<vtkCaptionRepresentation> captionRepresentation =
		vtkSmartPointer<vtkCaptionRepresentation>::New();
	captionRepresentation->GetCaptionActor2D()->SetCaption("VTK Caption Test");
	captionRepresentation->SetHandleSize(20);
	//captionRepresentation->GetCaptionActor2D()->SetBorder(false);
	captionRepresentation->GetCaptionActor2D()->GetTextActor()->GetTextProperty()->SetColor(1, 0, 0);
	captionRepresentation->GetCaptionActor2D()->GetTextActor()->GetTextProperty()->SetVerticalJustificationToCentered();
 
	double pos[3] = { 100,100, 10};
	captionRepresentation->SetAnchorPosition(pos);
	//captionWidget->SetCaptionActor2D(captionRepresentation->GetCaptionActor2D());
	captionWidget->SetRepresentation(captionRepresentation);
	captionWidget->On();
 
	imageViewer->Render();
	imageViewer->GetRenderer()->ResetCamera();
	imageViewer->Render();

	//memcpy(style->bound, captionWidget->GetRepresentation()->GetBounds(), sizeof(double) * 6);
	interactor->Start();

	return EXIT_SUCCESS;
}

举报

相关推荐

0 条评论