OpendTect-6_4  6.4
interpol3d.h
Go to the documentation of this file.
1 #ifndef interpol3d_h
2 #define interpol3d_h
3 
4 /*
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert
9  Date: Mar 2006
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 */
14 
15 #include "undefval.h"
16 
17 
18 namespace Interpolate
19 {
20 
25 template <class T>
27 {
28 public:
29 
31 
32 LinearReg3D( const T* const* const* v )
33 {
34  set( v[0][0][0], v[1][0][0], v[0][1][0], v[1][1][0],
35  v[0][0][1], v[1][0][1], v[0][1][1], v[1][1][1] );
36 }
37 
38 LinearReg3D( T v000, T v100, T v010, T v110, T v001, T v101, T v011, T v111 )
39 {
40  set( v000, v100, v010, v110, v001, v101, v011, v111 );
41 }
42 
43 inline void set( T v000, T v100, T v010, T v110, T v001, T v101, T v011, T v111)
44 {
45  a_[0] = v000;
46  a_[1] = v100 - v000;
47  a_[2] = v010 - v000;
48  a_[3] = v001 - v000;
49  a_[4] = v110 + v000 - v100 - v010;
50  a_[5] = v101 + v000 - v100 - v001;
51  a_[6] = v011 + v000 - v010 - v001;
52  a_[7] = v111 + v100 + v010 + v001 - (v000 + v110 + v101 + v011);
53 }
54 
55 inline T apply( float x, float y, float z ) const
56 {
57  return a_[0] + a_[1] * x + a_[2] * y + a_[3] * z
58  + a_[4] * x * y + a_[5] * x * z + a_[6] * y * z
59  + a_[7] * x * y * z;
60 }
61 
62  T a_[8];
63 
64 };
65 
66 
67 template <class T>
68 inline T linearReg3D( T v000, T v100, T v010, T v110,
69  T v001, T v101, T v011, T v111,
70  float x, float y, float z )
71 {
72  return LinearReg3D<T>( v000, v100, v010, v110, v001, v101, v011, v111 )
73  .apply( x, y, z );
74 }
75 
76 
81 template <class T>
83 {
84 public:
85 
87 
88 LinearReg3DWithUdf( const T* const* const* v )
89 {
90  set( v[0][0][0], v[1][0][0], v[0][1][0], v[1][1][0],
91  v[0][0][1], v[1][0][1], v[0][1][1], v[1][1][1] );
92 }
93 
94 LinearReg3DWithUdf( T v000, T v100, T v010, T v110,
95  T v001, T v101, T v011, T v111 )
96 {
97  set( v000, v100, v010, v110, v001, v101, v011, v111 );
98 }
99 
100 inline static T getReplVal( T v1, T v2, T v3, bool u1, bool u2, bool u3 )
101 {
102 
103  if ( u1 )
104  return u2 ? v3 : (u3 ? v2 : (v2 + v3) / 2);
105  else if ( u2 )
106  return u3 ? v1 : (v1 + v3) / 2;
107  else if ( u3 )
108  return (v1 + v2) / 2;
109 
110  return (v1 + v2 + v3) / 3;
111 }
112 
113 inline void set( T v000, T v100, T v010, T v110, T v001, T v101, T v011, T v111)
114 {
115  u000_ = mIsUdf(v000);
116  u100_ = mIsUdf(v100);
117  u010_ = mIsUdf(v010);
118  u110_ = mIsUdf(v110);
119  u001_ = mIsUdf(v001);
120  u101_ = mIsUdf(v101);
121  u011_ = mIsUdf(v011);
122  u111_ = mIsUdf(v111);
123  haveudf_ = u000_ || u100_ || u010_ || u110_
124  || u001_ || u101_ || u011_ || u111_;
125 
126  if ( haveudf_ )
127  {
128 # define mFillIfUdf(nd,nearx,neary,nearz,diagxy,diagxz,diagyz,opp) \
129  if ( u##nd##_ ) \
130  { \
131  if ( !u##nearx##_ || !u##neary##_ || !u##nearz##_ ) \
132  v##nd = getReplVal( v##nearx, v##neary, v##nearz, \
133  u##nearx##_, u##neary##_, u##nearz##_ ); \
134  else \
135  { \
136  if ( u##diagxy##_ && u##diagxz##_ && u##diagyz##_ ) \
137  v##nd = v##opp; \
138  else \
139  v##nd = getReplVal( v##diagxy, v##diagxz, v##diagyz, \
140  u##diagxy##_, u##diagxz##_, u##diagyz##_ ); \
141  } \
142  }
143 
144  mFillIfUdf(000,100,010,001,110,101,011,111)
145  mFillIfUdf(100,000,110,101,010,001,111,011)
146  mFillIfUdf(010,110,000,011,100,111,001,101)
147  mFillIfUdf(110,010,100,111,000,011,101,001)
148  mFillIfUdf(001,101,011,000,111,100,010,110)
149  mFillIfUdf(101,001,111,100,011,000,110,010)
150  mFillIfUdf(011,111,001,010,101,110,000,100)
151  mFillIfUdf(111,011,101,110,001,010,100,000)
152 
153 # undef mFillIfUdf
154  }
155 
156  intp_.set( v000, v100, v010, v110, v001, v101, v011, v111 );
157 }
158 
159 inline T apply( float x, float y, float z ) const
160 {
161  // return undef if the nearest node is undef
162  if ( haveudf_ && (
163  ( u000_ && x < 0.5 && y < 0.5 && z < 0.5 )
164  || ( u100_ && x >= 0.5 && y < 0.5 && z < 0.5 )
165  || ( u010_ && x < 0.5 && y >= 0.5 && z < 0.5 )
166  || ( u110_ && x >= 0.5 && y >= 0.5 && z < 0.5 )
167  || ( u001_ && x < 0.5 && y < 0.5 && z >= 0.5 )
168  || ( u101_ && x >= 0.5 && y < 0.5 && z >= 0.5 )
169  || ( u011_ && x < 0.5 && y >= 0.5 && z >= 0.5 )
170  || ( u111_ && x >= 0.5 && y >= 0.5 && z >= 0.5 ) ) )
171  return mUdf(T);
172 
173  return intp_.apply( x, y, z );
174 }
175 
177  bool haveudf_;
178  bool u000_;
179  bool u100_;
180  bool u010_;
181  bool u110_;
182  bool u001_;
183  bool u101_;
184  bool u011_;
185  bool u111_;
186 
187 };
188 
189 template <class T>
190 inline T linearReg3DWithUdf( T v000, T v100, T v010, T v110,
191  T v001, T v101, T v011, T v111,
192  float x, float y, float z )
193 {
194  return LinearReg3DWithUdf<T>(v000,v100,v010,v110,v001,v101,v011,v111)
195  .apply( x, y, z );
196 }
197 
198 
199 
218 template <class T>
220 {
221 public:
222 
224 
225 PolyReg3D( const T* const* const * v )
226 {
227  set( v[0][1][1], v[0][1][2], v[0][2][1], v[0][2][2],
228  v[1][0][1], v[1][0][2], v[1][1][0], v[1][1][1],
229  v[1][1][2], v[1][1][3], v[1][2][0], v[1][2][1],
230  v[1][2][2], v[1][2][3], v[1][3][1], v[1][3][2],
231  v[2][0][1], v[2][0][2], v[2][1][0], v[2][1][1],
232  v[2][1][2], v[2][1][3], v[2][2][0], v[2][2][1],
233  v[2][2][2], v[2][2][3], v[2][3][1], v[2][3][2],
234  v[3][1][1], v[3][1][2], v[3][2][1], v[3][2][2] );
235 }
236 
238  T vm100, T vm101, T vm110, T vm111,
239  T v0m10, T v0m11, T v00m1, T v000,
240  T v001, T v002, T v01m1, T v010,
241  T v011, T v012, T v020, T v021,
242  T v1m10, T v1m11, T v10m1, T v100,
243  T v101, T v102, T v11m1, T v110,
244  T v111, T v112, T v120, T v121,
245  T v200, T v201, T v210, T v211 )
246 {
247  set( vm100, vm101, vm110, vm111,
248  v0m10, v0m11, v00m1, v000,
249  v001, v002, v01m1, v010,
250  v011, v012, v020, v021,
251  v1m10, v1m11, v10m1, v100,
252  v101, v102, v11m1, v110,
253  v111, v112, v120, v121,
254  v200, v201, v210, v211 );
255 }
256 
257 inline void set(
258  T vm100, T vm101, T vm110, T vm111,
259  T v0m10, T v0m11, T v00m1, T v000,
260  T v001, T v002, T v01m1, T v010,
261  T v011, T v012, T v020, T v021,
262  T v1m10, T v1m11, T v10m1, T v100,
263  T v101, T v102, T v11m1, T v110,
264  T v111, T v112, T v120, T v121,
265  T v200, T v201, T v210, T v211 )
266 {
267  set( v000, v100, v010, v110, v001, v101, v011, v111,
268  (v00m1 + v01m1 + v10m1 + v11m1) / 4,
269  (v0m10 + v0m11 + v1m10 + v1m11) / 4,
270  (vm100 + vm101 + vm110 + vm111) / 4,
271  (v002 + v012 + v102 + v112) / 4,
272  (v020 + v021 + v120 + v121) / 4,
273  (v200 + v201 + v210 + v211) / 4 );
274 }
275 
276 inline void set( T v000, T v100, T v010, T v110, T v001, T v101, T v011, T v111,
277  T vxym1, T vxzm1, T vyzm1, T vxy1, T vxz1, T vyz1 )
278 {
279  // TODO
280 }
281 
282 inline T apply( float x, float y, float z ) const
283 {
284  return a_[0] + a_[1] * x + a_[2] * y + a_[3] * z
285  + a_[4] * x * y + a_[5] * x * z + a_[6] * y * z
286  + a_[7] * x * y * z
287  + a_[8] * x * x * y + a_[9] * x * x * z
288  + a_[10] * y * y * x + a_[11] * y * y * z
289  + a_[12] * z * z * x + a_[13] * z * z * y;
290 }
291 
292  T a_[14];
293 
294 };
295 
296 
297 template <class T>
298 inline T polyReg3D( const T* const* const * v, float x, float y, float z )
299 {
300  return PolyReg3D<T>( v ).apply( x, y, z );
301 }
302 
303 
313 } // namespace Interpolate
314 
315 #endif
Definition: interpol1d.h:38
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
bool u110_
Definition: interpol3d.h:181
T apply(float x, float y, float z) const
Definition: interpol3d.h:159
LinearReg3D()
Definition: interpol3d.h:30
LinearReg3DWithUdf(T v000, T v100, T v010, T v110, T v001, T v101, T v011, T v111)
Definition: interpol3d.h:94
bool u101_
Definition: interpol3d.h:183
bool u000_
Definition: interpol3d.h:178
Interpolate 3D regularly sampled, using a 3rd order surface.
Definition: interpol3d.h:219
static T getReplVal(T v1, T v2, T v3, bool u1, bool u2, bool u3)
Definition: interpol3d.h:100
PolyReg3D(T vm100, T vm101, T vm110, T vm111, T v0m10, T v0m11, T v00m1, T v000, T v001, T v002, T v01m1, T v010, T v011, T v012, T v020, T v021, T v1m10, T v1m11, T v10m1, T v100, T v101, T v102, T v11m1, T v110, T v111, T v112, T v120, T v121, T v200, T v201, T v210, T v211)
Definition: interpol3d.h:237
LinearReg3DWithUdf()
Definition: interpol3d.h:86
bool u010_
Definition: interpol3d.h:180
LinearReg3D< T > intp_
Definition: interpol3d.h:176
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
T linearReg3DWithUdf(T v000, T v100, T v010, T v110, T v001, T v101, T v011, T v111, float x, float y, float z)
Definition: interpol3d.h:190
PolyReg3D(const T *const *const *v)
Definition: interpol3d.h:225
T apply(float x, float y, float z) const
Definition: interpol3d.h:55
bool haveudf_
Definition: interpol3d.h:177
#define mFillIfUdf(nd, nearx, neary, nearz, diagxy, diagxz, diagyz, opp)
LinearReg3DWithUdf(const T *const *const *v)
Definition: interpol3d.h:88
bool u111_
Definition: interpol3d.h:185
LinearReg3D(T v000, T v100, T v010, T v110, T v001, T v101, T v011, T v111)
Definition: interpol3d.h:38
Linear 3D interpolation.
Definition: interpol3d.h:26
Linear 3D interpolation with standard undef handling.
Definition: interpol3d.h:82
bool u100_
Definition: interpol3d.h:179
PolyReg3D()
Definition: interpol3d.h:223
T polyReg3D(const T *const *const *v, float x, float y, float z)
PolyReg3D which smoothly handles undefined values.
Definition: interpol3d.h:298
bool u011_
Definition: interpol3d.h:184
T apply(float x, float y, float z) const
Definition: interpol3d.h:282
T linearReg3D(T v000, T v100, T v010, T v110, T v001, T v101, T v011, T v111, float x, float y, float z)
Definition: interpol3d.h:68
#define mClass(module)
Definition: commondefs.h:164
bool u001_
Definition: interpol3d.h:182
LinearReg3D(const T *const *const *v)
Definition: interpol3d.h:32

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