ITK/Examples/QuickViewDemo

From KitwarePublic
< ITK‎ | Examples
Revision as of 20:41, 23 October 2010 by Daviddoria (talk | contribs) (Created page with " ==QuickViewDemo.cxx== <source lang="cpp"> #include "itkImage.h" #include "itkImageFileReader.h" #include "itkRescaleIntensityImageFilter.h" #include "QuickView.h" int main(int...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

QuickViewDemo.cxx

<source lang="cpp">

  1. include "itkImage.h"
  2. include "itkImageFileReader.h"
  3. include "itkRescaleIntensityImageFilter.h"
  1. include "QuickView.h"

int main(int argc, char *argv[]) {

 if(argc < 2)
   {
   std::cerr << "Required: filename" << std::endl;
   return EXIT_FAILURE;
   }
 typedef itk::Image<unsigned char, 2>  ImageType;
 typedef itk::ImageFileReader<ImageType> ReaderType;
 ReaderType::Pointer reader = ReaderType::New();
 reader->SetFileName(argv[1]);
 typedef itk::RescaleIntensityImageFilter< ImageType, ImageType > RescaleFilterType;
 RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
 rescaleFilter->SetInput(reader->GetOutput());
 rescaleFilter->SetOutputMinimum(0);
 rescaleFilter->SetOutputMaximum(255);
 QuickView viewer;
 viewer.AddImage(reader->GetOutput());
 viewer.AddImage(rescaleFilter->GetOutput());
 viewer.Visualize();
 return EXIT_SUCCESS;

} </source>

QuickView.h

<source lang="cpp">

  1. ifndef QuickView_H
  2. define QuickView_H
  1. include <vector>
  1. include <itkImage.h>

class QuickView { public:

 void AddImage(itk::Image<unsigned char, 2>::Pointer  image);
 void Visualize();

private:

 std::vector<itk::Image<unsigned char, 2>::Pointer > Images;

};

  1. endif

</source>

QuickView.cxx

<source lang="cpp">

  1. include "QuickView.h"
  1. include "itkImage.h"
  1. include "vtkImageViewer.h"
  2. include "vtkRenderWindowInteractor.h"
  3. include "vtkSmartPointer.h"
  4. include "vtkImageActor.h"
  5. include "vtkInteractorStyleImage.h"
  6. include "vtkRenderer.h"
  1. include <itkImageToVTKImageFilter.h>

void QuickView::AddImage(itk::Image<unsigned char, 2>::Pointer image) {

 this->Images.push_back(image);

}

/* void QuickView::Visualize() {

 // Setup the render window
 vtkSmartPointer<vtkRenderWindow> renderWindow =
   vtkSmartPointer<vtkRenderWindow>::New();
 unsigned int rendererSize = 300;
 renderWindow->SetSize(rendererSize * this->Images.size(), rendererSize);
 vtkSmartPointer<vtkRenderWindowInteractor> interactor =
   vtkSmartPointer<vtkRenderWindowInteractor>::New();
 interactor->SetRenderWindow(renderWindow);


 typedef itk::ImageToVTKImageFilter<itk::Image<unsigned char, 2> > ConnectorType;
 ConnectorType::Pointer connector = ConnectorType::New();
 connector->SetInput(this->Images[0]);
 connector->Update();
 // (xmin, ymin, xmax, ymax)
 //double viewport[4] = {static_cast<double>(i)*step, 0.0, static_cast<double>(i+1)*step, 1.0};
 //viewports.push_back(viewport);
 vtkSmartPointer<vtkImageActor> actor =
   vtkSmartPointer<vtkImageActor>::New();
 actor->SetInput(connector->GetOutput());
 vtkSmartPointer<vtkRenderer> renderer =
   vtkSmartPointer<vtkRenderer>::New();
 renderWindow->AddRenderer(renderer);
 renderer->AddActor(actor);
 renderer->ResetCamera();
 renderWindow->Render();
 vtkSmartPointer<vtkInteractorStyleImage> style =
   vtkSmartPointer<vtkInteractorStyleImage>::New();
 interactor->SetInteractorStyle(style);
 interactor->Start();

}

  • /


void QuickView::Visualize() {

 // Setup the render window
 vtkSmartPointer<vtkRenderWindow> renderWindow =
   vtkSmartPointer<vtkRenderWindow>::New();
 unsigned int rendererSize = 300;
 renderWindow->SetSize(rendererSize * this->Images.size(), rendererSize);
 vtkSmartPointer<vtkRenderWindowInteractor> interactor =
   vtkSmartPointer<vtkRenderWindowInteractor>::New();
 interactor->SetRenderWindow(renderWindow);
 // Render all of the images
 double step = 1./(static_cast<double>(this->Images.size()));
 std::vector<double*> viewports;
 typedef itk::ImageToVTKImageFilter<itk::Image<unsigned char, 2> > ConnectorType;
 std::vector<ConnectorType::Pointer> connectors; // Force the connectors to persist (not lose scope) after each iteration of the loop
 for(unsigned int i = 0; i < this->Images.size(); i++)
   {
   
   ConnectorType::Pointer connector = ConnectorType::New();
   connectors.push_back(connector);
   connector->SetInput(this->Images[i]);
   connector->Update();
 
   // (xmin, ymin, xmax, ymax)
   double viewport[4] = {static_cast<double>(i)*step, 0.0, static_cast<double>(i+1)*step, 1.0};
   viewports.push_back(viewport);
   vtkSmartPointer<vtkImageActor> actor =
     vtkSmartPointer<vtkImageActor>::New();
   actor->SetInput(connector->GetOutput());
   // Setup both renderers
   vtkSmartPointer<vtkRenderer> renderer =
     vtkSmartPointer<vtkRenderer>::New();
   renderWindow->AddRenderer(renderer);
   renderer->SetViewport(viewports[i]);
   //renderer->SetBackground(.6, .5, .4);
   renderer->AddActor(actor);
   renderer->ResetCamera();
   }
 renderWindow->Render();
 vtkSmartPointer<vtkInteractorStyleImage> style =
   vtkSmartPointer<vtkInteractorStyleImage>::New();
 interactor->SetInteractorStyle(style);
 interactor->Start();

}

</source>


CMakeLists.txt

<source lang="cmake">

</source>