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