OpenTracker

An Open Architecture for Reconfigurable Tracking based on XML | Contact

UbisenseSource.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 "UbisenseSource.h"
00048 #ifdef USE_UBISENSE
00049 
00050 #ifdef WIN32
00051 #pragma comment(lib,"UClientAPI.lib")
00052 #endif
00053 
00054 namespace ot {
00055 
00056     UbisenseSource::UbisenseSource(const Object &object,const LocationClient &locationClient,DataClient &dataClient): Node(),button(0x0000),lastTime(0.),buttonTime(0.),event(),object(object),locationClient(locationClient),dataClient(dataClient)
00057     {
00058 #ifdef _DEBUG
00059         dataClient.notify(object,NotifyBeep);
00060         dataClient.notify(object,NotifyFlashGreen);
00061 #endif
00062     }
00063 
00064     UbisenseSource::~UbisenseSource()
00065     {
00066 #ifdef _DEBUG
00067         dataClient.notify(object,NotifyBeep);
00068         dataClient.notify(object,NotifyFlashRed);
00069 #endif
00070     }
00071 
00072     bool UbisenseSource::calcEvent()
00073     {
00074         Location location;
00075         MyNameClient client;
00076 
00077         printf("\n");
00078         //std::cout << "Getting all named people:";
00079         UClientAPI::Map<Object,String> all_people = client.get_all_named(Type("Person"));
00080         //for (UClientAPI::Map<Object,String>::const_iterator i = all_people.begin(); i != all_people.end(); ++i)
00081         //{   printf("\n");
00082         //std::cout << " " << (*i).first.to_string() << " has name " << (*i).second << std::endl;
00083         //}
00084 
00085         String found_name;
00086         if (!client.get_object_name(object,found_name))
00087         { std::cout << "Cannot get name of " << object.to_string();
00088           return false;
00089         }
00090         std::cout << "Ubitag name: " << found_name;
00091 
00092         if (locationClient.get_object_location(object,location) && location.time_ > lastTime)
00093         {
00094             event.clearAttributes();
00095             event.getPosition()[0] = static_cast<float>(location.pos_.x_);
00096             event.getPosition()[1] = static_cast<float>(location.pos_.y_);
00097             event.getPosition()[2] = static_cast<float>(location.pos_.z_);
00098 
00099 
00100             printf("\n  location x: %f", event.getPosition()[0]);
00101             printf("\n  location y: %f", event.getPosition()[1]);
00102             printf("\n  location z: %f\n\n", event.getPosition()[2]);
00103 
00104             if (buttonTime > lastTime)
00105             {
00106                 event.getButton() = button;
00107                 button = 0x0000;
00108             }
00109             event.time = (location.time_ > buttonTime ? location.time_: buttonTime) * 1000.;
00110             event.getConfidence() = 1.f;
00111             lastTime = location.time_ > buttonTime ? location.time_: buttonTime;
00112             return true;
00113         }
00114         else
00115             if (buttonTime > lastTime)
00116             {
00117                 event.getButton() = button;
00118                 event.time = buttonTime * 1000.;
00119                 event.getConfidence() = 1.f;
00120                 button = 0x0000;
00121                 lastTime = buttonTime;
00122                 return true;
00123             }
00124         return false;
00125     }
00126 
00127     void UbisenseSource::setButtonEvent(unsigned short button,double time)
00128     {
00129         UbisenseSource::button |= button;
00130         buttonTime = time;
00131     }
00132 
00133 } // namespace ot
00134 
00135 
00136 #else
00137 #pragma message(">>> no Ubisense support")
00138 #endif  // USE_UBISENSE
00139 
00140 /* 
00141  * ------------------------------------------------------------
00142  *   End of UbisenseSource.cxx
00143  * ------------------------------------------------------------
00144  *   Automatic Emacs configuration follows.
00145  *   Local Variables:
00146  *   mode:c++
00147  *   c-basic-offset: 4
00148  *   eval: (c-set-offset 'substatement-open 0)
00149  *   eval: (c-set-offset 'case-label '+)
00150  *   eval: (c-set-offset 'statement 'c-lineup-runin-statements)
00151  *   eval: (setq indent-tabs-mode nil)
00152  *   End:
00153  * ------------------------------------------------------------ 
00154  */

copyright (c) 2006 Graz University of Technology