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