Initial revision
[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 <map>
26 #include <string>
27
28 #include "model.h"
29 #include "turtle.h"
30
31 using namespace std;
32
33
34
35 /**
36 * Lindenmayer System
37 */
38 class LindenmayerSystem
39 {
40 public:
41 /**
42 * Constructor
43 * @param model the model for generation
44 */
45 LindenmayerSystem(Model *model);
46
47 /**
48 * Destructor
49 */
50 ~LindenmayerSystem();
51
52 /**
53 * Set the initial rule (the axiom)
54 * @param axiom the axiom
55 */
56 void setAxiom(string axiom);
57
58 /**
59 * Set one rule
60 * @param name rule name
61 * @param rule the rule
62 */
63 void setRule(string name, string rule);
64
65 /**
66 * Set the turn/pitch/roll angle
67 * @param degrees the angle, in degrees
68 */
69 void setAngle(double degrees);
70
71 /**
72 * Set the number of iterations
73 * @param numIterations number of iterations
74 */
75 void setNumIterations(int numIterations);
76
77 /**
78 * Get the initial rule (the axiom)
79 * @return the axiom
80 */
81 string getAxiom();
82
83 /**
84 * Get all rules
85 * @return the rules
86 */
87 map<string,string> getRules();
88
89 /**
90 * Get the turn/pitch/roll angle
91 * @return the angle, in degrees
92 */
93 double getAngle();
94
95 /**
96 * Get the number of iterations
97 * @return number of iterations
98 */
99 int getNumIterations();
100
101 /**
102 * Generate l-system data
103 */
104 void generate();
105
106 protected:
107
108 /**
109 * Walk through the rule string for specified number of levels
110 * @param rule the rule
111 * @param level current iteration level
112 */
113 void recursiveWalk(string rule, int level);
114
115 /**
116 * Verify and preprocess one rule string
117 * @param ruleOrAxiom the rule
118 * @return the preprocessed rule
119 */
120 string verifyAndPreprocessRule(string ruleOrAxiom);
121
122 /**
123 * Unpreprocess one rule string
124 * @param ruleOrAxiom the rule
125 * @return the unpreprocessed rule
126 */
127 string unpreprocessRule(string ruleOrAxiom);
128
129 // Parameters
130 string _axiom;
131 map<string,string> _rules; // TODO: use unsorted container?
132 int _numIterations;
133
134 Model *_model; // The model for generation
135 Turtle *_turtle; // The rendering turtle
136 };
137
138
139
140 #endif