OTB  7.2.0
Orfeo Toolbox
otbVariadicNamedInputsImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 #ifndef otb_VariadicNamedInputsImageFilter_h
21 #define otb_VariadicNamedInputsImageFilter_h
22 
24 
25 namespace otb
26 {
27 
29 
30 namespace internal
31 {
42 template <typename Arg, typename Tuple>
43 struct tuple_index;
44 template <typename Arg, typename... Args>
45 struct tuple_index<Arg, std::tuple<Arg, Args...>>
46 {
47  static constexpr std::size_t value = 0;
48 };
49 
50 template <typename Arg, typename NotMatching, typename... Args>
51 struct tuple_index<Arg, std::tuple<NotMatching, Args...>>
52 {
53  static_assert(sizeof...(Args) > 0, "Could not find requested type in tuple");
54  static constexpr std::size_t value = 1 + tuple_index<Arg, std::tuple<Args...>>::value;
55 };
56 }
57 
95 template <class TOuptut, class TInputNameMap, class... TInputs>
96 class VariadicNamedInputsImageFilter : public VariadicInputsImageFilter<TOuptut, TInputs...>
97 {
98 public:
99  using Self = VariadicNamedInputsImageFilter<TOuptut, TInputNameMap, TInputs...>;
100  using Pointer = itk::SmartPointer<Self>;
101  using ConstPointer = itk::SmartPointer<const Self>;
102  using Superclass = VariadicInputsImageFilter<TOuptut, TInputs...>;
103  ;
105 
107  template <size_t I>
108  using InputImageType = typename Superclass::template InputImageType<I>;
109  static constexpr size_t NumberOfInputs = Superclass::NumberOfInputs;
110 
111  // This checks that TInputNameMap has the correct size
112  static_assert(std::tuple_size<TInputNameMap>::value == NumberOfInputs, "Tuple for input name does not match the size of ... TInputs");
113 
114  // Good old new macro
115  itkNewMacro(Self);
116 
117  // Import definitions for SetInput and GetInput to avoid shadowing
118  // by SetInput<> and GetIntput<> defined in this method
119  using Superclass::GetInput;
120  using Superclass::SetInput;
121 
127  template <typename Tag>
129  {
131  this->SetNthInput(idx, const_cast<InputImageType<idx>*>(inputPtr));
132  }
134 
140  template <typename Tag>
142  {
143  this->template SetInput<Tag>(inputPtr);
144  }
145 
151  template <typename Tag>
153  {
155  return dynamic_cast<const InputImageType<idx>*>(this->Superclass::GetInput(idx));
156  }
158 
164  template <typename Tag>
166  {
167  return this->template GetInput<Tag>();
168  }
169 
170 protected:
171  VariadicNamedInputsImageFilter() = default;
172  ~VariadicNamedInputsImageFilter() = default;
173 
174 private:
175  VariadicNamedInputsImageFilter(const Self&) = delete;
176  void operator=(const Self&) = delete;
177 };
178 }
179 
180 #endif
void SetInput(Tag, const InputImageType< internal::tuple_index< Tag, TInputNameMap >::value > *inputPtr)
const InputImageType< internal::tuple_index< Tag, TInputNameMap >::value > * GetInput()
STL namespace.
typename Superclass::InputTypesTupleType InputTypesTupleType
retrieve index of a type in tuple if exists
void SetInput(const InputImageType< internal::tuple_index< Tag, TInputNameMap >::value > *inputPtr)
const InputImageType< internal::tuple_index< Tag, TInputNameMap >::value > * GetInput(Tag)
typename Superclass::template InputImageType< I > InputImageType
Adds tagged versions for Get/SetInput to otb::VariadicInputsImageFilter.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Base class for image filter with variadic inputs.
static constexpr GLenum value() noexcept