]> Creatis software - clitk.git/blob - filters/clitkSplitImageGenericFilter.cxx
added the new headers
[clitk.git] / filters / clitkSplitImageGenericFilter.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 /**
19  -------------------------------------------------------------------
20  * @file   clitkSplitImageGenericFilter.cxx
21  * @author Joël Schaerer
22  * @date   20 April 2009
23
24  * @brief  
25  -------------------------------------------------------------------*/
26
27 #include "clitkSplitImageGenericFilter.h"
28
29 #include "clitkSplitImageGenericFilter.txx"
30 //--------------------------------------------------------------------
31 clitk::SplitImageGenericFilter::SplitImageGenericFilter():
32   clitk::ImageToImageGenericFilter<Self>("SplitImage") {
33   mSplitDimension = 0;
34   InitializeImageType<3>();
35   InitializeImageType<4>();
36 }
37 //--------------------------------------------------------------------
38
39
40 //--------------------------------------------------------------------
41 template<unsigned int Dim>
42 void clitk::SplitImageGenericFilter::InitializeImageType() {      
43   ADD_IMAGE_TYPE(Dim, char);
44   ADD_IMAGE_TYPE(Dim, unsigned char);
45   ADD_IMAGE_TYPE(Dim, short);
46   ADD_IMAGE_TYPE(Dim, int);
47   ADD_IMAGE_TYPE(Dim, float);
48   ADD_VEC_IMAGE_TYPE(Dim, 3,float);
49 }
50 //--------------------------------------------------------------------
51
52 //--------------------------------------------------------------------
53 template<class ImageType>
54 void clitk::SplitImageGenericFilter::UpdateWithInputImageType() {
55
56   // Read input
57   typedef typename ImageType::PixelType PixelType;
58   typedef itk::Image<PixelType,ImageType::ImageDimension-1> OutputImageType;
59   typename ImageType::Pointer input = this->GetInput<ImageType>(0);
60   typedef itk::ExtractImageFilter<ImageType,OutputImageType> FilterType;
61   typename FilterType::Pointer filter= FilterType::New();
62
63   filter->SetInput(input);
64   typename ImageType::SizeType size=input->GetLargestPossibleRegion().GetSize();
65   size[mSplitDimension]=0;
66   typename ImageType::RegionType extracted_region;
67   extracted_region.SetSize(size);
68   filter->SetExtractionRegion(extracted_region);
69   filter->Update();
70
71   typename ImageType::IndexType index=input->GetLargestPossibleRegion().GetIndex();
72   std::string base_filename=GetOutputFilename();
73   unsigned int number_of_output_images=input->GetLargestPossibleRegion().GetSize()[mSplitDimension];
74   for (unsigned int i=0;i<number_of_output_images;i++)
75   {
76       std::ostringstream ss;
77       ss << i;
78       index[mSplitDimension]=i;
79       extracted_region.SetIndex(index);
80       filter->SetExtractionRegion(extracted_region);
81       filter->Update();
82       SetOutputFilename(base_filename+"_"+ss.str()+".mhd");
83       typename OutputImageType::Pointer output=filter->GetOutput();
84       SetNextOutput<OutputImageType>(output);
85   }
86 }
87 //--------------------------------------------------------------------