File: otbSamplingRateCalculatorListTest.cxx

package info (click to toggle)
otb 5.8.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,496 kB
  • ctags: 40,282
  • sloc: cpp: 306,573; ansic: 3,575; python: 450; sh: 214; perl: 74; java: 72; makefile: 70
file content (226 lines) | stat: -rw-r--r-- 7,227 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include "otbSamplingRateCalculatorList.h"

#include "otbStatisticsXMLFileReader.h"
#include "itkVariableLengthVector.h"
#include <fstream>

int otbSamplingRateCalculatorListNew(int itkNotUsed(argc), char* itkNotUsed(argv) [])
{
  typedef otb::SamplingRateCalculatorList RateCalculatorListType;
  
  RateCalculatorListType::Pointer rateCalculator = RateCalculatorListType::New();
  std::cout << rateCalculator << std::endl;
  return EXIT_SUCCESS;
}

int otbSamplingRateCalculatorList(int itkNotUsed(argc), char* argv[])
{
  std::ofstream file(argv[1], std::ios::out | std::ios::trunc);

  if (!file)
    {
    std::cout << " Couldn't open " << argv[1];
    return EXIT_FAILURE;
    }

  itk::Indent indent_1(1);

  typedef otb::SamplingRateCalculatorList::ClassCountMapType  ClassCountMapType;
  typedef otb::SamplingRateCalculatorList::PartitionType      PartitionType;

  PartitionType typeProportional = otb::SamplingRateCalculatorList::PROPORTIONAL;
  PartitionType typeEqual = otb::SamplingRateCalculatorList::EQUAL;
  PartitionType typeCustom = otb::SamplingRateCalculatorList::CUSTOM;

  std::string c1("1");
  std::string c2("2");
  std::string c3("3");
  std::string c4("4");

  ClassCountMapType classCount1, classCount2, classCount3;
  // input 1
  classCount1[c1] = 104;
  classCount1[c2] = 160;
  classCount1[c3] = 211;
  // input 2
  classCount2[c1] = 98;
  classCount2[c2] = 190;
  classCount2[c3] = 178;
  // input 3
  classCount3[c1] = 130;
  classCount3[c2] = 144;
  classCount3[c4] = 250;

  std::vector<unsigned long> nbSamplesCst;
  nbSamplesCst.push_back(151);

  std::vector<double> percent;
  percent.push_back(0.33);

  std::vector<unsigned long> total;
  total.push_back(300);

  std::vector<unsigned long> nbSamplesCstCustom;
  nbSamplesCstCustom.push_back(70);
  nbSamplesCstCustom.push_back(80);
  nbSamplesCstCustom.push_back(90);

  ClassCountMapType needed1;
  needed1[c1] = 140;
  needed1[c2] = 130;
  needed1[c3] = 124;

  std::vector<ClassCountMapType> nbByClass;
  nbByClass.push_back(needed1);

  ClassCountMapType needed2;
  needed2[c1] = 67;
  needed2[c2] = 55;
  needed2[c3] = 72;

  ClassCountMapType needed3;
  needed3[c1] = 77;
  needed3[c2] = 69;
  needed3[c3] = 34;

  ClassCountMapType needed4;
  needed4[c1] = 86;
  needed4[c2] = 43;
  needed4[c4] = 98;

  std::vector<ClassCountMapType> nbByClassCustom;
  nbByClassCustom.push_back(needed2);
  nbByClassCustom.push_back(needed3);
  nbByClassCustom.push_back(needed4);

  typedef otb::SamplingRateCalculatorList RateCalculatorListType;
  RateCalculatorListType::Pointer rateCalcList = RateCalculatorListType::New();
  rateCalcList->SetNthClassCount(0,classCount1);
  rateCalcList->SetNthClassCount(2,classCount3);
  rateCalcList->SetNthClassCount(1,classCount2);

  file << "# Test the strategy : smallest - equal" << std::endl;
  rateCalcList->SetMinimumNbOfSamplesByClass(typeEqual);
  for (unsigned int i=0 ; i<rateCalcList->Size() ; i++)
    {
    file << "# Input "<< i << std::endl;
    rateCalcList->GetNthElement(i)->Print(file, indent_1);
    }

  file << "# Test the strategy : smallest - custom" << std::endl;
  rateCalcList->SetMinimumNbOfSamplesByClass(typeCustom);
  for (unsigned int i=0 ; i<rateCalcList->Size() ; i++)
    {
    file << "# Input "<< i << std::endl;
    rateCalcList->GetNthElement(i)->Print(file, indent_1);
    }

  file << "# Test the strategy : constant - proportional" << std::endl;
  rateCalcList->SetNbOfSamplesAllClasses(nbSamplesCst,typeProportional);
  for (unsigned int i=0 ; i<rateCalcList->Size() ; i++)
    {
    file << "# Input "<< i << std::endl;
    rateCalcList->GetNthElement(i)->Print(file, indent_1);
    }

  file << "# Test the strategy : constant - equal" << std::endl;
  rateCalcList->SetNbOfSamplesAllClasses(nbSamplesCst,typeEqual);
  for (unsigned int i=0 ; i<rateCalcList->Size() ; i++)
    {
    file << "# Input "<< i << std::endl;
    rateCalcList->GetNthElement(i)->Print(file, indent_1);
    }

  file << "# Test the strategy : constant - custom" << std::endl;
  rateCalcList->SetNbOfSamplesAllClasses(nbSamplesCstCustom,typeCustom);
  for (unsigned int i=0 ; i<rateCalcList->Size() ; i++)
    {
    file << "# Input "<< i << std::endl;
    rateCalcList->GetNthElement(i)->Print(file, indent_1);
    }

  file << "# Test the strategy : byClass - proportional" << std::endl;
  rateCalcList->SetNbOfSamplesByClass(nbByClass,typeProportional);
  for (unsigned int i=0 ; i<rateCalcList->Size() ; i++)
    {
    file << "# Input "<< i << std::endl;
    rateCalcList->GetNthElement(i)->Print(file, indent_1);
    }

  file << "# Test the strategy : byClass - equal" << std::endl;
  rateCalcList->SetNbOfSamplesByClass(nbByClass,typeEqual);
  for (unsigned int i=0 ; i<rateCalcList->Size() ; i++)
    {
    file << "# Input "<< i << std::endl;
    rateCalcList->GetNthElement(i)->Print(file, indent_1);
    }

  file << "# Test the strategy : byClass - custom" << std::endl;
  rateCalcList->SetNbOfSamplesByClass(nbByClassCustom,typeCustom);
  for (unsigned int i=0 ; i<rateCalcList->Size() ; i++)
    {
    file << "# Input "<< i << std::endl;
    rateCalcList->GetNthElement(i)->Print(file, indent_1);
    }

  file << "# Test the strategy : all - equal" << std::endl;
  rateCalcList->SetAllSamples(typeEqual);
  for (unsigned int i=0 ; i<rateCalcList->Size() ; i++)
    {
    file << "# Input "<< i << std::endl;
    rateCalcList->GetNthElement(i)->Print(file, indent_1);
    }

  file <<"#Test the strategy : percent - proportional"<<std::endl;
  rateCalcList->SetPercentageOfSamples(percent,typeProportional);
  for (unsigned int i=0 ; i<rateCalcList->Size() ; i++)
    {
    file << "# Input "<< i << std::endl;
    rateCalcList->GetNthElement(i)->Print(file, indent_1);
    }
  
  file <<"#Test the strategy : percent - equal"<<std::endl;
  rateCalcList->SetPercentageOfSamples(percent,typeEqual);
  for (unsigned int i=0 ; i<rateCalcList->Size() ; i++)
    {
    file << "# Input "<< i << std::endl;
    rateCalcList->GetNthElement(i)->Print(file, indent_1);
    }

  file <<"#Test the strategy : total - proportional"<<std::endl;
  rateCalcList->SetTotalNumberOfSamples(total,typeProportional);
  for (unsigned int i=0 ; i<rateCalcList->Size() ; i++)
    {
    file << "# Input "<< i << std::endl;
    rateCalcList->GetNthElement(i)->Print(file, indent_1);
    }
  
  file <<"#Test the strategy : total - equal"<<std::endl;
  rateCalcList->SetTotalNumberOfSamples(total,typeEqual);
  for (unsigned int i=0 ; i<rateCalcList->Size() ; i++)
    {
    file << "# Input "<< i << std::endl;
    rateCalcList->GetNthElement(i)->Print(file, indent_1);
    }
  
  file.close();
  return EXIT_SUCCESS;
}