Skip to content

Commit d02fe7d

Browse files
authored
Optimize clipping calls #1661 (#1662)
1 parent b4d8c2b commit d02fe7d

58 files changed

Lines changed: 759 additions & 1154 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ All notable changes to this project will be documented in this file.
6868
- `AngleAxis` has position `AxisPosition.All` by default (#1574)
6969
- Clipping API changed from SetClip(...) and ResetClip() to PushClip(...) and PopClip() (#1593)
7070
- Remove TileMapAnnotation examples from automated testing (#1667)
71+
- Optimize clipping calls (#1661)
72+
- Mark CandleStickAndVolumeSeries as obsolete (#1661)
7173

7274
### Removed
7375
- Remove PlotModel.Legends (#644)
@@ -80,6 +82,8 @@ All notable changes to this project will be documented in this file.
8082
- Axis.UpdateFromSeries(...) and Series.UpdateValidData() (#741)
8183
- Support for IRenderContext implementations without native clipping (#1593)
8284
- CohenSutherlandClipping and SutherlandHodgmanClipping (#1593)
85+
- DrawClippedXxx(...) extensions in RenderingExtensions (#1661)
86+
- PathAnnotation.ClipText property - text is now always clipped (#1661)
8387

8488
### Fixed
8589
- Legend font size is not affected by DefaultFontSize (#1396)

Source/Examples/ExampleLibrary/Annotations/TileMapAnnotation.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ public TileMapAnnotation()
105105
/// <param name="rc">The render context.</param>
106106
public override void Render(IRenderContext rc)
107107
{
108-
base.Render(rc);
109-
110108
var lon0 = this.XAxis.ActualMinimum;
111109
var lon1 = this.XAxis.ActualMaximum;
112110
var lat0 = this.YAxis.ActualMinimum;
@@ -166,7 +164,7 @@ public override void Render(IRenderContext rc)
166164
var r = OxyRect.Create(s00.X, s00.Y, s11.X, s11.Y);
167165

168166
// draw the image
169-
rc.DrawClippedImage(clippingRectangle, img, r.Left, r.Top, r.Width, r.Height, this.Opacity, true);
167+
rc.DrawImage(img, r.Left, r.Top, r.Width, r.Height, this.Opacity, true);
170168
}
171169
}
172170

Source/Examples/ExampleLibrary/CustomSeries/ErrorSeries.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ public override void Render(IRenderContext rc)
7272

7373
this.VerifyAxes();
7474

75-
var clippingRect = this.GetClippingRect();
76-
7775
int n = points.Count;
7876

7977
// Transform all points to screen coordinates
@@ -114,8 +112,7 @@ public override void Render(IRenderContext rc)
114112
// clip the line segments with the clipping rectangle
115113
for (int i = 0; i + 1 < segments.Count; i += 2)
116114
{
117-
rc.DrawClippedLine(
118-
clippingRect,
115+
rc.DrawReducedLine(
119116
new[] { segments[i], segments[i + 1] },
120117
2,
121118
this.GetSelectableColor(this.Color),

Source/Examples/ExampleLibrary/CustomSeries/LineSegmentSeries.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ public override void Render(IRenderContext rc)
6262
throw new InvalidOperationException("Axis has not been defined.");
6363
}
6464

65-
var clippingRect = this.GetClippingRect();
66-
6765
var screenPoints = Points.Select(this.Transform).ToList();
6866
var verticalLines = new List<ScreenPoint>();
6967

@@ -86,13 +84,13 @@ public override void Render(IRenderContext rc)
8684
{
8785
if (this.LineStyle != LineStyle.None)
8886
{
89-
rc.DrawClippedLineSegments(clippingRect, screenPoints, this.ActualColor, this.StrokeThickness, this.EdgeRenderingMode, this.LineStyle.GetDashArray(), this.LineJoin);
87+
rc.DrawLineSegments(screenPoints, this.ActualColor, this.StrokeThickness, this.EdgeRenderingMode, this.LineStyle.GetDashArray(), this.LineJoin);
9088
}
9189

92-
rc.DrawClippedLineSegments(clippingRect, verticalLines, this.ActualColor, this.StrokeThickness / 3, this.EdgeRenderingMode, LineStyle.Dash.GetDashArray(), this.LineJoin);
90+
rc.DrawLineSegments(verticalLines, this.ActualColor, this.StrokeThickness / 3, this.EdgeRenderingMode, LineStyle.Dash.GetDashArray(), this.LineJoin);
9391
}
9492

95-
rc.DrawMarkers(screenPoints, clippingRect, this.MarkerType, null, this.MarkerSize, this.MarkerFill, this.MarkerStroke, this.MarkerStrokeThickness, this.EdgeRenderingMode);
93+
rc.DrawMarkers(screenPoints, this.MarkerType, null, this.MarkerSize, this.MarkerFill, this.MarkerStroke, this.MarkerStrokeThickness, this.EdgeRenderingMode);
9694
}
9795

9896
/// <summary>

Source/Examples/ExampleLibrary/CustomSeries/MatrixSeries.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,11 @@ public override void Render(IRenderContext rc)
161161
this.image = OxyImage.Create(pixels, ImageFormat.Png);
162162
}
163163

164-
var clip = this.GetClippingRect();
165164
var x0 = Math.Min(p0.X, p1.X);
166165
var y0 = Math.Min(p0.Y, p1.Y);
167166
var w = Math.Abs(p0.X - p1.X);
168167
var h = Math.Abs(p0.Y - p1.Y);
169-
rc.DrawClippedImage(clip, this.image, x0, y0, w, h, 1, false);
168+
rc.DrawImage(this.image, x0, y0, w, h, 1, false);
170169

171170
var points = new List<ScreenPoint>();
172171
if (this.GridInterval > 0)
@@ -197,7 +196,7 @@ public override void Render(IRenderContext rc)
197196
points.Add(this.Transform(n, m));
198197
}
199198

200-
rc.DrawClippedLineSegments(clip, points, this.GridColor, 1, this.EdgeRenderingMode, null, LineJoin.Miter);
199+
rc.DrawLineSegments(points, this.GridColor, 1, this.EdgeRenderingMode, null, LineJoin.Miter);
201200

202201
if (this.BorderColor.IsVisible())
203202
{
@@ -213,7 +212,7 @@ public override void Render(IRenderContext rc)
213212
this.Transform(m, n)
214213
};
215214

216-
rc.DrawClippedLineSegments(clip, borderPoints, this.BorderColor, 1, this.EdgeRenderingMode, null, LineJoin.Miter);
215+
rc.DrawLineSegments(borderPoints, this.BorderColor, 1, this.EdgeRenderingMode, null, LineJoin.Miter);
217216
}
218217
}
219218

Source/Examples/ExampleLibrary/CustomSeries/PolarHeatMapSeries.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ public void RenderDynamic(IRenderContext rc, PlotModel model)
196196
this.image = OxyImage.Create(p, ImageFormat.Png);
197197

198198
// Render the image
199-
var clip = this.GetClippingRect();
200-
rc.DrawClippedImage(clip, this.image, dest.Left, dest.Top, dest.Width, dest.Height, 1, false);
199+
rc.DrawImage(this.image, dest.Left, dest.Top, dest.Width, dest.Height, 1, false);
201200
}
202201

203202
/// <summary>
@@ -287,8 +286,7 @@ public void RenderFixed(IRenderContext rc, PlotModel model)
287286
}
288287

289288
// Render the image
290-
var clip = this.GetClippingRect();
291-
rc.DrawClippedImage(clip, this.image, dest.Left, dest.Top, dest.Width, dest.Height, 1, false);
289+
rc.DrawImage(this.image, dest.Left, dest.Top, dest.Width, dest.Height, 1, false);
292290
}
293291

294292
/// <summary>

Source/Examples/ExampleLibrary/Examples/RenderingCapabilities.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,12 @@ public override void Render(IRenderContext rc)
802802
base.Render(rc);
803803
this.Rendering(rc);
804804
}
805+
806+
/// <inheritdoc/>
807+
public override OxyRect GetClippingRect()
808+
{
809+
return OxyRect.Everything;
810+
}
805811
}
806812
}
807813
}

Source/Examples/ExampleLibrary/Misc/MiscExamples.cs

Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace ExampleLibrary
2323
using OxyPlot.Axes;
2424
using OxyPlot.Series;
2525
using OxyPlot.Legends;
26+
using System.Linq;
2627

2728
[Examples("Misc")]
2829
public static class MiscExamples
@@ -239,19 +240,41 @@ public static PlotModel TrainSchedule()
239240
Title = "Train schedule",
240241
Subtitle = "Bergensbanen (Oslo-Bergen, Norway)",
241242
IsLegendVisible = false,
242-
PlotAreaBorderThickness = new OxyThickness(0),
243-
PlotMargins = new OxyThickness(60, 4, 60, 40)
243+
PlotAreaBorderColor = OxyColors.LightGray,
244244
};
245-
model.Axes.Add(
246-
new LinearAxis
247-
{
248-
Position = AxisPosition.Left,
249-
Minimum = -20,
250-
Maximum = 540,
251-
Title = "Distance from Oslo S",
252-
IsAxisVisible = true,
253-
StringFormat = "0"
254-
});
245+
246+
var distanceAxis = new LinearAxis
247+
{
248+
Position = AxisPosition.Left,
249+
Minimum = -20,
250+
Maximum = 540,
251+
Title = "Distance from Oslo S",
252+
IsAxisVisible = true,
253+
StringFormat = "0",
254+
};
255+
256+
model.Axes.Add(distanceAxis);
257+
258+
var stationAxis = new CustomAxis
259+
{
260+
MajorGridlineStyle = LineStyle.Solid,
261+
MajorGridlineColor = OxyColors.LightGray,
262+
Minimum = distanceAxis.Minimum,
263+
Maximum = distanceAxis.Maximum,
264+
Position = AxisPosition.Right,
265+
IsPanEnabled = false,
266+
IsZoomEnabled = false,
267+
MajorTickSize = 0,
268+
};
269+
270+
distanceAxis.AxisChanged += (sender, e) =>
271+
{
272+
stationAxis.Minimum = distanceAxis.ActualMinimum;
273+
stationAxis.Maximum = distanceAxis.ActualMaximum;
274+
};
275+
276+
model.Axes.Add(stationAxis);
277+
255278
model.Axes.Add(
256279
new TimeSpanAxis
257280
{
@@ -315,23 +338,8 @@ public static PlotModel TrainSchedule()
315338
double x = double.Parse(fields[1], CultureInfo.InvariantCulture);
316339
if (!string.IsNullOrEmpty(fields[0]))
317340
{
318-
// Add a horizontal annotation line for the station
319-
model.Annotations.Add(
320-
new LineAnnotation
321-
{
322-
Type = LineAnnotationType.Horizontal,
323-
Y = x,
324-
Layer = AnnotationLayer.BelowSeries,
325-
LineStyle = LineStyle.Solid,
326-
Color = OxyColors.LightGray,
327-
Text = fields[0] + " ",
328-
TextVerticalAlignment = VerticalAlignment.Middle,
329-
TextLinePosition = 1,
330-
TextMargin = 0,
331-
TextPadding = 4,
332-
ClipText = false,
333-
TextHorizontalAlignment = HorizontalAlignment.Left
334-
});
341+
stationAxis.MajorTicks.Add(x);
342+
stationAxis.Labels.Add(fields[0]);
335343
}
336344

337345
for (int i = 0; i < series.Length; i++)
@@ -389,23 +397,6 @@ public static PlotModel TrainSchedule()
389397
return model;
390398
}
391399

392-
/* [Example("World population")]
393-
public static PlotModel WorldPopulation()
394-
{
395-
WorldPopulationDataSet dataSet;
396-
using (var stream = GetResourceStream("WorldPopulation.xml"))
397-
{
398-
var serializer = new XmlSerializer(typeof(WorldPopulationDataSet));
399-
dataSet = (WorldPopulationDataSet)serializer.Deserialize(stream);
400-
}
401-
402-
var model = new PlotModel { Title = "World population" };
403-
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "millions" });
404-
var series1 = new LineSeries { ItemsSource = dataSet.Items, DataFieldX = "Year", DataFieldY = "Population", StrokeThickness = 3, MarkerType = MarkerType.Circle };
405-
model.Series.Add(series1);
406-
return model;
407-
}*/
408-
409400
[Example("La Linea (AreaSeries)")]
410401
public static PlotModel LaLineaAreaSeries()
411402
{
@@ -2382,21 +2373,23 @@ protected override int Solve(double x0, double y0, int maxIterations)
23822373
}
23832374
}
23842375

