[vtkusers] vtkBlending and vtkResliceimageviewer with different lookup tables

vtkBeginner j.mlr at gmx.de
Mon Oct 2 14:17:32 EDT 2017


Hi,
I am trying to set up a pipeline blendng N medial imaging data sets which
may have different lookup tables.
{vtkImageReader2 => vtkImageMapToColors}N => vtkImageBlend =>
vtkRescliceImageViewer
I tried to adapt the examples ImageMapToColors, Colored2DImageFusion, and
CombineImages from /www.vtk.org/Wiki/VTK/Examples/Cxx/ to my needs, but I
probably failed to transfer the data properly into vtkRescliceImageViewer. I
needed
imgViewer2->GetImageActor()->GetMapper()->SetInputConnection(imgBlend->GetOutputPort())
to transfer the LUT information and
imgViewer2->SetInputConnection(imgBlend->GetOutputPort()) to enable browsing
through the slides.
Two input connections look weird and I lost the interactor function to
change the level/window. How are such pipelines supposed to be set up ?

Thanks an advance, Jorg


#include <vtkImageActor.h>
#include <vtkImageBlend.h>
#include <vtkImageData.h>
#include <vtkImageMapper3D.h>
#include <vtkImageMapToColors.h>
#include <vtkImageProperty.h>
#include <vtkLookupTable.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkResliceImageViewer.h>
#include <vtkSmartPointer.h>

int main(int, char*[])
{
    vtkSmartPointer<vtkImageData> image =
vtkSmartPointer<vtkImageData>::New();
    vtkSmartPointer<vtkImageData> image2 =
vtkSmartPointer<vtkImageData>::New();
    int imageExtent[6] = { 0, 7, 0, 7, 0, 3 };
    image->SetExtent(imageExtent);
    image2->SetExtent(imageExtent);
    image->AllocateScalars(VTK_DOUBLE, 1);
    image2->AllocateScalars(VTK_DOUBLE, 1);    for (int z = imageExtent[4];
z <= imageExtent[5]; z++){
        for (int y = imageExtent[2]; y <= imageExtent[3]; y++){
            for (int x = imageExtent[0]; x <= imageExtent[1]; x++){
                double* pixel =
static_cast<double*>(image->GetScalarPointer(x, y, z));
                double* pixel2 =
static_cast<double*>(image2->GetScalarPointer(y, x, z));
                pixel[0] = scalarvalue*x;
                pixel2[0]= scalarvalue*y;
                scalarvalue += 1.0;
            }
        }
    }

    // Map the scalar values in the image to colors with a lookup table:
    vtkSmartPointer<vtkLookupTable> lookupTable =
vtkSmartPointer<vtkLookupTable>::New();
    lookupTable->SetHueRange( 0.0, 0.2 );
    lookupTable->SetRange(0.0, 511.0);
    lookupTable->Build();

    vtkSmartPointer<vtkLookupTable> lookupTable2 =
vtkSmartPointer<vtkLookupTable>::New();
    lookupTable2->SetHueRange( 0.5, 0.7 );
    lookupTable2->SetRange(0.0, 511.0);
    lookupTable2->Build();

    // Pass the original image and the LUT to a filter to create a color
image:
    vtkSmartPointer<vtkImageMapToColors> scalarValuesToColors =
vtkSmartPointer<vtkImageMapToColors>::New();
    scalarValuesToColors->SetLookupTable(lookupTable);
    scalarValuesToColors->PassAlphaToOutputOn();
    scalarValuesToColors->SetInputData(image);

    vtkSmartPointer<vtkImageMapToColors> scalarValuesToColors2 =
vtkSmartPointer<vtkImageMapToColors>::New();
    scalarValuesToColors2->SetLookupTable(lookupTable2);
    scalarValuesToColors2->PassAlphaToOutputOn();
    scalarValuesToColors2->SetInputData(image2);

    vtkSmartPointer<vtkImageBlend> imgBlend =
vtkSmartPointer<vtkImageBlend>::New();
    imgBlend->AddInputConnection(scalarValuesToColors->GetOutputPort());
    imgBlend->AddInputConnection(scalarValuesToColors2->GetOutputPort());
    imgBlend->SetOpacity(0,0.5);
    imgBlend->SetOpacity(1,0.5);
    imgBlend->Update();

    vtkResliceImageViewer* imgViewer2=vtkResliceImageViewer::New();
    vtkRenderWindowInteractor* renWinIact=vtkRenderWindowInteractor::New();
    imgViewer2->DebugOn();
    imgViewer2->SetupInteractor(renWinIact);
   
imgViewer2->GetImageActor()->GetMapper()->SetInputConnection(imgBlend->GetOutputPort());
// required for LUT
    imgViewer2->SetInputConnection(imgBlend->GetOutputPort());  // required
to display all slices
   
imgViewer2->GetImageActor()->GetProperty()->SetInterpolationTypeToNearest();
    imgViewer2->GetRenderer()->ResetCamera();
    imgViewer2->GetRenderWindow()->Render();
    imgViewer2->GetInteractor()->Initialize();
    imgViewer2->GetInteractor()->Start();
}






--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list