OTB  6.7.0
Orfeo Toolbox
otbGeodesicMorphologyIterativeDecompositionImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 otbGeodesicMorphologyIterativeDecompositionImageFilter_hxx
22 #define otbGeodesicMorphologyIterativeDecompositionImageFilter_hxx
23 
25 
26 #include "itkProgressAccumulator.h"
27 #include "otbMacro.h"
28 
29 namespace otb
30 {
34 template <class TImage, class TStructuringElement>
37 {
38  // Create a process accumulator for tracking the progress of minipipeline
39  m_Progress = itk::ProgressAccumulator::New();
40  m_Progress->SetMiniPipelineFilter(this);
42 
43  this->SetNumberOfRequiredInputs(1);
44  this->SetNumberOfRequiredOutputs(3);
45  m_NumberOfIterations = 2;
46  m_InitialValue = 1;
47  m_Step = 1;
48  OutputImageListPointerType convList = OutputImageListType::New();
49  this->SetNthOutput(0, convList.GetPointer());
50  OutputImageListPointerType concList = OutputImageListType::New();
51  this->SetNthOutput(1, concList.GetPointer());
52  OutputImageListPointerType outputList = OutputImageListType::New();
53  this->SetNthOutput(2, outputList.GetPointer());
54 }
55 
56 template <class TImage, class TStructuringElement>
57 typename GeodesicMorphologyIterativeDecompositionImageFilter<TImage, TStructuringElement>
58 ::OutputImageListType*
60 ::GetOutput(void)
61 {
62  return dynamic_cast<OutputImageListType*>(this->itk::ProcessObject::GetOutput(2));
63 }
64 
65 template <class TImage, class TStructuringElement>
66 typename GeodesicMorphologyIterativeDecompositionImageFilter<TImage, TStructuringElement>
67 ::OutputImageListType*
70 {
71  return dynamic_cast<OutputImageListType*>(this->itk::ProcessObject::GetOutput(0));
72 }
73 
74 template <class TImage, class TStructuringElement>
75 typename GeodesicMorphologyIterativeDecompositionImageFilter<TImage, TStructuringElement>
76 ::OutputImageListType*
79 {
80  return dynamic_cast<OutputImageListType*>(this->itk::ProcessObject::GetOutput(1));
81 }
82 
83 template <class TImage, class TStructuringElement>
84 void
87 {
88  // Retrieving input/output pointers
89  InputImagePointerType inputPtr = this->GetInput();
90  OutputImageListPointerType outputPtr = this->GetOutput();
91  OutputImageListPointerType convOutputPtr = this->GetConvexOutput();
92  OutputImageListPointerType concOutputPtr = this->GetConcaveOutput();
93  if (outputPtr)
94  {
95  if (outputPtr->Size() != m_NumberOfIterations)
96  {
97  // in this case, clear the list
98  outputPtr->Clear();
99  for (unsigned int i = 0; i < m_NumberOfIterations; ++i)
100  {
101  //Create the output image
102  outputPtr->PushBack(OutputImageType::New());
103  }
104  }
105  // For each output image
106  typename OutputImageListType::Iterator outputListIt = outputPtr->Begin();
107  while (outputListIt != outputPtr->End())
108  {
109  //Set the image information
110  outputListIt.Get()->CopyInformation(this->GetInput());
111  outputListIt.Get()->SetRequestedRegion(this->GetInput()->GetLargestPossibleRegion());
112  ++outputListIt;
113  }
114  }
115  if (convOutputPtr)
116  {
117  if (convOutputPtr->Size() != m_NumberOfIterations)
118  {
119  // in this case, clear the list
120  convOutputPtr->Clear();
121  for (unsigned int i = 0; i < m_NumberOfIterations; ++i)
122  {
123  //Create the output image
124  convOutputPtr->PushBack(OutputImageType::New());
125  }
126  }
127  // For each output image
128  typename OutputImageListType::Iterator outputListIt = convOutputPtr->Begin();
129  while (outputListIt != convOutputPtr->End())
130  {
131  //Set the image information
132  outputListIt.Get()->CopyInformation(this->GetInput());
133  outputListIt.Get()->SetRequestedRegion(this->GetInput()->GetLargestPossibleRegion());
134  ++outputListIt;
135  }
136  }
137  if (concOutputPtr)
138  {
139  if (concOutputPtr->Size() != m_NumberOfIterations)
140  {
141  // in this case, clear the list
142  concOutputPtr->Clear();
143  for (unsigned int i = 0; i < m_NumberOfIterations; ++i)
144  {
145  //Create the output image
146  concOutputPtr->PushBack(OutputImageType::New());
147  }
148  }
149  // For each output image
150  typename OutputImageListType::Iterator outputListIt = concOutputPtr->Begin();
151  while (outputListIt != concOutputPtr->End())
152  {
153  //Set the image information
154  outputListIt.Get()->CopyInformation(this->GetInput());
155  outputListIt.Get()->SetRequestedRegion(this->GetInput()->GetLargestPossibleRegion());
156  ++outputListIt;
157  }
158  }
159 }
160 
161 template <class TImage, class TStructuringElement>
162 void
165 {
166  // Retrieving input/output pointers
167  InputImagePointerType inputPtr = this->GetInput();
168  OutputImageListPointerType outputPtr = this->GetOutput();
169 
170  // For each output image
171  typename OutputImageListType::Iterator outputListIt = outputPtr->Begin();
172  inputPtr->SetRequestedRegion(outputListIt.Get()->GetRequestedRegion());
173 }
174 
178 template <class TImage, class TStructuringElement>
179 void
181 ::GenerateData(void)
182 {
183  //Input image pointer
184  InputImagePointerType current = this->GetInput();
185  OutputImageListPointerType outputPtr = this->GetOutput();
186  OutputImageListPointerType convOutputPtr = this->GetConvexOutput();
187  OutputImageListPointerType concOutputPtr = this->GetConcaveOutput();
189 
190  unsigned int i = 0;
191 
192  DecompositionFilterPointerType filter;
193 
194  while (i < m_NumberOfIterations)
195  {
196  filter = DecompositionFilterType::New();
197 
198  // Register Internal Filter for progress
199  m_Progress->RegisterInternalFilter(filter, 1./m_NumberOfIterations);
200 
201  typename StructuringElementType::RadiusType radius;
202  radius.Fill(m_InitialValue + i * m_Step);
203  filter->SetRadius(radius);
204  filter->SetInput(current);
205  filter->GetOutput()->UpdateOutputInformation();
206  filter->GetOutput()->SetRequestedRegion(outputPtr->GetNthElement(i)->GetRequestedRegion());
207  filter->GetOutput()->PropagateRequestedRegion();
208  filter->GetOutput()->UpdateOutputData();
209 
210  outputPtr->SetNthElement(i, filter->GetOutput());
211  concOutputPtr->SetNthElement(i, filter->GetConcaveMap());
212  convOutputPtr->SetNthElement(i, filter->GetConvexMap());
213 
214  current = filter->GetOutput();
215 
216  ++i;
217  }
218 
219 }
OutputImageListType * GetOutput(void) override
static Pointer New()
DataObject * GetOutput(const DataObjectIdentifierType &key)