OpendTect-6_4  6.4
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Math::Formula Class Reference

Math formula: (expression, inputs, units, calculation, storage). More...

Classes

class  InpDef
 

Public Member Functions

 Formula (bool inputsareseries=true, const char *txt=0)
 
 Formula (bool inputsareseries, const SpecVarSet &, const char *txt=0)
 
 Formula (const Formula &)
 
 ~Formula ()
 
Formulaoperator= (const Formula &)
 
void setText (const char *)
 
bool isOK () const
 
bool isBad () const
 
const char * errMsg () const
 
const char * text () const
 
int nrInputs () const
 
const char * variableName (int iinp) const
 
bool isConst (int iinp) const
 
bool isSpec (int iinp) const
 
int specIdx (int) const
 
const TypeSet< int > & getShifts (int iinp) const
 
Interval< int > shiftRange (int iinp) const
 
bool isRecursive () const
 
int maxRecShift () const
 
void setInputDef (int, const char *)
 
void setInputUnit (int, const UnitOfMeasure *)
 
void setOutputUnit (const UnitOfMeasure *uom)
 
TypeSet< double > & recStartVals ()
 
void clearInputDefs ()
 
const UnitOfMeasureoutputUnit () const
 
const char * inputDef (int iinp) const
 
const UnitOfMeasureinputUnit (int iinp) const
 
double getConstVal (int) const
 if isConst returns toDouble(inputDef(i)), else Udf More...
 
int nrValues2Provide () const
 
void startNewSeries () const
 
float getValue (const float *, bool internal_units=true) const
 
double getValue (const double *, bool internal_units=true) const
 
void fillPar (IOPar &) const
 
void usePar (const IOPar &)
 
const Expressionexpression () const
 
const SpecVarSetspecVars () const
 
bool inputsAreSeries () const
 
int nrConsts () const
 
const char * userDispText () const
 
int nrExternalInputs () const
 

Static Public Member Functions

static const char * sKeyExpression ()
 
static const char * sKeyRecStartVals ()
 
static const char * sKeyFileType ()
 

Protected Member Functions

int varNameIdx (const char *varnm) const
 
void addShift (int, int, int &, TypeSet< TypeSet< int > > &)
 

Protected Attributes

BufferString text_
 
TypeSet< InpDefinps_
 
const UnitOfMeasureoutputunit_
 
TypeSet< double > recstartvals_
 
const SpecVarSetspecvars_
 
const bool inputsareseries_
 
Expressionexpr_
 
TypeSet< int > inpidxs_
 
TypeSet< int > recshifts_
 
TypeSet< int > validxs_
 
TypeSet< double > prevvals_
 
BufferString errmsg_
 

Detailed Description

Math formula: (expression, inputs, units, calculation, storage).

Before construction gather your 'special variables'. Users can insert them and they are not 'regular input'. See SpecVars and SpecVarSet.

At construction or when calling setText(), the input text is parsed. Then, the variable definitions are known. You can use setInputUnit(idx) before calculation, this unit is the unit that the user wants the variable value to be converted to before inserting it into the mathexpression.

When you know what is required, you can provide numbers for the different inputs and get a result using getValue(). The input values you provide must be in internal units.

