Orfeo Toolbox  3.16
itkWarpVectorImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkWarpVectorImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-03-05 20:21:36 $
7  Version: $Revision: 1.10 $
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 __itkWarpVectorImageFilter_txx
18 #define __itkWarpVectorImageFilter_txx
20 
21 #include "itkImageRegionIterator.h"
23 #include "itkProgressReporter.h"
24 
25 namespace itk
26 {
27 
31 template <class TInputImage,class TOutputImage,class TDeformationField>
34 {
35  // Setup the number of required inputs
36  this->SetNumberOfRequiredInputs( 2 );
37 
38  // Setup default values
39  m_OutputSpacing.Fill( 1.0 );
40  m_OutputOrigin.Fill( 0.0 );
41  m_OutputDirection.SetIdentity();
42 
43  for (unsigned int i=0; i<PixelDimension; i++)
44  {
45  m_EdgePaddingValue[i] = 0;
46  }
47 
48  // Setup default interpolator
49  typename DefaultInterpolatorType::Pointer interp =
50  DefaultInterpolatorType::New();
51 
52  m_Interpolator =
53  static_cast<InterpolatorType*>( interp.GetPointer() );
54 
55 }
56 
60 template <class TInputImage,class TOutputImage,class TDeformationField>
61 void
63 ::PrintSelf(std::ostream& os, Indent indent) const
64 {
65 
66  Superclass::PrintSelf(os, indent);
67 
68  os << indent << "OutputSpacing: " << m_OutputSpacing << std::endl;
69  os << indent << "OutputOrigin: " << m_OutputOrigin << std::endl;
70  os << indent << "OutputDirection: " << m_OutputDirection << std::endl;
71  os << indent << "EdgePaddingValue: "
72  << static_cast<typename NumericTraits<PixelType>::PrintType>(m_EdgePaddingValue)
73  << std::endl;
74  os << indent << "Interpolator: " << m_Interpolator.GetPointer() << std::endl;
75 
76 }
77 
79 template <class TInputImage,class TOutputImage,class TDeformationField>
80 void
82 ::SetOutputSpacing(const double* spacing)
83 {
84  SpacingType s(spacing);
85  this->SetOutputSpacing( s );
86 }
87 
89 template <class TInputImage,class TOutputImage,class TDeformationField>
90 void
92 ::SetOutputOrigin(const double* origin)
93 {
94  PointType p(origin);
95  this->SetOutputOrigin(p);
96 }
97 
98 
100 template <class TInputImage,class TOutputImage,class TDeformationField>
101 void
104  const DeformationFieldType * field )
105 {
106  // const cast is needed because the pipeline is not const-correct.
107  DeformationFieldType * input =
108  const_cast< DeformationFieldType * >( field );
109  this->ProcessObject::SetNthInput( 1, input );
110 }
111 
112 
117 template <class TInputImage,class TOutputImage,class TDeformationField>
118 void
121  DeformationFieldType * field )
122 {
123  this->ProcessObject::SetNthInput( 1, field );
124 }
125 
126 
130 template <class TInputImage,class TOutputImage,class TDeformationField>
132 ::DeformationFieldType *
135 {
136  return static_cast<DeformationFieldType *>
137  ( this->ProcessObject::GetInput( 1 ));
138 }
139 
140 
146 template <class TInputImage,class TOutputImage,class TDeformationField>
147 void
150 {
151 
152  if( !m_Interpolator )
153  {
154  itkExceptionMacro(<< "Interpolator not set");
155  }
156 
157  // Connect input image to interpolator
158  m_Interpolator->SetInputImage( this->GetInput() );
159 
160 }
161 
162 
166 template <class TInputImage,class TOutputImage,class TDeformationField>
167 void
170  const OutputImageRegionType& outputRegionForThread,
171  int threadId )
172 {
173 
174  InputImageConstPointer inputPtr = this->GetInput();
175  OutputImagePointer outputPtr = this->GetOutput();
176  DeformationFieldPointer fieldPtr = this->GetDeformationField();
177 
178  // support progress methods/callbacks
179  ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
180 
181  // iterator for the output image
183  outputPtr, outputRegionForThread );
184 
185  // iterator for the deformation field
187  fieldPtr, outputRegionForThread );
188 
189  IndexType index;
190  PointType point;
191  DisplacementType displacement;
192  PixelType outputValue;
193 
194  while( !outputIt.IsAtEnd() )
195  {
196  // get the output image index
197  index = outputIt.GetIndex();
198  outputPtr->TransformIndexToPhysicalPoint( index, point );
199 
200  // get the required displacement
201  displacement = fieldIt.Get();
202 
203  // compute the required input image point
204  for(unsigned int j = 0; j < ImageDimension; j++ )
205  {
206  point[j] += displacement[j];
207  }
208 
209  // get the interpolated value
210  if( m_Interpolator->IsInsideBuffer( point ) )
211  {
212  typedef typename InterpolatorType::OutputType OutputType;
213  const OutputType interpolatedValue = m_Interpolator->Evaluate( point );
214 
215  for( unsigned int k = 0; k < PixelDimension; k++ )
216  {
217  outputValue[k] = static_cast<ValueType>( interpolatedValue[k] );
218  }
219 
220  outputIt.Set( outputValue );
221  }
222  else
223  {
224  outputIt.Set( m_EdgePaddingValue );
225  }
226  ++outputIt;
227  ++fieldIt;
228  progress.CompletedPixel();
229  }
230 
231 }
232 
233 
234 template <class TInputImage,class TOutputImage,class TDeformationField>
235 void
238 {
239 
240  // call the superclass's implementation
241  Superclass::GenerateInputRequestedRegion();
242 
243  // request the largest possible region for the input image
244  InputImagePointer inputPtr =
245  const_cast< InputImageType * >( this->GetInput() );
246 
247  if( inputPtr )
248  {
249  inputPtr->SetRequestedRegionToLargestPossibleRegion();
250  }
251 
252  // just propagate up the output requested region for the
253  // deformation field.
254  DeformationFieldPointer fieldPtr = this->GetDeformationField();
255  OutputImagePointer outputPtr = this->GetOutput();
256  if( fieldPtr )
257  {
258  fieldPtr->SetRequestedRegion( outputPtr->GetRequestedRegion() );
259  }
260 
261 }
262 
263 
264 template <class TInputImage,class TOutputImage,class TDeformationField>
265 void
268 {
269  // call the superclass's implementation of this method
270  Superclass::GenerateOutputInformation();
271 
272  OutputImagePointer outputPtr = this->GetOutput();
273 
274  outputPtr->SetSpacing( m_OutputSpacing );
275  outputPtr->SetOrigin( m_OutputOrigin );
276  outputPtr->SetDirection( m_OutputDirection );
277 
278  DeformationFieldPointer fieldPtr = this->GetDeformationField();
279  if( fieldPtr )
280  {
281  outputPtr->SetLargestPossibleRegion( fieldPtr->
282  GetLargestPossibleRegion() );
283  }
284 
285 }
286 
287 
288 } // end namespace itk
289 
290 #endif

Generated at Sun Feb 3 2013 00:14:38 for Orfeo Toolbox with doxygen 1.8.1.1