Orfeo Toolbox  3.16
itkVectorResampleImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkVectorResampleImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-17 20:50:03 $
7  Version: $Revision: 1.18 $
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 __itkVectorResampleImageFilter_txx
18 #define __itkVectorResampleImageFilter_txx
19 
21 #include "itkObjectFactory.h"
22 #include "itkIdentityTransform.h"
24 #include "itkProgressReporter.h"
26 
27 namespace itk
28 {
29 
33 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
36 {
37  m_OutputSpacing.Fill(1.0);
38  m_OutputOrigin.Fill(0.0);
39  m_OutputDirection.SetIdentity();
40  m_Size.Fill( 0 );
41  m_OutputStartIndex.Fill( 0 );
42 
45  m_DefaultPixelValue.Fill(0);
46 
47 // Borland does not produce reliable results for nulti processors
48 #ifdef __BORLANDC__
49  this->SetNumberOfThreads(1);
50 #endif
51 }
52 
53 
59 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
60 void
62 ::PrintSelf(std::ostream& os, Indent indent) const
63 {
64  Superclass::PrintSelf(os,indent);
65 
66  os << indent << "DefaultPixelValue: "
67  << static_cast<typename NumericTraits<PixelType>::PrintType>(m_DefaultPixelValue)
68  << std::endl;
69  os << indent << "Size: " << m_Size << std::endl;
70  os << indent << "OutputStartIndex: " << m_OutputStartIndex << std::endl;
71  os << indent << "OutputSpacing: " << m_OutputSpacing << std::endl;
72  os << indent << "OutputOrigin: " << m_OutputOrigin << std::endl;
73  os << indent << "OutputDirection: " << m_OutputDirection << std::endl;
74  os << indent << "Transform: " << m_Transform.GetPointer() << std::endl;
75  os << indent << "Interpolator: " << m_Interpolator.GetPointer() << std::endl;
76 
77  return;
78 }
79 
83 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
84 void
86 ::SetOutputSpacing(const double* spacing)
87 {
88  SpacingType s(spacing);
89  this->SetOutputSpacing( s );
90 }
91 
95 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
96 void
98 ::SetOutputOrigin(const double* origin)
99 {
100  PointType p(origin);
101  this->SetOutputOrigin( p );
102 }
103 
109 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
110 void
113 {
114 
115  if( !m_Interpolator )
116  {
117  itkExceptionMacro(<< "Interpolator not set");
118  }
119 
120  // Connect input image to interpolator
121  m_Interpolator->SetInputImage( this->GetInput() );
122 
123 }
124 
128 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
129 void
132 {
133  // Disconnect input image from the interpolator
134  m_Interpolator->SetInputImage( NULL );
135 
136 }
137 
141 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
142 void
145  const OutputImageRegionType& outputRegionForThread,
146  int threadId)
147 {
148  itkDebugMacro(<<"Actually executing");
149 
150  // Get the output pointers
151  OutputImagePointer outputPtr = this->GetOutput();
152 
153  // Get ths input pointers
154  InputImageConstPointer inputPtr=this->GetInput();
155 
156  // Create an iterator that will walk the output region for this thread.
157  typedef ImageRegionIteratorWithIndex<TOutputImage> OutputIterator;
158 
159  OutputIterator outIt(outputPtr, outputRegionForThread);
160 
161  // Define a few indices that will be used to translate from an input pixel
162  // to an output pixel
163  PointType outputPoint; // Coordinates of current output pixel
164  PointType inputPoint; // Coordinates of current input pixel
165 
167  ContinuousIndexType inputIndex;
168 
169  const unsigned int numberOfComponents = PixelType::GetNumberOfComponents();
170 
171  // Support for progress methods/callbacks
172  ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
173 
174  typedef typename InterpolatorType::OutputType OutputType;
175 
176  // Walk the output region
177  outIt.GoToBegin();
178 
179  while ( !outIt.IsAtEnd() )
180  {
181  // Determine the index of the current output pixel
182  outputPtr->TransformIndexToPhysicalPoint( outIt.GetIndex(), outputPoint );
183 
184  // Compute corresponding input pixel position
185  inputPoint = m_Transform->TransformPoint(outputPoint);
186  inputPtr->TransformPhysicalPointToContinuousIndex(inputPoint, inputIndex);
187 
188  // Evaluate input at right position and copy to the output
189  if( m_Interpolator->IsInsideBuffer(inputIndex) )
190  {
191  PixelType pixval;
192  const OutputType value
193  = m_Interpolator->EvaluateAtContinuousIndex( inputIndex );
194  for( unsigned int i=0; i< numberOfComponents; i++ )
195  {
196  pixval[i] = static_cast<PixelComponentType>( value[i] );
197  }
198  outIt.Set( pixval );
199  }
200  else
201  {
202  outIt.Set(m_DefaultPixelValue); // default background value
203  }
204 
205  progress.CompletedPixel();
206  ++outIt;
207  }
208  return;
209 }
210 
218 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
219 void
222 {
223  // call the superclass's implementation of this method
224  Superclass::GenerateInputRequestedRegion();
225 
226  if ( !this->GetInput() )
227  {
228  return;
229  }
230 
231  // get pointers to the input and output
232  InputImagePointer inputPtr =
233  const_cast< TInputImage *>( this->GetInput() );
234 
235  // Request the entire input image
236  InputImageRegionType inputRegion;
237  inputRegion = inputPtr->GetLargestPossibleRegion();
238  inputPtr->SetRequestedRegion(inputRegion);
239 
240  return;
241 }
242 
246 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
247 void
250 {
251  // call the superclass' implementation of this method
252  Superclass::GenerateOutputInformation();
253 
254  // get pointers to the input and output
255  OutputImagePointer outputPtr = this->GetOutput();
256  if ( !outputPtr )
257  {
258  return;
259  }
260 
261  // Set the size of the output region
262  typename TOutputImage::RegionType outputLargestPossibleRegion;
263  outputLargestPossibleRegion.SetSize( m_Size );
264  outputLargestPossibleRegion.SetIndex( m_OutputStartIndex );
265  outputPtr->SetLargestPossibleRegion( outputLargestPossibleRegion );
266 
267  // Set spacing and origin
268  outputPtr->SetSpacing( m_OutputSpacing );
269  outputPtr->SetOrigin( m_OutputOrigin );
270  outputPtr->SetDirection( m_OutputDirection );
271 
272  return;
273 }
274 
278 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
279 unsigned long
281 ::GetMTime( void ) const
282 {
283  unsigned long latestTime = Object::GetMTime();
284 
285  if( m_Transform )
286  {
287  if( latestTime < m_Transform->GetMTime() )
288  {
289  latestTime = m_Transform->GetMTime();
290  }
291  }
292 
293  if( m_Interpolator )
294  {
295  if( latestTime < m_Interpolator->GetMTime() )
296  {
297  latestTime = m_Interpolator->GetMTime();
298  }
299  }
300 
301  return latestTime;
302 }
303 
304 } // end namespace itk
305 
306 #endif

Generated at Sun May 19 2013 00:13:11 for Orfeo Toolbox with doxygen 1.8.3.1