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

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