Orfeo Toolbox  3.16
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 "otbImageFileWriter.h"
22 
23 #include "itkProgressAccumulator.h"
24 
25 namespace otb
26 {
27 
28 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
31 {
32  // internal filters instanciation
33  m_DeformationFilter = DeformationFieldGeneratorType::New();
34  m_WarpFilter = WarpImageFilterType::New();
35 
36  // Initialize the deformation field spacing to zero : inconsistant
37  // value
38  this->SetDeformationFieldSpacing(itk::NumericTraits<SpacingType>::Zero);
39 
40  // Wire minipipeline
41  m_WarpFilter->SetDeformationField(m_DeformationFilter->GetOutput());
42 }
43 
44 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
45 void
48 {
49  // Set up progress reporting
51  progress->SetMiniPipelineFilter(this);
52  progress->RegisterInternalFilter(m_WarpFilter, 1.f);
53 
54  m_WarpFilter->GraftOutput(this->GetOutput());
55  m_WarpFilter->Update();
56  this->GraftOutput(m_WarpFilter->GetOutput());
57 }
58 
62 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
63 void
66 {
67  // call the superclass's implementation of this method
68  Superclass::GenerateOutputInformation();
69 
70  typename OutputImageType::Pointer outputPtr = this->GetOutput();
71 
72  outputPtr->SetSpacing( this->GetOutputSpacing() );
73  outputPtr->SetOrigin( this->GetOutputOrigin() );
74 
75  typename OutputImageType::RegionType region;
76  region.SetSize( this->GetOutputSize() );
77  region.SetIndex(this->GetOutputStartIndex() );
78 
79  outputPtr->SetLargestPossibleRegion(region);
80 
81  // check the output spacing of the deformation field
82  if(this->GetDeformationFieldSpacing()== itk::NumericTraits<SpacingType>::Zero)
83  {
84  this->SetDeformationFieldSpacing(2.*this->GetOutputSpacing());
85  }
86 }
87 
88 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
89 void
92 {
93  // Retrieve output pointer
94  OutputImageType * outputPtr = this->GetOutput();
95 
96  // Retrieve input pointer
97  const InputImageType * inputPtr = this->GetInput();
98 
99  // Retrieve output requested region
100  RegionType requestedRegion = outputPtr->GetRequestedRegion();
101  SizeType largestSize = outputPtr->GetLargestPossibleRegion().GetSize();
102 
103  // Set up deformation field filter
104  SizeType deformationFieldLargestSize;
105 
106  for(unsigned int dim = 0; dim < InputImageType::ImageDimension; ++dim)
107  {
108  // vcl_ceil to avoid numerical problems due to division of
109  // spacings
110  // + 1 : We need to enlarge the deformation field size cause
111  // itk::WarpImageFilter::EvaluateDeformationAtPhysicalPoint needs
112  // 4 neighbors and in the edges we can need 1 neighbor pixel
113  // outside the field
114  deformationFieldLargestSize[dim] = static_cast<unsigned int>(
115  vcl_ceil( largestSize[dim]*
116  vcl_abs(this->GetOutputSpacing()[dim] /
117  this->GetDeformationFieldSpacing()[dim]))) + 1;
118  }
119  m_DeformationFilter->SetOutputSize(deformationFieldLargestSize);
120  m_DeformationFilter->SetOutputIndex(this->GetOutputStartIndex());
121 
122  // Generate input requested region
123  m_WarpFilter->SetInput(inputPtr);
124  m_WarpFilter->GetOutput()->UpdateOutputInformation();
125  m_WarpFilter->GetOutput()->SetRequestedRegion(requestedRegion);
126  m_WarpFilter->GetOutput()->PropagateRequestedRegion();
127 }
128 
133 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
134 void
137 {
138  this->SetOutputOrigin ( image->GetOrigin() );
139  this->SetOutputSpacing ( image->GetSpacing() );
140  this->SetOutputStartIndex ( image->GetLargestPossibleRegion().GetIndex() );
141  this->SetOutputSize ( image->GetLargestPossibleRegion().GetSize() );
142 }
143 
144 
145 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
146 void
148 ::PrintSelf(std::ostream& os, itk::Indent indent) const
149 {
150  Superclass::PrintSelf(os, indent);
151  os << indent << "OutputOrigin: " << this->GetOutputOrigin() << std::endl;
152  os << indent << "OutputSpacing: " << this->GetOutputSpacing() << std::endl;
153  os << indent << "OutputStartIndex: " << this->GetOutputStartIndex() << std::endl;
154  os << indent << "OutputSize: " << this->GetOutputSize() << std::endl;
155 }
156 
157 
158 }
159 #endif

Generated at Sun May 26 2013 00:51:48 for Orfeo Toolbox with doxygen 1.8.3.1