OTB  9.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-2022 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;
89  typedef typename ImageType::PointType OrigineType;
90  typedef typename ImageType::SpacingType SpacingType;
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;
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
otb::BandMathXImageFilter::PixelType
ImageType::PixelType PixelType
Definition: otbBandMathXImageFilter.h:87
otb::BandMathXImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbBandMathXImageFilter.h:72
otb::BandMathXImageFilter::ParserType
ParserX ParserType
Definition: otbBandMathXImageFilter.h:91
otb::BandMathXImageFilter::RadiusType
itk::ConstNeighborhoodIterator< TImage >::RadiusType RadiusType
Definition: otbBandMathXImageFilter.h:85
otb::BandMathXImageFilter::m_ThreadOverflow
itk::Array< long > m_ThreadOverflow
Definition: otbBandMathXImageFilter.h:192
otb::BandMathXImageFilter::m_VVarName
std::vector< adhocStruct > m_VVarName
Definition: otbBandMathXImageFilter.h:175
otb::BandMathXImageFilter::m_VNotAllowedVarName
std::vector< adhocStruct > m_VNotAllowedVarName
Definition: otbBandMathXImageFilter.h:179
otb::BandMathXImageFilter::m_VParser
std::vector< std::vector< ParserType::Pointer > > m_VParser
Definition: otbBandMathXImageFilter.h:173
otb::BandMathXImageFilter::ValueType
ParserType::ValueType ValueType
Definition: otbBandMathXImageFilter.h:92
otb::BandMathXImageFilter::m_StatsVarDetected
std::vector< int > m_StatsVarDetected
Definition: otbBandMathXImageFilter.h:184
otbStreamingStatisticsVectorImageFilter.h
otb::BandMathXImageFilter::m_NeighDetected
std::vector< unsigned int > m_NeighDetected
Definition: otbBandMathXImageFilter.h:186
otb::BandMathXImageFilter::DataObjectPointerArraySizeType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbBandMathXImageFilter.h:93
otb::BandMathXImageFilter::m_AImage
std::vector< std::vector< adhocStruct > > m_AImage
Definition: otbBandMathXImageFilter.h:174
otb::BandMathXImageFilter::ImagePointer
ImageType::Pointer ImagePointer
Definition: otbBandMathXImageFilter.h:83
otb::StreamingStatisticsVectorImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbStreamingStatisticsVectorImageFilter.h:304
otb::BandMathXImageFilter::ImageType
TImage ImageType
Definition: otbBandMathXImageFilter.h:78
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::BandMathXImageFilter::IndexType
ImageType::IndexType IndexType
Definition: otbBandMathXImageFilter.h:88
otb::BandMathXImageFilter::Superclass
itk::ImageToImageFilter< TImage, TImage > Superclass
Definition: otbBandMathXImageFilter.h:70
otb::BandMathXImageFilter::m_outputsDimensions
std::vector< unsigned int > m_outputsDimensions
Definition: otbBandMathXImageFilter.h:180
otb::BandMathXImageFilter::OrigineType
ImageType::PointType OrigineType
Definition: otbBandMathXImageFilter.h:89
otb::StreamingStatisticsVectorImageFilter::MatrixType
StatFilterType::MatrixType MatrixType
Definition: otbStreamingStatisticsVectorImageFilter.h:322
otb::BandMathXImageFilter::ConstImagePointer
ImageType::ConstPointer ConstImagePointer
Definition: otbBandMathXImageFilter.h:82
otb::BandMathXImageFilter::Self
BandMathXImageFilter< TImage > Self
Definition: otbBandMathXImageFilter.h:69
otb::BandMathXImageFilter::adhocStruct::type
int type
Definition: otbBandMathXImageFilter.h:158
otb::BandMathXImageFilter::ImageRegionType
ImageType::RegionType ImageRegionType
Definition: otbBandMathXImageFilter.h:84
otb::ParserX::ValueType
mup::Value ValueType
Definition: otbParserX.h:79
otb::BandMathXImageFilter::PixelValueType
ImageType::PixelType::ValueType PixelValueType
Definition: otbBandMathXImageFilter.h:86
otb::BandMathXImageFilter::StreamingStatisticsVectorImageFilterPointerType
StreamingStatisticsVectorImageFilterType::Pointer StreamingStatisticsVectorImageFilterPointerType
Definition: otbBandMathXImageFilter.h:97
otb::BandMathXImageFilter::GlobalStatsDetected
bool GlobalStatsDetected() const
Definition: otbBandMathXImageFilter.h:136
otb::BandMathXImageFilter::m_VFinalAllowedVarName
std::vector< adhocStruct > m_VFinalAllowedVarName
Definition: otbBandMathXImageFilter.h:178
otb::StreamingStatisticsVectorImageFilter
This class streams the whole input image through the PersistentStatisticsImageFilter.
Definition: otbStreamingStatisticsVectorImageFilter.h:297
otb::BandMathXImageFilter::m_VAllowedVarNameAddedByUser
std::vector< adhocStruct > m_VAllowedVarNameAddedByUser
Definition: otbBandMathXImageFilter.h:177
otb::BandMathXImageFilter::adhocStruct::name
std::string name
Definition: otbBandMathXImageFilter.h:156
otbParserX.h
otb::BandMathXImageFilter::SpacingType
ImageType::SpacingType SpacingType
Definition: otbBandMathXImageFilter.h:90
otb::BandMathXImageFilter::m_ThreadUnderflow
itk::Array< long > m_ThreadUnderflow
Definition: otbBandMathXImageFilter.h:191
otb::BandMathXImageFilter::adhocStruct::value
ValueType value
Definition: otbBandMathXImageFilter.h:157
otb::BandMathXImageFilter::m_SizeNeighbourhood
unsigned int m_SizeNeighbourhood
Definition: otbBandMathXImageFilter.h:182
otb::BandMathXImageFilter::m_Expression
std::vector< std::string > m_Expression
Definition: otbBandMathXImageFilter.h:172
otb::BandMathXImageFilter::MatrixType
StreamingStatisticsVectorImageFilterType::MatrixType MatrixType
Definition: otbBandMathXImageFilter.h:98
otb::BandMathXImageFilter::m_VAllowedVarNameAuto
std::vector< adhocStruct > m_VAllowedVarNameAuto
Definition: otbBandMathXImageFilter.h:176
otb::ParserX
Definition of the standard floating point parser. Standard implementation of the mathematical express...
Definition: otbParserX.h:62
otb::BandMathXImageFilter::StreamingStatisticsVectorImageFilterType
StreamingStatisticsVectorImageFilter< ImageType > StreamingStatisticsVectorImageFilterType
Definition: otbBandMathXImageFilter.h:96
otb::BandMathXImageFilter
Performs mathematical operations on the input images according to the formula specified by the user.
Definition: otbBandMathXImageFilter.h:65
otb::BandMathXImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbBandMathXImageFilter.h:71
otb::BandMathXImageFilter::adhocStruct
Definition: otbBandMathXImageFilter.h:154
otb::BandMathXImageFilter::m_NeighExtremaSizes
std::vector< RadiusType > m_NeighExtremaSizes
Definition: otbBandMathXImageFilter.h:187
otb::BandMathXImageFilter::m_ManyExpressions
bool m_ManyExpressions
Definition: otbBandMathXImageFilter.h:194
otbBandMathXImageFilter.hxx
otb::BandMathXImageFilter::m_OverflowCount
long m_OverflowCount
Definition: otbBandMathXImageFilter.h:190
otb::BandMathXImageFilter::m_UnderflowCount
long m_UnderflowCount
Definition: otbBandMathXImageFilter.h:189