OpendTect  6.6
scaler.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: 8-9-1995
9  Contents: Scaler objects
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "algomod.h"
16 #include "gendefs.h"
17 #include "undefval.h"
18 
19 #define sLinScaler "Linear"
20 #define sLogScaler "Logarithmic"
21 #define sExpScaler "Exponential"
22 #define sAsymptScaler "Asymptotic"
23 
24 
33 {
34 public:
35  static Scaler* get(const char*);
36  virtual ~Scaler() {}
37 
38  mDeprecated("Provide the size of the write buffer")
39  void put(char*) const;
40  void put(char*,int sz) const;
41 
42  virtual bool isEmpty() const { return false; }
43  virtual Scaler* clone() const = 0;
44  virtual const char* type() const = 0;
45 
46  virtual double scale(double) const = 0;
47  virtual double unScale(double) const { return mUdf(double); }
48  virtual const char* toString() const = 0;
49  virtual void fromString(const char*) = 0;
50 };
51 
52 
57 mExpClass(Algo) LinScaler : public Scaler
58 {
59 public:
60  LinScaler( double c=0, double f=1 )
61  : constant(c), factor(f) {}
62  LinScaler( double x0, double y0, double x1, double y1 );
63  void set( double x0, double y0, double x1, double y1 );
64  virtual LinScaler* clone() const
65  { return new LinScaler(constant,factor); }
66  inline bool isEmpty() const;
67 
68  const char* type() const { return sLinScaler; }
69 
70  double scale(double) const;
71  double unScale(double) const;
72  const char* toString() const;
73  void fromString(const char*);
74 
75  bool operator==( const LinScaler& b ) const
76  {
77  return mIsEqual(constant,b.constant,mDefEps) &&
78  mIsEqual(factor,b.factor,mDefEps);
79  }
80 
81  double constant;
82  double factor;
83 };
84 
85 inline bool LinScaler::isEmpty() const
86 {
87  return constant > -1e-15 && constant < 1e-15 && mIsEqual(factor,1,mDefEps);
88 }
89 
90 
95 mExpClass(Algo) LogScaler : public Scaler
96 {
97 public:
98  LogScaler( bool powerof10=true )
99  : ten_(powerof10) {}
100  const char* type() const { return sLogScaler; }
101  virtual LogScaler* clone() const
102  { return new LogScaler(ten_); }
103 
104  double scale(double) const;
105  double unScale(double) const;
106  const char* toString() const;
107  void fromString(const char*);
108  bool operator==( const LogScaler& b ) const
109  { return ten_==b.ten_; }
110 
111  bool ten_;
112 };
113 
114 
119 mExpClass(Algo) ExpScaler : public Scaler
120 {
121 public:
122  ExpScaler( bool powerof10=true )
123  : ten_(powerof10) {}
124  const char* type() const { return sExpScaler; }
125  virtual ExpScaler* clone() const
126  { return new ExpScaler(ten_); }
127 
128  double scale(double) const;
129  double unScale(double) const;
130  const char* toString() const;
131  void fromString(const char*);
132 
133  bool operator==( const ExpScaler& b ) const
134  { return ten_==b.ten_; }
135 
136  bool ten_;
137 };
138 
139 
153 {
154 public:
155  AsymptScaler( double c=0, double w=1, double l=0.95 )
156  : center_(c), width_(w), linedge_(l), factor(1)
157  { set(c,w,l); }
158  const char* type() const { return sAsymptScaler; }
159  virtual AsymptScaler* clone() const
160  { return new AsymptScaler(center_,width_,linedge_); }
161 
162  double scale(double) const;
163  double unScale(double) const;
164  const char* toString() const;
165  void fromString(const char*);
166 
167  inline bool operator==( const AsymptScaler& b ) const
168  { return mIsEqual(center_,b.center_,mDefEps)
169  && mIsEqual(width_,b.width_,mDefEps)
170  && mIsEqual(linedge_,b.linedge_,mDefEps); }
171 
172  void set(double,double,double);
173  inline double center() const { return center_; }
174  inline double width() const { return width_; }
175  inline double linedge() const { return linedge_; }
176 
177 protected:
178 
179  double center_;
180  double width_;
181  double linedge_;
182 
183  double factor;
184 };
185 
186 
ExpScaler::scale
double scale(double) const
AsymptScaler::linedge_
double linedge_
Definition: scaler.h:181
Scaler::clone
virtual Scaler * clone() const =0
Scaler::type
virtual const char * type() const =0
AsymptScaler::AsymptScaler
AsymptScaler(double c=0, double w=1, double l=0.95)
Definition: scaler.h:155
mIsEqual
#define mIsEqual(x, y, eps)
Definition: commondefs.h:67
ExpScaler::unScale
double unScale(double) const
ExpScaler::fromString
void fromString(const char *)
ExpScaler
Exponential scaling, base e or ten.
Definition: scaler.h:120
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
LinScaler::toString
const char * toString() const
AsymptScaler::width_
double width_
Definition: scaler.h:180
LinScaler::isEmpty
bool isEmpty() const
Definition: scaler.h:85
LogScaler::toString
const char * toString() const
sLogScaler
#define sLogScaler
Definition: scaler.h:20
mDefEps
#define mDefEps
Definition: commondefs.h:71
AsymptScaler
Asymptotic or 'Squeeze' scaling, with a linear (main) part.
Definition: scaler.h:153
Scaler::mDeprecated
mDeprecated("Provide the size of the write buffer") void put(char *) const
LinScaler::constant
double constant
Definition: scaler.h:81
LinScaler::LinScaler
LinScaler(double c=0, double f=1)
Definition: scaler.h:60
ExpScaler::operator==
bool operator==(const ExpScaler &b) const
Definition: scaler.h:133
undefval.h
isEmpty
bool isEmpty(const NLAModel *mdl)
LinScaler::LinScaler
LinScaler(double x0, double y0, double x1, double y1)
LogScaler::unScale
double unScale(double) const
LogScaler::ten_
bool ten_
Definition: scaler.h:111
LinScaler
Linear scaling.
Definition: scaler.h:58
LinScaler::factor
double factor
Definition: scaler.h:82
AsymptScaler::set
void set(double, double, double)
Scaler
Scaling of floating point numbers.
Definition: scaler.h:33
AsymptScaler::center_
double center_
Definition: scaler.h:179
AsymptScaler::width
double width() const
Definition: scaler.h:174
ExpScaler::clone
virtual ExpScaler * clone() const
Definition: scaler.h:125
ExpScaler::toString
const char * toString() const
LinScaler::set
void set(double x0, double y0, double x1, double y1)
LinScaler::operator==
bool operator==(const LinScaler &b) const
Definition: scaler.h:75
gendefs.h
AsymptScaler::toString
const char * toString() const
LogScaler::operator==
bool operator==(const LogScaler &b) const
Definition: scaler.h:108
Scaler::fromString
virtual void fromString(const char *)=0
LogScaler::fromString
void fromString(const char *)
LinScaler::clone
virtual LinScaler * clone() const
Definition: scaler.h:64
Scaler::get
static Scaler * get(const char *)
LogScaler::type
const char * type() const
Definition: scaler.h:100
Conv::set
void set(T &_to, const F &fr)
template based type conversion
Definition: convert.h:27
LinScaler::fromString
void fromString(const char *)
AsymptScaler::linedge
double linedge() const
Definition: scaler.h:175
Scaler::toString
virtual const char * toString() const =0
AsymptScaler::clone
virtual AsymptScaler * clone() const
Definition: scaler.h:159
Scaler::scale
virtual double scale(double) const =0
Scaler::unScale
virtual double unScale(double) const
Definition: scaler.h:47
AsymptScaler::fromString
void fromString(const char *)
LinScaler::unScale
double unScale(double) const
LogScaler::scale
double scale(double) const
ExpScaler::ExpScaler
ExpScaler(bool powerof10=true)
Definition: scaler.h:122
Scaler::~Scaler
virtual ~Scaler()
Definition: scaler.h:36
AsymptScaler::unScale
double unScale(double) const
LogScaler::clone
virtual LogScaler * clone() const
Definition: scaler.h:101
AsymptScaler::type
const char * type() const
Definition: scaler.h:158
AsymptScaler::operator==
bool operator==(const AsymptScaler &b) const
Definition: scaler.h:167
mUdf
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:274
sExpScaler
#define sExpScaler
Definition: scaler.h:21
sAsymptScaler
#define sAsymptScaler
Definition: scaler.h:22
LinScaler::scale
double scale(double) const
ExpScaler::ten_
bool ten_
Definition: scaler.h:136
AsymptScaler::factor
double factor
Definition: scaler.h:183
AsymptScaler::scale
double scale(double) const
LinScaler::type
const char * type() const
Definition: scaler.h:68
LogScaler
Logarithmic scaling, base e or ten.
Definition: scaler.h:96
sLinScaler
#define sLinScaler
Definition: scaler.h:19
AsymptScaler::center
double center() const
Definition: scaler.h:173
ExpScaler::type
const char * type() const
Definition: scaler.h:124
LogScaler::LogScaler
LogScaler(bool powerof10=true)
Definition: scaler.h:98

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