user3195492
user3195492

Reputation: 35

VTK Image slices to volume (C++)

I'm trying to display a volume slices-composed in QT5+VTK 7.0.0. However, I don't know why using vtkImageSlice+vtkImageStack only shows me one slice instead of five slices. This is the code I'm using it:

/*This function receives an ultrasound image from network.
The function is working fine if we display the 2D images,
but I want to stack a bunch of images in a volume.
The imageStack at the end always keeps one image only.*/
void WDisplay::Disp(QImage b)
{
    // qimagevtk is a vtkSmartPointer<vtkQImageToImageSource> type
    qimagevtk->SetQImage(&b);
    qimagevtk->Update();
    // imageSliceMapper is a vtkSmartPointer<vtkImageSliceMapper> type
    imageSliceMapper->SetInputData(qimagevtk->GetOutput());
    // imageSliceMapper is a vtkSmartPointer<vtkImageSlice> type
    imageSlice->SetMapper(imageSliceMapper);
    imageSlice->GetProperty()->SetOpacity(.5);

    // Stack
    // vtkSmartPointer<vtkImageStack>
    imageStack->AddImage(imageSlice);
    if(!(idx<5)) //idx initialized at zero in the constructor
    {
        // m_renderer ---> vtkRenderer
        m_renderer->AddViewProp(imageStack);
        m_renderer->Render();
        // wvtk ---> QVTKWidget
        wvtk->GetInteractor()->Render();
        idx = 0;
    }
    else
        idx++;
}

This is the output (screenshot) I got when I run the function: screenshot

Every vtk object was created in the constructor using vtkSmartPointer<vtk object type>::New(). I hope anyone can help me. Thank you.

Upvotes: 0

Views: 1506

Answers (1)

mirni
mirni

Reputation: 695

The slices in vtkImageStack are in the same physical location, think layers in photoshop. Therefore you need to assign the layer number for each image slice.

Have a look at vtkImageProperty::SetLayerNumber(int) and vtkImageStack::SetActiveLayer(int).

Create a different lookup table to map for each slice, or change the opacity, so that you can see through the slices in the stack.

And do everyone who reads your code a favor and change if(!(idx<5)) to if(idx>=5).

HTH,

Miro

Upvotes: 1

Related Questions