/// <summary> /// Handle the display changing on this surface. /// </summary> /// <param name="obj"></param> private void Surface_OnDisplayChanged(Model.Surface obj) { this.Dispatcher.BeginInvoke((Action) delegate() { MakeUIMatchSurface(); }); }
/// <summary> /// Handle updates to the surface's spatial properties. /// </summary> /// <param name="obj"></param> private void Surface_OnPropertiesUpdated(Model.Surface obj) { this.Dispatcher.BeginInvoke((Action) delegate() { MakeUIMatchSurface(); }); }
/// <summary> /// Attempt to load calibration data from a file. /// </summary> /// <param name="bCalibration">Do we want to load hardware and calibration settings.</param> /// <param name="bSurfaces">Do we want to load surface data.</param> /// <param name="bDisplays">Do we want to load displays.</param> /// <param name="sFile">The file we want to load the data from.</param> private void Load(bool bCalibration, bool bSurfaces, bool bDisplays, String sFile) { // Open the XML file and parse out the data we are interested in. var pDocument = XDocument.Load(sFile); #region Load Calibration Data if (bCalibration) { // Parse the surfaces from the file. var dCalibration = (from item in pDocument.Root.Elements("calibration") select new { MonitorDevice = item.Element("monitor").Value, KinectDevice = item.Element("kinect").Value, KinectImage = (from pt in item.Element("kinectimage").Elements("point") select PointFromString(pt.Value)).ToArray(), ProjectedImage = (from pt in item.Element("projectedimage").Elements("point") select PointFromString(pt.Value)).ToArray(), }).FirstOrDefault(); // Check we have calibration data. if (dCalibration != null) { #region Load Screen // If we already have a monitor selected. if (SelectedScreen != null) { // If the device names are the same, all is well. if (SelectedScreen.DeviceName != dCalibration.MonitorDevice) { // We have one selected already, log and bail. Log.Write("Screen already selected. Ignoring '" + dCalibration.MonitorDevice + "'.", "Application", Log.Type.AppWarning); } // See if we can complete step 1. TryCompleteStep1(false); } // If we don't have a montior selected. else { // Attempt to find a montor with a matching device name. var lAvailable = Utilities.MonitorDetection.QueryDisplays(); foreach (var pMonitor in lAvailable) { if (pMonitor.DeviceName == dCalibration.MonitorDevice) { SelectedScreen = pMonitor; TryCompleteStep1(false); break; } } // If we didn't manage to select a screen, make a note in the log. if (SelectedScreen == null) { Log.Write("Could not find screen that matches the one in the file. You will need to choose another one.", "Application", Log.Type.AppWarning); } } #endregion #region Load Kinect // If we already have a kinect selected. if (SelectedKinect != null) { // If the device names are the same, all is well. if (SelectedKinect.DeviceConnectionId != dCalibration.KinectDevice) { // We have one selected already, log and bail. Log.Write("Kinect already selected. Ignoring '" + dCalibration.KinectDevice + "'.", "Application", Log.Type.AppWarning); } // See if we can complete step 1. TryCompleteStep1(false); } // If we don't have a kinect selected. else { // Attempt to find a montor with a matching device name. var lAvailable = KinectSensor.KinectSensors; foreach (var pKinect in lAvailable) { if (pKinect.DeviceConnectionId == dCalibration.KinectDevice) { SelectedKinect = pKinect; TryCompleteStep1(false); break; } } // If we didn't manage to select a screen, make a note in the log. if (SelectedKinect == null) { Log.Write("Could not find kinect that matches the one in the file. You will need to choose another one.", "Application", Log.Type.AppWarning); } } #endregion #region Load Calibration Settings // If we are NOT calibrated but are ready to be used. if (bCalibrated == false && SelectedKinect != null && SelectedScreen != null) { Calibrate(dCalibration.ProjectedImage, dCalibration.KinectImage); } // If we ARE calibrated and are ready to be used. else if (bCalibrated == true && SelectedKinect != null && SelectedScreen != null) { // Do we want to overwrite the existing calibration. var hResult = MessageBox.Show("Do you want to overwrite current calibration with imported one?", "Ubi Displays", MessageBoxButton.YesNo, MessageBoxImage.Question); if (hResult == MessageBoxResult.Yes) { Calibrate(dCalibration.ProjectedImage, dCalibration.KinectImage); } } // Otherwise we are not ready! else { Log.Write("Cannot import calibration because hardware is not selected.", "Application", Log.Type.AppWarning); } #endregion } } #endregion // Only import these if we are calibrated. if (!bCalibrated && (bSurfaces || bDisplays)) { Log.Write("Cannot import surfaces and displays. Please calibrate and try again.", "Application", Log.Type.AppWarning); return; } #region Load Surfaces if (bSurfaces) { // Parse the surfaces from the file. var lSurfaces = from item in pDocument.Root.Elements("surface") select new { Identifier = item.Element("name").Value, InjectMT = (item.Element("inject_multitouch").Value.ToLower() == "true") ? true : false, Projector = (from pt in item.Element("projector").Elements("point") select PointFromString(pt.Value)).ToArray(), Sensor = (from pt in item.Element("sensorspace").Elements("point") select Vector3FromString(pt.Value)).ToArray(), KinectImage = (from pt in item.Element("image").Elements("point") select PointFromString(pt.Value)).ToArray(), }; // For each surface, register one with the authority. foreach (var dSurfaceData in lSurfaces) { // Check the surface name is good. if (dSurfaceData.Identifier == null || dSurfaceData.Identifier == "") { Log.Write("Cannot import surface. Surface is missing a name.", "Application", Log.Type.AppWarning); continue; } // If the name is already taken, bail. if (Authority.FindSurface(dSurfaceData.Identifier) != null) { Log.Write("Cannot import surface '" + dSurfaceData.Identifier + "'. Surface with the same name already exists.", "Application", Log.Type.AppWarning); continue; } // Check we have valid data. if ((dSurfaceData.Projector == null || dSurfaceData.Projector.Length != 4) || (dSurfaceData.Sensor == null || dSurfaceData.Sensor.Length != 4) || (dSurfaceData.KinectImage == null || dSurfaceData.KinectImage.Length != 4)) { Log.Write("Cannot import surface '" + dSurfaceData.Identifier + "'. It does not contain valid data.", "Application", Log.Type.AppWarning); continue; } // Create the surface. var pSurface = new Model.Surface(dSurfaceData.Identifier); pSurface.AttemptMultiTouchInject = dSurfaceData.InjectMT; pSurface.SetSpatialProperties(dSurfaceData.Projector, dSurfaceData.Sensor, dSurfaceData.KinectImage); Authority.RegisterSurface(pSurface); } } #endregion #region Load Displays if (bDisplays) { // For each display in the surface file, attach it to the surface. var lDisplays = from item in pDocument.Root.Elements("display") select new { SurfaceName = item.Element("surfacename").Value, LoadInstruction = item.Element("loadinstruction").Value, Resolution = PointFromString(item.Element("resolution").Value), }; // Create the displays. foreach (var dDisplayData in lDisplays) { // Find the surface to place it on. var pSurface = Authority.FindSurface(dDisplayData.SurfaceName); if (pSurface == null) { Log.Write("Cannot import display '" + dDisplayData.LoadInstruction + "'. Could not find host surface '" + dDisplayData.SurfaceName + "'.", "Application", Log.Type.AppWarning); continue; } // Create the display. var pDisplay = new Display(dDisplayData.LoadInstruction, dDisplayData.Resolution); // Disable debug mode on the surface. pSurface.ShowDebug = false; // Show the display. Authority.ShowDisplay(pDisplay, pSurface); } } #endregion }