OTB  5.9.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 
22 #include "itkProgressAccumulator.h"
23 
24 namespace otb
25 {
26 
27 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
30 {
31  // internal filters instantiation
32  m_DisplacementFilter = DisplacementFieldGeneratorType::New();
33  m_WarpFilter = WarpImageFilterType::New();
34 
35  // Initialize the displacement field spacing to zero : inconsistent
36  // value
37  this->SetDisplacementFieldSpacing(itk::NumericTraits<SpacingType>::ZeroValue());
38 
39  // Wire minipipeline
40  m_WarpFilter->SetDisplacementField(m_DisplacementFilter->GetOutput());
41 }
42 
43 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
44 void
47 {
48  // Set up progress reporting
50  progress->SetMiniPipelineFilter(this);
51  progress->RegisterInternalFilter(m_WarpFilter, 1.f);
52 
53  m_WarpFilter->GraftOutput(this->GetOutput());
54  m_WarpFilter->UpdateOutputData(m_WarpFilter->GetOutput());
55  this->GraftOutput(m_WarpFilter->GetOutput());
56 }
57 
61 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
62 void
65 {
66  // check the output spacing of the displacement field
67  if(this->GetDisplacementFieldSpacing()== itk::NumericTraits<SpacingType>::ZeroValue())
68  {
69  this->SetDisplacementFieldSpacing(2.*this->GetOutputSpacing());
70  }
71 
72  // Retrieve output largest region
73  SizeType largestSize = this->GetOutputSize();
74 
75  // Set up displacement field filter
76  SizeType displacementFieldLargestSize;
77 
78  for(unsigned int dim = 0; dim < InputImageType::ImageDimension; ++dim)
79  {
80  // vcl_ceil to avoid numerical problems due to division of
81  // spacings
82  // + 1 : We need to enlarge the displacement field size cause
83  // itk::WarpImageFilter::EvaluateDisplacementAtPhysicalPoint needs
84  // 4 neighbors and in the edges we can need 1 neighbor pixel
85  // outside the field
86  displacementFieldLargestSize[dim] = static_cast<unsigned int>(
87  vcl_ceil( largestSize[dim]*
88  vcl_abs(this->GetOutputSpacing()[dim] /
89  this->GetDisplacementFieldSpacing()[dim]))) + 1;
90  }
91  m_DisplacementFilter->SetOutputSize(displacementFieldLargestSize);
92  m_DisplacementFilter->SetOutputIndex(this->GetOutputStartIndex());
93 
94  m_WarpFilter->SetInput(this->GetInput());
95  m_WarpFilter->GraftOutput(this->GetOutput());
96  m_WarpFilter->UpdateOutputInformation();
97  this->GraftOutput(m_WarpFilter->GetOutput());
98 }
99 
100 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
101 void
104 {
105  if (this->m_Updating) return;
106 
107  m_WarpFilter->GetOutput()->SetRequestedRegion(output);
108  m_WarpFilter->GetOutput()->PropagateRequestedRegion();
109 }
110 
115 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
116 void
119 {
120  this->SetOutputOrigin ( image->GetOrigin() );
121  this->SetOutputSpacing ( image->GetSpacing() );
122  this->SetOutputStartIndex ( image->GetLargestPossibleRegion().GetIndex() );
123  this->SetOutputSize ( image->GetLargestPossibleRegion().GetSize() );
124 }
126 
127 
128 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
129 void
131 ::PrintSelf(std::ostream& os, itk::Indent indent) const
132 {
133  Superclass::PrintSelf(os, indent);
134  os << indent << "OutputOrigin: " << this->GetOutputOrigin() << std::endl;
135  os << indent << "OutputSpacing: " << this->GetOutputSpacing() << std::endl;
136  os << indent << "OutputStartIndex: " << this->GetOutputStartIndex() << std::endl;
137  os << indent << "OutputSize: " << this->GetOutputSize() << std::endl;
138 }
139 
140 
141 }
142 #endif
void SetOutputParametersFromImage(const ImageBaseType *image)
const IndexType & GetIndex() const
virtual const RegionType & GetLargestPossibleRegion() const
static Pointer New()
virtual const SpacingType & GetSpacing() const
void PropagateRequestedRegion(itk::DataObject *output) ITK_OVERRIDE
const SizeType & GetSize() const
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
DisplacementFieldGeneratorType::SizeType SizeType
virtual const PointType & GetOrigin() const