frog
Class Session

java.lang.Object
  extended by frog.Session
All Implemented Interfaces:
DeviceListener, Serializable

public class Session
extends Object
implements DeviceListener, Serializable

Session is the FROG representation of a single user. A session keeps track of all the objects and methods that must be run in a certain order on data passed to it from a device.

Author:
Team Better Recognize
See Also:
Serialized Form

Constructor Summary
Session()
          Creates a new Session.
 
Method Summary
 void accelerationPerformed(AccelEvent e)
          Run every time a single acceleration has come in.
 void addFilter(Filter filter)
          Adds a filter to this session.
 void addFilter(Filter filter, int index)
          Adds a filter in a particular order to this session.
 void addSessionListener(SessionListener sl)
          Adds a new SessionListener to this Session.
 void dispose()
          Completely destroys this session.
 void editGesture(int index)
          Sets the current gesture to the one specified by the index.
 void gestureComplete(boolean good, Device d)
          Run when a single gesture has been completed.
 Filter[] getActiveFilters()
          Returns a list of filters currently active on this Session.
 int getCurrentGestureIndex()
          Accessor for the current gesture index.
 Device getDevice()
          Returns the Device this Session is receiving acceleration data from.
 BufferedImage getGestureIcon(int index)
          Returns the icon of the gesture specified by the index.
 String getGestureName(int index)
          Returns the name of the gesture specified by the index.
 Vector<GestureModel> getGestureSession()
          Returns the gesture session stored by this Session object.
 double getLastProbability()
          Accessor for the last recognition event probability.
 String getName()
          Returns the name of this Session.
 void inRecognitionMode()
          Sets the mode to recognition, enabling/disabling certain functionality.
 void inTrainingMode()
          Sets the mode to training, enabling/disabling certain functionality.
 GestureModel newGesture(String name)
          Creates a new gesture and adds it to the current session.
 GestureModel newGesture(String name, byte[] imgBuf)
          Creates a new gesture with a given image and adds it to the current session.
 void notifyGestureRecognized(GestureModel g)
          Notifies all SessionListeners of a recognition of a gesture g
 boolean removeAccel(int inum, int anum)
          Deletes an individual acceleration from the current gesture in the current gesture session at the specified index (assuming the indices are valid).
 boolean removeAccel(int snum, int inum, int anum)
          Deletes an individual acceleration from the current gesture session at the specified index (assuming the indices are valid).
 void removeFilter(int i)
          Removes a filter at a given index.
 boolean removeInstance(int inum)
          Deletes a gesture instance from the current gesture in the current gesture session at the specified index (assuming the index is valid).
 boolean removeInstance(int snum, int inum)
          Deletes a gesture instance from current gesture session at the specified index (assuming the index is valid).
 void removeSessionListener(SessionListener sl)
          Removes a SessionListener from this Session's list of listeners
 boolean removeSet()
          Deletes a gesture set from the current gesture session.
 boolean removeSet(int snum)
          Deletes a gesture set from the current gesture session at the specified index (assuming the index is valid).
 void restoreDefaults()
          Restores the default training parameters for this session.
 void setClassifierType(int type)
          Sets the type (an integer - see Classifier) of classifier to be used in the Session.
 void setDevice(Device d)
          Sets the device for this Session.
 void setGestureIcon(byte[] imageBuffer)
          Sets the icon of the current gesture to the one contained in a byte array.
 boolean setGestureIcon(int index, byte[] imageBuffer)
          Sets the icon of the specified gesture to the one contained in a byte array.
 boolean setGestureModelType(int type)
          Sets the type (an integer - see GestureModel) of gesture model to be used in the Session.
 void setName(String name)
          Sets the name of this Session.
 String toString()
           
 boolean train()
          Trains the GestureModel representing the current gesture in the current gesture session.
 boolean train(int index)
          Trains the GestureModel at the given index in the current gesture session.
 boolean train(int index, GestureHMMParameters gParams)
          Trains the GestureHMM at the given index in the current gesture session with the specified parameters.
 boolean train(int index, GestureHMMParameters gParams, KmeansParameters kParams)
          Trains the GestureHMM at the given index in the current gesture session with the specified parameters.
 void trainAll()
          Trains every GestureModel in the current gesture session.
 void unexpectedDisconnect(Device d)
          For handling an unexpected disconnect from a device.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Session

public Session()
Creates a new Session.

Method Detail

accelerationPerformed

public void accelerationPerformed(AccelEvent e)
Description copied from interface: DeviceListener
Run every time a single acceleration has come in.

It is highly recommended you keep this method simple or execute in a new Thread. There may be many listeners all wanting to execute some code when an event happens.

Specified by:
accelerationPerformed in interface DeviceListener
Parameters:
e - contains the acceleration data and the calling device

addFilter

