Functions | |
| <!--*(c) DisneyEnterprises,  Inc.Allrightsreserved.**ThisfileislicensedunderthetermsoftheMicrosoftPublicLicense(MS-PL)*asdefinedat:http:**Acompletecopyofthislicenseisincludedinthisdistributionasthefile *LICENSE.-->< 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 SeExpression 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 SeExpression 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 > 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 <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 SeExprVarRef 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 SeExprVarRef 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 > 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 | 
| <!--*(c)DisneyEnterprises,Inc.Allrightsreserved.**ThisfileislicensedunderthetermsoftheMicrosoftPublicLicense(MS-PL)*asdefinedat:http:**Acompletecopyofthislicenseisincludedinthisdistributionasthefile*LICENSE.--><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 | ) | 
| </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 | ( | ) | 
Definition at line 149 of file tutorial.txt.
| </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 SeExprEdShortEdit::checkErrors(), and main().
| for | ( | int |  i = 0;i<w;i++ | 
          ) | 
Definition at line 201 of file tutorial.txt.
| </pre> there might be errors in the expression you must check with isValid | ( | ) | 
Definition at line 169 of file tutorial.txt.
| </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 | ( | ) | const | 
Definition at line 133 of file tutorial.txt.
| * sin | ( | val | ) | const | 
Referenced by SeVec3d::rotateBy(), and SeExpr::sind().
| </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 101 of file tutorial.txt.
| </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 143 of file tutorial.txt.
| </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 SeExprVarRef from multiple expressions ! For example | 
Definition at line 120 of file tutorial.txt.
| </pre><h3> Binding our variable reference</h3> If we now tried to use expressions | 
Definition at line 132 of file tutorial.txt.
| </pre> Finally | 
Definition at line 177 of file tutorial.txt.
Definition at line 177 of file tutorial.txt.
| </pre> However | 
Definition at line 169 of file tutorial.txt.
| </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 101 of file tutorial.txt.
| </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 118 of file tutorial.txt.
| const double one_over_samples_per_pixel = 1./samplesPerPixel | 
Definition at line 184 of file tutorial.txt.
Referenced by main().
| </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 SeExprVarRef from multiple expressions ! For if you have expressions that all have access to the same variables | 
Definition at line 120 of file tutorial.txt.
| </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 101 of file tutorial.txt.
Referenced by CurveScene::drawPoly(), SeExpr::SeCurve< T >::getChannelValue(), SeExpr::SeCurve< T >::getValue(), main(), SeExprEdGrapherView::mouseMoveEvent(), SeExprEdChannelSlider::paintEvent(), SeExprEdControlCollection::rebuildControls(), SeExpr::satAdjust(), and SeExprEdGrapherView::update().
 1.6.1