edu.mit.sketch.toolkit
Class StrokeData

java.lang.Object
  extended by edu.mit.sketch.toolkit.StrokeData
All Implemented Interfaces:
java.io.Serializable

public class StrokeData
extends java.lang.Object
implements java.io.Serializable

This class stores all the data from a single stroke. Time array has the same length as points.

See Also:
Serialized Form

Field Summary
 boolean a_is_valid
           
 double[] acceleration
          Time derivative of speed
 double[] accumulated_length
          The accumulated length of the curve upto ith vertex.
 boolean accumulated_length_is_valid
           
 Rectangle bounding_box
           
 Point center
           
 double[] d
          Direction array.
 boolean d_is_valid
           
 double[] dd_dt
          Derivative of the direction array (d).
 Gaussian[] dd_dt_gaussians
           
 boolean dd_dt_is_valid
           
 double[][] dd_dt_scale_space
          Direction change scale space information.
 boolean dd_dt_scale_space_is_valid
           
 int direction_window_width
          Parameters and constants.
 LinearFit.Method fit_method
           
 PolarPoint[] polar_points
          The vertices mapped to polar coordinates.
 boolean polar_points_is_valid
           
 java.awt.Dimension radius
           
 double[] speed
          Time derivative of position
 Gaussian[] speed_gaussians
          The gaussian filters.
 double[][] speed_scale_space
          Speed scale space information.
 boolean speed_scale_space_is_valid
           
 double test_line_scale
           
 long[] time
          The absolute time stamps for the vertices.
 boolean v_is_valid
           
 Vertex[] vertices
          The vertices in this data set.
 
Constructor Summary
StrokeData(double[] xs, double[] ys, double[] ts)
          The constructor.
StrokeData(Point[] points_in)
          Create a stroke from these points, and by default, remove duplicate points
StrokeData(Point[] points_in, boolean removeDupes)
          The constructor.
StrokeData(Vertex[] vertices_in)
          The constructor.
 
Method Summary
static double absAverage(double[] l)
           
static double average(double[] l)
           
 double averageAbsoluteFinG(double[] f, double[] g)
          Average
 double averageAbsoluteFinG(double[] f, long[] g)
          Average
 double averageFinG(double[] f, double[] g)
          Average
 double averageFinG(double[] f, long[] g)
          Average
 double averageSpeed()
          Average speed
 void convolveChangeInDirection(double[] filter)
          Do convolution.
 void convolveDirection(double[] filter)
          Do convolution.
 double cosAngle(Point p, Point pl, Point pr)
           
 void derive_accumulated_length()
          Compute the derive accumulated length.
 void derive_d(LinearFit.Method method)
          Derive direction, and fill in the d array.
 void derive_dd_dt_scale_space()
          Compute the scale space data.
 void derive_dd_dt()
          Find time derivative of direction, and fill in the dd_dt array.
 void derive_speed_scale_space()
          Compute the scale space data.
 void deriveAcceleration()
          Derive acceleration, and fill in the acceleration array.
 void deriveBoundingBox()
          Derive the bounding box for the vertices.
 double[] deriveDirectionUsingRotationalSWODR(Point[] input, int window_span)
          Derive direction, and return it.
 double[] deriveDirectionViaSWODR(Point[] input, int twice_window_size)
          Derive direction, and fill in the d array.
 void derivePolarCoordinates()
          Derive the polar coordinates of the vertices with respect to the center.
 void derivePolarCoordinates(double x, double y, int width, int height)
           
 void deriveProperties()
          Derive speed, and fill in the speed array.
 void deriveScaleSpaces()
          Derive speed, and fill in the speed array.
 void deriveSpeed()
          Derive speed, and fill in the speed array.
 double diagnolLength()
           
 double[] differantiateDirection(double[] direction)
          Differantiate the direction array using the current timing data.
 int[] filterCollinearVertices(int[] indices)
          filterCollinearVertices.
 int[] filterVerticesByLSQE(int[] indices, double percentTolerance)
          filterCollinearVertices.
 Vertex[] filterVerticesByLSQE(Vertex[] vertices, double percentTolerance)
          filterCollinearVertices.
 int[] filterVerticesDownToN(int[] inds, int num)
           
 Vertex[] filterVerticesDownToN(Vertex[] verts, int num)
           
 Vertex[] filterVerticesDownToN(Vertex[] verts, int num, double errorBound)
           
 double[] getAngles()
          Get the directions for each of the vertex points.
 Rectangle getBoundingBox()
          Get the bounding box for this stroke.
 Polygon getDataPoints()
          Put the valid points in the points array in a Polygon and return it.
 Vertex[] getDirectionFit(double dd_dt_scale)
          Find the corners of the polygon using the change in the direction.
 Ellipse getEllipse()
          Return the ellipse fully containing the data points.
 Ellipse getEllipseBB()
           
 long getEndTime()
           
 int getNumVertices()
           
 java.awt.geom.Rectangle2D getOriginalBounds()
          Get the bounding box of the original points instead of the filtered points.
 Point[] getOrigPoints()
           
 Vertex[] getPolygonFit(double threshold, int min_size)
          Finds a polygon approximation using the a greedy error threshold method
 java.lang.Object getProperty(java.lang.String name)
          Get a property's value.
 java.lang.Object getProperty(java.lang.String name, java.lang.Object defaultVal)
          Get a property's value.
 Vertex[] getSpeedFit(double average_scale)
          Return the speed fit
 long getStartTime()
           
 double getStrokeLength()
           
 StrokeData getTranslated(double dx, double dy)
          Get a copy of this stroke data object translated by (x,y)
 Vertex[] getVertices()
          Return the vertices array.
 StrokeData interpolatePoints(double maxDist)
          This interpolates points along the stroke such that there is never more than maxDist between adjacent points.
 void invalidateCaches()
          Invalidates caches
 double leastSquaresForCircle()
           
 double leastSquaresForCircle2()
          calculate the lsq error.
 double leastSquaresForEllipse()
          calculate the lsq error.
