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

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