OpendTect-6_4  6.4
convolve3d.h
Go to the documentation of this file.
1 #ifndef convolve3d_h
2 #define convolve3d_h
3 
4 /*@+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Kristofer Tingdahl
9  Date: Feb 2008
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 
14 */
15 
16 #include "arraynd.h"
17 #include "paralleltask.h"
18 #include "math2.h"
19 
24 template <class T>
27 public:
28  inline Convolver3D();
29 
30  inline void setX(const Array3D<T>&,
31  int first0=0,int first1=0, int first2=0);
32  inline void setY(const Array3D<T>&,
33  int first0=0,int first1=0, int first2=0);
34  inline void setZ(Array3D<T>& z ) { z_ = &z; }
35  void setNormalize( bool n ) { normalize_ = n; }
38  void setCorrelate( bool yn ) { correlate_ = yn; }
41  void setHasUdfs(bool yn) { hasudfs_ = yn; }
43 
44  virtual bool executeParallel(bool);
45 
46  uiString uiMessage() const { return tr("Convolving 3D volume"); }
47  uiString uiNrDoneText() const { return tr("Positions done"); }
48 
49 protected:
50  inline bool shouldFFT() const;
51 
52  bool doFFT();
53  inline bool doWork( od_int64, od_int64, int );
54  od_int64 nrIterations() const { return z_->info().getTotalSz(); }
55  const Array3D<T>* x_;
56  int xshift0_;
57  int xshift1_;
58  int xshift2_;
59  const Array3D<T>* y_;
60  int yshift0_;
61  int yshift1_;
62  int yshift2_;
63 
65  bool normalize_;
66  bool correlate_;
67 
68  bool hasudfs_;
69 };
70 
71 
72 template <class T> inline
74  : x_( 0 )
75  , xshift0_( 0 )
76  , xshift1_( 0 )
77  , xshift2_( 0 )
78  , y_( 0 )
79  , yshift0_( 0 )
80  , yshift1_( 0 )
81  , yshift2_( 0 )
82  , z_( 0 )
83  , normalize_( false )
84  , correlate_( false )
85  , hasudfs_( false )
86 {}
87 
88 
89 template <class T> inline
91  int first0, int first1, int first2 )
92 {
93  x_ = &x;
94  xshift0_ = first0;
95  xshift1_ = first1;
96  xshift2_ = first2;
97 }
98 
99 
100 template <class T> inline
101 void Convolver3D<T>::setY( const Array3D<T>& y, int first0, int first1,
102  int first2 )
103 {
104  y_ = &y;
105  yshift0_ = first0;
106  yshift1_ = first1;
107  yshift2_ = first2;
108 }
109 
110 
111 #define mConvolver3DSetY( dim ) \
112 const int firsty##dim = correlate_ \
113  ? -xshift##dim##_-zvar[dim]+yshift##dim##_ \
114  : zvar[dim]+xshift##dim##_+yshift##dim##_; \
115 \
116  const char y##dim##inc = correlate_ ? 1 : -1
117 
118 
119 #define mConvolver3DSetIndex( dim ) \
120 const int idy##dim = firsty##dim+idx##dim*y##dim##inc; \
121 if ( idy##dim<0 ) \
122 { \
123  if ( correlate_ ) \
124  { \
125  idx##dim += (-idy##dim)-1; \
126  continue; \
127  } \
128  \
129  break; \
130 } \
131  \
132 if ( idy##dim>=ysz##dim ) \
133 { \
134  if ( correlate_ ) \
135  break; \
136  \
137  const int diff = idy##dim-(ysz##dim-1); \
138  idx##dim += diff-1; \
139  continue; \
140 }
141 
142 
143 template <class T> inline
144 bool Convolver3D<T>::doWork( od_int64 start, od_int64 stop, int )
145 {
146  const int xsz0 = x_->info().getSize( 0 );
147  const int xsz1 = x_->info().getSize( 1 );
148  const int xsz2 = x_->info().getSize( 2 );
149  const int ysz0 = y_->info().getSize( 0 );
150  const int ysz1 = y_->info().getSize( 1 );
151  const int ysz2 = y_->info().getSize( 2 );
152 
153  int startpos[3];
154 
155  if ( !z_->info().getArrayPos( start, startpos ) )
156  return false;
157 
158  ArrayNDIter iterator( z_->info() );
159  iterator.setPos( startpos );
160 
161  const ValueSeries<T>* xstor_ = x_->getStorage();
162  const T* xptr_ = x_->getData();
163 
164  const ValueSeries<T>* ystor_ = y_->getStorage();
165  const T* yptr_ = y_->getData();
166 
167  for ( int idx=mCast(int,start); idx<=stop; idx++ )
168  {
169  const int* zvar = iterator.getPos();
170  T sum = 0;
171  T ysum = 0;
172  int nrsamples = 0;
173 
174  mConvolver3DSetY( 0 );
175  mConvolver3DSetY( 1 );
176  mConvolver3DSetY( 2 );
177 
178  for ( int idx0=0; idx0<xsz0 && shouldContinue(); idx0++ )
179  {
181 
182  for ( int idx1=0; idx1<xsz1; idx1++ )
183  {
185 
186  const od_int64 yoffset = ystor_ || yptr_ ?
187  y_->info().getOffset( idy0, idy1, 0 ) : 0;
188 
189  const od_int64 xoffset = xstor_ || xptr_ ?
190  x_->info().getOffset( idx0, idx1, 0 ) : 0;
191 
192  for ( int idx2=0; idx2<xsz2; idx2++ )
193  {
195 
196  const T yval = yptr_
197  ? yptr_[yoffset+idy2]
198  : ystor_
199  ? ystor_->value( yoffset+idy2 )
200  : y_->get( idy0, idy1, idy2 );
201 
202  if ( mIsUdf(yval) )
203  continue;
204 
205  const T xval = xptr_
206  ? xptr_[xoffset+idx2]
207  : xstor_
208  ? xstor_->value( xoffset+idx2 )
209  : x_->get( idx0, idx1, idx2 );
210 
211  if ( mIsUdf(xval) )
212  continue;
213 
214  sum += xval * yval;
215  ysum += yval;
216  nrsamples++;
217  }
218  }
219  }
220 
221  if ( !nrsamples ) z_->setND( zvar, 0 );
222  else if ( normalize_ && !mIsZero(ysum,1e-8) )
223  z_->setND( zvar, sum/ysum );
224  else z_->setND( zvar, sum );
225 
226  addToNrDone( 1 );
227 
228  if ( !iterator.next() && idx!=stop )
229  return false;
230  }
231 
232  return true;
233 }
234 
235 
236 template <class T> inline
238 {
239  if ( shouldFFT() )
240  return doFFT();
241 
242  return ParallelTask::executeParallel( yn );
243 }
244 
245 
246 template <class T> inline
248 {
249  //TODO
250  return false;
251 }
252 
253 
254 template <class T> inline
256 {
257  return false;
258 }
259 
260 template <> inline
262 {
263  return false; //Remove when doFFT is implemented
264 /*
265  if ( correlate_ || normalize_ )
266  return false;
267 
268  if ( !x_ || !y_ || !z_ )
269  return false;
270 
271  const int xsz = x_->info().getTotalSz();
272  const int ysz = y_->info().getTotalSz();
273  const int zsz = z_->info().getTotalSz();
274 
275  int maxsz = x_->info().getTotalSz();
276  maxsz = mMAX( maxsz, y_->info().getTotalSz() );
277  maxsz = mMAX( maxsz, z_->info().getTotalSz() );
278 
279  const int tradsz = zsz * mMIN(ysz,xsz);
280  const float fftszf = maxsz * Math::Log( (float) maxsz );
281  const int fftsz = mNINT32( fftszf );
282 
283 
284  return fftsz<tradsz;
285  */
286 }
287 
288 
289 #endif
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
virtual T value(int64_t) const =0
bool correlate_
Definition: convolve3d.h:66
Convolves (or correlates) two 3D signals.
Definition: convolve3d.h:25
const Array3D< T > * y_
Definition: convolve3d.h:59
int yshift0_
Definition: convolve3d.h:60
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
uiString uiMessage() const
will be message() again in 7.x
Definition: convolve3d.h:46
void setY(const Array3D< T > &, int first0=0, int first1=0, int first2=0)
Definition: convolve3d.h:101
od_int64 nrIterations() const
Definition: convolve3d.h:54
#define mIsZero(x, eps)
Definition: commondefs.h:53
#define mCast(tp, v)
Definition: commondefs.h:124
#define od_int64
Definition: plftypes.h:36
int yshift1_
Definition: convolve3d.h:61
virtual bool shouldContinue()
Definition: uistring.h:89
int xshift1_
Definition: convolve3d.h:57
bool shouldFFT() const
Definition: convolve3d.h:255
Generalization of a task that can be run in parallel.
Definition: paralleltask.h:66
int xshift0_
Definition: convolve3d.h:56
Array3D< T > * z_
Definition: convolve3d.h:64
bool normalize_
Definition: convolve3d.h:65
Convolver3D()
Definition: convolve3d.h:73
#define mConvolver3DSetIndex(dim)
Definition: convolve3d.h:119
void setPos(const T &idxabl)
Definition: arraynd.h:256
void setNormalize(bool n)
Definition: convolve3d.h:35
Interface to a series of values.
Definition: odmemory.h:17
int yshift2_
Definition: convolve3d.h:62
int xshift2_
Definition: convolve3d.h:58
void setCorrelate(bool yn)
Definition: convolve3d.h:38
uiString uiNrDoneText() const
will be nrDoneText() in 7.x
Definition: convolve3d.h:47
virtual bool executeParallel(bool parallel)
#define mConvolver3DSetY(dim)
Definition: convolve3d.h:111
bool doFFT()
Definition: convolve3d.h:247
Iterates through all samples in an ArrayND.
Definition: arraynd.h:179
virtual bool executeParallel(bool)
Definition: convolve3d.h:237
void setX(const Array3D< T > &, int first0=0, int first1=0, int first2=0)
Definition: convolve3d.h:90
void setZ(Array3D< T > &z)
Definition: convolve3d.h:34
const Array3D< T > * x_
Definition: convolve3d.h:55
#define mClass(module)
Definition: commondefs.h:164
void setHasUdfs(bool yn)
Default is false.
Definition: convolve3d.h:41
Array3D ( Subclass of ArrayND ) is a three dimensional array.
Definition: arraynd.h:153
void addToNrDone(int64_t increment)
bool doWork(od_int64, od_int64, int)
Definition: convolve3d.h:144
bool hasudfs_
Definition: convolve3d.h:68

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