Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

gadget::SimGloveGesture Class Reference

Simulated glove class. More...

#include <SimGloveGesture.h>

Inheritance diagram for gadget::SimGloveGesture:

Inheritance graph
[legend]
Collaboration diagram for gadget::SimGloveGesture:

Collaboration graph
[legend]
List of all members.

Public Methods

 SimGloveGesture ()
 Constructs a SimGloveGesture. More...

virtual bool config (jccl::ConfigElementPtr element)
 Constructs the SimGloveGesture. More...

virtual int getGesture ()
 Gets the current gesture. More...

virtual const DigitalData getDigitalData (int devNum=0)
 Gets the digital data for the given devNum. More...

void loadTrainedFile (std::string fileName)
 Loads trained data for the gesture object. More...

bool startSampling ()
 Start a device sampling. More...

bool stopSampling ()
 StopSampling. More...

bool sample ()
 Sample the device. More...

void updateData ()
 Updates the device data. More...

void saveTrainedFile (std::string fileName)
 Saves a trained data file for the gesture object. More...

void loadSamplesFile (std::string filename)
 Loads the sample training data specified. More...

void saveSamplesFile (std::string filename)
 Saves the sample training data specified. More...

void clearSamples (int gestureId=-1)
 Clears the samples that we have taken so far. More...

void addSample (int gestureId)
 Adds a new sample of the given gesture to the training data. More...

void train ()
 This actually starts the training on the given data. More...

void operator delete (void *p)
 Invokes the global scope delete operator. More...


Static Public Methods

std::string getElementType ()
 Returns the string rep of the element type used to config this device. More...


Protected Methods

virtual void destroy ()
 Deletes this object. More...


Detailed Description

Simulated glove class.

This class simulates a gesture input device. By default the glove is in gesture 0.

Definition at line 53 of file SimGloveGesture.h.


Constructor & Destructor Documentation

gadget::SimGloveGesture::SimGloveGesture   [inline]
 

Constructs a SimGloveGesture.

Definition at line 58 of file SimGloveGesture.h.

00058 {;}


Member Function Documentation

bool gadget::SimGloveGesture::config jccl::ConfigElementPtr    element [virtual]
 

Constructs the SimGloveGesture.

Set the keyboard key pairs. Load the sample file. Trim the smallest so they are same length. Find/Set pos proxy for glove.

Reimplemented from gadget::SimInput.

Definition at line 57 of file SimGloveGesture.cpp.

References gadgetDBG_INPUT_MGR, gadget::GloveGesture::getNumGestures, loadTrainedFile, and gadget::SimInput::readKeyList.

00058 {
00059    if((!GloveGesture::config(element)) || (!SimInput::config(element)))
00060    {
00061       return false;
00062    }
00063 
00064    mCurGesture = 0;     // We are in no gesture yet
00065 
00066    std::vector<jccl::ConfigElementPtr> key_list;
00067    int key_count = element->getNum("key_pair");
00068    for ( int i = 0; i < key_count; ++i )
00069    {
00070       key_list.push_back(element->getProperty<jccl::ConfigElementPtr>("key_pair", i));
00071    }
00072    mSimKeys = readKeyList(key_list);
00073 
00074    // Get sample filename
00075    std::string sample_file = element->getProperty<std::string>("trained_filename");
00076    loadTrainedFile(vpr::replaceEnvVars(sample_file));
00077 
00078    // Trim the lengths
00079    unsigned int num_gestures = getNumGestures();
00080    while(num_gestures < mSimKeys.size())     // If we have to many keys
00081    {
00082       mSimKeys.pop_back();
00083       vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
00084          << "gadget::SimGloveGesture: Not enough gestures. Trimming"
00085          << std::endl << vprDEBUG_FLUSH;
00086    }
00087 
00088    // Find pos proxy
00089    std::string glove_pos_proxy = element->getProperty<std::string>("glove_position");    // Get the name of the pos_proxy
00090    if(glove_pos_proxy == std::string(""))
00091    {
00092       vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
00093          << clrOutNORM(clrRED, "ERROR:") << " SimGloveGesture has no posProxy."
00094          << std::endl << vprDEBUG_FLUSH;
00095       return false;
00096    }
00097    // init glove proxy interface
00098    /*
00099    int proxy_index = Kernel::instance()->getInputManager()->getProxyIndex(glove_pos_proxy);
00100    if(proxy_index != -1)
00101       mGlovePos[0] = Kernel::instance()->getInputManager()->getPosProxy(proxy_index);
00102    else
00103       vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
00104          << clrOutNORM(clrRED, "ERROR:")
00105          << " SimGloveGesture::CyberGlove: Can't find posProxy."
00106          << std::endl << std::endl << vprDEBUG_FLUSH;
00107    */
00108 
00109    // Set the indexes to defaults
00110    //resetIndexes();
00111 
00112    return true;
00113 }

