OTB  5.5.0
Orfeo Toolbox
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->UpdateOutputData(m_WarpFilter->GetOutput());
54  this->GraftOutput(m_WarpFilter->GetOutput());
55 }
56 
60 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
61 void
64 {
65  // check the output spacing of the displacement field
66  if(this->GetDisplacementFieldSpacing()== itk::NumericTraits<SpacingType>::ZeroValue())
67  {
68  this->SetDisplacementFieldSpacing(2.*this->GetOutputSpacing());
69  }
70 
71  // Retrieve output largest region
72  SizeType largestSize = this->GetOutputSize();
73 
74  // Set up displacement field filter
75  SizeType displacementFieldLargestSize;
76 
77  for(unsigned int dim = 0; dim < InputImageType::ImageDimension; ++dim)
78  {
79  // vcl_ceil to avoid numerical problems due to division of
80  // spacings
81  // + 1 : We need to enlarge the displacement field size cause
82  // itk::WarpImageFilter::EvaluateDisplacementAtPhysicalPoint needs
83  // 4 neighbors and in the edges we can need 1 neighbor pixel
84  // outside the field
85  displacementFieldLargestSize[dim] = static_cast<unsigned int>(
86  vcl_ceil( largestSize[dim]*
87  vcl_abs(this->GetOutputSpacing()[dim] /
88  this->GetDisplacementFieldSpacing()[dim]))) + 1;
89  }
90  m_DisplacementFilter->SetOutputSize(displacementFieldLargestSize);
91  m_DisplacementFilter->SetOutputIndex(this->GetOutputStartIndex());
92 
93  m_WarpFilter->SetInput(this->GetInput());
94  m_WarpFilter->GraftOutput(this->GetOutput());
95  m_WarpFilter->UpdateOutputInformation();
96  this->GraftOutput(m_WarpFilter->GetOutput());
97 }
98 
99 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
100 void
103 {
104  if (this->m_Updating) return;
105 
106  m_WarpFilter->GetOutput()->SetRequestedRegion(output);
107  m_WarpFilter->GetOutput()->PropagateRequestedRegion();
108 }
109 
114 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
115 void
118 {
119  this->SetOutputOrigin ( image->GetOrigin() );
120  this->SetOutputSpacing ( image->GetSpacing() );
121  this->SetOutputStartIndex ( image->GetLargestPossibleRegion().GetIndex() );
122  this->SetOutputSize ( image->GetLargestPossibleRegion().GetSize() );
123 }
125 
126 
127 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
128 void
130 ::PrintSelf(std::ostream& os, itk::Indent indent) const
131 {
132  Superclass::PrintSelf(os, indent);
133  os << indent << "OutputOrigin: " << this->GetOutputOrigin() << std::endl;
134  os << indent << "OutputSpacing: " << this->GetOutputSpacing() << std::endl;
135  os << indent << "OutputStartIndex: " << this->GetOutputStartIndex() << std::endl;
136  os << indent << "OutputSize: " << this->GetOutputSize() << std::endl;
137 }
138 
139 
140 }
141 #endif
void SetOutputParametersFromImage(const ImageBaseType *image)
virtual void PropagateRequestedRegion(itk::DataObject *output)
const IndexType & GetIndex() const
virtual const RegionType & GetLargestPossibleRegion() const
static Pointer New()
virtual const SpacingType & GetSpacing() const
const SizeType & GetSize() const
DisplacementFieldGeneratorType::SizeType SizeType
void PrintSelf(std::ostream &os, itk::Indent indent) const
virtual const PointType & GetOrigin() const