00001 package edu.stanford.hci.r3.render.ink;
00002
00003 import java.awt.Graphics2D;
00004 import java.awt.geom.GeneralPath;
00005 import java.util.List;
00006
00007 import edu.stanford.hci.r3.pen.ink.InkStroke;
00008
00021 class RenderingTechniqueQuadratic implements RenderingTechnique {
00022
00023 private static int ERROR_THRESHOLD = 500;
00024
00025 public void render(Graphics2D g2d, final List<InkStroke> strokes) {
00026
00027 g2d.setStroke(DEFAULT_INK_STROKE);
00028
00029
00030 for (final InkStroke s : strokes) {
00031
00032 final double[] xArr = s.getXSamples();
00033 final double[] yArr = s.getYSamples();
00034
00035 final GeneralPath strokePath = new GeneralPath();
00036 final int len = xArr.length;
00037 if (len > 0) {
00038 strokePath.moveTo(xArr[0], yArr[0]);
00039 }
00040
00041
00042 double lastGoodX = xArr[0];
00043 double lastGoodY = yArr[0];
00044
00045
00046
00047 int numPointsCollected = 0;
00048 for (int i = 0; i < len; i++) {
00049 final double currX = xArr[i];
00050 final double currY = yArr[i];
00051
00052 numPointsCollected++;
00053
00054 final double diffFromLastX = currX - lastGoodX;
00055 final double diffFromLastY = currY - lastGoodY;
00056
00057 if (Math.abs(diffFromLastX) > ERROR_THRESHOLD || Math.abs(diffFromLastY) > ERROR_THRESHOLD) {
00058
00059
00060
00061
00062
00063 } else {
00064
00065 if (numPointsCollected == 2) {
00066 numPointsCollected = 0;
00067 strokePath.quadTo(lastGoodX, lastGoodY, currX, currY);
00068 }
00069
00070
00071 lastGoodX = currX;
00072 lastGoodY = currY;
00073 }
00074 }
00075
00076
00077 if (numPointsCollected == 1) {
00078 strokePath.lineTo(lastGoodX, lastGoodY);
00079 }
00080 g2d.draw(strokePath);
00081 }
00082 }
00083
00084 }