CS 261 Homework 4 - Shape Decomposer

Due Fri Oct 17 at 11:59pm

Overview

For this assignment, you will develop a system for viewing shape decompositions. The basic idea is that a shape (like a polygon) can be represented as a sequence of coordinates ("points") 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 (from L to P), 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 user is also able to restore removed points to the polygon (the slider goes in both directions). 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 cs261-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.

There are two pieces to this assignment: the DecomposableShape and the GUI to display it. You will probably want to work on these parts simultaneously so that you can test your program as you write it.

DecomposableShape

The GUI Interface

You will also need a GUI window to display your shape and the control buttons and slider. This DecomposerFrame will look very similar to previous GUIs: 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.

You can put your main method in the GUI frame class (just have it instantiate the Frame), or create a separate "tester" class.

Completing the Program

This is a sizable program (you can think of it as a "midterm project"), but most parts are something that you have done before: file IO with the Scanner, JFrames, drawing panels, linked lists, etc. There are a few new pieces (circular linked lists, JSliders), but you need to be comfortable looking at 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 homework zip file, and upload it along with your code!

Plan of Attack and Timeline

You 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, along with some deadlines to keep you on track:

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 vhedwig, following the instructions detailed in Lab A. 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 midnight on Fri Oct 17.

Grading

This assignment will be graded out of 37 points: