OpendTect  6.3
interpolnd.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: Bert
8  Date: Apr 2010
9 ________________________________________________________________________
10 
11 */
12 
13 #include "math2.h"
14 
15 
16 namespace Interpolate
17 {
18 
69 template <class T>
70 inline T linearRegND( int N, const T* v, const T* pos )
71 {
72  if ( N == 0 )
73  return v[0];
74  else if ( N == 1 )
75  return v[0] * (1-pos[0]) + v[1] * pos[0];
76  else if ( N == 2 )
77  {
78  T a[4];
79  a[0] = v[0];
80  a[1] = v[1] - v[0];
81  a[2] = v[2] - v[0];
82  a[3] = v[3] + v[0] - v[1] - v[2];
83  return a[0] + a[1]*pos[0] + a[2]*pos[1] + a[3]*pos[0]*pos[1];
84  }
85  else
86  {
87  const int lowerN = N-1;
88  const od_int64 nlowerpts = Math::IntPowerOf( ((od_int64)2), lowerN );
89  float* lowerv = new float [nlowerpts];
90  const float lastpos = pos[lowerN];
91  for ( od_int64 idx=0; idx<nlowerpts; idx++ )
92  {
93  const float v0 = v[idx];
94  const float v1 = v[idx+nlowerpts];
95  lowerv[idx] = (1-lastpos) * v0 + lastpos * v1;
96  }
97  const float res = linearRegND( lowerN, lowerv, pos );
98  delete [] lowerv;
99  return res;
100  }
101 }
102 
103 
104 } // namespace Interpolate
Definition: interpol1d.h:36
#define od_int64
Definition: plftypes.h:34
T linearRegND(int N, const T *v, const T *pos)
Definition: interpolnd.h:70
iT IntPowerOf(iT i, iPOW p)
Definition: math2.h:126

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