int gadget::SimGloveGesture::getGesture   [virtual]
 

Gets the current gesture.

Returns:
id of current gesture.

Implements gadget::Gesture.

Definition at line 153 of file SimGloveGesture.cpp.

00154 { return mCurGesture; }

const DigitalData gadget::SimGloveGesture::getDigitalData int    devNum = 0 [virtual]
 

Gets the digital data for the given devNum.

Returns digital 0 or 1, if devNum makes sense. Returns -1 if function fails or if devNum is out of range.

Note:
If devNum is out of range, function will fail, possibly issueing an error to a log or console - but will not ASSERT.

Reimplemented from gadget::Digital.

Definition at line 123 of file SimGloveGesture.cpp.

00124 {
00125    int openLookupTable[] = { 0,0,0,0,0,-1,0,0,0,0,0 };
00126    int closedLookupTable[] = { 1,1,1,1,1,-1,1,1,1,1,1 };
00127    int pointingLookupTable[] = { 1,1,1,0,1,-1,1,1,1,0,1 };
00128    switch (mCurGesture)
00129    {
00130       case 0:
00131          //open
00132          mDigitalData = openLookupTable[devNum];
00133          break;
00134       case 1:
00135          //closed
00136          mDigitalData = closedLookupTable[devNum];
00137          break;
00138       case 2:
00139          // pointing
00140          mDigitalData = pointingLookupTable[devNum];
00141          break;
00142       default:
00143          mDigitalData = openLookupTable[devNum];
00144          break;
00145    }
00146    return mDigitalData;
00147 }

void gadget::SimGloveGesture::loadTrainedFile std::string    fileName [virtual]
 

Loads trained data for the gesture object.

Loads the file for trained data.

Implements gadget::Gesture.

Definition at line 187 of file SimGloveGesture.cpp.

References gadgetDBG_INPUT_MGR, and gadget::GloveGesture::loadFileHeader.

Referenced by config.

00188 {
00189    std::ifstream inFile(fileName.c_str());
00190 
00191    if(inFile)
00192    {
00193       this->loadFileHeader(inFile);
00194       inFile.close();                     // Close the file
00195    }
00196    else
00197    {
00198       vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
00199          << "gadget::SimGloveGesture:: Can't load trained file: "
00200          << fileName.c_str() << std::endl << vprDEBUG_FLUSH;
00201    }
00202 }

bool gadget::SimGloveGesture::startSampling   [inline, virtual]
 

Start a device sampling.

Start the device sampling, normally this will spawn a thread which will just repeatedly call Sample(). This function should return true when it sucessfully starts, false otherwise.

Implements gadget::Input.

Definition at line 76 of file SimGloveGesture.h.

00076 { return 1; }

bool gadget::SimGloveGesture::stopSampling   [inline, virtual]
 

StopSampling.

Reverse the effects of StartSampling().

Implements gadget::Input.

Definition at line 77 of file SimGloveGesture.h.

00077 { return 1; }

bool gadget::SimGloveGesture::sample   [inline, virtual]
 

Sample the device.

Read the next set of input. This method is normally used internally by threaded drivers to repetively sample data in a separate thread. (This new data is not accessable until UpdateData is called)

Implements gadget::Input.

