OpendTect  6.6
samplfunc.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: Kristofer Tingdahl
8  Date: 07-10-1999
9  RCS: $Id$
10 ________________________________________________________________________
11 
12 -*/
13 
14 #include "mathfunc.h"
15 #include "periodicvalue.h"
16 
24 template <class RT,class T>
26 {
27 public:
28  SampledFunction( bool periodic_= false )
29  : periodic( periodic_ ) {}
30 
31  virtual RT operator[](od_int64) const = 0;
32 
33  virtual float getDx() const = 0;
34  virtual float getX0() const = 0;
35 
36  virtual int size() const = 0;
37 
38  virtual float period() const { return mUdf(float); }
39  void setPeriodic( bool np ) { periodic = np; }
40 
41  float getIndex(float x) const
42  { return (x-getX0()) / getDx(); }
43 
44  int getNearestIndex(float x) const
45  { return mNINT32(getIndex( x )); }
46 
47  RT getValue( RT x ) const
48  {
49  if ( !doInterpolate() )
50  {
51  const int smpl = mNINT32( getIndex(x) );
52  if ( smpl<0 || smpl>=size() )
53  return mUdf(RT);
54  return (*this)[smpl];
55  }
56 
57  if ( periodic )
58  {
59  return
61  *this, size(),
62  getIndex(x), period(),
63  extrapolate());
64  }
65 
66  return hasUdfs()
68  size(), getIndex(x),
69  extrapolate())
70  : IdxAble::interpolateReg( *this,
71  size(), getIndex(x),
72  extrapolate());
73  }
74 
75  RT getValue( const RT* x ) const
76  { return getValue(*x); }
77 
78 protected:
79  bool periodic;
80 
81 
82  virtual bool extrapolate() const { return false; }
83  virtual bool hasUdfs() const { return false; }
84  virtual bool doInterpolate() const { return true; }
85 };
86 
87 
92 template <class RT, class T>
94 {
95 public:
96  SampledFunctionImpl(const T& idxabl,int sz,
97  float x0=0,float dx=1 )
98  : idxabl_( idxabl )
99  , sz_( sz )
100  , x0_( x0 )
101  , dx_( dx )
102  , period_ ( mUdf(float) )
103  , hasudfs_( false )
104  , interpolate_( true )
105  {}
106 
107  RT operator[](od_int64 idx) const { return idxabl_[idx];}
108 
109  float getDx() const { return dx_; }
110  float getX0() const { return x0_; }
111 
112  int size() const { return sz_; }
113 
114  float period() const { return period_; }
115  void setPeriod(float np) { period_ = np; }
116 
117  bool hasUdfs() const { return hasudfs_; }
118  void setHasUdfs(bool yn) { hasudfs_=yn; }
119 
120  bool doInterpolate() const { return interpolate_; }
121  void setInterpolate( bool yn ) { interpolate_=yn; }
122 
123 protected:
124 
125  const T& idxabl_;
126  int sz_;
128 
129  float dx_;
130  float x0_;
131 
132  float period_;
133  bool hasudfs_;
135 };
136 
SampledFunctionImpl::SampledFunctionImpl
SampledFunctionImpl(const T &idxabl, int sz, float x0=0, float dx=1)
Definition: samplfunc.h:96
SampledFunction::getDx
virtual float getDx() const =0
SampledFunctionImpl::setInterpolate
void setInterpolate(bool yn)
Definition: samplfunc.h:121
SampledFunctionImpl::sz_
int sz_
Definition: samplfunc.h:126
SampledFunction::size
virtual int size() const =0
SampledFunction::doInterpolate
virtual bool doInterpolate() const
Definition: samplfunc.h:84
SampledFunctionImpl::setHasUdfs
void setHasUdfs(bool yn)
Definition: samplfunc.h:118
SampledFunctionImpl::firstidx_
int firstidx_
Definition: samplfunc.h:127
od_int64
#define od_int64
Definition: plftypes.h:35
SampledFunctionImpl::setPeriod
void setPeriod(float np)
Definition: samplfunc.h:115
SampledFunctionImpl::idxabl_
const T & idxabl_
Definition: samplfunc.h:125
SampledFunctionImpl::x0_
float x0_
Definition: samplfunc.h:130
SampledFunctionImpl::dx_
float dx_
Definition: samplfunc.h:129
SampledFunction::getValue
RT getValue(RT x) const
Definition: samplfunc.h:47
periodicvalue.h
MathFunction< RT, RT >
SampledFunctionImpl::getDx
float getDx() const
Definition: samplfunc.h:109
SampledFunction::extrapolate
virtual bool extrapolate() const
Definition: samplfunc.h:82
SampledFunction::periodic
bool periodic
Definition: samplfunc.h:79
SampledFunction::getValue
RT getValue(const RT *x) const
Definition: samplfunc.h:75
SampledFunctionImpl::hasudfs_
bool hasudfs_
Definition: samplfunc.h:133
SampledFunctionImpl::period
float period() const
Definition: samplfunc.h:114
Strat::RT
const RefTree & RT()
IdxAble::interpolateYPeriodicReg
void interpolateYPeriodicReg(const T &idxabl, int sz, float pos, RT &ret, RT period, bool extrapolate=false)
Definition: periodicvalue.h:126
mClass
#define mClass(module)
Definition: commondefs.h:181
SampledFunctionImpl::size
int size() const
Definition: samplfunc.h:112
SampledFunctionImpl::interpolate_
bool interpolate_
Definition: samplfunc.h:134
SampledFunctionImpl::getX0
float getX0() const
Definition: samplfunc.h:110
SampledFunctionImpl::doInterpolate
bool doInterpolate() const
Definition: samplfunc.h:120
SampledFunctionImpl
Implementation for array-type of SampledFunction.
Definition: samplfunc.h:94
mathfunc.h
IdxAble::interpolateRegWithUdf
bool interpolateRegWithUdf(const T &idxabl, int sz, float pos, RT &ret, bool extrapolate=false, float snapdist=mDefEps)
Definition: idxable.h:313
SampledFunctionImpl::operator[]
RT operator[](od_int64 idx) const
Definition: samplfunc.h:107
SampledFunction::setPeriodic
void setPeriodic(bool np)
Definition: samplfunc.h:39
SampledFunction::SampledFunction
SampledFunction(bool periodic_=false)
Definition: samplfunc.h:28
mUdf
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:274
SampledFunction::getX0
virtual float getX0() const =0
SampledFunction::getNearestIndex
int getNearestIndex(float x) const
Definition: samplfunc.h:44
SampledFunction::operator[]
virtual RT operator[](od_int64) const =0
SampledFunctionImpl::period_
float period_
Definition: samplfunc.h:132
SampledFunction::getIndex
float getIndex(float x) const
Definition: samplfunc.h:41
mNINT32
#define mNINT32(x)
Definition: commondefs.h:58
SampledFunctionImpl::hasUdfs
bool hasUdfs() const
Definition: samplfunc.h:117
SampledFunction::period
virtual float period() const
Definition: samplfunc.h:38
SampledFunction::hasUdfs
virtual bool hasUdfs() const
Definition: samplfunc.h:83
SampledFunction
Make any sampled series comply with MathFunction.
Definition: samplfunc.h:26
IdxAble::interpolateReg
bool interpolateReg(const T &idxabl, int sz, float pos, RT &ret, bool extrapolate=false, float snapdist=mDefEps)
Definition: idxable.h:272

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