|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdiva.sketch.toolbox.CachingStrokeRecognizer
public class CachingStrokeRecognizer
A proxy recognizer implementation that caches the result of the target recognizer. If the same stroke is passed in with the same number of vertices, it returns the cached recognition result rather than calling the target recognizer. This is useful, for example, if multiple "high-level" recognizers (HLRs) want to share a basic recognizer to recognize shapes. Suppose the user draws a square. Without a cache:
The uncached version results in a lot of wasted computation on the part of the basic recognizer. With a cache, the sequence looks like this:
Since we expect most users will want to use a single basic recognizer, this should save a lot of unnecessary computation. Having this caching behavior in its own class makes it self-contained and possibly reusable.
Constructor Summary | |
---|---|
CachingStrokeRecognizer(StrokeRecognizer target)
Cache the recognitions of the given target recognizer. |
Method Summary | |
---|---|
void |
clear()
Manually clear the cache. |
boolean |
hasStrokeChanged(TimedStroke s)
Return whether or not the given stroke is changed relative to the previous cached version. |
RecognitionSet |
strokeCompleted(TimedStroke s)
Perform recognition in the target if the given stroke hasn't changed since the last time this method was called. |
RecognitionSet |
strokeModified(TimedStroke s)
Perform recognition in the target if the given stroke hasn't changed since the last time this method was called. |
RecognitionSet |
strokeStarted(TimedStroke s)
Perform recognition in the target if the given stroke hasn't changed since the last time this method was called. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CachingStrokeRecognizer(StrokeRecognizer target)
Method Detail |
---|
public void clear()
public boolean hasStrokeChanged(TimedStroke s)
This method can be overridden to make the caching more accurate or more sophisticated. For example it could be configured to perform recognition only after "N" vertices have been added.
public RecognitionSet strokeCompleted(TimedStroke s)
strokeCompleted
in interface StrokeRecognizer
public RecognitionSet strokeModified(TimedStroke s)
strokeModified
in interface StrokeRecognizer
public RecognitionSet strokeStarted(TimedStroke s)
strokeStarted
in interface StrokeRecognizer
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |