medimage 发表于 2015-12-5 17:59:37

VTK例子17-读取三维体数据,三位重建显示——任意平面的裁切

读取三维体数据,三位重建显示——任意平面的裁切//16位非压缩位图的读取与设置       //16位非压缩位图       v16 = vtkVolume16Reader::New();           //大小为64*64,每个文件大小为64*64*2=8192字节       v16->SetDataDimensions(64,64);        imageData = vtkImageData::New();       imageData = v16->GetOutput();       imageData->SetOrigin(.0,.0,.0);       imageData->SetDimensions(64,64,93);        //两个字节之间的字节序,采用印地安字节序       v16->SetDataByteOrderToLittleEndian();                      v16->SetFilePrefix ("E:/VTK/VTKData/BMPDATA/quarter");       //设置图片范围(1-93)       v16->SetImageRange (1,93);       //点间距                                           v16->SetDataSpacing (3.2,3.2,1.5);                         v16->Update(); /*       tfun = vtkPiecewiseFunction::New();       tfun->AddPoint(70.0,.0);       tfun->AddPoint( 599.0,.0);       tfun->AddPoint( 600.0,.0);       tfun->AddPoint(1195.0,.0);       tfun->AddPoint(1200.0,.2);       tfun->AddPoint(1300.0,.3);       tfun->AddPoint(2000.0,.3);       tfun->AddPoint(4095.0, 1.0);*/       ctfun = vtkColorTransferFunction::New();       ctfun->AddRGBPoint(    .0,.5,.0, .0);       ctfun->AddRGBPoint( 600.0, 0.1,.5, .5);       ctfun->AddRGBPoint(1280.0,.9,.2, .3);       ctfun->AddRGBPoint(1960.0, .81, .27, .1);       ctfun->AddRGBPoint(4095.0,.5,.5, .5);        compositeFunction = vtkVolumeRayCastCompositeFunction::New();        volumeMapper = vtkVolumeRayCastMapper::New();       //图像数据载入映射器       volumeMapper->SetInput(imageData);       volumeMapper->SetVolumeRayCastFunction(compositeFunction);        //裁切平面的设置       plane1 = vtkPlane::New();       //设置平面初始点       plane1->SetOrigin(50,50,50);       //设置平面法线       plane1->SetNormal(1, 1, 1);       //加载平面//   volumeMapper->AddClippingPlane(plane1);             //裁切平面的设置       plane2 = vtkPlane::New();       //设置平面初始点//   plane2->SetOrigin(80, 80, 80);       //设置平面法线//   plane2->SetNormal(-1, -1, -1);       //加载平面//   volumeMapper->AddClippingPlane(plane2);        volumeProperty = vtkVolumeProperty::New();       volumeProperty->SetColor(ctfun);//   volumeProperty->SetScalarOpacity(tfun);       volumeProperty->SetInterpolationTypeToLinear();       volumeProperty->ShadeOn();        newvol = vtkVolume::New();       newvol->SetMapper(volumeMapper);       newvol->SetProperty(volumeProperty);        //边界的设置与显示       outline = vtkOutlineFilter::New();       outline->SetInput(imageData);        outlineMapper = vtkPolyDataMapper::New();       outlineMapper->SetInput(outline->GetOutput());        outlineActor = vtkActor::New();       outlineActor->SetMapper(outlineMapper);        boxWidget = vtkBoxWidget::New();       boxWidget->SetInteractor(iren);       boxWidget->SetPlaceFactor(1.0);       boxWidget->SetInput(imageData);       boxWidget->PlaceWidget();       boxWidget->InsideOutOn();//   boxWidget->AddObserver()/**/       render->AddActor(outlineActor);       render->AddVolume(newvol); 滑动块事件:       int pos1 = this->m_PosionSlider.GetPos();       int pos2 = this->m_Slider2.GetPos();       int pos3 = this->m_Slider3.GetPos();       int pos4 = this->m_Slider4.GetPos();       int pos5 = this->m_Slider5.GetPos();       int pos6 = this->m_Slider6.GetPos();       CString str;       str.Format("%d",pos1);       this->m_Edit1.SetWindowText(str);       this->m_MyMedical.plane2->SetOrigin(pos1, pos2, pos3);       this->m_MyMedical.plane2->SetNormal(pos4, pos5, pos6);       this->m_MyMedical.volumeMapper->AddClippingPlane(this->m_MyMedical.plane2);           this->m_MyMedical.VTKToDialog(&(this->m_MyStatic));

biochemistry 发表于 2016-5-11 12:26:26

mri 发表于 2016-5-12 15:22:58

好好好好哈

江西丁工 发表于 2016-5-17 02:02:39

devstd 发表于 2016-5-23 12:51:49

谢谢你的辛苦劳动了!!!
页: [1]
查看完整版本: VTK例子17-读取三维体数据,三位重建显示——任意平面的裁切