/// <summary> /// Main Method of Vector Calculation Unit /// </summary> public override void Job() { try { _publisher.Detach(this); if (_stabilizer == null) { int ballRadius = (_imagingData.BallRadius < 0) ? 5 : _imagingData.BallRadius; _stabilizer = new CoordinatesStabilizer(ballRadius); } //Get data and remove noise BallCoordinates newCoordinates = _publisher.Data; BallCoordinates ballCoordinates = _stabilizer.Stabilize(newCoordinates, _storedBallCoordinates); //Draw coordinates from stabilizer if (ballCoordinates.IsDefined) { double x, y; TransformAgent.Data.InvertTransform(ballCoordinates.X, ballCoordinates.Y, out x, out y); } else { //Delete old locations Marks.DrawBall(new System.Windows.Point(0, 0), 0); } ballCoordinates.Vector = VectorCalculationAlgorithm(ballCoordinates); if (ballCoordinates.IsDefined && ballCoordinates.Vector.IsDefined) { try { (_coordinatesUpdater as BallCoordinatesUpdater).LastBallCoordinates = ballCoordinates; LastBallLocationPublisher.UpdateAndNotify(); Marks.DrawBallVector(new Point(ballCoordinates.X, ballCoordinates.Y), new Point(Convert.ToInt32(ballCoordinates.Vector.X), Convert.ToInt32(ballCoordinates.Vector.Y))); } catch (Exception e) { Log.Print(String.Format("{0} [{1}]", e.Message, ballCoordinates.ToString()), eCategory.Error, LogTag.VECTOR); } } else { Marks.DrawBallVector(new Point(0, 0), new Point(0, 0), false); } } catch (ThreadInterruptedException) { /* new data received */ } catch (Exception e) { Log.Print(String.Format("Error in vector calculation. Reason: {0}", e.Message), eCategory.Error, LogTag.VECTOR); } finally { _publisher.Attach(this); } }