OTB  10.0.0
Orfeo Toolbox
otbQuadraticallyConstrainedSimpleSolver.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
4  * Copyright (C) 2016-2019 IRSTEA
5  *
6  * This file is part of Orfeo Toolbox
7  *
8  * https://www.orfeo-toolbox.org/
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 #ifndef QuadraticallyConstrainedSimpleSolver_H_
23 #define QuadraticallyConstrainedSimpleSolver_H_
24 
25 #include "itkObjectFactory.h"
26 #include "itkLightObject.h"
27 #include "itkNumericTraits.h"
28 #include <vnl/vnl_matrix.h>
29 #include "vnl/algo/vnl_solve_qp.h"
30 
31 namespace otb
32 {
33 
65 template <class ValueType>
66 class ITK_EXPORT QuadraticallyConstrainedSimpleSolver : public itk::LightObject
67 {
68 public:
71  typedef itk::LightObject Superclass;
72  typedef itk::SmartPointer<Self> Pointer;
73  typedef itk::SmartPointer<const Self> ConstPointer;
74 
76  itkTypeMacro(QuadraticallyConstrainedSimpleSolver, LightObject);
77 
79  itkNewMacro(Self);
80 
82  typedef vnl_matrix<ValueType> RealMatrixType;
83  typedef vnl_vector<ValueType> RealVectorType;
84  typedef vnl_matrix<double> DoubleMatrixType;
85  typedef vnl_vector<double> DoubleVectorType;
86  typedef std::vector<unsigned int> ListIndexType;
87 
90  {
91  Cost_Function_rmse, // Root mean square error based
92  Cost_Function_musig, // Mean and standard deviation based
93  Cost_Function_mu, // Mean based
94  Cost_Function_weighted_musig // Mean and weighted standard deviation based
95  };
96 
98  void SetMeanInOverlaps(const RealMatrixType& matrix)
99  {
100  m_MeanInOverlaps = RealMatrixType(matrix);
101  }
103  {
104  return m_MeanInOverlaps;
105  }
107 
110  {
111  m_StandardDeviationInOverlaps = RealMatrixType(matrix);
112  }
114  {
115  return m_StandardDeviationInOverlaps;
116  }
118 
120  void SetAreaInOverlaps(const RealMatrixType& matrix)
121  {
122  m_AreaInOverlaps = RealMatrixType(matrix);
123  }
125  {
126  return m_AreaInOverlaps;
127  }
129 
132  {
133  m_MeanOfProductsInOverlaps = RealMatrixType(matrix);
134  }
136  {
137  return m_MeanOfProductsInOverlaps;
138  }
140 
143  {
144  return m_OutputCorrectionModel;
145  }
146 
153  void SetWeightOfStandardDeviationTerm(ValueType weight)
154  {
155  m_WeightOfStandardDeviationTerm = weight;
156  }
158  {
159  return m_WeightOfStandardDeviationTerm;
160  }
162 
164  void Solve();
165 
168  {
169  oft = Cost_Function_mu;
170  }
172  {
173  oft = Cost_Function_musig;
174  }
176  {
177  oft = Cost_Function_rmse;
178  }
180  {
181  oft = Cost_Function_weighted_musig;
182  }
184 
185 protected:
188 
189 private:
190  // Check inputs
191  void CheckInputs(void) const;
192 
193  // Deep First Search
194  void DFS(std::vector<bool>& marked, unsigned int s) const;
195 
196  // Compute the objective matrix
197  const DoubleMatrixType GetQuadraticObjectiveMatrix(const DoubleMatrixType& areas, const DoubleMatrixType& means, const DoubleMatrixType& stds,
198  const DoubleMatrixType& mops);
199 
200  // Extract a sub matrix from indices list
201  const DoubleMatrixType ExtractMatrix(const RealMatrixType& mat, const ListIndexType& idx);
202 
203  // Input
208 
209  // Params
210  ValueType m_WeightOfStandardDeviationTerm; // could be manually tuned for different results
211 
212  // Output correction models
214 
215  // objective function type (enum)
217 };
218 
219 } /* namespace otb */
220 #ifndef OTB_MANUAL_INSTANTIATION
222 #endif
223 #endif /* QuadraticallyConstrainedSimpleSolver_H_ */
Solves the optimisation problem for radiometric harmonisation of multiple overlapping images.
void Solve(const GCPsContainerType &gcpContainer, double &rmsError, Projection::RPCParam &outputParams)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.