]> Creatis software - clitk.git/blob - vv/vvMaximumIntensityProjection.cxx
added the new headers
[clitk.git] / vv / vvMaximumIntensityProjection.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #include <itkImage.h>
19 #include <itkMaximumProjectionImageFilter.h>
20
21 #include "clitkCommon.h"
22 #include "vvSlicerManager.h"
23 #include "vvSlicer.h"
24 #include "vvToITK.h"
25 #include "vvFromITK.h"
26 #include "vvMaximumIntensityProjection.h"
27
28 void vvMaximumIntensityProjection::Compute(vvSlicerManager * slicer_manager)
29 {
30 #define TRY_TYPE(TYPE)                                                  \
31 if (clitk::IsSameType<TYPE>(image->GetScalarTypeAsString())) { this->Update_WithPixelType<TYPE>(image); return; }
32     std::string list = clitk::CreateListOfTypes<short>();
33     vvImage::Pointer image=slicer_manager->GetSlicer(0)->GetImage();
34     TRY_TYPE(float);
35     TRY_TYPE(short);
36     std::cerr << "Error, I don't know the type '" << image->GetScalarTypeAsString() << "' for the input image. "
37         << std::endl << "Known types are " << list << std::endl;
38     exit(0);
39 #undef TRY_TYPE
40 }
41
42 template <class PixelType>
43 void vvMaximumIntensityProjection::Update_WithPixelType(vvImage::Pointer image)
44 {
45     switch(image->GetNumberOfDimensions())
46     {
47         case 3:
48             Update_WithDimAndPixelType<PixelType,3>(image);
49             break;;
50         case 4:
51             Update_WithDimAndPixelType<PixelType,4>(image);
52             break;;
53         default:
54             DD("Error: dimension not handled.");
55     }
56 }
57
58 template <class PixelType,int Dim>
59 void vvMaximumIntensityProjection::Update_WithDimAndPixelType(vvImage::Pointer image)
60 {
61     typedef itk::Image<PixelType,Dim> ImageType;
62     typedef itk::Image<PixelType,Dim-1> OutputImageType;
63     typedef itk::MaximumProjectionImageFilter<ImageType,OutputImageType> FilterType;
64     typename FilterType::Pointer filter = FilterType::New();
65     filter->SetProjectionDimension(Dim-1);
66     typename ImageType::ConstPointer input = vvImageToITK<ImageType>(image);
67     filter->SetInput(input);
68     filter->Update();
69     mOutputImage=vvImageFromITK<Dim-1,PixelType>(filter->GetOutput());
70 }