OTB  7.1.0
Orfeo Toolbox
otbModelComponentBase.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2007-2012 Institut Mines Telecom / Telecom Bretagne
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbModelComponentBase_hxx
23 #define otbModelComponentBase_hxx
24 
25 #include <iostream>
26 
27 #include "otbMacro.h"
28 #include "otbModelComponentBase.h"
29 
30 namespace otb
31 {
32 namespace Statistics
33 {
34 
35 template <class TSample>
37 {
38  m_Sample = nullptr;
39  m_PdfFunction = nullptr;
40  m_CdfFunction = nullptr;
41  m_SampleModified = 0;
42 }
43 
44 template <class TSample>
45 void ModelComponentBase<TSample>::PrintSelf(std::ostream& os, itk::Indent indent) const
46 {
47  Superclass::PrintSelf(os, indent);
48 
49  os << indent << "Sample: ";
50  if (m_Sample != nullptr)
51  {
52  os << m_Sample << std::endl;
53  }
54  else
55  {
56  os << "not set." << std::endl;
57  }
58 
59  os << indent << "Membership Function for pdf: ";
60  if (m_PdfFunction != nullptr)
61  {
62  os << m_PdfFunction << std::endl;
63  }
64  else
65  {
66  os << "not instantiated yet." << std::endl;
67  }
68 
69  os << indent << "Membership Function for cdf: ";
70  if (m_CdfFunction != nullptr)
71  {
72  os << m_CdfFunction << std::endl;
73  }
74  else
75  {
76  os << "not instantiated yet." << std::endl;
77  }
78 
79  os << indent << "Sample are modified and parameters updated: ";
80  os << m_SampleModified << std::endl;
81 }
82 
83 template <class TSample>
84 void ModelComponentBase<TSample>::ShowParameters(std::ostream& os, itk::Indent indent) const
85 {
86  os << indent << "Generic class of model-component. Parameters :\n";
87  for (unsigned int i = 0; i < m_Parameters.Size(); ++i)
88  os << indent << m_Parameters[i] << "\n";
89 }
90 
91 template <class TSample>
92 void ModelComponentBase<TSample>::SetSample(const TSample* sample)
93 {
94  m_Sample = sample;
95  m_SampleModified = 1;
96 }
97 
98 template <class TSample>
100 {
101  return m_Sample;
102 }
103 
104 template <class TSample>
106 {
107  if (m_Parameters != parameters)
108  m_Parameters = parameters;
109 }
110 
111 template <class TSample>
113 {
114  m_PdfFunction = function;
115 }
116 
117 template <class TSample>
119 {
120  m_CdfFunction = function;
121 }
122 
123 template <class TSample>
125 {
126  return m_PdfFunction;
127 }
128 
129 template <class TSample>
131 {
132  return m_CdfFunction;
133 }
134 
135 template <class TSample>
137 {
138  return this->m_PdfFunction->Evaluate(measurements);
139 }
140 
141 template <class TSample>
143 {
144  return m_CdfFunction->Evaluate(measurements);
145 }
146 
147 template <class TSample>
149 {
150  return m_SampleModified;
151 }
152 
153 template <class TSample>
155 {
156  if (m_SampleModified)
157  this->GenerateData();
158  m_SampleModified = 0;
159 }
160 
161 template <class TSample>
163 {
168  m_SampleModified = 0;
169 }
170 
171 } // end of namespace Statistics
172 } // end of namespace otb
173 
174 #endif
virtual void SetSample(const TSample *sample)
void SetParameters(const ParametersType &parameters)
virtual void ShowParameters(std::ostream &os, itk::Indent indent) const
MembershipFunctionType * GetCdfMembershipFunction()
void PrintSelf(std::ostream &os, itk::Indent indent) const override
double Pdf(MeasurementVectorType &measurements)
TSample::MeasurementVectorType MeasurementVectorType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
void SetCdfMembershipFunction(MembershipFunctionType *function)
double Cdf(MeasurementVectorType &measurements)
itk::Statistics::MembershipFunctionBase< MeasurementVectorType > MembershipFunctionType
void SetPdfMembershipFunction(MembershipFunctionType *function)
MembershipFunctionType * GetPdfMembershipFunction()