OpendTect  7.0
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...

Inheritance diagram for Math::Formula:
[legend]

Classes

class  InpDef
 

Public Member Functions

 Formula (bool inputsareseries, const SpecVarSet &, const char *txt=nullptr)
 
 Formula (bool inputsareseries=true, const char *txt=nullptr)
 
 Formula (const Formula &)
 
 ~Formula ()
 
void clearAllDefs ()
 
void clearInputDefs ()
 
FormulacopyFrom (const Math::Formula &)
 *< Does not use the description and values More...
 
const char * description () const
 
const char * errMsg () const
 
const Expressionexpression () const
 
void fillPar (IOPar &) const
 
double getConstVal (int) const
 if isConst returns toDouble(inputDef(i)), else Udf More...
 
void getInputMnemonics (MnemonicSelection &) const
 
const TypeSet< int > & getShifts (int iinp) const
 
double getValue (const double *) const
 
double getValue (const double *vals, bool internuns) const
 
float getValue (const float *vals, bool internuns=true) const
 
bool hasFixedUnits () const
 
const char * inputDef (int iinp) const
 
const char * inputDescription (int iinp) const
 
const UnitOfMeasureinputFormUnit (int iinp) const
 
const MnemonicinputMnemonic (int iinp) const
 
bool inputsAreSeries () const
 
const char * inputVar (int iinp) const
 
bool isBad () const
 
bool isCompatibleWith (const Formula &) const
 
bool isCompatibleWith (const Mnemonic &, const MnemonicSelection *inps=nullptr) 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 nrSpecs () const
 
int nrValues2Provide () const
 
bool operator!= (const Formula &) const
 *< Does not use the description More...
 
Formulaoperator= (const Formula &)
 *< Does not use the description More...
 
bool operator== (const Formula &) const
 
const UnitOfMeasureoutputFormUnit () const
 
const MnemonicoutputMnemonic () const
 
TypeSet< double > & recStartVals ()
 
void setDescription (const char *descstr)
 *< Does not copy input definitions and descriptions More...
 
void setInputDef (int, const char *)
 
void setInputDescription (int, const char *)
 Optional description of an input. More...
 
void setInputFormUnit (int, const UnitOfMeasure *)
 The input unit within the expression. More...
 
void setInputMnemonic (int, const Mnemonic *)
 
void setInputValUnit (int, const UnitOfMeasure *)
 The input unit of incoming values. More...
 
void setOutputFormUnit (const UnitOfMeasure *uom)
 The output unit of the math expression. More...
 
void setOutputMnemonic (const Mnemonic *mn)
 
void setOutputValUnit (const UnitOfMeasure *uom)
 The unit of the returned value (getValue) More...
 
virtual 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
 
- Public Member Functions inherited from NamedObject
 NamedObject (const char *nm=nullptr)
 
 NamedObject (const NamedObject &oth)
 
virtual ~NamedObject ()
 
virtual BufferString getName () const
 
bool getNameFromPar (const IOPar &)
 
const name_typename () const override
 
NamedObjectoperator= (const NamedObject &)
 
bool operator== (const NamedObject &oth) const
 
virtual void setName (const char *nm)
 
- Public Member Functions inherited from ObjectWithName
virtual ~ObjectWithName ()
 
bool hasName (const char *nm) const
 
bool hasName (const name_type &nm) const
 
void putNameInPar (IOPar &) 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 desc_
 
BufferString errmsg_
 
Expressionexpr_ = nullptr
 
Threads::Lock formlock_
 
TypeSet< int > inpidxs_
 
ObjectSet< InpDefinps_
 
const bool inputsareseries_
 
const Mnemonicoutputformmn_ = nullptr
 
const UnitOfMeasureoutputformunit_ = nullptr
 
const UnitOfMeasureoutputvalunit_ = nullptr
 
TypeSet< double > prevvals_
 
TypeSet< int > recshifts_
 
TypeSet< double > recstartvals_
 
const SpecVarSetspecvars_
 
BufferString text_
 
TypeSet< int > validxs_
 
- Protected Attributes inherited from NamedObject
BufferString name_
 

