Orfeo Toolbox  3.16
itkTransformToDeformationFieldSource.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkTransformToDeformationFieldSource.txx,v $
5  Language: C++
6  Date: $Date: 2009-04-29 23:54:31 $
7  Version: $Revision: 1.3 $
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 /*======================================================================
18 
19 This file is part of the elastix software.
20 
21 Copyright (c) University Medical Center Utrecht. All rights reserved.
22 See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php for
23 details.
24 
25 This software is distributed WITHOUT ANY WARRANTY; without even
26 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
27 PURPOSE. See the above copyright notices for more information.
28 
29 ======================================================================*/
30 #ifndef __itkTransformToDeformationFieldSource_txx
31 #define __itkTransformToDeformationFieldSource_txx
32 
34 
35 #include "itkIdentityTransform.h"
36 #include "itkProgressReporter.h"
39 
40 namespace itk
41 {
45 template <class TOutputImage, class TTransformPrecisionType>
48 {
49  this->m_OutputSpacing.Fill(1.0);
50  this->m_OutputOrigin.Fill(0.0);
51  this->m_OutputDirection.SetIdentity();
52 
53  SizeType size;
54  size.Fill( 0 );
55  this->m_OutputRegion.SetSize( size );
56 
57  IndexType index;
58  index.Fill( 0 );
59  this->m_OutputRegion.SetIndex( index );
60 
61  this->m_Transform
63 } // end Constructor
64 
70 template <class TOutputImage, class TTransformPrecisionType>
71 void
73  ::PrintSelf( std::ostream & os, Indent indent ) const
74 {
75  Superclass::PrintSelf( os, indent );
76 
77  os << indent << "OutputRegion: " << this->m_OutputRegion << std::endl;
78  os << indent << "OutputSpacing: " << this->m_OutputSpacing << std::endl;
79  os << indent << "OutputOrigin: " << this->m_OutputOrigin << std::endl;
80  os << indent << "OutputDirection: " << this->m_OutputDirection << std::endl;
81  os << indent << "Transform: " << this->m_Transform.GetPointer() << std::endl;
82 } // end PrintSelf()
83 
87 template <class TOutputImage, class TTransformPrecisionType>
88 void
90  ::SetOutputSize( const SizeType & size )
91 {
92  this->m_OutputRegion.SetSize( size );
93 }
94 
98 template <class TOutputImage, class TTransformPrecisionType>
99 const typename TransformToDeformationFieldSource<TOutputImage,
100  TTransformPrecisionType>
101  ::SizeType &
104 {
105  return this->m_OutputRegion.GetSize();
106 }
107 
111 template <class TOutputImage, class TTransformPrecisionType>
112 void
114  ::SetOutputIndex( const IndexType & index )
115 {
116  this->m_OutputRegion.SetIndex( index );
117 }
118 
122 template <class TOutputImage, class TTransformPrecisionType>
123 const typename TransformToDeformationFieldSource<TOutputImage,
124  TTransformPrecisionType>
125  ::IndexType &
128 {
129  return this->m_OutputRegion.GetIndex();
130 }
131 
135 template <class TOutputImage, class TTransformPrecisionType>
136 void
138  ::SetOutputSpacing( const double *spacing )
139 {
140  SpacingType s( spacing );
141 
142  this->SetOutputSpacing( s );
143 } // end SetOutputSpacing()
144 
148 template <class TOutputImage, class TTransformPrecisionType>
149 void
151  ::SetOutputOrigin( const double *origin )
152 {
153  OriginType p( origin );
154 
155  this->SetOutputOrigin( p );
156 }
157 
159 template <class TOutputImage, class TTransformPrecisionType>
160 void
163 {
164  if ( !image )
165  {
166  itkExceptionMacro(<< "Cannot use a null image reference");
167  }
168 
169  this->SetOutputOrigin( image->GetOrigin() );
170  this->SetOutputSpacing( image->GetSpacing() );
171  this->SetOutputDirection( image->GetDirection() );
172  this->SetOutputRegion( image->GetLargestPossibleRegion() );
173 } // end SetOutputParametersFromImage()
174 
180 template <class TOutputImage, class TTransformPrecisionType>
181 void
184 {
185  if ( !this->m_Transform )
186  {
187  itkExceptionMacro(<< "Transform not set");
188  }
189 } // end BeforeThreadedGenerateData()
190 
194 template <class TOutputImage, class TTransformPrecisionType>
195 void
198  const OutputImageRegionType & outputRegionForThread,
199  int threadId )
200 {
201  // Check whether we can use a fast path for resampling. Fast path
202  // can be used if the transformation is linear. Transform respond
203  // to the IsLinear() call.
204  if ( this->m_Transform->IsLinear() )
205  {
206  this->LinearThreadedGenerateData( outputRegionForThread, threadId );
207  return;
208  }
209 
210  // Otherwise, we use the normal method where the transform is called
211  // for computing the transformation of every point.
212  this->NonlinearThreadedGenerateData( outputRegionForThread, threadId );
213 } // end ThreadedGenerateData()
214 
215 template <class TOutputImage, class TTransformPrecisionType>
216 void
219  const OutputImageRegionType & outputRegionForThread,
220  int threadId )
221 {
222  // Get the output pointer
223  OutputImagePointer outputPtr = this->GetOutput();
224 
225  // Create an iterator that will walk the output region for this thread.
226  typedef ImageRegionIteratorWithIndex<TOutputImage> OutputIteratorType;
227  OutputIteratorType outIt( outputPtr, outputRegionForThread );
228 
229  // Define a few variables that will be used to translate from an input pixel
230  // to an output pixel
231  PointType outputPoint; // Coordinates of output pixel
232  PointType transformedPoint; // Coordinates of transformed pixel
233  PixelType deformation; // the difference
234 
235  // Support for progress methods/callbacks
236  ProgressReporter progress( this, threadId,
237  outputRegionForThread.GetNumberOfPixels() );
238 
239  // Walk the output region
240  outIt.GoToBegin();
241  while ( !outIt.IsAtEnd() )
242  {
243  // Determine the index of the current output pixel
244  outputPtr->TransformIndexToPhysicalPoint( outIt.GetIndex(), outputPoint );
245 
246  // Compute corresponding input pixel position
247  transformedPoint = this->m_Transform->TransformPoint( outputPoint );
248 
249  // Compute the deformation
250  for ( unsigned int i = 0; i < ImageDimension; ++i )
251  {
252  deformation[i] = static_cast<PixelValueType>(
253  transformedPoint[i] - outputPoint[i] );
254  }
255 
256  // Set it
257  outIt.Set( deformation );
258 
259  // Update progress and iterator
260  progress.CompletedPixel();
261  ++outIt;
262  }
263 } // end NonlinearThreadedGenerateData()
264 
265 template <class TOutputImage, class TTransformPrecisionType>
266 void
269  const OutputImageRegionType & outputRegionForThread,
270  int threadId )
271 {
272  // Get the output pointer
273  OutputImagePointer outputPtr = this->GetOutput();
274 
275  // Create an iterator that will walk the output region for this thread.
276  typedef ImageLinearIteratorWithIndex<TOutputImage> OutputIteratorType;
277  OutputIteratorType outIt( outputPtr, outputRegionForThread );
278 
279  outIt.SetDirection( 0 );
280 
281  // Define a few indices that will be used to translate from an input pixel
282  // to an output pixel
283  PointType outputPoint; // Coordinates of current output pixel
284  PointType transformedPoint; // Coordinates of transformed pixel
285  PixelType deformation; // the difference
286 
287  IndexType index;
288 
289  // Support for progress methods/callbacks
290  ProgressReporter progress( this, threadId,
291  outputRegionForThread.GetNumberOfPixels() );
292 
293  // Determine the position of the first pixel in the scanline
294  outIt.GoToBegin();
295  index = outIt.GetIndex();
296  outputPtr->TransformIndexToPhysicalPoint( index, outputPoint );
297 
298  // Compute corresponding transformed pixel position
299  transformedPoint = this->m_Transform->TransformPoint( outputPoint );
300 
301  // Compare with the ResampleImageFilter
302 
303  // Compute delta
304  PointType outputPointNeighbour;
305  PointType transformedPointNeighbour;
306  typedef typename PointType::VectorType VectorType;
307  VectorType delta;
308  ++index[0];
309  outputPtr->TransformIndexToPhysicalPoint( index, outputPointNeighbour );
310  transformedPointNeighbour = this->m_Transform->TransformPoint(
311  outputPointNeighbour );
312  delta = transformedPointNeighbour - transformedPoint
313  - ( outputPointNeighbour - outputPoint );
314 
315  // loop over the vector image
316  while ( !outIt.IsAtEnd() )
317  {
318  // Get current point
319  index = outIt.GetIndex();
320  outputPtr->TransformIndexToPhysicalPoint( index, outputPoint );
321 
322  // Compute transformed point
323  transformedPoint = this->m_Transform->TransformPoint( outputPoint );
324 
325  while ( !outIt.IsAtEndOfLine() )
326  {
327  // Compute the deformation
328  for ( unsigned int i = 0; i < ImageDimension; ++i )
329  {
330  deformation[i] = static_cast<PixelValueType>(
331  transformedPoint[i] - outputPoint[i] );
332  }
333 
334  // Set it
335  outIt.Set( deformation );
336 
337  // Update stuff
338  progress.CompletedPixel();
339  ++outIt;
340  transformedPoint += delta;
341  }
342 
343  outIt.NextLine();
344  }
345 } // end LinearThreadedGenerateData()
346 
350 template <class TOutputImage, class TTransformPrecisionType>
351 void
354 {
355  // call the superclass' implementation of this method
356  Superclass::GenerateOutputInformation();
357 
358  // get pointer to the output
359  OutputImagePointer outputPtr = this->GetOutput();
360  if ( !outputPtr )
361  {
362  return;
363  }
364 
365  outputPtr->SetLargestPossibleRegion( m_OutputRegion );
366 
367  outputPtr->SetSpacing( m_OutputSpacing );
368  outputPtr->SetOrigin( m_OutputOrigin );
369  outputPtr->SetDirection( m_OutputDirection );
370 } // end GenerateOutputInformation()
371 
375 template <class TOutputImage, class TTransformPrecisionType>
376 unsigned long
378  ::GetMTime( void ) const
379 {
380  unsigned long latestTime = Object::GetMTime();
381 
382  if ( this->m_Transform )
383  {
384  if ( latestTime < this->m_Transform->GetMTime() )
385  {
386  latestTime = this->m_Transform->GetMTime();
387  }
388  }
389 
390  return latestTime;
391 } // end GetMTime()
392 } // end namespace itk
393 
394 #endif // end #ifndef _itkTransformToDeformationFieldSource_txx

Generated at Sun May 19 2013 00:10:50 for Orfeo Toolbox with doxygen 1.8.3.1