OTB  9.0.0
Orfeo Toolbox
otbIndicesStackFunctor.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 
21 #ifndef otbIndicesStackFunctor_h
22 #define otbIndicesStackFunctor_h
23 
24 #include <vector>
25 #include <stdexcept>
26 #include "itkVariableLengthVector.h"
27 
28 namespace otb
29 {
30 
31 namespace Functor
32 {
46 template <typename TIndice>
48 {
49 public:
51  using IndiceType = TIndice;
52  using PixelType = typename IndiceType::PixelType;
53  // Output will be a VariableLengthVector of values return by
54  // radiometric indices
55  using OutputType = itk::VariableLengthVector<typename IndiceType::OutputType>;
56 
62  IndicesStackFunctor(const std::vector<IndiceType*>& indices) : m_Indices(std::move(indices))
63  {
64  if (indices.empty())
65  {
66  throw std::runtime_error("Can not build IndicesStackFunctor from an empty list of indices.");
67  }
68  }
70 
77  void operator()(OutputType& out, const PixelType& in) const
78  {
79  size_t idx = 0;
80  for (auto indice : m_Indices)
81  {
82  out[idx] = (*indice)(in);
83  ++idx;
84  }
85  }
86 
90  size_t OutputSize(...) const
91  {
92  return m_Indices.size();
93  }
94 
95 private:
97  std::vector<IndiceType*> m_Indices;
98 };
99 
100 } // End namespace Functor
101 
102 } // End namespace otb
103 
104 #endif
otb::Functor::IndicesStackFunctor::OutputType
itk::VariableLengthVector< typename IndiceType::OutputType > OutputType
Definition: otbIndicesStackFunctor.h:55
otb::Functor::IndicesStackFunctor::IndicesStackFunctor
IndicesStackFunctor(const std::vector< IndiceType * > &indices)
Definition: otbIndicesStackFunctor.h:62
otb::Functor::IndicesStackFunctor::PixelType
typename IndiceType::PixelType PixelType
Definition: otbIndicesStackFunctor.h:52
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::IndicesStackFunctor::m_Indices
std::vector< IndiceType * > m_Indices
The list of indices to use.
Definition: otbIndicesStackFunctor.h:97
otb::Functor::IndicesStackFunctor
A class to compute a stack of radiometric indices.
Definition: otbIndicesStackFunctor.h:47
otb::Functor::IndicesStackFunctor::operator()
void operator()(OutputType &out, const PixelType &in) const
Definition: otbIndicesStackFunctor.h:77
otb::Functor::IndicesStackFunctor::IndiceType
TIndice IndiceType
Read input / output types from TIndice.
Definition: otbIndicesStackFunctor.h:51
otb::Functor::IndicesStackFunctor::OutputSize
vcl_size_t OutputSize(...) const
Definition: otbIndicesStackFunctor.h:90