21 #ifndef otbMaskMuParserFilter_hxx
22 #define otbMaskMuParserFilter_hxx
28 #include "itkImageRegionIterator.h"
29 #include "itkNumericTraits.h"
35 template <
class TInputImage,
class TOutputImage,
class TFunction>
38 this->DynamicMultiThreadingOff();
41 m_ThreadUnderflow.SetSize(1);
42 m_ThreadOverflow.SetSize(1);
47 template <
class TInputImage,
class TOutputImage,
class TFunction>
52 template <
class TInputImage,
class TOutputImage,
class TFunction>
55 Superclass::PrintSelf(os, indent);
57 os << indent <<
"Expression: " << m_Expression << std::endl;
60 template <
class TInputImage,
class TOutputImage,
class TFunction>
63 if (m_Expression != expression)
64 m_Expression = expression;
68 template <
class TInputImage,
class TOutputImage,
class TFunction>
74 template <
class TInputImage,
class TOutputImage,
class TFunction>
77 std::vector<std::string> varList;
79 tempFunctor->SetExpression(m_Expression);
84 functor(this->GetInput()->GetPixel(this->GetInput()->GetBufferedRegion().GetIndex()));
86 catch (itk::ExceptionObject& err)
88 itkDebugMacro(<< err);
91 const std::map<std::string, double*>& varMap = functor.GetVar();
92 std::map<std::string, double*>::const_iterator it;
93 for (it = varMap.begin(); it != varMap.end(); ++it)
95 varList.push_back(it->first);
101 template <
class TInputImage,
class TOutputImage,
class TFunction>
105 tempFunctor->SetExpression(m_Expression);
111 functor(this->GetInput()->GetPixel(this->GetInput()->GetBufferedRegion().GetIndex()));
113 catch (itk::ExceptionObject& err)
115 itkDebugMacro(<< err);
118 return functor.GetFunList();
121 template <
class TInputImage,
class TOutputImage,
class TFunction>
125 checkFunctor->SetExpression(m_Expression);
131 functor(this->GetInput()->GetPixel(this->GetInput()->GetBufferedRegion().GetIndex()));
133 catch (itk::ExceptionObject& err)
135 itkDebugMacro(<< err);
144 template <
class TInputImage,
class TOutputImage,
class TFunction>
148 typename std::vector<FunctorPointer>::iterator itFunctor;
149 unsigned int nbThreads = this->GetNumberOfWorkUnits();
150 unsigned int thread_index;
151 std::ostringstream varName;
154 m_ThreadUnderflow.SetSize(nbThreads);
155 m_ThreadUnderflow.Fill(0);
156 m_ThreadOverflow.SetSize(nbThreads);
157 m_ThreadOverflow.Fill(0);
158 m_VFunctor.resize(nbThreads);
160 for (itFunctor = m_VFunctor.begin(); itFunctor < m_VFunctor.end(); itFunctor++)
161 *itFunctor = FunctorType::New();
163 for (thread_index = 0; thread_index < nbThreads; thread_index++)
165 m_VFunctor.at(thread_index)->SetExpression(m_Expression);
169 template <
class TInputImage,
class TOutputImage,
class TFunction>
171 itk::ThreadIdType threadId)
181 this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
184 itk::ImageRegionConstIterator<TInputImage> inputIt(inputPtr, inputRegionForThread);
185 itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
187 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
190 outputIt.GoToBegin();
194 while (!inputIt.IsAtEnd())
196 outputIt.Set(functor(inputIt.Get()));
199 progress.CompletedPixel();
203 template <
class TInputImage,
class TOutputImage,
class TFunction>
void SetExpression(const std::string expression)
void BeforeThreadedGenerateData() override
OutputImageType::RegionType OutputImageRegionType
Parser::FunctionMapType GetFunList()
InputImageType::ConstPointer InputImageConstPointer
FunctorType::Pointer FunctorPointer
std::string GetExpression() const
OutputImageType::Pointer OutputImagePointer
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
void PrintSelf(std::ostream &os, itk::Indent indent) const override
~MaskMuParserFilter() override
std::vector< std::string > GetVar()
void AfterThreadedGenerateData() override
InputImageType::RegionType InputImageRegionType
std::map< std::string, int > FunctionMapType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.