Orfeo Toolbox  3.16
itkFFTShiftImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkFFTShiftImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-02-14 23:05:16 $
7  Version: $Revision: 1.1 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkFFTShiftImageFilter_txx
18 #define __itkFFTShiftImageFilter_txx
19 
20 #include "itkFFTShiftImageFilter.h"
21 #include "itkNumericTraits.h"
22 #include "itkProgressReporter.h"
24 
25 
26 namespace itk {
27 
28 template <class TInputImage, class TOutputImage>
31 {
32  m_Inverse = false;
33 }
34 
35 
36 template <class TInputImage, class TOutputImage>
37 void
40 {
41  // call the superclass' implementation of this method
42  Superclass::GenerateInputRequestedRegion();
43 
44  // We need all the input.
45  InputImagePointer input = const_cast<InputImageType *>(this->GetInput());
46  if ( !input )
47  { return; }
48  input->SetRequestedRegion( input->GetLargestPossibleRegion() );
49 }
50 
51 
52 template<class TInputImage, class TOutputImage>
53 void
55 ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
56  int threadId)
57 {
58  // setup the progress reporter
59  ProgressReporter progress( this, threadId, outputRegionForThread.GetNumberOfPixels() );
60 
61  // the index and size of the image needed to compute the shift
62  const IndexType oIdx = this->GetOutput()->GetLargestPossibleRegion().GetIndex();
63  const SizeType oSize = this->GetOutput()->GetLargestPossibleRegion().GetSize();
64  // the size of the segments for all axes
65  SizeType seg1Size;
66  SizeType seg2Size;
67 
68  // the center pixel is not computed the same way for the inverse shift in
69  // case the size is odd, to restore the same image as before the shift
70  for( int i=0; i<ImageDimension; i++)
71  {
72  if( oSize[i] % 2 == 1 )
73  {
74  if( !m_Inverse )
75  {
76  seg1Size[i] = oSize[i] / 2 + 1;
77  seg2Size[i] = oSize[i] / 2;
78  }
79  else
80  {
81  seg1Size[i] = oSize[i] / 2;
82  seg2Size[i] = oSize[i] / 2 + 1;
83  }
84  }
85  else
86  {
87  seg1Size[i] = oSize[i] / 2;
88  seg2Size[i] = oSize[i] / 2;
89  }
90  }
91 
92  // now iterate over the pixels of the output region for this thread
93  ImageRegionIteratorWithIndex<OutputImageType> oIt( this->GetOutput(), outputRegionForThread );
94  for( oIt.GoToBegin(); !oIt.IsAtEnd(); ++oIt )
95  {
96  IndexType idx = oIt.GetIndex();
97 
98  for( int i=0; i<ImageDimension; i++ )
99  {
100  if( idx[i] < (int)(oIdx[i] + seg2Size[i]) )
101  {
102  idx[i] = idx[i] + seg1Size[i];
103  }
104  else
105  {
106  idx[i] = idx[i] - seg2Size[i];
107  }
108  }
109 
110  oIt.Set( static_cast< OutputImagePixelType >( this->GetInput()->GetPixel( idx ) ) );
111  progress.CompletedPixel();
112 
113  }
114 
115 }
116 
117 
118 template<class TInputImage, class TOutputImage>
119 void
121 ::PrintSelf(std::ostream &os, Indent indent) const
122 {
123  Superclass::PrintSelf(os, indent);
124 
125  os << indent << "Inverse: " << m_Inverse << std::endl;
126 }
127 
128 }// end namespace itk
129 #endif

Generated at Sat Feb 2 2013 23:37:28 for Orfeo Toolbox with doxygen 1.8.1.1