Ilwis-Objects  1.0
GIS and Remote Sensing framework for data access and processing
 All Classes Functions Enumerations Pages
operationhelperfeatures.h
1 #ifndef OPERATIONHELPERFEATURES_H
2 #define OPERATIONHELPERFEATURES_H
3 
4 namespace Ilwis {
5 
6 typedef std::function<bool(const std::vector<quint32>&)> SubSetAsyncFunc;
7 
8 class KERNELSHARED_EXPORT OperationHelperFeatures
9 {
10 public:
12  static IIlwisObject initialize(const IIlwisObject &inputObject, IlwisTypes tp, quint64 what);
13  static int subdivideTasks(ExecutionContext *ctx, const IFeatureCoverage& raster, std::vector<std::vector<quint32> > &subsets);
14  template<typename T> static bool execute(ExecutionContext* ctx, T func, IFeatureCoverage& inputFC, IFeatureCoverage& outputFC){
15  std::vector<std::vector<quint32>> subsets;
16 
17  int cores = OperationHelperFeatures::subdivideTasks(ctx,inputFC, subsets);
18  if ( cores == iUNDEF)
19  return false;
20 
21  std::vector<std::future<bool>> futures(cores);
22  bool res = true;
23 
24  for(int i =0; i < cores; ++i) {
25  futures[i] = std::async(std::launch::async, func, subsets[i]);
26  }
27 
28  for(int i =0; i < cores; ++i) {
29  res &= futures[i].get();
30  }
31 
32  return true;
33  }
34 
35  template<typename T> static bool execute(ExecutionContext* ctx, T func, IFeatureCoverage& inputFC, IFeatureCoverage& outputFC, ITable& tbl){
36  std::vector<std::vector<quint32>> subsets;
37 
38  int cores = OperationHelperFeatures::subdivideTasks(ctx,inputFC, subsets);
39  if ( cores == iUNDEF)
40  return false;
41 
42  std::vector<std::future<bool>> futures(cores);
43  bool res = true;
44 
45  for(int i =0; i < cores; ++i) {
46  futures[i] = std::async(std::launch::async, func, subsets[i]);
47  }
48 
49  for(int i =0; i < cores; ++i) {
50  res &= futures[i].get();
51  }
52 
53  if ( res && outputFC.isValid()) {
54  //TODO: better handling for multiple feature types
55  if ( !tbl.isValid())
56  return false;
57  for(int i=0; i < tbl->columnCount(); ++i ){
58  ColumnDefinition& def = tbl->columndefinition(i);
59  if ( def.datadef().domain()->valueType() & itNUMERIC) {
61  std::vector<QVariant> values = tbl->column(i);
62  std::vector<double> vec(values.size());
63  for(int i=0; i < vec.size(); ++i) {
64  vec[i] = values[i].toDouble();
65  }
66  stats.calculate(vec.begin(), vec.end());
67  NumericRange *rng = new NumericRange(stats[NumericStatistics::pMIN], stats[NumericStatistics::pMAX], std::pow(10,-stats.significantDigits()));
68  def.datadef().range(rng);
69  }
70  }
71  }
72  return true;
73  }
74 };
75 }
76 
77 #endif // OPERATIONHELPERFEATURES_H