00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
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
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
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
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 OT_MODULE(MagicYModule);
00234
00235
00236 }
00237
00238
00239 #endif // OT_NO_MAGICY_SUPPORT
00240
00241
00242 #endif
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258