OpendTect-6_4  6.4
interpolnd.h
Go to the documentation of this file.
1 #ifndef interpolnd_h
2 #define interpolnd_h
3 
4 /*
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert
9  Date: Apr 2010
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 */
14 
15 #include "math2.h"
16 
17 
18 namespace Interpolate
19 {
20 
71 template <class T>
72 inline T linearRegND( int N, const T* v, const T* pos )
73 {
74  if ( N == 0 )
75  return v[0];
76  else if ( N == 1 )
77  return v[0] * (1-pos[0]) + v[1] * pos[0];
78  else if ( N == 2 )
79  {
80  T a[4];
81  a[0] = v[0];
82  a[1] = v[1] - v[0];
83  a[2] = v[2] - v[0];
84  a[3] = v[3] + v[0] - v[1] - v[2];
85  return a[0] + a[1]*pos[0] + a[2]*pos[1] + a[3]*pos[0]*pos[1];
86  }
87  else
88  {
89  const int lowerN = N-1;
90  const od_int64 nlowerpts = Math::IntPowerOf( ((od_int64)2), lowerN );
91  float* lowerv = new float [nlowerpts];
92  const float lastpos = pos[lowerN];
93  for ( od_int64 idx=0; idx<nlowerpts; idx++ )
94  {
95  const float v0 = v[idx];
96  const float v1 = v[idx+nlowerpts];
97  lowerv[idx] = (1-lastpos) * v0 + lastpos * v1;
98  }
99  const float res = linearRegND( lowerN, lowerv, pos );
100  delete [] lowerv;
101  return res;
102  }
103 }
104 
105 
106 } // namespace Interpolate
107 
108 #endif
Definition: interpol1d.h:38
#define od_int64
Definition: plftypes.h:36
T linearRegND(int N, const T *v, const T *pos)
Definition: interpolnd.h:72
iT IntPowerOf(iT i, iPOW p)
Definition: math2.h:122

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