38 std::vector<std::pair<int, int> >
ranges;
44 for (
int i = 0;
i <
node->numChildren();
i++)
52 if (args.
nargs() >= 2) {
66 std::vector<std::pair<int, int> >
ranges;
73 for (
int i = 1;
i <
node->numChildren();
i++)
86 for (
int k = 2;
k <
num;
k++) val += args.
inFp<1>(
k)[0];
88 for (
int k = 0;
k < 3;
k++)
out[
k] = val;
99 std::vector<std::pair<int, int> >
ranges;
106 for (
int i = 1;
i <
node->numChildren();
i++)
121 for (
int k = 0;
k < 3;
k++)
out[
k] = val;
159 void eval(
double*
result) {
163 void eval(
const char**
reuslt) {}
167 mutable std::map<std::string, Var> vars;
168 mutable std::map<std::string, VecVar> vecvars;
171 ExprVarRef* resolveVar(
const std::string& name)
const {
173 std::map<std::string, Var>::iterator
i = vars.find(name);
174 if (
i != vars.end())
return &
i->second;
177 std::map<std::string, VecVar>::iterator
i = vecvars.find(name);
178 if (
i != vecvars.end())
return &
i->second;
184double clamp(
double x) {
return std::max(0., std::min(255.,
x)); }
188 std::cerr <<
"Usage: " <<
argv[0] <<
" <image file> <width> <height> <exprFile>" << std::endl;
201 std::cerr <<
"invalid width/height" << std::endl;
207 std::cerr <<
"Cannot read file " <<
exprFile << std::endl;
210 std::string
exprStr((std::istreambuf_iterator<char>(
istream)), std::istreambuf_iterator<char>());
214 expr.vars[
"u"] = ImageSynthExpr::Var(0.);
215 expr.vars[
"v"] = ImageSynthExpr::Var(0.);
216 expr.vars[
"w"] = ImageSynthExpr::Var(
width);
219 expr.vars[
"faceId"] = ImageSynthExpr::Var(0.);
220 expr.vecvars[
"P"] = ImageSynthExpr::VecVar();
221 expr.vecvars[
"Cs"] = ImageSynthExpr::VecVar();
222 expr.vecvars[
"Ci"] = ImageSynthExpr::VecVar();
225 bool valid =
expr.isValid();
227 std::cerr <<
"Invalid expression " << std::endl;
228 std::cerr <<
expr.parseError() << std::endl;
237 std::cerr <<
"Evaluating expresion...from " <<
exprFile << std::endl;
238 unsigned char* image =
new unsigned char[
width *
height * 4];
240 double& u =
expr.vars[
"u"].val;
241 double& v =
expr.vars[
"v"].val;
248 unsigned char*
pixel = image;
252 for (
int row = 0; row <
height; row++) {
281 std::cerr <<
"Writing image..." <<
imageFile << std::endl;
Node that calls a function.
Vec< double, d, true > inFp(int i)
Function Definition, used in parse tree and func table.
static void define(const char *name, ExprFunc f, const char *docString)
ExprType & FP(int d)
Mutate this into a floating point type of dimension d.
ExprType & Error()
Mutate this into an error type.
ExprType & Varying()
Mutate this into a varying lifetime.
Variable scope builder is used by the type checking and code gen to track visiblity of variables and ...
abstract class for implementing variable references
virtual ExprType prep(ExprFuncNode *node, bool wantScalar, ExprVarEnvBuilder &envBuilder) const
virtual void eval(ArgHandle args)
virtual ExprFuncNode::Data * evalConstant(const ExprFuncNode *node, ArgHandle args) const
virtual void eval(ArgHandle args)
virtual ExprType prep(ExprFuncNode *node, bool wantScalar, ExprVarEnvBuilder &envBuilder) const
virtual ExprFuncNode::Data * evalConstant(const ExprFuncNode *node, ArgHandle args) const
virtual void eval(ArgHandle args)
virtual ~TriplanarFuncX()
virtual ExprFuncNode::Data * evalConstant(const ExprFuncNode *node, ArgHandle args) const
virtual ExprType prep(ExprFuncNode *node, bool wantScalar, ExprVarEnvBuilder &envBuilder) const
int main(int argc, char *argv[])
static const char * rand_docstring
static const char * triplanar_docstring
static const char * map_docstring
SeExpr2::TriplanarFuncX triplanar
double clamp(double x, double lo, double hi)
base class for custom instance data
std::vector< std::pair< int, int > > ranges
std::vector< std::pair< int, int > > ranges
std::vector< std::pair< int, int > > ranges
</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 >< 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