1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.awt.Graphics2D;
|
---|
5 | import java.awt.image.BufferedImage;
|
---|
6 | import java.io.FileInputStream;
|
---|
7 |
|
---|
8 | import org.junit.BeforeClass;
|
---|
9 | import org.junit.Test;
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.data.Bounds;
|
---|
12 | import org.openstreetmap.josm.data.osm.visitor.paint.Rendering;
|
---|
13 | import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
|
---|
14 | import org.openstreetmap.josm.data.projection.Projections;
|
---|
15 | import org.openstreetmap.josm.gui.NavigatableComponent;
|
---|
16 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
|
---|
17 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
18 | import org.openstreetmap.josm.io.OsmReader;
|
---|
19 |
|
---|
20 | public class MapPaintVisitorPerformanceTest {
|
---|
21 |
|
---|
22 | private static final int IMG_WIDTH = 1400;
|
---|
23 | private static final int IMG_HEIGHT = 1050;
|
---|
24 |
|
---|
25 | private static Graphics2D g;
|
---|
26 | private static BufferedImage img;
|
---|
27 | private static NavigatableComponent nc;
|
---|
28 | private static DataSet dsRestriction;
|
---|
29 | private static DataSet dsMultipolygon;
|
---|
30 | private static DataSet dsCity;
|
---|
31 |
|
---|
32 | @BeforeClass
|
---|
33 | public static void load() throws Exception {
|
---|
34 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
|
---|
35 | img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_3BYTE_BGR);
|
---|
36 | g = (Graphics2D)img.getGraphics();
|
---|
37 | nc = new NavigatableComponent();
|
---|
38 | nc.setBounds(0, 0, IMG_WIDTH, IMG_HEIGHT);
|
---|
39 |
|
---|
40 | // TODO Test should have it's own copy of styles because change in style can influence performance
|
---|
41 | Main.pref.load();
|
---|
42 | MapPaintStyles.readFromPreferences();
|
---|
43 |
|
---|
44 | dsRestriction = OsmReader.parseDataSet(new FileInputStream("data_nodist/restriction.osm"), NullProgressMonitor.INSTANCE);
|
---|
45 | dsMultipolygon = OsmReader.parseDataSet(new FileInputStream("data_nodist/multipolygon.osm"), NullProgressMonitor.INSTANCE);
|
---|
46 | dsCity = OsmReader.parseDataSet(new FileInputStream("data_nodist/neubrandenburg.osm"), NullProgressMonitor.INSTANCE);
|
---|
47 |
|
---|
48 | // Warm up
|
---|
49 | new MapPaintVisitorPerformanceTest().testRestrictionSmall();
|
---|
50 | new MapPaintVisitorPerformanceTest().testCity();
|
---|
51 | }
|
---|
52 |
|
---|
53 | private static void test(int iterations, DataSet ds, Bounds bounds) throws Exception {
|
---|
54 | Rendering visitor = new StyledMapRenderer(g,nc,false);
|
---|
55 | nc.zoomTo(bounds);
|
---|
56 | for (int i=0; i<iterations; i++) {
|
---|
57 | visitor.render(ds, true, bounds);
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Test
|
---|
62 | public void testRestriction() throws Exception {
|
---|
63 | test(700, dsRestriction, new Bounds(51.12, 14.147472381591795, 51.128, 14.162492752075195));
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Test
|
---|
67 | public void testRestrictionSmall() throws Exception {
|
---|
68 | test(1500, dsRestriction, new Bounds(51.125, 14.147, 51.128, 14.152));
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Test
|
---|
72 | public void testMultipolygon() throws Exception {
|
---|
73 | test(400, dsMultipolygon, new Bounds(60, -180, 85, -122));
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Test
|
---|
77 | public void testMultipolygonSmall() throws Exception {
|
---|
78 | test(850, dsMultipolygon, new Bounds(-90, -180, 90, 180));
|
---|
79 | }
|
---|
80 |
|
---|
81 | @Test
|
---|
82 | public void testCity() throws Exception {
|
---|
83 | test(50, dsCity, new Bounds(53.51, 13.20, 53.59, 13.34));
|
---|
84 | }
|
---|
85 |
|
---|
86 | @Test
|
---|
87 | public void testCitySmall() throws Exception {
|
---|
88 | test(70, dsCity, new Bounds(52, 11, 55, 14));
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Test
|
---|
92 | public void testCityPart1() throws Exception {
|
---|
93 | test(250, dsCity, new Bounds(53.56, 13.25, 53.57, 13.26));
|
---|
94 | }
|
---|
95 |
|
---|
96 | @Test
|
---|
97 | public void testCityPart2() throws Exception {
|
---|
98 | test(200, dsCity, new Bounds(53.55, 13.29, 53.57, 13.30));
|
---|
99 | }
|
---|
100 |
|
---|
101 | @Test
|
---|
102 | public void testCitySmallPart2() throws Exception {
|
---|
103 | test(200, dsCity, new Bounds(53.56, 13.295, 53.57, 13.30));
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 | }
|
---|