2385-
/* [XmlRoot("DataSet")]
2386-
[XmlInclude(typeof(Data))]
2387-
public class WorldPopulationDataSet
2388-
{
2389-
[XmlElement("Data")]
2390-
public List<Data> Items { get; set; }
2376+
private class CustomAxis : LinearAxis
2377+
{
2378+
public IList<double> MajorTicks { get; } = new List<double>();
2379+
public IList<double> MinorTicks { get; } = new List<double>();
2380+
public IList<string> Labels { get; } = new List<string>();
23912381

2392-
public class Data
2393-
{
2394-
[XmlAttribute("Year")]
2395-
public int Year { get; set; }
2382+
public override void GetTickValues(out IList<double> majorLabelValues, out IList<double> majorTickValues, out IList<double> minorTickValues)
2383+
{
2384+
majorTickValues = majorLabelValues = this.MajorTicks.Where(d => d >= this.ActualMinimum && d <= this.ActualMaximum).ToList();
2385+
minorTickValues = this.MinorTicks.Where(d => d >= this.ActualMinimum && d <= this.ActualMaximum).ToList();
2386+
}
2387+
2388+
protected override string FormatValueOverride(double x)
2389+
{
2390+
return this.Labels[this.MajorTicks.IndexOf(x)];
2391+
}
2392+
}
23962393

2397-
[XmlAttribute("Population")]
2398-
public double Population { get; set; }
2399-
}
2400-
}*/
24012394
}
24022395
}

