]> Creatis software - clitk.git/blob - registration/clitkCalculateTREGenericFilter.cxx
*** empty log message ***
[clitk.git] / registration / clitkCalculateTREGenericFilter.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 #ifndef clitkCalculateTREGenericFilter_cxx
19 #define clitkCalculateTREGenericFilter_cxx
20
21 /* =================================================
22  * @file   clitkCalculateTREGenericFilter.cxx
23  * @author 
24  * @date   
25  * 
26  * @brief 
27  * 
28  ===================================================*/
29
30 #include "clitkCalculateTREGenericFilter.h"
31
32
33 namespace clitk
34 {
35
36
37   //-----------------------------------------------------------
38   // Constructor
39   //-----------------------------------------------------------
40   CalculateTREGenericFilter::CalculateTREGenericFilter()
41   {
42     m_Verbose=false;
43     m_InputFileName="";
44   }
45
46
47   //-----------------------------------------------------------
48   // Update
49   //-----------------------------------------------------------
50   void CalculateTREGenericFilter::Update()
51   {
52     // Read the Dimension and PixelType
53     int Dimension, Components;
54     std::string PixelType;
55     ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components);
56
57     
58     // Call UpdateWithDim
59     if(Dimension==2) ReadVectorFields<2,2>();
60     else if(Dimension==3) ReadVectorFields<3,3>();
61     else if (Dimension==4)ReadVectorFields<4,3>(); 
62     else 
63       {
64         std::cout<<"Error, Only for 2, 3 or 4  Dimensions!!!"<<std::endl ;
65         return;
66       }
67   }
68
69
70
71   //-----------------------------
72   // Process DVF
73   //-----------------------------
74   template< >
75   void 
76   CalculateTREGenericFilter::ProcessVectorFields<4,3>(std::vector<itk::Image<itk::Vector<float, 3>, 4>::Pointer > dvfs,  char** filenames )
77   {
78     // Typedefs
79     typedef itk::Vector<float,3> PixelType;
80     typedef itk::Image<PixelType, 4> InputImageType;
81     typedef itk::Image<PixelType, 3> OutputImageType;
82
83     // IO
84     InputImageType::Pointer input=dvfs[0];
85     std::vector<itk::Image<itk::Vector<float, 3>, 3>::Pointer > new_dvfs;
86     
87     // Split vector field
88     typedef itk::ExtractImageFilter<InputImageType,OutputImageType> FilterType;
89     unsigned int splitDimension=3;
90
91     // Make new file names
92     std::vector<std::string> new_filenames;
93     std::string base = filenames[0];
94
95     // Set the extract region
96     InputImageType::SizeType size=input->GetLargestPossibleRegion().GetSize();
97     size[splitDimension]=0;
98     InputImageType::RegionType extracted_region;
99     extracted_region.SetSize(size);
100     InputImageType::IndexType index=input->GetLargestPossibleRegion().GetIndex();
101     
102   
103     // Loop
104     for (unsigned int i=0;i<input->GetLargestPossibleRegion().GetSize()[splitDimension];i++)
105       {
106         
107         // Skip?
108         if (m_ArgsInfo.skip_given && i==(unsigned int) m_ArgsInfo.skip_arg) continue;
109
110         // extract dvf
111          FilterType::Pointer filter= FilterType::New();
112         filter->SetInput(input);
113         index[splitDimension]=i;
114         extracted_region.SetIndex(index);
115         filter->SetExtractionRegion(extracted_region);
116         filter->Update();
117         new_dvfs.push_back(filter->GetOutput());
118         
119         // make name
120         std::ostringstream number_dvf;
121         number_dvf << i;
122         std::string number =  number_dvf.str();
123         new_filenames.push_back(base+"_"+number);
124       }
125
126     // Update
127     this->UpdateWithDim<3>(new_dvfs, new_filenames); 
128
129   }
130
131
132
133
134   
135 } //end clitk
136
137 #endif  //#define clitkCalculateTREGenericFilter_cxx