* Adaptation to new classes Rule, RuleSet.
[lsystem3d.git] / src / lindenmayersystem.h
index efadab9a31aa785c94ae1350faec03008159feec..b937e72a95e819f3685eb870b2011a142c94f9e7 100644 (file)
@@ -1,6 +1,6 @@
 // Copyright (C) 2006 Erik Dahlberg
 // 
-// This file is part of LSystem3d.
+// This file is part of LSystem3D.
 // 
 // LSystem3D is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License
 #ifndef LINDENMAYERSYSTEM_H
 #define LINDENMAYERSYSTEM_H
 
-#include <map>
 #include <string>
 
 #include "model.h"
 #include "turtle.h"
+#include "rule.h"
+#include "ruleset.h"
 
 using namespace std;
 
@@ -38,9 +39,10 @@ using namespace std;
 class LindenmayerSystem
 {
 public:
+    
     /**
      * Constructor
-     * @param model the model for generation
+     * @param model empty model
      */
     LindenmayerSystem(Model *model);
 
@@ -49,18 +51,27 @@ public:
      */
     ~LindenmayerSystem();
     
+    /**
+     * Clear all parameters
+     */
+    void clear();
+    
+     /**
+     * Generate L-system data
+     */
+    void generate();
+    
     /**
      * Set the initial rule (the axiom)
      * @param axiom the axiom
      */
-    void setAxiom(string axiom);
+    void setAxiom(Rule axiom);
     
     /**
      * Set one rule
-     * @param name rule name
      * @param rule the rule
      */
-    void setRule(string name, string rule);
+    void setRule(Rule rule);
     
     /**
      * Set the turn/pitch/roll angle
@@ -69,22 +80,34 @@ public:
     void setAngle(double degrees);
     
     /**
-     * Set the number of iterations
-     * @param numIterations number of iterations
+     * Set depth of recursion
+     * @param depth depth of recursion
      */
-    void setNumIterations(int numIterations);
+    void setDepth(int depth);
+    
+    /**
+     * Set diameter of segment
+     * @param diameter the diameter
+     */
+    void setDiameter(double diameter);
+    
+    /**
+     * Set diameter factor
+     * @param diameterFactor the diameter factor
+     */
+    void setDiameterFactor(double diameterFactor);
     
     /**
      * Get the initial rule (the axiom)
      * @return the axiom
      */
-    string getAxiom();
+    Rule getAxiom();
     
     /**
      * Get all rules
      * @return the rules
      */
-    map<string,string> getRules();
+    RuleSet getRules();
     
     /**
      * Get the turn/pitch/roll angle
@@ -93,45 +116,32 @@ public:
     double getAngle();
     
     /**
-     * Get the number of iterations
-     * @return number of iterations
+     * Get depth of recursion
+     * @return depth of recursion
      */
-    int getNumIterations();
+    int getDepth();
     
     /**
-     * Generate l-system data
+     * Get the generated model
+     * @return generated model
      */
-    void generate();
+    Model *getModel();
     
 protected:
     
     /**
-     * Walk through the rule string for specified number of levels
-     * @param rule the rule
-     * @param level current iteration level
+     * Recursively apply the replacement rules
+     * @param rule rule
+     * @param level recursion level
      */
     void recursiveWalk(string rule, int level);
     
-    /**
-     * Verify and preprocess one rule string
-     * @param ruleOrAxiom the rule
-     * @return the preprocessed rule
-     */
-    string verifyAndPreprocessRule(string ruleOrAxiom);
-    
-    /**
-     * Unpreprocess one rule string
-     * @param ruleOrAxiom the rule
-     * @return the unpreprocessed rule
-     */
-    string unpreprocessRule(string ruleOrAxiom);
-    
     // Parameters
-    string _axiom;
-    map<string,string> _rules;      // TODO: use unsorted container?
-    int _numIterations;
+    Rule _axiom;
+    RuleSet _rules;
+    int _depth;
     
-    Model *_model;      // The model for generation
+    Model *_model;      // The active model
     Turtle *_turtle;    // The rendering turtle
 };