OTB  6.7.0
Orfeo Toolbox
otbVariadicNamedInputsImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 
28 
29 namespace internal
30 {
41 template<typename Arg, typename Tuple> struct tuple_index;
42 template<typename Arg, typename...Args> struct tuple_index<Arg, std::tuple<Arg,Args...> >
43 {
44  static constexpr std::size_t value = 0;
45 };
46 
47 template<typename Arg, typename NotMatching, typename...Args> struct tuple_index<Arg, std::tuple<NotMatching,Args...>>
48 {
49  static_assert(sizeof...(Args)>0,"Could not find requested type in tuple");
50  static constexpr std::size_t value = 1 + tuple_index<Arg,std::tuple<Args...>>::value;
51 };
52 }
53 
91 template<class TOuptut, class TInputNameMap, class ... TInputs> class VariadicNamedInputsImageFilter : public VariadicInputsImageFilter<TOuptut,TInputs...>
92 {
93 public:
94  using Self = VariadicNamedInputsImageFilter<TOuptut,TInputNameMap, TInputs...>;
97  using Superclass = VariadicInputsImageFilter<TOuptut, TInputs...>;;
99 
101  template <size_t I> using InputImageType = typename Superclass::template InputImageType<I>;
102  static constexpr size_t NumberOfInputs = Superclass::NumberOfInputs;
103 
104  // This checks that TInputNameMap has the correct size
105  static_assert(std::tuple_size<TInputNameMap>::value == NumberOfInputs,"Tuple for input name does not match the size of ... TInputs");
106 
107  // Good old new macro
108  itkNewMacro(Self);
109 
110  // Import definitions for SetInput and GetInput to avoid shadowing
111  // by SetInput<> and GetIntput<> defined in this method
112  using Superclass::GetInput;
113  using Superclass::SetInput;
114 
120  template <typename Tag>
122  {
124  this->SetNthInput(idx,const_cast<InputImageType<idx> *>(inputPtr));
125  }
127 
133  template <typename Tag>
135  {
136  SetInput<Tag>(inputPtr);
137  }
138 
144  template <typename Tag>
146  {
148  return dynamic_cast<const InputImageType<idx>*>(this->Superclass::GetInput(idx));
149  }
151 
157  template <typename Tag>
159  {
160  return GetInput<Tag>();
161  }
162 
163 protected:
164  VariadicNamedInputsImageFilter() = default;
166 
167 private:
168  VariadicNamedInputsImageFilter(const Self&) = delete;
169  void operator=(const Self&) = delete;
170 };
171 
172 }
173 
174 #endif
void SetInput(Tag, const InputImageType< internal::tuple_index< Tag, TInputNameMap >::value > *inputPtr)
const InputImageType< internal::tuple_index< Tag, TInputNameMap >::value > * GetInput()
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.
Base class for image filter with variadic inputs.
VariadicNamedInputsImageFilter< TOuptut, TInputNameMap, TInputs...> Self
void operator=(const Self &)=delete
virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input)