VTK使用入门(四)

xiaoxiao2021-03-01  30

#include "vtkDICOMImageReader.h"   #include "vtkRenderer.h"   #include "vtkRenderWindow.h"   #include "vtkRenderWindowInteractor.h"   //#include "vtkVolume16Reader.h"   #include "vtkPolyDataMapper.h"   #include "vtkActor.h"   #include "vtkProperty.h"   #include "vtkOutlineFilter.h"   #include "vtkCamera.h"   #include "vtkPolyDataNormals.h"   #include "vtkStripper.h"   #include "vtkMarchingCubes.h" int main(int argc, char **argv)   {   if (argc SetDirectoryName("d:/headsq/");   v16->SetFilePrefix(argv[1]);   v16->SetDataSpacing(1.0,1.0,1.0);   v16->Update();   //=====================重建皮肤=============================   vtkMarchingCubes *skinExtractor = vtkMarchingCubes::New();   skinExtractor->SetInputConnection(v16->GetOutputPort ());   skinExtractor->SetValue(0,500);   vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();   skinNormals->SetInputConnection(skinExtractor->GetOu tputPort());   skinNormals->SetFeatureAngle(60.0);   vtkStripper *skinStripper = vtkStripper::New();   skinStripper->SetInputConnection(skinNormals->GetOut putPort());   vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();   skinMapper->SetInputConnection(skinNormals->GetOutpu tPort());   skinMapper->ScalarVisibilityOff();   vtkActor *skin = vtkActor::New();   skin->SetMapper(skinMapper);   skin->GetProperty()->SetDiffuseColor(1, .49, .25);   skin->GetProperty()->SetSpecular( .3);   skin->GetProperty()->SetSpecularPower(20);   skin->GetProperty()->SetOpacity(1.0);   //=======================重建骨骼================================   vtkMarchingCubes *boneExtraractor = vtkMarchingCubes::New();   boneExtraractor->SetInputConnection(v16->GetOutputPo rt());   boneExtraractor->SetValue(0,1150);   vtkPolyDataNormals *boneNormals = vtkPolyDataNormals::New();   boneNormals->SetInputConnection(boneExtraractor->Get OutputPort());   boneNormals->SetFeatureAngle(60.0);   vtkStripper *boneStripper = vtkStripper::New();   boneStripper->SetInputConnection(boneStripper->GetOu tputPort());   vtkPolyDataMapper *boneMapper = vtkPolyDataMapper::New();   boneMapper->SetInputConnection(boneMapper->GetOutput Port());   boneMapper->ScalarVisibilityOff();   vtkActor *bone = vtkActor::New();   bone->SetMapper(boneMapper);   bone->GetProperty()->SetDiffuseColor(1,1, .9412);   //=============================建立轮廓============================   vtkOutlineFilter *outlineData = vtkOutlineFilter::New();   outlineData->SetInputConnection(v16->GetOutputPort() );   vtkPolyDataMapper *mapOutline = vtkPolyDataMapper::New();   mapOutline->SetInputConnection(outlineData->GetOutpu tPort());   vtkActor *outline = vtkActor::New();   outline->SetMapper(mapOutline);   outline->GetProperty()->SetColor(0,0,0);   //========================建立相机===============================   vtkCamera *aCamera = vtkCamera::New();   aCamera->SetViewUp(0,0,-1);   aCamera->SetPosition(0,1,0);   aCamera->SetFocalPoint(0,0,0);   aCamera->ComputeViewPlaneNormal();   //=======================准备演示=================================   vtkRenderer *aRenderer = vtkRenderer::New();   vtkRenderWindow *renWin = vtkRenderWindow::New();   renWin->AddRenderer(aRenderer);   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();   iren->SetRenderWindow(renWin);   aRenderer->AddActor(outline);   aRenderer->AddActor(skin);   aRenderer->AddActor(bone);   aRenderer->SetActiveCamera(aCamera);   aRenderer->ResetCamera();   aCamera->Dolly(1.5);   aRenderer->SetBackground(1,1,1);   aRenderer->ResetCameraClippingRange();   renWin->SetSize(640,480);   //=========================开始演示==============================   iren->Initialize();   iren->Start();   //==========================演示结束=============================   v16->Delete();   skinExtractor->Delete();   skinNormals->Delete();   skinStripper->Delete();   skinMapper->Delete();   skin->Delete();   boneExtraractor->Delete();   boneNormals->Delete();   boneStripper->Delete();   boneMapper->Delete();   bone->Delete();   outlineData->Delete();   mapOutline->Delete();   outline->Delete();   aCamera->Delete();   aRenderer->Delete();   renWin->Delete();   iren->Delete();   return 0;   }   =============程序来源于《Visual C++数字图象处理技术详解》==================   以上是在VS2005环境下VTK对医学图像成功3V重建的代码,基于MC算法,当然,前提是你配置好了VTK。         【不知道等上传后会不会出现代码丢失。。。。】   1,头文件的用法,声明,需要进一步搞明白;   2,程序的模块化后,一步一步,依次,读取-》重建皮肤-》重建骨骼-》建立轮廓-》建立相机-》准备演示-》开始演示-》演示结束~~~ 其实大致就包括信息读取,处理,新建窗口,窗口显示;   3,需要搞明白其中的算法;   4,还有很多~~~~~~~~~   这个只是VTK初探,慢慢学吧,呵呵。 相关资源:vtkDICOMImageReader一些用法
转载请注明原文地址: https://www.6miu.com/read-4150174.html

最新回复(0)