OpendTect-6_4  6.4
squeezing.h
Go to the documentation of this file.
1 #ifndef squeezing_h
2 #define squeezing_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert
9  Date: Aug 2010
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "algomod.h"
16 #include "ranges.h"
17 
42 template <class T>
44 {
45 public:
46 
47  inline DataSqueezer( const Interval<T>& l )
48  : urg_(mUdf(T),mUdf(T)) { setRange(l,true); }
49  void setUntouchedRange( const Interval<T>& r ) { setRange(r,false); }
50 
51  inline DataSqueezer( T l0, T l1 ) : urg_(mUdf(T),mUdf(T))
52  { setRange(Interval<T>(l0,l1),true); }
53  void setUntouchedRange( T u0, T u1 )
54  { setRange(Interval<T>(u0,u1),false); }
55 
56  T value(T) const;
57 
58  const Interval<T>& range( bool lim ) const { return lim?rg_:urg_; }
59  void setRange(const Interval<T>&,bool lim);
60 
61 protected:
62 
65  bool udfstart_, udfstop_;
66  bool udfustart_, udfustop_;
67 
68 };
69 
70 
71 template <class T>
72 inline void DataSqueezer<T>::setRange( const Interval<T>& inprg, bool lim )
73 {
74  Interval<T>& rg = lim ? rg_ : urg_;
75  rg = inprg;
76  if ( !mIsUdf(rg.start) && !mIsUdf(rg.stop) )
77  rg.sort(true);
78 
79  udfstart_ = mIsUdf(rg_.start); udfstop_ = mIsUdf(rg_.stop);
80  udfustart_ = mIsUdf(urg_.start); udfustop_ = mIsUdf(urg_.stop);
81  if ( !udfstart_ && !udfustart_ && urg_.start <= rg_.start )
82  { urg_.start = mUdf(T); udfustart_ = true; }
83  if ( !udfstop_ && !udfustop_ && urg_.stop >= rg_.stop )
84  { urg_.stop = mUdf(T); udfustop_ = true; }
85 }
86 
87 
88 template <class T>
89 inline T DataSqueezer<T>::value( T v ) const
90 {
91  if ( mIsUdf(v) ) return v;
92 
93  if ( !udfstart_ )
94  {
95  if ( udfustart_ )
96  {
97  if ( v < rg_.start )
98  v = rg_.start;
99  }
100  else if ( v < urg_.start )
101  {
102  const T w = rg_.start - urg_.start;
103  v = rg_.start - ((w*w) / (v + w - urg_.start));
104  }
105  }
106  if ( !udfstop_ )
107  {
108  if ( udfustop_ )
109  {
110  if ( v > rg_.stop )
111  v = rg_.stop;
112  }
113  else if ( v > urg_.stop )
114  {
115  const T w = rg_.stop - urg_.stop;
116  v = rg_.stop - ((w*w) / (v + w - urg_.stop));
117  }
118  }
119 
120  return v;
121 }
122 
123 
124 
125 #endif
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
bool udfustop_
Definition: squeezing.h:66
void setUntouchedRange(T u0, T u1)
Definition: squeezing.h:53
Interval of values.
Definition: commontypes.h:31
void setRange(const Interval< T > &, bool lim)
Definition: squeezing.h:72
bool udfstop_
Definition: squeezing.h:65
void setUntouchedRange(const Interval< T > &r)
Definition: squeezing.h:49
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
Interval< T > rg_
Definition: squeezing.h:63
Fits values into a pre-defined range.
Definition: squeezing.h:43
T stop
Definition: ranges.h:93
const Interval< T > & range(bool lim) const
Definition: squeezing.h:58
DataSqueezer(const Interval< T > &l)
Definition: squeezing.h:47
DataSqueezer(T l0, T l1)
Definition: squeezing.h:51
T start
Definition: ranges.h:92
T value(T) const
Definition: squeezing.h:89
virtual void sort(bool asc=true)
Definition: ranges.h:585
#define mClass(module)
Definition: commondefs.h:164
Interval< T > urg_
Definition: squeezing.h:64

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