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

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