OpendTect  6.6
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  RCS: $Id$
10 ________________________________________________________________________
11 
12 -*/
13 
14 #include "gendefs.h"
15 
20 template <class T>
22 {
23 public:
24 
25  inline SamplingData(T sa=0,T se=1);
26  inline SamplingData(T x0,T y0,T x1,T y1);
27  template <class FT> inline SamplingData(const SamplingData<FT>&);
28  template <class FT> inline SamplingData(const StepInterval<FT>&);
29 
30  inline bool operator==(const SamplingData&)const;
31  inline bool operator!=(const SamplingData&)const;
32 
33  template <class IT> inline StepInterval<T> interval(IT nrsamples) const;
34  template <class FT> inline float getfIndex(FT) const;
35  template <class FT> inline int nrSteps(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
132 int SamplingData<T>::nrSteps( FT x ) const
133 { const float fidx = getfIndex(x); return (int)(fidx + 1e-6f); }
134 
135 
136 template <class T>
137 template <class FT> inline
139 { const float fidx = getfIndex(x); return mNINT32(fidx); }
140 
141 
142 template <class T>
143 template <class FT> inline
144 int SamplingData<T>::indexOnOrAfter( FT x, float eps ) const
145 {
146  float fres = getfIndex( x );
147  int res = (int) getfIndex(x);
148  const float diff = fres-res;
149  if ( diff>eps )
150  res++;
151 
152  return res;
153 }
154 
155 
156 template <class T>
157 template <class FT> inline
158 T SamplingData<T>::snap( FT val ) const
159 { return start + step * nearestIndex(val); }
160 
161 
162 template <class T>
163 template <class IT> inline
164 T SamplingData<T>::atIndex( IT idx ) const
165 { return start + step * (T)idx; }
166 
167 
168 template <class T>
169 template <class FT> inline
170 void SamplingData<T>::set( FT sa, FT se )
171 { start = (T)sa; step = (T)se; }
172 
173 
174 template <class T>
175 template <class FT> inline
177 { start = (T)intv.start; step = (T)intv.step; }
178 
179 
180 template <class T>
181 template <class FT> inline
183 { start = (T)sd.start; step = (T)sd.step; }
184 
185 
186 template <class T> inline
188 { start *= scl; step *= scl; }
189 
190 
191 template <class T> inline
193 { return mIsUdf(start) || mIsUdf(step); }
194 
SamplingData::set
void set(FT, FT)
Definition: samplingdata.h:170
mIsUdf
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:289
SamplingData::SamplingData
SamplingData(T sa=0, T se=1)
Definition: samplingdata.h:56
SamplingData::operator!=
bool operator!=(const SamplingData &) const
Definition: samplingdata.h:111
SamplingData::set
void set(const SamplingData< FT > &)
Definition: samplingdata.h:182
SamplingData::interval
StepInterval< T > interval(IT nrsamples) const
Definition: samplingdata.h:117
mDefEps
#define mDefEps
Definition: commondefs.h:71
SamplingData::SamplingData
SamplingData(const SamplingData< FT > &)
Definition: samplingdata.h:71
SamplingData::operator==
bool operator==(const SamplingData &) const
Definition: samplingdata.h:86
StepInterval
Interval with step.
Definition: commontypes.h:32
SamplingData::atIndex
T atIndex(IT) const
Definition: samplingdata.h:164
SamplingData::scale
void scale(T)
Definition: samplingdata.h:187
mIsZero
#define mIsZero(x, eps)
Definition: commondefs.h:66
mClass
#define mClass(module)
Definition: commondefs.h:181
SamplingData::SamplingData
SamplingData(const StepInterval< FT > &)
Definition: samplingdata.h:80
SamplingData
Holds the fundamental sampling info: start and interval.
Definition: samplingdata.h:22
SamplingData::getfIndex
float getfIndex(FT) const
Definition: samplingdata.h:126
SamplingData::snap
T snap(FT) const
Definition: samplingdata.h:158
gendefs.h
SamplingData::start
T start
Definition: samplingdata.h:49
SamplingData::nearestIndex
int nearestIndex(FT) const
Definition: samplingdata.h:138
mCast
#define mCast(tp, v)
Definition: commondefs.h:137
SamplingData::isUdf
bool isUdf() const
Definition: samplingdata.h:192
SamplingData::set
void set(const StepInterval< FT > &)
Definition: samplingdata.h:176
SamplingData::nrSteps
int nrSteps(FT) const
Definition: samplingdata.h:132
SamplingData::indexOnOrAfter
int indexOnOrAfter(FT, float eps=(1e-10)) const
Definition: samplingdata.h:144
SamplingData::SamplingData
SamplingData(T x0, T y0, T x1, T y1)
Definition: samplingdata.h:62
ranges.h
SamplingData::step
T step
Definition: samplingdata.h:50
mNINT32
#define mNINT32(x)
Definition: commondefs.h:58
StepInterval::step
T step
Definition: ranges.h:200

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