[vtkusers] the pronlem of blending two volume by vtkImageBlend

Aashish Chaudhary aashish.chaudhary at kitware.com
Tue Sep 2 09:48:47 EDT 2014


Can you send us a small sample output dataset? I am not sure about the
values you are setting here unless I see the data.

- Aashish


On Sun, Aug 31, 2014 at 9:05 AM, Yuetian Liu <yuetian926 at 163.com> wrote:

> 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;
> }
>
>
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>


-- 



*| Aashish Chaudhary | Technical Leader         | Kitware Inc.            *
*| http://www.kitware.com/company/team/chaudhary.html
<http://www.kitware.com/company/team/chaudhary.html>*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140902/d755e2fe/attachment.html>


More information about the vtkusers mailing list