View Javadoc

1   /*
2    * @(#)$Id: GestureSampleHelper.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author		:	Ueli Kurmann, igesture@uelikurmann.ch
5    *                  
6    *
7    * Purpose		:   
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date				Who			Reason
14   *
15   * 12.06.2008			ukurmann	Initial Release
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
23   * 
24   */
25  
26  
27  package org.ximtec.igesture.algorithm.rubine;
28  
29  import java.util.logging.Level;
30  import java.util.logging.Logger;
31  
32  import org.sigtec.ink.Note;
33  import org.ximtec.igesture.algorithm.feature.FeatureException;
34  import org.ximtec.igesture.util.DoubleVector;
35  
36  
37  /**
38   * Comment
39   * @version 1.0 12.06.2008
40   * @author Ueli Kurmann
41   */
42  public class GestureSampleHelper {
43  
44     private static final Logger LOGGER = Logger.getLogger(GestureSampleHelper.class
45           .getName());
46  
47     private Note note;
48     private RubineConfiguration config;
49     private DoubleVector featureVector;
50  
51  
52     public GestureSampleHelper(Note note, RubineConfiguration config) {
53        this.note = note;
54        this.config = config;
55        LOGGER.setLevel(Level.SEVERE);
56     }
57     
58     /**
59      * Computes the feature vector for a given sample. The features to compute are
60      * passed as an array. The method returns a double vector representing the
61      * feature vector.
62      * 
63      * @param sample the sample.
64      * @param featureList the features to compute.
65      * @return the feature vector for the given sample.
66      */
67     private DoubleVector computeFeatureVector()
68           throws FeatureException {
69  
70        // clone the note to avoid side effects
71        Note clone = (Note)note.clone();
72        clone.scaleTo(200, 200);
73  
74        // filter the note using the min distance
75        clone.filter(config.getMinDistance());
76  
77        // create the feature vector
78        DoubleVector featureVector = new DoubleVector(config.getNumberOfFeatures());
79  
80        for (int i = 0; i < config.getNumberOfFeatures(); i++) {
81           featureVector.set(i, config.getFeatureList()[i].compute(clone));
82        }
83  
84        LOGGER.info(featureVector.toString());
85        return featureVector;
86     } // computeFeatureVector
87  
88  
89     public DoubleVector getFeatureVector() throws FeatureException {
90        if(featureVector == null){
91           featureVector = computeFeatureVector();
92        }
93        return featureVector;
94     }
95  
96  }