OpenTracker

An Open Architecture for Reconfigurable Tracking based on XML | Contact

QtMouseEventSinkBase.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  * ======================================================================== */
00045 #include <dllinclude.h>
00046 #if USE_OTQT
00047 
00048 #include "QtMouseEventSinkBase.h"
00049 #include "OTQtLog.h"
00050 
00051 namespace ot {
00052 
00053 //--------------------------------------------------------------------------------
00054 QtMouseEventSinkBase::QtMouseEventSinkBase(StringTable & xml_attrib_table)
00055   : state_(0),
00056     curr_event_(Event::null),
00057     prev_event_(Event::null),
00058     xml_attrib_table_(xml_attrib_table)
00059 {
00060 
00062 
00063   float one_meter = 0.0;
00064   xml_attrib_table.get("TrackingSystemScaleOneMeter", &one_meter);
00065 
00066   // position threshold filter radius
00067   float radius = 0.0;
00068   xml_attrib_table.get("PosThreshRadiusInMeter", &radius);
00069   if (radius > 0) {
00070     POS_THRESH_RADIUS = one_meter * radius;
00071     enableState(POS_THRESH_FILTER, true);
00072   }
00073   OTQT_DEBUG("QtMouseEventSinkBase::QtMouseEventSinkBase(): POS_THRESH_RADIUS = %f\n",
00074              POS_THRESH_RADIUS);
00075 
00076   // orientation threshold filter angle
00077   float angle = 0.0;
00078   xml_attrib_table.get("OrientThreshAngle", &angle);
00079   if (angle != 0) {
00080     MathUtils::eulerToQuaternion(angle, angle, angle, MathUtils::XYZ, ORIENT_THRESH_QUAT);
00081     enableState(ORIENT_THRESH_FILTER, true);
00082   }
00083   OTQT_DEBUG("QtMouseEventSinkBase::QtMouseEventSinkBase(): ORIENT_THRESH_QUAT = %f %f %f %f\n",
00084              ORIENT_THRESH_QUAT[0], ORIENT_THRESH_QUAT[1], ORIENT_THRESH_QUAT[2], ORIENT_THRESH_QUAT[3]);
00085 
00086   // consume event aka global forward lock switch
00087   std::string consume_events_response = xml_attrib_table.get("consume-events");
00088   enableState(CONSUME_EVENTS, ((consume_events_response == "true") ? true : false));
00089   OTQT_DEBUG("QtMouseEventSinkBase::QtMouseEventSinkBase(): StateFlag::CONSUME_EVENTS = %if\n",
00090              (state_ & CONSUME_EVENTS));
00091 }
00092 
00093 //--------------------------------------------------------------------------------
00094 bool QtMouseEventSinkBase::enableState(StateFlag flag, bool enable)
00095 {
00096   if (enable) { state_ |= flag; }
00097   else { state_ &= ~flag; }
00098   return (state_ & flag);
00099 }
00100 
00101 //--------------------------------------------------------------------------------
00102 bool
00103 QtMouseEventSinkBase::isInsidePosThreshSphere(Event const & event) const
00104 {
00105   return (OTQtMath::distance(event.getPosition(), curr_event_.getPosition()) <= POS_THRESH_RADIUS);
00106 }
00107 
00108 //--------------------------------------------------------------------------------
00109 bool
00110 QtMouseEventSinkBase::isInsideOrientThreshCone(Event const & event) const
00111 {
00112   std::vector<float> orient_conj(4);
00113   MathUtils::invertQuaternion(curr_event_.getOrientation(), orient_conj);
00114   std::vector<float> orient_diff(4);
00115   MathUtils::multiplyQuaternion(event.getOrientation(), orient_conj, orient_diff);
00116 
00117   for (int i = 0; i < 4; i++) {
00118     if (fabsf(orient_diff[i]) > fabsf(ORIENT_THRESH_QUAT[i]))
00119       return false;
00120   }
00121   return true;
00122 }
00123 
00124 //--------------------------------------------------------------------------------
00125 void
00126 QtMouseEventSinkBase::acquireEvent(Event const & event)
00127 {
00128   // acquire tracking event
00129   prev_event_ = curr_event_;
00130   curr_event_ = event;
00131   // set pending flag
00132   state_ |= EVENT_PENDING_SIGNAL;
00133 }
00134 
00135 //--------------------------------------------------------------------------------
00136 void QtMouseEventSinkBase::forwardEvent(Event & event)
00137 {
00138     // consume the event
00139     if ((state_ & CONSUME_EVENTS) && (state_ & EVENT_CONSUME_SIGNAL))
00140         return;
00141     // forward the event: pass it to parent nodes
00142     updateObservers(event);
00143 }
00144 
00145 } // namespace ot
00146 
00147 #endif // USE_OTQT
00148 
00149 
00150 /*
00151  * ------------------------------------------------------------
00152  *   End of QtMouseEventSinkBase.cxx
00153  * ------------------------------------------------------------
00154  *   Automatic Emacs configuration follows.
00155  *   Local Variables:
00156  *   mode:c++
00157  *   c-basic-offset: 4
00158  *   eval: (c-set-offset 'substatement-open 0)
00159  *   eval: (c-set-offset 'case-label '+)
00160  *   eval: (c-set-offset 'statement 'c-lineup-runin-statements)
00161  *   eval: (setq indent-tabs-mode nil)
00162  *   End:
00163  * ------------------------------------------------------------
00164  */

copyright (c) 2006 Graz University of Technology