BBWIWARG.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 bbiwarg.Output.DebugOutput;
  9. using bbiwarg.Output.GlassesOutput;
  10. using bbiwarg.Input.InputProviding;
  11. using bbiwarg.Input.InputHandling;
  12. using bbiwarg.TUIO;
  13. namespace bbiwarg
  14. {
  15. class BBIWARG
  16. {
  17. InputProvider inputProvider;
  18. InputHandler inputHandler;
  19. TuioCommunicator tuioCommunicator;
  20. DebugWindow debugWindow;
  21. GlassesWindow glassesWindow;
  22. Thread debugOutputThread;
  23. Thread glassesOutputThread;
  24. static void Main(string[] args)
  25. {
  26. Console.SetWindowSize(Parameters.ConsoleWidth, Parameters.ConsoleHeight);
  27. handleArgs(args);
  28. BBIWARG program = new BBIWARG();
  29. program.run();
  30. }
  31. public BBIWARG()
  32. {
  33. // inputProvider
  34. createInputProvider();
  35. inputProvider.DeviceStartedEvent += handleDeviceStartedEvent;
  36. // inputHandler
  37. inputHandler = new InputHandler();
  38. inputProvider.NewFrameEvent += inputHandler.handleNewFrame;
  39. // tuioCommunicator
  40. if (Parameters.TuioEnabled)
  41. {
  42. tuioCommunicator = new TuioCommunicator(Parameters.TuioIP.ToString(), Parameters.TuioPort);
  43. inputHandler.NewProcessedFrameEvent += tuioCommunicator.handleNewFrameData;
  44. }
  45. // debug output
  46. if (Parameters.DebugWindowEnabled)
  47. {
  48. debugOutputThread = new Thread(new ThreadStart(debugOutputThreadStart));
  49. }
  50. // glasses output
  51. if (Parameters.GlassesWindowEnabled)
  52. {
  53. glassesOutputThread = new Thread(new ThreadStart(glassesOutputThreadStart));
  54. }
  55. }
  56. public void run()
  57. {
  58. inputProvider.start();
  59. }
  60. private void createInputProvider()
  61. {
  62. if (Parameters.InputSource == InputType.Movie)
  63. inputProvider = new VideoInputProvider(Parameters.InputMoviePath);
  64. else
  65. inputProvider = new InputProvider();
  66. }
  67. private void debugOutputThreadStart()
  68. {
  69. debugWindow = new DebugWindow(inputProvider, inputHandler);
  70. debugWindow.Run(Parameters.DebugWindowUpdateRate, Parameters.DebugWindowRenderRate);
  71. }
  72. private void glassesOutputThreadStart()
  73. {
  74. glassesWindow = new GlassesWindow(inputProvider, inputHandler);
  75. glassesWindow.Run(Parameters.GlassesWindowUpdateRate, Parameters.GlassesWindowRenderRate);
  76. }
  77. private void handleDeviceStartedEvent(object sender, EventArgs e)
  78. {
  79. startOutputThreads();
  80. }
  81. private void startOutputThreads()
  82. {
  83. if (Parameters.DebugWindowEnabled)
  84. debugOutputThread.Start();
  85. if (Parameters.GlassesWindowEnabled)
  86. glassesOutputThread.Start();
  87. }
  88. private static void handleArgs(String[] args)
  89. {
  90. if (args.Length > 0)
  91. {
  92. IPAddress ipAddress;
  93. Int16 port;
  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 ipAddress))
  109. {
  110. Console.WriteLine("Please insert the TUIO-Client's IP (Default is 127.0.0.1):");
  111. ipString = Console.ReadLine();
  112. }
  113. Console.WriteLine("TUIO-IP is set to:" + Parameters.TuioIP.ToString());
  114. while (!TuioCommunicator.tryParsePort(portString, out port))
  115. {
  116. Console.WriteLine("Please insert the TUIO-Client's Port (Default is 3333):");
  117. portString = Console.ReadLine();
  118. }
  119. Console.WriteLine("TUIO-PORT is set to:" + Parameters.TuioPort);
  120. Parameters.setTuioParameters(true, ipAddress, port);
  121. }
  122. }
  123. }
  124. }