Orfeo Toolbox  3.16
itkFFTWRealToComplexConjugateImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkFFTWRealToComplexConjugateImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2010-02-26 23:50:55 $
7  Version: $Revision: 1.13 $
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 __itkFFTWRealToComplexConjugateImageFilter_txx
18 #define __itkFFTWRealToComplexConjugateImageFilter_txx
19 
22 #include <iostream>
23 #include "itkIndent.h"
24 #include "itkMetaDataObject.h"
25 #include "itkProgressReporter.h"
26 
27 namespace itk
28 {
34 template <typename TPixel, unsigned int VDimension>
35 void
38 {
39  // get pointers to the input and output
40  typename TInputImageType::ConstPointer inputPtr = this->GetInput();
41  typename TOutputImageType::Pointer outputPtr = this->GetOutput();
42 
43  if ( !inputPtr || !outputPtr )
44  {
45  return;
46  }
47 
48  // we don't have a nice progress to report, but at least this simple line
49  // reports the begining and the end of the process
50  ProgressReporter progress(this, 0, 1);
51 
52  // allocate output buffer memory
53  outputPtr->SetBufferedRegion( outputPtr->GetRequestedRegion() );
54  outputPtr->Allocate();
55 
56  const typename TInputImageType::SizeType& inputSize
57  = inputPtr->GetLargestPossibleRegion().GetSize();
58  const typename TOutputImageType::SizeType& outputSize
59  = outputPtr->GetLargestPossibleRegion().GetSize();
60 
61  // figure out sizes
62  // size of input and output aren't the same which is handled in the superclass,
63  // sort of.
64  // the input size and output size only differ in the fastest moving dimension
65  unsigned int total_inputSize = 1;
66  unsigned int total_outputSize = 1;
67 
68  for(unsigned i = 0; i < VDimension; i++)
69  {
70  total_inputSize *= inputSize[i];
71  total_outputSize *= outputSize[i];
72  }
73 
74  if(this->m_PlanComputed) // if we've already computed a plan
75  {
76  // if the image sizes aren't the same,
77  // we have to compute the plan again
78  if(this->m_LastImageSize != total_inputSize)
79  {
80  delete [] this->m_InputBuffer;
81  delete [] this->m_OutputBuffer;
82  FFTWProxyType::DestroyPlan(this->m_Plan);
83  this->m_PlanComputed = false;
84  }
85  }
86  if(!this->m_PlanComputed)
87  {
88  this->m_InputBuffer = new TPixel[total_inputSize];
89  this->m_OutputBuffer =
90  new typename FFTWProxyType::ComplexType[total_outputSize];
91  this->m_LastImageSize = total_inputSize;
92  switch(VDimension)
93  {
94  case 1:
95  this->m_Plan = FFTWProxyType::Plan_dft_r2c_1d(inputSize[0],
96  this->m_InputBuffer,
97  this->m_OutputBuffer,
98  FFTW_ESTIMATE);
99  break;
100  case 2:
101  this->m_Plan = FFTWProxyType::Plan_dft_r2c_2d(inputSize[1],
102  inputSize[0],
103  this->m_InputBuffer,
104  this->m_OutputBuffer,
105  FFTW_ESTIMATE);
106  break;
107  case 3:
108  this->m_Plan = FFTWProxyType::Plan_dft_r2c_3d(inputSize[2],
109  inputSize[1],
110  inputSize[0],
111  this->m_InputBuffer,
112  this->m_OutputBuffer,
113  FFTW_ESTIMATE);
114  break;
115  default:
116  int *sizes = new int[VDimension];
117  for(unsigned int i = 0; i < VDimension; i++)
118  {
119  sizes[(VDimension - 1) - i] = inputSize[i];
120  }
121 
122  this->m_Plan = FFTWProxyType::Plan_dft_r2c(VDimension,sizes,
123  this->m_InputBuffer,
124  this->m_OutputBuffer,
125  FFTW_ESTIMATE);
126  delete [] sizes;
127  }
128  this->m_PlanComputed = true;
129  }
130  memcpy(this->m_InputBuffer,
131  inputPtr->GetBufferPointer(),
132  total_inputSize * sizeof(TPixel));
133  FFTWProxyType::Execute(this->m_Plan);
134  memcpy(outputPtr->GetBufferPointer(),
135  this->m_OutputBuffer,
136  total_outputSize * sizeof(typename FFTWProxyType::ComplexType));
137 }
138 
139 template <typename TPixel,unsigned int VDimension>
140 bool
143 {
144  return false;
145 }
146 
147 } // namespace itk
148 
149 #endif //_itkFFTWRealToComplexConjugateImageFilter_txx

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