BBWIWARG.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Threading;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Net;
  8. using System.Windows;
  9. using System.Windows.Forms;
  10. using bbiwarg.Output.DebugOutput;
  11. using bbiwarg.Output.GlassesOutput;
  12. using bbiwarg.Input.InputProviding;
  13. using bbiwarg.Input.InputHandling;
  14. using bbiwarg.TUIO;
  15. namespace bbiwarg
  16. {
  17. class BBIWARG
  18. {
  19. private InputProvider inputProvider;
  20. private InputHandler inputHandler;
  21. private bool tuioEnabled;
  22. private String tuioIP;
  23. private Int16 tuioPort;
  24. private TuioCommunicator tuioCommunicator;
  25. private bool debugWindowEnabled;
  26. private DebugWindow debugWindow;
  27. private Thread debugWindowThread;
  28. private bool glassesWindowEnabled;
  29. private Thread glassesWindowThread;
  30. private GlassesWindow glassesWindow;
  31. static void Main(string[] args)
  32. {
  33. Console.SetWindowSize(Parameters.ConsoleWidth, Parameters.ConsoleHeight);
  34. BBIWARG program = new BBIWARG(args);
  35. program.run();
  36. }
  37. public BBIWARG(string[] args)
  38. {
  39. handleArgs(args);
  40. debugWindowEnabled = Parameters.DebugWindowEnabled;
  41. glassesWindowEnabled = Parameters.GlassesWindowEnabled && Screen.AllScreens.Count() >= 2;
  42. // inputProvider
  43. createInputProvider();
  44. inputProvider.initialize();
  45. inputProvider.DeviceStartedEvent += handleDeviceStartedEvent;
  46. // inputHandler
  47. inputHandler = new InputHandler(inputProvider);
  48. // tuioCommunicator
  49. if (tuioEnabled)
  50. {
  51. tuioCommunicator = new TuioCommunicator(tuioIP, tuioPort);
  52. inputHandler.NewProcessedFrameEvent += tuioCommunicator.handleNewFrameData;
  53. }
  54. // debug output
  55. if (debugWindowEnabled)
  56. debugWindowThread = new Thread(new ThreadStart(debugWindowThreadStart));
  57. // glasses output
  58. if (glassesWindowEnabled)
  59. glassesWindowThread = new Thread(new ThreadStart(glassesWindowThreadStart));
  60. }
  61. public void run()
  62. {
  63. inputProvider.start();
  64. }
  65. private void createInputProvider()
  66. {
  67. if (Parameters.InputSource == InputType.Movie)
  68. inputProvider = new VideoInputProvider(Parameters.InputMoviePath);
  69. else
  70. inputProvider = new InputProvider();
  71. }
  72. private void debugWindowThreadStart()
  73. {
  74. debugWindow = new DebugWindow(inputProvider, inputHandler, Parameters.DebugWindowTitle, Parameters.DebugWindowUpdateIntervall);
  75. Application.Run(debugWindow);
  76. }
  77. private void glassesWindowThreadStart()
  78. {
  79. glassesWindow = new GlassesWindow(inputProvider, inputHandler, Parameters.GlassesWindowTitle, Screen.AllScreens[1], Parameters.GlassesWindowUpdateInterval);
  80. Application.Run(glassesWindow);
  81. }
  82. private void handleDeviceStartedEvent(object sender, EventArgs e)
  83. {
  84. if (debugWindowEnabled)
  85. debugWindowThread.Start();
  86. if (glassesWindowEnabled)
  87. glassesWindowThread.Start();
  88. }
  89. private void handleArgs(String[] args)
  90. {
  91. if (args.Length > 0)
  92. {
  93. tuioEnabled = true;
  94. String ipString = null;
  95. String portString = null;
  96. if (args.Length == 2)
  97. {
  98. ipString = args[0];
  99. portString = args[1];
  100. }
  101. else if (args.Length == 1)
  102. {
  103. String[] parts = args[0].Split(':');
  104. ipString = parts[0];
  105. if (parts.Length == 2)
  106. portString = parts[1];
  107. }
  108. while (!TuioCommunicator.tryParseIPAddress(ipString, out tuioIP))
  109. {
  110. Console.WriteLine("Please insert the TUIO-Client's IP (Default is " + Parameters.TuioDefaultIP + "):");
  111. ipString = Console.ReadLine();
  112. }
  113. Console.WriteLine("TUIO-IP is set to:" + tuioIP);
  114. while (!TuioCommunicator.tryParsePort(portString, out tuioPort))
  115. {
  116. Console.WriteLine("Please insert the TUIO-Client's Port (Default is " + Parameters.TuioDefaultPort + "):");
  117. portString = Console.ReadLine();
  118. }
  119. Console.WriteLine("TUIO-PORT is set to:" + tuioPort);
  120. }
  121. else
  122. {
  123. tuioEnabled = Parameters.TuioEnabledByDefault;
  124. tuioIP = Parameters.TuioDefaultIP;
  125. tuioPort = Parameters.TuioDefaultPort;
  126. }
  127. }
  128. }
  129. }