public ScreenCrosshair(TPoint Center) { this.InitializeComponent(); _center = Center; SettingsManager.ScreenMappingSet.OnScreenSettingsUpdate += new Code.PositionMapping.ScreenMappingSettings.ScreenSettingsUpdateHandler(ScreenMappingSet_OnScreenSettingsUpdate); ChangePosition(); }
public bool IsInRegion(TPoint p) { p.CalculateScreenfromDepthCoords(); if ((p.ScreenX >= TopLeft.ScreenX) && (p.ScreenX <= BottomRight.ScreenX) && (p.ScreenY >= TopLeft.ScreenY) && (p.ScreenY <= BottomRight.ScreenY)) return true; return false; }
/// <summary> /// Calculates the screenAreas for the buttons and fields /// </summary> public void CalculateScreenAreas() { //Arrow Left/up double Tx = r_up.Margin.Left + menugrid.Margin.Left + Canvas.GetLeft(this); double Ty = r_up.Margin.Top + menugrid.Margin.Top + Canvas.GetTop(this); double Bx = r_up.Margin.Left + menugrid.Margin.Left + Canvas.GetLeft(this) + r_up.RenderedGeometry.Bounds.Width; double By = r_up.Margin.Top + menugrid.Margin.Top + Canvas.GetTop(this) + r_up.Height; TPoint left = new TPoint((int) Math.Round(Tx), (int) Math.Round(Ty), TPoint.PointCreationType.screen); TPoint right = new TPoint((int)Math.Round(Bx), (int)Math.Round(By), TPoint.PointCreationType.screen); arrowLeft = new GraphicalRegion(left, right); //Arrow right/down Tx = r_down.Margin.Left + menugrid.Margin.Left + Canvas.GetLeft(this); Ty = r_down.Margin.Top + menugrid.Margin.Top + Canvas.GetTop(this); Bx = r_down.Margin.Left + menugrid.Margin.Left + Canvas.GetLeft(this) + r_down.Width; By = r_down.Margin.Top + menugrid.Margin.Top + Canvas.GetTop(this) + r_down.Height; left = new TPoint((int)Math.Round(Tx), (int)Math.Round(Ty), TPoint.PointCreationType.screen); right = new TPoint((int)Math.Round(Bx), (int)Math.Round(By), TPoint.PointCreationType.screen); arrowRight = new GraphicalRegion(left, right); //MenuObject 1 Tx = c1.Margin.Left + menugrid.Margin.Left + Canvas.GetLeft(this); Ty = c1.Margin.Top + menugrid.Margin.Top + Canvas.GetTop(this); Bx = c1.Margin.Left + menugrid.Margin.Left + Canvas.GetLeft(this) + c1.Width; By = c1.Margin.Top + menugrid.Margin.Top + Canvas.GetTop(this) + c1.Height; left = new TPoint((int)Math.Round(Tx), (int)Math.Round(Ty), TPoint.PointCreationType.screen); right = new TPoint((int)Math.Round(Bx), (int)Math.Round(By), TPoint.PointCreationType.screen); MObject1 = new GraphicalRegion(left, right); //MenuObject 2 Tx = c2.Margin.Left + menugrid.Margin.Left + Canvas.GetLeft(this); Ty = c2.Margin.Top + menugrid.Margin.Top + Canvas.GetTop(this); Bx = c2.Margin.Left + menugrid.Margin.Left + Canvas.GetLeft(this) + c2.Width; By = c2.Margin.Top + menugrid.Margin.Top + Canvas.GetTop(this) + c2.Height; left = new TPoint((int)Math.Round(Tx), (int)Math.Round(Ty), TPoint.PointCreationType.screen); right = new TPoint((int)Math.Round(Bx), (int)Math.Round(By), TPoint.PointCreationType.screen); MObject2 = new GraphicalRegion(left, right); //MenuObject 3 Tx = c3.Margin.Left + menugrid.Margin.Left + Canvas.GetLeft(this); Ty = c3.Margin.Top + menugrid.Margin.Top + Canvas.GetTop(this); Bx = c3.Margin.Left + menugrid.Margin.Left + Canvas.GetLeft(this) + c3.Width; By = c3.Margin.Top + menugrid.Margin.Top + Canvas.GetTop(this) + c3.Height; left = new TPoint((int)Math.Round(Tx), (int)Math.Round(Ty), TPoint.PointCreationType.screen); right = new TPoint((int)Math.Round(Bx), (int)Math.Round(By), TPoint.PointCreationType.screen); MObject3 = new GraphicalRegion(left, right); //MenuObject 4 Tx = c4.Margin.Left + menugrid.Margin.Left + Canvas.GetLeft(this); Ty = c4.Margin.Top + menugrid.Margin.Top + Canvas.GetTop(this); Bx = c4.Margin.Left + menugrid.Margin.Left + Canvas.GetLeft(this) + c4.Width; By = c4.Margin.Top + menugrid.Margin.Top + Canvas.GetTop(this) + c4.Height; left = new TPoint((int)Math.Round(Tx), (int)Math.Round(Ty), TPoint.PointCreationType.screen); right = new TPoint((int)Math.Round(Bx), (int)Math.Round(By), TPoint.PointCreationType.screen); MObject4 = new GraphicalRegion(left, right); }
public ScreenLineCircle(TPoint center, double objectScale = 1.0) { this.InitializeComponent(); //resize to objectScale this.Width = this.Width*objectScale; this.Height = this.Height*objectScale; //calculate x and y values of the upper left corner _x = (int)Math.Round(center.ScreenX - (this.Width / 2)); _y = (int)Math.Round(center.ScreenY - (this.Height / 2)); }
public static TPoint GetDepthCoordsfromScreen(TPoint screenPoint) { //Rewind the move double X = screenPoint.ScreenX - SettingsManager.ScreenMappingSet.MoveX; double Y = screenPoint.ScreenY - SettingsManager.ScreenMappingSet.MoveY; //Re-scale int x = (int)Math.Round(X / SettingsManager.ScreenMappingSet.ScaleX); int y = (int)Math.Round(Y / SettingsManager.ScreenMappingSet.ScaleY); return new TPoint(x,y,TPoint.PointCreationType.depth); }
public ScreenLineArrow(Vector direction, TPoint Center, double scale) { InitializeComponent(); _center = Center; this.Width = 96 * scale; this.Height = 40*scale; double angle = ScreenMathHelper.VectorToDegree(direction) - 90.0; RotateTransform rt = new RotateTransform(angle); this.RenderTransform = rt; }
public ScreenCircle() { this.InitializeComponent(); _center = new TPoint(0, 0, TPoint.PointCreationType.screen); _rotationTimer = new DispatcherTimer(); _rotationTimer.Interval = new TimeSpan(0, 0, 0, 0, 50); _rotationTimer.Tick += new EventHandler(OnRotationTimerTick); _rotationTimer.IsEnabled = true; SettingsManager.ScreenMappingSet.OnScreenSettingsUpdate += new ScreenMappingSettings.ScreenSettingsUpdateHandler(ScreenMappingSettings_OnScreenSettingsUpdate); }
public ScreenLine(TPoint source, TPoint destination, EScreenLineElementType lineElementTypeType = EScreenLineElementType.Circle) { this.InitializeComponent(); _source = source; _destination = destination; _lineElementType = lineElementTypeType; //Bind to screenSettingsUpdate event SettingsManager.ScreenMappingSet.OnScreenSettingsUpdate += new Code.PositionMapping.ScreenMappingSettings.ScreenSettingsUpdateHandler(ScreenMappingSet_OnScreenSettingsUpdate); CalculateLine(); }
private void ChangePosition() { //Recalculate the screen position if depthPosition is given if ((_center.DepthX != 0) || (_center.DepthY != 0)) { _center = PositionMapper.GetScreenCoordsfromDepth(_center); } int x = (int)Math.Round((double)_center.ScreenX - (this.Width / 2)); int y = (int)Math.Round((double)_center.ScreenY - (this.Height / 2)); //this.Margin = new Thickness(x, y, 0, 0); Canvas.SetLeft(this, x); Canvas.SetTop(this, y); }
public static TPoint GetColorCoordinatesfromDepth(TPoint depth_point, bool CutIntoBounds = false, int distanceFromSensor = -1) { //if the distance is not set (=-1), use the Table distance as an approximation to the real distance if (distanceFromSensor == -1) distanceFromSensor = SettingsManager.RecognitionSet.TableDistance; //if no runtime is assigned, return null if (_kinectController == null) return null; //Calculate the approx. Coordinates with help of the kinect try { _kinectController.GetColorPixelCoordinatesFromDepthPixel(depth_point.DepthX, depth_point.DepthY, (short) distanceFromSensor, out depth_point.ColorX, out depth_point.ColorY); } catch (Exception) { //TODO: adequate catch } //Move accordingly to the settings depth_point.ColorX = depth_point.ColorX + SettingsManager.ScreenMappingSet.ColorMoveX; depth_point.ColorY = depth_point.ColorY + SettingsManager.ScreenMappingSet.ColorMoveY; //If true, check whether the coordinates exeed the bounds if (CutIntoBounds) { int xmax=0, ymax=0; SettingsManager.KinectSet.GetVideoResolution(out xmax, out ymax); if (depth_point.ColorX > xmax - 1) depth_point.ColorX = xmax - 1; if (depth_point.ColorY > ymax - 1) depth_point.ColorY = ymax - 1; if (depth_point.ColorX < 0) depth_point.ColorX = 0; if (depth_point.ColorY < 0) depth_point.ColorY = 0; } return depth_point; }
public ScreenLine(TPoint source, Vector LineVector, EScreenLineElementType lineElementTypeType = EScreenLineElementType.Circle) { this.InitializeComponent(); _source = source; _lineElementType = lineElementTypeType; _destination = new TPoint( Convert.ToInt32(_source.ScreenX + LineVector.X), Convert.ToInt32(_source.ScreenY + LineVector.Y), TPoint.PointCreationType.screen ); //Bind to screenSettingsUpdate event SettingsManager.ScreenMappingSet.OnScreenSettingsUpdate += new Code.PositionMapping.ScreenMappingSettings.ScreenSettingsUpdateHandler(ScreenMappingSet_OnScreenSettingsUpdate); CalculateLine(); }
public ObjectCircle(TPoint Center) { this.InitializeComponent(); _center = Center; //Automatically calculate the screen position if the depthPosition is given; set correct size of the circle _center.CalculateScreenfromDepthCoords(); //update ChangeSize(); _rotationTimer = new DispatcherTimer(); _rotationTimer.Interval = new TimeSpan(0,0,0,0,50); _rotationTimer.Tick += new EventHandler(OnRotationTimerTick); _rotationTimer.IsEnabled = true; RotationSpeed = 20; SettingsManager.ScreenMappingSet.OnScreenSettingsUpdate += new ScreenMappingSettings.ScreenSettingsUpdateHandler(ScreenMappingSettings_OnScreenSettingsUpdate); }
public ScreenCircle(TPoint Center) { this.InitializeComponent(); _center = Center; //Automatically calculate the screen position if the depthPosition is given; set correct size of the circle if ((_center.DepthX != 0) || (_center.DepthY != 0)) { _center = PositionMapper.GetScreenCoordsfromDepth(_center); } //update ChangeSize(); _rotationTimer = new DispatcherTimer(); _rotationTimer.Interval = new TimeSpan(0,0,0,0,50); _rotationTimer.Tick += new EventHandler(OnRotationTimerTick); _rotationTimer.IsEnabled = true; SettingsManager.ScreenMappingSet.OnScreenSettingsUpdate += new ScreenMappingSettings.ScreenSettingsUpdateHandler(ScreenMappingSettings_OnScreenSettingsUpdate); }
/// <summary> /// Updates the object's screenLine /// </summary> /// <param name="obj"></param> /// <param name="_screenLine">the screen line. null, if no screen line exists</param> /// <returns>returns a screen line if a screenline needs to be created</returns> public static ScreenLine UpdateBeam(this SimulationObject obj, ScreenLine _screenLine, SimulationObject destination, Vector Direction) { if (obj.LastTableObject.RotationDefined) { if (_screenLine == null) { //recreate it _screenLine = new ScreenLine(obj.LastTableObject.Center, Direction * 1000, ScreenLine.EScreenLineElementType.Arrow); return _screenLine; } else { //just modify //If destination is set, let the screen line end.if not:infinite if (destination != null) { _screenLine.Source = obj.LastTableObject.Center; _screenLine.Destination = destination.LastTableObject.Center; } else { _screenLine.Source = obj.LastTableObject.Center; TPoint dest = new TPoint( Convert.ToInt32(obj.LastTableObject.Center.ScreenX + Direction.X * 1000), Convert.ToInt32(obj.LastTableObject.Center.ScreenY + Direction.Y * 1000), TPoint.PointCreationType.screen); _screenLine.Destination = dest; } } } return null; }
private void UpdateSecScreenLine(SimulationObject SimO, SimObjGraphicsSettings gfxSet) { if (gfxSet.DrawSecScreenLine && SimO.LastTableObject.RotationDefined) { bool recalculate = false; if (gfxSet.SecScreenLineDest != null) { //Case 1: a target object is set if (gfxSet.SecScreenLineRef == null) { gfxSet.SecScreenLineRef = new ScreenLine(SimO.LastTableObject.Center, gfxSet.SecScreenLineDest.LastTableObject.Center, gfxSet.SecSlElementType); gfxSet.SecScreenLineRef.LineElementColor = gfxSet.SecSlElementColor; _tmgr.DisplayManager.AddElement(gfxSet.SecScreenLineRef, DisplayManager.DisplayLayer.middle); recalculate = true; } else { gfxSet.SecScreenLineRef.LineElementColor = gfxSet.SecSlElementColor; if (!gfxSet.SecScreenLineRef.Source.Equals(SimO.LastTableObject.Center)) { gfxSet.SecScreenLineRef.Source = SimO.LastTableObject.Center; recalculate = true; } if (!gfxSet.SecScreenLineRef.Destination.Equals(gfxSet.SecScreenLineDest.LastTableObject.Center)) { gfxSet.SecScreenLineRef.Destination = gfxSet.SecScreenLineDest.LastTableObject.Center; recalculate = true; } } } else { //Case 2: Use direction Vector if (gfxSet.SecScreenLineRef == null) { gfxSet.SecScreenLineRef = new ScreenLine(SimO.LastTableObject.Center, gfxSet.SecScreenLineDirection, gfxSet.SecSlElementType); gfxSet.SecScreenLineRef.LineElementColor = gfxSet.SecSlElementColor; _tmgr.DisplayManager.AddElement(gfxSet.SecScreenLineRef, DisplayManager.DisplayLayer.middle); recalculate = true; } else { gfxSet.SecScreenLineRef.LineElementColor = gfxSet.SecSlElementColor; if (!gfxSet.SecScreenLineRef.Source.Equals(SimO.LastTableObject.Center)) { gfxSet.SecScreenLineRef.Source = SimO.LastTableObject.Center; recalculate = true; } TPoint dest = new TPoint( Convert.ToInt32(SimO.LastTableObject.Center.ScreenX + gfxSet.SecScreenLineDirection.X * 1000), Convert.ToInt32(SimO.LastTableObject.Center.ScreenY + gfxSet.SecScreenLineDirection.Y * 1000), TPoint.PointCreationType.screen); if (!gfxSet.SecScreenLineRef.Destination.Equals(dest)) { gfxSet.SecScreenLineRef.Destination = dest; recalculate = true; } } } if (recalculate) gfxSet.SecScreenLineRef.CalculateLine(); } else { //Do not draw ScreenLine if (gfxSet.SecScreenLineRef != null) { _tmgr.DisplayManager.DeleteElement(gfxSet.SecScreenLineRef); gfxSet.SecScreenLineRef = null; } } }
public ScreenLine() { this.InitializeComponent(); _source = new TPoint(0, 0, TPoint.PointCreationType.screen); _destination = new TPoint(0, 0, TPoint.PointCreationType.screen); }
private void p_img_MouseClick(object sender, MouseEventArgs e) { //Add to Calibrationpoints Point mpoint = new Point(e.X, e.Y); TPoint tp = new TPoint(mpoint.X, mpoint.Y, TPoint.PointCreationType.depth); _calibrationPoints.Add(tp); Update(); }
private void AddScreenCircle(TPoint center) { ScreenLineCircle c = new ScreenLineCircle(center,SettingsManager.ScreenMappingSet.DisplayObjectScale); switch (_lineElementColor) { case EScreenLineElementColor.Blue: c.el_fill.Fill = (GradientBrush)c.Resources["gradient_blue"]; break; case EScreenLineElementColor.Green: c.el_fill.Fill = (GradientBrush)c.Resources["gradient_green"]; break; case EScreenLineElementColor.Red: c.el_fill.Fill = (GradientBrush)c.Resources["gradient_red"]; break; case EScreenLineElementColor.White: c.el_fill.Fill = (GradientBrush)c.Resources["gradient_white"]; break; case EScreenLineElementColor.Yellow: c.el_fill.Fill = (GradientBrush)c.Resources["gradient_yellow"]; break; } mainCanvas.Children.Add(c); Canvas.SetLeft(c, c.X); Canvas.SetTop(c, c.Y); }
public GraphicalRegion(TPoint TopLeft, TPoint BottomRight) { this.TopLeft = TopLeft; this.BottomRight = BottomRight; }
private void RecalculatePositions() { if ((_source.DepthX != 0) || (_source.DepthY != 0)) { _source = PositionMapper.GetScreenCoordsfromDepth(_source); } if ((_destination.DepthX != 0) || (_destination.DepthY != 0)) { _destination = PositionMapper.GetScreenCoordsfromDepth(_destination); } }
public TPoint Clone() { TPoint p = new TPoint(this.DepthX, this.DepthY, PointCreationType.depth); p.ColorX = ColorX; p.ColorY = ColorY; p.ScreenX = ScreenX; p.ScreenY = ScreenY; p.InitialCreationType = InitialCreationType; return p; }
/// <summary> /// Calculates the element centers of the lineElements /// </summary> /// <param name="height"></param> /// <param name="width"></param> /// <returns></returns> private List<TPoint> CalculateElementCenters(int canvasx, int canvasy) { //Create the direction vector Vector vDirection = new Vector(_destination.ScreenX - _source.ScreenX, _destination.ScreenY - _source.ScreenY); Vector vSource = new Vector(_source.ScreenX - canvasx, _source.ScreenY - canvasy); //Rescale the vector so that it seperates one element from another (according to _lineElementDistance) Vector vElementSpacer = ScreenMathHelper.RescaleVector(vDirection, _lineElementDistance*SettingsManager.ScreenMappingSet.DisplayObjectScale); //the position is calculated by adding n*vElementSpacer to the upperLeftCorner (0|0) until //n*vElementSpacer.Length >= vDirection.Length -> it reached the destination List<TPoint> elementCenters = new List<TPoint>(); int n = 1; while (vDirection.Length >= vElementSpacer.Length*n) { Vector vPosition = vSource + vElementSpacer*n; TPoint p = new TPoint(Convert.ToInt32(vPosition.X), Convert.ToInt32(vPosition.Y), TPoint.PointCreationType.screen); elementCenters.Add(p); n++; } return elementCenters; }
/// <summary> /// Calculates the distance to another Point /// </summary> /// <param name="SecondPoint"></param> /// <param name="layer"></param> /// <returns></returns> public double DistanceTo(TPoint SecondPoint, PointCreationType layer) { int X1=0, X2=0, Y1=0, Y2=0; //Assign coords switch (layer) { case PointCreationType.color: X1 = this.ColorX; Y1 = this.ColorY; X2 = SecondPoint.ColorX; Y2 = SecondPoint.ColorY; break; case PointCreationType.depth: X1 = this.DepthX; Y1 = this.DepthY; X2 = SecondPoint.DepthX; Y2 = SecondPoint.DepthY; break; case PointCreationType.screen: X1 = this.ScreenX; Y1 = this.ScreenY; X2 = SecondPoint.ScreenX; Y2 = SecondPoint.ScreenY; break; } //Calculate distance return Math.Sqrt((X1 - X2)*(X1 - X2) + (Y1 - Y2)*(Y1 - Y2)); }
public static TPoint GetScreenCoordsfromDepth(TPoint depth_point) { //First, scale the coordinates double tmpX = depth_point.DepthX*SettingsManager.ScreenMappingSet.ScaleX; double tmpY = depth_point.DepthY*SettingsManager.ScreenMappingSet.ScaleY; //Move them accoding to the settings depth_point.ScreenX = (int) Math.Round(tmpX + SettingsManager.ScreenMappingSet.MoveX); depth_point.ScreenY = (int) Math.Round(tmpY + SettingsManager.ScreenMappingSet.MoveY); return depth_point; }
private void CalculateRotation(TableObject obj) { TPoint rPoint = null, bPoint = null; //calculate the average values int x = 0, y = 0; int avRed=0, avGreen=0, avBlue=0; for (x = 0; x < obj.ExtractedBitmap.Width - 2; x++) { for (y = 0; y < obj.ExtractedBitmap.Height - 2; y++) { Color c = obj.ExtractedBitmap.GetPixel(x, y); avRed += c.R; avGreen += c.G; avBlue += c.B; } } int Pixels = obj.ExtractedBitmap.Height*obj.ExtractedBitmap.Width; avRed = (int) Math.Round((double)avRed / Pixels); avGreen = (int)Math.Round((double)avGreen / Pixels); avBlue = (int)Math.Round((double)avBlue / Pixels); //check for every suitable point, whether the point itself and at least 7 direct neighbours are red x = 1; y = 1; //The Points at the border have not enought direct neighbours for (x = 1; x < obj.ExtractedBitmap.Width-2; x++) { for (y = 1; y < obj.ExtractedBitmap.Height - 2; y++ ) { if (rPoint == null) { bool red = true; int count = CountPOints(obj, red, y, x,avRed,avBlue,avGreen); if (count >= 7) rPoint = new TPoint(x, y, TPoint.PointCreationType.screen); } } } //Same for blue point for (x = 1; x < obj.ExtractedBitmap.Width - 2; x++) { for (y = 1; y < obj.ExtractedBitmap.Height - 2; y++) { if (bPoint == null) { bool red = false; int count = CountPOints(obj, red, y, x, avRed, avBlue, avGreen); if (count >= 7) bPoint = new TPoint(x, y, TPoint.PointCreationType.screen); } } } //Were two points recognized? if ((rPoint == null) || (bPoint == null)) return; //Calculate the vector x = rPoint.ScreenX - bPoint.ScreenX; y = rPoint.ScreenY - bPoint.ScreenY; obj.DirectionVector = new System.Windows.Vector(x, y); obj.RotationDefined = true; }
private void ChangeSize() { //Automatically calculate the screen position if the depthPosition is given; set correct size of the circle if ((_center.DepthX != 0) || (_center.DepthY != 0)) { _center = PositionMapper.GetScreenCoordsfromDepth(_center); } int x = (int) Math.Round((double)_center.ScreenX - (_size/2)); int y = (int)Math.Round((double)_center.ScreenY - (_size / 2)); //this.Margin = new Thickness(x, y, 0, 0); Canvas.SetLeft(this, x); Canvas.SetTop(this, y); this.Width = _size* SettingsManager.ScreenMappingSet.DisplayObjectScale; Height = _size * SettingsManager.ScreenMappingSet.DisplayObjectScale; }
void ScreenMappingSettings_OnScreenSettingsUpdate() { //use the dispatcher because the event might be from another thread this.Dispatcher.Invoke((Action) (() => { //Recalculate the screen position if depthPosition is given if ((_center.DepthX != 0)||(_center.DepthY != 0)) { _center = PositionMapper.GetScreenCoordsfromDepth(_center); } //update ChangeSize(); })); // (Dispatcher) }
private void AddScreenArrow(TPoint center) { Vector direction = new Vector(_destination.ScreenX - _source.ScreenX, _destination.ScreenY - _source.ScreenY); ScreenLineArrow sla = new ScreenLineArrow(direction, center, SettingsManager.ScreenMappingSet.DisplayObjectScale); mainCanvas.Children.Add(sla); Canvas.SetLeft(sla, sla.X); Canvas.SetTop(sla, sla.Y); }