1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Some parts of this code are derived from ITK. See ITKCopyright.txt
for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef otbMaskMuParserFilter_h
#define otbMaskMuParserFilter_h
#include "itkProgressReporter.h"
#include <iostream>
#include <string>
#include <vector>
#include "itkArray.h"
#include "otbMaskMuParserFunctor.h"
#include "itkImageToImageFilter.h"
#include "itkImageRegionIteratorWithIndex.h"
namespace otb
{
/** \class MaskMuParserImageFilter
* \brief Performs a mathematical operation on the input images
* according to the formula specified by the user. values different from 0 are set to 1
*
* This filter is based on the mathematical parser library muParser.
* The built in functions and operators list is available at:
* http://muparser.sourceforge.net/mup_features.html#idDef2
*
* OTB additional functions:
* ndvi(r, niri)
*
* OTB additional constants:
* e - log2e - log10e - ln2 - ln10 - pi - euler
*
* an input vector image and a Mu Parser compliant fomula is needed
* each band of vector image is name bX, where X is the band index
* for example b2 correspond to the second band of the input image.
* Next step is to set the expression according to the variable
* names. For example, in the default case with three input images the
* following expression is valid :
* "b1<140"
*
*
* \sa Parser
*
* \ingroup Streamed
* \ingroup Threaded
*
* \ingroup OTBMathParser
*/
template<class TInputImage, class TOutputImage, class TFunction = Functor::MaskMuParserFunctor<
typename TInputImage::PixelType> >
class ITK_EXPORT MaskMuParserFilter: public itk::ImageToImageFilter<TInputImage, TOutputImage>
{
public:
/** Standard class typedefs. */
typedef MaskMuParserFilter Self;
typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self)
;
/** Run-time type information (and related methods). */
itkTypeMacro(MaskMuParserFilter, itk::ImageToImageFilter)
;
/** Some convenient typedefs. */
typedef TInputImage InputImageType;
typedef typename InputImageType::RegionType InputImageRegionType;
typedef typename InputImageType::PixelType PixelType;
typedef typename InputImageType::IndexType IndexType;
typedef typename InputImageType::Pointer InputImagePointer;
typedef typename InputImageType::ConstPointer InputImageConstPointer;
typedef TOutputImage OutputImageType;
typedef typename OutputImageType::RegionType OutputImageRegionType;
typedef typename OutputImageType::Pointer OutputImagePointer;
typedef TFunction FunctorType;
typedef typename FunctorType::Pointer FunctorPointer;
typedef MaskMuParserFilter<InputImageType, OutputImageType, FunctorType> MaskMuParserFilterType;
/** Set the expression to be parsed */
void SetExpression(const std::string expression);
/**Check expression */
bool CheckExpression();
/** Return the expression to be parsed */
std::string GetExpression() const;
std::vector<std::string> GetVar();
Parser::FunctionMapType GetFunList();
protected:
MaskMuParserFilter();
~MaskMuParserFilter() ITK_OVERRIDE;
void PrintSelf(std::ostream& os, itk::Indent indent) const ITK_OVERRIDE;
void BeforeThreadedGenerateData() ITK_OVERRIDE;
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) ITK_OVERRIDE;
void AfterThreadedGenerateData() ITK_OVERRIDE;
private:
MaskMuParserFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
std::vector<FunctorPointer> m_VFunctor;
std::string m_Expression;
long m_UnderflowCount;
long m_OverflowCount;
itk::Array<long> m_ThreadUnderflow;
itk::Array<long> m_ThreadOverflow;
};
}//end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbMaskMuParserFilter.txx"
#endif
#endif
|