1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
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.
13 It is distributed under dual licence
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
21 /* =================================================
22 * @file clitkCalculateTREGenericFilter.cxx
28 ===================================================*/
30 #include "clitkCalculateTREGenericFilter.h"
37 //-----------------------------------------------------------
39 //-----------------------------------------------------------
40 CalculateTREGenericFilter::CalculateTREGenericFilter()
50 //-----------------------------------------------------------
52 //-----------------------------------------------------------
53 void CalculateTREGenericFilter::Update()
55 // Read the Dimension and PixelType
56 if (m_ArgsInfo.vf_given && m_ArgsInfo.coeff_given)
58 std::cout << "Error, You have to supply either vector fields or coefficient images. Supplying both is not allowed. See clitkCalculateTRE --help for details."<<std::endl;;
61 else if (!m_ArgsInfo.vf_given && !m_ArgsInfo.coeff_given)
63 std::cout << "Error, You have to supply either vector fields or coefficient images. Supplying none is not allowed. See clitkCalculateTRE --help for details."<<std::endl;;
66 else if (m_ArgsInfo.vf_given)
67 m_InputFileName=m_ArgsInfo.vf_arg[0];
70 m_InputFileName=m_ArgsInfo.coeff_arg[0];
73 int Dimension, Components;
74 std::string PixelType;
75 ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components);
76 if (Dimension < 2 || Dimension > 4)
78 std::cout<<"Error, Only for 2, 3 or 4 Dimensions!!!"<<std::endl ;
83 if (m_ArgsInfo.vf_given)
85 if(Dimension==2) ReadVectorFields<2,2>();
87 if(Dimension==3) ReadVectorFields<3,3>();
88 else if (Dimension==4)ReadVectorFields<4,3>();
92 if(Dimension==2) ReadCoefficientImages<2,2>();
94 if(Dimension==3) ReadCoefficientImages<3,3>();
95 else if (Dimension==4)ReadCoefficientImages<4,3>();
99 //-----------------------------
101 //-----------------------------
104 CalculateTREGenericFilter::ProcessVectorFields<4,3>(std::vector<itk::Image<itk::Vector<double, 3>, 4>::Pointer > dvfs, char** filenames )
107 typedef itk::Vector<double,3> PixelType;
108 typedef itk::Image<PixelType, 4> InputImageType;
109 typedef itk::Image<PixelType, 3> OutputImageType;
112 InputImageType::Pointer input=dvfs[0];
113 std::vector<itk::Image<itk::Vector<double, 3>, 3>::Pointer > new_dvfs;
115 // Split vector field
116 typedef itk::ExtractImageFilter<InputImageType,OutputImageType> FilterType;
117 unsigned int splitDimension=3;
119 // Make new file names
120 std::vector<std::string> new_filenames;
121 std::string base = filenames[0];
123 // Set the extract region
124 InputImageType::SizeType size=input->GetLargestPossibleRegion().GetSize();
125 size[splitDimension]=0;
126 InputImageType::RegionType extracted_region;
127 extracted_region.SetSize(size);
128 InputImageType::IndexType index=input->GetLargestPossibleRegion().GetIndex();
132 for (unsigned int i=0;i<input->GetLargestPossibleRegion().GetSize()[splitDimension];i++)
136 if (m_ArgsInfo.skip_given && i==(unsigned int) m_ArgsInfo.skip_arg) continue;
139 FilterType::Pointer filter= FilterType::New();
140 filter->SetInput(input);
141 index[splitDimension]=i;
142 extracted_region.SetIndex(index);
143 filter->SetExtractionRegion(extracted_region);
145 new_dvfs.push_back(filter->GetOutput());
148 std::ostringstream number_dvf;
150 std::string number = number_dvf.str();
151 new_filenames.push_back(base+"_"+number);
155 this->UpdateDVFWithDim<3>(new_dvfs, new_filenames);
159 //-----------------------------
160 // Process Coefficient images
161 //-----------------------------
164 CalculateTREGenericFilter::ProcessCoefficientImages<4,3>(std::vector<itk::Image<itk::Vector<double, 3>, 4>::Pointer > coeffs, char** filenames )
167 typedef itk::Vector<double,3> PixelType;
168 typedef itk::Image<PixelType, 4> InputImageType;
169 typedef itk::Image<PixelType, 3> OutputImageType;
172 InputImageType::Pointer input=coeffs[0];
173 std::vector<itk::Image<itk::Vector<double, 3>, 3>::Pointer > new_coeffs;
175 // Split vector field
176 typedef itk::ExtractImageFilter<InputImageType,OutputImageType> FilterType;
177 unsigned int splitDimension=3;
179 // Make new file names
180 std::vector<std::string> new_filenames;
181 std::string base = filenames[0];
183 // Set the extract region
184 InputImageType::SizeType size=input->GetLargestPossibleRegion().GetSize();
185 size[splitDimension]=0;
186 InputImageType::RegionType extracted_region;
187 extracted_region.SetSize(size);
188 InputImageType::IndexType index=input->GetLargestPossibleRegion().GetIndex();
192 for (unsigned int i=0;i<input->GetLargestPossibleRegion().GetSize()[splitDimension];i++)
196 if (m_ArgsInfo.skip_given && i==(unsigned int) m_ArgsInfo.skip_arg) continue;
199 FilterType::Pointer filter= FilterType::New();
200 filter->SetInput(input);
201 index[splitDimension]=i;
202 extracted_region.SetIndex(index);
203 filter->SetExtractionRegion(extracted_region);
205 new_coeffs.push_back(filter->GetOutput());
208 std::ostringstream number_dvf;
210 std::string number = number_dvf.str();
211 new_filenames.push_back(base+"_"+number);
215 this->UpdateCoeffsWithDim<3>(new_coeffs, new_filenames);
223 #endif //#define clitkCalculateTREGenericFilter_cxx