UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.satin.stroke
Class StrokeLib

java.lang.Object
  |
  +--edu.berkeley.guir.lib.satin.stroke.StrokeLib
All Implemented Interfaces:
SatinConstants

public class StrokeLib
extends Object
implements SatinConstants

Utilities for manipulating strokes, including:

See Polygon2D.simplify() for how to simplify a polyline.

This software is distributed under the Berkeley Software License.

 Revisions:  - SATIN-v1.0-1.0.0, Aug 02 1999, JH
               Created class
             - SATIN-v1.0-1.0.0, Jul 22 2000, JH
               Moved the temporal and spatial distance methods
               from PhraseInterpreter to here.
             - SATIN-v2.1-1.0.0, Aug 11 2000, JH
               Touched for SATIN release
             - SATIN-v2.1-1.1.0, Oct 07 2000, JH
               Added computeApproxDirectionVector()
 

Since:
JDK 1.2
Version:
SATIN-v2.1-1.1.0, Oct 07 2000
Author:
Jason Hong ( jasonh@cs.berkeley.edu )

Inner classes inherited from class edu.berkeley.guir.lib.satin.SatinConstants
SatinConstants.ObjectPoolAffineTransform, SatinConstants.ObjectPoolPoint2D, SatinConstants.ObjectPoolPolygon2D, SatinConstants.ObjectPoolRectangle2D, SatinConstants.ObjectPoolStringBuffer, SatinConstants.UniqueAffineTransform, SatinConstants.UniquePoint2D, SatinConstants.UniquePolygon2D, SatinConstants.UniqueRectangle2D
 
Fields inherited from interface edu.berkeley.guir.lib.satin.SatinConstants
ABOVE, ALL, BAR, BELOW, clipboard, clprops, cmdqueue, cmdsubsys, CONTAINEDBY, CONTAINS, COORD_ABS, COORD_LOCAL, COORD_REL, DAMAGE_LATER, DAMAGE_NOW, DEBUG_GRAPHICS_OFFSET, DEBUG_STYLE_FILE, DEBUG_STYLE_GPROPERTY, DEEP, DEFAULT_POINT2D_POOL_SIZE, DEFAULT_POLYGON2D_POOL_SIZE, DEFAULT_RECTANGLE_POOL_SIZE, DEFAULT_REPAINT_THRESHOLD, DEFAULT_SELECT_THRESHOLD, DEFAULT_STRINGBUFFER_POOL_SIZE, DEFAULT_TRANSFORM_POOL_SIZE, DIR_CENTER, DIR_DOWN, DIR_DOWN_LEFT, DIR_DOWN_RIGHT, DIR_LEFT, DIR_RIGHT, DIR_UP, DIR_UP_LEFT, DIR_UP_RIGHT, FILTER_THRESHOLD, FIRST, FLOATING_PT_TOLERANCE, glprops, INTERSECTS, KEY_STYLE_DASHARRAY, KEY_STYLE_DASHPHASE, KEY_STYLE_DRAWCOLOR, KEY_STYLE_DRAWFONT, KEY_STYLE_DRAWTRANSPARENCY, KEY_STYLE_ENDCAP, KEY_STYLE_FILLCOLOR, KEY_STYLE_FILLTRANSPARENCY, KEY_STYLE_LINEJOIN, KEY_STYLE_LINEWIDTH, KEY_STYLE_MITERLIMIT, NEAR, NOTIFY_BOUNDS, NOTIFY_LAYER, NOTIFY_LOCATION, NOTIFY_STYLE, NOTIFY_TRANSFORM, poolPoints, poolPolys, poolRects, poolStrbuf, poolTx, rand, SATIN_DATA_DIRECTORY_DEFAULT, SATIN_DATA_DIRECTORY_GPROPERTY, SATIN_PROPERTIES_FILENAME, SHALLOW
 
Constructor Summary
StrokeLib()
           
 
Method Summary
static Point2D computeApproxDirection(int cdsys, TimedStroke stk)
          Given a stroke, approximate the direction that the last few endpoints are going in.
static double computeDistance(double relImportanceSpace, double relImportanceTime, TimedStroke stk1, TimedStroke stk2)
          Compute the distance between two strokes in some "stroke-space".
static double computeDistance(TimedStroke stk1, TimedStroke stk2)
          Compute the distance between two strokes in some "stroke-space".
static double computeHandwritingDistance(TimedStroke stk1, TimedStroke stk2)
          Compute how far two strokes are in "handwriting space".
static double computeSpatialDistance(double relImportanceX, double relImportanceY, TimedStroke stk1, TimedStroke stk2)
          Compute the spatial distance between two strokes.
static double computeSpatialDistance(TimedStroke stk1, TimedStroke stk2)
          Calls the other computeSpatialDistance() method using unbiased distances (ie weights of 1).
static double computeTemporalDistance(TimedStroke stk1, TimedStroke stk2)
          Compute the distance between two strokes in terms of time.
static double computeTemporalDistance(TimedStroke stk1, TimedStroke stk2, double maxTimeDistance)
          Compute the distance between two strokes in terms of time.
static float[] getCumulativeLengths(Polygon2D poly)
          Return an array that contains the cumulative length of the polygon.
