/// <summary> /// Updates the camera list /// </summary> public static void UpdateCameraList() { if (APIRunning) { numberOfCameras = TrackingTools.CameraCount(); OptiTrackCamera camera = new OptiTrackCamera(); connectedCameraDetails = " Number of Cameras Connected: " + numberOfCameras + "\n"; double[] tempRotationMatrix = new double[9]; int j = 0; for (int i = 0; i < numberOfCameras; i++) { camera.CameraNumber = i; camera.CameraName = TrackingTools.CameraName(i); camera.xCoordinate = TrackingTools.CameraLocationX(i) * 1000; camera.yCoordinate = TrackingTools.CameraLocationY(i) * 1000; camera.zCoordinate = TrackingTools.CameraLocationZ(i) * 1000; connectedCameraDetails += " Camera : " + camera.CameraName + "\n"; j = 0; for (j = 0; j < 9; j++) { tempRotationMatrix[j] = TrackingTools.CameraOrientation(i, j); } camera.RotationMatrix = tempRotationMatrix; OptitrackCameraList.AddCamera(camera); } } }
/// <summary> /// Starts up the Tracking Tools API /// </summary> public static int Initialize() { int result = -1; // Check that the Tracking Tools API .dll file exists then initialize result = TrackingTools.Initialize(); if (result == 100)// Custom error code for DLL missing - shut down program { MessageBox.Show("NPTrackingTools.dll is missing", null, MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } else { apiRunning = true; UpdateCameraList(); if (result != 0) { // If the API failed to initialize correctly shutdown the api but keep the program running Shutdown(); } } return(result); }
/// <summary> /// Loads the Tracking Tools Project (Calibration + Rigid Bodys etc) /// Not very usefull as they can't be transfered between each new development build /// </summary> /// <param name="ProjectPath"></param> public static int LoadProject(string ProjectPath) { int result = -1; if (APIRunning) { result = TrackingTools.LoadProject(ProjectPath); } else { result = 101; // Custom error code for API not running } return(result); }
/// <summary> /// Loads the calibration file defined in CalibrationPath /// </summary> /// <param name="CalibrationPath">The .cal file Path</param> public static int LoadCalibration(string CalibrationPath) { int result = -1; if (APIRunning) { result = TrackingTools.LoadCalibration(CalibrationPath); } else { result = 101; // Custom error code for API not running } return(result); }
/// <summary> /// Returns the Trackable for the index specified /// </summary> /// <param name="TrackableIndex">The index of the trackable</param> /// <returns>The result</returns> public static Trackable GetTrackableLocation(int TrackableIndex) { Trackable trackable = new Trackable(); float x, y, z; float qx, qy, qz, qw; float yaw, pitch, roll; GetTrackableLocation(TrackableIndex, out x, out y, out z, out qx, out qy, out qz, out qw, out yaw, out pitch, out roll); trackable.xCoordinate = (int)(x * 1000); // Positive faceing the screen going right trackable.yCoordinate = (int)(y * 1000); // Positive Up trackable.zCoordinate = (int)(z * 1000); // Positive Towards the screen trackable.Yaw = -Math.Round(yaw, 1); // invert yaw trackable.Pitch = Math.Round(roll, 1); // Swap around pitch and roll trackable.Roll = Math.Round(pitch, 1); trackable.TimeStamp = System.DateTime.Now.Ticks; trackable.ID = TrackableID(TrackableIndex); trackable.Name = TT_TrackableName(TrackableIndex); trackable.TrackableIndex = TrackableIndex; trackable.QW = qw; trackable.QX = qx; trackable.QY = qy; trackable.QZ = qz; Marker trackableMarker = null; trackable.TrackableMarkers = new List <Marker>(); // Build the rotation matrix StroMoHab_Matrix.RotationMatrix rotationMatix = new StroMoHab_Matrix.RotationMatrix(Math.PI * trackable.Pitch / 180, Math.PI * trackable.Yaw / 180, Math.PI * trackable.Roll / 180); //loop through and get all of the markers that are part of the trackable, apply the rotation matrix, and add them for (int j = 0; j < TrackingTools.TrackableMarkerCount(TrackableIndex); j++) { trackableMarker = TrackingTools.TrackableMarker(TrackableIndex, j); // get the marker // rotate the marker StroMoHab_Matrix.PointMatrix newPointMatrix = StroMoHab_Matrix.Operations.Rotate(new StroMoHab_Matrix.PointMatrix(trackableMarker.xCoordinate, trackableMarker.yCoordinate, trackableMarker.zCoordinate), rotationMatix); //get the new marker position trackableMarker.xCoordinate = Math.Round(newPointMatrix.XCoordinate, 1); trackableMarker.yCoordinate = Math.Round(newPointMatrix.YCoordinate, 1); trackableMarker.zCoordinate = Math.Round(newPointMatrix.ZCoordinate, 1); trackable.TrackableMarkers.Add(trackableMarker); } return(trackable); }
/// <summary> /// Turns an error code of type int into a string containing the error message /// </summary> /// <param name="errorCode"></param> public static string GetErrorMessage(int errorCode) { string errorMessage = null; switch (errorCode) { case 0: // Method worked errorMessage = "Success"; break; case 100: // Custom error when .dll is missing errorMessage = "NPTrackingTools.dll is missing"; break; case 101: // Custom error when API is not running errorMessage = "Tracking Tools API is not running\n"; break; case 102: //Timer is already running errorMessage = "The update timer has already been started"; break; case 2: //orveride missing file errorMessage = "File not found - Have you imported the requiered settings?"; break; case 11: // Overide Invalid licence error and add the list of cameras connected errorMessage = "Invalid Licence - Usually the licenced camera isn't connected\n" + connectedCameraDetails; break; default: // Decode error message using Tracking Tools API as its not a custom error code errorMessage = TrackingTools.GetResultString(errorCode); break; } return(errorMessage); }
/// <summary> /// Updates the list of markers with lastest marker coordinates /// </summary> public static void UpdateCoordinates(bool updateMarker, bool updateTrackable) { if (APIRunning) { // Get the timestamp to apply to all markers and trackables long timeStamp = System.DateTime.Now.Ticks; try { if (TrackingTools.UpdateAll() == 0) // If it updates correctly { if (updateMarker) { int markerCount = TrackingTools.FrameMarkerCount(); Marker marker = new Marker(); for (int i = 0; i < markerCount; i++) { //Get the marker details from TrackingTools marker.MarkerId = i; marker.TimeStamp = timeStamp; marker.xCoordinate = -(int)(TrackingTools.FrameMarkerX(i) * 1000); marker.yCoordinate = (int)(TrackingTools.FrameMarkerY(i) * 1000); marker.zCoordinate = (int)(TrackingTools.FrameMarkerZ(i) * 1000); MarkerList.AddMarker(marker); marker = new Marker(); } MarkerList.RemoveExcessMarkersFromList(markerCount); OnMarkerListAvaliable(MarkerList.listOfMarkers, timeStamp); } if (updateTrackable) { int trackableCount = TrackingTools.TrackableCount(); trackableList.Clear(); Trackable newTrackable = null; // Go through the loaded trackables and if they are in the current frame // add them to the trackableList for (int i = 0; i < trackableCount; i++) { if (TrackingTools.IsTrackableTracked(i)) { newTrackable = TrackingTools.GetTrackableLocation(i); newTrackable.TimeStamp = timeStamp; trackableList.Add(newTrackable); } } OnTrackableListAvaliable(trackableList, timeStamp); } } } catch (AccessViolationException ex) { System.Diagnostics.Debug.WriteLine("Error With UpdateALL() " + ex + " Time Stamp : " + timeStamp); } catch (System.Runtime.InteropServices.SEHException ex) { System.Diagnostics.Debug.WriteLine("Error With UpdateALL() " + ex + " Time Stamp : " + timeStamp); } } }
/// <summary> /// Shuts down the API and driver threads - the application must now be re-started /// </summary> public static void FinalShutdown() { TrackingTools.FinalShutdown(); }
/// <summary> /// Shuts down the Tracking Tools API - but doesn't shutdown the driver thread /// </summary> public static void Shutdown() { apiRunning = false; TrackingTools.Shutdown(); }