Source/Examples/ExampleLibrary/Utilities/PlotModelUtilities.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public static class PlotModelUtilities
5555
/// </summary>
5656
private static readonly HashSet<Type> NonTransposableDataSpaceAnnotationTypes = new HashSet<Type>
5757
{
58-
typeof(TileMapAnnotation),
5958
};
6059

6160
/// <summary>
@@ -90,18 +89,8 @@ public static bool IsTransposable(this PlotModel model)
9089
{
9190
return (model.Axes.Count > 0 || model.Series.Count > 0)
9291
&& model.Axes.All(a => a.Position != AxisPosition.None)
93-
&& model.Series.All(s =>
94-
{
95-
var type = s.GetType();
96-
return s is XYAxisSeries
97-
&& type.GetTypeInfo().Assembly == typeof(PlotModel).GetTypeInfo().Assembly
98-
&& !NonTransposableSeriesTypes.Contains(type);
99-
})
100-
&& model.Annotations.All(a =>
101-
{
102-
var type = a.GetType();
103-
return !NonTransposableDataSpaceAnnotationTypes.Contains(type);
104-
});
92+
&& model.Series.All(s => s is ITransposablePlotElement && !NonTransposableSeriesTypes.Contains(s.GetType()))
93+
&& model.Annotations.All(a => a is ITransposablePlotElement && !NonTransposableDataSpaceAnnotationTypes.Contains(a.GetType()));
10594
}
10695

