hhreco.toolbox
Class ApproximateStrokeFilter

java.lang.Object
  extended byhhreco.toolbox.StrokeFilter
      extended byhhreco.toolbox.ApproximateStrokeFilter

public class ApproximateStrokeFilter
extends StrokeFilter

Implementation of a point reduction technique.

[1] Hanaki, Temma, Yoshida, "An On-line Character Recognition Aimed at a Substitution for a Billing Machine Keyboard", Pattern Recognition, Vol.8, pp63-71, 1976.


Field Summary
static double DEFAULT_THRESH_DISTANCE
          If the farthest point from a line segment is less than the DEFAULT_THRESH_DISTANCE, remove all of the in-between points.
 
Constructor Summary
ApproximateStrokeFilter()
          Construct a ApproximateStrokeFilter with default threshold distance of 4 units.
ApproximateStrokeFilter(double threshold)
          Construct a ApproximateStrokeFilter with the given threshold.
 
Method Summary
 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)
          Approximate the given stroke using the specified threshold distance.
 double getThreshDistance()
          Return the threshold distance.
 void setThreshDistance(double 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, remove all of the in-between points. If the distance is greater than this value, recursively filter the stroke by breaking off at the farthest point. The default value is set to 4 units.

See Also:
Constant Field Values
Constructor Detail

ApproximateStrokeFilter

public ApproximateStrokeFilter()
Construct a ApproximateStrokeFilter with default threshold distance of 4 units.


ApproximateStrokeFilter

public ApproximateStrokeFilter(double threshold)
Construct a ApproximateStrokeFilter with the given threshold.

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)
Approximate the given stroke using the specified threshold distance.


setThreshDistance

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


getThreshDistance

public double getThreshDistance()
Return the threshold distance.