Ilwis-Objects  1.0
GIS and Remote Sensing framework for data access and processing
 All Classes Functions Enumerations Pages
operationhelpergrid.h
1 #ifndef OPERATIONHELPERRASTER_H
2 #define OPERATIONHELPERRASTER_H
3 
4 namespace Ilwis {
5 
6 typedef std::function<bool(const BoundingBox&)> BoxedAsyncFunc;
7 
8 class KERNELSHARED_EXPORT OperationHelperRaster
9 {
10 public:
12  static BoundingBox initialize(const IRasterCoverage &inputRaster, IRasterCoverage &outputRaster, const Ilwis::Parameter &parm, quint64 what);
13  static int subdivideTasks(ExecutionContext *ctx,const IRasterCoverage& raster, const BoundingBox& bounds, std::vector<BoundingBox > &boxes);
14  static bool resample(IRasterCoverage& input1, IRasterCoverage& input2, ExecutionContext *ctx);
15 
16  template<typename T> static bool execute(ExecutionContext* ctx, T func, IRasterCoverage& outputRaster, const BoundingBox& bounds=BoundingBox()) {
17  std::vector<BoundingBox> boxes;
18 
19  int cores = OperationHelperRaster::subdivideTasks(ctx,outputRaster,bounds, boxes);
20 
21  if ( cores == iUNDEF)
22  return false;
23 
24  std::vector<std::future<bool>> futures(cores);
25  bool res = true;
26 
27  for(int i =0; i < cores; ++i) {
28  futures[i] = std::async(std::launch::async, func, boxes[i]);
29  }
30 
31  for(int i =0; i < cores; ++i) {
32  res &= futures[i].get();
33  }
34 
35  if ( res && outputRaster.isValid()) {
36  if ( outputRaster->datadef().domain()->valueType() & itNUMERIC) {
37  NumericStatistics stats;
38  PixelIterator iter(outputRaster);
39  stats.calculate(iter, iter.end());
40  NumericRange *rng = new NumericRange(stats[NumericStatistics::pMIN], stats[NumericStatistics::pMAX], std::pow(10,-stats.significantDigits()));
41  outputRaster->datadef().range(rng);
42  }
43  }
44  return res;
45  }
46  static IIlwisObject initialize(const IIlwisObject &inputObject, IlwisTypes tp, quint64 what);
47 };
48 }
49 
50 #endif // OPERATIONHELPER_H