Browse Source

documented more Utility classes and BBIWARG

Daniel Kauth 10 years ago
parent
commit
3ecbbead2e

+ 80 - 0
bbiwarg/BBWIWARG.cs

@@ -15,24 +15,79 @@ using bbiwarg.TUIO;
 
 namespace bbiwarg
 {
+    /// <summary>
+    /// Main class which creates and starts the input, tuio and window objects.
+    /// </summary>
     class BBIWARG
     {
+        /// <summary>
+        /// the input provider
+        /// </summary>
         private InputProvider inputProvider;
+
+        /// <summary>
+        /// the input handler
+        /// </summary>
         private InputHandler inputHandler;
 
+
+        /// <summary>
+        /// true iff the tuio server is enabled
+        /// </summary>
         private bool tuioEnabled;
+
+        /// <summary>
+        /// the ip address for the tuio server
+        /// </summary>
         private String tuioIP;
+
+        /// <summary>
+        /// the port for the tuio server
+        /// </summary>
         private Int16 tuioPort;
+
+        /// <summary>
+        /// the tuio communicator
+        /// </summary>
         private TuioCommunicator tuioCommunicator;
 
+
+        /// <summary>
+        /// true iff the debug window is enabled
+        /// </summary>
         private bool debugWindowEnabled;
+
+        /// <summary>
+        /// the debug window
+        /// </summary>
         private DebugWindow debugWindow;
+
+        /// <summary>
+        /// the thread the debug window runs in
+        /// </summary>
         private Thread debugWindowThread;
 
+
+        /// <summary>
+        /// true iff the glasses window is enabled
+        /// </summary>
         private bool glassesWindowEnabled;
+
+        /// <summary>
+        /// the thread the glasses window runs in
+        /// </summary>
         private Thread glassesWindowThread;
+
+        /// <summary>
+        /// the glasses window
+        /// </summary>
         private GlassesWindow glassesWindow;
 
+
+        /// <summary>
+        /// Starts the program.
+        /// </summary>
+        /// <param name="args"></param>
         static void Main(string[] args)
         {
             Console.SetWindowSize(Parameters.ConsoleWidth, Parameters.ConsoleHeight);
@@ -41,6 +96,10 @@ namespace bbiwarg
             program.run();
         }
 
+        /// <summary>
+        /// Parses the command line arguments and depending on them creates the input, tuio and window objects.
+        /// </summary>
+        /// <param name="args">command line arguments</param>
         public BBIWARG(string[] args)
         {
             handleArgs(args);
@@ -73,11 +132,17 @@ namespace bbiwarg
 
         }
 
+        /// <summary>
+        /// Runs the main program.
+        /// </summary>
         public void run()
         {
             inputProvider.start();
         }
 
+        /// <summary>
+        /// Creates the input provider.
+        /// </summary>
         private void createInputProvider()
         {
             if (Parameters.InputSource == InputType.Movie)
@@ -86,18 +151,29 @@ namespace bbiwarg
                 inputProvider = new InputProvider();
         }
 
+        /// <summary>
+        /// Runs the debug window in its own thread.
+        /// </summary>
         private void debugWindowThreadStart()
         {
             debugWindow = new DebugWindow(inputProvider, inputHandler, Parameters.DebugWindowTitle, Parameters.DebugWindowUpdateIntervall);
             Application.Run(debugWindow);
         }
 
+        /// <summary>
+        /// Runs the glasses window in its own thread.
+        /// </summary>
         private void glassesWindowThreadStart()
         {
             glassesWindow = new GlassesWindow(inputProvider, inputHandler, Parameters.GlassesWindowTitle, Screen.AllScreens[1], Parameters.GlassesWindowUpdateInterval);
             Application.Run(glassesWindow);
         }
 
+        /// <summary>
+        /// Handles the event that the device has started by starting the enabled windows.
+        /// </summary>
+        /// <param name="sender">event sender</param>
+        /// <param name="e">event arguments</param>
         private void handleDeviceStartedEvent(object sender, EventArgs e)
         {
             if (debugWindowEnabled)
@@ -107,6 +183,10 @@ namespace bbiwarg
                 glassesWindowThread.Start();
         }
 
+        /// <summary>
+        /// Parses the command line arguments and sets parameters depending on them.
+        /// </summary>
+        /// <param name="args">command line arguments</param>
         private void handleArgs(String[] args)
         {
             if (args.Length > 0)

+ 1 - 1
bbiwarg/Output/DebugOutput/TouchEventVisualizer.cs

@@ -17,7 +17,7 @@ namespace bbiwarg.Output.DebugOutput
     class TouchEventVisualizer
     {
         /// <summary>
-        /// used to prevent the simultaneous access to <see cref="handleNewFrameData"/> and <see cref="getOutputImage"/> from different threads
+        /// used to prevent running <see cref="handleNewFrameData"/> and <see cref="getOutputImage"/> simultaneously from different threads
         /// </summary>
         private Object sync;
 

+ 14 - 0
bbiwarg/Utility/Logger.cs

@@ -6,6 +6,9 @@ using System.Threading.Tasks;
 
 namespace bbiwarg.Utility
 {
+    /// <summary>
+    /// flags describing the different log subjects
+    /// </summary>
     public enum LogSubject
     {
         None = 0,
@@ -22,10 +25,21 @@ namespace bbiwarg.Utility
         PalmTracker = 1024
     }
 
+    /// <summary>
+    /// Logs messages.
+    /// </summary>
     static class Logger
     {
+        /// <summary>
+        /// the current frame
+        /// </summary>
         public static int CurrentFrame { get; set; }
 
+        /// <summary>
+        /// May print a message depending on the subject and <see cref="Parameters.LoggerEnabledSubjects"/>.
+        /// </summary>
+        /// <param name="message">the message</param>
+        /// <param name="subject">the subject the message belongs to, determines if this message is printed</param>
         public static void log(string message, LogSubject subject)
         {
             if (Parameters.LoggerEnabledSubjects.HasFlag(subject))

+ 56 - 0
bbiwarg/Utility/Projection2DTo2D.cs

@@ -9,17 +9,54 @@ using Emgu.CV.Structure;
 
 namespace bbiwarg.Utility
 {
+    /// <summary>
+    /// Computes and stores a homography matrix and provides functions to export it and project points.
+    /// </summary>
     class Projection2DTo2D
     {
+        /// <summary>
+        /// size of the image the original points are in
+        /// </summary>
         private ImageSize sizeA;
+
+        /// <summary>
+        /// size of the image the projected points are in
+        /// </summary>
         private ImageSize sizeB;
+
+        /// <summary>
+        /// calibration points in the first image (match points in calibrationPointsB)
+        /// </summary>
         private List<PointF> calibrationPointsA;
+
+        /// <summary>
+        /// calibration points in the second image (match points in calibrationPointsA)
+        /// </summary>
         private List<PointF> calibrationPointsB;
+
+        /// <summary>
+        /// number of points used for the calibration
+        /// </summary>
         private int numPointsForCalibration;
+
+        /// <summary>
+        /// homography matrix used to compute the projected points
+        /// </summary>
         private HomographyMatrix homography;
 
+
+        /// <summary>
+        /// true iff the calibration is finished
+        /// </summary>
         public bool IsCalibrated { get; private set; }
 
+
+        /// <summary>
+        /// Constructs a Projection2DTo2D.
+        /// </summary>
+        /// <param name="sizeA">size of the image the original points are in</param>
+        /// <param name="sizeB">size of the image the projected points are in</param>
+        /// <param name="numPointsForCalibration">number of points used for the calibration</param>
         public Projection2DTo2D(ImageSize sizeA, ImageSize sizeB, int numPointsForCalibration = 4) {
             this.sizeA = sizeA;
             this.sizeB = sizeB;
@@ -28,6 +65,9 @@ namespace bbiwarg.Utility
             reset();
         }
 
+        /// <summary>
+        /// Resets the calibration.
+        /// </summary>
         public void reset() {
             homography = null;
             IsCalibrated = false;
@@ -35,6 +75,11 @@ namespace bbiwarg.Utility
             calibrationPointsB = new List<PointF>();
         }
 
+        /// <summary>
+        /// Adds a pair of calibration points.
+        /// </summary>
+        /// <param name="pointA">point in the first image</param>
+        /// <param name="pointB">point in the second image</param>
         public void addCalibrationPoints(Vector2D pointA, Vector2D pointB) {
             calibrationPointsA.Add(sizeA.getRelativePoint(pointA));
             calibrationPointsB.Add(sizeB.getRelativePoint(pointB));
@@ -43,12 +88,20 @@ namespace bbiwarg.Utility
                 calibrate();
         }
 
+        /// <summary>
+        /// Projects a point.
+        /// </summary>
+        /// <param name="pointA">the point to project</param>
+        /// <returns>projected point</returns>
         public Vector2D projectPoint(Vector2D pointA) {
             PointF[] pointfsB = new PointF[1] {sizeA.getRelativePoint(pointA)};
             homography.ProjectPoints(pointfsB);
             return sizeB.getAbsolutePoint(new Vector2D(pointfsB[0]));
         }
 
+        /// <summary>
+        /// Computes the homography from the lists of calibration points.
+        /// </summary>
         private void calibrate() {
             homography = CameraCalibration.FindHomography(calibrationPointsA.ToArray(), calibrationPointsB.ToArray(), Emgu.CV.CvEnum.HOMOGRAPHY_METHOD.DEFAULT, 0.995);
             
@@ -59,6 +112,9 @@ namespace bbiwarg.Utility
             exportHomography();
         }
 
+        /// <summary>
+        /// Writes the homography to a file.
+        /// </summary>
         private void exportHomography() {
             String[] fileData = new String[homography.Size.Height];
             StringBuilder sb = new StringBuilder();

+ 48 - 1
bbiwarg/Utility/Timer.cs

@@ -7,17 +7,56 @@ using System.Threading;
 
 namespace bbiwarg.Utility
 {
-    class Timer
+    /// <summary>
+    /// Stores and prints timing information for different code sections.
+    /// </summary>
+    static class Timer
     {
+        /// <summary>
+        /// used to prevent running <see cref="start"/>, <see cref="stop"/> and <see cref="outputAll"/> simultaneously from different threads
+        /// </summary>
         private static Object sync = new object();
+
+        /// <summary>
+        /// dictionary of stopwatches indexed by name of the code section
+        /// </summary>
         private static Dictionary<String, Stopwatch> stopwatches = new Dictionary<string, Stopwatch>();
+
+        /// <summary>
+        /// dictionary of current runtimes indexed by name of the code section
+        /// </summary>
         private static Dictionary<String, double> currentTimes = new Dictionary<string, double>();
+
+        /// <summary>
+        /// dictionary of minimum runtimes indexed by name of the code section
+        /// </summary>
         private static Dictionary<String, double> minTimes = new Dictionary<string, double>();
+
+        /// <summary>
+        /// dictionary of maximum runtimes indexed by name of the code section
+        /// </summary>
         private static Dictionary<String, double> maxTimes = new Dictionary<string, double>();
+
+        /// <summary>
+        /// dictionary of the sum of runtimes indexed by name of the code section
+        /// </summary>
         private static Dictionary<String, double> sumTimes = new Dictionary<string, double>();
+
+        /// <summary>
+        /// dictionary of the number of times the time was measured indexed by name of the code section
+        /// </summary>
         private static Dictionary<String, int> numTimes = new Dictionary<string, int>();
+
+        /// <summary>
+        /// the maximum length for the name of a code section
+        /// </summary>
         private static int maxNameLength = 1;
 
+
+        /// <summary>
+        /// Starts a timer for the given name and initializes the dictionaries when called for the first time with this name.
+        /// </summary>
+        /// <param name="name">name of the code section</param>
         public static void start(String name)
         {
             lock (sync)
@@ -36,6 +75,10 @@ namespace bbiwarg.Utility
             }
         }
 
+        /// <summary>
+        /// Stops the timer for the given name and stores timing information.
+        /// </summary>
+        /// <param name="name">name of the code section</param>
         public static void stop(String name)
         {
             lock (sync)
@@ -49,6 +92,10 @@ namespace bbiwarg.Utility
                 currentTimes[name] = time;
             }
         }
+
+        /// <summary>
+        /// Prints all collected timing information.
+        /// </summary>
         public static void outputAll()
         {
             lock (sync)