PhantomMiddlewareSink.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 _PHANTOMMIDDLEWARESINK_H
00053 #define _PHANTOMMIDDLEWARESINK_H
00054 
00055 #include <cmath>
00056 
00057 #include <OpenTracker/OpenTracker.h>
00058 #include <OpenTracker/tool/OT_ACE_Log.h>
00059 #include <phantom/MulticastSocket.hh>
00060 #include <phantom/PhantomMessageV1.hh>
00061 
00070 namespace ot {
00071 
00072 class PhantomMiddlewareModule;
00073 
00074 class OPENTRACKER_API PhantomMiddlewareSink : public Node
00075 {
00076 // Members
00077 public:
00079   //OT_CORBA::Node_var corba_sink;
00081     int frequency;
00082     int cycle;
00083     int pid;
00084     unsigned char seq;
00085     short eid;
00086     std::string src;
00087     Phantom::Utils::MulticastSocketSender* mss;
00088     
00089 
00090 // Methods
00091 protected:
00096     PhantomMiddlewareSink( const char* multicast_group, int frequency_, int pid_, short eid_, const std::string& src_) :
00097       Node(), 
00098       frequency( frequency_ ),
00099       pid( pid_ ), 
00100       cycle ( 0 ),
00101       seq ( 0 ),
00102       eid ( eid_ )
00103       {
00104         mss = new Phantom::Utils::MulticastSocketSender(multicast_group);
00105         src = src_;
00106       }
00107     
00108       PhantomMiddlewareSink( const char* multicast_group, int frequency_, int pid_, short eid_):
00109       Node(), 
00110       frequency( frequency_ ),
00111       pid( pid_ ), 
00112       cycle ( 0 ),
00113       seq ( 0 ),
00114       eid ( eid_ )
00115         {
00116         mss = new Phantom::Utils::MulticastSocketSender(multicast_group);
00117         src = "";         
00118         }
00119 
00120     virtual ~PhantomMiddlewareSink() {
00121       delete mss;
00122       logPrintE("PhantomMiddlewareSink destructor\n");
00123     }
00124 
00125 public:
00129     virtual int isEventGenerator()
00130     {
00131       return 1;
00132       //return 0;
00133     }
00134 
00135     int getEventId() {
00136       return eid;
00137     }
00138     
00148     virtual void onEventGenerated( Event& event, Node& generator)
00149     {
00150       cycle++;
00151       if ((cycle % frequency) == 0) {
00152         seq++;
00153         try {
00154           Phantom::PhantomMessageV1 pm(eid, seq);
00155           std::vector<float> position = event.getPosition();
00156           std::vector<float> orientation = event.getOrientation();
00157           float theta = 2.0f *atan2(orientation[1], orientation[3]);
00158           float alpha = MathUtils::Pi - theta;
00159           pm << pid;
00160           pm << (float) position[0];
00161           pm << (float) -position[2];
00162           pm << (float) position[1];
00163           pm << (float) (alpha / MathUtils::GradToRad);
00164           //      if (eid == 24) {
00165           //        pm << src;
00166           //      }
00167           (*mss) << pm;
00168         }
00169         catch (...) {}
00170         updateObservers( event );
00171       }
00172     }
00173  
00174  friend class PhantomMiddlewareModule;
00175 };
00176 
00177 }
00178 
00179 #endif

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