OpendTect-6_4  6.4
smoother3d.h
Go to the documentation of this file.
1 #ifndef smoother3d_h
2 #define smoother3d_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: K. Tingdahl
9  Date: Feb 2008
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "task.h"
16 #include "convolve3d.h"
17 #include "arrayndimpl.h"
18 #include "iopar.h"
19 #include "coord.h"
20 #include "windowfunction.h"
21 
26 template <class T>
27 mClass(Algo) Smoother3D : public Task
28 {
29 public:
30 
31  Smoother3D();
32 
33  void setInput(const Array3D<T>&);
34  void setOutput(Array3D<T>&);
36  bool setWindow(const char* nm,float param,
37  int sz0,int sz1,int sz2);
38  int getWindowSize(int dim) const;
39  const char* getWindowName() const;
40  float getWindowParam() const;
41 
42  inline void fillPar(IOPar&) const;
43  inline bool usePar(const IOPar&);
44 
45  inline void setProgressMeter( ProgressMeter* pm );
46  inline bool execute();
47  inline void enableWorkControl(bool);
48  inline void controlWork(Task::Control);
49  inline Task::Control getState() const;
50 
51  static const char* sKeyWinFunc() { return "Window function"; }
52  static const char* sKeyWinParam() { return "Window parameter"; }
53  static const char* sKeyWinSize() { return "Window size"; }
54 
55 protected:
56 
58 
61  float windowparam_;
62 };
63 
64 
65 template <class T> inline
67  : windowparam_( mUdf(float) )
68  , window_( 1, 1, 1 )
69 {
70  convolver_.setNormalize( true );
71  convolver_.setCorrelate( false );
72  window_.set( 0, 0, 0, 1 );
73 }
74 
75 
76 template <class T> inline
77 int Smoother3D<T>::getWindowSize(int dim) const
78 { return window_.info().getSize( dim ); }
79 
80 
81 template <class T> inline
82 const char* Smoother3D<T>::getWindowName() const
83 { return windowname_.buf(); }
84 
85 
86 template <class T> inline
88 { return windowparam_; }
89 
90 
91 template <class T> inline
93 {
94  convolver_.setX( ni, 0, 0, 0 );
95 }
96 
97 
98 template <class T> inline
100 {
101  convolver_.setZ( no );
102 }
103 
104 
105 template <class T> inline
106 bool Smoother3D<T>::setWindow( const char* nm, float param,
107  int sz0, int sz1, int sz2 )
108 {
109  PtrMan<WindowFunction> wf = WINFUNCS().create( nm );
110  if ( !wf )
111  return false;
112 
113  if ( wf->hasVariable() && !wf->setVariable( param ) )
114  return false;
115 
116  if ( sz0<=0 || sz1<=0 || sz2<=0 )
117  return false;
118 
119  window_.setSize( sz0, sz1, sz2 );
120  if ( !window_.isOK() )
121  return false;
122 
123  const int hsz0 = sz0/2; const int hsz1 = sz1/2; const int hsz2 = sz2/2;
124  Coord3 pos;
125 
126  for ( int idx0=0; idx0<sz0; idx0++ )
127  {
128  pos[0] = hsz0 ? ((double)(idx0-hsz0))/hsz0 : 0;
129  for ( int idx1=0; idx1<sz1; idx1++ )
130  {
131  pos[1] = hsz1 ? ((double)(idx1-hsz1))/hsz1 : 0;
132  for ( int idx2=0; idx2<sz2; idx2++ )
133  {
134  pos[2] = hsz2 ? ((double)(idx2-hsz2))/hsz2 : 0;
135 
136  window_.set( idx0, idx1, idx2,
137  wf->getValue( (float) pos.abs() ) );
138  }
139  }
140  }
141 
142  convolver_.setY( window_, hsz0, hsz1, hsz2 );
143 
144  windowname_ = nm;
145  windowparam_ = (float) ( wf->hasVariable() ? param : 1e30 );
146 
147  return true;
148 }
149 
150 
151 template <class T> inline
152 void Smoother3D<T>::fillPar( IOPar& par ) const
153 {
154  par.set( sKeyWinFunc(), windowname_ );
155  if ( !mIsUdf(windowparam_) )
156  par.set( sKeyWinParam(), windowparam_ );
157  par.set( sKeyWinSize(), window_.info().getSize(0),window_.info().getSize(1),
158  window_.info().getSize(2) );
159 }
160 
161 
162 template <class T> inline
163 bool Smoother3D<T>::usePar( const IOPar& par )
164 {
165  int sz0, sz1, sz2;
166  if ( !par.get(sKeyWinSize(), sz0, sz1, sz2 ) )
167  return false;
168 
169  const char* wn = par.find( sKeyWinFunc() );
170  float var = mUdf(float);
171  par.get( sKeyWinParam(), var );
172 
173  return setWindow( wn, var, sz0, sz1, sz2 );
174 }
175 
176 
177 #define mImplSetFunc( func, vartype ) \
178 template <class T> inline void Smoother3D<T>::func( vartype var ) \
179 { convolver_.func( var ); }
180 
184 
185 template <class T> inline
187 {
188  if ( !window_.isOK() )
189  return false;
190 
191  return convolver_.execute();
192 }
193 
194 
195 template <class T> inline
197 { return convolver_.getState(); }
198 
199 #endif
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
Convolver3D< T > convolver_
Definition: smoother3d.h:57
float getWindowParam() const
Definition: smoother3d.h:87
void setOutput(Array3D< T > &)
Definition: smoother3d.h:99
static const char * sKeyWinSize()
Definition: smoother3d.h:53
Convolves (or correlates) two 3D signals.
Definition: convolve3d.h:25
void fillPar(IOPar &) const
Definition: smoother3d.h:152
static const char * sKeyWinParam()
Definition: smoother3d.h:52
is an interface where processes can report their progress.
Definition: progressmeter.h:21
static const char * sKeyWinFunc()
Definition: smoother3d.h:51
void usePar(const IOPar &iop, ODPolygon< T > &poly, const char *inpkey)
Definition: polygon.h:188
Array3DImpl< T > window_
Definition: smoother3d.h:59
virtual bool hasVariable() const
Definition: windowfunction.h:31
bool setWindow(const char *nm, float param, int sz0, int sz1, int sz2)
Definition: smoother3d.h:106
bool get(const char *, int &) const
float windowparam_
Definition: smoother3d.h:61
#define mImplSetFunc(func, vartype)
Definition: smoother3d.h:177
void enableWorkControl(bool)
Must be called before execute()
Definition: smoother3d.h:182
Definition: ptrman.h:79
void setProgressMeter(ProgressMeter *pm)
Must be called before execute()
Definition: smoother3d.h:181
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:47
Control
Definition: task.h:55
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
const char * find(const char *) const
returns null if not found
DistType abs() const
const char * getWindowName() const
Definition: smoother3d.h:82
virtual bool setVariable(float)
Definition: windowfunction.h:33
void fillPar(IOPar &iop, const ODPolygon< T > &poly, const char *inpkey)
Definition: polygon.h:175
A cartesian coordinate in 3D space.
Definition: coord.h:72
const char * buf() const
Definition: odstring.h:47
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
BufferString windowname_
Definition: smoother3d.h:60
Smoothes a 3d signal with an operator.
Definition: smoother3d.h:27
bool usePar(const IOPar &)
Definition: smoother3d.h:163
Implementation of Array3D.
Definition: arrayndimpl.h:151
void setInput(const Array3D< T > &)
Definition: smoother3d.h:92
void controlWork(Task::Control)
Definition: smoother3d.h:183
#define mClass(module)
Definition: commondefs.h:164
bool execute()
Definition: smoother3d.h:186
void set(const char *ky, const char *val)
Array3D ( Subclass of ArrayND ) is a three dimensional array.
Definition: arraynd.h:153
virtual RT getValue(PT) const =0
Generalization of something (e.g. a computation) that needs to be done in multiple steps...
Definition: task.h:28
int getWindowSize(int dim) const
Definition: smoother3d.h:77
Smoother3D()
Definition: smoother3d.h:66
Task::Control getState() const
Definition: smoother3d.h:196

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