注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

八哥吧室

那山沟里真的有山花吗

 
 
 

日志

 
 
 
 

VTK体绘制代码  

2010-07-31 10:28:23|  分类: C/C++ |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
纯属笔记

#include <vtkDICOMImageReader.h>
#include <vtkImageShiftScale.h>
#include <vtkImageCast.h>
#include <vtkPiecewiseFunction.h>
#include <vtkColorTransferFunction.h>
#include <vtkVolumeProperty.h>
#include <vtkVolumeRayCastCompositeFunction.h>
#include <vtkVolumeRayCastMapper.h>
#include <vtkVolume.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkImageData.h>
int main()
{
vtkDICOMImageReader* pReader = vtkDICOMImageReader::New();
pReader->SetDirectoryName("data");
vtkImageShiftScale* pShift = vtkImageShiftScale::New(); // The output intensity will be (originInt + shift) * scale.
pShift->SetInput(pReader->GetOutput());
pShift->SetShift(20.0);
pShift->SetScale(1.0);
vtkImageCast* pCast = vtkImageCast::New();
pCast->SetInput(pShift->GetOutput());
pCast->SetOutputScalarTypeToUnsignedChar(); // vtkVolumeRayCastMapper only supports unsigned char or unsigned short.
vtkPiecewiseFunction* pOpacity = vtkPiecewiseFunction::New(); // This function will determine the voxels' opacity.
pOpacity->AddPoint(600.0, 0.0); // The points defined will determine the piecewise function. 0 is transparent, 1 is opacity.
pOpacity->AddPoint(1200.0, 0.2);
pOpacity->AddPoint(1300.0, 0.3);
pOpacity->AddPoint(2000.0, 0.3);
pOpacity->AddPoint(4095.0, 1.0);
vtkColorTransferFunction* pColor = vtkColorTransferFunction::New(); // This function will determine the color/gray of voxels.
pColor->AddRGBPoint(0.0, 0.5, 0.0, 0.0); // The first argument is gray level, the lasts are r/g/b components.
pColor->AddRGBPoint(600.0, 1.0, 0.5, 0.5);
pColor->AddRGBPoint(1280.0, 0.5, 0.5, 0.3);
pColor->AddRGBPoint(1960.0, 0.5, 0.77, 0.6);
pColor->AddRGBPoint(4095.0, 0.5, 0.9, 0.9);
vtkPiecewiseFunction* pGradient = vtkPiecewiseFunction::New(); // This function will determine the gradient. The gradient will determine how to map the gray difference to opacity.
pGradient->AddPoint(0.0, 2.0);
pGradient->AddPoint(500.0, 2.0);
pGradient->AddPoint(1300.0, 0.1);
vtkVolumeProperty* pPro = vtkVolumeProperty::New(); // Tie all the function to property.
pPro->SetColor(pColor);
pPro->SetScalarOpacity(pOpacity);
pPro->SetGradientOpacity(pGradient);
vtkVolumeRayCastCompositeFunction* pRayCast = vtkVolumeRayCastCompositeFunction::New(); // The ray casting function. The alternative choices are vtkVolumeRayCastIsosurfaceFunction & vtkVolumeRayCastMIPFunction.

vtkVolumeRayCastMapper* pMapper = vtkVolumeRayCastMapper::New(); // Start rendering pipeline.
pMapper->SetInput(pCast->GetOutput());
pMapper->SetVolumeRayCastFunction(pRayCast);
vtkVolume* pVol = vtkVolume::New();
pVol->SetMapper(pMapper);
pVol->SetProperty(pPro);
vtkRenderer* pRen = vtkRenderer::New();
pRen->AddVolume(pVol);
vtkRenderWindow* pRenWin = vtkRenderWindow::New();
pRenWin->AddRenderer(pRen);
pRenWin->Render();
vtkRenderWindowInteractor* pRenInt = vtkRenderWindowInteractor::New();
pRenInt->SetRenderWindow(pRenWin);
pRenInt->Initialize();
pRenInt->Start();

pReader->Delete();
pShift->Delete();
pCast->Delete();
pOpacity->Delete();
pColor->Delete();
pGradient->Delete();
pPro->Delete();
pRayCast->Delete();
pMapper->Delete();
pVol->Delete();
pRen->Delete();
pRenWin->Delete();
pRenInt->Delete();
}
  评论这张
 
阅读(892)| 评论(3)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017