X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flindenmayersystem.h;fp=src%2Flindenmayersystem.h;h=efadab9a31aa785c94ae1350faec03008159feec;hb=15c82487a77555b040f3f4e03bc11da8b9bc5905;hp=0000000000000000000000000000000000000000;hpb=db873ae7535fc6bde3c61d7d0e6346797c658477;p=lsystem3d.git diff --git a/src/lindenmayersystem.h b/src/lindenmayersystem.h new file mode 100644 index 0000000..efadab9 --- /dev/null +++ b/src/lindenmayersystem.h @@ -0,0 +1,140 @@ +// Copyright (C) 2006 Erik Dahlberg +// +// 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 +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// LSystem3D is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with LSystem3D; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + + + +#ifndef LINDENMAYERSYSTEM_H +#define LINDENMAYERSYSTEM_H + +#include +#include + +#include "model.h" +#include "turtle.h" + +using namespace std; + + + +/** + * Lindenmayer System + */ +class LindenmayerSystem +{ +public: + /** + * Constructor + * @param model the model for generation + */ + LindenmayerSystem(Model *model); + + /** + * Destructor + */ + ~LindenmayerSystem(); + + /** + * Set the initial rule (the axiom) + * @param axiom the axiom + */ + void setAxiom(string axiom); + + /** + * Set one rule + * @param name rule name + * @param rule the rule + */ + void setRule(string name, string rule); + + /** + * Set the turn/pitch/roll angle + * @param degrees the angle, in degrees + */ + void setAngle(double degrees); + + /** + * Set the number of iterations + * @param numIterations number of iterations + */ + void setNumIterations(int numIterations); + + /** + * Get the initial rule (the axiom) + * @return the axiom + */ + string getAxiom(); + + /** + * Get all rules + * @return the rules + */ + map getRules(); + + /** + * Get the turn/pitch/roll angle + * @return the angle, in degrees + */ + double getAngle(); + + /** + * Get the number of iterations + * @return number of iterations + */ + int getNumIterations(); + + /** + * Generate l-system data + */ + void generate(); + +protected: + + /** + * Walk through the rule string for specified number of levels + * @param rule the rule + * @param level current iteration 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 _rules; // TODO: use unsorted container? + int _numIterations; + + Model *_model; // The model for generation + Turtle *_turtle; // The rendering turtle +}; + + + +#endif