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://oncora1.lyon.fnclcc.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 ======================================================================-====*/
20 #include "clitkCommon.h"
23 #include <itkExtractImageFilter.h>
25 //--------------------------------------------------------------------
26 template <class ImageType>
27 clitk::ExtractSliceFilter<ImageType>::
32 this->SetNumberOfRequiredInputs(1);
35 //--------------------------------------------------------------------
38 //--------------------------------------------------------------------
39 template <class ImageType>
41 clitk::ExtractSliceFilter<ImageType>::
42 SetInput(const ImageType * image)
44 // Process object is not const-correct so the const casting is required.
45 this->SetNthInput(0, const_cast<ImageType *>(image));
47 //--------------------------------------------------------------------
50 //--------------------------------------------------------------------
51 template <class ImageType>
53 clitk::ExtractSliceFilter<ImageType>::
54 GetOutputSlices(std::vector<typename SliceType::Pointer> & o)
56 DD("GetOutputSlices");
58 for(unsigned int i=0; i<this->GetNumberOfOutputs(); i++) {
59 o.push_back(this->GetOutput(i));
60 // writeImage<SliceType>(this->GetOutput(i), "extractB"+clitk::toString(i)+".mhd");
63 //--------------------------------------------------------------------
66 //--------------------------------------------------------------------
67 template <class ImageType>
69 clitk::ExtractSliceFilter<ImageType>::
70 GenerateOutputInformation()
72 DD("GenerateOutputInformation");
73 ImagePointer input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
75 // Create region to extract
76 m_region = input->GetLargestPossibleRegion();
77 m_size = m_region.GetSize();
78 m_index = m_region.GetIndex();
79 m_NumberOfSlices = m_region.GetSize()[GetDirection()];
82 //--------------------------------------------------------------------
85 //--------------------------------------------------------------------
86 template <class ImageType>
88 clitk::ExtractSliceFilter<ImageType>::
89 GenerateInputRequestedRegion() {
90 DD("GenerateInputRequestedRegion");
92 Superclass::GenerateInputRequestedRegion();
93 // Get input pointers and set requested region to common region
94 ImagePointer input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
95 input->SetRequestedRegion(input->GetLargestPossibleRegion());
97 //--------------------------------------------------------------------
99 //--------------------------------------------------------------------
100 template <class ImageType>
102 clitk::ExtractSliceFilter<ImageType>::
106 //--------------------------------------------------------------------
108 input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
110 //--------------------------------------------------------------------
111 // Create region to extract in 3D (and 2D = not used)
112 m_size[GetDirection()] = 0;
113 m_region.SetSize(m_size);
114 int start = m_index[GetDirection()];
116 this->SetNumberOfOutputs(m_NumberOfSlices);
118 typename SliceType::RegionType regionSlice;
119 typename SliceType::SizeType sizeSlice;
120 typename SliceType::IndexType indexSlice;
122 for(int i=0; i<ImageDimension; i++) {
123 if (i != GetDirection()) {
124 sizeSlice[j] = m_size[i];
125 indexSlice[j] = m_index[j];
129 regionSlice.SetSize(sizeSlice);
130 regionSlice.SetIndex(indexSlice);
134 //--------------------------------------------------------------------
135 // loop ExtractImageFilter with region updated, push_back
136 typedef itk::ExtractImageFilter<ImageType, SliceType> ExtractImageFilterType;
137 typename ExtractImageFilterType::Pointer extract = ExtractImageFilterType::New();
138 extract->SetInput(input);
139 for(int i=0; i<m_NumberOfSlices; i++) {
140 extract = ExtractImageFilterType::New();
141 extract->SetInput(input);
143 m_index[GetDirection()] = start + i;
144 m_region.SetIndex(m_index);
146 extract->SetExtractionRegion(m_region);
149 SetNthOutput(i, extract->GetOutput());
150 // writeImage<SliceType>(extract->GetOutput(), "extractA"+clitk::toString(i)+".mhd");
155 //--------------------------------------------------------------------