PhantomMiddlewareSource.h

Go to the documentation of this file.
00001 /* ======================================================================== 
00002  * Copyright (C) 2006  Graz University of Technology
00003  *
00004  * This framework is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This framework is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this framework; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  * For further information please contact 
00019  * Dieter Schmalstieg
00020  * <schmalstieg@icg.tu-graz.ac.at>
00021  * Graz University of Technology, 
00022  * Institut for Computer Graphics and Vision,
00023  * Inffeldgasse 16a, 8010 Graz, Austria.
00024  * ========================================================================
00025  * PROJECT: OpenTracker
00026  * ======================================================================== */
00033  /* ======================================================================= */
00034 
00052 #ifndef _PHANTOMMIDDLEWARESOURCE_H
00053 #define _PHANTOMMIDDLEWARESOURCE_H
00054 
00055 #include <cmath>
00056 
00057 #include <OpenTracker/OpenTracker.h>
00058 #include <OpenTracker/tool/OT_ACE_Log.h>
00059 #include <ace/Thread_Mutex.h>
00060 #include <phantom/MulticastSocket.hh>
00061 #include <phantom/PhantomMessageV1.hh>
00062 
00071 namespace ot {
00072 
00073 class PhantomMiddlewareModule;
00074 
00075 class OPENTRACKER_API PhantomMiddlewareSource : public Node
00076 {
00077 // Members
00078 public:
00081   Event event;
00082 
00083   int pid;
00084   short eid;
00085   std::string source;
00086   //Phantom::Utils::MulticastSocketReceiver* msr;
00087     
00088 
00089   // Methods
00090 protected:
00094   PhantomMiddlewareSource( const char* multicast_group, int pid_, short eid_, const std::string& source_) :
00095     Node(), 
00096     pid( pid_ ), 
00097     eid( eid_ ),
00098     source( source_ )
00099       {
00100         mu = new ACE_Thread_Mutex("phantommiddlewaresource");
00101       }
00102 
00103     
00104     PhantomMiddlewareSource( const char* multicast_group, int pid_, short eid_) :
00105     Node(), 
00106     pid( pid_ ), 
00107     eid( eid_ )
00108       {
00109         mu = new ACE_Thread_Mutex("phantommiddlewaresource");
00110         source = "";
00111       }
00112       
00113 
00114     virtual ~PhantomMiddlewareSource() {
00115       //delete msr;
00116       delete mu;
00117       logPrintE("PhantomMiddlewareSource destructor\n");
00118     }
00119 private:
00120     ACE_Thread_Mutex* mu;
00121     bool modified;
00122     
00123 public:
00124     void lock() { mu->acquire(); };
00125     void unlock() { mu->release(); };
00126     bool isModified() {return modified;};
00127     void setEvent(float x, float y, float z, float theta, int t1, int t2, short event_id, char* event_source) {
00128       //      if ( (event_id == eid) && strcmp(event_source, source) ) {
00129       setEvent(x, y, z, theta, t1, t2, event_id);
00130       //      }
00131     };
00132 
00133     void setEvent(float x, float y, float z, float alpha, int t1, int t2, short event_id) {
00134       //      if ( (event_id == eid) && strcmp(event_source, source) ) {
00135         std::vector<float> position(3);
00136         std::vector<float> orientation(4);
00137         position[0] = x; position[1] =  z; position[2] = -y;
00138         float theta    = 180.0f - alpha; 
00139         float thetaby2 = theta * MathUtils::GradToRad / 2.0;
00140         orientation[0] = 0.0;
00141         orientation[1] = sin(thetaby2);
00142         orientation[2] = 0.0; 
00143         orientation[3] = cos(thetaby2);
00144         lock();
00145         event.setPosition(position);
00146         event.setOrientation(orientation);
00147         event.time = (double) t1 + ((double) t2)/1000000.0;
00148         modified=true;
00149         unlock();
00150         //      }
00151     };
00152 
00153 
00154     int getEventId() {
00155       return eid;
00156     }
00157 
00158     void push()
00159     {
00160       lock();
00161       if (modified) {
00162         updateObservers( event );
00163         modified = false;
00164       } 
00165       unlock();
00166     }
00170     virtual int isEventGenerator()
00171     {
00172       return 1;
00173     }
00174     
00175     friend class PhantomMiddlewareModule;
00176     friend class PhantomListener;
00177 };
00178 
00179 }
00180 
00181 #endif

Generated on Wed Feb 28 15:18:51 2007 for NaviTrack by  doxygen 1.4.6