OpendTect-6_4  6.4
array2dfunc.h
Go to the documentation of this file.
1 #ifndef array2dfunc_h
2 #define array2dfunc_h
3 
4 /*
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: K. Tingdahl
9  Date: 9-3-1999
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 */
14 
15 #include "mathfunc.h"
16 #include "interpol2d.h"
17 #include "simpnumer.h"
18 
24 template <class RT,class PT,class T>
25 mClass(General) Array2DFunc : public MathXYFunction<RT,PT>
26 {
27 public:
28  inline void set( const Array2D<T>& t, bool hasudfs )
29  {
30  arr_ = &t;
31  xsize_ = arr_->info().getSize(0);
32  ysize_ = arr_->info().getSize(1);
33  hasudfs_ = hasudfs;
34  }
35 
36  inline RT getValue(PT,PT) const;
37  inline RT getValue( const PT* p ) const
38  { return getValue(p[0],p[1]); }
39 
40 protected:
41 
42  const Array2D<T>* arr_;
43  int xsize_;
44  int ysize_;
45  bool hasudfs_;
46 };
47 
48 
49 template <class RT,class PT,class T> inline
51 {
52  float xrelpos;
53  const int ix0 = Interpolate::getArrIdxPosition( x, xsize_, xrelpos );
54  if ( ix0<0 || ix0>=xsize_-1 ) return mUdf(RT);
55 
56  float yrelpos;
57  const int iy0 = Interpolate::getArrIdxPosition( y, ysize_, yrelpos );
58  if ( iy0<0 || iy0>=ysize_-1) return mUdf(RT);
59 
60  if ( xsize_<4 || ysize_<4 || !ix0 || !iy0 ||
61  ix0>=xsize_-2 || iy0>=ysize_-2 )
62  {
63  if ( hasudfs_ )
64  {
65  return Interpolate::linearReg2DWithUdf<T>(
66  arr_->get( ix0, iy0 ),
67  arr_->get( ix0, iy0+1 ),
68  arr_->get( ix0+1, iy0 ),
69  arr_->get( ix0+1, iy0+1),
70  xrelpos, yrelpos );
71  }
72 
73  return Interpolate::linearReg2D<T>(
74  arr_->get( ix0, iy0 ),
75  arr_->get( ix0, iy0+1 ),
76  arr_->get( ix0+1, iy0 ),
77  arr_->get( ix0+1, iy0+1 ),
78  xrelpos, yrelpos );
79  }
80 
81  if ( hasudfs_ )
82  {
83  return Interpolate::polyReg2DWithUdf<T>(
84  arr_->get( ix0-1, iy0 ),
85  arr_->get( ix0-1, iy0+1 ),
86  arr_->get( ix0, iy0-1 ),
87  arr_->get( ix0, iy0 ),
88  arr_->get( ix0, iy0+1 ),
89  arr_->get( ix0, iy0+2 ),
90  arr_->get( ix0+1, iy0-1 ),
91  arr_->get( ix0+1, iy0 ),
92  arr_->get( ix0+1, iy0+1 ),
93  arr_->get( ix0+1, iy0+2 ),
94  arr_->get( ix0+2, iy0 ),
95  arr_->get( ix0+2, iy0+1 ),
96  xrelpos, yrelpos );
97  }
98 
99 
100  return Interpolate::polyReg2D<T>( arr_->get( ix0-1, iy0 ),
101  arr_->get( ix0-1, iy0+1 ),
102  arr_->get( ix0, iy0-1 ),
103  arr_->get( ix0, iy0 ),
104  arr_->get( ix0, iy0+1 ),
105  arr_->get( ix0, iy0+2 ),
106  arr_->get( ix0+1, iy0-1 ),
107  arr_->get( ix0+1, iy0 ),
108  arr_->get( ix0+1, iy0+1 ),
109  arr_->get( ix0+1, iy0+2 ),
110  arr_->get( ix0+2, iy0 ),
111  arr_->get( ix0+2, iy0+1 ),
112  xrelpos, yrelpos );
113 }
114 
115 #endif
int xsize_
Definition: array2dfunc.h:43
RT getValue(PT, PT) const
Definition: array2dfunc.h:50
int ysize_
Definition: array2dfunc.h:44
Array2D ( Subclass of ArrayND ) is a two dimensional array.
Definition: arraynd.h:131
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
RT getValue(const PT *p) const
Definition: array2dfunc.h:37
A Math Function as in F(x,y).
Definition: mathfunc.h:105
const RefTree & RT()
bool hasudfs_
Definition: array2dfunc.h:45
#define mClass(module)
Definition: commondefs.h:164
const Array2D< T > * arr_
Definition: array2dfunc.h:42
int getArrIdxPosition(const float farridx, const int arrsz, float &relpos, const float eps=1e-4)
Definition: simpnumer.h:29
Adaptor to make an Array2D behave like a MathXYFunction. Will do linear interpolation at the edges...
Definition: array2dfunc.h:25

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