OpenTracker

An Open Architecture for Reconfigurable Tracking based on XML | Contact

UbisenseModule.cxx

Go to the documentation of this file.
00001 /* ========================================================================
00002  * Copyright (c) 2006,
00003  * Institute for Computer Graphics and Vision
00004  * Graz University of Technology
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are
00009  * met:
00010  *
00011  * Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the following disclaimer.
00013  *
00014  * Redistributions in binary form must reproduce the above copyright
00015  * notice, this list of conditions and the following disclaimer in the
00016  * documentation and/or other materials provided with the distribution.
00017  *
00018  * Neither the name of the Graz University of Technology nor the names of
00019  * its contributors may be used to endorse or promote products derived from
00020  * this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00023  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00024  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00025  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00026  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  * ========================================================================
00034  * PROJECT: OpenTracker
00035  * ======================================================================== */
00042 /* ======================================================================= */
00043 
00044 // this will remove the warning 4786
00045 #include "../tool/disable4786.h"
00046 
00047 #include "UbisenseModule.h"
00048 #include "UbisenseSource.h"
00049 #include <iostream>
00050 
00051 #ifdef USE_UBISENSE
00052 
00053 
00054 #include "UClientAPI/name_client.h"
00055 #include "UClientAPI/location_client.h"
00056 
00057 #ifdef WIN32
00058 #pragma comment(lib,"UClientAPI.lib")
00059 #endif
00060 
00061 namespace ot {
00062 
00063     UbisenseModule::UbisenseModule(): Module(),NodeFactory(),locationClient(),dataClient(pSources),cells(locationClient.get_all_cells())
00064         //UbisenseModule::UbisenseModule(): Module(),NodeFactory(),locationClient(),dataClient(pSources)
00065     {
00066     // all lines from Gerhard for testing
00067     //String cell_name; 
00068     //UClientAPI::Set<String> tmpCells = locationClient.get_all_cells();
00069 
00070     //std::set<std::string> myCells;
00071 
00072     //cells.insert(tmpCells.begin(), tmpCells.end());
00073 
00074     
00075         /*
00076           std::cout << "detected location cell: ";
00077           for (UClientAPI::Set<String>::const_iterator i = cells.begin(); i != cells.end(); ++i) 
00078           {   std::cout << " " << *i; 
00079           }
00080           if (cells.empty()) 
00081           {   std::cout << "No available cells"; 
00082           }
00083         */
00084     //cell_name = *(cells.begin()); 
00085     //std::cout << "Loading cell " << cell_name;
00086     //std::cout << "  ";
00087     }
00088 
00089     UbisenseModule::~UbisenseModule()
00090     {
00091         for (NodeVector::iterator it = pSources.begin();it != pSources.end();it ++)
00092             delete *it;
00093         pSources.clear();
00094     }
00095 
00096     Node* UbisenseModule::createNode(const std::string &name,StringTable &attributes)
00097     {
00098         if (name.compare("UbisenseSource") == 0)
00099         {
00100             NameClient nameClient;
00101             Object object;
00102             const char* objectString =    attributes.get("object").c_str();
00103             UClientAPI::String str(objectString);
00104             if (nameClient.get_named_object(objectString,object))
00105             {
00106                 UbisenseSource* pSource = new UbisenseSource(object,locationClient,dataClient);
00107                 pSources.push_back(pSource);
00108             return pSource;
00109             }
00110         }
00111         return NULL;
00112     }
00113 
00114     void UbisenseModule::start()
00115     {
00116     for (UClientAPI::Set<String>::const_iterator i = cells.begin();i != cells.end();++ i)
00117             locationClient.load_cell(*i);
00118 
00119         //  for (std::set<std::string>::const_iterator i = cells.begin();i != cells.end();++ i)
00120         //      locationClient.load_cell(i->c_str());
00121 
00122     }
00123 
00124     void UbisenseModule::close()
00125     {
00126     locationClient.unload_all_cells();
00127     }
00128 
00129     void UbisenseModule::pushEvent()
00130     {
00131         for (NodeVector::iterator it = pSources.begin();it != pSources.end();it ++)
00132         {
00133             UbisenseSource* pSource = reinterpret_cast<UbisenseSource*>(*it);
00134             if (pSource->calcEvent())
00135                 pSource->updateObservers(pSource->getEvent());
00136         }
00137     }
00138 
00139     void UbisenseModule::init(StringTable &attributes,ConfigNode* pLocalTree)
00140     {
00141     NameClient nameClient;
00142     Object object;
00143 
00144     cells.clear();
00145     for (unsigned int i = 0;i < pLocalTree->countChildren();i ++)
00146     {
00147             ConfigNode* pNode = reinterpret_cast<ConfigNode*>(pLocalTree->getChild(i));
00148             if (! pNode->getType().compare("UbisenseCell"))
00149             {
00150                 ot::StringTable& attributes = pNode->getAttributes(); //Gerhard
00151                 std::string str = attributes.get("name");             //Gerhard   
00152                 //cells.insert(pNode->getAttributes().get("name").c_str());
00153                 cells.insert(str.c_str()); //Gerhard
00154 
00155 
00156                 std::cout << "ot location cell: ";
00157                 for (UClientAPI::Set<String>::const_iterator i = cells.begin(); i != cells.end(); ++i) 
00158                     //          for (std::set<std::string>::const_iterator i = cells.begin();i != cells.end();++ i)
00159                 {   std::cout << " " << *i << std::endl; 
00160                 }
00161                 if (cells.empty()) 
00162                 {   std::cout << "No available cells" << std::endl; 
00163                 }
00164 
00165                 //cell_name = *(cells.begin()); 
00166                 //std::cout << "Loading cell " << cell_name;
00167                 std::cout << "  ";
00168 
00169             }
00170     }
00171     }
00172 
00173 
00174     UbisenseModule::WrappedDataClient::WrappedDataClient(NodeVector &pSources): DataClient(),pSources(pSources)
00175     {
00176     }
00177 
00178     void UbisenseModule::WrappedDataClient::on_button(const Object &tag,UbitagButton button,double time)
00179     {
00180     Object owner;
00181     get_tag_owner(tag,owner);
00182         for (NodeVector::iterator it = pSources.begin();it != pSources.end();it ++)
00183         {
00184             UbisenseSource* pSource = reinterpret_cast<UbisenseSource*>(*it);
00185             const Object &object = pSource->getObject();
00186             if (tag == object || owner == object)
00187                 pSource->setButtonEvent(button == Orange ? 0x0001: button == Blue ? 0x0002: 0x0000,time);
00188     }
00189     }
00190 
00191 } // namespace ot
00192 
00193 
00194 #else
00195 #pragma message(">>> no Ubisense support")
00196 #endif  // USE_UBISENSE
00197 
00198 /* 
00199  * ------------------------------------------------------------
00200  *   End of UbisenseModule.cxx
00201  * ------------------------------------------------------------
00202  *   Automatic Emacs configuration follows.
00203  *   Local Variables:
00204  *   mode:c++
00205  *   c-basic-offset: 4
00206  *   eval: (c-set-offset 'substatement-open 0)
00207  *   eval: (c-set-offset 'case-label '+)
00208  *   eval: (c-set-offset 'statement 'c-lineup-runin-statements)
00209  *   eval: (setq indent-tabs-mode nil)
00210  *   End:
00211  * ------------------------------------------------------------ 
00212  */

copyright (c) 2006 Graz University of Technology