📄 medical1.cpp
字号:
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: Medical1.cxx,v $
Language: C++
Date: $Date: 2002/11/27 16:06:38 $
Version: $Revision: 1.2 $
Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
//
// This example reads a volume dataset, extracts an isosurface that
// represents the skin and displays it.
//
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkVolume16Reader.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkOutlineFilter.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMIPFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkVolumeTextureMapper2D.h"
int main (int argc, char **argv)
{
if (argc < 2)
{
cout << "Usage: " << argv[0] << " nero/raw" << endl;
return 1;
}
// Create the renderer, the render window, and the interactor. The renderer
// draws into the render window, the interactor enables mouse- and
// keyboard-based interaction with the data within the render window.
//
vtkRenderer *aRenderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(aRenderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
// The following reader is used to read a series of 2D slices (images)
// that compose the volume. The slice dimensions are set, and the
// pixel spacing. The data Endianness must also be specified. The reader
// usese the FilePrefix in combination with the slice number to construct
// filenames using the format FilePrefix.%d. (In this case the FilePrefix
// is the root name of the file: quarter.)
vtkVolume16Reader *v16 = vtkVolume16Reader::New();
v16->SetDataDimensions (125,155);
v16->SetImageRange (0,39);
v16->SetDataByteOrderToLittleEndian();
v16->SetFilePrefix (argv[1]);
v16->SetDataSpacing (3.2, 3.2, 1.5);
vtkPiecewiseFunction *opacityTFunc=vtkPiecewiseFunction::New();
opacityTFunc->AddPoint(0.0, 0.0);
opacityTFunc->AddPoint(5000.0, 0.5);
//opacityTFunc->AddPoint(60.0, 0.1);
opacityTFunc->AddPoint(10000.0, 1.0);
// opacityTFunc->AddPoint(225, .2);
// opacityTFunc->AddPoint(430, .9);
// opacityTFunc->AddPoint(500, .9);
// opacityTFunc->AddPoint(4095.0, 1.0);
//vtkColorTransferFunction *colorTFunc=vtkColorTransferFunction::New();
// colorTFunc->AddRGBPoint(0.0, 0.0, 0.5, 0.0);
// colorTFunc->AddRGBPoint(600.0, 0.5, 1.0, 0.5);
// colorTFunc->AddRGBPoint(1280.0, 0.2, 0.9, 0.3);
// colorTFunc->AddRGBPoint(1960.0, 0.27, 0.81, 0.1);
// colorTFunc->AddRGBPoint(4095.0, 0.5, 0.5, 0.5);
vtkVolumeProperty *volumeProperty=vtkVolumeProperty::New();
// volumeProperty->SetColor(colorTFunc);
volumeProperty->SetScalarOpacity(opacityTFunc);
volumeProperty->SetInterpolationTypeToLinear();
volumeProperty->SetAmbient(0.2);
volumeProperty->SetDiffuse(0.9);
volumeProperty->SetSpecular(0.2);
volumeProperty->SetSpecularPower(10);
volumeProperty->ShadeOn();
//光线合成法
vtkVolumeRayCastCompositeFunction
*compositeFunction=vtkVolumeRayCastCompositeFunction::New();
//最大值投射法
// vtkVolumeRayCastMIPFunction *compositeFunction=vtkVolumeRayCastMIPFunction::New();
vtkVolumeRayCastMapper *volumeMapper=vtkVolumeRayCastMapper::New();
volumeMapper->SetInput(v16->GetOutput());
volumeMapper->SetVolumeRayCastFunction(compositeFunction);
volumeMapper->SetNumberOfThreads(3);
// cerr<GetNumberOfThreads();
//二维纹理映射
/* vtkVolumeTextureMapper2D* volumeMapper=vtkVolumeTextureMapper2D::New();
volumeMapper->SetInput(v16->GetOutput());
*/
vtkVolume *volume=vtkVolume::New();
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);
vtkOutlineFilter *outline = vtkOutlineFilter::New();
outline->SetInput((vtkDataSet *)v16->GetOutput());
vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
outlineMapper->SetInput(outline->GetOutput());
vtkActor *outlineActor = vtkActor::New();
outlineActor->SetMapper(outlineMapper);
aRenderer->AddActor(outlineActor);
aRenderer->AddVolume(volume);
aRenderer->SetBackground(0,0,0);
renWin->SetSize(300, 300);
iren->Initialize();
renWin->Render();
iren->Start();
v16->Delete();
opacityTFunc->Delete();
// colorTFunc->Delete();
volumeProperty->Delete();
compositeFunction->Delete();
volumeMapper->Delete();
volume->Delete();
outline->Delete();
outlineMapper->Delete();
outlineActor->Delete();
aRenderer->Delete();
renWin->Delete();
iren->Delete();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -