/********************************************************************** 文件名: 7.2_ClippingApp.cpp Copyright (c) 张晓东, 罗火灵. All rights reserved. 更多信息请访问: http://www.vtkchina.org (VTK中国) http://blog.csdn.net/www_doling_net (东灵工作室) **********************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //测试:../data/mummy.128.vtk int main(int argc, char *argv[]) { if(argc <= 1) { std::cout<<"usage:"< reader = vtkSmartPointer::New(); reader->SetFileName(argv[1]); reader->Update(); vtkSmartPointer rayCastFun = vtkSmartPointer::New(); vtkSmartPointer volumeMapper = vtkSmartPointer::New(); volumeMapper->SetInput(reader->GetOutput()); volumeMapper->SetVolumeRayCastFunction(rayCastFun); //clipping vtkSmartPointer plane = vtkSmartPointer::New(); plane->SetOrigin(100,100,0); plane->SetNormal(1,1,0); volumeMapper->AddClippingPlane(plane); vtkSmartPointer volumeProperty = vtkSmartPointer::New(); volumeProperty->SetInterpolationTypeToLinear(); volumeProperty->ShadeOn(); //打开或者关闭阴影测试 volumeProperty->SetAmbient(0.4); volumeProperty->SetDiffuse(0.6); volumeProperty->SetSpecular(0.2); vtkSmartPointer compositeOpacity = vtkSmartPointer::New(); compositeOpacity->AddPoint(70, 0.00); compositeOpacity->AddPoint(90, 0.40); compositeOpacity->AddPoint(180, 0.60); //volumeProperty->SetScalarOpacity(compositeOpacity); //设置不透明度传输函数 vtkSmartPointer volumeGradientOpacity = vtkSmartPointer::New(); volumeGradientOpacity->AddPoint(10, 0.0); volumeGradientOpacity->AddPoint(90, 0.5); volumeGradientOpacity->AddPoint(100, 1.0); volumeProperty->SetGradientOpacity(volumeGradientOpacity);//设置梯度不透明度效果对比 vtkSmartPointer color = vtkSmartPointer::New(); color->AddRGBPoint(0.000, 0.00, 0.00, 0.00); color->AddRGBPoint(64.00, 1.00, 0.52, 0.30); color->AddRGBPoint(190.0, 1.00, 1.00, 1.00); color->AddRGBPoint(220.0, 0.20, 0.20, 0.20); volumeProperty->SetColor(color); vtkSmartPointer volume = vtkSmartPointer::New(); volume->SetMapper(volumeMapper); volume->SetProperty(volumeProperty); vtkSmartPointer ren = vtkSmartPointer::New(); ren->SetBackground(1.0, 1.0, 1.0); ren->AddVolume( volume ); vtkSmartPointer renWin = vtkSmartPointer::New(); renWin->AddRenderer(ren); renWin->SetSize(640, 480); renWin->Render(); renWin->SetWindowName("ClippingApp"); vtkSmartPointer iren = vtkSmartPointer::New(); iren->SetRenderWindow(renWin); ren->ResetCamera(); renWin->Render(); iren->Start(); return EXIT_SUCCESS; }