static void main(java.lang.String[] args)
           
static double[] normalize(double[] l)
           
 void paint(java.awt.Graphics g)
          Paint
 void paint(java.awt.Graphics g, Range range, java.awt.Color c)
          Paint points in range with color c
 Point[] removeDuplicatePoints(Point[] points_in)
          Remove points w/repeating (x,y) or t
 Vertex[] removeDuplicateVertices(Vertex[] vertices_in)
          Remove vertices w/repeating (x,y) or t
 Point[] removeHooks(Point[] points_in)
          Removes hook artifacts, signified by regions of high curvature within 10 pixels of the beginning or end of a stroke
 java.lang.Object removeProperty(java.lang.String name)
          Remove the mapping for the given property.
 Vertex[] removeRedundantEndPoints(Vertex[] input_points)
          Remove the redundant at the beginning and the end.
 void setFitMethod(LinearFit.Method method)
          Set fit method
 void setOrigPoints(Point[] points)
           
 void setProperty(java.lang.String name, java.lang.Object value)
          Set a property to the given value.
 Vertex[] smFit(double tolerance)
          Return the split and merge fit.
 boolean testLine(double test_line_scale)
          See if the input is a line.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

vertices

public Vertex[] vertices
The vertices in this data set.


time

public long[] time
The absolute time stamps for the vertices.


speed

public transient double[] speed
Time derivative of position


acceleration

public transient double[] acceleration
Time derivative of speed


d

public transient double[] d
Direction array. Length of this array is the same as the length of the vertices array. Basically the direction (ie. the angle of the tangent) at the last point in vertices is just the same as that of the previous point.


dd_dt

public transient double[] dd_dt
Derivative of the direction array (d). The length of this array is one less than that of d.


accumulated_length

public transient double[] accumulated_length
The accumulated length of the curve upto ith vertex.


speed_scale_space

public transient double[][] speed_scale_space
Speed scale space information. The rightmost dimension indexes the speed values at different scales, and the leftmost dimension indexes the scale parameter. Higher values correspond to coarser scales.


dd_dt_scale_space

public transient double[][] dd_dt_scale_space
Direction change scale space information. The rightmost dimension indexes the data values at different scales, and the leftmost dimension indexes the scale parameter. Higher values correspond to coarser scales.


speed_gaussians

public transient Gaussian[] speed_gaussians
The gaussian filters.


dd_dt_gaussians

public transient Gaussian[] dd_dt_gaussians

polar_points

public PolarPoint[] polar_points
The vertices mapped to polar coordinates.


direction_window_width

public int direction_window_width
Parameters and constants.


fit_method

public LinearFit.Method fit_method

test_line_scale

public double test_line_scale

center

public Point center

bounding_box

public Rectangle bounding_box

