public Edge GetJoinEdge(ToothPoint point) { foreach (Edge item in this.Edges) { if (item.StartPoint.OrderNumber == this.OrderNumber && item.EndPoint.OrderNumber == point.OrderNumber) return item; if (item.EndPoint.OrderNumber == this.OrderNumber && item.StartPoint.OrderNumber == point.OrderNumber) return item; } return null; }
public Edge(ToothPoint from, ToothPoint to) { StartPoint = from; EndPoint = to; Distance = (int)Math.Sqrt(((EndPoint.X - StartPoint.X) * (EndPoint.X - StartPoint.X) + (EndPoint.Y - StartPoint.Y) * (EndPoint.Y - StartPoint.Y))); }
private ToothPoint CreateNewCustomPoint() { Point cursorPosition = this.TranslatePoint(Mouse.GetPosition(this), cnvGraph); ToothPoint resultPoint = new ToothPoint() { OrderNumber = _polygon.Points.Count + 1, X = (int)cursorPosition.X, Y = (int)cursorPosition.Y }; return resultPoint; }
private void DrawPoint(ToothPoint point) { Ellipse ellipse = CreateCircleObject(ToothPoint.RADIUS, Color.FromRgb(255, 0, 0), point.X, point.Y); //ellipse.MouseLeftButtonUp += new MouseButtonEventHandler(point_MouseLeftButtonUp); //ellipse.ContextMenu = cnvGraph.ContextMenu; //ellipse.ContextMenuOpening += new ContextMenuEventHandler(ellipse_ContextMenuOpening); ellipse.MouseRightButtonUp += new MouseButtonEventHandler(ellipse_MouseRightButtonUp); if (shouldBeAddedEdge) { AddNewPointToGraph(point); } // DeselecteCurrentShape(); _selectedPoint = ellipse; ellipse.DataContext = point; TextBlock name = new TextBlock(); name.Text = string.Format("({0})", point.OrderNumber.ToString()); name.SetValue(Canvas.TopProperty, (double)(point.Y)); name.SetValue(Canvas.LeftProperty, (double)(point.X + 10)); name.SetValue(Canvas.ZIndexProperty, 1); name.FontSize = 8; SolidColorBrush textBrush = new SolidColorBrush(); textBrush.Color = Color.FromRgb(225, 0, 0); name.Foreground = textBrush; cnvGraph.Children.Add(name); ValidateAuxiliaryPrimitives(); }
private void ClearAuxiliaryPrimitives() { cnvGraph.Children.Remove(SectioningN1); cnvGraph.Children.Remove(SectioningN2); cnvGraph.Children.Remove(ProblemToothWidth); cnvGraph.Children.Remove(NormalToothTangent); cnvGraph.Children.Remove(NearestPointToBoneOnNormalToothEllipse); cnvGraph.Children.Remove(NearestPointOnProblemToothToNormalEllipse); SectioningN1 = null; SectioningN2 = null; ProblemToothWidth = null; NormalToothTangent = null; NearestPointToBoneOnNormalTooth = null; NearestPointOnProblemToothToNormal = null; }
private void CancelFollowingPoints(ToothPoint point, Shape activeShape) { Shape _selectedPointTemp = activeShape; //cnvGraph.Children.Clear(); if (point.OrderNumber > 1) { //Get previous point ToothPoint currentPoint = ((ToothPoint)_selectedPointTemp.DataContext); Edge e = (from c in _polygon.Points[currentPoint.OrderNumber - 2].Edges where c.EndPoint.OrderNumber == currentPoint.OrderNumber select c).SingleOrDefault(); ToothPoint previousPoint = e.StartPoint; foreach (UIElement element in cnvGraph.Children) { if (element is Ellipse && ((Ellipse)element).DataContext == previousPoint) { _selectedPointTemp = (Ellipse)element; break; } } } else { _selectedPointTemp = null; //shouldBeAddedEdge = false; } _polygon.CancelFollowingPoints(point.OrderNumber); //_polygon.DrawGraph(DrawPoint, DrawLine); DrawAllPolygons(false); _selectedPoint = _selectedPointTemp; }
private void CalculateAuxiliaryGeometry() { Point p = Mathematics.FindNearestPoligonPointToGivenPoint( _toothSet.NormalTooth.GetPolygon(), _toothSet.BoneEdge.Points[0].GetPoint()); NearestPointToBoneOnNormalTooth = new ToothPoint(); NearestPointToBoneOnNormalTooth.X = (int)p.X; NearestPointToBoneOnNormalTooth.Y = (int)p.Y; NearestPointOnProblemToothToNormal = FindNearestPointOnProblemToothByAngles(p); Line line = new Line(); line.X1 = NearestPointToBoneOnNormalTooth.X; line.Y1 = NearestPointToBoneOnNormalTooth.Y; line.X2 = NearestPointOnProblemToothToNormal.X; line.Y2 = NearestPointOnProblemToothToNormal.Y; NormalToothTangent = line; //Find tooth split line SectioningN1 = GetSectioningLineN1(NormalToothTangent); //Find tooth split 2 line Point center = Mathematics.GetLineCenter(SectioningN1); ToothPoint tp_betweenRoots = _toothSet.ProblemTooth.Points.Where(x => x.OrderNumber == PointBetweenRootsNumber).Single(); Point betweenRoots = tp_betweenRoots.GetPoint(); SectioningN2 = new Line(); SectioningN2.X1 = center.X; SectioningN2.Y1 = center.Y; SectioningN2.X2 = tp_betweenRoots.X; SectioningN2.Y2 = tp_betweenRoots.Y; //Find problem tooth width ProblemToothWidth = FindProblemToothWidthLine(); }
private void AddPoint(ToothPoint point) { if (_polygon.Points.Count == _polygon.MaxPoligonPointsNumber) { return; } //ToothPoint point = CreateNewCustomPoint(); shouldBeAddedEdge = true; DrawPoint(point); shouldBeAddedEdge = false; }
private void AddNewPointToGraph(ToothPoint point) { if (_selectedPoint != null) { ToothPoint selectedPoint = _selectedPoint.DataContext as ToothPoint; if (selectedPoint != null) { _polygon.Points.Add(point); Edge edge = new Edge(selectedPoint, point); selectedPoint.Edges.Add(edge); point.Edges.Add(edge); DrawLine(edge, point.OrderNumber == _polygon.MaxPoligonPointsNumber); if (point.OrderNumber == _polygon.MaxPoligonPointsNumber) { Edge finalEdge = new Edge(point, (ToothPoint)_polygon.Points[0]); point.Edges.Add(finalEdge); ((ToothPoint)_polygon.Points[0]).Edges.Add(finalEdge); DrawLine(finalEdge); shouldBeAddedEdge = false; DrawAllPolygons(); } } } else { _polygon.Points.Add(point); } }