52 if (name ==
"x")
return &
x;
68 if (!
expr.isValid()) {
69 std::cerr <<
"expression failed " <<
expr.parseError() << std::endl;
71 }
else if (!
expr.returnType().isFP(1)) {
73 <<
expr.returnType().toString() << std::endl;
77 double xmin = -10, xmax = 10, ymin = -10, ymax = 10;
83 int j_zero = (-ymin) / (ymax - ymin) *
h;
85 for (
int i = 0;
i <
w;
i++) {
90 int i_zero = (-xmin) / (xmax - xmin) *
w;
92 for (
int j = 0;
j <
h;
j++) {
100 for (
int i = 0;
i <
w;
i++) {
107 const double* val =
expr.evalFP();
113 int j = (
y - ymin) / (ymax - ymin) *
h;
120 for (
int j =
h - 1;
j >= 0;
j--) {
121 for (
int i = 0;
i <
w;
i++) {
124 std::cout << std::endl;
int main(int argc, char *argv[])
ExprType & FP(int d)
Mutate this into a floating point type of dimension d.
std::string toString() const
Stringify the type into a printable string.
ExprType & Varying()
Mutate this into a varying lifetime.
abstract class for implementing variable references
virtual void eval(double *result)=0
returns this variable's value by setting result
</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")
const double one_over_samples_per_pixel
</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 > 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
This is the same as the prman cellnoise function< br ></div >< br > float< b > float y< br > float< b > float y