vtk提取切面





#include 
VTK_MODULE_INIT(vtkRenderingOpenGL2);

#include 
#include 
#include 
#include  //
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


int main(int argc, char *argv[])
{
	vtkSmartPointer reader = vtkSmartPointer::New(); //创建读取dicom图片指针对象
	//设置医学图像文件夹路径
	reader->SetFileName(
		"C:\\Users\\rw\\Documents\\Visual Studio 2015\\Projects\\VtkLearning\\triangle_point\\x64\\Release\\data\\brain.mhd"); 
	reader->Update();
	cout << "读取数据完成" << endl;


	int extent[6];
	double spacing[3];
	double origin[3];

	reader->GetOutput()->GetExtent(extent);
	reader->GetOutput()->GetSpacing(spacing);
	reader->GetOutput()->GetOrigin(origin);

	double center[3];
	center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]);
	center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]);
	center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]);
	//*****************************************************************//
	static double axialElements[16] = {
		1, 0, 0, 0,
		0, 1, 0, 0,
		0, 0, 1, 0,
		0, 0, 0, 1
	};

	vtkSmartPointer resliceAxes =
		vtkSmartPointer::New();
	resliceAxes->DeepCopy(axialElements);
	resliceAxes->SetElement(0, 3, center[0]);
	resliceAxes->SetElement(1, 3, center[1]);
	resliceAxes->SetElement(2, 3, center[2]);

	// reslice实现切面的提取
	vtkSmartPointer reslice =
		vtkSmartPointer::New();
	reslice->SetInputConnection(reader->GetOutputPort());
	reslice->SetOutputDimensionality(2);
	reslice->SetResliceAxes(resliceAxes);
	reslice->SetInterpolationModeToLinear();
	//*****************************************************************//
	vtkSmartPointer colorTable =
		vtkSmartPointer::New();
	colorTable->SetRange(-500, 1500);
	colorTable->SetValueRange(0.0, 1.0);
	colorTable->SetSaturationRange(0.0, 0.0);
	colorTable->SetRampToLinear();
	colorTable->Build();


	vtkSmartPointer colorMap =
		vtkSmartPointer::New();
	colorMap->SetLookupTable(colorTable);
	colorMap->SetInputConnection(reslice->GetOutputPort());
	colorMap->Update();
	//*****************************************************************//
	vtkSmartPointer imgActor =
		vtkSmartPointer::New();
	imgActor->SetInputData(colorMap->GetOutput());

	vtkSmartPointer renderer =
		vtkSmartPointer::New();
	renderer->AddActor(imgActor);
	renderer->SetBackground(0.4, 0.5, 0.6);

	vtkSmartPointer renderWindow =
		vtkSmartPointer::New();
	renderWindow->AddRenderer(renderer);
	renderWindow->Render();
	renderWindow->SetSize(640, 480);
	renderWindow->SetWindowName("Extract3Dslice");

	vtkSmartPointer rwi =
		vtkSmartPointer::New();
	vtkSmartPointer imagestyle =
		vtkSmartPointer::New();
	rwi->SetInteractorStyle(imagestyle);
	rwi->SetRenderWindow(renderWindow);
	rwi->Initialize();
	rwi->Start();

	return 0;

}

你可能感兴趣的:(VTK,python,android,java)