OpendTect-6_4  6.4
array2dfilter.h
Go to the documentation of this file.
1 #ifndef array2dfilter_h
2 #define array2dfilter_h
3 
4 /*@+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert Bril
9  Date: Nov 2006
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 
14 @$*/
15 
16 #include "arrayndimpl.h"
17 #include "statruncalc.h"
18 #include "executor.h"
19 #include "iopar.h"
20 #include "rowcol.h"
21 #include <math.h>
22 
32 {
33 
35  RowCol rc=RowCol(1,1),
36  bool filludf=false )
37  : type_(t)
38  , stepout_(rc)
39  , filludf_(filludf)
40  , rowdist_(mUdf(float))
41  , distfac_(1) {}
42 
43  static const char* sKeyArray2DFilterPars()
44  { return "Array 2D Filter Pars"; }
45  static const char* sKeyFillUndefined() { return "Fill undefined"; }
46  static const char* sKeyRowDistance() { return "Row distance"; }
47  static const char* sKeyDistanceFactor() { return "Distance factor"; }
48 
49  bool fillPar( IOPar& par ) const
50  {
51  IOPar iop;
53  iop.set( sKey::StepOut(), stepout_.row(), stepout_.col() );
55  iop.set( sKeyRowDistance(), rowdist_ );
57  par.mergeComp( iop, sKeyArray2DFilterPars() );
58  return true;
59  }
60 
61  bool usePar( const IOPar& par )
62  {
64  if ( !iop ) return false;
65 
66  Stats::TypeDef().parse( *iop, sKey::Type(), type_ );
67  iop->get( sKey::StepOut(), stepout_.row(), stepout_.col() );
68  iop->getYN( sKeyFillUndefined(), filludf_ );
69  iop->get( sKeyRowDistance(), rowdist_ );
70  iop->get( sKeyDistanceFactor(), distfac_ );
71  return true;
72  }
73 
76  bool filludf_;
77  float rowdist_;
78  float distfac_;
79 
80 };
81 
82 
83 
90 template <class T>
91 mClass(General) Array2DFilterer : public Executor
93 public:
94 
96  inline Array2DFilterer(const Array2D<T>&,
97  Array2D<T>&, const RowCol& origin,
98  const Array2DFilterPars&);
99  inline ~Array2DFilterer();
100 
101  inline void setScope(const Interval<int>& rowrg,
102  const Interval<int>& colrg);
103 
104  inline Array2D<T>& output() { return output_; }
105  inline const Array2D<T>& output() const { return output_; }
106 
107  inline const Array2DFilterPars& pars() const { return pars_; }
108  inline const Stats::RunCalc<float>& calc() const { return *calc_; }
109 
110  inline int nextStep();
111  inline uiString uiMessage() const { return tr("Filtering data"); }
112  inline od_int64 nrDone() const { return nrrowsdone_; }
113  inline uiString uiNrDoneText() const { return tr("Columns handled");}
114  inline od_int64 totalNr() const {return outputrowrg_.width()+1;}
115 
116 protected:
117 
121 
124 
127 
128  const int inputrowsize_;
129  const int inputcolsize_;
130  const int nrcols_;
131  bool linefilt_;
133 
134  inline void filterRow(int);
135  inline void doPoint(int,int);
136 
137 };
138 
139 
140 template <class T> inline
142  : Executor("2D Filtering")
143  , input_( a )
144  , pars_(p)
145  , output_(a)
146  , calc_(0)
147  , inputrowsize_(a.info().getSize(0))
148  , inputcolsize_(a.info().getSize(1))
149  , nrcols_(2 * p.stepout_.col() + 1)
150  , nrrowsdone_(0)
151  , origin_( 0, 0 )
152 {
155 
157  setup.require( pars_.type_ );
158  calc_ = new Stats::RunCalc<float>( setup );
159 }
160 
161 
162 template <class T> inline
164  const RowCol& origin,
165  const Array2DFilterPars& p )
166  : Executor("2D Filtering")
167  , input_( input )
168  , pars_(p)
169  , output_(a)
170  , calc_(0)
171  , inputrowsize_(input.info().getSize(0))
172  , inputcolsize_(input.info().getSize(1))
173  , nrcols_(2 * p.stepout_.col() + 1)
174  , nrrowsdone_(0)
175  , origin_( origin )
176 {
177  outputrowrg_.start = origin.row();
178  outputrowrg_.stop = origin.row()+a.info().getSize(0)-1;
179 
180  outputcolrg_.start = origin.col();
181  outputcolrg_.stop = origin.col()+a.info().getSize(1)-1;
182 
184  setup.require( pars_.type_ );
185  calc_ = new Stats::RunCalc<float>( setup );
186 }
187 
188 
189 template <class T> inline
191 { }
192 
193 
194 template <class T>
196  const Interval<int>& colrg)
197 {
198  outputrowrg_ = rowrg;
199  outputcolrg_ = colrg;
200 }
201 
202 
203 template <class T> inline int Array2DFilterer<T>::nextStep()
204 {
205  if ( !nrrowsdone_ )
206  {
207  if ( !input_.getData() )
208  {
209  ErrMsg("Memory full");
210  return ErrorOccurred();
211  }
212 
213  if ( pars_.stepout_.col()<1 && pars_.stepout_.row()<1 )
214  {
215  ErrMsg("Invalid parameters");
216  return ErrorOccurred();
217  }
218 
219  linefilt_ = pars_.stepout_.row() == 0 || pars_.stepout_.col() == 0;
220  }
221 
222 
223  const int currow = outputrowrg_.start + nrrowsdone_;
224  if ( currow>outputrowrg_.stop )
225  return Executor::Finished();
226 
227  filterRow( currow );
228  nrrowsdone_++;
229  return Executor::MoreToDo();
230 }
231 
232 
233 template <class T> inline void Array2DFilterer<T>::filterRow( int row )
234 {
235  const T* inputptr = pars_.filludf_
236  ? 0
237  : input_.getData() + input_.info().getOffset( row, 0 );
238 
239  if ( inputptr )
240  {
241  for ( int col=outputcolrg_.start; col<=outputcolrg_.stop;
242  col++, inputptr++ )
243  {
244  if ( !mIsUdf(*inputptr) )
245  doPoint( row, col );
246  }
247 
248  return;
249  }
250 
251  for ( int col=outputcolrg_.start; col<=outputcolrg_.stop; col++ )
252  doPoint( row, col );
253 }
254 
255 
256 template <class T>
257 inline void Array2DFilterer<T>::doPoint( int row, int col )
258 {
259  calc_->clear();
260 
261  const bool isweighted = calc_->isWeighted();
262  const int startrow = row - pars_.stepout_.row();
263  int firstrow = startrow;
264  if ( firstrow < 0 ) firstrow = 0;
265  const int endrow = row + pars_.stepout_.row();
266  int lastrow = endrow;
267  if ( lastrow >= inputrowsize_ ) lastrow = inputrowsize_-1;
268 
269  const int startcol = col - pars_.stepout_.col();
270  int firstcol = startcol;
271  if ( firstcol < 0 ) firstcol = 0;
272  const int endcol = col + pars_.stepout_.col();
273  int lastcol = endcol;
274  if ( lastcol >= inputcolsize_ ) lastcol = inputcolsize_-1;
275 
276  for ( int irow=firstrow; irow<=lastrow; irow++ )
277  {
278  const bool issiderow = irow == startrow || irow == endrow;
279  const int rowdist = row-irow;
280  const int rowdist2 = rowdist*rowdist;
281  const bool iscenterrow = irow == row;
282 
283  const T* buf = input_.getData()+input_.info().getOffset(irow,firstcol);
284 
285  for ( int icol=firstcol; icol<=lastcol; icol++, buf++ )
286  {
287  const bool issidecol = icol == startcol || icol == endcol;
288  const bool iscentercol = icol == col;
289 
290  if ( !linefilt_ && ( (issidecol && !iscenterrow )
291  || (issiderow && !iscentercol) ) )
292  continue;
293 
294  if ( isweighted )
295  {
296  const int coldist = icol - col;
297  const int coldist2 = coldist*coldist;
298  float wt = pars_.rowdist_ * rowdist2 + coldist2 ;
299  wt = 1.f / (1 + pars_.distfac_ * wt);
300  calc_->addValue( *buf, wt );
301  }
302  else
303  *calc_ += *buf;
304  }
305  }
306 
307  output_.set( row-origin_.row(), col-origin_.col(),
308  (T) calc_->getValue(pars_.type_));
309 }
310 
311 
312 #endif
IdxType & row()
Definition: posidxpair.h:45
static const char * sKeyDistanceFactor()
Definition: array2dfilter.h:47
int nextStep()
Definition: array2dfilter.h:203
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
FixedString Type()
Definition: keystrs.h:138
int nrrowsdone_
Definition: array2dfilter.h:132
static const char * sKeyRowDistance()
Definition: array2dfilter.h:46
Setup for the Stats::RunCalc and Stats::ParallelCalc objects.
Definition: statruncalc.h:38
IOPar * subselect(const char *) const
returns iopar with key that start with <str>.
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
static int ErrorOccurred()
Definition: task.h:141
od_int64 totalNr() const
Definition: array2dfilter.h:114
bool usePar(const IOPar &par)
Definition: array2dfilter.h:61
void clear()
Definition: statruncalc.h:292
FixedString StepOut()
Definition: keystrs.h:178
#define od_int64
Definition: plftypes.h:36
od_int64 nrDone() const
Definition: array2dfilter.h:112
const Array2D< T > & output() const
Definition: array2dfilter.h:105
Implementation of Array2D.
Definition: arrayndimpl.h:102
Stats::RunCalc< float > * calc_
Definition: array2dfilter.h:120
void filterRow(int)
Definition: array2dfilter.h:233
Definition: uistring.h:89
static int MoreToDo()
Definition: task.h:143
double getValue(Type) const
Definition: statruncalc.h:302
RunCalc< T > & addValue(T data, T weight=1)
Definition: statruncalc.h:595
bool get(const char *, int &) const
bool linefilt_
Definition: array2dfilter.h:131
Array2DFilterPars(Stats::Type t=Stats::Average, RowCol rc=RowCol(1, 1), bool filludf=false)
Definition: array2dfilter.h:34
const int inputrowsize_
Definition: array2dfilter.h:128
const Array2DFilterPars & pars() const
Definition: array2dfilter.h:107
Type
Definition: stattype.h:21
void setScope(const Interval< int > &rowrg, const Interval< int > &colrg)
Definition: array2dfilter.h:195
virtual int getSize(int dim) const =0
static int Finished()
Definition: task.h:142
void ErrMsg(const char *, bool progr=false)
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:47
Array2D ( Subclass of ArrayND ) is a two dimensional array.
Definition: arraynd.h:131
void mergeComp(const IOPar &, const char *)
merge entries, where IOPar&#39;s entries get a prefix
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
Stats::Type type_
Definition: array2dfilter.h:74
~Array2DFilterer()
Definition: array2dfilter.h:190
RowCol origin_
Definition: array2dfilter.h:123
bool fillPar(IOPar &par) const
Definition: array2dfilter.h:49
Definition: stattype.h:24
void setYN(const char *, bool)
Array2D< T > & output_
Definition: array2dfilter.h:118
Array2D< T > & output()
Definition: array2dfilter.h:104
Array2DFilterPars pars_
Definition: array2dfilter.h:119
Interval< int > outputcolrg_
Definition: array2dfilter.h:126
Interval< int > outputrowrg_
Definition: array2dfilter.h:125
Array2DFilterer(Array2D< T > &, const Array2DFilterPars &)
Definition: array2dfilter.h:141
const Stats::RunCalc< float > & calc() const
Definition: array2dfilter.h:108
IdxPair used for its row() and col().
Definition: rowcol.h:25
const int inputcolsize_
Definition: array2dfilter.h:129
T stop
Definition: ranges.h:93
IdxType & col()
Definition: posidxpair.h:50
void doPoint(int, int)
Definition: array2dfilter.h:257
CalcSetup & require(Type)
RowCol stepout_
In nodes. Center point not counted.
Definition: array2dfilter.h:75
Parameters for Array2DFilterer.
Definition: array2dfilter.h:31
T start
Definition: ranges.h:92
static const char * sKeyFillUndefined()
Definition: array2dfilter.h:45
uiString uiNrDoneText() const
will be nrDoneText() in 7.x
Definition: array2dfilter.h:113
float distfac_
if weigthed, distance factor
Definition: array2dfilter.h:78
uiString uiMessage() const
will be message() again in 7.x
Definition: array2dfilter.h:111
#define mClass(module)
Definition: commondefs.h:164
static const char * sKeyArray2DFilterPars()
Definition: array2dfilter.h:43
virtual const Array2DInfo & info() const =0
void set(const char *ky, const char *val)
float rowdist_
non-undef = weighted filter
Definition: array2dfilter.h:77
bool isWeighted() const
Definition: statruncalc.h:108
const int nrcols_
Definition: array2dfilter.h:130
Export_Basic const char * toString(ViewStyle)
bool getYN(const char *, bool &) const
bool filludf_
Output when center point is undef?
Definition: array2dfilter.h:76
Filters an Array2D.
Definition: array2dfilter.h:91
Specification to enable chunkwise execution of a process.
Definition: executor.h:39
Definition: ptrman.h:101
Array2DImpl< T > input_
Definition: array2dfilter.h:122

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