Helios++
Helios software for LiDAR simulations
UnivarExprTreeNode< NumericType > Class Template Reference

Class implementing a Univariate Expression Tree Node. More...

#include <UnivarExprTreeNode.h>

Inheritance diagram for UnivarExprTreeNode< NumericType >:
Collaboration diagram for UnivarExprTreeNode< NumericType >:

Public Types

enum  SymbolType { OPERATOR , NUMBER , VARIABLE , FUNCTION }
 The different types of element (symbols) supported by the univariate expression tree node.
 
enum  OpType {
  OP_ADD , OP_SUB , OP_MUL , OP_DIV ,
  OP_POW , OP_IPOW , OP_atan2
}
 The different operators supported by the univariate expression tree node.
 
enum  FunType {
  f_exp , f_ln , f_sqrt , f_abs ,
  f_cos , f_sin , f_tan , f_acos ,
  f_asin , f_atan , f_cosh , f_sinh ,
  f_tanh
}
 The different functions supported by the univariate expression tree node.
 

Public Member Functions

 UnivarExprTreeNode (UnivarExprTreeNode *left=nullptr, UnivarExprTreeNode *right=nullptr)
 Default constructor for Univariate Expression Tree Node. More...
 
NumericType doOperation (NumericType const x, NumericType const y) const
 Do the operation if the node is an operator node. Otherwise, something really wrong might happen. Something that you don't want to experiment. More...
 
NumericType doFunction (NumericType const x) const
 Compute the function's output for the given input \(x\). More...
 
NumericType eval (NumericType const t) const override
 
IBinaryTreeNodegetLeftChild () const override
 Obtain the left child of current node. More...
 
IBinaryTreeNodegetRightChild () const override
 Obtain the right child of current node. More...
 
bool isLeafNode () const override
 Simplified check because for UnivarExprTreeNode there is no right child without a left child. More...
 
bool isOperator () const
 Check whether the node is an operator (true) or not (false) More...
 
bool isFunction () const
 Check whether the node is a function (true) or not (false) More...
 
bool isNumber () const
 Check whether the node is a number (true) or not (false) More...
 
bool isVariable () const
 Check whether the node is a variable (true) or not (false) More...
 
void setOperator (std::string const &opStr)
 Set the operator UnivarExprTreeNode::op from given string. More...
 

Public Attributes

SymbolType symbolType
 The type of element (symbol) used by the univariate expression tree node. More...
 
union {
   NumericType   num
 Number as node's element.
 
   OpType   op
 Operator as node's element.
 
   FunType   fun
 Function as node's element.
 
}; 
 The element of the node.
 
UnivarExprTreeNodeleft
 The left child node.
 
UnivarExprTreeNoderight
 The right child node.
 

Detailed Description

template<typename NumericType>
class UnivarExprTreeNode< NumericType >

Class implementing a Univariate Expression Tree Node.

Author
Alberto M. Esmoris Pena
Version
1.0

The Univariate Expression Tree Node supports univariate expressions where \(t\) is the variable. Univariate expression trees can work with real numbers (complex are outside its scope). Supported operators are \(+, -, *, /, \textrm{^}\). Supported constants are \(e, \pi\). Supported functions are \(\exp, \ln, \mathrm{sqrt}, \mathrm{abs}, \) \(\cos, \sin, \tan, \mathrm{acos}, \mathrm{asin}, \mathrm{atan}, \) \(\mathrm{atan2}, \cosh, \sinh, \tanh\). However since \(atan2\) is a bivariate function, it is internally considered as an operator due to an implementation trick.

Template Parameters
NumericTypeThe numeric type to be used by the univariate expression tree. It must be contained or equal to the reals ( \(\subseteq \mathbb{R}\)).

Constructor & Destructor Documentation

◆ UnivarExprTreeNode()

template<typename NumericType >
UnivarExprTreeNode< NumericType >::UnivarExprTreeNode ( UnivarExprTreeNode< NumericType > *  left = nullptr,
UnivarExprTreeNode< NumericType > *  right = nullptr 
)
inline

Default constructor for Univariate Expression Tree Node.

Parameters
leftThe left child node
rightThe right child node

Member Function Documentation

◆ doFunction()

template<typename NumericType >
NumericType UnivarExprTreeNode< NumericType >::doFunction ( NumericType const  x) const
inline

Compute the function's output for the given input \(x\).

Parameters
xThe function's input \(x\)
Returns
The function's output \(f(x)\)

◆ doOperation()

template<typename NumericType >
NumericType UnivarExprTreeNode< NumericType >::doOperation ( NumericType const  x,
NumericType const  y 
) const
inline

Do the operation if the node is an operator node. Otherwise, something really wrong might happen. Something that you don't want to experiment.

Parameters
xThe left hand side (lhs) \(x\)
yThe right hand side (rhs) \(x\)
Returns
Result of applying the operator \(\odot\) such that \(x \odot y\)

◆ eval()

template<typename NumericType >
NumericType UnivarExprTreeNode< NumericType >::eval ( NumericType const  t) const
inlineoverridevirtual

◆ getLeftChild()

template<typename NumericType >
IBinaryTreeNode* UnivarExprTreeNode< NumericType >::getLeftChild ( ) const
inlineoverridevirtual

Obtain the left child of current node.

Returns
Left child

Implements IBinaryTreeNode.

◆ getRightChild()

template<typename NumericType >
IBinaryTreeNode* UnivarExprTreeNode< NumericType >::getRightChild ( ) const
inlineoverridevirtual

Obtain the right child of current node.

Returns
Right child

Implements IBinaryTreeNode.

◆ isFunction()

template<typename NumericType >
bool UnivarExprTreeNode< NumericType >::isFunction ( ) const
inline

Check whether the node is a function (true) or not (false)

Returns
True if node is a function, false otherwise

◆ isLeafNode()

template<typename NumericType >
bool UnivarExprTreeNode< NumericType >::isLeafNode ( ) const
inlineoverridevirtual

Simplified check because for UnivarExprTreeNode there is no right child without a left child.

See also
IBinaryTreeNode::isLeafNode

Reimplemented from IBinaryTreeNode.

◆ isNumber()

template<typename NumericType >
bool UnivarExprTreeNode< NumericType >::isNumber ( ) const
inline

Check whether the node is a number (true) or not (false)

Returns
True if node is a number, false otherwise

◆ isOperator()

template<typename NumericType >
bool UnivarExprTreeNode< NumericType >::isOperator ( ) const
inline

Check whether the node is an operator (true) or not (false)

Returns
True if node is an operator, false otherwise

◆ isVariable()

template<typename NumericType >
bool UnivarExprTreeNode< NumericType >::isVariable ( ) const
inline

Check whether the node is a variable (true) or not (false)

Returns
True if node is a variable, false otherwise

◆ setOperator()

template<typename NumericType >
void UnivarExprTreeNode< NumericType >::setOperator ( std::string const &  opStr)
inline

Set the operator UnivarExprTreeNode::op from given string.

Parameters
opStrString representing an operator for the node

Member Data Documentation

◆ symbolType

template<typename NumericType >
SymbolType UnivarExprTreeNode< NumericType >::symbolType

The type of element (symbol) used by the univariate expression tree node.

See also
UnivarExprTreeNode::SymbolType

The documentation for this class was generated from the following file: