ITK/Examples/QuickViewDemo: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Created page with " ==QuickViewDemo.cxx== <source lang="cpp"> #include "itkImage.h" #include "itkImageFileReader.h" #include "itkRescaleIntensityImageFilter.h" #include "QuickView.h" int main(int...")
 
(Moving QuickView to ItkVtkGlue)
Line 1: Line 1:
==QuickViewDemo.cxx==
==QuickViewDemo.cxx==
<source lang="cpp">
<source lang="cpp">
Line 36: Line 35:
}
}
</source>
</source>
==QuickView.h==
<source lang="cpp">
#ifndef QuickView_H
#define QuickView_H
#include <vector>
#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;
};
#endif
</source>
==QuickView.cxx==
<source lang="cpp">
#include "QuickView.h"
#include "itkImage.h"
#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkImageActor.h"
#include "vtkInteractorStyleImage.h"
#include "vtkRenderer.h"
#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==
==CMakeLists.txt==

Revision as of 22:15, 15 November 2010

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>

CMakeLists.txt

<source lang="cmake">

</source>