radius

public java.awt.Dimension radius

v_is_valid

public boolean v_is_valid

a_is_valid

public boolean a_is_valid

d_is_valid

public boolean d_is_valid

dd_dt_is_valid

public boolean dd_dt_is_valid

polar_points_is_valid

public boolean polar_points_is_valid

accumulated_length_is_valid

public boolean accumulated_length_is_valid

dd_dt_scale_space_is_valid

public boolean dd_dt_scale_space_is_valid

speed_scale_space_is_valid

public boolean speed_scale_space_is_valid
Constructor Detail

StrokeData

public StrokeData(double[] xs,
                  double[] ys,
                  double[] ts)
The constructor.


StrokeData

public StrokeData(Vertex[] vertices_in)
The constructor.


StrokeData

public StrokeData(Point[] points_in,
                  boolean removeDupes)
The constructor.


StrokeData

public StrokeData(Point[] points_in)
Create a stroke from these points, and by default, remove duplicate points

Parameters:
points_in - The points making up the stroke
Method Detail

getOrigPoints

public Point[] getOrigPoints()

setOrigPoints

public void setOrigPoints(Point[] points)

removeDuplicatePoints

public Point[] removeDuplicatePoints(Point[] points_in)
Remove points w/repeating (x,y) or t


removeDuplicateVertices

public Vertex[] removeDuplicateVertices(Vertex[] vertices_in)
Remove vertices w/repeating (x,y) or t


removeHooks

public Point[] removeHooks(Point[] points_in)
Removes hook artifacts, signified by regions of high curvature within 10 pixels of the beginning or end of a stroke


cosAngle

public double cosAngle(Point p,
                       Point pl,
                       Point pr)

interpolatePoints

public StrokeData interpolatePoints(double maxDist)
This interpolates points along the stroke such that there is never more than maxDist between adjacent points. The distance will not necessarily be constant, it only gaurantees that the distance will be less than the given amount.

Parameters:
maxDist - Max distance allowed between consequtive points
Returns:
The interpolated points in a new stroke

deriveProperties

public void deriveProperties()
Derive speed, and fill in the speed array. This method should cache data in order to save computation.


deriveScaleSpaces

public void deriveScaleSpaces()
Derive speed, and fill in the speed array. This method should cache data in order to save computation.


invalidateCaches

public void invalidateCaches()
Invalidates caches


getVertices

public Vertex[] getVertices()
Return the vertices array.


getAngles

public double[] getAngles()
Get the directions for each of the vertex points. This shares the same indexes as the vertexes array.


getBoundingBox

public Rectangle getBoundingBox()
Get the bounding box for this stroke.

Returns:
The bounding box of this stroke

derivePolarCoordinates

public void derivePolarCoordinates()
Derive the polar coordinates of the vertices with respect to the center. Also determine the upper_right and lower right points (for surrounding rectangle).


derivePolarCoordinates

public void derivePolarCoordinates(double x,
                                   double y,
                                   int width,
                                   int height)

deriveBoundingBox

public void deriveBoundingBox()
Derive the bounding box for the vertices.


getOriginalBounds

public java.awt.geom.Rectangle2D getOriginalBounds()
Get the bounding box of the original points instead of the filtered points. Return the result as a Rectangle2D to preserve the double precision.

Returns:
The BBox of the original points

getStartTime

public long getStartTime()

getEndTime

public long getEndTime()

deriveSpeed

public void deriveSpeed()
Derive speed, and fill in the speed array. This method should cache data in order to save computation.


deriveAcceleration

public void deriveAcceleration()
Derive acceleration, and fill in the acceleration array.


derive_d

public void derive_d(LinearFit.Method method)
Derive direction, and fill in the d array.


derive_dd_dt

public void derive_dd_dt()
Find time derivative of direction, and fill in the dd_dt array.


derive_accumulated_length

public void derive_accumulated_length()
Compute the derive accumulated length.


derive_dd_dt_scale_space

public void derive_dd_dt_scale_space()
Compute the scale space data.


derive_speed_scale_space

public void derive_speed_scale_space()
Compute the scale space data.


filterVerticesDownToN

public Vertex[] filterVerticesDownToN(Vertex[] verts,
                                      int num)

filterVerticesDownToN

public Vertex[] filterVerticesDownToN(Vertex[] verts,
                                      int num,
                                      double errorBound)

filterVerticesDownToN

