OpenTracker

An Open Architecture for Reconfigurable Tracking based on XML | Contact

MagicYModule.h

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 
00065 #ifndef _MAGICYMODULE_H
00066 #define _MAGICYMODULE_H
00067 
00068 #include "../OpenTracker.h"
00069 #include "MagicYSource.h"
00070 
00071 #include <ace/SOCK_Dgram.h>
00072 #include <ace/SOCK_Connector.h>
00073 #include <ace/INET_Addr.h>
00074 #include <ace/Handle_Set.h>
00075 
00076 #include <vector>
00077 
00078 
00079 #ifndef OT_NO_MAGICY_SUPPORT
00080 
00081 
00082 namespace ot {
00083 
00085     class MagicY
00086     {
00087     public:
00088         int number;    
00089     bool average;
00090         Event event;
00091         int modified;
00092         MagicYSource * source;
00093 
00094         MagicY( const int number_, const bool average_, MagicYSource * source_ ) :
00095             number( number_ ), average( average_ ), modified( 0 ), source( source_ )
00096         {
00097             event.getPosition()[0] = 0;
00098             event.getPosition()[1] = 0;
00099             event.getPosition()[2] = 0;
00100 
00101             event.getOrientation()[0] = 0;
00102             event.getOrientation()[1] = 0;
00103             event.getOrientation()[2] = 0;
00104             event.getOrientation()[3] = 0;
00105 
00106             event.getButton() = 0;
00107             event.getConfidence() = 0.0f;
00108     };
00109     };
00110 
00111     // struct to store points for intermediate processing (prediction, etc.)
00112     struct MagicPoint
00113     {
00114     int x, y;
00115         bool trigger;
00116 
00117     MagicPoint(const int x_, const int y_) : x(x_), y(y_), trigger(0) {};
00118     MagicPoint(const int x_, const int y_, const bool trigger_) : x(x_), y(y_), trigger(trigger_) {};
00119     MagicPoint(const MagicPoint &src) : x(src.x), y(src.y), trigger(src.trigger) {};
00120     };
00121 
00122     // struct to store ports and offsets for data streams for extra screens
00123     struct Screen
00124     {
00125     ACE_SOCK_Stream socket;
00126     ACE_INET_Addr address;
00127     int x_offset, y_offset;
00128     bool connected;
00129 
00130     Screen(const int port_, const std::string hostname_, const int x_offset_, const int y_offset_)
00131     {
00132             address.set((u_short)port_, hostname_.c_str()); 
00133             x_offset = x_offset_; 
00134             y_offset = y_offset_;
00135             connected = false;
00136     };
00137     }; 
00138 
00139     typedef std::vector<MagicY *> MagicYVector;
00140     typedef std::vector<Screen *> ScreenVector;
00141     typedef std::vector<MagicPoint> PointVector;
00142 
00144     const int magicYMaxUnits = 1000;
00145 
00154     class OPENTRACKER_API MagicYModule : public ThreadModule, public NodeFactory
00155     {
00156         // members
00157     protected:    
00158     
00160     MagicYVector magicYs;
00162     PointVector points;
00164     ScreenVector screens;
00166     std::string hostname;
00167 
00168     ACE_SOCK_Connector connector;
00169     ACE_Handle_Set readHandles;
00170 
00171         int stop;
00172     int positionMapping[3];
00173     int invertPosition[3];
00174     float z_value;
00175     float orientation[4];
00176     
00177         // methods
00178     protected:
00179 
00182     int connect();
00183     void setSelect();
00184     int receive();
00185     int stillConnected(); 
00186     void disconnect();
00187     void run();
00188     int parseVector(const std::string & line, int * val);
00189     int parseVector(const std::string & line, float * val);
00190     int parseScreens(const std::string & line);
00191     void initMappping(int *mapping);
00192     void initInversion(int *inversion);
00193     void initOrientation(float *orientation);
00194     void calcInversion(int *inversion);
00195     void calcMapping(int *mapping);
00196     void correctData(std::vector<float> &d, int *mapping, int *inversion);
00197 
00198     public:    
00200         MagicYModule();
00201 
00203         virtual ~MagicYModule();
00209         virtual void init(StringTable& attributes, ConfigNode * localTree);
00217         virtual Node * createNode( const std::string& name,  StringTable& attributes);        
00221         virtual void start();
00225         virtual void close();    
00231         virtual void pushEvent();             
00232     };
00233 
00234 } // namespace ot
00235 
00236 
00237 #endif // OT_NO_MAGICY_SUPPORT
00238 
00239 
00240 #endif
00241 
00242 /* 
00243  * ------------------------------------------------------------
00244  *   End of MagicYModule.h
00245  * ------------------------------------------------------------
00246  *   Automatic Emacs configuration follows.
00247  *   Local Variables:
00248  *   mode:c++
00249  *   c-basic-offset: 4
00250  *   eval: (c-set-offset 'substatement-open 0)
00251  *   eval: (c-set-offset 'case-label '+)
00252  *   eval: (c-set-offset 'statement 'c-lineup-runin-statements)
00253  *   eval: (setq indent-tabs-mode nil)
00254  *   End:
00255  * ------------------------------------------------------------ 
00256  */

copyright (c) 2006 Graz University of Technology