SeExpr
ExprBuiltins.h
Go to the documentation of this file.
1 /*
2 * Copyright Disney Enterprises, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License
6 * and the following modification to it: Section 6 Trademarks.
7 * deleted and replaced with:
8 *
9 * 6. Trademarks. This License does not grant permission to use the
10 * trade names, trademarks, service marks, or product names of the
11 * Licensor and its affiliates, except as required for reproducing
12 * the content of the NOTICE file.
13 *
14 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
16 */
17 
18 #ifndef ExprBuiltins_h
19 #define ExprBuiltins_h
20 
21 #include "ExprFunc.h"
22 #include "Platform.h"
23 
24 namespace SeExpr2 {
25 
26 void initPerlin();
27 
28 // trig
29 inline double deg(double angle) { return angle * (180 / M_PI); }
30 inline double rad(double angle) { return angle * (M_PI / 180); }
31 inline double cosd(double x) { return cos(rad(x)); }
32 inline double sind(double x) { return sin(rad(x)); }
33 inline double tand(double x) { return tan(rad(x)); }
34 inline double acosd(double x) { return deg(acos(x)); }
35 inline double asind(double x) { return deg(asin(x)); }
36 inline double atand(double x) { return deg(atan(x)); }
37 inline double atan2d(double y, double x) { return deg(atan2(y, x)); }
38 
39 // clamping
40 inline double clamp(double x, double lo, double hi) { return x < lo ? lo : x > hi ? hi : x; }
41 inline double round(double x) { return x < 0 ? ceil(x - 0.5) : floor(x + 0.5); }
42 inline double max(double x, double y) { return x > y ? x : y; }
43 inline double min(double x, double y) { return x < y ? x : y; }
44 
45 // blending / remapping
46 inline double invert(double x) { return 1 - x; }
47 double compress(double x, double lo, double hi);
48 double expand(double x, double lo, double hi);
49 double fit(double x, double a1, double b1, double a2, double b2);
50 double gamma(double x, double g);
51 double bias(double x, double b);
52 double contrast(double x, double c);
53 double boxstep(double x, double a);
54 double linearstep(double x, double a, double b);
55 double smoothstep(double x, double a, double b);
56 double gaussstep(double x, double a, double b);
57 double remap(double x, double s, double r, double f, double interp);
58 double mix(double x, double y, double alpha);
59 Vec3d hsi(int n, const Vec3d* args);
60 Vec3d midhsi(int n, const Vec3d* args);
61 Vec3d rgbtohsl(const Vec3d& rgb);
62 Vec3d hsltorgb(const Vec3d& hsl);
63 
64 // noise
65 double hash(int n, double* args);
66 double noise(int n, const Vec3d* args);
67 double snoise(const Vec3d& p);
68 Vec3d cnoise(const Vec3d& p);
69 Vec3d vnoise(const Vec3d& p);
70 double turbulence(int n, const Vec3d* args);
71 Vec3d vturbulence(int n, const Vec3d* args);
72 Vec3d cturbulence(int n, const Vec3d* args);
73 double fbm(int n, const Vec3d* args);
74 Vec3d vfbm(int n, const Vec3d* args);
75 Vec3d cfbm(int n, const Vec3d* args);
76 double cellnoise(const Vec3d& p);
77 Vec3d ccellnoise(const Vec3d& p);
78 double pnoise(const Vec3d& p, const Vec3d& period);
79 
80 // vectors
81 double dist(double ax, double ay, double az, double bx, double by, double bz);
82 double length(const Vec3d& v);
83 double hypot(double x, double y);
84 double dot(const Vec3d& a, const Vec3d& b);
85 Vec3d norm(const Vec3d& a);
86 Vec3d cross(const Vec3d& a, const Vec3d& b);
87 double angle(const Vec3d& a, const Vec3d& b);
88 Vec3d ortho(const Vec3d& a, const Vec3d& b);
89 Vec3d up(const Vec3d& vec, const Vec3d& upvec);
90 
91 // variations
92 double cycle(double index, double loRange, double hiRange);
93 double pick(int n, double* params);
94 double choose(int n, double* params);
95 double wchoose(int n, double* params);
96 double spline(int n, double* params);
97 
98 // add builtins to expression function table
100 }
101 
102 #endif
double cellnoise(const Vec3d &p)
void(* Define3)(const char *name, ExprFunc f, const char *docString)
Definition: ExprFunc.h:65
Defined as float g float float float a2
Definition: userdoc.txt:162
Vec3d hsi(int n, const Vec3d *args)
Vec3d up(const Vec3d &P, const Vec3d &upvec)
double dot(const Vec3d &a, const Vec3d &b)
Vec3d vfbm(int n, const Vec3d *args)
double atan2d(double y, double x)
Definition: ExprBuiltins.h:37
Vec3d ccellnoise(const Vec3d &p)
double invert(double x)
Definition: ExprBuiltins.h:46
double asind(double x)
Definition: ExprBuiltins.h:35
double rad(double angle)
Definition: ExprBuiltins.h:30
Vec3d cturbulence(int n, const Vec3d *args)
double round(double x)
Definition: ExprBuiltins.h:41
void defineBuiltins(ExprFunc::Define define, ExprFunc::Define3 define3)
The result is computed int loRange
Definition: userdoc.txt:322
The result is computed int int hiRange
Definition: userdoc.txt:322
double sind(double x)
Definition: ExprBuiltins.h:32
double remap(double x, double source, double range, double falloff, double interp)
double expand(double x, double lo, double hi)
double choose(int n, double *params)
double smoothstep(double x, double a, double b)
double pick(int n, double *params)
with numParticles numAttributes A variable block contains variable names and types but doesn t care what the values are< pre > void f(const std::string &s, MyParticleData *p, int outputDim=3)
Definition: varblocks.txt:35
double length(const Vec3d &v)
double tand(double x)
Definition: ExprBuiltins.h:33
Vec3d cnoise(const Vec3d &p)
double max(double x, double y)
Definition: ExprBuiltins.h:42
double bias(double x, double b)
The result is computed int int< br >< divstyle="margin-left:40px;"> Picks values randomly between loRange and hiRange based on supplied index(which is automatically hashed).&nbsp
Defined as float g float a1
Definition: userdoc.txt:162
double cycle(double index, double loRange, double hiRange)
Vec< double, 3, false > Vec3d
Definition: Vec.h:368
double contrast(double x, double c)
double min(double x, double y)
Definition: ExprBuiltins.h:43
Between a and b
Definition: userdoc.txt:180
double wchoose(int n, double *params)
double fbm(int n, const Vec3d *args)
double cosd(double x)
Definition: ExprBuiltins.h:31
static const int p[514]
Definition: NoiseTables.h:20
Vec3d vnoise(const Vec3d &p)
double dist(double ax, double ay, double az, double bx, double by, double bz)
double gamma(double x, double g)
double linearstep(double x, double a, double b)
void(* Define)(const char *name, ExprFunc f)
Definition: ExprFunc.h:64
</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: tutorial.txt:108
Vec3d cross(const Vec3d &a, const Vec3d &b)
double mix(double x, double y, double alpha)
double fit(double x, double a1, double b1, double a2, double b2)
Vec3d midhsi(int n, const Vec3d *args)
Vec3d vturbulence(int n, const Vec3d *args)
double boxstep(double x, double a)
double atand(double x)
Definition: ExprBuiltins.h:36
double clamp(double x, double lo, double hi)
Definition: ExprBuiltins.h:40
double deg(double angle)
Definition: ExprBuiltins.h:29
void initPerlin()
Defined as float g float float b1
Definition: userdoc.txt:162
double hypot(double x, double y)
double turbulence(int n, const Vec3d *args)
double angle(const Vec3d &a, const Vec3d &b)
double snoise(const Vec3d &p)
Vec3d rgbtohsl(const Vec3d &rgb)
double spline(int n, double *params)
double acosd(double x)
Definition: ExprBuiltins.h:34
Vec3d hsltorgb(const Vec3d &hsl)
Defined as a *alpha b *alpha< br ></div >< br > float< b > float a
Definition: userdoc.txt:174
Vec3d norm(const Vec3d &a)
double compress(double x, double lo, double hi)
* 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
double pnoise(const Vec3d &p, const Vec3d &period)
Vec3d ortho(const Vec3d &a, const Vec3d &b)
This is the same as the prman cellnoise function< br ></div >< br > float< b > float y< br > float< b > float y
Definition: userdoc.txt:218
double hash(int n, double *args)
Platform-specific classes, functions, and includes.
double noise(int n, const Vec3d *args)
double gaussstep(double x, double a, double b)
Vec3d cfbm(int n, const Vec3d *args)