vtk vtkMarchingCubes 体绘制

int showVTKData(vtkImageData* vtkData, vtkImageData* RevtkData, vtkMatrix4x4 *vtkMat = nullptr)
{
	// 已知等值面或等值线值500对应于
	// 病人的皮肤。
	vtkSmartPointer<vtkMarchingCubes> skinExtractor =
		vtkSmartPointer<vtkMarchingCubes>::New();
	skinExtractor->SetInputData(vtkData);
	skinExtractor->SetValue(0, 50);

	vtkSmartPointer<vtkDataSetMapper> skinMapper =
		vtkSmartPointer<vtkDataSetMapper>::New();
	skinMapper->SetInputConnection(skinExtractor->GetOutputPort());
	skinMapper->ScalarVisibilityOff();

	vtkSmartPointer<vtkActor> skin =
		vtkSmartPointer<vtkActor>::New();

	if (nullptr != vtkMat)
		skin->SetUserMatrix(vtkMat);
	skin->SetMapper(skinMapper);
	skin->GetProperty()->SetDiffuseColor(1, .49, .25);

	vtkSmartPointer<vtkProperty> backProp =
		vtkSmartPointer<vtkProperty>::New();
	backProp->SetDiffuseColor(0.8900, 0.8100, 0.3400);
	skin->SetBackfaceProperty(backProp);

	//创建数据的初始视图很方便。的FocalPoint而位置构成一个矢量方向。稍后(ResetCamera()方法)
	//这个矢量是用来定位摄像机来查看数据的

	//这个方向。
	vtkSmartPointer<vtkCamera> aCamera =
		vtkSmartPointer<vtkCamera>::New();
	aCamera->SetViewUp(0, 0, -1);
	aCamera->SetPosition(0, -1, 0);
	aCamera->SetFocalPoint(0, 0, 0);
	aCamera->ComputeViewPlaneNormal();
	aCamera->Azimuth(30.0);
	aCamera->Elevation(30.0);

	vtkSmartPointer<vtkRenderer> aRenderer =
		vtkSmartPointer<vtkRenderer>::New();
	vtkSmartPointer<vtkRenderWindow> renWin =
		vtkSmartPointer<vtkRenderWindow>::New();
	renWin->AddRenderer(aRenderer);

	vtkSmartPointer<vtkRenderWindowInteractor> iren =
		vtkSmartPointer<vtkRenderWindowInteractor>::New();
	iren->SetRenderWindow(renWin);

	 aRenderer->AddActor(skin);
	//aRenderer->AddActor(getVTKActor(RevtkData));
	
	aRenderer->SetActiveCamera(aCamera);
	aRenderer->ResetCamera();
	aCamera->Dolly(1.5);


	aRenderer->SetBackground(.2, .3, .4);
	renWin->SetSize(640, 480);

	aRenderer->ResetCameraClippingRange();

	renWin->Render();
	iren->Initialize();
	iren->Start();

	return EXIT_SUCCESS;
}

 

©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页