SeExpr

Functions | Variables
tutorial.txt File Reference

## Functions
<!-- Copyright Disney Enterprises, Inc. All rights reserved. Licensed under the Apache License, Version 2.0(the "License");you may not use this file except in compliance with the License and the following modification to it:Section 6 Trademarks. deleted and replaced with:6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor and its affiliates, except as required for reproducing the content of the NOTICE file. You may obtain a copy of the License at http:-->< h2 > Programmer Tutorial</h2 >< p > Getting started with SeExpr is relatively easy SeExpr gives you a way to evaluate one or many evaluations of an expression What changes between different applications of expressions is mainly the particular variables that are | accessible (sometimes also the set of functions). Each application of expressions generally has it 's own subclass of Expression that gets instantiated. To get started we 're going to go through a simple application that is an ascii graphing calculator. This is located in the src/demos/asciiGraph.cpp part of the source tree.< p >< h2 >Problem Overview</h2 > We are going to write a function grapher that displays in ASCII. In particular for a given f(x) we can evaluate it at all the x 's in a window and draw the resulting y 's. For example if the user ran our program< pre > ./asciiGraph "val
* | sin (val)/val" </pre> we would get <pre> | | | | | </pre> or if we did <pre> ./asciiGraph "x-3" </pre> we'd get <pre> | | ------------------------------|----------------- | | | | | </pre> <h2>Implement the subclass</h2> First we subclass Expression and give it a const ructor
</pre > Once we have this we need an instance to store our variable and provide a reference to that We make it because | resolveVar () is const . One does not need to store a variable reference in a given expression. In fact
</pre >< h3 > Binding our variable reference</h3 > If we now tried to use the variable would still not be found by our expressions To make it bindable we need to override the resolveVar() function as follows</pre >< h3 > Variable setting</h3 > Next we need to make a way of setting the variable As the controlling code will use the expression it will repeatedly alternate between setting the independent variables that are used and calling evaluate(). What it has to do depends very much on the application. In this case we only need to set the independent variable x as</pre >< h2 > Evaluating expressions</h2 > Evaluating an expression is pretty easy But before we can do that we need to make an instance< pre > GrapherExpr | expr ("x+x^2")
</pre > there might be errors in the expression you must check with | isValid () before you can evaluate. Then you can print a parse error as well< pre > if(!expr.isValid())
| for (int i=0;i &lt;w;i++)

## Variables
</pre >< h3 > A simple variable reference</h3 > This is not a very interesting subclass of expression until we add some additional variables Variables on some applications may be very dynamic In this | case
</pre >< h3 > A simple variable reference</h3 > This is not a very interesting subclass of expression until we add some additional variables Variables on some applications may be very dynamic In this | however
</pre >< h3 > A simple variable reference</h3 > This is not a very interesting subclass of expression until we add some additional variables Variables on some applications may be very dynamic In this we only need | x
</pre > Once we have this we need an instance to store our variable and provide a reference to that We make it | mutable
</pre > Once we have this we need an instance to store our variable and provide a reference to that We make it because it may be useful to use the same ExprVarRef from multiple expressions ! For | example
</pre > Once we have this we need an instance to store our variable and provide a reference to that We make it because it may be useful to use the same ExprVarRef from multiple expressions ! For if you have expressions that all have access to the same | variables
</pre >< h3 > Binding our variable reference</h3 > If we now tried to use | expressions
</pre >< h3 > Binding our variable reference</h3 > If we now tried to use the variable would still not be found by our expressions To make it bindable we need to override the resolveVar() function as follows</pre >< h3 > Variable setting</h3 > Next we need to make a way of setting the variable As the controlling code will use the expression | evaluation
</pre > | However
</pre > | Finally
</pre > we can loop through all the x points in the graph and find out the y value as | follows
const double | one_over_samples_per_pixel =1./samplesPerPixel

## Function Documentation

## ◆ accessible()

<!-- Copyright Disney Enterprises, Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License and the following modification to it: Section 6 Trademarks. deleted and replaced with: 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor and its affiliates, except as required for reproducing the content of the NOTICE file. You may obtain a copy of the License at http: --><h2> Programmer Tutorial</h2><p> Getting started with SeExpr is relatively easy SeExpr gives you a way to evaluate one or many evaluations of an expression What changes between different applications of expressions is mainly the particular variables that are accessible | ( | sometimes also the set of | functions | ) |

## ◆ expr()

</pre><h3> Binding our variable reference</h3> If we now tried to use the variable would still not be found by our expressions To make it bindable we need to override the resolveVar () function as follows</pre><h3> Variable setting</h3> Next we need to make a way of setting the variable As the controlling code will use the expression it will repeatedly alternate between setting the independent variables that are used and calling evaluate (). What it has to do depends very much on the application. In this case we only need to set the independent variable x as</pre><h2> Evaluating expressions</h2> Evaluating an expression is pretty easy But before we can do that we need to make an instance<pre> GrapherExpr expr | ( | "x+x^2" |  | ) |

