15c82487 |
1 | // Copyright (C) 2006 Erik Dahlberg |
2 | // |
3d90821a |
3 | // This file is part of LSystem3D. |
15c82487 |
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 | |
15c82487 |
25 | #include <string> |
26 | |
27 | #include "model.h" |
28 | #include "turtle.h" |
3d90821a |
29 | #include "rule.h" |
30 | #include "ruleset.h" |
31 | |
32 | using namespace std; |
15c82487 |
33 | |
15c82487 |
34 | |
35 | |
36 | /** |
37 | * Lindenmayer System |
38 | */ |
39 | class LindenmayerSystem |
40 | { |
41 | public: |
526db675 |
42 | |
15c82487 |
43 | /** |
44 | * Constructor |
526db675 |
45 | * @param model empty model |
15c82487 |
46 | */ |
47 | LindenmayerSystem(Model *model); |
48 | |
49 | /** |
50 | * Destructor |
51 | */ |
52 | ~LindenmayerSystem(); |
53 | |
526db675 |
54 | /** |
55 | * Clear all parameters |
56 | */ |
57 | void clear(); |
58 | |
59 | /** |
60 | * Generate L-system data |
61 | */ |
62 | void generate(); |
63 | |
15c82487 |
64 | /** |
65 | * Set the initial rule (the axiom) |
66 | * @param axiom the axiom |
67 | */ |
3d90821a |
68 | void setAxiom(Rule axiom); |
15c82487 |
69 | |
70 | /** |
71 | * Set one rule |
15c82487 |
72 | * @param rule the rule |
73 | */ |
3d90821a |
74 | void setRule(Rule rule); |
15c82487 |
75 | |
76 | /** |
77 | * Set the turn/pitch/roll angle |
78 | * @param degrees the angle, in degrees |
79 | */ |
80 | void setAngle(double degrees); |
81 | |
82 | /** |
3d90821a |
83 | * Set depth of recursion |
84 | * @param depth depth of recursion |
15c82487 |
85 | */ |
3d90821a |
86 | void setDepth(int depth); |
15c82487 |
87 | |
526db675 |
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 | |
15c82487 |
100 | /** |
101 | * Get the initial rule (the axiom) |
102 | * @return the axiom |
103 | */ |
3d90821a |
104 | Rule getAxiom(); |
15c82487 |
105 | |
106 | /** |
107 | * Get all rules |
108 | * @return the rules |
109 | */ |
3d90821a |
110 | RuleSet getRules(); |
15c82487 |
111 | |
112 | /** |
113 | * Get the turn/pitch/roll angle |
114 | * @return the angle, in degrees |
115 | */ |
116 | double getAngle(); |
117 | |
118 | /** |
3d90821a |
119 | * Get depth of recursion |
120 | * @return depth of recursion |
15c82487 |
121 | */ |
3d90821a |
122 | int getDepth(); |
15c82487 |
123 | |
124 | /** |
526db675 |
125 | * Get the generated model |
126 | * @return generated model |
15c82487 |
127 | */ |
526db675 |
128 | Model *getModel(); |
15c82487 |
129 | |
130 | protected: |
131 | |
132 | /** |
526db675 |
133 | * Recursively apply the replacement rules |
134 | * @param rule rule |
135 | * @param level recursion level |
15c82487 |
136 | */ |
137 | void recursiveWalk(string rule, int level); |
138 | |
15c82487 |
139 | // Parameters |
3d90821a |
140 | Rule _axiom; |
141 | RuleSet _rules; |
142 | int _depth; |
15c82487 |
143 | |
526db675 |
144 | Model *_model; // The active model |
15c82487 |
145 | Turtle *_turtle; // The rendering turtle |
146 | }; |
147 | |
148 | |
149 | |
150 | #endif |