OpendTect-6_4  6.4
arrayndstacker.h
Go to the documentation of this file.
1 #ifndef arrayndstacker_h
2 #define arrayndstacker_h
3 
4 /*+
5 
6 ________________________________________________________________________
7 
8  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
9  Author: Arnaud Huck
10  Date: Nov 2013
11  RCS: $Id:
12 ________________________________________________________________________
13 
14 -*/
15 
16 #include "algomod.h"
17 #include "arraynd.h"
18 #include "paralleltask.h"
19 
26 template <class fT,class ArrT >
28 {
29 public:
30 
32  ArrT& out )
33  : inp_(inp)
34  , out_(out)
35  , totalnr_(-1)
36  , normalize_(false)
37  {
38  if ( !inp.isEmpty() && inp[0] )
39  totalnr_ = inp[0]->info().getTotalSz();
40  }
41 
42  bool doPrepare( int nrthreads )
43  {
44  if ( totalnr_ < 1 )
45  return false;
46 
47  for ( int iarr=1; iarr<inp_.size(); iarr++ )
48  {
49  if ( !inp_[iarr] )
50  continue;
51 
52  if ( inp_[iarr]->info().getTotalSz() > totalnr_ )
53  totalnr_ = inp_[iarr]->info().getTotalSz();
54  }
55 
56  out_.setSize( totalnr_ );
57  if ( !out_.getData() )
58  {
59  msg_ = "Cannot stack this type of object";
60  return false;
61  }
62 
63  out_.setAll( 0 );
64  return true;
65  }
66 
67  bool doWork( od_int64 start, od_int64 stop, int threadidx )
68  {
69  fT* outarr = out_.getData();
70  int count = 0;
71  for ( od_int64 idx=start; idx<=stop; idx++ )
72  {
73  fT& outval = outarr[idx];
74  for ( int iarr=0; iarr<inp_.size(); iarr++ )
75  {
76  if ( !inp_[iarr] ) continue;
77  const fT* inparr = inp_[iarr]->getData();
78  if ( !inparr ||
79  idx >= inp_[iarr]->info().getTotalSz() )
80  continue;
81 
82  const fT val = inparr[idx];
83  if ( !mIsUdf(val) )
84  {
85  outval += val;
86  count++;
87  }
88  }
89 
90  if ( normalize_ && count )
91  outval /= count;
92  }
93 
94  return true;
95  }
96 
97  od_int64 nrIterations() const { return totalnr_; }
98  void doNormalize( bool normalize ) { normalize_ = normalize; }
99  const char* errMsg() const { return msg_.str(); }
100 
101 protected:
102 
105  ArrT& out_;
108 
109 };
110 
111 
112 //TODO implement the ND version
113 
114 #endif
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
Array1DStacker(const ObjectSet< ArrT > &inp, ArrT &out)
Definition: arrayndstacker.h:31
OD::String that holds an existing text string.
Definition: fixedstring.h:29
#define od_int64
Definition: plftypes.h:36
FixedString msg_
Definition: arrayndstacker.h:107
void doNormalize(bool normalize)
Definition: arrayndstacker.h:98
bool isEmpty() const
Definition: odset.h:45
bool normalize_
Definition: arrayndstacker.h:106
Generalization of a task that can be run in parallel.
Definition: paralleltask.h:66
od_int64 nrIterations() const
Definition: arrayndstacker.h:97
const char * errMsg() const
Definition: arrayndstacker.h:99
bool doWork(od_int64 start, od_int64 stop, int threadidx)
Definition: arrayndstacker.h:67
out_[idx]
Definition: arrayndalgo.h:1702
bool doPrepare(int nrthreads)
Definition: arrayndstacker.h:42
ArrT & out_
Definition: arrayndstacker.h:105
Gently stacks ArrayND by summation along the secondary axis Currently implemented only 1D...
Definition: arrayndstacker.h:27
const ObjectSet< ArrT > & inp_
Definition: arrayndstacker.h:104
#define mClass(module)
Definition: commondefs.h:164
od_int64 totalnr_
Definition: arrayndstacker.h:103

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019