CS40 Lab 7: Procedural methods

Due 2:30pm Wednesday 3 April 2013

You may work with one partner on this assignment. In this lab, you will design and implement a grammar based model for rendering plants and trees.

Data
See myplant.txt for a sample test file describing a grammar to model.
Git Setup
Get a clean copy of the code from the origin/master branch and create a local and remote project07 branch by following these steps.
git fetch origin
git checkout -b project07 origin/master
git push -u private project07
The above commands assume that the default class code is on the origin remote, and your personal remote is named private. Furthermore, your working directory must be clean (no uncommitted changes to files under version control), before checking out a new branch. If this is not the case, add and commit you changes locally before switching to a project07 branch.

Once you and your partner have pushed the project07 branches, you can each checkout a shared07 branch to follow your partner's changes

git fetch partner
git checkout -b shared07 partner/project07
Note you should not merge into either the master, shared, or shared07 branches as you will later be unable to push your changes. Make sure you are on either the working or project07 branch before merging.
Procedural Methods
Draw two or more trees or some other plants using L-sytems and the procedural methods discussed in class. You may want to consult Algorithmic Botany and in particular chapter one of The Algorithmic Beauty of Plants. A local copy is also available.

This assignment is fairly open ended. Here are my requirements

Getting Started
First take a look at the input format for defining the grammar in myplant.txt. Each plant must begin from a start symbol/seed. Rules are specified by symbols separated by spaces. The first symbol is the symbol to be replaced. The remaining symbols are the replacement string. For symbols that can have multiple productions (e.g., F->FF or F->F), we can optionally assign a relative weight to the each production.

parseFile in plant.cpp reads an input file as described above and stores the grammar as a small dictionary. The dictionary maps symbols to a vector of possible replacement productions. A production is simply the weight and a vector of replacement symbols. By storing the symbols in a vector and by separating symbols by spaces in the input file, you can have multi-character symbols, e.g., A1, B17.

The first task to complete is the function derive or a similar replacement. What this function does is derives a new vector of symbols by applying the grammar rules to the current vector of symbols (initially just the start symbol). Complete this function and have a method that printPlant() that displays the derivation correct result.

Next, modify PaintGL or drawTree to look at each symbol in the derived plant vector and assign a geometric interpretation using openGL commands. These could be drawing branches, leaves, rotating, pushing, popping, etc.

Things to Consider

You may want to apply a global scaling factor to keep you plant on the screen. Keyboard controls can help adjust this factor.

Adding textures
Find an awesome bark/leaf texture and want to share? Copy the file to /scratch/adas/public/. Then you can refer to it by data/xtra/yourfilename.png in your code. Occasionally I will make these files readable by everyone, or if you are in a hurry run chmod 644 on the file in /scratch/adas/public.
Submit
You should regularly commit your changes to the project07 branch and occasionally push to your private remote. Note you must push to your remote to share updates with your partner. Ideally you should commit changes at the end of every session of working on the project. You will be graded on work that appears in your remote project07 branch by the project deadline