1 #ifndef valseriesevent_h 2 #define valseriesevent_h 39 template <
class VT,
class PT>
64 template <
class VT,
class PT>
74 , lastfound_(VSEvent::
None) {}
85 int idxminus1,
int idx0,
int idx1,
86 VT vminus1,VT v0,VT v1,
111 #define mIncSampIdx(idx) { \ 113 if ( idx == sg.stop+inc ) \ 114 return ValueSeriesEvent<VT,PT>( 0, mUdf(PT) ); } 115 #undef mDecrOccAtZero 116 #define mDecrOccAtZero(idx) { \ 119 return ValueSeriesEvent<VT,PT>( 0, sd_.atIndex(idx) ); } 122 template <
class VT,
class PT>
126 const int inc = sg.
start < sg.
stop ? 1 : -1;
129 VT v0 = vs_.value( idx );
134 v0 = vs_.value( idx );
137 int frompositive = v0 > 0;
140 for ( ; idx!=sg.
stop+inc; idx+=inc )
142 VT v1 = vs_.value( idx );
147 v1 = vs_.value( idx );
150 if ( ( (v1<0) != frompositive && needtoneg )
151 || ( (v1>0) != frompositive && needtopos ) )
155 v0 = v1; frompositive = v0 > 0;
156 v1 = vs_.value( idx );
161 const bool istopos = v0 < 0 && v1 > 0;
162 const bool istoneg = v0 > 0 && v1 < 0;
163 if ( ( istopos && needtopos ) || ( istoneg && needtoneg ) )
170 PT pos = idx - inc * (v1 / ( v1 - v0 ));
181 template <
class VT,
class PT>
184 VT vm1, VT v0, VT v1,
188 {
Swap( idxm1, idx1 );
Swap( vm1, v1 ); }
191 idxm1 -= idx0; idx1 -= idx0;
193 vm1 /= idxm1; v1 /= idx1;
195 VT a = (vm1 - v1) / (idxm1 - idx1);
205 ret.
val = (VT)(v0 + a * relpos * relpos + b * relpos);
211 template <
class VT,
class PT>
220 int extridx = sg.
start; VT extrval = vs_.value( extridx );
221 for ( curidx=sg.
start+1;
mIsUdf(extrval) && curidx<=sg.
stop; curidx++ )
222 { extridx = curidx; extrval = vs_.value( curidx ); }
227 for ( ; curidx<=sg.
stop; curidx++ )
229 const VT val = vs_.value( curidx );
230 if (
mIsUdf(val) )
continue;
232 if ( (needmax && val > extrval) || (!needmax && val < extrval) )
233 { extridx = curidx; extrval = val; }
238 VT vm1 = extridx > sg.
start ? vs_.value(extridx-1) : v0;
239 if (
mIsUdf(vm1) ) vm1 = v0;
240 VT v1 = extridx < sg.
stop-1 ? vs_.value(extridx+1) : v0;
241 if (
mIsUdf(v1) ) v1 = v0;
244 extridx-1, extridx, extridx+1, vm1, v0, v1, sd_ );
248 template <
class VT,
class PT>
252 const int inc = sg.
start < sg.
stop ? 1 : -1;
254 VT v0 = vs_.value( idx0 );
255 bool havevm1 = (inc > 0 && sg.
start > 0) || (inc < 0 && sg.
start < maxidx_);
256 VT vm1 = havevm1 ? vs_.value( sg.
start - inc ) : v0;
257 if (
mIsUdf(vm1) ) vm1 = v0;
258 bool upw0 = v0 > vm1;
265 VT v1 = vs_.value( idx1 );
266 if (
mIsUdf(v1) || v1 == v0 )
269 const bool upw1 = v1 > v0;
270 bool ishit = havevm1 && !
mIsUdf(v0) && upw0 != upw1;
273 const bool atmax = upw0 && !upw1;
284 return exactExtreme( evtype, idx0-inc, idx0, idx1,
287 upw0 = upw1; idx0 = idx1; vm1 = v0; v0 = v1;
295 template <
class VT,
class PT>
305 pErrMsg(
"Weird request: less than first occ of event.");
312 const int inc = pg.
start < pg.
stop ? 1 : -1;
313 if ( pg.
start < sd_.start )
314 {
if ( inc < 0 )
return ev; pg.
start = sd_.start; }
315 if ( pg.
stop < sd_.start )
316 {
if ( inc > 0 )
return ev; pg.
stop = sd_.start; }
318 const PT endpos = sd_.atIndex( maxidx_ );
319 if ( pg.
start > endpos )
320 {
if ( inc > 0 )
return ev; pg.
start = endpos; }
321 if ( pg.
stop > endpos )
322 {
if ( inc < 0 )
return ev; pg.
stop = endpos; }
351 ev = getExtreme( sg, occ, evtype );
354 ev = getZC( sg, occ, evtype );
362 if ( ( inc > 0 && ev.
pos < pg.
start ) ||
363 ( inc < 0 && ev.pos > pg.
start ) )
375 template <
class VT,
class PT>
390 const bool isascending = pg.
stop > pg.
start;
392 while ( isascending == (curg.
stop>curg.
start) )
405 if ( !posset.
size() )
return false;
412 #undef mDecrOccAtZero #define mExpClass(module)
Definition: commondefs.h:160
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
T step
Definition: samplingdata.h:50
const SamplingData< PT > & samplingData() const
Definition: valseriesevent.h:77
Definition: valseriesevent.h:26
#define mCast(tp, v)
Definition: commondefs.h:124
Definition: valseriesevent.h:26
Definition: valseriesevent.h:23
#define mIncSampIdx(idx)
Definition: valseriesevent.h:111
Definition: stattype.h:26
ValueSeriesEvent< VT, PT > getExtreme(const Interval< int > &, int, VSEvent::Type) const
Definition: valseriesevent.h:249
Definition: valseriesevent.h:26
#define mDeclareEnumUtils(enm)
Some utilities surrounding the often needed enum <-> string table.
Definition: enums.h:258
Interval of values.
Definition: commontypes.h:31
ValueSeriesEvent< VT, PT > find(VSEvent::Type, const Interval< PT > &, int occ=1) const
Definition: valseriesevent.h:296
FixedString None()
Definition: keystrs.h:90
VT val
Definition: valseriesevent.h:48
Definition: valseriesevent.h:27
Definition: valseriesevent.h:26
int maxidx_
Definition: valseriesevent.h:98
Set of (small) copyable elements.
Definition: commontypes.h:30
static ValueSeriesEvent< VT, PT > exactExtreme(VSEvent::Type, int idxminus1, int idx0, int idx1, VT vminus1, VT v0, VT v1, const SamplingData< PT > &)
Definition: valseriesevent.h:182
Definition: stattype.h:26
ValueSeriesEvent< VT, PT > getZC(const Interval< int > &, int, VSEvent::Type) const
Definition: valseriesevent.h:123
Event in value series.
Definition: valseriesevent.h:40
#define mDecrOccAtZero(idx)
Definition: valseriesevent.h:116
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
ValueSeriesEvent< VT, PT > getGateExtr(const Interval< int > &, bool) const
Definition: valseriesevent.h:212
PT pos
Definition: valseriesevent.h:49
T start
Definition: samplingdata.h:49
const ValueSeries< VT > & valueSeries() const
Definition: valseriesevent.h:76
void Swap(T &a, T &b)
Definition: commondefs.h:36
Event finder in gate.
Definition: valseriesevent.h:65
const T * find(const ObjectSet< T > &os, const S &val)
Get const object in set.
Definition: objectset.h:183
Definition: valseriesevent.h:27
VSEvent::Type lastFound() const
Useful when finding Extr or ZC.
Definition: valseriesevent.h:91
T stop
Definition: ranges.h:93
VSEvent::Type lastfound_
Definition: valseriesevent.h:99
Definition: valseriesevent.h:26
const ValueSeries< VT > & vs_
Definition: valseriesevent.h:96
T start
Definition: ranges.h:92
virtual void sort(bool asc=true)
Definition: ranges.h:585
#define mClass(module)
Definition: commondefs.h:164
#define pErrMsg(msg)
Definition: errmsg.h:60
Type
Definition: valseriesevent.h:26
bool findEvents(TypeSet< PT > &, Interval< PT >, VSEvent::Type)
Definition: valseriesevent.h:376
const SamplingData< PT > sd_
Definition: valseriesevent.h:97
ValueSeriesEvFinder(const ValueSeries< VT > &v, int maxidx, const SamplingData< PT > &s)
Definition: valseriesevent.h:68
ValueSeriesEvent(VT v=mUdf(VT), PT p=mUdf(PT))
Definition: valseriesevent.h:45
Definition: valseriesevent.h:26