]> Creatis software - clitk.git/blob - filters/clitkSplitImageGenericFilter.cxx
Reformatted using new coding style
[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 {
34   mSplitDimension = 0;
35   InitializeImageType<3>();
36   InitializeImageType<4>();
37 }
38 //--------------------------------------------------------------------
39
40
41 //--------------------------------------------------------------------
42 template<unsigned int Dim>
43 void clitk::SplitImageGenericFilter::InitializeImageType()
44 {
45   ADD_DEFAULT_IMAGE_TYPES(Dim);
46   ADD_VEC_IMAGE_TYPE(Dim, 3,float);
47 }
48 //--------------------------------------------------------------------
49
50 //--------------------------------------------------------------------
51 template<class ImageType>
52 void clitk::SplitImageGenericFilter::UpdateWithInputImageType()
53 {
54
55   // Read input
56   typedef typename ImageType::PixelType PixelType;
57   typedef itk::Image<PixelType,ImageType::ImageDimension-1> OutputImageType;
58   typename ImageType::Pointer input = this->GetInput<ImageType>(0);
59   typedef itk::ExtractImageFilter<ImageType,OutputImageType> FilterType;
60   typename FilterType::Pointer filter= FilterType::New();
61
62   filter->SetInput(input);
63   typename ImageType::SizeType size=input->GetLargestPossibleRegion().GetSize();
64   size[mSplitDimension]=0;
65   typename ImageType::RegionType extracted_region;
66   extracted_region.SetSize(size);
67   filter->SetExtractionRegion(extracted_region);
68   filter->Update();
69
70   typename ImageType::IndexType index=input->GetLargestPossibleRegion().GetIndex();
71   std::string base_filename=GetOutputFilename();
72   unsigned int number_of_output_images=input->GetLargestPossibleRegion().GetSize()[mSplitDimension];
73   for (unsigned int i=0; i<number_of_output_images; i++) {
74     std::ostringstream ss;
75     ss << i;
76     index[mSplitDimension]=i;
77     extracted_region.SetIndex(index);
78     filter->SetExtractionRegion(extracted_region);
79     filter->Update();
80     SetOutputFilename(base_filename+"_"+ss.str()+".mhd");
81     typename OutputImageType::Pointer output=filter->GetOutput();
82     SetNextOutput<OutputImageType>(output);
83   }
84 }
85 //--------------------------------------------------------------------