protected override void OnRenderCore(DrawingContext dc, RenderState state) { if (DataSource == null) return; var transform = Plotter2D.Viewport.Transform; Rect bounds = Rect.Empty; using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext())) { Point point = new Point(); while (enumerator.MoveNext()) { enumerator.GetCurrent(ref point); enumerator.ApplyMappings(this); Point zero = new Point(point.X, 0); Point screenPoint = point.DataToScreen(transform); Point screenZero = zero.DataToScreen(transform); double height = screenPoint.Y = screenZero.Y; height = (height >= 0) ? height : -height; dc.DrawRectangle(Fill, new Pen(Stroke, StrokeThickness), new Rect(screenPoint.X - BarWidth / 2, screenZero.Y, BarWidth, height)); bounds = Rect.Union(bounds, point); } } ContentBounds = bounds; }
public override void Render(DrawingContext dc, Point screenPoint) { Point dataPoint = screenPoint.ScreenToData(this.ct.Transform); Point dataPointZero = new Point(dataPoint.X,0.0); Point screenPointZero = dataPointZero.DataToScreen(this.ct.Transform); //const double verticalShift = 5; // px //dc.DrawLine(new Pen(Brushes.Black, 1), Point.Add(screenPoint, new Vector(0, 40)), screenPoint); double pointx = screenPointZero.X + 2; double pointy = screenPointZero.Y + 2; FormattedText textToDraw = new FormattedText(dataPoint.Y.ToString("0.000"), Thread.CurrentThread.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 12, Brushes.Black); dc.DrawText(textToDraw, new Point(pointx, pointy)); /* string svalue = dataPoint.Y.ToString("0.000"); foreach (var s in svalue) { if (s.Equals('.')) continue; FormattedText textToDraw = new FormattedText(s.ToString(), Thread.CurrentThread.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 12, Brushes.Black); dc.DrawText(textToDraw, new Point(pointx,pointy)); pointy = pointy + 10; } * */ }
public override void Render(DrawingContext dc, Point screenPoint) { Point dataPoint = screenPoint.ScreenToData(this.ct.Transform); Point dataPointZero = new Point(dataPoint.X, 0.0); Point screenPointZero = dataPointZero.DataToScreen(this.ct.Transform); //const double verticalShift = 5; // px //dc.DrawLine(new Pen(Brushes.Black, 1), Point.Add(screenPoint, new Vector(0, 40)), screenPoint); double pointx = screenPointZero.X + 2; double pointy = screenPointZero.Y + 13; FormattedText textToDraw = new FormattedText(dataPoint.Y.ToString("0.0"), Thread.CurrentThread.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 12, Brushes.Black); dc.DrawText(textToDraw, new Point(pointx, pointy)); /* * string svalue = dataPoint.Y.ToString("0.000"); * foreach (var s in svalue) * { * if (s.Equals('.')) * continue; * FormattedText textToDraw = new FormattedText(s.ToString(), Thread.CurrentThread.CurrentCulture, * FlowDirection.LeftToRight, new Typeface("Arial"), 12, Brushes.Black); * dc.DrawText(textToDraw, new Point(pointx,pointy)); * pointy = pointy + 10; * * } * */ }
protected override void OnRenderCore(DrawingContext dc, RenderState state) { // base.OnRenderCore if (DataSource == null) return; if (Marker == null) return; var left = Viewport.Visible.Location.X; var right = Viewport.Visible.Location.X + Viewport.Visible.Size.Width; var top = Viewport.Visible.Location.Y; var bottom = Viewport.Visible.Location.Y + Viewport.Visible.Size.Height; var transform = Plotter2D.Viewport.Transform; DataRect bounds = DataRect.Empty; using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext())) { Point point = new Point(); while (enumerator.MoveNext()) { enumerator.GetCurrent(ref point); if (point.X >= left && point.X <= right && point.Y >= top && point.Y <= bottom) { enumerator.ApplyMappings(Marker); Point screenPoint = point.DataToScreen(transform); bounds = DataRect.Union(bounds, point); Marker.Render(dc, screenPoint); } } } Viewport2D.SetContentBounds(this, bounds); }
protected override void OnRenderCore(DrawingContext dc, RenderState state) { if (DataSource == null) { return; } if (Marker == null) { return; } var transform = Plotter2D.Viewport.Transform; Rect bounds = Rect.Empty; using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext())) { Point point = new Point(); while (enumerator.MoveNext()) { enumerator.GetCurrent(ref point); enumerator.ApplyMappings(Marker); //Point screenPoint = point.Transform(state.Visible, state.Output); Point screenPoint = point.DataToScreen(transform); bounds = Rect.Union(bounds, point); Marker.Render(dc, screenPoint); } } ContentBounds = bounds; }
protected override void OnRenderCore(DrawingContext dc, RenderState state) { if (DataSource == null) { return; } var transform = Plotter2D.Viewport.Transform; Rect bounds = Rect.Empty; using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext())) { Point point = new Point(); while (enumerator.MoveNext()) { enumerator.GetCurrent(ref point); enumerator.ApplyMappings(this); Point zero = new Point(point.X, 0); Point screenPoint = point.DataToScreen(transform); Point screenZero = zero.DataToScreen(transform); double height = screenPoint.Y = screenZero.Y; height = (height >= 0) ? height : -height; dc.DrawRectangle(Fill, new Pen(Stroke, StrokeThickness), new Rect(screenPoint.X - BarWidth / 2, screenZero.Y, BarWidth, height)); bounds = Rect.Union(bounds, point); } } ContentBounds = bounds; }
protected override void OnRenderCore(DrawingContext dc, RenderState state) { if (DataSource == null) { markers.Clear(); canvas.Children.Clear(); return; } if (Marker == null) { return; } var transform = Viewport.Transform; if (markers.Count == 0) { Rect bounds = Rect.Empty; using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext())) { Point point = new Point(); while (enumerator.MoveNext()) { enumerator.GetCurrent(ref point); enumerator.ApplyMappings(Marker); Point screenPoint = point.DataToScreen(transform); if (!screenPoint.IsFinite()) { continue; } bounds = Rect.Union(bounds, point); UIElement marker = Marker.CreateMarker(); Marker.SetPosition(marker, screenPoint); // todo было раскомментировано. Сделать хранение маркеров и добавление их на плоттер. canvas.Children.Add(marker); markers.Add(marker); } } ContentBounds = bounds; } else { int index = 0; using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext())) { Point point = new Point(); while (enumerator.MoveNext()) { enumerator.GetCurrent(ref point); Point screenPoint = point.DataToScreen(transform); Marker.SetPosition(markers[index++], screenPoint); } } } }
protected override void OnRenderCore(DrawingContext dc, RenderState state) { if (Marker == null) { return; } if (DataSource == null) // No data is specified { if (canvas != null) { foreach (UIElement child in canvas.Children) { unused.Add(child); } canvas.Children.Clear(); } } else // There is some data { int index = 0; var transform = GetTransform(); using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext())) { Point point = new Point(); while (enumerator.MoveNext()) { enumerator.GetCurrent(ref point); enumerator.ApplyMappings(Marker); if (index >= canvas.Children.Count) { UIElement newMarker; if (unused.Count > 0) { newMarker = unused[unused.Count - 1]; unused.RemoveAt(unused.Count - 1); } else { newMarker = Marker.CreateMarker(); } canvas.Children.Add(newMarker); } Marker.SetMarkerProperties(canvas.Children[index]); Point screenPoint = point.DataToScreen(transform); Marker.SetPosition(canvas.Children[index], screenPoint); index++; } while (index < canvas.Children.Count) { unused.Add(canvas.Children[index]); canvas.Children.RemoveAt(index); } } } }
private void UpdateUIRepresentation(Point mousePosInData) { if (Plotter2D == null) { return; } var transform = Plotter2D.Viewport.Transform; DataRect visible = Plotter2D.Viewport.Visible; Rect output = Plotter2D.Viewport.Output; Point mousePos = mousePosInData.DataToScreen(transform); if (!output.Contains(mousePos)) { if (autoHide) { circleGrid.Visibility = Visibility.Hidden; } return; } var xText = ((Func <string>)(() => { double xValue = mousePosInData.X; var text = xTextMapping?.Invoke(xValue); // doesnot have xTextMapping or it returned null text = text ?? GetRoundedValue(visible.XMin, visible.XMax, xValue); if (!string.IsNullOrEmpty(customXFormat)) { text = string.Format(customXFormat, text); } return(text); })).Invoke(); var yText = ((Func <string>)(() => { double yValue = mousePosInData.Y; var text = yTextMapping?.Invoke(yValue); // doesnot have xTextMapping or it returned null text = text ?? GetRoundedValue(visible.YMin, visible.YMax, yValue); if (!string.IsNullOrEmpty(customYFormat)) { text = string.Format(customYFormat, text); } return(text); })).Invoke(); Canvas.SetLeft(circleGrid, mousePos.X); Canvas.SetTop(circleGrid, mousePos.Y); coordTextBlock.Text = $"{xText},{yText}"; }
private static Rect GetElementBounds(CoordinateTransform transform, UIElement child) { Point p1 = GetPoint1(child); Point p2 = GetPoint2(child); Point p1Screen = p1.DataToScreen(transform); Point p2Screen = p2.DataToScreen(transform); Rect bounds = new Rect(p1Screen, p2Screen); return(bounds); }
protected override void UpdateUIRepresentationCore() { if (Plotter == null) { return; } var transform = Plotter.Viewport.Transform; Point p1 = StartPoint.DataToScreen(transform); Point p2 = EndPoint.DataToScreen(transform); lineGeometry.StartPoint = p1; lineGeometry.EndPoint = p2; }
public void SelectNearest(Point coord) { // convert everything to screen coordinates to get the visually closest line var cursor = coord.DataToScreen(Plotter2D.Transform); RadioBandLine closest = null; double closestDistance = double.MaxValue; foreach (var line in GetLines()) { Point leftPoint = new Point(line.Start, line.GroupAxisCoord).DataToScreen(Plotter2D.Transform); Point rightPoint = new Point(line.End, line.GroupAxisCoord).DataToScreen(Plotter2D.Transform); double distance = MathHelper.DistancePointToSegment(cursor, (leftPoint, rightPoint)).distance; if (distance < closestDistance) { closestDistance = distance; closest = line; } line.IsSelected = false; } closest.IsSelected = true; }
private void UpdateUIRepresentation(Point mousePosInData) { if (Plotter2D == null) { return; } var transform = Plotter2D.Viewport.Transform; DataRect visible = Plotter2D.Viewport.Visible; Rect output = Plotter2D.Viewport.Output; Point mousePos = mousePosInData.DataToScreen(transform); if (!output.Contains(mousePos)) { circleGrid.Visibility = Visibility.Hidden; return; } var xText = ((Func <string>)(() => { double xValue = mousePosInData.X; return(xValue.ToEngineeringNotation() + "Hz"); })).Invoke(); var yText = ((Func <string>)(() => { double yValue = mousePosInData.Y; string text = (Plotter2D as RadioBandChartPlotter)?.GetGroupID(yValue) ?? ""; return(text); })).Invoke(); Canvas.SetLeft(circleGrid, mousePos.X); Canvas.SetTop(circleGrid, mousePos.Y); coordTextBlock.Text = $"{xText} {yText}"; }
protected override void OnRenderCore(DrawingContext dc, RenderState state) { if (DataSource == null) { return; } if (Marker == null) { return; } if (Marker.markers == null) { return; } var transform = Plotter2D.Viewport.Transform; DataRect bounds = DataRect.Empty; IEnumerable <Point> ps = GetPoints();//实际值 List <Point> buf = new List <Point>(ps); if (buf.Count < 1) { return; } double xstart = buf[0].X; foreach (MarkersPoint mp in Marker.markers) { try { int idx = (int)((mp.x - xstart) / Step.len); Point screenPoint = buf[idx].DataToScreen(transform); bounds = DataRect.Union(bounds, buf[idx]); Marker.Render(dc, screenPoint, mp);//画标记 } catch (Exception ex) { return; } } Viewport2D.SetContentBounds(this, bounds); return; using (IPointEnumerator enumerator = DataSource.GetEnumerator(GetContext())) { Point point = new Point(); int i = 0; while (enumerator.MoveNext()) { enumerator.GetCurrent(ref point); if (!Marker.markers.Contains(new MarkersPoint { x = (float)point.X })) { continue; } enumerator.ApplyMappings(Marker); i++; MarkersPoint mp = Marker.markers[i - 1]; //Point screenPoint = point.Transform(state.Visible, state.Output); Point screenPoint = point.DataToScreen(transform); bounds = DataRect.Union(bounds, point); Marker.Render(dc, screenPoint, mp); //画标记 } } Viewport2D.SetContentBounds(this, bounds); }
private void UpdateUIRepresentation(Point mousePos) { if (Plotter2D == null) return; var transform = Plotter2D.Viewport.Transform; DataRect visible = Plotter2D.Viewport.Visible; Rect output = Plotter2D.Viewport.Output; if (!output.Contains(mousePos)) { if (autoHide) { horizGrid.Visibility = horizLine.Visibility = vertGrid.Visibility = vertLine.Visibility = Visibility.Hidden; } return; } if (!followMouse) { mousePos = mousePos.DataToScreen(transform); } horizLine.X1 = output.Left; horizLine.X2 = output.Right; horizLine.Y1 = mousePos.Y; horizLine.Y2 = mousePos.Y; vertLine.X1 = mousePos.X; vertLine.X2 = mousePos.X; vertLine.Y1 = output.Top; vertLine.Y2 = output.Bottom; if (UseDashOffset) { horizLine.StrokeDashOffset = (output.Right - mousePos.X) / 2; vertLine.StrokeDashOffset = (output.Bottom - mousePos.Y) / 2; } Point mousePosInData = mousePos.ScreenToData(transform); string text = null; if (showVerticalLine) { double xValue = mousePosInData.X; if (xTextMapping != null) text = xTextMapping(xValue); // doesnot have xTextMapping or it returned null if (text == null) text = GetRoundedValue(visible.XMin, visible.XMax, xValue); if (!String.IsNullOrEmpty(customXFormat)) text = String.Format(customXFormat, text); horizTextBlock.Text = text; } double width = horizGrid.ActualWidth; double x = mousePos.X + blockShift.X; if (x + width > output.Right) { x = mousePos.X - blockShift.X - width; } Canvas.SetLeft(horizGrid, x); if (showHorizontalLine) { double yValue = mousePosInData.Y; text = null; if (yTextMapping != null) text = yTextMapping(yValue); if (text == null) text = GetRoundedValue(visible.YMin, visible.YMax, yValue); if (!String.IsNullOrEmpty(customYFormat)) text = String.Format(customYFormat, text); vertTextBlock.Text = text; } // by default vertGrid is positioned on the top of line. double height = vertGrid.ActualHeight; double y = mousePos.Y - blockShift.Y - height; if (y < output.Top) { y = mousePos.Y + blockShift.Y; } Canvas.SetTop(vertGrid, y); if (followMouse) Position = mousePos; }
private void FillVertexBuffer() { if (DxHost == null) { return; } if (DataSource == null) { return; } if (Palette == null) { return; } if (Device == null) { return; } var dataSource = DataSource; var palette = Palette; var minMax = dataSource.GetMinMax(); var contentBounds = dataSource.GetGridBounds(); Viewport2D.SetContentBounds(this, contentBounds); var transform = Plotter.Transform; vertexCount = DataSource.Width * DataSource.Height; verticesArray = new VertexPosition4Color[vertexCount]; for (int i = 0; i < verticesArray.Length; i++) { int ix = i % DataSource.Width; int iy = i / DataSource.Width; Point point = dataSource.Grid[ix, iy]; double data = dataSource.Data[ix, iy]; double interpolatedData = (data - minMax.Min) / minMax.GetLength(); var color = palette.GetColor(interpolatedData); var pointInScreen = point.DataToScreen(transform); var position = new Vector4((float)pointInScreen.X, (float)pointInScreen.Y, 0.5f, 1); verticesArray[i] = new VertexPosition4Color { Position = position, Color = color.ToArgb() }; } vertexBuffer = new VertexBuffer(Device, vertexCount * VertexPosition4Color.SizeInBytes, Usage.WriteOnly, VertexFormat.Position | VertexFormat.Diffuse, Pool.Default); using (var stream = vertexBuffer.Lock(0, vertexCount * VertexPosition4Color.SizeInBytes, LockFlags.None)) { stream.WriteRange <VertexPosition4Color>(verticesArray); } vertexBuffer.Unlock(); indicesCount = (dataSource.Width - 1) * (dataSource.Height - 1) * 2 * 3; indicesArray = new int[indicesCount]; int index = 0; int width = dataSource.Width; for (int iy = 0; iy < dataSource.Height - 1; iy++) { for (int ix = 0; ix < dataSource.Width - 1; ix++) { indicesArray[index + 0] = ix + 0 + iy * width; indicesArray[index + 1] = ix + 1 + iy * width; indicesArray[index + 2] = ix + (iy + 1) * width; indicesArray[index + 3] = ix + 1 + iy * width; indicesArray[index + 4] = ix + (iy + 1) * width; indicesArray[index + 5] = ix + 1 + (iy + 1) * width; index += 6; } } indexBuffer = new IndexBuffer(Device, indicesCount * sizeof(int), Usage.WriteOnly, Pool.Default, false); using (var stream = indexBuffer.Lock(0, indicesCount * sizeof(int), LockFlags.None)) { stream.WriteRange <int>(indicesArray); } indexBuffer.Unlock(); }
private void UpdateUIRepresentation(Point mousePos) { if (Plotter2D == null) { return; } var transform = Plotter2D.Viewport.Transform; DataRect visible = Plotter2D.Viewport.Visible; Rect output = Plotter2D.Viewport.Output; if (!output.Contains(mousePos)) { if (autoHide) { horizGrid.Visibility = horizLine.Visibility = vertGrid.Visibility = vertLine.Visibility = Visibility.Hidden; } return; } if (!followMouse) { mousePos = mousePos.DataToScreen(transform); } horizLine.X1 = output.Left; horizLine.X2 = output.Right; horizLine.Y1 = mousePos.Y; horizLine.Y2 = mousePos.Y; vertLine.X1 = mousePos.X; vertLine.X2 = mousePos.X; vertLine.Y1 = output.Top; vertLine.Y2 = output.Bottom; if (UseDashOffset) { horizLine.StrokeDashOffset = (output.Right - mousePos.X) / 2; vertLine.StrokeDashOffset = (output.Bottom - mousePos.Y) / 2; } Point mousePosInData = mousePos.ScreenToData(transform); string text = null; if (showVerticalLine) { double xValue = mousePosInData.X; if (xTextMapping != null) { text = xTextMapping(xValue); } // doesnot have xTextMapping or it returned null if (text == null) { text = GetRoundedValue(visible.XMin, visible.XMax, xValue); } if (!String.IsNullOrEmpty(customXFormat)) { text = String.Format(customXFormat, text); } horizTextBlock.Text = text; } double width = horizGrid.ActualWidth; double x = mousePos.X + blockShift.X; if (x + width > output.Right) { x = mousePos.X - blockShift.X - width; } Canvas.SetLeft(horizGrid, x); if (showHorizontalLine) { double yValue = mousePosInData.Y; text = null; if (yTextMapping != null) { text = yTextMapping(yValue); } if (text == null) { text = GetRoundedValue(visible.YMin, visible.YMax, yValue); } if (!String.IsNullOrEmpty(customYFormat)) { text = String.Format(customYFormat, text); } vertTextBlock.Text = text; } // by default vertGrid is positioned on the top of line. double height = vertGrid.ActualHeight; double y = mousePos.Y - blockShift.Y - height; if (y < output.Top) { y = mousePos.Y + blockShift.Y; } Canvas.SetTop(vertGrid, y); if (followMouse) { Position = mousePos; } }
protected void UpdateUIRepresentation(Point mousePosInData, Point cursorPosInData) { if (Plotter2D == null) { return; } var transform = Plotter2D.Viewport.Transform; DataRect visible = Plotter2D.Viewport.Visible; Rect output = Plotter2D.Viewport.Output; Point mousePos = cursorPosInData.DataToScreen(transform); if (!followMouse) { mousePos = mousePos.DataToScreen(transform); } // Ensure coordinates are valid if (!(mousePos.X.IsFinite() && mousePos.Y.IsFinite())) { return; } horizLine.X1 = output.Left; horizLine.X2 = output.Right; horizLine.Y1 = Math.Floor(mousePos.Y) + 0.5; horizLine.Y2 = Math.Floor(mousePos.Y) + 0.5; vertLine.X1 = Math.Floor(mousePos.X) + 0.5; vertLine.X2 = Math.Floor(mousePos.X) + 0.5; vertLine.Y1 = output.Top; vertLine.Y2 = output.Bottom; if (UseDashOffset) { horizLine.StrokeDashOffset = (output.Right - mousePos.X) / 2; vertLine.StrokeDashOffset = (output.Bottom - mousePos.Y) / 2; } string text = null; if (showVerticalLine) { double xValue = cursorPosInData.X; if (xTextMapping != null) { text = xTextMapping(xValue); } // doesnot have xTextMapping or it returned null if (text == null) { text = GetRoundedValue(visible.XMin, visible.XMax, xValue); } if (!string.IsNullOrEmpty(customXFormat)) { text = string.Format(customXFormat, text); } horizTextBlock.Text = text; // Set opacitiy not visiblity to avoid conflicting with the visibility settings horizGrid.Opacity = string.IsNullOrWhiteSpace(text) ? 0 : 1.0; } double width = horizGrid.ActualWidth; double x = mousePos.X + blockShift.X; if (x + width > output.Right) { x = mousePos.X - blockShift.X - width; } Canvas.SetLeft(horizGrid, x); if (showHorizontalLine) { double yValue = cursorPosInData.Y; text = null; if (yTextMapping != null) { text = yTextMapping(yValue); } if (text == null) { text = GetRoundedValue(visible.YMin, visible.YMax, yValue); } if (!string.IsNullOrEmpty(customYFormat)) { text = string.Format(customYFormat, text); } vertTextBlock.Text = text; // Set opacitiy not visiblity to avoid conflicting with the visibility settings vertGrid.Opacity = string.IsNullOrWhiteSpace(text) ? 0 : 1.0; } // by default vertGrid is positioned on the top of line. double height = vertGrid.ActualHeight; double y = mousePos.Y - blockShift.Y - height; if (y < output.Top) { y = mousePos.Y + blockShift.Y; } Canvas.SetTop(vertGrid, y); if (followMouse) { Position = mousePos; } }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); var dc = drawingContext; if (plotter == null) { return; } if (Points == null) { return; } var transform = plotter.Transform; VoronoiMain.main(Points); var lines = Output.LineCollection.OrderBy(line => line.EdgeNumber).ToArray(); var vertices = Output.VertexCollection.OrderBy(vertex => vertex.SiteNumber).ToArray(); var endPoints = Output.EndPointCollection.OrderBy(edge => edge.edgeNumber).ToArray(); Pen linePen = new Pen(Brushes.Black, 1); var segments = new List <Segment>(); for (int i = 0; i < endPoints.Length; i++) { var endPoint = endPoints[i]; var vertexId = endPoint.edgeNumber; var line = lines[vertexId]; var leftId = endPoint.EndPoints[0] != null ? endPoint.EndPoints[0].SiteNumber : -1; var rightId = endPoint.EndPoints[1] != null ? endPoint.EndPoints[1].SiteNumber : -1; Point pLeft = new Point(); Point pRight = new Point(); // at least one endPointId will be != -1 if (rightId == -1) { pLeft = GetSegmentCoordinate(vertices, line, leftId, new Point()); pRight = GetSegmentCoordinate(vertices, line, rightId, pLeft); segments.Add(new Segment { Start = pLeft, End = pRight, InfinityPoint = InfinityPoint.End, Site1 = line.Site1, Site2 = line.Site2 }); } else if (leftId == -1) { pRight = GetSegmentCoordinate(vertices, line, rightId, new Point()); pLeft = GetSegmentCoordinate(vertices, line, leftId, pRight); segments.Add(new Segment { Start = pRight, End = pLeft, InfinityPoint = InfinityPoint.End, Site1 = line.Site1, Site2 = line.Site2 }); } else // leftId != -1 && rightId != -1 { pLeft = GetSegmentCoordinate(vertices, line, leftId, new Point()); pRight = GetSegmentCoordinate(vertices, line, rightId, pLeft); segments.Add(new Segment { Start = pLeft, End = pRight, InfinityPoint = InfinityPoint.None, Site1 = line.Site1, Site2 = line.Site2 }); } pLeft = pLeft.DataToScreen(transform); pRight = pRight.DataToScreen(transform); dc.DrawLine(linePen, pLeft, pRight); } var pointsSequences = GetPointsSequences(segments); foreach (var sequence in pointsSequences) { var pathFigure = new PathFigure { IsClosed = true, IsFilled = true }; pathFigure.StartPoint = sequence.Points.First().DataToScreen(transform); pathFigure.Segments.Add(new PolyLineSegment(sequence.Points.Skip(1).DataToScreen(transform), false)); PathGeometry geometry = new PathGeometry(); geometry.Figures.Add(pathFigure); if (!brushes.ContainsKey(sequence.Site)) { brushes[sequence.Site] = ColorHelper.RandomBrush.MakeTransparent(0.5); } dc.DrawGeometry(brushes[sequence.Site], null, geometry); } }