]> Creatis software - clitk.git/blob - vv/vvMaximumIntensityProjection.cxx
Reformatted using new coding style
[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 #include <QMessageBox>
28
29 void vvMaximumIntensityProjection::Compute(vvSlicerManager * slicer_manager)
30 {
31 #define TRY_TYPE(TYPE)                                                  \
32 if (clitk::IsSameType<TYPE>(image->GetScalarTypeAsString())) { this->Update_WithPixelType<TYPE>(image); return; }
33   std::string list = clitk::CreateListOfTypes<short>();
34   vvImage::Pointer image=slicer_manager->GetSlicer(0)->GetImage();
35   TRY_TYPE(float);
36   TRY_TYPE(double);
37   TRY_TYPE(int);
38   TRY_TYPE(unsigned int);
39   TRY_TYPE(short);
40   TRY_TYPE(unsigned short);
41   TRY_TYPE(char);
42   TRY_TYPE(unsigned char);
43   QMessageBox::warning(0,"Unsupported image type",QString("Error, I don't know the type")+QString(image->GetScalarTypeAsString().c_str()) +QString("' for the input image.\nKnown types are ") + QString(list.c_str()));
44   error=true;
45 #undef TRY_TYPE
46 }
47
48 template <class PixelType>
49 void vvMaximumIntensityProjection::Update_WithPixelType(vvImage::Pointer image)
50 {
51   switch(image->GetNumberOfDimensions()) {
52   case 3:
53     Update_WithDimAndPixelType<PixelType,3>(image);
54     break;;
55   case 4:
56     Update_WithDimAndPixelType<PixelType,4>(image);
57     break;;
58   default:
59     QMessageBox::warning(0,"Unsupported image dimension",QString("Unsupported image dimension. Supported dimensions are 3 and 4"));
60     error=true;
61   }
62 }
63
64 template <class PixelType,int Dim>
65 void vvMaximumIntensityProjection::Update_WithDimAndPixelType(vvImage::Pointer image)
66 {
67   typedef itk::Image<PixelType,Dim> ImageType;
68   typedef itk::Image<PixelType,Dim-1> OutputImageType;
69   typedef itk::MaximumProjectionImageFilter<ImageType,OutputImageType> FilterType;
70   typename FilterType::Pointer filter = FilterType::New();
71   filter->SetProjectionDimension(Dim-1);
72   typename ImageType::ConstPointer input = vvImageToITK<ImageType>(image);
73   filter->SetInput(input);
74   filter->Update();
75   mOutputImage=vvImageFromITK<Dim-1,PixelType>(filter->GetOutput());
76 }