21 #ifndef otbLabelObjectOpeningMuParserFilter_hxx
22 #define otbLabelObjectOpeningMuParserFilter_hxx
28 #include "itkImageRegionIterator.h"
29 #include "itkNumericTraits.h"
35 template <
class TImage,
class TFunction>
39 this->SetNumberOfRequiredOutputs(2);
40 this->SetNthOutput(1,
static_cast<TImage*
>(this->MakeOutput(1).GetPointer()));
44 template <
class TImage,
class TFunction>
49 template <
class TImage,
class TFunction>
52 Superclass::PrintSelf(os, indent);
53 os << indent <<
"Expression: " << m_Expression << std::endl;
56 template <
class TImage,
class TFunction>
59 if (m_Expression != expression)
60 m_Expression = expression;
61 m_Functor.SetExpression(m_Expression);
65 template <
class TImage,
class TFunction>
71 template <
class TImage,
class TFunction>
74 return this->m_Functor.GetVar();
77 template <
class TImage,
class TFunction>
80 return this->m_Functor.GetFunList();
83 template <
class TImage,
class TFunction>
86 const std::map<std::string, double*>& variables = this->m_Functor.GetVar();
89 std::map<std::string, double*>::const_iterator item = variables.begin();
92 for (; item != variables.end(); ++item)
94 std::cout <<
"Name: " << item->first <<
" Address: [0x" << item->second <<
"]\n";
98 template <
class TImage,
class TFunction>
101 return this->m_Functor.CheckExpression();
104 template <
class TImage,
class TFunction>
108 this->m_Functor.SetAttributes(shapeAttributes, statAttributes, nbOfBands);
112 template <
class TImage,
class TFunction>
116 if (this->GetInPlace() && this->CanRunInPlace())
121 ImagePointer inputAsOutput =
dynamic_cast<TImage*
>(
const_cast<TImage*
>(this->GetInput()));
126 this->GraftOutput(inputAsOutput);
127 this->GetOutput()->SetLargestPossibleRegion(this->GetOutput()->GetLargestPossibleRegion());
128 this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetRequestedRegion());
129 this->GetOutput()->SetBufferedRegion(this->GetOutput()->GetBufferedRegion());
133 for (
unsigned int i = 1; i < this->GetNumberOfOutputs(); ++i)
137 outputPtr = this->GetOutput(i);
138 outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
139 outputPtr->Allocate();
144 Superclass::AllocateOutputs();
151 template <
class TImage,
class TFunction>
154 itk::ImageToImageFilter<TImage, TImage>::GenerateInputRequestedRegion();
157 template <
class TImage,
class TFunction>
163 this->AllocateOutputs();
167 assert(this->GetNumberOfOutputs() == 2);
168 assert(output2 != NULL);
171 output2->SetBackgroundValue(output->GetBackgroundValue());
173 itk::ProgressReporter progress(
this, 0, output->GetNumberOfLabelObjects());
174 typename ImageType::Iterator it(output);
176 while (!it.IsAtEnd())
178 typename LabelObjectType::LabelType label = it.GetLabel();
181 if (!m_Functor(*labelObject))
185 output2->AddLabelObject(labelObject);
186 output->RemoveLabel(label);
193 progress.CompletedPixel();