RenderingTechniqueHybrid.java

00001 package edu.stanford.hci.r3.render.ink;
00002 
00003 import java.awt.BasicStroke;
00004 import java.awt.Graphics2D;
00005 import java.awt.geom.Path2D;
00006 import java.util.List;
00007 
00008 import edu.stanford.hci.r3.pen.ink.InkStroke;
00009 import edu.stanford.hci.r3.pen.ink.InkUtils;
00010 import edu.stanford.hci.r3.util.geometry.CatmullRomSpline;
00011 
00023 class RenderingTechniqueHybrid implements RenderingTechnique {
00024 
00025         public void render(Graphics2D g2d, List<InkStroke> strokes) {
00026                 for (InkStroke stroke : strokes) {
00027                         double width = stroke.getWidth();
00028                         g2d.setStroke(new BasicStroke((float) width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
00029 
00030                         // this doubles as a good max velocity measure, since the samples come in at more or less a
00031                         // constant rate. If the max velocity is too high, we should probably use catmull rom.
00032                         // TODO: In the future, we should hybridize at an even finer granularity (i.e. within stroke)
00033                         // right now, we are hybridizing between strokes.
00034                         double maxDistanceBetweenSamples = InkUtils.getMaxDistanceBetweenSamples(stroke);
00035                         // DebugUtils.println("MaxD: " + maxDistanceBetweenSamples);
00036 
00037                         boolean largeStroke = maxDistanceBetweenSamples > 75;
00038                         if (largeStroke) {
00039                                 final CatmullRomSpline crspline = new CatmullRomSpline();
00040                                 final double[] x = stroke.getXSamples();
00041                                 final double[] y = stroke.getYSamples();
00042                                 crspline.setPoints(x, y);
00043                                 g2d.draw(crspline.getShape());
00044                         } else {
00045                                 final Path2D.Double path = new Path2D.Double();
00046                                 final double[] x = stroke.getXSamples();
00047                                 final double[] y = stroke.getYSamples();
00048                                 path.moveTo(x[0], y[0]);
00049                                 for (int i = 1; i < stroke.getNumSamples(); i++) {
00050                                         path.lineTo(x[i], y[i]);
00051                                 }
00052                                 g2d.draw(path);
00053                         }
00054                 }
00055         }
00056 }

Generated on Sat Apr 14 18:21:38 2007 for R3 Paper Toolkit by  doxygen 1.4.7