[vtkusers] the pronlem of blending two volume by vtkImageBlend
Yuetian Liu
yuetian926 at 163.com
Sun Aug 31 09:15:15 EDT 2014
Hi vtkusers,
I want to blend the two volumes by vtkImageBlend. And I use vtkMetaImageReader to read two volumes(CT and MR)
Then I use the vtkImageBlend to blend two volumes. And then I use the Ray Casting Algorithm to render the two volumes
after blending. But the result has one color. And it is not the result that I want. My hoping result is that the CT volume is
red and the MR volume was blue.
How can I solve it. Please help me. And my code is attached.
Thank you very much!
Bset
Yuetian
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkImageData.h>
#include <vtkSmartPointer.h>
#include <vtkImageBlend.h>
#include "vtkMetaImageReader.h"
#include <string>
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkImageCast.h"
#include <vtkLookupTable.h>
int main ( int argc, char* argv[] )
{
std::string input1Filename = argv[1];
std::string input2Filename = argv[2];
vtkSmartPointer<vtkMetaImageReader>Reader1 =
vtkSmartPointer<vtkMetaImageReader>::New();
Reader1->SetFileName ( input1Filename.c_str() );
vtkSmartPointer<vtkMetaImageReader> jReader2 =
vtkSmartPointer<vtkMetaImageReader>::New();
Reader2->SetFileName ( input2Filename.c_str() );
vtkSmartPointer<vtkImageBlend> imgBlender =
vtkSmartPointer<vtkImageBlend>::New();
imgBlender->SetOpacity( 0, 0.2 );
imgBlender->SetOpacity( 1, 0.6 );
imgBlender->AddInputConnection( Reader1->GetOutputPort() );
imgBlender->AddInputConnection( Reader2->GetOutputPort() );
vtkSmartPointer< vtkImageCast> readerImageCast =
vtkSmartPointer< vtkImageCast>::New();
readerImageCast->SetInputConnection(imgBlender->GetOutputPort());
readerImageCast->SetOutputScalarTypeToUnsignedShort ();
readerImageCast->ClampOverflowOn();
vtkSmartPointer< vtkPiecewiseFunction> opacityTransferFunction =
vtkSmartPointer< vtkPiecewiseFunction>::New();
opacityTransferFunction->AddPoint(20, 0.0);
opacityTransferFunction->AddPoint(255, 0.8);
vtkSmartPointer< vtkColorTransferFunction > colorTransferFunction =
vtkSmartPointer< vtkColorTransferFunction > ::New();
colorTransferFunction->AddRGBPoint(0,0.9,0.7,0.5);
colorTransferFunction->AddRGBPoint(15,1,0.7,0.6);
colorTransferFunction->AddRGBPoint(255,1,0,0);
vtkSmartPointer<vtkVolumeProperty> volumeProperty =
vtkSmartPointer<vtkVolumeProperty>::New();
volumeProperty->SetColor(colorTransferFunction);
volumeProperty->SetScalarOpacity(opacityTransferFunction);
volumeProperty->ShadeOn();
volumeProperty->SetInterpolationTypeToLinear();
volumeProperty->SetSpecular(0.1);
volumeProperty->SetSpecularPower(8);
volumeProperty->SetScalarOpacityUnitDistance(0.8919);
vtkSmartPointer<vtkVolumeRayCastCompositeFunction> compositeFunction =
vtkSmartPointer<vtkVolumeRayCastCompositeFunction>::New();
vtkSmartPointer< vtkVolumeRayCastMapper> volumeMapper =
vtkSmartPointer< vtkVolumeRayCastMapper> ::New();
volumeMapper->SetVolumeRayCastFunction(compositeFunction);
volumeMapper->SetInputConnection(readerImageCast->GetOutputPort());
volumeMapper->SetNumberOfThreads(3);
vtkSmartPointer<vtkVolume> volume =
vtkSmartPointer<vtkVolume>::New();
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddVolume(volume);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140831/de83baf0/attachment.html>
More information about the vtkusers
mailing list