Bläddra i källkod

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/etri-smartspaces

Daniel Kauth 11 år sedan
förälder
incheckning
1f85f223e6
2 ändrade filer med 68 tillägg och 14 borttagningar
  1. 36 10
      bbiwarg/Server/TUIO/TuioServer.cs
  2. 32 4
      bbiwarg/VideoHandle.cs

+ 36 - 10
bbiwarg/Server/TUIO/TuioServer.cs

@@ -13,25 +13,34 @@ namespace TUIO
     {
         const int MAX_PACKET_SIZE = 65535 - 8;
 
-        OSCTransmitter transmitter = null;
-        String host = "127.0.0.1";
-        int port = 3333;
+        private OSCTransmitter transmitter = null;
+        private String host = "127.0.0.1";
+        private int port = 3333;
+        private long sessionID = 0;
+        private TuioTime currentFrameTime;
 
-        List<TuioCursor> cursorList = new List<TuioCursor>();
-        List<TuioCursor> updatedCursorList;
+        private List<TuioCursor> cursorList;
+        private List<TuioCursor> updatedCursorList;
 
-        public TuioServer() { transmitter = new OSCTransmitter(host, port); }
+        public TuioServer() { init(); }
 
         public TuioServer(int port)
         {
             this.port = port;
-            transmitter = new OSCTransmitter(host, port);
+            init();
         }
 
         public TuioServer(String host, int port)
         {
             this.host = host;
             this.port = port;
+            init();
+        }
+
+        private void init()
+        {
+            TuioTime.initSession();
+            cursorList = new List<TuioCursor>();
             transmitter = new OSCTransmitter(host, port);
         }
 
@@ -43,19 +52,35 @@ namespace TUIO
 
         public TuioCursor addTuioCursor(float x, float y)
         {
-            TuioCursor tcur = new TuioCursor(cursorList.Count, cursorList.Count, x, y);
+            TuioCursor tcur = new TuioCursor(sessionID, cursorList.Count, x, y);
             cursorList.Add(tcur);
             updatedCursorList.Add(tcur);
+
+            sessionID++;
             return tcur;
         }
 
         public void updateTuioCursor(TuioCursor tcur, float xp, float yp)
         {
-            tcur.update(new TuioTime(0, 0), xp, yp);
+            tcur.update(currentFrameTime, xp, yp);
             if (!updatedCursorList.Contains(tcur))
                 updatedCursorList.Add(tcur);
         }
 
+        public void updateTuioCursor(long s_id, float xp, float yp)
+        {
+            TuioCursor tcur;
+            for (int i = 0; i < cursorList.Count; i++)
+            {
+                tcur = cursorList[i];
+                if (tcur.getSessionID() == s_id)
+                {
+                    updateTuioCursor(tcur, xp, yp);
+                    return;
+                }
+            }
+        }
+
         public void removeTuioCursor(TuioCursor tcur)
         {
             cursorList.Remove(tcur);
@@ -64,6 +89,7 @@ namespace TUIO
 
         public void initFrame()
         {
+            currentFrameTime = TuioTime.getSessionTime();
             updatedCursorList = new List<TuioCursor>();
         }
 
@@ -91,7 +117,7 @@ namespace TUIO
                 currentMessage.Append("set");
                 currentMessage.Append((int)cursor.getSessionID());
                 currentMessage.Append((float)cursor.getX());
-                currentMessage.Append((float)cursor.getY()); 
+                currentMessage.Append((float)cursor.getY());
                 currentMessage.Append((float)cursor.getXSpeed());
                 currentMessage.Append((float)cursor.getYSpeed());
                 currentMessage.Append((float)cursor.getMotionAccel());

+ 32 - 4
bbiwarg/VideoHandle.cs

@@ -15,6 +15,7 @@ using bbiwarg.InputProviders;
 using Emgu.CV;
 using Emgu.CV.Structure;
 using bbiwarg.Graphics;
+using TUIO;
 
 namespace bbiwarg
 {
@@ -23,6 +24,9 @@ namespace bbiwarg
         private IInputProvider inputProvider;
         private InputFrame inputFrame;
 
+        private TuioServer server;
+        private TuioCursor currentTouchevent;
+
         public int Width { get; private set; }
         public int Height { get; private set; }
 
@@ -54,7 +58,7 @@ namespace bbiwarg
 
         private TouchEventVisualizer touchEventVisualizer;
 
-        private int videoFrame = 0;
+        private int videoFrame = 1;
 
         public VideoHandle(IInputProvider inputProvider)
         {
@@ -64,6 +68,7 @@ namespace bbiwarg
         public void start()
         {
             palmDetector = new PalmDetector();
+            server = new TuioServer("127.0.0.1", 3333);
 
             inputProvider.init();
             inputProvider.start();
@@ -74,6 +79,7 @@ namespace bbiwarg
         public void stop()
         {
             inputProvider.stop();
+            server.close();
         }
 
         public bool sourceIsMovie()
@@ -120,7 +126,7 @@ namespace bbiwarg
         {
             Timer.start("processFrameUpdate");
 
-            if (CurrentFrame == 0) {
+            if (CurrentFrame == 1) {
                 //initialize trackers
                 touchTracker = new TouchTracker();
                 fingerTracker = new FingerTracker();
@@ -184,7 +190,7 @@ namespace bbiwarg
 
             //detect palm
             Timer.start("palmDetection");
-            if (CurrentFrame == 0)
+            if (CurrentFrame == 1)
                 palmDetector.reset();
             palmDetector.findPalmQuad(OutputImages[3], handDetector.Hands);
             Timer.stop("palmDetection");
@@ -201,10 +207,32 @@ namespace bbiwarg
             touchTracker.setDetectedTouchEventsThisFrame(touchDetector.TouchEvents, OutputImages[3]);
             Timer.stop("touchTracking");
 
+
+            //send touchevent
+            if (palmTouchDetector != null)
+            {
+                server.initFrame();
+                if (palmTouchDetector.PalmTouchEvents.Count == 1)
+                {
+                    PalmTouchEvent touchEvent = palmTouchDetector.PalmTouchEvents[0];
+                    if (currentTouchevent == null)
+                        currentTouchevent = server.addTuioCursor(touchEvent.RelativePalmPosition.X, touchEvent.RelativePalmPosition.Y);
+                    else
+                        server.updateTuioCursor(currentTouchevent, touchEvent.RelativePalmPosition.X, touchEvent.RelativePalmPosition.Y);
+                }
+                else if (currentTouchevent != null)
+                {
+                    server.removeTuioCursor(currentTouchevent);
+                    currentTouchevent = null;
+                }
+                server.commitFrame();
+            }
+
+
             // touch event visualizer
             if (touchEventVisualizer == null)
                 touchEventVisualizer = new TouchEventVisualizer(Width, Height);
-            if (CurrentFrame == 0)
+            if (CurrentFrame == 1)
                 touchEventVisualizer.Reset();
             if (palmTouchDetector != null)
             {