2 //----------------------------------------------------------------------
3 // File: ann_sample.cpp
4 // Programmer: Sunil Arya and David Mount
5 // Last modified: 03/04/98 (Release 0.1)
6 // Description: Sample program for ANN
7 //----------------------------------------------------------------------
8 // Copyright (c) 1997-2005 University of Maryland and Sunil Arya and
9 // David Mount. All Rights Reserved.
11 // This software and related documentation is part of the Approximate
12 // Nearest Neighbor Library (ANN). This software is provided under
13 // the provisions of the Lesser GNU Public License (LGPL). See the
14 // file ../ReadMe.txt for further information.
16 // The University of Maryland (U.M.) and the authors make no
17 // representations about the suitability or fitness of this software for
18 // any purpose. It is provided "as is" without express or implied
20 //----------------------------------------------------------------------
22 #include "qtvtkviewerwidget.h"
23 #include <QMainWindow>
24 #include <QApplication>
26 #include "itktovtkimageimport.h"
28 #include "itkRGBPixel.h"
29 #include "itkImageFileReader.h"
32 #include "itkvtkcolortransferfunction.h"
41 using namespace std; // make std:: accessible
44 int main(int argc, char **argv)
56 std::cout << "ERROR: Image filename missing, Filename RGB Image 2D"
61 std::string inputFilename = argv[1];
62 //std::string inputFilename2 = argv[2];
65 typedef unsigned char PixelType;
66 typedef itk::RGBPixel< PixelType > RGBPixelType;
67 typedef itk::Image< RGBPixelType, 2 > RGBImageType;
69 typedef itk::ImageFileReader< RGBImageType > ImageReaderType ;
70 ImageReaderType::Pointer imageReader = ImageReaderType::New() ;
71 imageReader->SetFileName(inputFilename.c_str());
72 imageReader->Update();
73 RGBImageType::Pointer imagergb = imageReader->GetOutput();
76 typedef itk::ITKToVTKImageImport< RGBImageType > ITKToVTKRGBType;
77 ITKToVTKRGBType::Pointer itktovtkrgb = ITKToVTKRGBType::New();
78 itktovtkrgb->SetITKImage(imagergb);
83 typedef itk::Image< RGBPixelType, 3> RGBImage3DType;
84 RGBImage3DType::Pointer image = RGBImage3DType::New();
85 RGBImage3DType::RegionType region;
86 region.SetSize(0, 256);
87 region.SetSize(1, 256);
88 region.SetSize(2, 256);
93 image->SetRegions(region);
96 typedef itk::ITKToVTKImageImport< RGBImage3DType > ITKToVTKType;
97 ITKToVTKType::Pointer itktovtk = ITKToVTKType::New();
98 itktovtk->SetITKImage(image);
101 typedef itk::Image< unsigned char, 2 > LuminanceImageType;
102 typedef itk::RGBToLuminanceImageFilter< RGBImageType, LuminanceImageType> RGBToLumType;
103 RGBToLumType::Pointer rgbtolum = RGBToLumType::New();
104 rgbtolum->SetInput(imagergb);
106 LuminanceImageType::Pointer lumimage = rgbtolum->GetOutput();
109 typedef itk::ITKToVTKImageImport< LuminanceImageType > ITKToVTKLuminanceType;
110 ITKToVTKLuminanceType::Pointer itktovtklum = ITKToVTKLuminanceType::New();
111 itktovtklum->SetITKImage(lumimage);
114 vtkImageData* vtkimage =itktovtklum->GetOutputVTKImage();
118 typedef itk::VTKColorTransferFunction< RGBImageType > VTKColorTransferType;
119 VTKColorTransferType::Pointer vtkcolortransfer = VTKColorTransferType::New();
121 vtkcolortransfer->SetInput(imagergb);
122 vtkcolortransfer->Update();
123 vtkColorTransferFunction* colortransfer = vtkcolortransfer->GetOutput();
125 QApplication app(argc, argv);
128 QMainWindow* mainwindow = new QMainWindow();
130 QtVTKViewerWidget *viewer = new QtVTKViewerWidget(mainwindow);
132 mainwindow-> setCentralWidget(viewer);
137 viewer->setImage(vtkimage);
138 viewer->SetLookupTable((vtkLookupTable*)colortransfer);
139 int scalnum = vtkimage->GetNumberOfScalarComponents();