OTB  9.0.0
Orfeo Toolbox
otbVectorPrediction.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 otbVectorPrediction_h
22 #define otbVectorPrediction_h
23 
24 #include "otbWrapperApplication.h"
26 
28 #include "otbOGRFeatureWrapper.h"
29 
30 #include "itkVariableLengthVector.h"
32 
33 #include "itkListSample.h"
35 
37 
39 
40 #include <time.h>
41 
42 namespace otb
43 {
44 namespace Wrapper
45 {
46 
47 template <bool RegressionMode>
49 {
50 public:
54  using Pointer = itk::SmartPointer<Self>;
55  using ConstPointer = itk::SmartPointer<const Self>;
56 
58  itkNewMacro(Self);
59 
60  itkTypeMacro(Self, Application)
61 
62 
63  using ValueType = float;
64  // Label type is float for regression and unsigned int for classification
65  using LabelType = typename std::conditional<RegressionMode, float, unsigned int>::type;
66 
67  using LabelSampleType = itk::FixedArray<LabelType, 1>;
68  using LabelListSampleType = itk::Statistics::ListSample<LabelSampleType>;
69 
74 
76  using MeasurementType = itk::VariableLengthVector<ValueType>;
78 
79  using InputSampleType = itk::VariableLengthVector<ValueType>;
80  using ListSampleType = itk::Statistics::ListSample<InputSampleType>;
81  using ShiftScaleFilterType = otb::Statistics::ShiftScaleSampleListFilter<ListSampleType, ListSampleType>;
82 
83  ~VectorPrediction() override
84  {
86  }
87 
88 private:
89  void DoInit() override;
90 
92  void DoInitSpecialization();
93 
94  void DoUpdateParameters() override;
95 
96  void DoExecute() override;
97 
99  bool shouldComputeConfidenceMap() const;
100 
102  typename ListSampleType::Pointer ReadInputListSample(otb::ogr::Layer const& layer);
103 
105  typename ListSampleType::Pointer NormalizeListSample(ListSampleType::Pointer input);
106 
109  ogr::DataSource::Pointer buffer);
110 
113 
117  void AddPredictionField(otb::ogr::Layer& outLayer, otb::ogr::Layer const& layer, bool computeConfidenceMap);
118 
120  void FillOutputLayer(otb::ogr::Layer& outLayer, otb::ogr::Layer const& layer, typename LabelListSampleType::Pointer target,
121  typename ConfidenceListSampleType::Pointer quality, bool updateMode, bool computeConfidenceMap);
122 
124 
126  std::string confFieldName = "confidence";
127 };
128 }
129 }
130 
131 #ifndef OTB_MANUAL_INSTANTIATION
132 #include "otbVectorPrediction.hxx"
133 #endif
134 
135 #endif
otb::MachineLearningModelFactory::CleanFactories
static void CleanFactories()
Definition: otbMachineLearningModelFactory.hxx:127
otb::Wrapper::Application
This class represent an application TODO.
Definition: otbWrapperApplication.h:76
otb::MachineLearningModelFactory
Creation of object instance using object factory.
Definition: otbMachineLearningModelFactory.h:35
otb::Wrapper::Application::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbWrapperApplication.h:82
otbStatisticsXMLFileReader.h
otbVectorPrediction.hxx
otb::Wrapper::VectorPrediction::ReadInputListSample
ListSampleType::Pointer ReadInputListSample(otb::ogr::Layer const &layer)
Definition: otbVectorPrediction.hxx:80
otb::Wrapper::VectorPrediction::DoInit
void DoInit() override
Definition: otbVectorPrediction.hxx:32
otb::Wrapper::VectorPrediction
Definition: otbVectorPrediction.h:48
otb::Wrapper::VectorPrediction::m_Model
ModelPointerType m_Model
Definition: otbVectorPrediction.h:123
otbWrapperApplication.h
otb::Wrapper::VectorPrediction::FillOutputLayer
void FillOutputLayer(otb::ogr::Layer &outLayer, otb::ogr::Layer const &layer, typename LabelListSampleType::Pointer target, typename ConfidenceListSampleType::Pointer quality, bool updateMode, bool computeConfidenceMap)
Definition: otbVectorPrediction.hxx:239
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Wrapper::VectorPrediction::ListSampleType
itk::Statistics::ListSample< InputSampleType > ListSampleType
Definition: otbVectorPrediction.h:80
otb::Wrapper::VectorPrediction::LabelType
typename std::conditional< RegressionMode, float, unsigned int >::type LabelType
Definition: otbVectorPrediction.h:65
otbWrapperApplicationFactory.h
otb::Wrapper::VectorPrediction::DoUpdateParameters
void DoUpdateParameters() override
Definition: otbVectorPrediction.hxx:46
otb::Wrapper::VectorPrediction::DoExecute
void DoExecute() override
Definition: otbVectorPrediction.hxx:280
otb::Wrapper::VectorPrediction::AddPredictionField
void AddPredictionField(otb::ogr::Layer &outLayer, otb::ogr::Layer const &layer, bool computeConfidenceMap)
Definition: otbVectorPrediction.hxx:199
otb::Wrapper::Application::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbWrapperApplication.h:83
otbMachineLearningModel.h
otb::Wrapper::VectorPrediction::ReopenDataSourceInUpdateMode
otb::ogr::DataSource::Pointer ReopenDataSourceInUpdateMode(ogr::DataSource::Pointer source, ogr::Layer &layer, ogr::DataSource::Pointer buffer)
Definition: otbVectorPrediction.hxx:165
otb::Statistics::ShiftScaleSampleListFilter
This class generate a shifted and scaled version of the input sample list.
Definition: otbShiftScaleSampleListFilter.h:51
otb::Wrapper::Application::Application
Application()
otb::Wrapper::VectorPrediction::confFieldName
std::string confFieldName
Definition: otbVectorPrediction.h:126
otb::ogr::DataSource::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbOGRDataSourceWrapper.h:90
otbMachineLearningModelFactory.h
otb::Wrapper::VectorPrediction::NormalizeListSample
ListSampleType::Pointer NormalizeListSample(ListSampleType::Pointer input)
Definition: otbVectorPrediction.hxx:127
otb::StatisticsXMLFileReader
Read a xml file where are stored several statistics.
Definition: otbStatisticsXMLFileReader.h:42
otb::Wrapper::VectorPrediction::InputSampleType
itk::VariableLengthVector< ValueType > InputSampleType
Definition: otbVectorPrediction.h:79
otb::MachineLearningModel
MachineLearningModel is the base class for all classifier objects (SVM, KNN, Random Forests,...
Definition: otbMachineLearningModel.h:70
otb::Wrapper::VectorPrediction::LabelListSampleType
itk::Statistics::ListSample< LabelSampleType > LabelListSampleType
Definition: otbVectorPrediction.h:68
itk
Definition: otbNoDataHelper.h:31
otb::Wrapper::Application::Superclass
itk::Object Superclass
Definition: otbWrapperApplication.h:81
otb::Wrapper::VectorPrediction::LabelSampleType
itk::FixedArray< LabelType, 1 > LabelSampleType
Definition: otbVectorPrediction.h:67
otb::Wrapper::VectorPrediction::MeasurementType
itk::VariableLengthVector< ValueType > MeasurementType
Definition: otbVectorPrediction.h:76
otb::Wrapper::VectorPrediction::ValueType
float ValueType
Definition: otbVectorPrediction.h:63
otb::Wrapper::VectorPrediction::DoInitSpecialization
void DoInitSpecialization()
otb::Wrapper::VectorPrediction::ModelPointerType
typename MachineLearningModelType::Pointer ModelPointerType
Definition: otbVectorPrediction.h:72
otb::ogr::Layer
Layer of geometric objects.
Definition: otbOGRLayerWrapper.h:80
otb::Wrapper::VectorPrediction::CreateOutputDataSource
otb::ogr::DataSource::Pointer CreateOutputDataSource(ogr::Layer &layer)
Definition: otbVectorPrediction.hxx:182
otb::Wrapper::VectorPrediction::ConfidenceListSampleType
typename MachineLearningModelType::ConfidenceListSampleType ConfidenceListSampleType
Definition: otbVectorPrediction.h:73
otbOGRFeatureWrapper.h
otbOGRDataSourceWrapper.h
otb::Wrapper::VectorPrediction::shouldComputeConfidenceMap
bool shouldComputeConfidenceMap() const
otbShiftScaleSampleListFilter.h