OTB  10.0.0
Orfeo Toolbox
otbPatternSampler.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 otbPatternSampler_h
22 #define otbPatternSampler_h
23 
24 #include "otbSamplerBase.h"
25 #include "OTBStatisticsExport.h"
26 #include <string>
27 
28 namespace otb
29 {
30 
40 class OTBStatistics_EXPORT PatternSampler : public SamplerBase
41 {
42 public:
45  typedef itk::SmartPointer<Self> Pointer;
46  typedef itk::SmartPointer<const Self> ConstPointer;
47 
51  typedef struct Parameter
52  {
53 
55  unsigned long MaxPatternSize = 0;
56 
58  std::vector<bool> Pattern1;
59 
62  std::vector<bool> Pattern2;
63 
65  unsigned int Seed = 0;
66 
67  bool operator!=(const struct Parameter& param) const;
69 
71  itkNewMacro(Self);
72 
74  itkTypeMacro(PatternSampler, SamplerBase);
75 
77  void SetParameters(const ParameterType& param)
78  {
79  if (m_Parameters != param)
80  {
81  this->Modified();
82  m_Parameters = param;
83  }
84  }
86 
89  {
90  return m_Parameters;
91  }
92 
96  void Reset(void) override;
97 
102  bool TakeSample(void);
103 
108  static void ImportPatterns(const std::string& data, ParameterType& param);
109 
114  static void ExportPatterns(const ParameterType& param, std::string& data);
115 
116 protected:
119 
121  ~PatternSampler() override
122  {
123  }
124 
125 private:
126  // Not implemented
128  void operator=(const Self&);
129 
131  std::vector<bool> RandArray(unsigned long N, unsigned long T);
132 
134  unsigned long FindBestSize(unsigned long tot);
135 
138 
140  unsigned long m_Index1;
141 
143  unsigned long m_Index2;
144 
149  static unsigned int ParseSymbol(const char& s);
150 };
151 
152 } // namespace otb
153 #endif
Periodic sampler for iteration loops.
std::vector< bool > RandArray(unsigned long N, unsigned long T)
unsigned long FindBestSize(unsigned long tot)
void operator=(const Self &)
itk::SmartPointer< const Self > ConstPointer
itk::SmartPointer< Self > Pointer
void SetParameters(const ParameterType &param)
ParameterType m_Parameters
static void ExportPatterns(const ParameterType &param, std::string &data)
static void ImportPatterns(const std::string &data, ParameterType &param)
ParameterType GetParameters()
PatternSampler(const Self &)
bool TakeSample(void)
void Reset(void) override
static unsigned int ParseSymbol(const char &s)
This is a base class for sampling methods.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
bool operator!=(const struct Parameter &param) const