21 #ifndef otbBandsStatisticsAttributesLabelMapFilter_hxx
22 #define otbBandsStatisticsAttributesLabelMapFilter_hxx
25 #include "itkVectorIndexSelectionCastImageFilter.h"
32 template <
class TLabelObject,
class TFeatureImage>
38 template <
class TLabelObject,
class TFeatureImage>
44 template <
class TLabelObject,
class TFeatureImage>
48 resp = resp && (m_ReducedAttributeSet !=
self.m_ReducedAttributeSet);
49 resp = resp && (m_StatsFunctorsMap !=
self.m_StatsFunctorsMap);
54 template <
class TLabelObject,
class TFeatureImage>
57 return !(
this !=
self);
63 template <
class TLabelObject,
class TFeatureImage>
67 for (
typename StatsFunctorsMapType::const_iterator it = m_StatsFunctorsMap.begin(); it != m_StatsFunctorsMap.end(); ++it)
75 template <
class TLabelObject,
class TFeatureImage>
91 m_StatsFunctorsMap[name] = newFunctor;
95 template <
class TLabelObject,
class TFeatureImage>
98 return (m_StatsFunctorsMap.erase(name) == 1);
102 template <
class TLabelObject,
class TFeatureImage>
105 if (m_StatsFunctorsMap.count(name) == 0)
107 itkGenericExceptionMacro(<<
"No feature named " << name <<
" in map.");
109 return m_StatsFunctorsMap[name].GetFeatureImage();
114 template <
class TLabelObject,
class TFeatureImage>
117 m_StatsFunctorsMap.clear();
121 template <
class TLabelObject,
class TFeatureImage>
124 return m_StatsFunctorsMap.size();
128 template <
class TLabelObject,
class TFeatureImage>
132 m_ReducedAttributeSet = flag;
135 for (
typename StatsFunctorsMapType::iterator it = m_StatsFunctorsMap.begin(); it != m_StatsFunctorsMap.end(); ++it)
141 template <
class TLabelObject,
class TFeatureImage>
144 return m_ReducedAttributeSet;
148 template <
class TImage,
class TFeatureImage>
151 this->SetNumberOfRequiredInputs(2);
155 template <
class TImage,
class TFeatureImage>
159 this->SetNthInput(1,
const_cast<TFeatureImage*
>(input));
163 template <
class TImage,
class TFeatureImage>
167 return static_cast<const TFeatureImage*
>(this->itk::ProcessObject::GetInput(1));
171 template <
class TImage,
class TFeatureImage>
174 if (this->GetFunctor().GetReducedAttributeSet() != flag)
183 template <
class TImage,
class TFeatureImage>
190 template <
class TImage,
class TFeatureImage>
194 if (this->GetInPlace() && this->CanRunInPlace())
199 ImagePointer inputAsOutput =
dynamic_cast<TImage*
>(
const_cast<TImage*
>(this->GetInput()));
204 this->GraftOutput(inputAsOutput);
205 this->GetOutput()->SetLargestPossibleRegion(this->GetOutput()->GetLargestPossibleRegion());
206 this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetRequestedRegion());
207 this->GetOutput()->SetBufferedRegion(this->GetOutput()->GetBufferedRegion());
211 for (
unsigned int i = 1; i < this->GetNumberOfOutputs(); ++i)
215 outputPtr = this->GetOutput(i);
216 outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
217 outputPtr->Allocate();
224 Superclass::AllocateOutputs();
232 template <
class TImage,
class TFeatureImage>
235 itk::ImageToImageFilter<TImage, TImage>::GenerateInputRequestedRegion();
239 template <
class TImage,
class TFeatureImage>
243 Superclass::BeforeThreadedGenerateData();
245 unsigned long nbComponents = this->GetFeatureImage()->GetNumberOfComponentsPerPixel();
248 this->GetFunctor().ClearAllFeatures();
251 for (
unsigned int i = 0; i < nbComponents; ++i)
253 typedef itk::VectorIndexSelectionCastImageFilter<FeatureImageType, InternalImageType> VectorIndexSelectionCastImageFilterType;
255 typename VectorIndexSelectionCastImageFilterType::Pointer band = VectorIndexSelectionCastImageFilterType::New();
256 band->SetInput(this->GetFeatureImage());
258 band->UpdateOutputInformation();
259 band->GetOutput()->SetRequestedRegion(this->GetOutput()->GetRequestedRegion());
261 std::ostringstream oss;
262 oss <<
"Band" << i + 1;
263 this->GetFunctor().AddFeature(oss.str(), band->GetOutput());
267 template <
class TImage,
class TFeatureImage>
270 Superclass::PrintSelf(os, indent);