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

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