还有我怎么才能不显示 边上的干扰物 只显示 人 呢?
代码:
int main(int argc, char *argv[])
{
vtkRenderer *aRender = vtkRenderer::New(); //设置绘制类
vtkRenderWindow*renWin=vtkRenderWindow::New();//设置绘制窗口
renWin->AddRenderer(aRender); //装载绘制类
vtkRenderWindowInteractor*iRen=vtkRenderWindowInteractor::New();//设置绘制窗口的交互
iRen->SetRenderWindow(renWin); //装载绘制窗口
//vtkVolume16Reader*reader=vtkVolume16Reader::New();//读取DICOM数据
vtkVolume16Reader *reader = vtkVolume16Reader::New();
reader->SetDataDimensions (512,512);//设置图像像素值
reader->SetImageRange (1,237); //设置图片数量
reader->SetDataByteOrderToLittleEndian();
reader->SetFilePrefix("E:/data/CT/CTAtt009_CT");//设置数据路径
reader->SetFilePattern("%s%03d.dcm");
reader->SetDataSpacing (1.0, 1.0, 3.8); //设置数据的间距
vtkPiecewiseFunction*opacityTransferFunction=vtkPiecewiseFunction::New();//设置不透明度传递函数
opacityTransferFunction->AddPoint(-3024, 0, 0.5, 0.0);
opacityTransferFunction->AddPoint(-16, 0, .49, .61);
opacityTransferFunction->AddSegment(641, .72, .5, 0.0);
opacityTransferFunction->AddPoint(3071, 0.0, 0.5, 0.0);
vtkColorTransferFunction *colorTransferFunction = vtkColorTransferFunction::New();//设置颜色传递函数
colorTransferFunction->AddRGBPoint(0.0, 0.91, 0.65, 0.66); //灰度值及RGB颜色值
colorTransferFunction->AddRGBPoint(30.0, 0.91, 0.65, 0.66);
colorTransferFunction->AddRGBPoint(128.0, 0.91, 0.65, 0.66);
colorTransferFunction->AddRGBPoint(1200.0, 0.43, 0.43, 0.43);
colorTransferFunction->AddRGBPoint(1800.0, 0.43, 0.43, 0.43);
colorTransferFunction->AddRGBPoint(2950, .9, 0.0, 0.0);
colorTransferFunction->AddRGBPoint(3050, .9, 0.0, 0.0);
colorTransferFunction->ClampingOff();
vtkPiecewiseFunction *gradientTransferFunction = vtkPiecewiseFunction::New();//设置梯度传递函数
gradientTransferFunction->AddPoint(0, 2.0);
gradientTransferFunction->AddPoint(500, 2.0);
gradientTransferFunction->AddSegment(600, 0.73, 900, 0.9);
gradientTransferFunction->AddPoint(1300, 0.1);
vtkVolumeProperty*volumeProperty=vtkVolumeProperty::New();//定义并设置相关体属性
volumeProperty->SetColor(colorTransferFunction);
volumeProperty->SetScalarOpacity(opacityTransferFunction);
volumeProperty->SetGradientOpacity(gradientTransferFunction);
volumeProperty->SetInterpolationTypeToLinear();
volumeProperty->ShadeOn(); //打开或者关闭阴影测试
volumeProperty->SetAmbient(0.4);
volumeProperty->SetDiffuse(0.6);
volumeProperty->SetSpecular(0.2);
//------------------------------------------------------------------------------------------光线投射法
vtkVolumeRayCastCompositeFunction*compositeRaycastFunction = vtkVolumeRayCastCompositeFunction::New();//定义光线投射方法为合成体绘制方法
vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
compositeRaycastFunction->SetCompositeMethodToInterpolateFirst(); //设置分类优先
//compositeRaycastFunction->SetCompositeMethodToClassifyFirst();//设置差值优先
volumeMapper->SetSampleDistance(1);
volumeMapper->SetVolumeRayCastFunction(compositeRaycastFunction);//载入体绘制方法
volumeMapper->SetInput(reader->GetOutput());
vtkVolume *volume = vtkVolume::New();//定义Volume
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);//设置体属性
aRender->AddVolume(volume); //将Volume装载到绘制类中
aRender->SetBackground(0, 0, 0);
renWin->SetSize(800, 800); //设置背景颜色和绘制窗口大小
renWin->Render(); //窗口进行绘制
iRen->Initialize();
iRen->Start(); //初始化并进行交互绘制
return EXIT_SUCCESS;
}
2016年06月01日 03点06分
3