Jelajahi Sumber

documented TUIO

Daniel Kauth 10 tahun lalu
induk
melakukan
b033549b27
2 mengubah file dengan 159 tambahan dan 10 penghapusan
  1. 116 10
      bbiwarg/TUIO/TUIO/TuioServer.cs
  2. 43 0
      bbiwarg/TUIO/TuioCommunicator.cs

+ 116 - 10
bbiwarg/TUIO/TUIO/TuioServer.cs

@@ -11,30 +11,85 @@ using bbiwarg.Utility;
 
 namespace TUIO
 {
+    /// <summary>
+    /// Tuio server class to send tuio cursors and objects to tuio clients.
+    /// </summary>
     class TuioServer
     {
+        /// <summary>
+        /// the maximum packet size
+        /// </summary>
         const int MAX_PACKET_SIZE = 65535 - 8;
 
+
+        /// <summary>
+        /// transmitter to send packages over udp
+        /// </summary>
         private OSCTransmitter transmitter = null;
+
+        /// <summary>
+        /// server ip address
+        /// </summary>
         private String host = "127.0.0.1";
+
+        /// <summary>
+        /// server port
+        /// </summary>
         private int port = 3333;
+
+        /// <summary>
+        /// tuio session id
+        /// </summary>
         private long sessionID = 0;
+
+        /// <summary>
+        /// current tuio time
+        /// </summary>
         private TuioTime currentFrameTime;
 
+
+        /// <summary>
+        /// list of generated cursors
+        /// </summary>
         private List<TuioCursor> cursorList;
+
+        /// <summary>
+        /// list of cursors updated in the current frame
+        /// </summary>
         private List<TuioCursor> updatedCursorList;
 
+
+        /// <summary>
+        /// list of all generated objects
+        /// </summary>
         private List<TuioObject> objectList;
+
+        /// <summary>
+        /// list of objects updated in the current frame
+        /// </summary>
         private List<TuioObject> updatedObjectList;
 
+
+        /// <summary>
+        /// Creates a tuio server with default ip and port.
+        /// </summary>
         public TuioServer() { init(); }
 
+        /// <summary>
+        /// Creates a tuio server with default ip.
+        /// </summary>
+        /// <param name="port">server port</param>
         public TuioServer(int port)
         {
             this.port = port;
             init();
         }
 
+        /// <summary>
+        /// Creates a tuio server.
+        /// </summary>
+        /// <param name="host">server ip</param>
+        /// <param name="port">server port</param>
         public TuioServer(String host, int port)
         {
             this.host = host;
@@ -42,6 +97,9 @@ namespace TUIO
             init();
         }
 
+        /// <summary>
+        /// Initializes the server, cursors and objects.
+        /// </summary>
         private void init()
         {
             TuioTime.initSession();
@@ -50,12 +108,20 @@ namespace TUIO
             transmitter = new OSCTransmitter(host, port);
         }
 
-
+        /// <summary>
+        /// Closes the transmission.
+        /// </summary>
         public void close()
         {
             transmitter.Close();
         }
 
+        /// <summary>
+        /// Adds and returns a tuio cursor.
+        /// </summary>
+        /// <param name="xp">x position of the cursor</param>
+        /// <param name="yp">y position of the cursor</param>
+        /// <returns>the added cursor</returns>
         public TuioCursor addTuioCursor(float xp, float yp)
         {
             TuioCursor tcur = new TuioCursor(sessionID, cursorList.Count, xp, yp);
@@ -66,6 +132,12 @@ namespace TUIO
             return tcur;
         }
 
+        /// <summary>
+        /// Updates a tui cursor.
+        /// </summary>
+        /// <param name="tcur">the cursor to update</param>
+        /// <param name="xp">new x position</param>
+        /// <param name="yp">new y position</param>
         public void updateTuioCursor(TuioCursor tcur, float xp, float yp)
         {
             tcur.update(currentFrameTime, xp, yp);
@@ -73,11 +145,22 @@ namespace TUIO
                 updatedCursorList.Add(tcur);
         }
 
+        /// <summary>
+        /// Removes a tuio cursor.
+        /// </summary>
+        /// <param name="tcur">the cursor to remove</param>
         public void removeTuioCursor(TuioCursor tcur)
         {
             cursorList.Remove(tcur);
         }
 
+        /// <summary>
+        /// Adds and returns tuio object.
+        /// </summary>
+        /// <param name="xp">x position of the object</param>
+        /// <param name="yp">y position of the object</param>
+        /// <param name="angle">angle of the object</param>
+        /// <returns>the added object</returns>
         public TuioObject addTuioObject(float xp, float yp, float angle)
         {
             TuioObject tobj = new TuioObject(sessionID, objectList.Count, xp, yp, angle);
@@ -88,6 +171,12 @@ namespace TUIO
             return tobj;
         }
 
+        /// <summary>
+        /// Updates a tuio object.
+        /// </summary>
+        /// <param name="tobj">the object to update</param>
+        /// <param name="xp">new x position</param>
+        /// <param name="yp">new y position</param>
         public void updateTuioObject(TuioObject tobj, float xp, float yp)
         {
             tobj.update(currentFrameTime, xp, yp);
@@ -95,11 +184,18 @@ namespace TUIO
                 updatedObjectList.Add(tobj);
         }
 
+        /// <summary>
+        /// Removes a tuio object.
+        /// </summary>
+        /// <param name="tobj">the object to remove</param>
         public void removeTuioObject(TuioObject tobj)
         {
             objectList.Remove(tobj);
         }
 
+        /// <summary>
+        /// Initializes cursor and object lists for sending information for a new frame.
+        /// </summary>
         public void initFrame()
         {
             currentFrameTime = TuioTime.getSessionTime();
@@ -107,16 +203,27 @@ namespace TUIO
             updatedObjectList = new List<TuioObject>();
         }
 
+        /// <summary>
+        /// Sends cursors and objects which were updated in the current frame.
+        /// </summary>
         public void commitFrame()
         {
             sendMessage(updatedCursorList, updatedObjectList);
         }
 
+        /// <summary>
+        /// Sends all cursors and objects.
+        /// </summary>
         public void sendFullMessages()
         {
             sendMessage(cursorList, objectList);
         }
 
+        /// <summary>
+        /// Sends cursors and objects.
+        /// </summary>
+        /// <param name="cursorList">list of cursors to send</param>
+        /// <param name="objectList">list of objects to send</param>
         private void sendMessage(List<TuioCursor> cursorList, List<TuioObject> objectList)
         {
             OSCBundle packet = new OSCBundle();
@@ -136,15 +243,6 @@ namespace TUIO
                 currentMessage.Append(tcur.getXSpeed());
                 currentMessage.Append(tcur.getYSpeed());
                 currentMessage.Append(tcur.getMotionAccel());
-
-                /*if (Marshal.SizeOf(packet) + Marshal.SizeOf(currentOscElement) >= MAX_PACKET_SIZE)
-                {
-                    packet.AddElement(new OscElement("/tuio/2Dcur", new Object[] { "fseq", -1 }));
-                    udpwriter.Send(packet);
-
-                    packet = new OscBundle();
-                    addAliveCursorMessagesToBundle(packet);
-                }*/
                 packet.Append(currentMessage);
             }
             currentMessage = new OSCMessage("/tuio/2Dcur");
@@ -185,6 +283,10 @@ namespace TUIO
             transmitter.Send(packet);
         }
 
+        /// <summary>
+        /// Adds a tuio cursor alive message to a packet.
+        /// </summary>
+        /// <param name="packet">packet to add the message to</param>
         private void addAliveCursorMessagesToBundle(OSCBundle packet)
         {
             OSCMessage mssg = new OSCMessage("/tuio/2Dcur");
@@ -196,6 +298,10 @@ namespace TUIO
             packet.Append(mssg);
         }
 
+        /// <summary>
+        /// Adds a tuio object alive message to a packet.
+        /// </summary>
+        /// <param name="packet">packet to add the message to</param>
         private void addAliveObjectMessagesToBundle(OSCBundle packet)
         {
             OSCMessage mssg = new OSCMessage("/tuio/2Dobj");

+ 43 - 0
bbiwarg/TUIO/TuioCommunicator.cs

@@ -13,12 +13,32 @@ using TUIO;
 
 namespace bbiwarg.TUIO
 {
+    /// <summary>
+    /// TuioCommunicator sends generated touch events and palm grid coordinates to tuio clients using a <see cref="TuioServer"/>.
+    /// </summary>
     class TuioCommunicator
     {
+        /// <summary>
+        /// the tuio server
+        /// </summary>
         private TuioServer server;
+
+        /// <summary>
+        /// dictionary of lists of tuio cursors indexed by touch id
+        /// </summary>
         private Dictionary<int, TuioCursor> tcursors;
+
+        /// <summary>
+        /// dictionary of lists of tuio objects indexed by palm id
+        /// </summary>
         private Dictionary<int, List<TuioObject>> tobjects;
 
+
+        /// <summary>
+        /// Constructs a TuioCommunicator.
+        /// </summary>
+        /// <param name="host">server ip</param>
+        /// <param name="port">server port</param>
         public TuioCommunicator(string host, int port)
         {
             server = new TuioServer(host, port);
@@ -26,6 +46,11 @@ namespace bbiwarg.TUIO
             tobjects = new Dictionary<int, List<TuioObject>>();
         }
 
+        /// <summary>
+        /// Handles the event that a new frame is finished processing by updating the cursors and objects and sending them.
+        /// </summary>
+        /// <param name="sender">event sender</param>
+        /// <param name="e">event arguments</param>
         public void handleNewFrameData(object sender, NewProcessedFrameEventArgs e)
         {
             server.initFrame();
@@ -93,11 +118,17 @@ namespace bbiwarg.TUIO
             server.commitFrame();
         }
 
+        /// <summary>
+        /// Closes the server.
+        /// </summary>
         public void close()
         {
             server.close();
         }
 
+        /// <summary>
+        /// Resets the server by removing all cursors and objects.
+        /// </summary>
         public void reset()
         {
             foreach (int id in tcursors.Keys)
@@ -112,6 +143,12 @@ namespace bbiwarg.TUIO
             tobjects.Clear();
         }
 
+        /// <summary>
+        /// Tries to parse an ip address string.
+        /// </summary>
+        /// <param name="ipIn">the ip address string to parse</param>
+        /// <param name="ipOut">out parameter for the ip address in *.*.*.* format if ipIn is valid and null otherwise</param>
+        /// <returns>true iff ipIn is a valid ip address</returns>
         public static bool tryParseIPAddress(String ipIn, out String ipOut)
         {
             IPAddress ipAddress;
@@ -123,6 +160,12 @@ namespace bbiwarg.TUIO
             return result;
         }
 
+        /// <summary>
+        /// Tries to parse a port string.
+        /// </summary>
+        /// <param name="portIn">the port string to parse</param>
+        /// <param name="portOut">out parameter for the port as an Int16 if portIn is valid and undefined otherwise</param>
+        /// <returns>true iff portIn is a valid port</returns>
         public static bool tryParsePort(String portIn, out Int16 portOut)
         {
             return Int16.TryParse(portIn, out portOut);