public int[] filterVerticesDownToN(int[] inds,
                                   int num)

filterVerticesByLSQE

public Vertex[] filterVerticesByLSQE(Vertex[] vertices,
                                     double percentTolerance)
filterCollinearVertices.


filterVerticesByLSQE

public int[] filterVerticesByLSQE(int[] indices,
                                  double percentTolerance)
filterCollinearVertices.


filterCollinearVertices

public int[] filterCollinearVertices(int[] indices)
filterCollinearVertices.


deriveDirectionUsingRotationalSWODR

public double[] deriveDirectionUsingRotationalSWODR(Point[] input,
                                                    int window_span)
Derive direction, and return it. This method is different than the previous one in that here we look at a collection of vertices rather than two vertices to come up with the direction. Also use the rotation method.


deriveDirectionViaSWODR

public double[] deriveDirectionViaSWODR(Point[] input,
                                        int twice_window_size)
Derive direction, and fill in the d array. This method is different than the previous one in that here we look at a collection of vertices rather than two vertices to find the direction. Also this is supposed to work faster. Returns the direction array.


differantiateDirection

public double[] differantiateDirection(double[] direction)
Differantiate the direction array using the current timing data.


averageSpeed

public double averageSpeed()
Average speed


averageFinG

public double averageFinG(double[] f,
                          double[] g)
Average


averageAbsoluteFinG

public double averageAbsoluteFinG(double[] f,
                                  double[] g)
Average


averageFinG

public double averageFinG(double[] f,
                          long[] g)
Average


averageAbsoluteFinG

public double averageAbsoluteFinG(double[] f,
                                  long[] g)
Average


getDataPoints

public Polygon getDataPoints()
Put the valid points in the points array in a Polygon and return it.


smFit

public Vertex[] smFit(double tolerance)
Return the split and merge fit. Tolerance in pixels


getSpeedFit

public Vertex[] getSpeedFit(double average_scale)
Return the speed fit


getDirectionFit

public Vertex[] getDirectionFit(double dd_dt_scale)
Find the corners of the polygon using the change in the direction. This is basically done by finding the peaks of the dd_dt array.


normalize

public static double[] normalize(double[] l)

average

public static double average(double[] l)

absAverage

public static double absAverage(double[] l)

getPolygonFit

public Vertex[] getPolygonFit(double threshold,
                              int min_size)
Finds a polygon approximation using the a greedy error threshold method


diagnolLength

public double diagnolLength()

testLine

public boolean testLine(double test_line_scale)
See if the input is a line.


getEllipse

public Ellipse getEllipse()
Return the ellipse fully containing the data points.


getEllipseBB

public Ellipse getEllipseBB()

leastSquaresForEllipse

public double leastSquaresForEllipse()
calculate the lsq error.


leastSquaresForCircle

public double leastSquaresForCircle()

leastSquaresForCircle2

public double leastSquaresForCircle2()
calculate the lsq error.


removeRedundantEndPoints

public Vertex[] removeRedundantEndPoints(Vertex[] input_points)
Remove the redundant at the beginning and the end.


setFitMethod

public void setFitMethod(LinearFit.Method method)
Set fit method


convolveDirection

public void convolveDirection(double[] filter)
Do convolution.


convolveChangeInDirection

public void convolveChangeInDirection(double[] filter)
Do convolution.


paint

public void paint(java.awt.Graphics g)
Paint


getNumVertices

public int getNumVertices()

getTranslated

public StrokeData getTranslated(double dx,
                                double dy)
Get a copy of this stroke data object translated by (x,y)

Parameters:
dx - Translate this far in x
dy - Translate this far in y
Returns:
A new StrokeData translated by the given amount

paint

public void paint(java.awt.Graphics g,
                  Range range,
                  java.awt.Color c)
Paint points in range with color c


getStrokeLength

public double getStrokeLength()

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
Set a property to the given value. This can be used for things like names, ids, etc...


getProperty

public java.lang.Object getProperty(java.lang.String name)
Get a property's value. This can be used for things like names, ids, etc...


getProperty

public java.lang.Object getProperty(java.lang.String name,
                                    java.lang.Object defaultVal)
Get a property's value. This can be used for things like names, ids, etc...


removeProperty

public java.lang.Object removeProperty(java.lang.String name)
Remove the mapping for the given property. It returns the value of the removed key. (note: null may mean no such property or that the properties value was null)


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)