CS 261 Homework 4 - Shape Decomposer

Due Mon Mar 03 at 9:00am

Overview

For this assignment, you will write a system for viewing shape decompositions. The basic idea is that a shape (like a polygon) can be represented as a sequence of coordinates in Euclidean space--connecting these points in order produces the outline of the shape. If we start algorithmically removing points from this outline, we start "decomposing" the shape and producing a more abstract polygon. For example:

The above images show the original picture on the left, and then the picture with 90% of its "least important" points removed. Importance here is determined using the following simple algorithm (described in more detail in the Koffman text, page 146):

Given a point P and its neighbors L and R, compute the distances LP, PR, and LR. Importance is measured as LP + PR - LR

Your task is to write a program that loads a sequence of points from a file, displays those points as a polygon on the screen, and allows the user to remove unimportant points in order to deform the polygon using a slider. Furthermore, the slider goes in both directions, enabling the user to also restore removed points to the polygon. You will be writing this system from scratch, though I will give you some guidance below.

This assignment should be completed individually. You are welcome to ask for help from me, or from your classmates (but remember to follow the Gilligan's Island rule)!

Objectives

Necessary Files

You will want a copy of the Hwk4.zip file which contains a number of "shape files" (text files with lists of points) that you can use in writing your program.

The zip file also contains the README.txt for this assignment--be sure and answer the questions thoroughly for full credit!

You may also want to have old code on hand to provide you with examples and a starting point. In particular, you will likely draw from your BabyName assignment (the NameDatabase class for file IO, and the NameFrame/NameGraph classes for drawing), the Bead lab (for making a linked list), and the linked-list example from class (which can be found on Moodle).

Assignment Details

Read through all of these instructions carefully before you begin! They detail the specifics of what you will need to implement to complete this assignment.

This is a large project, but think about how you can break this into small, achievable steps. If you get stuck, there is a spoiler plan of attack at the bottom.

DecomposableShape

The GUI Interface

You will also need a GUI window to display your shape and the control slider. This DecomposerFrame will look very similar to the NecklaceFrame: it will extend a simple JFrame and draw a ShapePanel that will extend JPanel and that can be drawn on by overriding the paintComponent() method. Note that you can make the ShapePanel an inner class, as in the NecklaceFrame from the Bead lab.

Completing the Program

This is a sizable program, but each part is something that you have done before: file IO with the Scanner, JFrames, drawing panels, JSliders, etc. While we might be using classes in new ways, you need to be comfortable looking at the Java documentation to figure out these classes.

Be sure and TEST your program to make sure it works!

As always, once you're finished, be sure that all your code is fully documented. This means full Javadoc comments on each method you create, and lots of comments explaining your code. Remember to explain the why of the code, not the what.

Finally, be sure to complete the README.txt that you found in the Hwk4.zip file, and upload it along with your code!

Plan of Attack and Timeline

You really should be able to figure out how to write a program of this size on your own. Try doing it by yourself, and see if you can make any progress. But if you get stuck, below is a rough ordering for how to attack the problem:

This assignment is much larger than the last. In fact, this is the kind of "full sized program" that we will be writing for the rest of the semester. Do not put it off. Try to make a little progress each day, and if you get stuck, ask for help early!

Extensions

Submitting

BEFORE YOU SUBMIT: make sure your code is fully documented and functional! If your code doesn't run, I can't give you credit! Your name should be in the class comment at the top of each class.

Submit your program to the Hwk4 submission folder on hedwig. Make sure you upload your work to the correct folder!. You should upload your entire src folder with all your classes. Be sure to complete the provided README.txt file with details about your program.

The homework is due at the start of class on Mon Mar 03. Note that we have the first exam that day; getting the homework done earlier will give you more chance to study!

Grading

This assignment will be graded on approximately the following criteria: