OpendTect-6_4  6.4
mathformula.h
Go to the documentation of this file.
1 #ifndef mathformula_h
2 #define mathformula_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Bert
9  Date: Apr 2014
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "generalmod.h"
16 #include "typeset.h"
17 #include "ranges.h"
18 class UnitOfMeasure;
19 
20 
21 namespace Math
22 {
23 
24 class SpecVarSet;
25 class Expression;
26 
27 
28 
66 {
67 public:
68 
69  Formula(bool inputsareseries=true,const char* txt=0);
70  Formula(bool inputsareseries,const SpecVarSet&,
71  const char* txt=0);
72  Formula(const Formula&);
73  ~Formula();
74  Formula& operator =(const Formula&);
75 
76  // 0. Specify the formula text. Will construct a new Expression
77 
78  void setText(const char*);
79 
80  // 1. Things known after construction or setText()
81 
82  bool isOK() const { return expr_; }
83  bool isBad() const { return !expr_
84  && !text_.isEmpty(); }
85  const char* errMsg() const { return errmsg_; }
86 
87  const char* text() const { return text_; }
88  int nrInputs() const { return inps_.size(); }
89  const char* variableName( int iinp ) const
90  { return inps_[iinp].varname_; }
91  bool isConst( int iinp ) const
92  { return inps_[iinp].isConst();}
93  bool isSpec( int iinp ) const
94  { return inps_[iinp].isSpec(); }
95  int specIdx(int) const;
96  const TypeSet<int>& getShifts( int iinp ) const
97  { return inps_[iinp].shifts_; }
98  Interval<int> shiftRange( int iinp ) const
99  { return inps_[iinp].shftRg(); }
100  bool isRecursive() const { return maxRecShift() > 0; }
101  int maxRecShift() const { return recstartvals_.size(); }
102 
103  // 2. Things to set before calculation or store
104 
105  void setInputDef(int,const char*);
106  void setInputUnit(int,const UnitOfMeasure*);
107  void setOutputUnit( const UnitOfMeasure* uom )
108  { outputunit_ = uom; }
109  TypeSet<double>& recStartVals() { return recstartvals_; }
110  void clearInputDefs();
111 
112  // 3. Things you have set yourself or that were retrieved
113 
114  const UnitOfMeasure* outputUnit() const { return outputunit_; }
115  const char* inputDef( int iinp ) const
116  { return inps_[iinp].inpdef_; }
117  const UnitOfMeasure* inputUnit( int iinp ) const
118  { return inps_[iinp].unit_; }
119  double getConstVal(int) const;
121 
122  // 4. To get an output value
123 
124  int nrValues2Provide() const;
125  void startNewSeries() const; // resets recursive values
126  float getValue(const float*,bool internal_units=true) const;
127  double getValue(const double*,bool internal_units=true) const;
128 
129  // 5. store/retrieve to/from IOPar
130 
131  void fillPar(IOPar&) const;
132  void usePar(const IOPar&);
133 
134 
135  const Expression* expression() const { return expr_; };
136  const SpecVarSet& specVars() const { return *specvars_; }
137  bool inputsAreSeries() const { return inputsareseries_; }
138  int nrConsts() const;
139  const char* userDispText() const;
140  int nrExternalInputs() const;
141 
142  static const char* sKeyExpression() { return "Expression"; }
143  static const char* sKeyRecStartVals() { return "Recursion start"; }
144  static const char* sKeyFileType() { return "Math Formula"; }
145 
146 protected:
147 
148  class InpDef
149  {
150  public:
151 
152  enum Type { Var, Const, Spec };
153 
154  InpDef( const char* nm, Type t )
155  : varname_(nm), unit_(0), type_(t) {}
156  bool operator==( const InpDef& id ) const
157  { return varname_ == id.varname_; }
158 
159  BufferString varname_; // from Expression
160  Type type_; // from Expression
161  TypeSet<int> shifts_; // from Expression
162  BufferString inpdef_; // filled by class user
163  const UnitOfMeasure* unit_; // filled by class user
164 
165  Interval<int> shftRg() const;
166  bool isConst() const { return type_ == Const; }
167  bool isSpec() const { return type_ == Spec; }
168 
169  };
170 
176  const bool inputsareseries_;
177 
179 
180  // length: expr_->nrVariables()
184 
187 
188  int varNameIdx(const char* varnm) const;
189  void addShift(int,int,int&,TypeSet< TypeSet<int> >&);
190 
191 };
192 
193 
194 } // namespace Math
195 
196 
197 #endif
#define mExpClass(module)
Definition: commondefs.h:160
int maxRecShift() const
Definition: mathformula.h:101
Type
Definition: mathformula.h:152
TypeSet< int > validxs_
Definition: mathformula.h:183
InpDef(const char *nm, Type t)
Definition: mathformula.h:154
const char * variableName(int iinp) const
Definition: mathformula.h:89
bool isRecursive() const
Definition: mathformula.h:100
void setOutputUnit(const UnitOfMeasure *uom)
Definition: mathformula.h:107
Interval< int > shiftRange(int iinp) const
Definition: mathformula.h:98
void usePar(const IOPar &iop, ODPolygon< T > &poly, const char *inpkey)
Definition: polygon.h:188
Type type_
Definition: mathformula.h:160
TypeSet< double > recstartvals_
Definition: mathformula.h:174
const SpecVarSet * specvars_
Definition: mathformula.h:175
static const char * sKeyRecStartVals()
Definition: mathformula.h:143
TypeSet< double > & recStartVals()
Definition: mathformula.h:109
const Expression * expression() const
Definition: mathformula.h:135
static const char * sKeyFileType()
Definition: mathformula.h:144
BufferString varname_
Definition: mathformula.h:159
Set of special variables for Math Formulae/Expressions.
Definition: mathspecvars.h:47
BufferString errmsg_
Definition: mathformula.h:186
bool isConst() const
Definition: mathformula.h:166
bool isBad() const
Definition: mathformula.h:83
TypeSet< double > prevvals_
Definition: mathformula.h:185
Math formula: (expression, inputs, units, calculation, storage).
Definition: mathformula.h:65
const UnitOfMeasure * outputunit_
Definition: mathformula.h:173
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:47
BufferString inpdef_
Definition: mathformula.h:162
bool isOK() const
Definition: mathformula.h:82
TypeSet< int > inpidxs_
Definition: mathformula.h:181
const TypeSet< int > & getShifts(int iinp) const
Definition: mathformula.h:96
static const char * sKeyExpression()
Definition: mathformula.h:142
void fillPar(IOPar &iop, const ODPolygon< T > &poly, const char *inpkey)
Definition: polygon.h:175
BufferString text_
Definition: mathformula.h:171
Expression * expr_
Definition: mathformula.h:178
TypeSet< int > shifts_
Definition: mathformula.h:161
bool isSpec(int iinp) const
Definition: mathformula.h:93
bool operator==(const InpDef &id) const
Definition: mathformula.h:156
Parsed Math expression.
Definition: mathexpression.h:32
Definition: mathformula.h:152
const UnitOfMeasure * inputUnit(int iinp) const
Definition: mathformula.h:117
TypeSet< int > recshifts_
Definition: mathformula.h:182
bool isConst(int iinp) const
Definition: mathformula.h:91
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
BufferString errmsg_
Definition: horizontracker.h:119
const SpecVarSet & specVars() const
Definition: mathformula.h:136
Definition: math2.h:29
const UnitOfMeasure * outputUnit() const
Definition: mathformula.h:114
bool isSpec() const
Definition: mathformula.h:167
const char * inputDef(int iinp) const
Definition: mathformula.h:115
const bool inputsareseries_
Definition: mathformula.h:176
TypeSet< InpDef > inps_
Definition: mathformula.h:172
const UnitOfMeasure * unit_
Definition: mathformula.h:163
const char * text() const
Definition: mathformula.h:87
Unit of Measure.
Definition: unitofmeasure.h:35
bool inputsAreSeries() const
Definition: mathformula.h:137
const char * errMsg() const
Definition: mathformula.h:85
Definition: mathformula.h:148
int nrInputs() const
Definition: mathformula.h:88

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