VTK provide two viewers:
· 1. vtkImageviewer2
· 2. vtkResliceImageViewer
vtkImageviewer2
· vtkImageviewer2 is
convienient class for displaying 2D image sequence of a image volume. It replace
earlier version of the class vtkImageviewer. vtkImageviewer2 encapsulates
several objects
o vtkRenderWindow
o vtkRenderer
o vtkImageActor
o vtkImageMapToWindowLevelColors
This class also include vtkInteractorStyleImage that allow zooming, panning,Orientation(XY,YZ,XZ)
and windowing.
It provide the function SetSlice() to
change the image data(slice) on viewer.
There are two ways to use it:
· vtkImageviewer2 *viewer=
vtkImageviewer2::New();
viewer->SetInputConnection(reader->GetOutputPort());
viewer->SetSlice(40);
viewer->SetSliceOrientationToXY();
viewer->Render();
· This is to add geometry and Image
viewer->SetInputConnection(reader->GetOutputPort());
viewer->GetRenderer()->AddActor(actor);
This is the sample code:
#include <vtkSmartPointer.h>
#include <vtkJPEGReader.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkImageViewer2.h>
int main(int argc, char
*argv[])
{
vtkSmartPointer<vtkJPEGReader>
reader=vtkSmartPointer<vtkJPEGReader>::New();
//SetFileName()for single file .Use SetFileNames for
more than one file(This will cover in next blog with Qt)
reader->SetFileName("D:\\testing_Dataset\\JPEG "/*Dataset Path*/);
reader->Update();
vtkSmartPointer<vtkImageViewer2>viewer=
vtkSmartPointer<vtkImageViewer2>::New();
vtkSmartPointer<vtkRenderWindowInteractor>interactor
=vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow( viewer->GetRenderWindow() );
viewer->SetupInteractor(interactor);
viewer->SetInputConnection(reader->GetOutputPort());
viewer->GetRenderer()->ResetCamera();
viewer->Render();
interactor->Start();
return
EXIT_SUCCESS;
}
vtkResliceImageViewer
This
class is similar to vtkImageViewer2. It displays the image along with a
two cross hairs for reslicing. The cross hairs may be interactively manipulated
and are typically used to reslice two other views of vtkResliceImageViewer. This class has default behaviour
of vtkImageViewer2 if the Reslice mode is set to
RESLICE_AXIS_ALIGNED.This class provide default functionality
for scrolling image data and automatic windowing.
This is the sample code:
#include <vtkSmartPointer.h>
#include <vtkDICOMImageReader.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkResliceImageViewer.h>
int main(int argc, char
*argv[])
{
vtkSmartPointer<vtkDICOMImageReader>
reader=vtkSmartPointer<vtkDICOMImageReader>::New();
reader->SetDirectoryName(("D:\\testing_Dataset\\DICOM
"/*Directory Path*/);
reader->Update();
vtkSmartPointer<vtkResliceImageViewer>viewer =vtkSmartPointer<vtkResliceImageViewer>::New();
vtkSmartPointer<vtkRenderWindowInteractor>interactor
=vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow( viewer->GetRenderWindow() );
viewer->SetupInteractor(interactor);
viewer->SetInputConnection(reader->GetOutputPort());
int midslice
=viewer->GetSliceMax()/2;
viewer->SetSlice(midslice);
viewer->SetSliceOrientationToXY();
viewer->GetRender
er()->ResetCamera();
viewer->Render();
interactor->Start();
return
EXIT_SUCCESS;
}
NOTE: vtkResliceImageViewer provide slice change on scroll by default but vtkImageViewer2
doesn’t provide so we have to code callback, vtkResliceImageViewer also provide
Oblique mode,Reslice mode(default) and SliceChangeEvent
that will be included in next blog.
No comments:
Post a Comment