22 #ifndef otbLabelMapToAttributeImageFilter_hxx
23 #define otbLabelMapToAttributeImageFilter_hxx
32 template <
class TInputImage,
class TOutputImage,
class TAttributeAccessor>
35 m_ChosenAttributes.resize(0);
40 template <
class TInputImage,
class TOutputImage,
class TAttributeAccessor>
43 m_ChosenAttributes = newAttributes;
46 template <
class TInputImage,
class TOutputImage,
class TAttributeAccessor>
49 return m_ChosenAttributes.size();
52 template <
class TInputImage,
class TOutputImage,
class TAttributeAccessor>
55 std::string strAttribute(attribute);
56 if (strAttribute.size() == 0)
62 if (channel < GetNumberOfComponentsPerPixel())
64 m_ChosenAttributes[channel] = strAttribute;
66 else if (channel == GetNumberOfComponentsPerPixel())
68 m_ChosenAttributes.push_back(strAttribute);
77 template <
class TInputImage,
class TOutputImage,
class TAttributeAccessor>
80 if (this->GetOutput() && this->GetInput())
82 this->GetOutput()->CopyInformation(this->GetInput());
83 this->GetOutput()->SetNumberOfComponentsPerPixel(GetNumberOfComponentsPerPixel());
87 template <
class TInputImage,
class TOutputImage,
class TAttributeAccessor>
91 Superclass::BeforeThreadedGenerateData();
93 unsigned int nbChannels = GetNumberOfComponentsPerPixel();
96 itkExceptionMacro(
"No attribute given");
101 backgroundPixel.SetSize(nbChannels);
102 for (
unsigned int k = 0; k < nbChannels; k++)
104 backgroundPixel[k] = m_BackgroundValue;
106 output->FillBuffer(backgroundPixel);
109 template <
class TInputImage,
class TOutputImage,
class TAttributeAccessor>
112 unsigned int nbChannels = GetNumberOfComponentsPerPixel();
116 outPixel.SetSize(nbChannels);
117 for (
unsigned int k = 0; k < nbChannels; k++)
119 accessor.SetAttributeName(m_ChosenAttributes[k].c_str());
126 while (!lit.IsAtEnd())
128 IndexType idx = lit.GetLine().GetIndex();
129 unsigned long length = lit.GetLine().GetLength();
130 for (
unsigned int i = 0; i < length; i++)
132 output->SetPixel(idx, outPixel);