/// <summary> /// Capture and act upon the 'capture' event, fired by the tracker. /// Can use this method to actually collect a value from the sensor. /// </summary> /// <param name="sender"></param> /// <param name="skel"></param> internal void capture(object sender, SkeletonPosition skel) { System.Diagnostics.Debug.WriteLine("Scan captured! END"); if (this.CaptureMode == (int)CaptureModes.Capture_New) { // Write location and timestamp to the database //initialise database class DatabaseEngine db = new DatabaseEngine(); DateTime timestamp = DateTime.Now; sharedPosition = skel; ((CoreLoader)(this.Owner)).savedLocation = sharedPosition; //add record to database //db.insertScanLocations("null", skel.jointName1, "null", skel.offsetXJ1, skel.offsetYJ1, "0", timestamp); Console.WriteLine("Writing to database! Values = " + skel.jointName1 + ", " + skel.offsetXJ1 + ", " + skel.offsetYJ1 + ", " + timestamp); } if (this.CaptureMode == (int)CaptureModes.Capture_Existing) { // Capture data from the scanner.... } tracker.stop(); this.Close(); }
private void scan_existing_Click(object sender, RoutedEventArgs e) { this.CaptureMode = (int)CaptureModes.Capture_Existing; // hide buttons from form //cancel_scan.Visibility = Visibility.Collapsed; start_scan.Visibility = Visibility.Collapsed; rescanButton.Visibility = Visibility.Collapsed; // show image & instructions Visualisation.Visibility = Visibility.Visible; instructionblock.Visibility = Visibility.Collapsed; instructionblock2.Text = "Loading..."; instructionblock2.Visibility = Visibility.Visible; // TODO move the button to the edge but keep it visible cancel_scan.Visibility = Visibility.Hidden; System.Diagnostics.Debug.WriteLine("Starting measurement window..."); // Start tracking tracker = new SensorTracker(Visualisation, this, instructionblock2); //tracker.captureNewLocation(); // Get a position from the database SkeletonPosition targetLocation = new SkeletonPosition(); /*DatabaseEngine db = new DatabaseEngine(); * Tuple<int, String, double, double, DateTime> scanloc = db.getLatestScanLoc(); * * targetLocation.jointName1 = scanloc.Item2; * targetLocation.offsetXJ1 = scanloc.Item3; * targetLocation.offsetYJ1 = scanloc.Item4;*/ targetLocation = ((CoreLoader)(this.Owner)).savedLocation; tracker.captureAtLocation(targetLocation); // Hook up to the capture event, fired by the tracker. tracker.Capture += new SensorTracker.CaptureEventHandler(capture); }
/// <summary> /// Returns a distance metric, which describes the distance between this SP and the provided SP. /// </summary> /// <remarks> /// Used to operate the timer in SensorTracker /// </remarks> /// <param name="skeletonPosition"></param> /// <returns></returns> internal double distanceTo(SkeletonPosition targetPosition) { double distance = 50; System.Diagnostics.Debug.WriteLine("JN1 " + this.jointName1); System.Diagnostics.Debug.WriteLine("SPJN1 " + targetPosition.jointName1); if (this.jointName1 != targetPosition.jointName1) { return(100); } else { double dx = this.offsetXJ1 - targetPosition.offsetXJ1; double dy = this.offsetYJ1 - targetPosition.offsetYJ1; distance = Math.Pow(dx, 2) + Math.Pow(dy, 2); distance = Math.Pow(distance, 1 / 2); } return(distance); }
private void scan_existing_Click(object sender, RoutedEventArgs e) { this.CaptureMode = (int)CaptureModes.Capture_Existing; // hide buttons from form //cancel_scan.Visibility = Visibility.Collapsed; start_scan.Visibility = Visibility.Collapsed; rescanButton.Visibility = Visibility.Collapsed; // show image & instructions Visualisation.Visibility = Visibility.Visible; instructionblock.Visibility = Visibility.Collapsed; instructionblock2.Text = "Loading..."; instructionblock2.Visibility = Visibility.Visible; // TODO move the button to the edge but keep it visible cancel_scan.Visibility = Visibility.Hidden; System.Diagnostics.Debug.WriteLine("Starting measurement window..."); // Start tracking tracker = new SensorTracker(Visualisation, this, instructionblock2); //tracker.captureNewLocation(); // Get a position from the database SkeletonPosition targetLocation = new SkeletonPosition(); /*DatabaseEngine db = new DatabaseEngine(); Tuple<int, String, double, double, DateTime> scanloc = db.getLatestScanLoc(); targetLocation.jointName1 = scanloc.Item2; targetLocation.offsetXJ1 = scanloc.Item3; targetLocation.offsetYJ1 = scanloc.Item4;*/ targetLocation = ((CoreLoader)(this.Owner)).savedLocation; tracker.captureAtLocation(targetLocation); // Hook up to the capture event, fired by the tracker. tracker.Capture += new SensorTracker.CaptureEventHandler(capture); }
/// <summary> /// Takes the latest skeleton and sensor position data, and updates the stored position. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="angleXY"></param> /// <param name="angleZ"></param> /// <param name="skeleton"></param> /*internal void updatePosition(int x, int y, double angleXY, double angleZ, Skeleton skeleton) { // Update the position? }*/ internal string getDirections(SkeletonPosition targetPosition) { String output = ""; if (this.jointName1 != targetPosition.jointName1) { output += "Wrong joint: Current=" + this.jointName1 + " - target the " + targetPosition.jointName1; } else { double dx = this.offsetXJ1 - targetPosition.offsetXJ1; double dy = this.offsetYJ1 - targetPosition.offsetYJ1; double dist = Math.Pow(dx, 2) + Math.Pow(dy, 2); dist = Math.Pow(dist, 1/2); output += "X: " + Math.Round(dx, 1); output += ", Y: " + Math.Round(dy, 1); output += " d: " + Math.Round(dist, 2); Console.WriteLine("Offsets: " + "this: X: " + this.offsetXJ1 + ", Y: " + this.offsetYJ1 + " Target: X: " + targetPosition.offsetXJ1 + ", Y: " + targetPosition.offsetYJ1); } return output; }
/// <summary> /// Returns a distance metric, which describes the distance between this SP and the provided SP. /// </summary> /// <remarks> /// Used to operate the timer in SensorTracker /// </remarks> /// <param name="skeletonPosition"></param> /// <returns></returns> internal double distanceTo(SkeletonPosition targetPosition) { double distance = 50; System.Diagnostics.Debug.WriteLine("JN1 " + this.jointName1); System.Diagnostics.Debug.WriteLine("SPJN1 " + targetPosition.jointName1); if (this.jointName1 != targetPosition.jointName1) return 100; else { double dx = this.offsetXJ1 - targetPosition.offsetXJ1; double dy = this.offsetYJ1 - targetPosition.offsetYJ1; distance = Math.Pow(dx, 2) + Math.Pow(dy, 2); distance = Math.Pow(distance, 1/2); } return distance; }