Referenced by SeExpr2::Expressions::addExpression(), ExprShortEdit::checkErrors(), SeExpr2::findComment(), main(), and EditableExpression::setExpr().

## ◆ for()

for | ( | int | i = `0;i&lt;w;i++` | ) |

Definition at line 193 of file tutorial.txt.

Referenced by SeExpr2::PrintFuncX::eval().

## ◆ isValid()

</pre> there might be errors in the expression you must check with isValid | ( |  | ) |

Definition at line 177 of file tutorial.txt.

Referenced by SeExpr2::ExprPrototypeNode::prep().

## ◆ resolveVar()

</pre> Once we have this we need an instance to store our variable and provide a reference to that We make it because resolveVar | ( |  | ) | const

## ◆ sin()

* sin | ( | val |  | ) | const

Referenced by SeExpr2::defineBuiltins(), SeExpr2::Vec< double, 3, false >::rotateBy(), and SeExpr2::sind().

## Variable Documentation

## ◆ case

</pre><h3> A simple variable reference</h3> This is not a very interesting subclass of expression until we add some additional variables Variables on some applications may be very dynamic In this case

Definition at line 108 of file tutorial.txt.

## ◆ evaluation

</pre><h3> Binding our variable reference</h3> If we now tried to use the variable would still not be found by our expressions To make it bindable we need to override the resolveVar () function as follows</pre><h3> Variable setting</h3> Next we need to make a way of setting the variable As the controlling code will use the expression evaluation

Definition at line 141 of file tutorial.txt.

## ◆ example

</pre> Once we have this we need an instance to store our variable and provide a reference to that We make it because it may be useful to use the same ExprVarRef from multiple expressions ! For example

Definition at line 128 of file tutorial.txt.

## ◆ expressions

</pre><h3> Binding our variable reference</h3> If we now tried to use expressions

Definition at line 140 of file tutorial.txt.

## ◆ Finally

</pre> Finally

Definition at line 185 of file tutorial.txt.

## ◆ follows

</pre> we can loop through all the x points in the graph and find out the y value as follows

Definition at line 185 of file tutorial.txt.

## ◆ however

</pre><h3> A simple variable reference</h3> This is not a very interesting subclass of expression until we add some additional variables Variables on some applications may be very dynamic In this however

Definition at line 108 of file tutorial.txt.

## ◆ However

</pre> However

Definition at line 177 of file tutorial.txt.

## ◆ mutable

</pre> Once we have this we need an instance to store our variable and provide a reference to that We make it mutable

Definition at line 126 of file tutorial.txt.

## ◆ one_over_samples_per_pixel

const double one_over_samples_per_pixel =1./samplesPerPixel

Definition at line 192 of file tutorial.txt.

Referenced by main().

## ◆ variables

</pre> Once we have this we need an instance to store our variable and provide a reference to that We make it because it may be useful to use the same ExprVarRef from multiple expressions ! For if you have expressions that all have access to the same variables

Definition at line 128 of file tutorial.txt.

Referenced by ExprControlCollection::rebuildControls().

## ◆ x

</pre><h3> A simple variable reference</h3> This is not a very interesting subclass of expression until we add some additional variables Variables on some applications may be very dynamic In this we only need x

Definition at line 108 of file tutorial.txt.

Referenced by SeExpr2::acosd(), GenericCurveEditable< TVAL >::add(), CCurveScene::addPoint(), CurveScene::addPoint(), ExprCurve::addPoint(), ExprColorCurve::addPoint(), SeExpr2::asind(), SeExpr2::atan2d(), SeExpr2::atand(), SeExpr2::bias(), SeExpr2::boxstep(), SeExpr2::clamp(), clamp(), SeExpr2::compress(), SeExpr2::contrast(), SeExpr2::cosd(), SeExpr2::dist(), CurveScene::drawPoly(), DeepWaterScene::drawPoly(), SeExpr2::expand(), ExprSpecVectorNode::ExprSpecVectorNode(), SeExpr2::fit(), SeDeepWater< T >::fromLog(), SeExpr2::gamma(), SeExpr2::gaussstep(), SeDeepWater< T >::generateSpectrum(), SeExpr2::Curve< T >::getChannelValue(), SeExpr2::Curve< T >::getValue(), SeExpr2::hsltorgb(), SeExpr2::hslvalue(), SeExpr2::hypot(), SeExpr2::invert(), SeExpr2::linearstep(), main(), SeExpr2::max(), SeExpr2::min(), SeExpr2::mix(), ExprGrapherView::mouseMoveEvent(), ExprChannelSlider::paintEvent(), SeDeepWater< T >::powerLaw(), ExprControlCollection::rebuildControls(), SeExpr2::remap(), SeDeepWater< T >::rescale(), SeExpr2::rgbtohsl(), SeExpr2::round(), SeExpr2::sind(), SeExpr2::smoothstep(), SeDeepWater< T >::sqr(), SeExpr2::tand(), SeDeepWater< T >::toIndex(), and ExprGrapherView::update().