Department of Computer Science Worcester Polytechnic Institute |
---|
Objective: | In this assignment, you will learn how to generate a forest of trees using
an iterated function system (IFS) called Lindenmayer Systems (a.k.a. L-Systems), and place those trees
on a "ground plane." As with Assignment 1, this assignment consists of two parts: a "Preparation" part
and a "New Stuff" part.
NOTE: The "prep" portion is due on November 09, and the "new" stuff is due on November 14. | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Preparation: |
The aim of this preparation part is for you to create the IFS for generating the
strings that will define each tree for the forest. In addition, you will create a
PolyCylinder routine to better understand transformations (e.g., translations, rotations) in OpenGL.
A drawing pattern is defined by a turtle string made up of command characters that control how the turtle moves, as well as its state. The commands include:
L-Systems are used to generate a turtle string by iteratively expanding a start token by applying production (or re-writing) rules. Each L-System consists of a grammar that defines re-writing rules. Each rule in the grammar consists of a left-hand side (LHS) and a right-hand side (RHS), separated by a colon. A sample grammar looks like this:
In addition to specifying a grammar, we also need to specify the values for len, xrot, yrot, and zrot, as well as a value denoting how many times we want to iterate (i.e., apply the production rule(s)). Similar to the way the Koch curve is created by replacing each segment with a predefined pattern, the turtle string is rewritten by substituting every instance of a LHS by its corresponding RHS. For any token in the string for which there is no matching LHS, the token is simply copied into the new string. For example, given the grammar:
after one iteration, the resulting turtle string would be:
Your system should be able to handle multiple production rules, each having a unique LHS, for example:
| ||||||||||||||||||||||||
Setup: | Copy the Makefile you used in Assignment 1, change the names accordingly for your program, and add in the other modules you have created (e.g., grammar.h grammar.cpp, etc.). | ||||||||||||||||||||||||
Prep Coding: |
|
||||||||||||||||||||||||
New Stuff: |
Now we need to put it all together.
(If you REALLY want to test your program, try this input file. This is from p. 20 of the reference book listed at the bottom of this page and is PURELY OPTIONAL!) |
||||||||||||||||||||||||
Extra Credit: |
The extra credit for this assignment allows you to generate more-realistic tress.
|
||||||||||||||||||||||||
Attacking the Problem: |
For the L-System part, start out by creating several classes that will help you manage the different things
you will need to keep straight. For example, you might want to have a turtle class consisting of a
position, orientation, length when drawing, and a string representing the turtle
string.
You might want to have a rule class that has strings for the lhs and rhs. A grammar class would consist of a list of rules, along with a method (addRule) to add a new rule to the grammar. The main method for the grammar class might be something like a rewrite method that takes in a turtle and a number of iterations, and returns a new string after applying the rules to the turtle string for the desired number of iterations. The functionality for implementing '[' and ']' can be greatly simplified by using the built-in OpenGL functions glPushMatrix and glPopMatrix. This will save and return you to the proper state. Another thing that will help you greatly is to use the Standard Template Library (STL) that is available with C++. There are a number of classes that you will find very useful, such as "string," "hash_map," "multimap," and/or "list." If you have never used these before, this is a good opportunity for you to "get out of your comfort zone," as these tools will serve you well in most future endeavors, both in this class and well beyond. Some good links to C++ help include the SGI site and also CPP Reference. |
||||||||||||||||||||||||
Documentation: | You must create adequate documentation, both internal and external, along with your assignment.
The best way to produce internal documentation is by including inline comments. The preferred way to do this
is to write the comments as you code. Get in the habit of writing comments as you type in
your code. A good rule of thumb is that all code that does something non-trivial should have comments
describing what you are doing. This is as much for others who might have to maintain your code, as for
you (imagine you have to go back and maintain code you have not looked at for six months -- this WILL
happen to you in the future!).
I use these file and function (method) headers, in my code. Please adopt these (or the official CS ones) for all your assignments. The file header should be used for both ".h" and ".c" (or ".cpp") files. Create external documentation for your program and submit it along with the project. The documentation does not have to be unnecessarily long, but should explain briefly what each part of your program does, and how your filenames tie in. Most importantly, tell the TA how to compile and run your program. |
||||||||||||||||||||||||
What to Turn in: |
Submit everything you need to compile and run your program (source files, data files, etc.)
BEFORE YOU SUBMIT YOUR ASSIGNMENT, put everything in one directory on ccc.wpi.edu, compile it, and make sure it runs. Then tar everything up into a single archive file. The command to tar everything, assuming your code is in a directory "ass2", is: tar cvf FirstName_LastName_ass2.tar ass2 To submit your work, you will use the turnin utility on CCC. Here is a link to instructions about how to do this. The turnin ID for the "Prep" part is "hw2-prep" and for the "new stuff" part is: "hw2", so to submit your new stuff, you would type something like this when logged in to the CCC machine: /cs/bin/turnin submit cs4731 hw2 FirstName_LastName_ass2.tar
|
||||||||||||||||||||||||
Academic Honesty: |
Remember the policy on Academic Honesty: You may discuss the assignment with others, but you are to do your own work. The official WPI statement for Academic Honesty can be accessed HERE. | ||||||||||||||||||||||||
References: |
Back to course page.
|