static float[] getCumulativeXValues(Polygon2D poly)
          Return an array that contains the cumulative X values of the polygon.
static float[] getCumulativeYValues(Polygon2D poly)
          Return an array that contains the cumulative X values of the polygon.
static TimedStroke linearize(TimedStroke stk)
          Given a stroke, straighten it out.
static TimedStroke mergeStrokes(TimedStroke stkAA, TimedStroke stkBB)
          Do our best to merge two strokes together into a new one.
static List splitStroke(TimedStroke stk, Rectangle2D rect)
          Given a stroke and a box, return an iterator to a list of strokes that results from erasing the region in the box, possibly cutting the given stroke into several smaller strokes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StrokeLib

public StrokeLib()
Method Detail

getCumulativeLengths

public static float[] getCumulativeLengths(Polygon2D poly)
Return an array that contains the cumulative length of the polygon. For example, index[0] is 0.0, index[1] is the length from point 0 to 1, index[2] is length from point 0 to 2, etc.

getCumulativeXValues

public static float[] getCumulativeXValues(Polygon2D poly)
Return an array that contains the cumulative X values of the polygon. For example, given polygon {(2, 3), (6, 7), (9, 10)}, the array returned would be {2, 8, 17} (2, 2+6, 2+6+9).

getCumulativeYValues

public static float[] getCumulativeYValues(Polygon2D poly)
Return an array that contains the cumulative X values of the polygon. For example, given polygon {(2, 3), (6, 7), (9, 10)}, the array returned would be {3, 10, 20} (3, 3+7, 3+7+10).

computeApproxDirection

public static Point2D computeApproxDirection(int cdsys,
                                             TimedStroke stk)
Given a stroke, approximate the direction that the last few endpoints are going in.
Parameters:
cdsys - is the coordinate system to use.
stk - is the stroke whose approximate direction we want.
Returns:
a Point2D representing direction and magnitude.

computeSpatialDistance

public static double computeSpatialDistance(TimedStroke stk1,
                                            TimedStroke stk2)
Calls the other computeSpatialDistance() method using unbiased distances (ie weights of 1).

computeSpatialDistance

public static double computeSpatialDistance(double relImportanceX,
                                            double relImportanceY,
                                            TimedStroke stk1,
                                            TimedStroke stk2)
Compute the spatial distance between two strokes. The spatial distance between two strokes is the weighted sum of the minimum x-distance and the minimum y-distance between two strokes.

Method uses a version of the algorithm proposed by Chiu and Wilcox in Chiu, P. and Wilcox, L. "A Dynamic Grouping Technique for Ink and Audio Notes," Proceedings of UIST 98, San Francisco, CA, November 1-4, 1998, pp. 195-202.

Parameters:
relImportanceX - is the weight on the x-distance.
relImportanceY - is the weight on the y-distance.
stk1 - is a stroke.
stk2 - is a stroke.

computeTemporalDistance

public static double computeTemporalDistance(TimedStroke stk1,
                                             TimedStroke stk2)
Compute the distance between two strokes in terms of time. Use a maximum time value of 100,000.

computeTemporalDistance

public static double computeTemporalDistance(TimedStroke stk1,
                                             TimedStroke stk2,
                                             double maxTimeDistance)
Compute the distance between two strokes in terms of time.

Method uses a version of the algorithm proposed by Chiu and Wilcox in Chiu, P. and Wilcox, L. "A Dynamic Grouping Technique for Ink and Audio Notes," Proceedings of UIST 98, San Francisco, CA, November 1-4, 1998, pp. 195-202.


computeDistance

public static double computeDistance(TimedStroke stk1,
                                     TimedStroke stk2)
Compute the distance between two strokes in some "stroke-space". Weight temporal distances and spatial distances equally (ie 1).

computeHandwritingDistance

public static double computeHandwritingDistance(TimedStroke stk1,
                                                TimedStroke stk2)
Compute how far two strokes are in "handwriting space". Lower values mean these two strokes should be aggregated together. Only takes spatial distance into account, ignores temporal.

computeDistance

public static double computeDistance(double relImportanceSpace,
                                     double relImportanceTime,
                                     TimedStroke stk1,
                                     TimedStroke stk2)
Compute the distance between two strokes in some "stroke-space".

Method uses a version of the algorithm proposed by Chiu and Wilcox in Chiu, P. and Wilcox, L. "A Dynamic Grouping Technique for Ink and Audio Notes," Proceedings of UIST 98, San Francisco, CA, November 1-4, 1998, pp. 195-202.


linearize

public static TimedStroke linearize(TimedStroke stk)
Given a stroke, straighten it out. In other words, make a hand-drawn stroke go up, down, left, or right only, with 90 degree transitions.

mergeStrokes

public static TimedStroke mergeStrokes(TimedStroke stkAA,
                                       TimedStroke stkBB)
Do our best to merge two strokes together into a new one.

splitStroke

public static List splitStroke(TimedStroke stk,
                               Rectangle2D rect)
Given a stroke and a box, return an iterator to a list of strokes that results from erasing the region in the box, possibly cutting the given stroke into several smaller strokes.
Parameters:
stk - is the stroke to cut.
rect - is the Rectangle in absolute coordinates.

Copyright Information