]> Creatis software - clitk.git/blob - filters/clitkGuerreroVentilationGenericFilter.cxx
Initial revision
[clitk.git] / filters / clitkGuerreroVentilationGenericFilter.cxx
1 /*=========================================================================
2
3   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
4   l'Image). All rights reserved. See Doc/License.txt or
5   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
6                                                                                 
7      This software is distributed WITHOUT ANY WARRANTY; without even
8      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9      PURPOSE.  See the above copyright notices for more information.
10                                                                              
11 =========================================================================*/
12
13 /**
14  -------------------------------------------------------------------
15  * @file   clitkGuerreroVentilationGenericFilter.cxx
16  * @author Joël Schaerer
17  * @date   20 April 2009
18
19  * @brief  
20  -------------------------------------------------------------------*/
21
22 #include "clitkGuerreroVentilationGenericFilter.h"
23 #include <itkBinaryGuerreroFilter.h>
24 #include <itkImageDuplicator.h>
25 //--------------------------------------------------------------------
26 clitk::GuerreroVentilationGenericFilter::GuerreroVentilationGenericFilter() 
27 {
28     blood_mass_factor=1.;
29 }
30 //--------------------------------------------------------------------
31
32 //--------------------------------------------------------------------
33 void clitk::GuerreroVentilationGenericFilter::Update () {
34   
35   // Determine dim, pixel type, number of components
36   this->GetInputImageDimensionAndPixelType(mDim,mPixelTypeName,mNbOfComponents);
37   
38   // Switch by dimension
39   if (mDim == 3) { Update_WithDim<3>(); return; }
40   if (mDim == 2) { Update_WithDim<2>(); return; }
41   std::cerr << "Error, dimension of input image is " << mDim << ", but I only work with 2 or 3." << std::endl;
42   exit(0);
43 }
44 //--------------------------------------------------------------------
45
46 //This is where you put the actual implementation
47
48 #include <sstream>
49 #include <itkExtractImageFilter.h>
50
51
52 //--------------------------------------------------------------------
53 template<unsigned int Dim>
54 void clitk::GuerreroVentilationGenericFilter::Update_WithDim() { 
55 #define TRY_TYPE(TYPE)                                                  \
56   if (IsSameType<TYPE>(mPixelTypeName)) { Update_WithDimAndPixelType<Dim, TYPE>(); return; } 
57   // TRY_TYPE(signed char);
58   // TRY_TYPE(uchar);
59   TRY_TYPE(short);
60   //TRY_TYPE(ushort);
61   // TRY_TYPE(int);
62 //   TRY_TYPE(unsigned int); 
63   //TRY_TYPE(float);
64   // TRY_TYPE(double);
65 #undef TRY_TYPE
66
67   std::string list = CreateListOfTypes<uchar, short, ushort, int, uint, float, double>();
68   std::cerr << "Error, I don't know the type '" << mPixelTypeName << "' for the input image '"
69             << mInputFilenames[0] << "'." << std::endl << "Known types are " << list << std::endl;
70   exit(0);
71 }
72 //--------------------------------------------------------------------
73
74 //--------------------------------------------------------------------
75 template<unsigned int Dim, class PixelType>
76 void clitk::GuerreroVentilationGenericFilter::Update_WithDimAndPixelType() {
77
78     // Read input
79     assert(mInputFilenames.size() == 2);
80     typedef itk::Image<PixelType,Dim> ImageType;
81     typedef itk::Image<float,Dim> OutputImageType;
82     typename ImageType::Pointer input = clitk::readImage<ImageType>(mInputFilenames[0], mIOVerbose);
83     typename ImageType::Pointer ref = clitk::readImage<ImageType>(mInputFilenames[1], mIOVerbose);
84
85
86     typedef itk::BinaryGuerreroFilter<ImageType,ImageType,OutputImageType> GFilterType;
87     typename GFilterType::Pointer filter = GFilterType::New();
88     filter->SetInput1(ref);
89     filter->SetInput2(input);
90     filter->SetBloodCorrectionFactor(blood_mass_factor);
91     filter->SetUseCorrectFormula(use_correct_formula);
92     filter->Update();
93     this->SetNextOutput<OutputImageType>(filter->GetOutput());
94     //clitk::writeImage<OutputImageType>(filter->GetOutput(), mOutputFilename, mIOVerbose);
95     //std::cout << "Warning: removed " << filter->GetFunctor().aberant_voxels << " aberant voxels from the ventilation image"
96         //<< std::endl;
97 }