OTB  6.7.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>
38 {
39  m_Sample = nullptr;
40  m_PdfFunction = nullptr;
41  m_CdfFunction = nullptr;
42  m_SampleModified = 0;
43 }
44 
45 template<class TSample>
46 void
48 ::PrintSelf(std::ostream& os, itk::Indent indent) const
49 {
50  Superclass::PrintSelf(os, indent);
51 
52  os << indent << "Sample: ";
53  if (m_Sample != nullptr)
54  {
55  os << m_Sample << std::endl;
56  }
57  else
58  {
59  os << "not set." << std::endl;
60  }
61 
62  os << indent << "Membership Function for pdf: ";
63  if (m_PdfFunction != nullptr)
64  {
65  os << m_PdfFunction << std::endl;
66  }
67  else
68  {
69  os << "not instantiated yet." << std::endl;
70  }
71 
72  os << indent << "Membership Function for cdf: ";
73  if (m_CdfFunction != nullptr)
74  {
75  os << m_CdfFunction << std::endl;
76  }
77  else
78  {
79  os << "not instantiated yet." << std::endl;
80  }
81 
82  os << indent << "Sample are modified and parameters updated: ";
83  os << m_SampleModified << std::endl;
84 }
85 
86 template <class TSample>
87 void
89 ::ShowParameters(std::ostream& os, itk::Indent indent) const
90 {
91  os << indent << "Generic class of model-component. Parameters :\n";
92  for (unsigned int i = 0; i < m_Parameters.Size(); ++i)
93  os << indent << m_Parameters[i] << "\n";
94 }
95 
96 template<class TSample>
97 void
99 ::SetSample(const TSample* sample)
100 {
101  m_Sample = sample;
102  m_SampleModified = 1;
103 }
104 
105 template<class TSample>
106 const TSample*
108 ::GetSample() const
109 {
110  return m_Sample;
111 }
112 
113 template<class TSample>
114 void
116 ::SetParameters(const ParametersType& parameters)
117 {
118  if (m_Parameters != parameters) m_Parameters = parameters;
119 }
120 
121 template<class TSample>
122 void
125 {
126  m_PdfFunction = function;
127 }
128 
129 template<class TSample>
130 void
133 {
134  m_CdfFunction = function;
135 }
136 
137 template<class TSample>
141 {
142  return m_PdfFunction;
143 }
144 
145 template<class TSample>
149 {
150  return m_CdfFunction;
151 }
152 
153 template<class TSample>
154 inline double
157 {
158  return this->m_PdfFunction->Evaluate(measurements);
159 }
160 
161 template<class TSample>
162 inline double
165 {
166  return m_CdfFunction->Evaluate(measurements);
167 }
168 
169 template <class TSample>
170 int
173 {
174  return m_SampleModified;
175 }
176 
177 template<class TSample>
178 void
181 {
182  if (m_SampleModified) this->GenerateData();
183  m_SampleModified = 0;
184 }
185 
186 template <class TSample>
187 void
190 {
195  m_SampleModified = 0;
196 }
197 
198 } // end of namespace Statistics
199 } // end of namespace otb
200 
201 #endif
virtual void SetSample(const TSample *sample)
void SetParameters(const ParametersType &parameters)
MembershipFunctionType * GetCdfMembershipFunction()
void PrintSelf(std::ostream &os, itk::Indent indent) const override
double Pdf(MeasurementVectorType &measurements)
TSample::MeasurementVectorType MeasurementVectorType
virtual void ShowParameters(std::ostream &os, itk::Indent indent) const
void SetCdfMembershipFunction(MembershipFunctionType *function)
double Cdf(MeasurementVectorType &measurements)
void SetPdfMembershipFunction(MembershipFunctionType *function)
MembershipFunctionType * GetPdfMembershipFunction()