OTB  7.0.0
Orfeo Toolbox
otbBandMathXImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 
23 #ifndef otbBandMathXImageFilter_h
24 #define otbBandMathXImageFilter_h
25 
26 #include "itkConstNeighborhoodIterator.h"
27 #include "itkImageToImageFilter.h"
28 #include "itkArray.h"
29 
31 #include "otbParserX.h"
32 
33 #include <vector>
34 #include <string>
35 
36 
37 namespace otb
38 {
64 template <class TImage>
65 class ITK_EXPORT BandMathXImageFilter : public itk::ImageToImageFilter<TImage, TImage>
66 {
67 public:
70  typedef itk::ImageToImageFilter<TImage, TImage> Superclass;
71  typedef itk::SmartPointer<Self> Pointer;
72  typedef itk::SmartPointer<const Self> ConstPointer;
73 
75  itkNewMacro(Self);
76 
78  itkTypeMacro(BandMathXImageFilter, ImageToImageFilter);
79 
81  typedef TImage ImageType;
82  typedef typename ImageType::ConstPointer ConstImagePointer;
83  typedef typename ImageType::Pointer ImagePointer;
84  typedef typename ImageType::RegionType ImageRegionType;
85  typedef typename itk::ConstNeighborhoodIterator<TImage>::RadiusType RadiusType;
86  typedef typename ImageType::PixelType::ValueType PixelValueType;
87  typedef typename ImageType::PixelType PixelType;
88  typedef typename ImageType::IndexType IndexType;
92  typedef typename ParserType::ValueType ValueType;
93  typedef itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType;
94 
99 
101  using Superclass::SetNthInput;
102  void SetNthInput(DataObjectPointerArraySizeType idx, const ImageType* image);
103  void SetNthInput(DataObjectPointerArraySizeType idx, const ImageType* image, const std::string& varName);
105 
107  ImageType* GetNthInput(DataObjectPointerArraySizeType idx);
108 
110  void SetManyExpressions(bool flag);
111 
113  void SetExpression(const std::string& expression);
114 
116  std::string GetExpression(unsigned int IDExpression) const;
117 
119  void SetMatrix(const std::string& name, const std::string& definition);
120 
122  void SetConstant(const std::string& name, double value);
123 
125  void ExportContext(const std::string& filename);
126 
128  void ImportContext(const std::string& filename);
129 
131  void ClearExpression();
132 
134  std::vector<std::string> GetVarNames() const;
135 
136  bool GlobalStatsDetected() const
137  {
138  return !m_StatsVarDetected.empty();
139  }
140 
141 protected:
143  ~BandMathXImageFilter() override;
144  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
145 
146  void GenerateOutputInformation() override;
147  void GenerateInputRequestedRegion() override;
148 
149  void BeforeThreadedGenerateData() override;
150  void ThreadedGenerateData(const ImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
151  void AfterThreadedGenerateData() override;
152 
153 private:
154  typedef struct
155  {
156  std::string name;
157  ValueType value;
158  int type;
159  int info[5];
160  } adhocStruct;
161 
162 
163  BandMathXImageFilter(const Self&) = delete;
164  void operator=(const Self&) = delete;
165 
166  void AddVariable(adhocStruct&);
167  void CheckImageDimensions();
168  void PrepareParsers();
169  void PrepareParsersGlobStats();
170  void OutputsDimensions();
171 
172  std::vector<std::string> m_Expression;
173  std::vector<std::vector<ParserType::Pointer>> m_VParser;
174  std::vector<std::vector<adhocStruct>> m_AImage;
175  std::vector<adhocStruct> m_VVarName;
176  std::vector<adhocStruct> m_VAllowedVarNameAuto;
177  std::vector<adhocStruct> m_VAllowedVarNameAddedByUser;
178  std::vector<adhocStruct> m_VFinalAllowedVarName; // m_VFinalAllowedVarName = m_VAllowedVarNameAuto + m_VAllowedVarNameAddedByUser
179  std::vector<adhocStruct> m_VNotAllowedVarName;
180  std::vector<unsigned int> m_outputsDimensions;
181 
182  unsigned int m_SizeNeighbourhood;
183 
184  std::vector<int> m_StatsVarDetected; // input image ID for which global statistics have been detected
185 
186  std::vector<unsigned int> m_NeighDetected; // input image ID for which neighbourhood have been detected
187  std::vector<RadiusType> m_NeighExtremaSizes;
188 
191  itk::Array<long> m_ThreadUnderflow;
192  itk::Array<long> m_ThreadOverflow;
193 
195 };
196 
197 } // end namespace otb
198 
199 #ifndef OTB_MANUAL_INSTANTIATION
201 #endif
202 
203 #endif
std::vector< std::vector< adhocStruct > > m_AImage
StreamingStatisticsVectorImageFilterType::MatrixType MatrixType
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
static constexpr char const * name() noexcept
ImageType::ConstPointer ConstImagePointer
BandMathXImageFilter< TImage > Self
ParserType::ValueType ValueType
itk::SmartPointer< Self > Pointer
std::vector< std::string > m_Expression
Definition of the standard floating point parser. Standard implementation of the mathematical express...
Definition: otbParserX.h:59
itk::SmartPointer< const Self > ConstPointer
StreamingStatisticsVectorImageFilterType::Pointer StreamingStatisticsVectorImageFilterPointerType
std::vector< unsigned int > m_outputsDimensions
itk::ConstNeighborhoodIterator< TImage >::RadiusType RadiusType
std::vector< adhocStruct > m_VNotAllowedVarName
ImageType::RegionType ImageRegionType
itk::ImageToImageFilter< TImage, TImage > Superclass
ImageType::PixelType::ValueType PixelValueType
std::vector< adhocStruct > m_VAllowedVarNameAuto
ImageType::SpacingType SpacingType
std::vector< adhocStruct > m_VAllowedVarNameAddedByUser
mup::Value ValueType
Definition: otbParserX.h:76
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
static constexpr GLenum value() noexcept
std::vector< unsigned int > m_NeighDetected
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
StreamingStatisticsVectorImageFilter< ImageType > StreamingStatisticsVectorImageFilterType
std::vector< std::vector< ParserType::Pointer > > m_VParser
std::vector< RadiusType > m_NeighExtremaSizes
std::vector< adhocStruct > m_VVarName
This class streams the whole input image through the PersistentStatisticsImageFilter.
VectorImageType::SpacingType SpacingType
Definition: mvdTypes.h:175
ImageType::PointType OrigineType
std::vector< adhocStruct > m_VFinalAllowedVarName
VectorImageType::PointType PointType
Definition: mvdTypes.h:183
Performs mathematical operations on the input images according to the formula specified by the user...