]> Creatis software - creaMaracasVisu.git/blob - appli/QtVTKViewer/qtvtkviewer.cxx
dcafe09de208d6d8654123649d44860e33d9248e
[creaMaracasVisu.git] / appli / QtVTKViewer / qtvtkviewer.cxx
1
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.
10 //
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.
15 //
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
19 // warranty.
20 //----------------------------------------------------------------------
21
22 #include "qtvtkviewerwidget.h"
23 #include <QMainWindow>
24 #include <QApplication>
25
26 #include "itktovtkimageimport.h"
27 #include "itkImage.h"
28 #include "itkRGBPixel.h"
29 #include "itkImageFileReader.h"
30
31
32 #include "itkvtkcolortransferfunction.h"
33
34
35 #include "iostream"
36
37
38
39
40
41 using namespace std;                                    // make std:: accessible
42
43
44 int main(int argc, char **argv)
45 {
46
47
48
49
50
51
52
53
54     if (argc < 2)
55       {
56         std::cout << "ERROR: data file name argument missing."
57                   << std::endl ;
58         return EXIT_FAILURE;
59       }
60
61     std::string inputFilename = argv[1];
62     //std::string inputFilename2 = argv[2];
63
64
65     typedef unsigned char PixelType;
66     typedef itk::RGBPixel< PixelType > RGBPixelType;
67     typedef itk::Image< RGBPixelType, 2 > RGBImageType;
68
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();
74
75
76     typedef itk::ITKToVTKImageImport< RGBImageType > ITKToVTKRGBType;
77     ITKToVTKRGBType::Pointer itktovtkrgb = ITKToVTKRGBType::New();
78     itktovtkrgb->SetITKImage(imagergb);
79
80
81
82
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);
89     region.SetIndex(0,0);
90     region.SetIndex(1,0);
91     region.SetIndex(2,0);
92
93     image->SetRegions(region);
94     image->Allocate();
95
96     typedef itk::ITKToVTKImageImport< RGBImage3DType > ITKToVTKType;
97     ITKToVTKType::Pointer itktovtk = ITKToVTKType::New();
98     itktovtk->SetITKImage(image);
99
100
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);
105     rgbtolum->Update();
106     LuminanceImageType::Pointer lumimage =  rgbtolum->GetOutput();
107
108
109     typedef itk::ITKToVTKImageImport< LuminanceImageType > ITKToVTKLuminanceType;
110     ITKToVTKLuminanceType::Pointer itktovtklum = ITKToVTKLuminanceType::New();
111     itktovtklum->SetITKImage(lumimage);
112
113
114     vtkImageData* vtkimage =itktovtklum->GetOutputVTKImage();
115
116
117
118     typedef itk::VTKColorTransferFunction< RGBImageType > VTKColorTransferType;
119     VTKColorTransferType::Pointer vtkcolortransfer = VTKColorTransferType::New();
120
121     vtkcolortransfer->SetInput(imagergb);
122     vtkcolortransfer->Update();
123     vtkColorTransferFunction* colortransfer = vtkcolortransfer->GetOutput();
124
125     QApplication app(argc, argv);
126
127
128     QMainWindow* mainwindow = new QMainWindow();
129
130     QtVTKViewerWidget *viewer = new QtVTKViewerWidget(mainwindow);
131
132     mainwindow-> setCentralWidget(viewer);
133
134
135     mainwindow->show();
136
137     viewer->setImage(vtkimage);
138     viewer->SetLookupTable((vtkLookupTable*)colortransfer);
139     int scalnum = vtkimage->GetNumberOfScalarComponents();
140
141     cout<<scalnum<<endl;
142
143
144
145
146
147     return app.exec();
148 }
149