]> Creatis software - clitk.git/blob - vv/vvMaximumIntensityProjection.cxx
Only update cursor value when clicking point
[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 #include <QInputDialog>
29
30 void vvMaximumIntensityProjection::Compute(vvSlicerManager * slicer_manager)
31 {
32   mCurrentSlicerManager = slicer_manager;
33   mDimension = QInputDialog::getInteger(0, "MIP Axis","Choose the axis along which to perform the MIP",0,0,\
34                                      slicer_manager->GetImage()->GetNumberOfDimensions()-1,1);
35 #define TRY_TYPE(TYPE)                                                  \
36   if (clitk::IsSameType<TYPE>(image->GetScalarTypeAsITKString())) { this->Update_WithPixelType<TYPE>(image); return; }
37   std::string list = clitk::CreateListOfTypes<short>();
38   vvImage::Pointer image=slicer_manager->GetSlicer(0)->GetImage();
39   TRY_TYPE(float);
40   TRY_TYPE(double);
41   TRY_TYPE(int);
42   TRY_TYPE(unsigned int);
43   TRY_TYPE(short);
44   TRY_TYPE(unsigned short);
45   TRY_TYPE(char);
46   TRY_TYPE(unsigned char);
47   QMessageBox::warning(0,"Unsupported image type",
48                        QString("Error, I don't know the type")+QString(image->GetScalarTypeAsITKString().c_str()) +QString("' for the input image.\nKnown types are ") + QString(list.c_str()));
49   error=true;
50 #undef TRY_TYPE
51 }
52
53 template <class PixelType>
54 void vvMaximumIntensityProjection::Update_WithPixelType(vvImage::Pointer image)
55 {
56   switch(image->GetNumberOfDimensions()) {
57   case 3:
58     Update_WithDimAndPixelType<PixelType,3>(image);
59     break;;
60   case 4:
61     Update_WithDimAndPixelType<PixelType,4>(image);
62     break;;
63   default:
64     QMessageBox::warning(0,"Unsupported image dimension",QString("Unsupported image dimension. Supported dimensions are 3 and 4"));
65     error=true;
66   }
67 }
68
69 template <class PixelType,int Dim>
70 void vvMaximumIntensityProjection::Update_WithDimAndPixelType(vvImage::Pointer image)
71 {
72   typedef itk::Image<PixelType,Dim> ImageType;
73   typedef itk::Image<PixelType,Dim-1> OutputImageType;
74   typedef itk::MaximumProjectionImageFilter<ImageType,OutputImageType> FilterType;
75   typename FilterType::Pointer filter = FilterType::New();
76   filter->SetProjectionDimension(mDimension);
77   typename ImageType::ConstPointer input = vvImageToITK<ImageType>(image);
78   filter->SetInput(input);
79   filter->Update();
80   mOutputImage=vvImageFromITK<Dim-1,PixelType>(filter->GetOutput());
81   // std::ostringstream osstream;
82   // osstream << "MIP_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";  
83   // AddImage(mOutputImage,osstream.str());
84 }