1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm.visitor.paint;
|
---|
3 |
|
---|
4 | import java.awt.Color;
|
---|
5 | import java.awt.Graphics2D;
|
---|
6 | import java.awt.Point;
|
---|
7 | import java.awt.image.BufferedImage;
|
---|
8 | import java.io.File;
|
---|
9 | import java.io.IOException;
|
---|
10 | import java.io.InputStream;
|
---|
11 | import java.nio.file.Files;
|
---|
12 | import java.nio.file.Paths;
|
---|
13 |
|
---|
14 | import javax.imageio.ImageIO;
|
---|
15 |
|
---|
16 | import org.junit.Rule;
|
---|
17 | import org.junit.Test;
|
---|
18 | import org.junit.rules.Timeout;
|
---|
19 | import org.openstreetmap.josm.JOSMFixture;
|
---|
20 | import org.openstreetmap.josm.data.Bounds;
|
---|
21 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
22 | import org.openstreetmap.josm.gui.NavigatableComponent;
|
---|
23 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
24 | import org.openstreetmap.josm.io.Compression;
|
---|
25 | import org.openstreetmap.josm.io.OsmReader;
|
---|
26 |
|
---|
27 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Abstract superclass of {@code StyledMapRendererPerformanceTest} and {@code WireframeMapRendererPerformanceTest}.
|
---|
31 | */
|
---|
32 | public abstract class AbstractMapRendererPerformanceTestParent {
|
---|
33 |
|
---|
34 | private static final int IMG_WIDTH = 1400;
|
---|
35 | private static final int IMG_HEIGHT = 1050;
|
---|
36 |
|
---|
37 | @SuppressFBWarnings(value = "MS_PKGPROTECT")
|
---|
38 | protected static Graphics2D g;
|
---|
39 | @SuppressFBWarnings(value = "MS_PKGPROTECT")
|
---|
40 | protected static BufferedImage img;
|
---|
41 | @SuppressFBWarnings(value = "MS_PKGPROTECT")
|
---|
42 | protected static NavigatableComponent nc;
|
---|
43 | private static DataSet dsRestriction;
|
---|
44 | private static DataSet dsMultipolygon;
|
---|
45 | private static DataSet dsOverpass;
|
---|
46 | private static DataSet dsCity;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Global timeout applied to all test methods.
|
---|
50 | */
|
---|
51 | @Rule
|
---|
52 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
53 | public Timeout globalTimeout = Timeout.seconds(15*60);
|
---|
54 |
|
---|
55 | protected static void load() throws Exception {
|
---|
56 | JOSMFixture.createPerformanceTestFixture().init(true);
|
---|
57 | img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_ARGB);
|
---|
58 | g = (Graphics2D) img.getGraphics();
|
---|
59 | g.setClip(0, 0, IMG_WIDTH, IMG_HEIGHT);
|
---|
60 | g.setColor(Color.BLACK);
|
---|
61 | g.fillRect(0, 0, IMG_WIDTH, IMG_HEIGHT);
|
---|
62 | nc = new NavigatableComponent() {
|
---|
63 | {
|
---|
64 | setBounds(0, 0, IMG_WIDTH, IMG_HEIGHT);
|
---|
65 | updateLocationState();
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Override
|
---|
69 | protected boolean isVisibleOnScreen() {
|
---|
70 | return true;
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Override
|
---|
74 | public Point getLocationOnScreen() {
|
---|
75 | return new Point(0, 0);
|
---|
76 | }
|
---|
77 | };
|
---|
78 |
|
---|
79 | // Force reset of preferences
|
---|
80 | StyledMapRenderer.PREFERENCE_ANTIALIASING_USE.put(true);
|
---|
81 | StyledMapRenderer.PREFERENCE_TEXT_ANTIALIASING.put("gasp");
|
---|
82 |
|
---|
83 | try (InputStream fisR = Files.newInputStream(Paths.get("nodist/data/restriction.osm"));
|
---|
84 | InputStream fisM = Files.newInputStream(Paths.get("nodist/data/multipolygon.osm"));
|
---|
85 | InputStream fisC = Compression.getUncompressedFileInputStream(new File("nodist/data/neubrandenburg.osm.bz2"));
|
---|
86 | InputStream fisO = Compression.getUncompressedFileInputStream(new File("nodist/data/overpass-download.osm.bz2"));) {
|
---|
87 | dsRestriction = OsmReader.parseDataSet(fisR, NullProgressMonitor.INSTANCE);
|
---|
88 | dsMultipolygon = OsmReader.parseDataSet(fisM, NullProgressMonitor.INSTANCE);
|
---|
89 | dsCity = OsmReader.parseDataSet(fisC, NullProgressMonitor.INSTANCE);
|
---|
90 | dsOverpass = OsmReader.parseDataSet(fisO, NullProgressMonitor.INSTANCE);
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | protected static void clean() throws Exception {
|
---|
95 | g = null;
|
---|
96 | img = null;
|
---|
97 | nc = null;
|
---|
98 | dsRestriction = null;
|
---|
99 | dsMultipolygon = null;
|
---|
100 | dsCity = null;
|
---|
101 | }
|
---|
102 |
|
---|
103 | protected abstract Rendering buildRenderer();
|
---|
104 |
|
---|
105 | protected final void test(int iterations, DataSet ds, Bounds bounds) throws Exception {
|
---|
106 | nc.zoomTo(bounds);
|
---|
107 | Rendering visitor = buildRenderer();
|
---|
108 | for (int i = 0; i < iterations; i++) {
|
---|
109 | visitor.render(ds, true, bounds);
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | @Test
|
---|
114 | public void testRestriction() throws Exception {
|
---|
115 | test(700, dsRestriction, new Bounds(51.12, 14.147472381591795, 51.128, 14.162492752075195));
|
---|
116 | }
|
---|
117 |
|
---|
118 | @Test
|
---|
119 | public void testRestrictionSmall() throws Exception {
|
---|
120 | test(1500, dsRestriction, new Bounds(51.125, 14.147, 51.128, 14.152));
|
---|
121 | }
|
---|
122 |
|
---|
123 | @Test
|
---|
124 | public void testMultipolygon() throws Exception {
|
---|
125 | test(400, dsMultipolygon, new Bounds(60, -180, 85, -122));
|
---|
126 | }
|
---|
127 |
|
---|
128 | @Test
|
---|
129 | public void testMultipolygonSmall() throws Exception {
|
---|
130 | test(850, dsMultipolygon, new Bounds(-90, -180, 90, 180));
|
---|
131 | }
|
---|
132 |
|
---|
133 | @Test
|
---|
134 | /**
|
---|
135 | * Complex polygon (Lake Ontario) with small download area.
|
---|
136 | */
|
---|
137 | public void testOverpassDownload() throws Exception {
|
---|
138 | test(20, dsOverpass, new Bounds(43.4510496, -76.536684, 43.4643202, -76.4954853));
|
---|
139 | }
|
---|
140 |
|
---|
141 | @Test
|
---|
142 | public void testCity() throws Exception {
|
---|
143 | test(50, dsCity, new Bounds(53.51, 13.20, 53.59, 13.34));
|
---|
144 | }
|
---|
145 |
|
---|
146 | @Test
|
---|
147 | public void testCitySmall() throws Exception {
|
---|
148 | test(70, dsCity, new Bounds(52, 11, 55, 14));
|
---|
149 | }
|
---|
150 |
|
---|
151 | @Test
|
---|
152 | public void testCityPart1() throws Exception {
|
---|
153 | test(250, dsCity, new Bounds(53.56, 13.25, 53.57, 13.26));
|
---|
154 | }
|
---|
155 |
|
---|
156 | @Test
|
---|
157 | public void testCityPart2() throws Exception {
|
---|
158 | test(200, dsCity, new Bounds(53.55, 13.29, 53.57, 13.30));
|
---|
159 | }
|
---|
160 |
|
---|
161 | @Test
|
---|
162 | public void testCitySmallPart2() throws Exception {
|
---|
163 | test(200, dsCity, new Bounds(53.56, 13.295, 53.57, 13.30));
|
---|
164 | }
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * run this manually to verify that the rendering is set up properly
|
---|
168 | * @throws IOException if any I/O error occurs
|
---|
169 | */
|
---|
170 | @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD")
|
---|
171 | private void dumpRenderedImage() throws IOException {
|
---|
172 | ImageIO.write(img, "png", new File("test-neubrandenburg.png"));
|
---|
173 | }
|
---|
174 | }
|
---|