OpendTect-6_4  6.4
samplingdata.h
Go to the documentation of this file.
1 #ifndef samplingdata_h
2 #define samplingdata_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H. Bril
9  Date: 23-10-1996
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "gendefs.h"
16 
21 template <class T>
23 {
24 public:
25 
26  inline SamplingData(T sa=0,T se=1);
27  inline SamplingData(T x0,T y0,T x1,T y1);
28  template <class FT> inline SamplingData(const SamplingData<FT>&);
29  template <class FT> inline SamplingData(const StepInterval<FT>&);
30 
31  inline bool operator==(const SamplingData&)const;
32  inline bool operator!=(const SamplingData&)const;
33 
34  template <class IT> inline StepInterval<T> interval(IT nrsamples) const;
35  template <class FT> inline float getfIndex(FT) const;
36  template <class FT> inline int nearestIndex(FT) const;
37  template <class FT> inline int indexOnOrAfter(FT,
38  float eps=mDefEps ) const;
40  template <class IT> inline T atIndex(IT) const;
41  template <class FT> inline T snap(FT) const;
42 
43  template <class FT> inline void set(FT,FT);
44  template <class FT> inline void set(const SamplingData<FT>&);
45  template <class FT> inline void set(const StepInterval<FT>&);
46  inline void scale(T);
47  inline bool isUdf() const;
48 
49  T start;
50  T step;
51 };
52 
53 
54 
55 template <class T> inline
57  : start(sa), step(se)
58 {}
59 
60 
61 template <class T> inline
62 SamplingData<T>::SamplingData( T x0, T y0, T x1, T y1 )
63 {
64  step = (y1-y0) / (x1-x0);
65  start = y0 - step*x0;
66 }
67 
68 
69 template <class T>
70 template <class FT> inline
72  : start( mCast(T,sd.start) ), step( mCast(T,sd.step) )
73 {}
74 
75 
76 #include "ranges.h"
77 
78 template <class T>
79 template <class FT> inline
81  : start(mCast(T,intv.start)), step(mCast(T,intv.step))
82 {}
83 
84 
85 template <class T> inline
87 { return start == sd.start && step == sd.step; }
88 
89 
90 template <> inline
92 {
93  float val = start - sd.start;
94  if ( !mIsZero(val,1e-6f) ) return false;
95  val = 1 - (step / sd.step);
96  return val < 1e-6f && val > -1e-6f;
97 }
98 
99 
100 template <> inline
102 {
103  double val = start - sd.start;
104  if ( !mIsZero(val,1e-10) ) return false;
105  val = 1 - (step / sd.step);
106  return val < 1e-10 && val > -1e-10;
107 }
108 
109 
110 template <class T> inline
112 { return ! (sd == *this); }
113 
114 
115 template <class T>
116 template <class IT> inline
118 {
119  return nrsamp ? StepInterval<T>( start, start+(nrsamp-1)*step, step )
120  : StepInterval<T>( start, start, step );
121 }
122 
123 
124 template <class T>
125 template <class FT> inline
126 float SamplingData<T>::getfIndex( FT val ) const
127 { return mIsZero(step,mDefEps) ? 0.f : (float) ((val-start) / step); }
128 
129 
130 template <class T>
131 template <class FT> inline
133 { const float fidx = getfIndex(x); return mNINT32(fidx); }
134 
135 
136 template <class T>
137 template <class FT> inline
138 int SamplingData<T>::indexOnOrAfter( FT x, float eps ) const
139 {
140  float fres = getfIndex( x );
141  int res = (int) getfIndex(x);
142  const float diff = fres-res;
143  if ( diff>eps )
144  res++;
145 
146  return res;
147 }
148 
149 
150 template <class T>
151 template <class FT> inline
152 T SamplingData<T>::snap( FT val ) const
153 { return start + step * nearestIndex(val); }
154 
155 
156 template <class T>
157 template <class IT> inline
158 T SamplingData<T>::atIndex( IT idx ) const
159 { return start + step * (T)idx; }
160 
161 
162 template <class T>
163 template <class FT> inline
164 void SamplingData<T>::set( FT sa, FT se )
165 { start = (T)sa; step = (T)se; }
166 
167 
168 template <class T>
169 template <class FT> inline
171 { start = (T)intv.start; step = (T)intv.step; }
172 
173 
174 template <class T>
175 template <class FT> inline
177 { start = (T)sd.start; step = (T)sd.step; }
178 
179 
180 template <class T> inline
182 { start *= scl; step *= scl; }
183 
184 
185 template <class T> inline
187 { return mIsUdf(start) || mIsUdf(step); }
188 
189 #endif
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
T step
Definition: samplingdata.h:50
bool operator==(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:53
int nearestIndex(FT) const
Definition: samplingdata.h:132
#define mIsZero(x, eps)
Definition: commondefs.h:53
void set(FT, FT)
Definition: samplingdata.h:164
#define mCast(tp, v)
Definition: commondefs.h:124
bool operator==(const SamplingData &) const
Definition: samplingdata.h:86
int indexOnOrAfter(FT, float eps=(1e-10)) const
Definition: samplingdata.h:138
T snap(FT) const
Definition: samplingdata.h:152
T atIndex(IT) const
Definition: samplingdata.h:158
#define mNINT32(x)
Definition: commondefs.h:45
T step
Definition: ranges.h:199
T start
Definition: samplingdata.h:49
Interval with step.
Definition: commontypes.h:33
bool isUdf() const
Definition: samplingdata.h:186
bool operator!=(const ArrayNDInfo &a1, const ArrayNDInfo &a2)
Definition: arrayndinfo.h:62
void scale(T)
Definition: samplingdata.h:181
#define mDefEps
Definition: commondefs.h:58
float getfIndex(FT) const
Definition: samplingdata.h:126
SamplingData(T sa=0, T se=1)
Definition: samplingdata.h:56
T start
Definition: ranges.h:92
Holds the fundamental sampling info: start and interval.
Definition: samplingdata.h:22
#define mClass(module)
Definition: commondefs.h:164
bool operator!=(const SamplingData &) const
Definition: samplingdata.h:111
StepInterval< T > interval(IT nrsamples) const
Definition: samplingdata.h:117
bool isUdf(const T &t)
Definition: undefval.h:243

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