View Javadoc

1   /*
2    * @(#)$Id: F26.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author       :   Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose      :   Rubine Feature F1. Cosine of the initial angle of the
7    *                  gesture.
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date             Who         Reason
14   *
15   * Dec 26, 2006     ukurmann    Initial Release
16   * Mar 15, 2007     bsigner     Cleanup
17   *
18   * -----------------------------------------------------------------------
19   *
20   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
21   *
22   * This software is the proprietary information of ETH Zurich.
23   * Use is subject to license terms.
24   * 
25   */
26  
27  package org.ximtec.igesture.algorithm.feature;
28  
29  import org.sigtec.ink.Note;
30  import org.sigtec.ink.Point;
31  import org.sigtec.ink.Trace;
32  
33  /**
34   * F26, proportion of points below / over the line start - endpoint
35   * 
36   * @version 1.0 Dec 2006
37   * @author Ueli Kurmann, igesture@uelikurmann.ch
38   * @author Beat Signer, signer@inf.ethz.ch
39   */
40  public class F26 implements Feature {
41  
42  	private static final int MINIMAL_NUMBER_OF_POINTS = 5;
43  
44  	public double compute(Note note) throws FeatureException {
45  		if (note.getPoints().size() < MINIMAL_NUMBER_OF_POINTS) {
46  			throw new FeatureException(FeatureException.NOT_ENOUGH_POINTS);
47  		}
48  
49  		Trace trace = FeatureTool.createTrace(note);
50  
51  		double m = (trace.getEndPoint().getY() - trace.getStartPoint().getY())
52  				/ (trace.getEndPoint().getX() - trace.getStartPoint().getX());
53  
54  		double b = trace.getStartPoint().getY() - trace.getStartPoint().getX()
55  				* m;
56  
57  		int below = 1;
58  		int above = 1;
59  
60  		for (Point point : trace.getPoints()) {
61  			if (m * point.getX() + b > point.getY()) {
62  				below++;
63  			} else {
64  				above++;
65  			}
66  		}
67  
68  
69  		return (double) above / (double) below;
70  	} // compute
71  
72  	public int getMinimalNumberOfPoints() {
73  		return MINIMAL_NUMBER_OF_POINTS;
74  	} // getMinimalNumberOfPoints
75  
76  }