Orfeo Toolbox  4.0
otbStreamingResampleImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbStreamingResampleImageFilter_txx
19 #define __otbStreamingResampleImageFilter_txx
20 
21 #include "itkProgressAccumulator.h"
22 
23 namespace otb
24 {
25 
26 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
29 {
30  // internal filters instanciation
31  m_DisplacementFilter = DisplacementFieldGeneratorType::New();
32  m_WarpFilter = WarpImageFilterType::New();
33 
34  // Initialize the displacement field spacing to zero : inconsistant
35  // value
36  this->SetDisplacementFieldSpacing(itk::NumericTraits<SpacingType>::ZeroValue());
37 
38  // Wire minipipeline
39  m_WarpFilter->SetDisplacementField(m_DisplacementFilter->GetOutput());
40 }
41 
42 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
43 void
46 {
47  // Set up progress reporting
49  progress->SetMiniPipelineFilter(this);
50  progress->RegisterInternalFilter(m_WarpFilter, 1.f);
51 
52  m_WarpFilter->GraftOutput(this->GetOutput());
53  m_WarpFilter->Update();
54  this->GraftOutput(m_WarpFilter->GetOutput());
55 }
56 
60 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
61 void
64 {
65  // call the superclass's implementation of this method
66  Superclass::GenerateOutputInformation();
67 
68  typename OutputImageType::Pointer outputPtr = this->GetOutput();
69 
70  outputPtr->SetSpacing( this->GetOutputSpacing() );
71  outputPtr->SetOrigin( this->GetOutputOrigin() );
72 
73  typename OutputImageType::RegionType region;
74  region.SetSize( this->GetOutputSize() );
75  region.SetIndex(this->GetOutputStartIndex() );
76 
77  outputPtr->SetLargestPossibleRegion(region);
78 
79  // check the output spacing of the displacement field
80  if(this->GetDisplacementFieldSpacing()== itk::NumericTraits<SpacingType>::ZeroValue())
81  {
82  this->SetDisplacementFieldSpacing(2.*this->GetOutputSpacing());
83  }
84 }
85 
86 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
87 void
90 {
91  // Retrieve output pointer
92  OutputImageType * outputPtr = this->GetOutput();
93 
94  // Retrieve input pointer
95  const InputImageType * inputPtr = this->GetInput();
96 
97  // Retrieve output requested region
98  RegionType requestedRegion = outputPtr->GetRequestedRegion();
99  SizeType largestSize = outputPtr->GetLargestPossibleRegion().GetSize();
100 
101  // Set up displacement field filter
102  SizeType displacementFieldLargestSize;
103 
104  for(unsigned int dim = 0; dim < InputImageType::ImageDimension; ++dim)
105  {
106  // vcl_ceil to avoid numerical problems due to division of
107  // spacings
108  // + 1 : We need to enlarge the displacement field size cause
109  // itk::WarpImageFilter::EvaluateDisplacementAtPhysicalPoint needs
110  // 4 neighbors and in the edges we can need 1 neighbor pixel
111  // outside the field
112  displacementFieldLargestSize[dim] = static_cast<unsigned int>(
113  vcl_ceil( largestSize[dim]*
114  vcl_abs(this->GetOutputSpacing()[dim] /
115  this->GetDisplacementFieldSpacing()[dim]))) + 1;
116  }
117  m_DisplacementFilter->SetOutputSize(displacementFieldLargestSize);
118  m_DisplacementFilter->SetOutputIndex(this->GetOutputStartIndex());
119 
120  // Generate input requested region
121  m_WarpFilter->SetInput(inputPtr);
122  m_WarpFilter->GetOutput()->UpdateOutputInformation();
123  m_WarpFilter->GetOutput()->SetRequestedRegion(requestedRegion);
124  m_WarpFilter->GetOutput()->PropagateRequestedRegion();
125 }
126 
131 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
132 void
135 {
136  this->SetOutputOrigin ( image->GetOrigin() );
137  this->SetOutputSpacing ( image->GetSpacing() );
138  this->SetOutputStartIndex ( image->GetLargestPossibleRegion().GetIndex() );
139  this->SetOutputSize ( image->GetLargestPossibleRegion().GetSize() );
140 }
141 
142 
143 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
144 void
146 ::PrintSelf(std::ostream& os, itk::Indent indent) const
147 {
148  Superclass::PrintSelf(os, indent);
149  os << indent << "OutputOrigin: " << this->GetOutputOrigin() << std::endl;
150  os << indent << "OutputSpacing: " << this->GetOutputSpacing() << std::endl;
151  os << indent << "OutputStartIndex: " << this->GetOutputStartIndex() << std::endl;
152  os << indent << "OutputSize: " << this->GetOutputSize() << std::endl;
153 }
154 
155 
156 }
157 #endif

Generated at Sat Apr 12 2014 16:21:18 for Orfeo Toolbox with doxygen 1.8.3.1