public void addFilter(Filter filter)
Adds a filter to this session.

Parameters:
filter - the filter to be added

addFilter

public void addFilter(Filter filter,
                      int index)
Adds a filter in a particular order to this session.

Parameters:
filter - the filter to be added
index - the position in the filter order
Throws:
ArrayOutOfBoundsException - if the position was invalid

addSessionListener

public void addSessionListener(SessionListener sl)
Adds a new SessionListener to this Session.

Parameters:
sl - a new SessionListener to be notified of Session changes

dispose

public void dispose()
Completely destroys this session. Readies it for garbage collection.


editGesture

public void editGesture(int index)
Sets the current gesture to the one specified by the index. This method does nothing if the index is invalid.

Parameters:
index - the index of the gesture to work on

gestureComplete

public void gestureComplete(boolean good,
                            Device d)
Description copied from interface: DeviceListener
Run when a single gesture has been completed. If the gesture was cut unexpectedly short either due to an error or hardware failure the boolean will be false and appropriate action should be taken to discard all acceleration data up to this point since the last known good gesture.

Specified by:
gestureComplete in interface DeviceListener
Parameters:
good - true if this gesture is complete. false if this gesture should be discarded.
d - the device that completed the gesture

getActiveFilters

public Filter[] getActiveFilters()
Returns a list of filters currently active on this Session.

Returns:
an array of all the Filters currently active in the correct order

getCurrentGestureIndex

public int getCurrentGestureIndex()
Accessor for the current gesture index.

Returns:
the index of the current gesture

getDevice

public Device getDevice()
Returns the Device this Session is receiving acceleration data from.

Returns:
the device with which the Session is communicating (listening)

getGestureIcon

public BufferedImage getGestureIcon(int index)
Returns the icon of the gesture specified by the index. This method returns null if the GestureModel has no icon or if the index was invalid.

Parameters:
index - the index of the gesture to retrieve the icon of
Returns:
the icon of the gesture, or null if:
  • the gesture has no icon
  • the index given was invalid

getGestureName

public String getGestureName(int index)
Returns the name of the gesture specified by the index. If the index is invalid, this method returns null.

Parameters:
index - the index of the gesture to retrieve the name of
Returns:
the name of this gesture or null if the index was invalid

getGestureSession

public Vector<GestureModel> getGestureSession()
Returns the gesture session stored by this Session object. The gesture session is all of the GestureModels combined. Each GestureModel represents one gesture, which itself is made up of several trainings of that gesture called gesture instances.

Returns:
the set of GestureModels currently loaded in the Session

getLastProbability

public double getLastProbability()
Accessor for the last recognition event probability. This corresponds to the last probability obtained from the classifier associated with this session.

Returns:
the probability of the last recognition event

getName

public String getName()
Returns the name of this Session.

Returns:
the name of this Session

inRecognitionMode

public void inRecognitionMode()
Sets the mode to recognition, enabling/disabling certain functionality.


inTrainingMode

public void inTrainingMode()
Sets the mode to training, enabling/disabling certain functionality.


newGesture

public GestureModel newGesture(String name)
Creates a new gesture and adds it to the current session.

Parameters:
name - the name to give this gesture; cannot be null
Returns:
a reference to the new GestureModel for convenience. It has already been added to the Session.
Throws:
IllegalArgumentExecption - if the gesture name is null

newGesture

public GestureModel newGesture(String name,
                               byte[] imgBuf)
                        throws IOException
Creates a new gesture with a given image and adds it to the current session.

Parameters:
name - the name to give this gesture; cannot be null
imgBuf - the byte array of the image to use as an icon
Returns:
a reference to the new GestureModel for convenience. It has already been added to the Session.
Throws:
IOException - if there was a problem creating an icon from the given byte array

notifyGestureRecognized

public void notifyGestureRecognized(GestureModel g)
Notifies all SessionListeners of a recognition of a gesture g

Parameters:
g - the gesture g (a GestureModel) that was recognized

removeAccel

public boolean removeAccel(int inum,
                           int anum)
Deletes an individual acceleration from the current gesture in the current gesture session at the specified index (assuming the indices are valid).

Parameters:
inum - the index of the gesture instance
anum - the index of the Accel3D to delete
Returns:
signifies the success or failure of deletion

removeAccel

public boolean removeAccel(int snum,
                           int inum,
                           int anum)
Deletes an individual acceleration from the current gesture session at the specified index (assuming the indices are valid).

Parameters:
snum - the index of the gesture set
inum - the index of the gesture instance
anum - the index of the Accel3D to delete
Returns:
a boolean that signifies the success or failure of deletion

removeFilter

public void removeFilter(int i)
Removes a filter at a given index.

Parameters:
i - the index for deletion

removeInstance