If your formula is to work on a series of input vectors, then two things become possible: 1) Recursive values. This is when the user uses out[i] ot this[i]. 2) Input shifts. For example: ampl[-1] or den[3]. For (1), you can specify start values. The maximum shift is the size of the TypeSet. These recursive variables will not show up in the inputs. For (2), you need to have extra values in the input value array (i.e. you need to loop over the getShifts(iinp).

Before using getValue(), you want to use setInputDef(idx) and maybe set the input unit conversions. This makes it possible to store/retrieve in IOPar, but this is aso required if there are constants in the expression.

The setOutputUnit() can be used to keep track of what the result means, or to get the result in that unit from getValue().

Lastly, the SpecVarSet you provide usually lives forever, but should at least stay alive during the lifetime of the formula (it is not copied).

Constructor & Destructor Documentation

Math::Formula::Formula ( bool  inputsareseries = true,
const char *  txt = 0 
)
Math::Formula::Formula ( bool  inputsareseries,
const SpecVarSet ,
const char *  txt = 0 
)
Math::Formula::Formula ( const Formula )
Math::Formula::~Formula ( )

Member Function Documentation

void Math::Formula::addShift ( int  ,
int  ,
int &  ,
TypeSet< TypeSet< int > > &   
)
protected
void Math::Formula::clearInputDefs ( )
const char* Math::Formula::errMsg ( ) const
inline
const Expression* Math::Formula::expression ( ) const
inline
void Math::Formula::fillPar ( IOPar ) const
double Math::Formula::getConstVal ( int  ) const

if isConst returns toDouble(inputDef(i)), else Udf

const TypeSet<int>& Math::Formula::getShifts ( int  iinp) const
inline
float Math::Formula::getValue ( const float *  ,
bool  internal_units = true 
) const
double Math::Formula::getValue ( const double *  ,
bool  internal_units = true 
) const
const char* Math::Formula::inputDef ( int  iinp) const
inline
bool Math::Formula::inputsAreSeries ( ) const
inline
const UnitOfMeasure* Math::Formula::inputUnit ( int  iinp) const
inline
bool Math::Formula::isBad ( ) const
inline
bool Math::Formula::isConst ( int  iinp) const
inline
bool Math::Formula::isOK ( ) const
inline
bool Math::Formula::isRecursive ( ) const
inline
bool Math::Formula::isSpec ( int  iinp) const
inline
int Math::Formula::maxRecShift ( ) const
inline
int Math::Formula::nrConsts ( ) const
int Math::Formula::nrExternalInputs ( ) const
int Math::Formula::nrInputs ( ) const
inline
int Math::Formula::nrValues2Provide ( ) const
Formula& Math::Formula::operator= ( const Formula )
const UnitOfMeasure* Math::Formula::outputUnit ( ) const
inline
TypeSet<double>& Math::Formula::recStartVals ( )
inline
void Math::Formula::setInputDef ( int  ,
const char *   
)
void Math::Formula::setInputUnit ( int  ,
const UnitOfMeasure  
)
void Math::Formula::setOutputUnit ( const UnitOfMeasure uom)
inline
void Math::Formula::setText ( const char *  )
Interval<int> Math::Formula::shiftRange ( int  iinp) const
inline
static const char* Math::Formula::sKeyExpression ( )
inlinestatic
static const char* Math::Formula::sKeyFileType ( )
inlinestatic
static const char* Math::Formula::sKeyRecStartVals ( )
inlinestatic
int Math::Formula::specIdx ( int  ) const
const SpecVarSet& Math::Formula::specVars ( ) const
inline
void Math::Formula::startNewSeries ( ) const
const char* Math::Formula::text ( ) const
inline
void Math::Formula::usePar ( const IOPar )
const char* Math::Formula::userDispText ( ) const
const char* Math::Formula::variableName ( int  iinp) const
inline
int Math::Formula::varNameIdx ( const char *  varnm) const
protected

Member Data Documentation

BufferString Math::Formula::errmsg_
mutableprotected
Expression* Math::Formula::expr_
protected
TypeSet<int> Math::Formula::inpidxs_
protected
TypeSet<InpDef> Math::Formula::inps_
protected
const bool Math::Formula::inputsareseries_
protected
const UnitOfMeasure* Math::Formula::outputunit_
protected
TypeSet<double> Math::Formula::prevvals_
mutableprotected
TypeSet<int> Math::Formula::recshifts_
protected
TypeSet<double> Math::Formula::recstartvals_
protected
const SpecVarSet* Math::Formula::specvars_
protected
BufferString Math::Formula::text_
protected
TypeSet<int> Math::Formula::validxs_
protected

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