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