source: josm/trunk/test/performance/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRendererPerformanceTest.java@ 9773

Last change on this file since 9773 was 9773, checked in by Don-vip, 8 years ago

checkstyle

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/plain
File size: 4.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm.visitor.paint;
3
4import java.awt.Color;
5import java.awt.Graphics2D;
6import java.awt.image.BufferedImage;
7import java.io.File;
8import java.io.FileInputStream;
9import java.io.IOException;
10import java.io.InputStream;
11
12import javax.imageio.ImageIO;
13
14import org.junit.BeforeClass;
15import org.junit.Rule;
16import org.junit.Test;
17import org.junit.rules.Timeout;
18import org.openstreetmap.josm.JOSMFixture;
19import org.openstreetmap.josm.Main;
20import org.openstreetmap.josm.data.Bounds;
21import org.openstreetmap.josm.data.osm.DataSet;
22import org.openstreetmap.josm.gui.NavigatableComponent;
23import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
24import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
25import org.openstreetmap.josm.io.Compression;
26import org.openstreetmap.josm.io.OsmReader;
27
28public class StyledMapRendererPerformanceTest {
29
30 private static final int IMG_WIDTH = 1400;
31 private static final int IMG_HEIGHT = 1050;
32
33 private static Graphics2D g;
34 private static BufferedImage img;
35 private static NavigatableComponent nc;
36 private static DataSet dsRestriction;
37 private static DataSet dsMultipolygon;
38 private static DataSet dsCity;
39
40 /**
41 * Global timeout applied to all test methods.
42 */
43 @Rule
44 public Timeout globalTimeout = Timeout.seconds(15*60);
45
46 @BeforeClass
47 public static void load() throws Exception {
48 JOSMFixture.createPerformanceTestFixture().init(true);
49 img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_ARGB);
50 g = (Graphics2D) img.getGraphics();
51 g.setClip(0, 0, IMG_WIDTH, IMG_WIDTH);
52 g.setColor(Color.BLACK);
53 g.fillRect(0, 0, IMG_WIDTH, IMG_WIDTH);
54 nc = Main.map.mapView;
55 nc.setBounds(0, 0, IMG_WIDTH, IMG_HEIGHT);
56
57 // TODO Test should have it's own copy of styles because change in style can influence performance
58 MapPaintStyles.readFromPreferences();
59
60 try (
61 InputStream fisR = new FileInputStream("data_nodist/restriction.osm");
62 InputStream fisM = new FileInputStream("data_nodist/multipolygon.osm");
63 InputStream fisC = Compression.getUncompressedFileInputStream(new File("data_nodist/neubrandenburg.osm.bz2"));
64 ) {
65 dsRestriction = OsmReader.parseDataSet(fisR, NullProgressMonitor.INSTANCE);
66 dsMultipolygon = OsmReader.parseDataSet(fisM, NullProgressMonitor.INSTANCE);
67 dsCity = OsmReader.parseDataSet(fisC, NullProgressMonitor.INSTANCE);
68 }
69 }
70
71 private static void test(int iterations, DataSet ds, Bounds bounds) throws Exception {
72 Rendering visitor = new StyledMapRenderer(g, nc, false);
73 nc.zoomTo(bounds);
74 for (int i = 0; i < iterations; i++) {
75 visitor.render(ds, true, bounds);
76 }
77 }
78
79 @Test
80 public void testRestriction() throws Exception {
81 test(700, dsRestriction, new Bounds(51.12, 14.147472381591795, 51.128, 14.162492752075195));
82 }
83
84 @Test
85 public void testRestrictionSmall() throws Exception {
86 test(1500, dsRestriction, new Bounds(51.125, 14.147, 51.128, 14.152));
87 }
88
89 @Test
90 public void testMultipolygon() throws Exception {
91 test(400, dsMultipolygon, new Bounds(60, -180, 85, -122));
92 }
93
94 @Test
95 public void testMultipolygonSmall() throws Exception {
96 test(850, dsMultipolygon, new Bounds(-90, -180, 90, 180));
97 }
98
99 @Test
100 public void testCity() throws Exception {
101 test(50, dsCity, new Bounds(53.51, 13.20, 53.59, 13.34));
102 }
103
104 @Test
105 public void testCitySmall() throws Exception {
106 test(70, dsCity, new Bounds(52, 11, 55, 14));
107 }
108
109 @Test
110 public void testCityPart1() throws Exception {
111 test(250, dsCity, new Bounds(53.56, 13.25, 53.57, 13.26));
112 }
113
114 @Test
115 public void testCityPart2() throws Exception {
116 test(200, dsCity, new Bounds(53.55, 13.29, 53.57, 13.30));
117 }
118
119 @Test
120 public void testCitySmallPart2() throws Exception {
121 test(200, dsCity, new Bounds(53.56, 13.295, 53.57, 13.30));
122 }
123
124 /** run this manually to verify that the rendering is set up properly */
125 private void dumpRenderedImage() throws IOException {
126 File outputfile = new File("test-neubrandenburg.png");
127 ImageIO.write(img, "png", outputfile);
128 }
129}
Note: See TracBrowser for help on using the repository browser.