/disk1/scratch/aselle/projects/seexpr/SeExpr/src/doc/tutorial.txt File Reference

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 &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 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

Function Documentation

<!--*(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 (  ) 
Type Constraints

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"   ) 
for ( int  i = 0;i&lt;w;i++  ) 

Definition at line 201 of file tutorial.txt.

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

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
Type Constraints

Definition at line 133 of file tutorial.txt.

* sin ( val   )  const

Referenced by SeVec3d::rotateBy(), and SeExpr::sind().


Variable Documentation

</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.

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

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

Generated on 25 Jul 2013 for SeExpr by  doxygen 1.6.1