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

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