[vtkusers] MIP VolumeRendering very slow
Stéphane CALANDE
scalande at gmail.com
Thu Dec 18 10:56:20 EST 2008
Hi,
I've done a very simple MIP-visualizer with VTK 5.2 (Thanks to Aurélie for
the help).
But I'm a little disappointed because it's very slow. The refresh time of
the window is very long.
I make tests with a DICOM Series (36 CT-slices).
Here's the program very simplified :
#include "vtkDICOMImageReader.h"
#include "vtkImageData.h"
#include "vtkImageShiftScale.h"
#include "vtkPiecewiseFunction.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkVolume.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolumeRayCastMIPFunction.h"
#include <sstream>
using namespace std;
int main (int argc, char **argv)
{
if( argc < 2 )
{
std::cerr << argv[0] << " rep";
return 1;
}
else
{
string rep;
rep = argv[1];
vtkDICOMImageReader * reader;
reader = vtkDICOMImageReader::New();
string dir("");
ostringstream oss(dir.c_str());
oss << rep ;
dir = oss.str();
const char* adresse = dir.c_str();
reader->SetDirectoryName(adresse);
cout << adresse << endl;
reader->Update();
reader->SetDataScalarTypeToShort();
reader->UpdateWholeExtent();
reader->GetOutput()->UpdateInformation();
vtkRenderer* renderer = vtkRenderer::New();
vtkRenderWindow* renWin = vtkRenderWindow::New();
renWin->AddRenderer(renderer);
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
double range[2];
reader->GetOutput()->GetScalarRange(range);
double min = range[0];
double max = range[1];
double diff = max-min;
double slope = 255.0/diff;
double inter = -slope*min;
double shift = inter/slope;
vtkImageShiftScale *vtkImageCast = vtkImageShiftScale::New();
vtkImageCast->SetInput(reader->GetOutput());
vtkImageCast->SetShift(shift);
vtkImageCast->SetScale(slope);
vtkImageCast->SetOutputScalarTypeToUnsignedShort();
vtkImageCast->Update();
vtkImageCast->GetOutput()->GetScalarRange(range);
double level = 0.5 * (range[1] + range[0]);
double window = range[1] - range[0];
vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();
opacityTransferFunction->AddPoint( level - window/2 , 0.0 );
opacityTransferFunction->AddPoint( level + window/2 , 1.0 );
vtkPiecewiseFunction *grayTransferFunction = vtkPiecewiseFunction::New();
grayTransferFunction->AddSegment( level - window/2, 0.0 , level + window/2,
1.0 );
vtkVolumeProperty *mipProperty;
mipProperty = vtkVolumeProperty::New();
mipProperty->SetScalarOpacity( opacityTransferFunction );
mipProperty->SetColor( grayTransferFunction );
mipProperty->SetInterpolationTypeToLinear();
vtkVolumeRayCastMIPFunction* mipFunction =
vtkVolumeRayCastMIPFunction::New();
mipFunction->SetMaximizeMethodToOpacity();
vtkVolumeRayCastMapper* volumeMapper = vtkVolumeRayCastMapper::New();
volumeMapper->SetVolumeRayCastFunction( mipFunction );
volumeMapper->SetInput( vtkImageCast->GetOutput() );
vtkVolume* volume = vtkVolume::New();
volume->SetMapper( volumeMapper );
volume->SetProperty( mipProperty );
renderer->AddViewProp( volume );
renderer->Render();
renWin->SetSize( 1000 , 700 );
iren->Initialize();
iren->Start();
iren->Delete();
renWin->Delete();
renderer->Delete();
return 0;
}
}
and here's the CMakeLists.txt :
PROJECT (Project)
FIND_PACKAGE(VTK REQUIRED)
IF(NOT VTK_USE_RENDERING)
MESSAGE(FATAL_ERROR "Example ${PROJECT_NAME} requires VTK_USE_RENDERING.")
ENDIF(NOT VTK_USE_RENDERING)
INCLUDE(${VTK_USE_FILE})
ADD_EXECUTABLE(MIP_TEST MIP_TEST.cxx)
TARGET_LINK_LIBRARIES(MIP_TEST vtkVolumeRendering)
To test you just have to give as input a repertory of a DICOM Serie.
My porpose is obviously to create a program more "complicated" than this
one, but it will be impossible if it's so slow.
Do you have any advice, remarks,...? to make it quicker ?
Thank you very much,
Regards,
Stéphane
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081218/fe6cb2bb/attachment.htm>
More information about the vtkusers
mailing list