diva.sketch.toolbox

## Class ApproximateStrokeFilter

• ```public class ApproximateStrokeFilter
extends StrokeFilter```
An object which filters a pen stroke using "approximation by line segments" technique, (Hanaki, Temma, Yoshida, "An On-line Character Recognition Aimed at a Substitution for a Billing Machine Keyboard", Pattern Recognition, Vol.8, pp63-71, 1976).
Version:
\$Revision: 1.12 \$
Author:
Heloise Hse (hwawen@eecs.berkeley.edu)
• ### Field Summary

Fields
Modifier and Type Field and Description
`static double` `DEFAULT_THRESH_DISTANCE`
If the farthest point from a line segment is less than the DEFAULT_THRESH_DISTANCE, we can throw away all the in-between points, because they are almost colinear.
• ### Fields inherited from class diva.sketch.toolbox.StrokeFilter

`PROPERTY_KEY`
• ### Constructor Summary

Constructors
Constructor and Description
`ApproximateStrokeFilter()`
Construct a ApproximateStrokeFilter with default threshold distance of 2 units.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`TimedStroke` `apply(TimedStroke s)`
Reduce the number of points in the given pen stroke using the "approximation by line segments" algorithm.
`static TimedStroke` `approximate(TimedStroke s)`
Reduce the number of points in the given pen stroke using the "approximation by line segments" algorithm.
`static TimedStroke` ```approximate(TimedStroke s, double threshDist)```
Reduce the number of points in the given pen stroke using the "approximation by line segments" algorithm.
`void` `setThreshDistance(int val)`
Set the threshold distance of a point from a line segment.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Field Detail

• #### DEFAULT_THRESH_DISTANCE

`public static final double DEFAULT_THRESH_DISTANCE`
If the farthest point from a line segment is less than the DEFAULT_THRESH_DISTANCE, we can throw away all the in-between points, because they are almost colinear. If the distance is greather than this value, we recursively filter the stroke by breaking off at the farthest point. The default value is set to 2 units.
Constant Field Values
• ### Constructor Detail

• #### ApproximateStrokeFilter

`public ApproximateStrokeFilter()`
Construct a ApproximateStrokeFilter with default threshold distance of 2 units.
• ### Method Detail

• #### apply

`public TimedStroke apply(TimedStroke s)`
Reduce the number of points in the given pen stroke using the "approximation by line segments" algorithm.

Algorithm: Form a line with the first and last points of the stroke. Find a farthest point (P) from the line segment such that distance between the line and P exceeds a threshold value. Then, break the line segment into 2 and recursively apply filtering on the 2 parts, (first, P) and (P, last). The threshold value is defaulted to DEFAULT_THRESH_DISTANCE.

Specified by:
`apply` in class `StrokeFilter`
Parameters:
`s` - the stroke to be filtered.
• #### approximate

`public static TimedStroke approximate(TimedStroke s)`
Reduce the number of points in the given pen stroke using the "approximation by line segments" algorithm.

Algorithm: Form a line with the first and last points of the stroke. Find a farthest point (P) from the line segment such that distance between the line and P exceeds a threshold value. Then, break the line segment into 2 and recursively apply filtering on the 2 parts, (first, P) and (P, last). The threshold value is defaulted to DEFAULT_THRESH_DISTANCE.

Parameters:
`s` - the stroke to be filtered.
• #### approximate

```public static TimedStroke approximate(TimedStroke s,
double threshDist)```
Reduce the number of points in the given pen stroke using the "approximation by line segments" algorithm.

Algorithm: Form a line with the first and last points of the stroke. Find a farthest point (P) from the line segment such that distance between the line and P exceeds a threshold value (threshDist). Then, break the line segment into 2 and recursively apply filtering on the 2 parts, (first, P) and (P, last).

• #### setThreshDistance

`public void setThreshDistance(int val)`
Set the threshold distance of a point from a line segment. If 'val' is negative, throws an IllegalArgumentException.