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

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