vtk vtkMarchingCubes 体绘制

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

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

	vtkSmartPointer skin =
		vtkSmartPointer::New();

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

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

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

	//这个方向。
	vtkSmartPointer aCamera =
		vtkSmartPointer::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 aRenderer =
		vtkSmartPointer::New();
	vtkSmartPointer renWin =
		vtkSmartPointer::New();
	renWin->AddRenderer(aRenderer);

	vtkSmartPointer iren =
		vtkSmartPointer::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;
}

 

你可能感兴趣的:(vtk)