OTB  9.0.0
Orfeo Toolbox
otbMetaImageFunction.hxx
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 otbMetaImageFunction_hxx
22 #define otbMetaImageFunction_hxx
23 
24 #include "otbMetaImageFunction.h"
26 
27 #include <algorithm>
28 
29 namespace otb
30 {
31 template <class TOutputPrecision, class TCoordRep>
33 {
34 }
35 
36 template <class TOutputPrecision, class TCoordRep>
38 {
39  this->ClearFunctions();
40 }
41 
42 template <class TOutputPrecision, class TCoordRep>
44 {
45  m_FunctionContainer.push_back(function);
46 }
47 
48 template <class TOutputPrecision, class TCoordRep>
50 {
51  m_FunctionContainer.clear();
52 }
53 
54 template <class TOutputPrecision, class TCoordRep>
56 {
57  return m_FunctionContainer.size();
58 }
59 
60 template <class TOutputPrecision, class TCoordRep>
62 {
63  return m_FunctionContainer.at(index);
64 }
65 
66 template <class TOutputPrecision, class TCoordRep>
68 {
69  typename FunctionContainerType::iterator fIt = m_FunctionContainer.begin() + index;
70  m_FunctionContainer.erase(fIt);
71 }
72 
73 template <class TOutputPrecision, class TCoordRep>
75 {
76  // Build output
77  OutputType resp;
78 
79  // For each function
80  typename FunctionContainerType::const_iterator fIt = m_FunctionContainer.begin();
81  while (fIt != m_FunctionContainer.end())
82  {
83  // Store current size
84  unsigned int currentSize = static_cast<unsigned int>(resp.GetSize());
85 
86  // Call current function evaluation
87  OutputType currentVector = (*fIt)->Evaluate(point);
88 
89  // Compute current vector size
90  unsigned int currentVectorSize = static_cast<unsigned int>(currentVector.GetSize());
91 
92  // Enlarge the output vector
93  resp.SetSize(currentSize + currentVectorSize, false);
94 
95  // Fill the output
96  for (unsigned int i = 0; i < currentVectorSize; ++i)
97  {
98  resp.SetElement(currentSize + i, static_cast<ValueType>(currentVector[i]));
99  }
100 
101  // Go to next function
102  ++fIt;
103  }
104 
105  return resp;
106 }
107 
108 
109 template <class TOutputPrecision, class TCoordRep>
110 void MetaImageFunction<TOutputPrecision, TCoordRep>::PrintSelf(std::ostream& os, itk::Indent indent) const
111 {
112  Superclass::PrintSelf(os, indent);
113  os << indent << "Number of image functions: " << this->GetNumberOfFunctions() << std::endl;
114 }
115 
116 } // end namespace otb
117 
118 #endif
otbMetaImageFunction.h
otb::MetaImageFunction::Evaluate
OutputType Evaluate(const PointType &point) const override
Definition: otbMetaImageFunction.hxx:74
otb::MetaImageFunction::~MetaImageFunction
~MetaImageFunction() override
Definition: otbMetaImageFunction.hxx:37
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::MetaImageFunction::MetaImageFunction
MetaImageFunction()
Definition: otbMetaImageFunction.hxx:32
otb::MetaImageFunction::RemoveNthFunction
void RemoveNthFunction(unsigned int index)
Definition: otbMetaImageFunction.hxx:67
otb::MetaImageFunction::GetNumberOfFunctions
unsigned int GetNumberOfFunctions() const
Definition: otbMetaImageFunction.hxx:55
otb::MetaImageFunction::PointType
itk::Point< CoordRepType, 2 > PointType
Definition: otbMetaImageFunction.h:65
otbImageFunctionAdaptor.h
otb::MetaImageFunction::OutputType
itk::VariableLengthVector< ValueType > OutputType
Definition: otbMetaImageFunction.h:67
otb::MetaImageFunction::ValueType
TOutputPrecision ValueType
Definition: otbMetaImageFunction.h:66
otb::MetaImageFunction::AddFunction
void AddFunction(FunctionType *function)
Definition: otbMetaImageFunction.hxx:43
otb::MetaImageFunction::FunctionType
Superclass FunctionType
Definition: otbMetaImageFunction.h:70
otb::MetaImageFunction::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbMetaImageFunction.hxx:110
otb::MetaImageFunction::ClearFunctions
void ClearFunctions()
Definition: otbMetaImageFunction.hxx:49
otb::MetaImageFunction::GetNthFunction
FunctionType * GetNthFunction(unsigned int index)
Definition: otbMetaImageFunction.hxx:61