]> Creatis software - clitk.git/blob - vv/vvMaximumIntensityProjection.cxx
- new vv tool
[clitk.git] / vv / vvMaximumIntensityProjection.cxx
1 /*=========================================================================
2
3  Program:   vv
4  Language:  C++
5  Author :   Joel Schaerer (joel.schaerer@insa-lyon.fr)
6
7 Copyright (C) 2008
8 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
9 CREATIS-LRMN http://www.creatis.insa-lyon.fr
10
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, version 3 of the License.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23 =========================================================================*/
24
25 #include <itkImage.h>
26 #include <itkMaximumProjectionImageFilter.h>
27
28 #include "clitkCommon.h"
29 #include "vvSlicerManager.h"
30 #include "vvSlicer.h"
31 #include "vvToITK.h"
32 #include "vvFromITK.h"
33 #include "vvMaximumIntensityProjection.h"
34
35 void vvMaximumIntensityProjection::Compute(vvSlicerManager * slicer_manager)
36 {
37 #define TRY_TYPE(TYPE)                                                  \
38 if (clitk::IsSameType<TYPE>(image->GetScalarTypeAsString())) { this->Update_WithPixelType<TYPE>(image); return; }
39     std::string list = clitk::CreateListOfTypes<short>();
40     vvImage::Pointer image=slicer_manager->GetSlicer(0)->GetImage();
41     TRY_TYPE(float);
42     TRY_TYPE(short);
43     std::cerr << "Error, I don't know the type '" << image->GetScalarTypeAsString() << "' for the input image. "
44         << std::endl << "Known types are " << list << std::endl;
45     exit(0);
46 #undef TRY_TYPE
47 }
48
49 template <class PixelType>
50 void vvMaximumIntensityProjection::Update_WithPixelType(vvImage::Pointer image)
51 {
52     switch(image->GetNumberOfDimensions())
53     {
54         case 3:
55             Update_WithDimAndPixelType<PixelType,3>(image);
56             break;;
57         case 4:
58             Update_WithDimAndPixelType<PixelType,4>(image);
59             break;;
60         default:
61             DD("Error: dimension not handled.");
62     }
63 }
64
65 template <class PixelType,int Dim>
66 void vvMaximumIntensityProjection::Update_WithDimAndPixelType(vvImage::Pointer image)
67 {
68     typedef itk::Image<PixelType,Dim> ImageType;
69     typedef itk::Image<PixelType,Dim-1> OutputImageType;
70     typedef itk::MaximumProjectionImageFilter<ImageType,OutputImageType> FilterType;
71     typename FilterType::Pointer filter = FilterType::New();
72     filter->SetProjectionDimension(Dim-1);
73     typename ImageType::ConstPointer input = vvImageToITK<ImageType>(image);
74     filter->SetInput(input);
75     filter->Update();
76     mOutputImage=vvImageFromITK<Dim-1,PixelType>(filter->GetOutput());
77 }