View Javadoc
1   package edu.uci.ics.jung.visualization;
2   
3   import java.awt.Shape;
4   import java.awt.geom.PathIterator;
5   import java.awt.image.BufferedImage;
6   
7   import edu.uci.ics.jung.visualization.util.ImageShapeUtils;
8   import junit.framework.TestCase;
9   
10  public class TestImageShaper extends TestCase {
11  	
12  	BufferedImage image;
13  	
14  	@Override
15  	protected void setUp() throws Exception {
16  		super.setUp();
17  		int width = 6;
18  		int height = 5;
19  		image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
20  		for(int i=0; i<height; i++) {
21  			for(int j=0; j<width; j++) {
22  				image.setRGB(j, i, 0x00000000);
23  //				System.err.println("["+j+","+i+"] = "+image.getRGB(j, i));
24  //				if((image.getRGB(j,i) & 0xff000000) != 0) {
25  //					System.err.println("got an opaque point at ["+j+","+i+"]");
26  //				}
27  			}
28  		}
29  		image.setRGB(3, 1, 0xffffffff);
30  		image.setRGB(4, 1, 0xffffffff);
31  		image.setRGB(2, 2, 0xffffffff);
32  		image.setRGB(4, 2, 0xffffffff);
33  		image.setRGB(1, 3, 0xffffffff);
34  		image.setRGB(2, 3, 0xffffffff);
35  		image.setRGB(3, 3, 0xffffffff);
36  		image.setRGB(4, 3, 0xffffffff);
37  	}
38  
39  	public void testShaper() {
40  		Shape shape = ImageShapeUtils.getShape(image, 30);
41  //		System.err.println("complete shape = "+shape);
42  		float[] seg = new float[6];
43  		for (PathIterator i = shape.getPathIterator(null, 1); !i.isDone(); i
44  				.next()) {
45  			int ret = i.currentSegment(seg);
46  //			if (ret == PathIterator.SEG_MOVETO) {
47  //				System.err.println("move to "+seg[0]+","+seg[1]);
48  //			} else if (ret == PathIterator.SEG_LINETO) {
49  //				System.err.println("line to "+seg[0]+","+seg[1]);
50  //			} else if(ret == PathIterator.SEG_CLOSE) {
51  //				System.err.println("done");
52  //			}
53  		}
54  	}
55  }