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

Static Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

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

◆ Formula() [1/3]

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

◆ Formula() [2/3]

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

◆ Formula() [3/3]

Math::Formula::Formula ( const Formula )

◆ ~Formula()

Math::Formula::~Formula ( )

Member Function Documentation

◆ addShift()

void Math::Formula::addShift ( int  ,
int  ,
int &  ,
TypeSet< TypeSet< int > > &   
)
protected

◆ clearInputDefs()

void Math::Formula::clearInputDefs ( )

◆ errMsg()

const char* Math::Formula::errMsg ( ) const
inline

◆ expression()

const Expression* Math::Formula::expression ( ) const
inline

◆ fillPar()

void Math::Formula::fillPar ( IOPar ) const

◆ getConstVal()

double Math::Formula::getConstVal ( int  ) const

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

◆ getShifts()

const TypeSet<int>& Math::Formula::getShifts ( int  iinp) const
inline

◆ getValue() [1/2]

double Math::Formula::getValue ( const double *  ,
bool  internal_units = true 
) const

◆ getValue() [2/2]

float Math::Formula::getValue ( const float *  ,
bool  internal_units = true 
) const

◆ inputDef()

const char* Math::Formula::inputDef ( int  iinp) const
inline

◆ inputsAreSeries()

bool Math::Formula::inputsAreSeries ( ) const
inline

◆ inputUnit()

const UnitOfMeasure* Math::Formula::inputUnit ( int  iinp) const
inline

◆ isBad()

bool Math::Formula::isBad ( ) const
inline

◆ isConst()

bool Math::Formula::isConst ( int  iinp) const
inline

◆ isOK()

bool Math::Formula::isOK ( ) const
inline

◆ isRecursive()

bool Math::Formula::isRecursive ( ) const
inline

◆ isSpec()

bool Math::Formula::isSpec ( int  iinp) const
inline

◆ maxRecShift()

int Math::Formula::maxRecShift ( ) const
inline

◆ nrConsts()

int Math::Formula::nrConsts ( ) const

◆ nrExternalInputs()

int Math::Formula::nrExternalInputs ( ) const

◆ nrInputs()

int Math::Formula::nrInputs ( ) const
inline

◆ nrValues2Provide()

int Math::Formula::nrValues2Provide ( ) const

◆ operator=()

Formula& Math::Formula::operator= ( const Formula )

◆ outputUnit()

const UnitOfMeasure* Math::Formula::outputUnit ( ) const
inline

◆ recStartVals()

TypeSet<double>& Math::Formula::recStartVals ( )
inline

◆ setInputDef()

void Math::Formula::setInputDef ( int  ,
const char *   
)

◆ setInputUnit()

void Math::Formula::setInputUnit ( int  ,
const UnitOfMeasure  
)

◆ setOutputUnit()

void Math::Formula::setOutputUnit ( const UnitOfMeasure uom)
inline

◆ setText()

void Math::Formula::setText ( const char *  )

◆ shiftRange()

Interval<int> Math::Formula::shiftRange ( int  iinp) const
inline

◆ sKeyExpression()

static const char* Math::Formula::sKeyExpression ( )
inlinestatic

◆ sKeyFileType()

static const char* Math::Formula::sKeyFileType ( )
inlinestatic

◆ sKeyRecStartVals()

static const char* Math::Formula::sKeyRecStartVals ( )
inlinestatic

◆ specIdx()

int Math::Formula::specIdx ( int  ) const

◆ specVars()

const SpecVarSet& Math::Formula::specVars ( ) const
inline

◆ startNewSeries()

void Math::Formula::startNewSeries ( ) const

◆ text()

const char* Math::Formula::text ( ) const
inline

◆ usePar()

void Math::Formula::usePar ( const IOPar )

◆ userDispText()

const char* Math::Formula::userDispText ( ) const

◆ variableName()

const char* Math::Formula::variableName ( int  iinp) const
inline

◆ varNameIdx()

int Math::Formula::varNameIdx ( const char *  varnm) const
protected

Member Data Documentation

◆ errmsg_

BufferString Math::Formula::errmsg_
mutableprotected

◆ expr_

Expression* Math::Formula::expr_
protected

◆ formlock_

Threads::Lock Math::Formula::formlock_
mutableprotected

◆ inpidxs_

TypeSet<int> Math::Formula::inpidxs_
protected

◆ inps_

TypeSet<InpDef> Math::Formula::inps_
protected

◆ inputsareseries_

const bool Math::Formula::inputsareseries_
protected

◆ outputunit_

const UnitOfMeasure* Math::Formula::outputunit_
protected

◆ prevvals_

TypeSet<double> Math::Formula::prevvals_
mutableprotected

◆ recshifts_

TypeSet<int> Math::Formula::recshifts_
protected

◆ recstartvals_

TypeSet<double> Math::Formula::recstartvals_
protected

◆ specvars_

const SpecVarSet* Math::Formula::specvars_
protected

◆ text_

BufferString Math::Formula::text_
protected

◆ validxs_

TypeSet<int> Math::Formula::validxs_
protected

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