OTB  9.0.0
Orfeo Toolbox
otbVariadicNamedInputsImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 GetInput<> 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;
173 
174 private:
175  VariadicNamedInputsImageFilter(const Self&) = delete;
176  void operator=(const Self&) = delete;
177 };
178 }
179 
180 #endif
otb::VariadicNamedInputsImageFilter::InputImageType
typename Superclass::template InputImageType< I > InputImageType
Definition: otbVariadicNamedInputsImageFilter.h:108
otb::VariadicInputsImageFilter< TOuptut, TInputs... >::NumberOfInputs
static constexpr vcl_size_t NumberOfInputs
Definition: otbVariadicInputsImageFilter.h:71
otb::VariadicInputsImageFilter< TOuptut, TInputs... >::GetInput
const InputImageType< I > * GetInput()
Definition: otbVariadicInputsImageFilter.h:115
otb::VariadicNamedInputsImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbVariadicNamedInputsImageFilter.h:101
otb::VariadicNamedInputsImageFilter::SetInput
void SetInput(Tag, const InputImageType< internal::tuple_index< Tag, TInputNameMap >::value > *inputPtr)
Definition: otbVariadicNamedInputsImageFilter.h:141
otb::VariadicNamedInputsImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbVariadicNamedInputsImageFilter.h:100
otb::VariadicInputsImageFilter
Base class for image filter with variadic inputs.
Definition: otbVariadicInputsImageFilter.h:58
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::VariadicNamedInputsImageFilter::~VariadicNamedInputsImageFilter
~VariadicNamedInputsImageFilter()=default
otb::VariadicNamedInputsImageFilter::VariadicNamedInputsImageFilter
VariadicNamedInputsImageFilter()=default
otb::VariadicNamedInputsImageFilter::InputTypesTupleType
typename Superclass::InputTypesTupleType InputTypesTupleType
Definition: otbVariadicNamedInputsImageFilter.h:106
otb::VariadicInputsImageFilter< TOuptut, TInputs... >::SetInput
void SetInput(const InputImageType< I > *inputPtr)
Definition: otbVariadicInputsImageFilter.h:85
otb::internal::tuple_index
retrieve index of a type in tuple if exists
Definition: otbVariadicNamedInputsImageFilter.h:43
otb::VariadicNamedInputsImageFilter::GetInput
const InputImageType< internal::tuple_index< Tag, TInputNameMap >::value > * GetInput(Tag)
Definition: otbVariadicNamedInputsImageFilter.h:165
otb::VariadicNamedInputsImageFilter::Self
VariadicNamedInputsImageFilter< TOuptut, TInputNameMap, TInputs... > Self
Definition: otbVariadicNamedInputsImageFilter.h:99
otb::VariadicNamedInputsImageFilter::SetInput
void SetInput(const InputImageType< internal::tuple_index< Tag, TInputNameMap >::value > *inputPtr)
Definition: otbVariadicNamedInputsImageFilter.h:128
otbVariadicInputsImageFilter.h
otb::VariadicNamedInputsImageFilter::GetInput
const InputImageType< internal::tuple_index< Tag, TInputNameMap >::value > * GetInput()
Definition: otbVariadicNamedInputsImageFilter.h:152
otb::VariadicNamedInputsImageFilter
Adds tagged versions for Get/SetInput to otb::VariadicInputsImageFilter.
Definition: otbVariadicNamedInputsImageFilter.h:96
otb::VariadicNamedInputsImageFilter::NumberOfInputs
static constexpr vcl_size_t NumberOfInputs
Definition: otbVariadicNamedInputsImageFilter.h:109
otb::VariadicNamedInputsImageFilter::operator=
void operator=(const Self &)=delete
otb::VariadicInputsImageFilter< TOuptut, TInputs... >::InputTypesTupleType
std::tuple< TInputs... > InputTypesTupleType
Definition: otbVariadicInputsImageFilter.h:67