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.rubinebd;
28  
29  import java.math.BigDecimal;
30  import java.util.logging.Level;
31  import java.util.logging.Logger;
32  
33  import org.sigtec.ink.Note;
34  import org.ximtec.igesture.algorithm.feature.FeatureException;
35  import org.ximtec.igesture.util.BigDecimalVector;
36  
37  
38  /**
39   * Comment
40   * @version 1.0 12.06.2008
41   * @author Ueli Kurmann
42   */
43  public class GestureSampleHelper {
44  
45     private static final Logger LOGGER = Logger.getLogger(GestureSampleHelper.class
46           .getName());
47  
48     private Note note;
49     private RubineConfiguration config;
50     private BigDecimalVector featureVector;
51  
52  
53     public GestureSampleHelper(Note note, RubineConfiguration config) {
54        this.note = note;
55        this.config = config;
56        LOGGER.setLevel(Level.SEVERE);
57     }
58     
59     /**
60      * Computes the feature vector for a given sample. The features to compute are
61      * passed as an array. The method returns a double vector representing the
62      * feature vector.
63      * 
64      * @param sample the sample.
65      * @param featureList the features to compute.
66      * @return the feature vector for the given sample.
67      */
68     private BigDecimalVector computeFeatureVector()
69           throws FeatureException {
70       
71      
72  
73        // clone the note to avoid side effects
74        Note clonedNote = (Note)note.clone();
75        clonedNote.scaleTo(200, 200);
76  
77        // filter the note using the min distance
78        clonedNote.filter(config.getMinDistance());
79  
80        // create the feature vector
81        BigDecimalVector featureVector = new BigDecimalVector(config.getNumberOfFeatures());
82  
83        for (int i = 0; i < config.getNumberOfFeatures(); i++) {
84        
85          
86           featureVector.set(i, new BigDecimal(config.getFeatureList()[i].compute(clonedNote)));
87        }
88        System.out.println(featureVector.toString());
89        LOGGER.info(featureVector.toString());
90        return featureVector;
91     } // computeFeatureVector
92  
93  
94     public BigDecimalVector getFeatureVector() throws FeatureException {
95        if(featureVector == null){
96           featureVector = computeFeatureVector();
97        }
98        return featureVector;
99     }
100 
101 }