📄 volumecut.cpp
字号:
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPiecewiseFunction.h"
//#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkVolume16Reader.h"
#include "vtkCamera.h"
#include "vtkDICOMImageReader.h"
#include "vtkImageCast.h"
#include "vtkPlane.h"
int main()
{
vtkRenderer *aRender = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(aRender);
vtkRenderWindowInteractor *iRen = vtkRenderWindowInteractor::New();
iRen->SetRenderWindow(renWin);
vtkPlane *plane = vtkPlane::New();
plane->SetOrigin(0, 0.0, 0.0);
plane->SetNormal(0.0, 0.0, 1.0);
vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
reader->SetDataByteOrderToLittleEndian();
reader->SetDirectoryName("E:\\Data\\CTHead");
reader->SetDataSpacing(3.2, 3.2, 1.5);
reader->SetDataOrigin(0.0, 0.0, 0.0);
vtkImageCast *readerImageCast = vtkImageCast::New();
readerImageCast->SetInput(reader->GetOutput());
readerImageCast->SetOutputScalarTypeToUnsignedChar();
readerImageCast->ClampOverflowOn();
vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();
opacityTransferFunction->AddPoint(0, 0.0);
opacityTransferFunction->AddSegment(30, 0.1, 300, 0.9);
opacityTransferFunction->AddPoint(1000, 1.0);
opacityTransferFunction->ClampingOn();
/*
vtkColorTransferFunction *colorTransferFunction = vtkColorTransferFunction::New();
colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
colorTransferFunction->AddRGBPoint(64.0, 1.0, 0.0, 0.0);
colorTransferFunction->AddRGBPoint(128.0, 0.0, 0.0, 1.0);
colorTransferFunction->AddRGBPoint(192.0, 0.0, 1.0, 0.0);
colorTransferFunction->AddRGBPoint(255.0, 0.0, 0.2, 0.0);
*/
vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
// volumeProperty->SetColor(colorTransferFunction);
volumeProperty->SetScalarOpacity(opacityTransferFunction);
volumeProperty->ShadeOn();
volumeProperty->SetInterpolationTypeToLinear();
vtkVolumeRayCastCompositeFunction *compositeFunction = vtkVolumeRayCastCompositeFunction::New();
vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
volumeMapper->SetVolumeRayCastFunction(compositeFunction);
volumeMapper->SetInput(readerImageCast->GetOutput());
volumeMapper->AddClippingPlane(plane);
vtkVolume *volume = vtkVolume::New();
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);
vtkCamera *camera = vtkCamera::New();
camera->SetViewUp(0,0,1);
camera->SetPosition(0,2,0);
camera->SetFocalPoint(0,0,0);
camera->Dolly(1.2);
//aRender->SetActiveCamera(camera);
aRender->AddVolume(volume);
aRender->SetBackground(0, 0, 0);
renWin->SetSize(300, 300);
renWin->Render();
iRen->Initialize();
iRen->Start();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -