HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_LSystem.h
Go to the documentation of this file.
1 #ifndef __GU_LSystem_h__
2 #define __GU_LSystem_h__
3 
4 #include "GU_API.h"
5 #include "GU_LSysExpr.h"
6 #include <GA/GA_Handle.h>
7 
8 #include <UT/UT_Array.h>
9 #include <UT/UT_Vector3.h>
10 #include <UT/UT_VectorTypes.h>
11 
12 #ifdef WIN32
13  #include <float.h>
14 #endif
15 
17 {
20 };
21 
22 class TIL_TextureMap;
23 class IMG_Raster;
24 class GA_ATIBlindData;
25 class GA_PrimitiveGroup;
26 class GEO_Face;
27 class GEO_PrimPoly;
28 class GU_Detail;
29 class gu_LSysTurtleStack;
30 class gu_LSysTurtleData;
31 
33 {
34 public:
35 
36  guLsysRule(const char *r)
37  {
38  rule = r ? strdup(r) : 0;
39  srule = 0;
40  cond = 0;
41  probs = 0;
42  xyzRule = 0;
43  if (r)
44  {
45  // trim is a temporary buffer we store the space trimmed
46  // rule.
47  trim = new char [strlen(r) + 1];
48  trim[0] = '\0';
49  }
50  else
51  trim = 0;
52  }
53 
55  {
56  if (rule)
57  free(rule);
58  if (trim)
59  delete [] trim;
60  }
61 
62  char *rule; // original
63  char *srule; // substitution
64  char *cond; // condition
65  char *probs; // probability
66  char xyzRule; // contains refs to x,y,z
67 
68  char *trim; // no spaces rules
69  char pred[LSYS_MAX_PARAMS+2];
70  char lstr[LSYS_MAX_PARAMS+2];
71  char rstr[LSYS_MAX_PARAMS+2];
72 
73 };
74 
75 
77 {
78 public:
79 
81  ~GU_LSystemParms();
82 
83  // Pre-Construction initialization values
84 
85  GU_LSystemGeoType geotype; // skeleton or tube
86  float generations; // number of recursions
87  int contAngl; // fractional angles
88  int contLength; // fractional forward growth
89  int contWidth; // fractional tube growth
90  bool myOldStyleContext; // Context rules cross into
91  // sibling branches.
92 
93  IMG_Raster *picRaster; // used in 'pic' function
94 
95  char *groupLabel; // group name base
96 
97  TIL_TextureMap *colorMap; // map to add colors with
98  float colorUInc; // U color texture increment
99  float colorVInc; // V color texture increment
100 
101  int doPointWidth; // Add width pt attribute
102  int doPointSort; // Sort the points by age.
104  float textVInc; // V texture increment
105 
106  float b, c, d; // extra expression variables
107 
108  UT_Vector3 startpos; // initial position
109  float size; // initial step size
110  float thickness; // tube thickness
111  float angle; // angle value to turn by
112 
113  float sizeFactor; // factor to * step size by
114  float thicknessFactor; // factor to * thickness by
115  float angleFactor; // factor to * angle value by
116 
117 
118  float rndScale; // random factor
119  int rndSeed;
120 
121  int tubeSides; // dimensions of tube
122  int tubeSegs;
123  float tubeTension;
124  float tubeSmooth;
125 
126  float gravity; // affect of gravity
127 
128  char *contextIgnore; // characters to ignore
129  // in context checking
130 
131  char *initial; // premise
132  GU_Detail *meta; // inside test geometry
133  GU_Detail *gdp; // where to add geometry
134 
135 
136  void clearRules(); // rules
137  void addRule(const char *);
138 
139  void clearVariables(); // variables
140  void addVariable(const char *var, float val);
141 
142 
143  // callback methods
144 
145  float (*getChanValue)(int ind, void *data); // chan func
146  GU_Detail *(*getLeaf)(char ind, float,
147  float, float, void *data); // leaf func
149 
150  // Construction methods
151 
152  int preprocessStrings();
153  int executeLSystem(int len);
155  gu_LSysTurtleData *buildGeometry(char *buildStr, float numGen, int len,
156  gu_LSysTurtleData *startState,
157  int offset);
158 
159  // Post-construction retrieval methods
160 
161  const char *getExpandedString() { return str; } // result of lsystem
162  int getMaxSize() { return strSize; }
163 
164  int getParam(int i, int j, float &value)
165  {
166  int result = 0;
167  if (i < LSYS_MAX_PARAMS)
168  {
169  value = var[i][j];
170  result = (value != LSYS_EXPR_UNUSED);
171  }
172  return result;
173  }
174 
175 
176 private:
177 
178  GU_LSysExpr expr;
179 
180  char *str; // resultant lsystem string
181  char *strOriginal; // temp copy of above
182  char *strTmp; // temp copy of above
183 
184  char *ran; // random # for each str char
185  int *age; // generation of each str char
186 
187  float *var[LSYS_MAX_PARAMS]; // evaluated args
188 
189  int strSize; // current length of max premise
190 
191 
192  UT_Array<guLsysRule *> myRules; // subsitution rules
193 
194 
195  GA_ATIBlindData *myPtInfoRef; // pt. attribute ref
196  GA_ATIBlindData *myPrimInfoRef; // prim attribute ref
197  GA_RWHandleV3 myClrHandle; // clr attribute handle
198 
199  int numberOfRules;
200  int isError;
201  int forceTubeNmls;
202 
203  GU_Detail *skelgdp;
204 
206  UT_Array<GEO_PrimPoly *> myPolyStack;
207 
208  unsigned myCurrSeed;
209 
210  UT_Vector3 myLastBezierLocation;
211 
212  int startBuild();
213  void stopBuild();
214  int substituteRule(unsigned int p, int i, int slen,
215  int *prune, int &len);
216 
217  void assignParameters(char *module, unsigned int p,
218  GU_LSysExpr &expr);
219 
220  int increaseLSysSize();
221 
222  void addPointWidthAttribute();
223 
224  void expandBranches(int);
225  int smoothBranches();
226  UT_Matrix4 bezier3D(GEO_Face *,float,float &, float &, UT_Vector3 &);
227 
228  void lsysPrune(int, int &);
229  void lsysTurn(float);
230  void lsysRandom(char , float );
231  void lsysPitch(float);
232  void lsysRoll(float);
233  void lsysGravity(float);
234  void lsysLookToSun(int, float, float, float);
235  void lsysForward(float, float, int, int, int, int);
236  void lsysLeaf(float, float, float, float, char, int);
237 
238  void lsysPushPoly();
239  void lsysPopPoly();
240  void lsysPolyVertex();
241 
242  void lsysSetGroup(int num);
243  GA_PrimitiveGroup *lsysLeafGroup(char c);
244 
245  gu_LSysTurtleData *lsysLocation(int p, int offset, int &branch,
246  float g, gu_LSysTurtleData *startState);
247  gu_LSysTurtleData *lsysPopTurtle();
248  gu_LSysTurtleData *lsysPushTurtle();
249 
250  void lsysAddAttribute(int atrname, float v1, float v2, float v3);
251 
252 
253  void addPoint(gu_LSysTurtleData *, float, float, int, int, int);
254  void startLine(float, int, int, int);
255 
256 };
257 
258 #endif
259 
char * srule
Definition: GU_LSystem.h:63
GU_Detail * gdp
Definition: GU_LSystem.h:133
GU_Detail * meta
Definition: GU_LSystem.h:132
GLboolean * data
Definition: glcorearb.h:131
GLboolean GLboolean g
Definition: glcorearb.h:1222
bool myOldStyleContext
Definition: GU_LSystem.h:90
char * groupLabel
Definition: GU_LSystem.h:95
float generations
Definition: GU_LSystem.h:86
**But if you need a result
Definition: thread.h:613
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
char * contextIgnore
Definition: GU_LSystem.h:128
GLfloat GLfloat GLfloat GLfloat v3
Definition: glcorearb.h:819
#define LSYS_EXPR_UNUSED
Definition: GU_LSysExpr.h:33
Attribute type implementation to store blind data per element.
UT_Vector3 startpos
Definition: GU_LSystem.h:108
GLintptr offset
Definition: glcorearb.h:665
IMATH_NAMESPACE::V2f float
GU_LSystemGeoType geotype
Definition: GU_LSystem.h:85
void * callbackData
Definition: GU_LSystem.h:148
char xyzRule
Definition: GU_LSystem.h:66
char * probs
Definition: GU_LSystem.h:65
IMG_Raster * picRaster
Definition: GU_LSystem.h:93
float thicknessFactor
Definition: GU_LSystem.h:114
void trim(std::string &s)
Definition: Name.h:83
#define GU_API
Definition: GU_API.h:14
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint j
Definition: glad.h:2733
TIL_TextureMap * colorMap
Definition: GU_LSystem.h:97
guLsysRule(const char *r)
Definition: GU_LSystem.h:36
GU_LSystemGeoType
Definition: GU_LSystem.h:16
GLfloat GLfloat v1
Definition: glcorearb.h:817
GLuint GLfloat * val
Definition: glcorearb.h:1608
const char * getExpandedString()
Definition: GU_LSystem.h:161
Definition: core.h:1131
GLboolean r
Definition: glcorearb.h:1222
void prune(TreeT &tree, typename TreeT::ValueType tolerance=zeroVal< typename TreeT::ValueType >(), bool threaded=true, size_t grainSize=1)
Reduce the memory footprint of a tree by replacing with tiles any nodes whose values are all the same...
Definition: Prune.h:335
int getParam(int i, int j, float &value)
Definition: GU_LSystem.h:164
GA_API const UT_StringHolder age
char * rule
Definition: GU_LSystem.h:62
char * trim
Definition: GU_LSystem.h:68
#define LSYS_MAX_PARAMS
Definition: GU_LSysExpr.h:34
char * cond
Definition: GU_LSystem.h:64