From CS559 Computer Graphics Fall 2007

Main: P1Sample

The Picture Processor Sample Solution

We have built an example solution for the project. The binary is available (coming soon) so you can play with it and see what your project should do. The example doesn't implement all of the optional features, and doesn't necessarily provide exemplary implementations of all the functions. But it should be good enough for you to figure out what is going on.

We also are providing you with some of the source code. You are free to use it for your own project. We explicitly designed the implementation so that it is easy to add new commands to it. So, all you need to do is to take the example project and start adding new commands to implement the ones we didn't give to you!

A zip file containing everything you need to get started adding to the sample code is (coming soon). We've even included the visual studio project and solution files.

It should be possible to complete the project only by adding code to the example code. You don't need to edit the example code files. If you do make changes, please explain it in your project documentation.

In fact, you are better off avoiding making changes to the provided files. That way if there are updates, you can simply plug them in.

Note: the example solution reads commands until it gets to an end of file. For the console under windows, and end of file is created by hitting CTRL-Z.

You can download the whole thing here as a single 21K zip file.

Example Code Overview

The example code provides the interpreter for the scripting language, and a few example commands (including reading and writing images).

The files are:

The project also includes the files for LibTarga and TargaImage (as documented in Main.Tutorial5).

For completeness, we've also given you the Visual Studio 2005 files for building the project (the same files you need to turn in)

These files were built by following the directions in Main.Tutorial1.

Download the whole thing here as a single 21K zip file.

Adding to the Example Solution

As provided, the example solution only implements 6 commands (info, test, blank, write, read, darken). You will need to add a whole bunch more.

You should be able to add new commands without modifying the existing files.

To add a new command, define a new class that is a subclass of Command (which is defined in PictureProcessor.H), and create a global instance of that class. Using a bit of C++ trickery, the command will install itself at run time. Basically, the constructors of all of the global variables are called before main. The constructor of the base class Command adds each instantiated object to a linked list, so they are all available to main. Main doesn't need to know anything about the commands - it just calls the methods as appropriate. There is no long list of all the command in the program. To make the example code, we just leave out a bunch of files that implement the commands.

A warning: sometimes, when you add a new global variable, visual studio gets confused and doesn't call the constructor in the right order. If you've added a new command and it isn't showing up (the program prints a list when it starts), you might need to do a "Rebuild All" in VS2005.

The "guts" of your implementation will be in the doit methods of the commands that you implement. This is where the work actually gets done. The doit method takes the command (as a vector of words) and a Context (which contains the active set of variables that store the images), and "does it" (where "it" is whatever the command is supposed to do).

From the six example commands you should be able to figure out enough of the mechanics so that you can spend your time writing the image processing operations, not the parsing.

Retrieved from
Page last modified on September 13, 2007, at 04:56 PM