* Adaptation to new classes Rule, RuleSet.
[lsystem3d.git] / src / lindenmayersystem.h
1 // Copyright (C) 2006 Erik Dahlberg
2 //
3 // This file is part of LSystem3D.
4 //
5 // LSystem3D is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // LSystem3D is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with LSystem3D; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
21
22 #ifndef LINDENMAYERSYSTEM_H
23 #define LINDENMAYERSYSTEM_H
24
25 #include <string>
26
27 #include "model.h"
28 #include "turtle.h"
29 #include "rule.h"
30 #include "ruleset.h"
31
32 using namespace std;
33
34
35
36 /**
37 * Lindenmayer System
38 */
39 class LindenmayerSystem
40 {
41 public:
42
43 /**
44 * Constructor
45 * @param model empty model
46 */
47 LindenmayerSystem(Model *model);
48
49 /**
50 * Destructor
51 */
52 ~LindenmayerSystem();
53
54 /**
55 * Clear all parameters
56 */
57 void clear();
58
59 /**
60 * Generate L-system data
61 */
62 void generate();
63
64 /**
65 * Set the initial rule (the axiom)
66 * @param axiom the axiom
67 */
68 void setAxiom(Rule axiom);
69
70 /**
71 * Set one rule
72 * @param rule the rule
73 */
74 void setRule(Rule rule);
75
76 /**
77 * Set the turn/pitch/roll angle
78 * @param degrees the angle, in degrees
79 */
80 void setAngle(double degrees);
81
82 /**
83 * Set depth of recursion
84 * @param depth depth of recursion
85 */
86 void setDepth(int depth);
87
88 /**
89 * Set diameter of segment
90 * @param diameter the diameter
91 */
92 void setDiameter(double diameter);
93
94 /**
95 * Set diameter factor
96 * @param diameterFactor the diameter factor
97 */
98 void setDiameterFactor(double diameterFactor);
99
100 /**
101 * Get the initial rule (the axiom)
102 * @return the axiom
103 */
104 Rule getAxiom();
105
106 /**
107 * Get all rules
108 * @return the rules
109 */
110 RuleSet getRules();
111
112 /**
113 * Get the turn/pitch/roll angle
114 * @return the angle, in degrees
115 */
116 double getAngle();
117
118 /**
119 * Get depth of recursion
120 * @return depth of recursion
121 */
122 int getDepth();
123
124 /**
125 * Get the generated model
126 * @return generated model
127 */
128 Model *getModel();
129
130 protected:
131
132 /**
133 * Recursively apply the replacement rules
134 * @param rule rule
135 * @param level recursion level
136 */
137 void recursiveWalk(string rule, int level);
138
139 // Parameters
140 Rule _axiom;
141 RuleSet _rules;
142 int _depth;
143
144 Model *_model; // The active model
145 Turtle *_turtle; // The rendering turtle
146 };
147
148
149
150 #endif