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 ===========================================================================**/
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)
57 for(unsigned int i=0; i<this->GetNumberOfOutputs(); i++) {
58 o.push_back(this->GetOutput(i));
61 //--------------------------------------------------------------------
64 //--------------------------------------------------------------------
65 template <class ImageType>
67 clitk::ExtractSliceFilter<ImageType>::
68 GenerateOutputInformation()
70 ImagePointer input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
72 // Create region to extract
73 m_region = input->GetLargestPossibleRegion();
74 m_size = m_region.GetSize();
75 m_index = m_region.GetIndex();
76 m_NumberOfSlices = m_region.GetSize()[GetDirection()];
78 //--------------------------------------------------------------------
81 //--------------------------------------------------------------------
82 template <class ImageType>
84 clitk::ExtractSliceFilter<ImageType>::
85 GenerateInputRequestedRegion() {
87 Superclass::GenerateInputRequestedRegion();
88 // Get input pointers and set requested region to common region
89 ImagePointer input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
90 input->SetRequestedRegion(input->GetLargestPossibleRegion());
92 //--------------------------------------------------------------------
94 //--------------------------------------------------------------------
95 template <class ImageType>
97 clitk::ExtractSliceFilter<ImageType>::
99 //--------------------------------------------------------------------
101 input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
103 //--------------------------------------------------------------------
104 // Create region to extract in 3D (and 2D = not used)
105 m_size[GetDirection()] = 0;
106 m_region.SetSize(m_size);
107 int start = m_index[GetDirection()];
108 this->SetNumberOfOutputs(m_NumberOfSlices);
110 //--------------------------------------------------------------------
111 // loop ExtractImageFilter with region updated, push_back
112 typedef itk::ExtractImageFilter<ImageType, SliceType> ExtractImageFilterType;
113 typename ExtractImageFilterType::Pointer extract = ExtractImageFilterType::New();
114 extract->SetInput(input);
115 for(int i=0; i<m_NumberOfSlices; i++) {
116 extract = ExtractImageFilterType::New();
117 extract->SetInput(input);
118 m_index[GetDirection()] = start + i;
119 m_region.SetIndex(m_index);
120 extract->SetExtractionRegion(m_region);
121 #if ITK_VERSION_MAJOR == 4
122 extract->SetDirectionCollapseToSubmatrix();
125 SetNthOutput(i, extract->GetOutput());
129 //--------------------------------------------------------------------