Definition at line 78 of file SimGloveGesture.h.

00078 { return 1; }

void gadget::SimGloveGesture::updateData   [virtual]
 

Updates the device data.

Get the gesture id. Set the glove params.

Implements gadget::Input.

Definition at line 161 of file SimGloveGesture.cpp.

00162 {
00163 /*  TEMPORARILY REMOVE
00164    // Get the current gesture
00165    for(unsigned int i=0;i<mSimKeys.size();i++)
00166    {
00167       if(checkKeyPair(mSimKeys[i]) > 0)
00168       {
00169          mCurGesture = i;
00170          vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
00171             << "vjSimGloveGesture: Got gesture: "
00172             << getGestureString(mCurGesture).c_str()
00173             << std::endl << vprDEBUG_FLUSH;
00174 
00175          // Set the glove to the sample
00176          mTheData[0][current] = mGestureExamples[mCurGesture];    // Copy over the example
00177          mTheData[0][current].calcXforms();                       // Update the xform data
00178       }
00179    }
00180 */
00181 }

std::string gadget::SimGloveGesture::getElementType   [static]
 

Returns the string rep of the element type used to config this device.

This string is used by the device factory to look up device drivers based up the type of element it is trying to load.

Reimplemented from gadget::Input.

Definition at line 45 of file SimGloveGesture.cpp.

00046 {
00047    return "simulated_glove_gesture";
00048 }

void gadget::SimGloveGesture::saveTrainedFile std::string    fileName [inline, virtual]
 

Saves a trained data file for the gesture object.

Implements gadget::Gesture.

Definition at line 86 of file SimGloveGesture.h.

00087    {
00088       boost::ignore_unused_variable_warning(fileName);
00089    }

void gadget::SimGloveGesture::loadSamplesFile std::string    filename [inline, virtual]
 

Loads the sample training data specified.

This file contains previous samples for the gesture recognizer to train from.

Implements gadget::Gesture.

Definition at line 91 of file SimGloveGesture.h.

00092    {
00093       boost::ignore_unused_variable_warning(filename);
00094    }

void gadget::SimGloveGesture::saveSamplesFile std::string    filename [inline, virtual]
 

Saves the sample training data specified.

This data can be loaded at a later time to do more sample training.

Implements gadget::Gesture.

Definition at line 96 of file SimGloveGesture.h.

00097    {
00098       boost::ignore_unused_variable_warning(filename);
00099    }

void gadget::SimGloveGesture::clearSamples int    gestureId = -1 [inline, virtual]
 

Clears the samples that we have taken so far.

Parameters:
gestureId  = -1 (default) then we clear all gestures else we clear only the gesture that is specified.

Implements gadget::Gesture.

Definition at line 101 of file SimGloveGesture.h.

00102    {
00103       boost::ignore_unused_variable_warning(gestureId);
00104    }

void gadget::SimGloveGesture::addSample int    gestureId [inline, virtual]
 

Adds a new sample of the given gesture to the training data.

Implements gadget::Gesture.

Definition at line 106 of file SimGloveGesture.h.

00107    {
00108       boost::ignore_unused_variable_warning(gestureId);
00109    }

void gadget::SimGloveGesture::train   [inline, virtual]
 

This actually starts the training on the given data.

Implements gadget::Gesture.

Definition at line 111 of file SimGloveGesture.h.

00111 { ; }

void gadget::SimGloveGesture::operator delete void *    p [inline]
 

Invokes the global scope delete operator.

This is required for proper releasing of memory in DLLs on Win32.

Definition at line 117 of file SimGloveGesture.h.

00118    {
00119       ::operator delete(p);
00120    }

virtual void gadget::SimGloveGesture::destroy   [inline, protected, virtual]
 

Deletes this object.

This is an implementation of the pure virtual gadget::Input::destroy() method.

Implements gadget::Input.

Definition at line 127 of file SimGloveGesture.h.

00128    {
00129       delete this;
00130    }


The documentation for this class was generated from the following files:
Generated on Sun May 2 14:26:50 2004 for Gadgeteer by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002