SimGloveGesture.cpp

Go to the documentation of this file.
00001 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00002  *
00003  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Christopher Just,
00007  *   Patrick Hartling, Kevin Meinert,
00008  *   Carolina Cruz-Neira, Albert Baker
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Library General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Library General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Library General Public
00021  * License along with this library; if not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023  * Boston, MA 02111-1307, USA.
00024  *
00025  * -----------------------------------------------------------------
00026  * File:          $RCSfile$
00027  * Date modified: $Date: 2005-01-01 14:59:16 -0600 (Sat, 01 Jan 2005) $
00028  * Version:       $Revision: 16524 $
00029  * -----------------------------------------------------------------
00030  *
00031  *************** <auto-copyright.pl END do not edit this line> ***************/
00032 
00033 #include <gadget/gadgetConfig.h>
00034 
00035 #include <fstream>
00036 #include <vpr/Util/FileUtils.h>
00037 #include <jccl/Config/ConfigElement.h>
00038 #include <gadget/Util/Debug.h>
00039 #include <gadget/Devices/Sim/SimGloveGesture.h>
00040 
00041 
00042 namespace gadget
00043 {
00044 
00045 std::string SimGloveGesture::getElementType()
00046 {
00047    return "simulated_glove_gesture";
00048 }
00049 
00057 bool SimGloveGesture::config(jccl::ConfigElementPtr element)
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 }
00114 
00123 const DigitalData SimGloveGesture::getDigitalData(int devNum)
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 }
00148 
00153 int SimGloveGesture::getGesture()
00154 { return mCurGesture; }
00155 
00161 void SimGloveGesture::updateData()
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             << "gadget::SimGloveGesture: 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 }
00182 
00187 void SimGloveGesture::loadTrainedFile(std::string fileName)
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 }
00203 
00204 } // End of gadget namespace

Generated on Thu Jan 4 10:41:56 2007 for Gadgeteer by  doxygen 1.5.1