1.裁剪
2.基于Cropping 的裁剪技术
vtkVolumeMapper中定义了Cropping接口函数,使用Cropping进行裁剪的代码下:
volumeMapper->SetCropping(1);//开启Cropping功能 volumeMapper->SetCroppingRegionPlanes(50, 150, 50, 200, 50, 150);//设置三个坐标轴上6个裁剪面的位置 volumeMapper->SetCroppingRegionFlags(0x0002000);//设置显示区域标记
此外,该类也提供了其他成员函数设置显示区域,避免自行计算显示区域标记:
SetCroppingRegionFlagsToSubVolume();
SetCroppingRegionFlagsToFence();
SetCroppingRegionFlagsToInvertedFence();
SetCroppingRegionFlagsToCross();
SetCroppingRegionFlagsToInvertedCross();
#include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL2); VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2); VTK_MODULE_INIT(vtkRenderingFreeType); VTK_MODULE_INIT(vtkInteractionStyle); #include <vtkSmartPointer.h> #include <vtkStructuredPoints.h>//vtkStructuredPointsReader* -> vtkGPUVolumeRayCastMapper* #include <vtkStructuredPointsReader.h> #include <vtkGPUVolumeRayCastMapper.h> #include <vtkVolumeProperty.h> #include <vtkPiecewiseFunction.h> #include <vtkColorTransferFunction.h> #include <vtkVolume.h> #include <vtkRenderer.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> #include <vtkCamera.h> int main() {
vtkSmartPointer<vtkStructuredPointsReader> reader = vtkSmartPointer<vtkStructuredPointsReader>::New(); reader->SetFileName("data/mummy.128.vtk"); reader->Update(); vtkSmartPointer<vtkGPUVolumeRayCastMapper> origMapper = vtkSmartPointer<vtkGPUVolumeRayCastMapper>::New(); origMapper->SetInputData(reader->GetOutput()); vtkSmartPointer<vtkGPUVolumeRayCastMapper> volumeMapper = vtkSmartPointer<vtkGPUVolumeRayCastMapper>::New(); volumeMapper->SetInputData(reader->GetOutput()); volumeMapper->SetCropping(1);//开启Cropping功能 volumeMapper->SetCroppingRegionPlanes(50, 150, 50, 200, 50, 150); volumeMapper->SetCroppingRegionFlags(0x0002000); /*/ //设置体绘制相关属性 vtkSmartPointer<vtkVolumeProperty> volumeProperty = vtkSmartPointer<vtkVolumeProperty>::New(); volumeProperty->SetInterpolationTypeToLinear(); //设置线性插值方式 volumeProperty->ShadeOn();//开启阴影属性 volumeProperty->SetAmbient(0.4);//设置环境温度 volumeProperty->SetDiffuse(0.6);//设置漫反射系数 volumeProperty->SetSpecular(0.2);//设置镜面反射系数 //添加灰度不透明度属性 vtkSmartPointer<vtkPiecewiseFunction> compositeOpacity = vtkSmartPointer<vtkPiecewiseFunction>::New(); compositeOpacity->AddPoint(70, 0.0); compositeOpacity->AddPoint(90, 0.4); compositeOpacity->AddPoint(180, 0.6); volumeProperty->SetScalarOpacity(compositeOpacity); //添加梯度不同明度属性 vtkSmartPointer<vtkPiecewiseFunction> gradientOpacity = vtkSmartPointer<vtkPiecewiseFunction>::New(); gradientOpacity->AddPoint(10, 0.0); gradientOpacity->AddPoint(90, 0.5); gradientOpacity->AddPoint(100, 1.0); volumeProperty->SetGradientOpacity(gradientOpacity); //添加颜色传输 vtkSmartPointer<vtkColorTransferFunction> color = vtkSmartPointer<vtkColorTransferFunction>::New(); color->AddRGBPoint(0, 0, 0, 0); color->AddRGBPoint(64, 1.0, 0.52, 0.3); color->AddRGBPoint(190.0, 1.00, 1.00, 1.00); color->AddRGBPoint(220.0, 0.20, 0.20, 0.20); volumeProperty->SetColor(color); /*/ //渲染管道 vtkSmartPointer<vtkVolume> origVolume = vtkSmartPointer<vtkVolume>::New(); origVolume->SetMapper(origMapper); origVolume->SetProperty(volumeProperty); vtkSmartPointer<vtkVolume> croppingVolume = vtkSmartPointer<vtkVolume>::New(); croppingVolume->SetMapper(volumeMapper); croppingVolume->SetProperty(volumeProperty); // double origView[4] = {
0, 0, 0.5, 1 }; double croppingView[4] = {
0.5, 0, 1, 1 }; vtkSmartPointer<vtkRenderer> origRender = vtkSmartPointer<vtkRenderer>::New(); origRender->AddVolume(origVolume); origRender->SetBackground(1, 1, 0); origRender->SetViewport(origView); vtkSmartPointer<vtkRenderer> croppingRender = vtkSmartPointer<vtkRenderer>::New(); croppingRender->AddVolume(croppingVolume); croppingRender->SetBackground(0, 1, 0); croppingRender->SetViewport(croppingView); /// vtkSmartPointer<vtkRenderWindow> rw = vtkSmartPointer<vtkRenderWindow>::New(); rw->AddRenderer(origRender); rw->AddRenderer(croppingRender); rw->SetWindowName("Cropping Volume"); rw->SetSize(640, 320); vtkSmartPointer<vtkRenderWindowInteractor> rwi = vtkSmartPointer<vtkRenderWindowInteractor>::New(); rwi->SetRenderWindow(rw); origRender->GetActiveCamera()->SetPosition(0, -1, 0); origRender->GetActiveCamera()->SetFocalPoint(0, 0, 0); origRender->GetActiveCamera()->SetViewUp(0, 0, 1); origRender->GetActiveCamera()->Azimuth(30); origRender->GetActiveCamera()->Elevation(30); origRender->ResetCamera(); croppingRender->SetActiveCamera(origRender->GetActiveCamera()); rw->Render(); rwi->Start(); return 0; }
今天的文章
VTK:体绘制裁剪——Cropping技术分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/99608.html