Additional Inherited Members

- Public Types inherited from ObjectWithName
typedef OD::String name_type
 

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 setInputFormUnit(idx) before calculation, this unit is the unit that the user wants the variable value to be used into the mathexpression. setOutputFormUnit(idx) will specify the unit of the variable return by 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 match the form input units, otherwise setInputValUnit must be called. The output values will match the form output unit, unless setOutputValUnit was called.

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 = nullptr 
)

◆ Formula() [2/3]

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

◆ 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

◆ clearAllDefs()

void Math::Formula::clearAllDefs ( )

◆ clearInputDefs()

void Math::Formula::clearInputDefs ( )

◆ copyFrom()

Formula& Math::Formula::copyFrom ( const Math::Formula )

*< Does not use the description and values

◆ description()

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

◆ 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

◆ getInputMnemonics()

void Math::Formula::getInputMnemonics ( MnemonicSelection ) const

◆ getShifts()

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

◆ getValue() [1/3]

double Math::Formula::getValue ( const double *  ) const

You may annotate the units of incoming values, and require the conversion of the output value

◆ getValue() [2/3]

double Math::Formula::getValue ( const double *  vals,
bool  internuns 
) const

◆ getValue() [3/3]

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

◆ hasFixedUnits()

bool Math::Formula::hasFixedUnits ( ) const

◆ inputDef()

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

◆ inputDescription()

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

◆ inputFormUnit()

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

◆ inputMnemonic()

const Mnemonic* Math::Formula::inputMnemonic ( int  iinp) const
inline

◆ inputsAreSeries()

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

◆ inputVar()

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

◆ isBad()

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

◆ isCompatibleWith() [1/2]

bool Math::Formula::isCompatibleWith ( const Formula ) const

◆ isCompatibleWith() [2/2]

bool Math::Formula::isCompatibleWith ( const Mnemonic ,
const MnemonicSelection inps = nullptr 
) const

◆ 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

◆ nrSpecs()

int Math::Formula::nrSpecs ( ) const

◆ nrValues2Provide()

int Math::Formula::nrValues2Provide ( ) const

◆ operator!=()

bool Math::Formula::operator!= ( const Formula ) const

*< Does not use the description

◆ operator=()

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

*< Does not use the description

◆ operator==()

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

◆ outputFormUnit()

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

◆ outputMnemonic()

const Mnemonic* Math::Formula::outputMnemonic ( ) const
inline

◆ recStartVals()

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

◆ setDescription()

void Math::Formula::setDescription ( const char *  descstr)
inline

*< Does not copy input definitions and descriptions

Optional description of the formula output

◆ setInputDef()

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

The variable name (replacing c*), or a string carrying a constant/special value

◆ setInputDescription()

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

Optional description of an input.

◆ setInputFormUnit()

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

The input unit within the expression.

◆ setInputMnemonic()

void Math::Formula::setInputMnemonic ( int  ,
const Mnemonic  
)

◆ setInputValUnit()

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

The input unit of incoming values.

◆ setOutputFormUnit()

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

The output unit of the math expression.

◆ setOutputMnemonic()

void Math::Formula::setOutputMnemonic ( const Mnemonic mn)
inline

◆ setOutputValUnit()

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

The unit of the returned value (getValue)

◆ setText()

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

Reimplemented in RockPhysics::Formula.

◆ 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

◆ desc_

BufferString Math::Formula::desc_
protected

◆ errmsg_

BufferString Math::Formula::errmsg_
mutableprotected

◆ expr_

Expression* Math::Formula::expr_ = nullptr
protected

◆ formlock_

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

◆ inpidxs_

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

◆ inps_

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

◆ inputsareseries_

const bool Math::Formula::inputsareseries_
protected

◆ outputformmn_

const Mnemonic* Math::Formula::outputformmn_ = nullptr
protected

◆ outputformunit_

const UnitOfMeasure* Math::Formula::outputformunit_ = nullptr
protected

◆ outputvalunit_

const UnitOfMeasure* Math::Formula::outputvalunit_ = nullptr
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-2024