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

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