OTB  9.0.0
Orfeo Toolbox
otbImageAndVectorImageOperationFilter.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 otbImageAndVectorImageOperationFilter_h
24 #define otbImageAndVectorImageOperationFilter_h
25 
26 #include "itkBinaryFunctorImageFilter.h"
27 #include "itkImageToImageFilter.h"
28 
29 #include "otbMacro.h"
30 
31 namespace otb
32 {
33 namespace Functor
34 {
35 template <typename TInput, typename TVectorInput, typename TOutput>
37 {
38 public:
39  typedef typename TVectorInput::ValueType InternalInputPixelType;
40  typedef typename TOutput::ValueType InternalOutputPixelType;
41  typedef enum { MULTIPLICATION, ADDITION, DIVISION, SUBTRACTION } OperatorType;
42 
44  {
45  m_Operator = ADDITION; // 1;
46  };
48  {
49  }
50 
52  {
53  m_Operator = oper;
54  }
56  {
57  return m_Operator;
58  }
59 
60  inline TOutput operator()(const TInput& inPix, const TVectorInput& vInPix)
61  {
62  TOutput out;
63  out.SetSize(vInPix.Size());
64  TVectorInput vInTmp = vInPix;
65 
66  switch (m_Operator)
67  {
68  case MULTIPLICATION:
69  {
70  vInTmp *= static_cast<InternalInputPixelType>(inPix);
71  break;
72  }
73  case ADDITION:
74  {
75  vInTmp += static_cast<InternalInputPixelType>(inPix);
76  break;
77  }
78  case DIVISION:
79  {
80  if (inPix != 0)
81  vInTmp /= static_cast<InternalInputPixelType>(inPix);
82  else
83  {
84  vInTmp.Fill(0);
85  }
86  break;
87  }
88  case SUBTRACTION:
89  {
90  vInTmp -= static_cast<InternalInputPixelType>(inPix);
91  break;
92  }
93  default:
94  {
95  }
96  }
97 
98  for (unsigned int i = 0; i < vInTmp.Size(); ++i)
99  {
100  out[i] = static_cast<InternalInputPixelType>(vInTmp[i]);
101  }
102  return out;
103  }
104 
105 protected:
107 };
108 }
109 
126 template <class TInputImage, class TVectorInputImage, class TOutputImage>
128  : public itk::BinaryFunctorImageFilter<TInputImage, TVectorInputImage, TOutputImage,
129  Functor::ImageAndVectorImageOperationFunctor<typename TInputImage::PixelType, typename TVectorInputImage::PixelType,
130  typename TOutputImage::PixelType>>
131 // ImageToImageFilter< TVectorInputImage, TOutputImage >
132 {
133 public:
136  // typedef itk::ImageToImageFilter<TVectorInputImage, TOutputImage> Superclass;
139  typedef itk::BinaryFunctorImageFilter<TInputImage, TVectorInputImage, TOutputImage, FunctorType> Superclass;
140  typedef itk::SmartPointer<Self> Pointer;
141  typedef itk::SmartPointer<const Self> ConstPointer;
142 
144  itkNewMacro(Self);
145 
147  itkTypeMacro(ImageAndVectorImageOperationFilter, itk::BinaryFunctorImageFilter);
148 
150  typedef TInputImage InputImageType;
151  typedef typename InputImageType::PixelType InputPixelType;
152  typedef TVectorInputImage VectorInputImageType;
153  typedef typename VectorInputImageType::PixelType VectorInputPixelType;
154  typedef TOutputImage OutputImageType;
155  typedef typename OutputImageType::PixelType OutputPixelType;
156 
159 
161  using Superclass::SetInput;
162  void SetInput(const InputImageType* input) override;
163  void SetVectorInput(const VectorInputImageType* input);
165 
167  const InputImageType* GetInput();
168  const VectorInputImageType* GetVectorInput();
170 
172  itkGetMacro(UseAddition, bool);
173  itkGetMacro(UseMultiplication, bool);
174  itkGetMacro(UseDivision, bool);
175  itkGetMacro(UseSubtraction, bool);
177 
178  void UseAddition()
179  {
180  m_UseAddition = true;
181  m_UseMultiplication = false;
182  m_UseDivision = false;
183  m_UseSubtraction = false;
184  this->GetFunctor().SetOperator(static_cast<OperatorType>(1));
185  this->Modified();
186  }
188  {
189  m_UseAddition = false;
190  m_UseMultiplication = true;
191  m_UseDivision = false;
192  m_UseSubtraction = false;
193  this->GetFunctor().SetOperator(static_cast<OperatorType>(0));
194  this->Modified();
195  }
196  void UseDivision()
197  {
198  m_UseAddition = false;
199  m_UseMultiplication = false;
200  m_UseDivision = true;
201  m_UseSubtraction = false;
202  this->GetFunctor().SetOperator(static_cast<OperatorType>(2));
203  this->Modified();
204  }
206  {
207  m_UseAddition = false;
208  m_UseMultiplication = false;
209  m_UseDivision = false;
210  m_UseSubtraction = true;
211  this->GetFunctor().SetOperator(static_cast<OperatorType>(3));
212  this->Modified();
213  }
214 
215 protected:
218 
222  void GenerateOutputInformation() override;
223 
224 private:
226  void operator=(const ImageAndVectorImageOperationFilter&) = delete;
227 
232 };
233 
234 } // end namespace otb
235 
236 #ifndef OTB_MANUAL_INSTANTIATION
238 #endif
239 
240 #endif
otb::ImageAndVectorImageOperationFilter::UseSubtraction
void UseSubtraction()
Definition: otbImageAndVectorImageOperationFilter.h:205
otb::Functor::ImageAndVectorImageOperationFunctor::InternalInputPixelType
TVectorInput::ValueType InternalInputPixelType
Definition: otbImageAndVectorImageOperationFilter.h:39
otb::ImageAndVectorImageOperationFilter::UseMultiplication
void UseMultiplication()
Definition: otbImageAndVectorImageOperationFilter.h:187
otb::ImageAndVectorImageOperationFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageAndVectorImageOperationFilter.h:140
otb::Functor::ImageAndVectorImageOperationFunctor::GetOperator
OperatorType GetOperator()
Definition: otbImageAndVectorImageOperationFilter.h:55
otb::ImageAndVectorImageOperationFilter::m_UseDivision
bool m_UseDivision
Definition: otbImageAndVectorImageOperationFilter.h:230
otb::ImageAndVectorImageOperationFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbImageAndVectorImageOperationFilter.h:154
otb::Functor::ImageAndVectorImageOperationFunctor::m_Operator
OperatorType m_Operator
Definition: otbImageAndVectorImageOperationFilter.h:106
otb::ImageAndVectorImageOperationFilter::VectorInputPixelType
VectorInputImageType::PixelType VectorInputPixelType
Definition: otbImageAndVectorImageOperationFilter.h:153
otb::ImageAndVectorImageOperationFilter::m_UseSubtraction
bool m_UseSubtraction
Definition: otbImageAndVectorImageOperationFilter.h:231
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbMacro.h
otb::ImageAndVectorImageOperationFilter::OperatorType
FunctorType::OperatorType OperatorType
Definition: otbImageAndVectorImageOperationFilter.h:158
otb::ImageAndVectorImageOperationFilter::InputPixelType
InputImageType::PixelType InputPixelType
Definition: otbImageAndVectorImageOperationFilter.h:151
otb::ImageAndVectorImageOperationFilter::FunctorType
Functor::ImageAndVectorImageOperationFunctor< typename TInputImage::PixelType, typename TVectorInputImage::PixelType, typename TOutputImage::PixelType > FunctorType
Definition: otbImageAndVectorImageOperationFilter.h:138
otb::ImageAndVectorImageOperationFilter::UseDivision
void UseDivision()
Definition: otbImageAndVectorImageOperationFilter.h:196
otb::Functor::ImageAndVectorImageOperationFunctor
Definition: otbImageAndVectorImageOperationFilter.h:36
otb::Functor::ImageAndVectorImageOperationFunctor::SetOperator
void SetOperator(OperatorType oper)
Definition: otbImageAndVectorImageOperationFilter.h:51
otb::Functor::ImageAndVectorImageOperationFunctor::OperatorType
OperatorType
Definition: otbImageAndVectorImageOperationFilter.h:41
otb::Functor::ImageAndVectorImageOperationFunctor::ImageAndVectorImageOperationFunctor
ImageAndVectorImageOperationFunctor()
Definition: otbImageAndVectorImageOperationFilter.h:43
otb::Functor::ImageAndVectorImageOperationFunctor::InternalOutputPixelType
TOutput::ValueType InternalOutputPixelType
Definition: otbImageAndVectorImageOperationFilter.h:40
otb::ImageAndVectorImageOperationFilter::VectorInputImageType
TVectorInputImage VectorInputImageType
Definition: otbImageAndVectorImageOperationFilter.h:152
otb::ImageAndVectorImageOperationFilter::InputImageType
TInputImage InputImageType
Definition: otbImageAndVectorImageOperationFilter.h:147
otb::ImageAndVectorImageOperationFilter::m_UseMultiplication
bool m_UseMultiplication
Definition: otbImageAndVectorImageOperationFilter.h:229
otb::ImageAndVectorImageOperationFilter::Superclass
itk::BinaryFunctorImageFilter< TInputImage, TVectorInputImage, TOutputImage, FunctorType > Superclass
Definition: otbImageAndVectorImageOperationFilter.h:139
otb::ImageAndVectorImageOperationFilter::UseAddition
void UseAddition()
Definition: otbImageAndVectorImageOperationFilter.h:178
otb::ImageAndVectorImageOperationFilter::Self
ImageAndVectorImageOperationFilter Self
Definition: otbImageAndVectorImageOperationFilter.h:135
otb::ImageAndVectorImageOperationFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbImageAndVectorImageOperationFilter.h:141
otb::Functor::ImageAndVectorImageOperationFunctor::operator()
TOutput operator()(const TInput &inPix, const TVectorInput &vInPix)
Definition: otbImageAndVectorImageOperationFilter.h:60
otb::ImageAndVectorImageOperationFilter
Provides simple pixel to pixel operation between Image and VectorImage.
Definition: otbImageAndVectorImageOperationFilter.h:127
otb::ImageAndVectorImageOperationFilter::m_UseAddition
bool m_UseAddition
Definition: otbImageAndVectorImageOperationFilter.h:228
otb::Functor::ImageAndVectorImageOperationFunctor::~ImageAndVectorImageOperationFunctor
virtual ~ImageAndVectorImageOperationFunctor()
Definition: otbImageAndVectorImageOperationFilter.h:47
otb::ImageAndVectorImageOperationFilter::OutputPixelType
OutputImageType::PixelType OutputPixelType
Definition: otbImageAndVectorImageOperationFilter.h:155
otbImageAndVectorImageOperationFilter.hxx