[vtkusers] Reshape and display vtkImageData with vktImageViewer

Morten Wigen morten.wigen at gmail.com
Fri Feb 21 03:05:04 EST 2014


Hi everyone,
I have an image represented with vtkImageData. I want to fit and fill this
image into a qvtkwidget. I have succesfully rotated and reshaped the image
to the size of my renderwindow, however when I display it is seems to be
scaled down and is surrounded with a lot of space(see image).

And another thing; when is it necessary to "update()" the different image
interactors?

If anyone have any input that could help me to achieve my objective, please
help me out here! :)

The code I use is as follows:

vtkSmartPointer<vtkImageViewer2> viewer1 =
vtkSmartPointer<vtkImageViewer2>::New ();
vtkSmartPointer<vtkImageData> image = vtkSmartPointer<vtkImageData>::New();
vtkSmartPointer<vtkImageResize> resize =
vtkSmartPointer<vtkImageResize>::New();
vtkSmartPointer<vtkTransform> rotate =
vtkSmartPointer<vtkTransform>::New();
vtkSmartPointer<vtkImageReslice> reslice =
vtkSmartPointer<vtkImageReslice>::New();
vtkSmartPointer<vtkMatrix4x4> transposeMatrix =
vtkSmartPointer<vtkMatrix4x4>::New();

viewer1->SetupInteractor(physioApp->dopplerDataWidget->GetInteractor());
viewer1->SetRenderWindow(physioApp->dopplerDataWidget->GetRenderWindow());

image->DeepCopy(dopplerImages[previousDopplerFrameIndex]);

rotate->RotateZ(-90);
rotate->GetTranspose(transposeMatrix);


reslice->SetInput(image);
reslice->Update();
reslice->SetResliceAxes(transposeMatrix);
reslice->SetInterpolationModeToLinear();
reslice->Update();

resize->SetInputConnection(reslice->GetOutputPort());
resize->SetBorder(0);
resize->SetCropping(0);
resize->Update();

int * r=resize->GetOutput()->GetDimensions();

int* size =
physioApp->dopplerDataWidget->GetRenderWindow()->GetInteractor()->GetSize();

if(r[0]>0 && r[1]>0 && r[2]>0)
        resize->SetOutputDimensions(size[0],size[1],1);

resize->Update();
reslice->Update();

viewer1->SetInputConnection(reslice->GetOutputPort());
viewer1->Render();

Resulting image:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140221/3fe8b742/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dopplerwidget.jpg
Type: image/jpeg
Size: 15794 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140221/3fe8b742/attachment.jpg>


More information about the vtkusers mailing list