[vtkusers] Reslice a volume using the transformation of the rendering

lucaslovercio lucaslovercio at gmail.com
Sun Mar 3 18:07:31 EST 2019


Hi!

I want to apply the rotation that the user does in the rendering, to the
volume. Thus, I want to store it in the position that the user wants.
However, when I apply the transformation and render it, the volume is not
oriented as in the orientation seen in the first window.

Can you help? Any suggestion?

Here is my code



vtkSmartPointer<vtkTIFFReader> reader =
vtkSmartPointer<vtkTIFFReader>::New();
reader->SetFileName("volume.tif"); // Multi slice TIFF
reader->Update();
vtkSmartPointer<vtkImageData> image = reader->GetOutput();

// Color transfer functions

vtkSmartPointer<vtkFixedPointVolumeRayCastMapper> volumeMapper =
vtkSmartPointer<vtkFixedPointVolumeRayCastMapper>::New();
volumeMapper->SetInputConnection(reader->GetOutputPort());

vtkSmartPointer<vtkVolume> volume = vtkSmartPointer<vtkVolume>::New();
volume->SetMapper(volumeMapper);

// (To the best of my knowledge) I define this Interactor to rotate the
volume, not the view or camera
vtkSmartPointer<vtkInteractorStyleTrackballActor> style =
vtkSmartPointer<vtkInteractorStyleTrackballActor>::New();

vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(ren1);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renWin);
renderWindowInteractor->SetInteractorStyle( style );

ren1->AddViewProp(volume); //Or AddVolume?
ren1->SetBackground(0,0,0);
ren1->ResetCamera();

renWin->SetSize(800, 800);
renWin->Render();
renderWindowInteractor->Start();

//After the user close the window, I want to apply the transformation to the
original volume
//Probably, my problem is in this section of code

vtkSmartPointer<vtkMatrix4x4> matrixRot =
vtkSmartPointer<vtkMatrix4x4>::New();
volume->GetMatrix(matrixRot);

vtkSmartPointer<vtkImageReslice> reslice =
vtkSmartPointer<vtkImageReslice>::New();
reslice->SetInputConnection(reader->GetOutputPort());
// Rotate about the center of the image?
vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->SetMatrix(matrixRot);
reslice->SetOutputOrigin( reader->GetOutput()->GetOrigin()[0],
reader->GetOutput()->GetOrigin()[1], reader->GetOutput()->GetOrigin()[2]);
reslice->SetResliceTransform(transform);
reslice->SetInterpolationModeToCubic();
reslice->SetOutputSpacing(
reader>GetOutput()->GetSpacing()[0], reader->GetOutput()->GetSpacing()[1],
reader->GetOutput()->GetSpacing()[2]);
reslice->SetOutputExtent(reader->GetOutput()->GetExtent());
reslice->Update();



Thanks in advance.
Lucas




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


More information about the vtkusers mailing list