123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Threading;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.Windows;
- using System.Windows.Forms;
- using bbiwarg.Output.DebugOutput;
- using bbiwarg.Output.GlassesOutput;
- using bbiwarg.Input.InputProviding;
- using bbiwarg.Input.InputHandling;
- 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);
- BBIWARG program = new BBIWARG(args);
- 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);
- debugWindowEnabled = Parameters.DebugWindowEnabled;
- glassesWindowEnabled = Parameters.GlassesWindowEnabled && Screen.AllScreens.Count() >= 2;
- // inputProvider
- createInputProvider();
- inputProvider.initialize();
- inputProvider.DeviceStartedEvent += handleDeviceStartedEvent;
- // inputHandler
- inputHandler = new InputHandler(inputProvider);
- // tuioCommunicator
- if (tuioEnabled)
- {
- tuioCommunicator = new TuioCommunicator(tuioIP, tuioPort);
- inputHandler.NewProcessedFrameEvent += tuioCommunicator.handleNewFrameData;
- }
- // debug output
- if (debugWindowEnabled)
- debugWindowThread = new Thread(new ThreadStart(debugWindowThreadStart));
- // glasses output
- if (glassesWindowEnabled)
- glassesWindowThread = new Thread(new ThreadStart(glassesWindowThreadStart));
- }
- /// <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)
- inputProvider = new VideoInputProvider(Parameters.InputMoviePath);
- else
- 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)
- debugWindowThread.Start();
- if (glassesWindowEnabled)
- 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)
- {
- tuioEnabled = true;
- String ipString = null;
- String portString = null;
- if (args.Length == 2)
- {
- ipString = args[0];
- portString = args[1];
- }
- else if (args.Length == 1)
- {
- String[] parts = args[0].Split(':');
- ipString = parts[0];
- if (parts.Length == 2)
- portString = parts[1];
- }
- while (!TuioCommunicator.tryParseIPAddress(ipString, out tuioIP))
- {
- Console.WriteLine("Please insert the TUIO-Client's IP (Default is " + Parameters.TuioDefaultIP + "):");
- ipString = Console.ReadLine();
- }
- Console.WriteLine("TUIO-IP is set to:" + tuioIP);
- while (!TuioCommunicator.tryParsePort(portString, out tuioPort))
- {
- Console.WriteLine("Please insert the TUIO-Client's Port (Default is " + Parameters.TuioDefaultPort + "):");
- portString = Console.ReadLine();
- }
- Console.WriteLine("TUIO-PORT is set to:" + tuioPort);
- }
- else
- {
- tuioEnabled = Parameters.TuioEnabledByDefault;
- tuioIP = Parameters.TuioDefaultIP;
- tuioPort = Parameters.TuioDefaultPort;
- }
- }
- }
- }
|