Orfeo Toolbox  4.0
otbSimpleRcsPanSharpeningFusionImageFilter.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  Some parts of this code are derived from ITK. See ITKCopyright.txt
13  for details.
14 
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notices for more information.
19 
20 =========================================================================*/
21 #ifndef __otbSimpleRcsPanSharpeningFusionImageFilter_txx
22 #define __otbSimpleRcsPanSharpeningFusionImageFilter_txx
23 
25 
26 namespace otb
27 {
28 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
29 SimpleRcsPanSharpeningFusionImageFilter
30 <TPanImageType, TXsImageType, TOutputImageType, TInternalPrecision>
32 {
33  // Fix number of required inputs
34  this->SetNumberOfRequiredInputs(2);
35 
36  // Instantiate convolution filter
37  m_ConvolutionFilter = ConvolutionFilterType::New();
38  m_ConvolutionFilter->NormalizeFilterOn();
39 
40  // Set-up default parameters
41  m_Radius.Fill(3);
42  m_Filter.SetSize(7 * 7);
43  m_Filter.Fill(1);
44 
45  // Instantiate fusion filter
46  m_FusionFilter = FusionFilterType::New();
47  m_FusionFilter->SetInput2(m_ConvolutionFilter->GetOutput());
48 
49  // Set-up progress reporting
50  m_ProgressAccumulator = itk::ProgressAccumulator::New();
51  m_ProgressAccumulator->SetMiniPipelineFilter(this);
52  m_ProgressAccumulator->RegisterInternalFilter(m_ConvolutionFilter, 0.9);
53  m_ProgressAccumulator->RegisterInternalFilter(m_FusionFilter, 0.1);
54 }
55 
56 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
57 void
59 <TPanImageType, TXsImageType, TOutputImageType, TInternalPrecision>
60 ::SetPanInput(const TPanImageType *image)
61 {
62  // We have 2 inputs: an image and a vector image
63 
64  // Process object is not const-correct so the const_cast is required here
66  const_cast<TPanImageType*>(image));
67  this->Modified();
68 }
69 
70 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
71 const TPanImageType *
73 <TPanImageType, TXsImageType, TOutputImageType, TInternalPrecision>
74 ::GetPanInput(void) const
75 {
76  if (this->GetNumberOfInputs() < 2)
77  {
78  return 0;
79  }
80 
81  return static_cast<const TPanImageType *>
83 }
84 
85 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
86 void
88 <TPanImageType, TXsImageType, TOutputImageType, TInternalPrecision>
89 ::SetXsInput(const TXsImageType *image)
90 {
91  // We have 2 inputs: an image and a vector image
92 
93  // Process object is not const-correct so the const_cast is required here
95  const_cast<TXsImageType*>(image));
96  this->Modified();
97 }
98 
99 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
100 const TXsImageType *
102 <TPanImageType, TXsImageType, TOutputImageType, TInternalPrecision>
103 ::GetXsInput(void) const
104 {
105  if (this->GetNumberOfInputs() < 1)
106  {
107  return 0;
108  }
109 
110  return static_cast<const TXsImageType *>
111  (this->itk::ProcessObject::GetInput(0));
112 }
113 
114 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
115 void
117 <TPanImageType, TXsImageType, TOutputImageType, TInternalPrecision>
118 ::GenerateData()
119 {
120  //Check if size is correct
121  typename TPanImageType::SizeType sizePan;
122  typename TXsImageType::SizeType sizeXs;
123  sizePan = this->GetPanInput()->GetLargestPossibleRegion().GetSize();
124  sizeXs = this->GetXsInput()->GetLargestPossibleRegion().GetSize();
125  if ((sizePan[0] != sizeXs[0]) || (sizePan[1] != sizeXs[1]))
126  {
127  itkExceptionMacro(<< "SimpleRcsPanSharpeningFusionImageFilter: Wrong Pan/Xs size");
128  }
129 
130  //Process the fusion
131  m_ConvolutionFilter->SetInput(this->GetPanInput());
132  m_ConvolutionFilter->SetRadius(this->m_Radius);
133  m_ConvolutionFilter->SetFilter(this->m_Filter);
134 
135  m_FusionFilter->SetInput1(this->GetXsInput());
136  m_FusionFilter->SetInput3(this->GetPanInput());
137 
138  // Wire composite filter
139  m_FusionFilter->GraftOutput(this->GetOutput());
140  m_FusionFilter->Update();
141  this->GraftOutput(m_FusionFilter->GetOutput());
142 }
143 
144 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
145 void
147 <TPanImageType, TXsImageType, TOutputImageType, TInternalPrecision>
148 ::PrintSelf(std::ostream& os, itk::Indent indent) const
149 {
150  Superclass::PrintSelf(os, indent);
151  os
152  << indent << "Radius:" << this->m_Radius
153  << std::endl;
154 }
155 
156 } // end namespace otb
157 
158 #endif

Generated at Sat Mar 8 2014 16:18:08 for Orfeo Toolbox with doxygen 1.8.3.1