Orfeo Toolbox  4.0
otbMorphologicalPyramidSynthesisFilter.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 __otbMorphologicalPyramidSynthesisFilter_txx
19 #define __otbMorphologicalPyramidSynthesisFilter_txx
20 
22 
24 #include "itkSubtractImageFilter.h"
25 #include "itkAddImageFilter.h"
26 #include "itkImageDuplicator.h"
27 #include "otbMacro.h"
28 
29 namespace otb
30 {
34 template <class TInputImage, class TOutputImage>
37 {
38  this->SetNumberOfRequiredInputs(5);
39 }
43 template <class TInputImage, class TOutputImage>
50 template <class TInputImage, class TOutputImage>
51 void
54 {
55  this->SetNthInput(1, const_cast<InputImageListType *>(imageList));
56 }
61 template <class TInputImage, class TOutputImage>
62 void
65 {
66  this->SetNthInput(2, const_cast<InputImageListType *>(imageList));
67 }
68 
73 template <class TInputImage, class TOutputImage>
74 void
77 {
78  this->SetNthInput(3, const_cast<InputImageListType *>(imageList));
79 }
84 template <class TInputImage, class TOutputImage>
85 void
88 {
89  this->SetNthInput(4, const_cast<InputImageListType *>(imageList));
90 }
91 
96 template <class TInputImage, class TOutputImage>
98 ::InputImageListType*
101 {
102  return dynamic_cast<InputImageListType *>(this->itk::ProcessObject::GetInput(1));
103 }
108 template <class TInputImage, class TOutputImage>
110 ::InputImageListType*
113 {
114  return dynamic_cast<InputImageListType *>(this->itk::ProcessObject::GetInput(2));
115 }
120 template <class TInputImage, class TOutputImage>
122 ::InputImageListType*
125 {
126  return dynamic_cast<InputImageListType *>(this->itk::ProcessObject::GetInput(3));
127 }
132 template <class TInputImage, class TOutputImage>
134 ::InputImageListType*
137 {
138  return dynamic_cast<InputImageListType *>(this->itk::ProcessObject::GetInput(4));
139 }
143 template <class TInputImage, class TOutputImage>
144 void
147 {
148  otbMsgDevMacro(<< "MorphologicalPyramidSynthesisFilter : Entering main method.");
149  // Input image pointer
150  InputImageListType * supFilter = this->GetSupFilter();
151  InputImageListType * infFilter = this->GetInfFilter();
152  InputImageListType * supDeci = this->GetSupDeci();
153  InputImageListType * infDeci = this->GetInfDeci();
154 
155  // Output pointer
156  OutputImageListType * OutputImageList = this->GetOutput();
157 
158  // typedefs of the filters
162  typedef itk::ImageDuplicator<InputImageType> DuplicatorType;
163 
164  // Input Image duplication to the currentImage Pointer
165  typename DuplicatorType::Pointer duplicator = DuplicatorType::New();
166  duplicator->SetInputImage(this->GetInput());
167  duplicator->Update();
168 
169  // Input Image duplication to the currentImage Pointer
170  typename InputImageType::Pointer currentImage = duplicator->GetOutput();
171 
172  // Filters declarations
173  typename AddFilterType::Pointer add1, add2;
174  typename SubtractFilterType::Pointer subtract1, subtract2;
175  typename ResamplerType::Pointer resampler;
176 
177  // Size vector computation
178  SizeVectorType size;
179 
180  ImageListIterator it = supFilter->Begin();
181 
182  while (it != supFilter->End())
183  {
184  size.push_back(it.Get()->GetLargestPossibleRegion().GetSize());
185  ++it;
186  }
187  otbMsgDevMacro(<< "MorphologicalPyramidSynthesisFilter : Size vector computation OK");
188 
189  // Iterators definition
190  ImageListReverseIterator itinfFilter = infFilter->ReverseBegin();
191  ImageListReverseIterator itsupFilter = supFilter->ReverseBegin();
192  ImageListReverseIterator itinfDeci = infDeci->ReverseBegin();
193  ImageListReverseIterator itsupDeci = supDeci->ReverseBegin();
194  SizeReverseIterator itSize = size.rbegin();
195 
196  int i = 1;
197 //--------------------------------------------------------//
198 // Main loop //
199 //--------------------------------------------------------//
200  while (itinfFilter != infFilter->ReverseEnd()
201  && itsupFilter != supFilter->ReverseEnd()
202  && itinfDeci != infDeci->ReverseEnd()
203  && itsupDeci != supDeci->ReverseEnd()
204  && itSize != size.rend())
205  {
206 
207  ++i;
208  // Upsampling current image
209  resampler = ResamplerType::New();
210  resampler->SetSize(*itSize);
211  resampler->SetInput(currentImage);
212  resampler->Update();
213  otbMsgDevMacro(<< "MorphologicalPyramidSynthesisFilter: step " << i << " Upsampling OK");
214  // Adding *sup details from current level
215  add1 = AddFilterType::New();
216  add1->SetInput1(resampler->GetOutput());
217  add1->SetInput2(itsupFilter.Get());
218  add2 = AddFilterType::New();
219  add2->SetInput1(add1->GetOutput());
220  add2->SetInput2(itsupDeci.Get());
221 
222  // Adding *inf details from current level
223  subtract1 = SubtractFilterType::New();
224  subtract1->SetInput1(add2->GetOutput());
225  subtract1->SetInput2(itinfFilter.Get());
226  subtract2 = SubtractFilterType::New();
227  subtract2->SetInput1(subtract1->GetOutput());
228  subtract2->SetInput2(itinfDeci.Get());
229  subtract2->Update();
230  otbMsgDevMacro(<< "MorphologicalPyramidSynthesisFilter: step " << i << " Details addition OK");
231 
232  // Updating current image
233  currentImage = subtract2->GetOutput();
234  OutputImageList->PushBack(currentImage);
235 
236  // Iterators incrementation
237  ++itsupFilter;
238  ++itinfFilter;
239  ++itsupDeci;
240  ++itinfDeci;
241  ++itSize;
242  }
243  otbMsgDevMacro(<< "MorphologicalPyramidSynthesisFilter: Exiting main method.");
244 }
248 template <class TInputImage, class TOutputImage>
249 void
251 ::PrintSelf(std::ostream& os, itk::Indent indent) const
252 {
253  Superclass::PrintSelf(os, indent);
254 }
255 } // End namespace otb
256 
257 #endif

Generated at Sat Mar 8 2014 16:09:25 for Orfeo Toolbox with doxygen 1.8.3.1