public boolean removeInstance(int inum)
Deletes a gesture instance from the current gesture in the current gesture session at the specified index (assuming the index is valid).

Parameters:
inum - the index of the instance to delete
Returns:
a boolean that signifies the success or failure of deletion

removeInstance

public boolean removeInstance(int snum,
                              int inum)
Deletes a gesture instance from current gesture session at the specified index (assuming the index is valid).

Parameters:
snum - the index of the gesture set
inum - the index of the instance to delete
Returns:
a boolean that signifies the success or failure of deletion

removeSessionListener

public void removeSessionListener(SessionListener sl)
Removes a SessionListener from this Session's list of listeners

Parameters:
sl - The SessionListener to remove

removeSet

public boolean removeSet()
Deletes a gesture set from the current gesture session.

Returns:
a boolean that signifies the success or failure of deletion

removeSet

public boolean removeSet(int snum)
Deletes a gesture set from the current gesture session at the specified index (assuming the index is valid).

Parameters:
snum - the index of the gesture set to delete
Returns:
a boolean that signifies the success or failure of deletion

restoreDefaults

public void restoreDefaults()
Restores the default training parameters for this session.


setClassifierType

public void setClassifierType(int type)
Sets the type (an integer - see Classifier) of classifier to be used in the Session.

Parameters:
type - the classifier type

setDevice

public void setDevice(Device d)
               throws IOException
Sets the device for this Session. Setting the Device causes the Session to attempt to connect to it if it isn't connected already. Note that the old Device is not disconnected first.

Parameters:
d - The device to connect to
Throws:
IOException

setGestureIcon

public void setGestureIcon(byte[] imageBuffer)
                    throws IOException
Sets the icon of the current gesture to the one contained in a byte array.

Parameters:
imageBuffer - the byte array containing the data to construct an image for the icon
Throws:
IOException - if an image could not be constructed from the given byte array

setGestureIcon

public boolean setGestureIcon(int index,
                              byte[] imageBuffer)
                       throws IOException
Sets the icon of the specified gesture to the one contained in a byte array.

Parameters:
index - the index of the gesture to modify
imageBuffer - the byte array containing the data to construct an image for the icon
Returns:
true if the index was valid; false otherwise.
Throws:
IOException - if an image could not be constructed from the given byte array

setGestureModelType

public boolean setGestureModelType(int type)
Sets the type (an integer - see GestureModel) of gesture model to be used in the Session. This will modify which gesture session is currently in use. That is, Session can work on multiple different types of GestureModel sessions, but must focus on a single one at a time.

Parameters:
type - the gesture model type
Returns:
a boolean signifying success/failure (fails for an invalid type)

train

public boolean train()
Trains the GestureModel representing the current gesture in the current gesture session. The type of GestureModel constructed depends on the current model type of the Session (as set by setGestureModelType(int). Requires being in training mode.

Returns:
a boolean signifying success/failure of training

train

public boolean train(int index)
Trains the GestureModel at the given index in the current gesture session. Training fails if the index is invalid. The type of GestureModel constructed depends on the current model type of the Session (as set by setGestureModelType(int). Requires being in training mode.

Parameters:
index - the index of the GestureModel to train
Returns:
a boolean signifying success/failure of training

train

public boolean train(int index,
                     GestureHMMParameters gParams)
Trains the GestureHMM at the given index in the current gesture session with the specified parameters. If the current gesture session is not a GestureHMM session, an error will be reported. Training fails if the index is invalid. Requires being in training mode.

Parameters:
index - the index of the GestureHMM to train
gParams - the parameters for the GestureHMM
Returns:
a boolean signifying success/failure of training

train

public boolean train(int index,
                     GestureHMMParameters gParams,
                     KmeansParameters kParams)
Trains the GestureHMM at the given index in the current gesture session with the specified parameters. If the current gesture session is not a GestureHMM session, an error will be reported. Training fails if the index is invalid. Requires being in training mode.

Parameters:
index -
gParams -
Returns:
a boolean signifying success/failure of training

trainAll

public void trainAll()
Trains every GestureModel in the current gesture session.


setName

public void setName(String name)
Sets the name of this Session.

Parameters:
name - the name to give this Session

toString

public String toString()
Overrides:
toString in class Object

unexpectedDisconnect

public void unexpectedDisconnect(Device d)
Description copied from interface: DeviceListener
For handling an unexpected disconnect from a device. This is not called when a user has specified that they wish to disconnect. If a Device has gone out of range or the battery dies, that is an appropriate time to use this.

Common sense would dictate this is a job for Exceptions. However, if a disconnect occurs while idle, it is impossible to throw an exception beyond the Plugin. Devices need a listener to notify when something goes wrong.

Specified by:
unexpectedDisconnect in interface DeviceListener
Parameters:
d - Device that was unexpectedly disconnected