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

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