OTB  5.11.0
Orfeo Toolbox
otbStreamingResampleImageFilter.txx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbStreamingResampleImageFilter_txx
22 #define otbStreamingResampleImageFilter_txx
23 
25 #include "itkProgressAccumulator.h"
26 
27 namespace otb
28 {
29 
30 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
33 {
34  // internal filters instantiation
35  m_DisplacementFilter = DisplacementFieldGeneratorType::New();
36  m_WarpFilter = WarpImageFilterType::New();
37 
38  // Initialize the displacement field spacing to zero : inconsistent
39  // value
40  this->SetDisplacementFieldSpacing(itk::NumericTraits<SpacingType>::ZeroValue());
41 
42  // Wire minipipeline
43  m_WarpFilter->SetDisplacementField(m_DisplacementFilter->GetOutput());
44 }
45 
46 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
47 void
50 {
51  // Set up progress reporting
53  progress->SetMiniPipelineFilter(this);
54  progress->RegisterInternalFilter(m_WarpFilter, 1.f);
55 
56  m_WarpFilter->GraftOutput(this->GetOutput());
57  m_WarpFilter->UpdateOutputData(m_WarpFilter->GetOutput());
58  this->GraftOutput(m_WarpFilter->GetOutput());
59 }
60 
64 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
65 void
68 {
69  // check the output spacing of the displacement field
70  if(this->GetDisplacementFieldSpacing()== itk::NumericTraits<SpacingType>::ZeroValue())
71  {
72  this->SetDisplacementFieldSpacing(2.*this->GetOutputSpacing());
73  }
74 
75  // Retrieve output largest region
76  SizeType largestSize = this->GetOutputSize();
77 
78  // Set up displacement field filter
79  SizeType displacementFieldLargestSize;
80 
81  for(unsigned int dim = 0; dim < InputImageType::ImageDimension; ++dim)
82  {
83  // vcl_ceil to avoid numerical problems due to division of
84  // spacings
85  // + 1 : We need to enlarge the displacement field size cause
86  // itk::WarpImageFilter::EvaluateDisplacementAtPhysicalPoint needs
87  // 4 neighbors and in the edges we can need 1 neighbor pixel
88  // outside the field
89  displacementFieldLargestSize[dim] = static_cast<unsigned int>(
90  vcl_ceil( largestSize[dim]*
91  vcl_abs(this->GetOutputSpacing()[dim] /
92  this->GetDisplacementFieldSpacing()[dim]))) + 1;
93  }
94  m_DisplacementFilter->SetOutputSize(displacementFieldLargestSize);
95  m_DisplacementFilter->SetOutputIndex(this->GetOutputStartIndex());
96 
97  m_WarpFilter->SetInput(this->GetInput());
98  m_WarpFilter->GraftOutput(this->GetOutput());
99  m_WarpFilter->UpdateOutputInformation();
100  this->GraftOutput(m_WarpFilter->GetOutput());
101 }
102 
103 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
104 void
107 {
108  if (this->m_Updating) return;
109 
110  m_WarpFilter->GetOutput()->SetRequestedRegion(output);
111  m_WarpFilter->GetOutput()->PropagateRequestedRegion();
112 }
113 
118 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
119 void
122 {
123  this->SetOutputOrigin ( image->GetOrigin() );
124  this->SetOutputSpacing ( image->GetSpacing() );
125  this->SetOutputStartIndex ( image->GetLargestPossibleRegion().GetIndex() );
126  this->SetOutputSize ( image->GetLargestPossibleRegion().GetSize() );
127 }
129 
130 
131 template <class TInputImage, class TOutputImage, class TInterpolatorPrecisionType>
132 void
134 ::PrintSelf(std::ostream& os, itk::Indent indent) const
135 {
136  Superclass::PrintSelf(os, indent);
137  os << indent << "OutputOrigin: " << this->GetOutputOrigin() << std::endl;
138  os << indent << "OutputSpacing: " << this->GetOutputSpacing() << std::endl;
139  os << indent << "OutputStartIndex: " << this->GetOutputStartIndex() << std::endl;
140  os << indent << "OutputSize: " << this->GetOutputSize() << std::endl;
141 }
142 
143 
144 }
145 #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