10796
/// <summary>

Source/OxyPlot.Tests/Svg/SvgExporterTests.cs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -93,43 +93,5 @@ void ExportModelAndCheckFileExists(PlotModel model, string fileName)
9393
}
9494
}
9595
}
96-
97-
[Test]
98-
public void Export_BoundedTest()
99-
{
100-
const string DestinationDirectory = "SvgExporterTests_Meh";
101-
if (!Directory.Exists(DestinationDirectory))
102-
{
103-
Directory.CreateDirectory(DestinationDirectory);
104-
}
105-
106-
var fileName = "BoundedTest";
107-
var path = Path.Combine(DestinationDirectory, FileNameUtilities.CreateValidFileName(fileName, ".svg"));
108-
109-
var width = 550;
110-
var height = 550;
111-
var whole = new OxyRect(0, 0, width, height);
112-
113-
var rect = new OxyRect(50, 50, 400, 400);
114-
//var model = ExampleLibrary.PolarPlotExamples.ArchimedeanSpiral();
115-
var model = ExampleLibrary.AxisExamples.PositionTier();
116-
model.Title = "Title";
117-
model.Subtitle = "SubTitle";
118-
model.PlotAreaBorderColor = OxyColors.Black;
119-
model.PlotAreaBorderThickness = new OxyThickness(1.0);
120-
var textMeasurer = new PdfRenderContext(width, height, model.Background);
121-
122-
using (var stream = new FileStream(path, FileMode.Create))
123-
using (var rc = new SvgRenderContext(stream, width, height, false, textMeasurer, model.Background, true))
124-
{
125-
((IPlotModel)model).Update(true);
126-
((IPlotModel)model).Render(rc, rect);
127-
rc.DrawClippedRectangle(whole, rect.Inflate(2.0, 2.0), OxyColors.Transparent, OxyColors.Blue, 1.0, EdgeRenderingMode.Adaptive);
128-
rc.DrawClippedRectangle(whole, model.PlotBounds, OxyColors.Transparent, OxyColors.Black, 1.0, EdgeRenderingMode.Adaptive);
129-
rc.DrawClippedRectangle(whole, whole, OxyColors.Transparent, OxyColors.Black, 1.0, EdgeRenderingMode.Adaptive);
130-
rc.Complete();
131-
rc.Flush();
132-
}
133-
}
13496
}
13597
}

0 commit comments

Comments
 (0)