Orfeo Toolbox  3.16
itkDeformationFieldSource.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkDeformationFieldSource.txx,v $
5  Language: C++
6  Date: $Date: 2009-11-21 21:21:56 $
7  Version: $Revision: 1.8 $
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 #ifndef __itkDeformationFieldSource_txx
20 #define __itkDeformationFieldSource_txx
21 
23 #include "itkProgressReporter.h"
26 
27 namespace itk
28 {
29 
33 template <class TOutputImage>
36 {
37  m_OutputSpacing.Fill(1.0);
38  m_OutputOrigin.Fill(0.0);
39  m_OutputDirection.SetIdentity();
40 
42  double,
43  itkGetStaticConstMacro( ImageDimension ) > DefaultTransformType;
44 
45  m_KernelTransform = DefaultTransformType::New();
46 
47 }
48 
49 
55 template <class TOutputImage>
56 void
58 ::PrintSelf(std::ostream& os, Indent indent) const
59 {
60  Superclass::PrintSelf(os,indent);
61 
62  os << indent << "OutputRegion: " << m_OutputRegion << std::endl;
63  os << indent << "OutputSpacing: " << m_OutputSpacing << std::endl;
64  os << indent << "OutputOrigin: " << m_OutputOrigin << std::endl;
65  os << indent << "OutputDirection: " << m_OutputDirection << std::endl;
66  os << indent << "KernelTransform: " << m_KernelTransform.GetPointer() << std::endl;
67  os << indent << "Source Landmarks: " << m_SourceLandmarks.GetPointer() << std::endl;
68  os << indent << "Target Landmarks: " << m_TargetLandmarks.GetPointer() << std::endl;
69 
70  return;
71 }
72 
76 template <class TOutputImage>
77 void
80  const double* spacing)
81 {
82  SpacingType s(spacing);
83  this->SetOutputSpacing( s );
84 }
85 
89 template <class TOutputImage>
90 void
93  const double* origin)
94 {
95  OriginPointType p(origin);
96  this->SetOutputOrigin( p );
97 }
98 
103 template <class TOutputImage>
104 void
107 {
108 
109 
110  // Shameful violation of const-correctness due to the
111  // lack of constness in the PointSet. That is, the point
112  // set is actually allowed to modify its points containers.
113 
114  LandmarkContainer * sources =
115  const_cast< LandmarkContainer * >(
116  m_SourceLandmarks.GetPointer() );
117 
118  LandmarkContainer * targets =
119  const_cast< LandmarkContainer * >(
120  m_TargetLandmarks.GetPointer() );
121 
122  m_KernelTransform->GetTargetLandmarks()->SetPoints( targets );
123  m_KernelTransform->GetSourceLandmarks()->SetPoints( sources );
124 
125  itkDebugMacro( << "Before ComputeWMatrix() ");
126 
127  m_KernelTransform->ComputeWMatrix();
128 
129  itkDebugMacro( << "After ComputeWMatrix() ");
130 
131 }
132 
136 template <class TOutputImage>
137 void
140 {
141 
142  // First subsample the input deformation field in order to create
143  // the KernelBased spline.
144  this->PrepareKernelBaseSpline();
145 
146  itkDebugMacro(<<"Actually executing");
147 
148  // Get the output pointers
149  OutputImageType * outputPtr = this->GetOutput();
150 
151  outputPtr->SetBufferedRegion( outputPtr->GetRequestedRegion() );
152  outputPtr->Allocate();
153 
154  // Create an iterator that will walk the output region for this thread.
156  TOutputImage> OutputIterator;
157 
158  OutputImageRegionType region = outputPtr->GetRequestedRegion();
159 
160  OutputIterator outIt( outputPtr, region );
161 
162  // Define a few indices that will be used to translate from an input pixel
163  // to an output pixel
164  OutputIndexType outputIndex; // Index to current output pixel
165 
166  typedef typename KernelTransformType::InputPointType InputPointType;
167  typedef typename KernelTransformType::OutputPointType OutputPointType;
168 
169  InputPointType outputPoint; // Coordinates of current output pixel
170 
171  // Support for progress methods/callbacks
172  ProgressReporter progress(this, 0, region.GetNumberOfPixels(), 10);
173 
174  outIt.GoToBegin();
175 
176  // Walk the output region
177  while ( !outIt.IsAtEnd() )
178  {
179  // Determine the index of the current output pixel
180  outputIndex = outIt.GetIndex();
181  outputPtr->TransformIndexToPhysicalPoint( outputIndex, outputPoint );
182 
183 
184  // Compute corresponding inverse displacement vector
185  OutputPointType interpolatedDeformation =
186  m_KernelTransform->TransformPoint( outputPoint );
187 
188  OutputPixelType displacement;
189  for( unsigned int i=0; i < ImageDimension; i++)
190  {
191  displacement[i] = interpolatedDeformation[i] - outputPoint[i];
192  }
193 
194  outIt.Set( displacement );
195  ++outIt;
196  progress.CompletedPixel();
197  }
198 
199  return;
200 }
201 
205 template <class TOutputImage>
206 void
209 {
210  // call the superclass' implementation of this method
211  Superclass::GenerateOutputInformation();
212 
213  // get pointers to the input and output
214  OutputImagePointer outputPtr = this->GetOutput();
215  if ( !outputPtr )
216  {
217  return;
218  }
219 
220  // Set the size of the output region
221  outputPtr->SetLargestPossibleRegion( m_OutputRegion );
222 
223  // Set spacing and origin
224  outputPtr->SetSpacing( m_OutputSpacing );
225  outputPtr->SetOrigin( m_OutputOrigin );
226  outputPtr->SetDirection( m_OutputDirection );
227 
228  return;
229 }
230 
234 template <class TOutputImage>
235 unsigned long
237 ::GetMTime( void ) const
238 {
239  unsigned long latestTime = Object::GetMTime();
240 
241  if( m_KernelTransform )
242  {
243  if( latestTime < m_KernelTransform->GetMTime() )
244  {
245  latestTime = m_KernelTransform->GetMTime();
246  }
247  }
248 
249  if( m_SourceLandmarks )
250  {
251  if( latestTime < m_SourceLandmarks->GetMTime() )
252  {
253  latestTime = m_SourceLandmarks->GetMTime();
254  }
255  }
256 
257 
258  if( m_TargetLandmarks )
259  {
260  if( latestTime < m_TargetLandmarks->GetMTime() )
261  {
262  latestTime = m_TargetLandmarks->GetMTime();
263  }
264  }
265  return latestTime;
266 }
267 
268 } // end namespace itk
269 
270 #endif

Generated at Sat Feb 2 2013 23:34:48 for Orfeo Toolbox with doxygen 1.8.1.1