20 #ifndef __itkBSplineDecompositionImageFilter_txx
21 #define __itkBSplineDecompositionImageFilter_txx
34 template <
class TInputImage,
class TOutputImage>
41 m_IteratorDirection = 0;
42 this->SetSplineOrder(SplineOrder);
49 template <
class TInputImage,
class TOutputImage>
56 Superclass::PrintSelf( os, indent );
57 os << indent <<
"Spline Order: " << m_SplineOrder << std::endl;
62 template <
class TInputImage,
class TOutputImage>
73 if (m_DataLength[m_IteratorDirection] == 1)
79 for (
int k = 0; k < m_NumberOfPoles; k++)
82 c0 = c0 * (1.0 - m_SplinePoles[k]) * (1.0 - 1.0 / m_SplinePoles[k]);
86 for (
unsigned int n = 0; n < m_DataLength[m_IteratorDirection]; n++)
92 for (
int k = 0; k < m_NumberOfPoles; k++)
95 this->SetInitialCausalCoefficient(m_SplinePoles[k]);
97 for (
unsigned int n = 1; n < m_DataLength[m_IteratorDirection]; n++)
99 m_Scratch[n] += m_SplinePoles[k] * m_Scratch[n - 1];
103 this->SetInitialAntiCausalCoefficient(m_SplinePoles[k]);
105 for (
int n = m_DataLength[m_IteratorDirection] - 2; 0 <= n; n--)
107 m_Scratch[n] = m_SplinePoles[k] * (m_Scratch[n + 1] - m_Scratch[n]);
115 template <
class TInputImage,
class TOutputImage>
120 if (SplineOrder == m_SplineOrder)
124 m_SplineOrder = SplineOrder;
131 template <
class TInputImage,
class TOutputImage>
139 switch (m_SplineOrder)
143 m_SplinePoles[0] = vcl_sqrt(3.0) - 2.0;
153 m_SplinePoles[0] = vcl_sqrt(8.0) - 3.0;
157 m_SplinePoles[0] = vcl_sqrt(664.0 - vcl_sqrt(438976.0)) + vcl_sqrt(304.0) - 19.0;
158 m_SplinePoles[1] = vcl_sqrt(664.0 + vcl_sqrt(438976.0)) - vcl_sqrt(304.0) - 19.0;
162 m_SplinePoles[0] = vcl_sqrt(135.0 / 2.0 - vcl_sqrt(17745.0 / 4.0)) + vcl_sqrt(105.0 / 4.0)
164 m_SplinePoles[1] = vcl_sqrt(135.0 / 2.0 + vcl_sqrt(17745.0 / 4.0)) - vcl_sqrt(105.0 / 4.0)
171 err.
SetDescription(
"SplineOrder must be between 0 and 5. Requested spline order has not been implemented yet." );
178 template <
class TInputImage,
class TOutputImage>
187 unsigned long horizon;
190 horizon = m_DataLength[m_IteratorDirection];
192 if (m_Tolerance > 0.0)
194 horizon = (long)vcl_ceil(vcl_log(m_Tolerance) / vcl_log(vcl_fabs(z)));
196 if (horizon < m_DataLength[m_IteratorDirection])
200 for (
unsigned int n = 1; n < horizon; n++)
202 sum += zn * m_Scratch[n];
210 z2n = vcl_pow(z, (
double)(m_DataLength[m_IteratorDirection] - 1L));
211 sum = m_Scratch[0] + z2n * m_Scratch[m_DataLength[m_IteratorDirection] - 1L];
213 for (
unsigned int n = 1; n <= (m_DataLength[m_IteratorDirection] - 2); n++)
215 sum += (zn + z2n) * m_Scratch[n];
219 m_Scratch[0] = sum / (1.0 - zn * zn);
224 template <
class TInputImage,
class TOutputImage>
232 m_Scratch[m_DataLength[m_IteratorDirection] - 1] =
233 (z / (z * z - 1.0)) *
234 (z * m_Scratch[m_DataLength[m_IteratorDirection] - 2] + m_Scratch[m_DataLength[m_IteratorDirection] - 1]);
238 template <
class TInputImage,
class TOutputImage>
247 unsigned int count = output->GetBufferedRegion().GetNumberOfPixels() / size[0] * ImageDimension;
252 this->CopyImageToImage();
254 for (
unsigned int n=0; n < ImageDimension; n++)
256 m_IteratorDirection = n;
263 while ( !CIterator.IsAtEnd() )
266 this->CopyCoefficientsToScratch( CIterator );
270 this->DataToCoefficients1D();
274 CIterator.GoToBeginOfLine();
275 this->CopyScratchToCoefficients( CIterator );
276 CIterator.NextLine();
286 template <
class TInputImage,
class TOutputImage>
294 typedef typename TOutputImage::PixelType OutputPixelType;
296 InputIterator inIt( this->GetInput(), this->GetInput()->GetBufferedRegion() );
297 OutputIterator outIt( this->GetOutput(), this->GetOutput()->GetBufferedRegion() );
300 outIt = outIt.Begin();
302 while ( !outIt.IsAtEnd() )
304 outIt.Set( static_cast<OutputPixelType>( inIt.Get() ) );
315 template <
class TInputImage,
class TOutputImage>
320 typedef typename TOutputImage::PixelType OutputPixelType;
324 Iter.
Set( static_cast<OutputPixelType>( m_Scratch[j] ) );
335 template <
class TInputImage,
class TOutputImage>
353 template <
class TInputImage,
class TOutputImage>
363 inputPtr->SetRequestedRegionToLargestPossibleRegion();
371 template <
class TInputImage,
class TOutputImage>
380 TOutputImage *imgData;
381 imgData =
dynamic_cast<TOutputImage*
>( output );
384 imgData->SetRequestedRegionToLargestPossibleRegion();
392 template <
class TInputImage,
class TOutputImage>
400 m_DataLength = inputPtr->GetBufferedRegion().GetSize();
402 unsigned long maxLength = 0;
403 for (
unsigned int n = 0; n < ImageDimension; n++ )
405 if ( m_DataLength[n] > maxLength )
407 maxLength = m_DataLength[n];
410 m_Scratch.resize( maxLength );
414 outputPtr->SetBufferedRegion( outputPtr->GetRequestedRegion() );
415 outputPtr->Allocate();
418 this->DataToCoefficientsND();