[4074] | 1 | // License: GPL. For details, see LICENSE file. |
---|
[7068] | 2 | package org.openstreetmap.josm.gui.mappaint.mapcss; |
---|
[4074] | 3 | |
---|
| 4 | import static org.junit.Assert.* |
---|
| 5 | |
---|
| 6 | import java.awt.Graphics2D |
---|
| 7 | import java.awt.image.BufferedImage |
---|
| 8 | |
---|
| 9 | import org.junit.* |
---|
[7142] | 10 | import org.openstreetmap.josm.JOSMFixture |
---|
[4074] | 11 | import org.openstreetmap.josm.Main |
---|
| 12 | import org.openstreetmap.josm.data.Bounds |
---|
| 13 | import org.openstreetmap.josm.data.osm.DataSet |
---|
[4087] | 14 | import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer |
---|
[4074] | 15 | import org.openstreetmap.josm.gui.MainApplication |
---|
[7142] | 16 | import org.openstreetmap.josm.gui.NavigatableComponent |
---|
[4074] | 17 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles |
---|
| 18 | import org.openstreetmap.josm.gui.preferences.SourceEntry |
---|
[7142] | 19 | import org.openstreetmap.josm.gui.preferences.ToolbarPreferences |
---|
[7141] | 20 | import org.openstreetmap.josm.io.Compression |
---|
[4074] | 21 | import org.openstreetmap.josm.io.OsmReader |
---|
| 22 | |
---|
| 23 | /** |
---|
[7068] | 24 | * This performance test measures the time for a full run of MapPaintVisitor.visitAll() |
---|
[4074] | 25 | * against a test data set using a test style. |
---|
[7068] | 26 | * |
---|
[4074] | 27 | */ |
---|
[7068] | 28 | class MapCSSPerformanceTest { |
---|
[4074] | 29 | |
---|
| 30 | /* ------------------------ configuration section ---------------------------- */ |
---|
| 31 | /** |
---|
[7068] | 32 | * The path to the style file used for rendering. |
---|
| 33 | */ |
---|
| 34 | def static STYLE_FILE="styles/standard/elemstyles.mapcss" |
---|
| 35 | |
---|
| 36 | /** |
---|
| 37 | * The data file to be rendered |
---|
| 38 | */ |
---|
[7141] | 39 | def static DATA_FILE = "data_nodist/neubrandenburg.osm.bz2" |
---|
[7068] | 40 | /* ------------------------ / configuration section ---------------------------- */ |
---|
| 41 | |
---|
[4074] | 42 | def DataSet ds |
---|
[7068] | 43 | |
---|
[4074] | 44 | def static boolean checkTestEnvironment() { |
---|
[7142] | 45 | File f = new File(STYLE_FILE); |
---|
[4074] | 46 | if ( !f.isFile() || ! f.exists()) { |
---|
| 47 | fail("STYLE_FILE refers to '${STYLE_FILE}. This is either not a file or doesn't exist.\nPlease update configuration settings in the unit test file.") |
---|
| 48 | } |
---|
| 49 | } |
---|
[7068] | 50 | |
---|
[4074] | 51 | @BeforeClass |
---|
[7142] | 52 | public static void createJOSMFixture() { |
---|
| 53 | JOSMFixture.createPerformanceTestFixture().init(); |
---|
| 54 | Main.toolbar = new ToolbarPreferences(); |
---|
| 55 | new MainApplication(); |
---|
[4074] | 56 | } |
---|
[7068] | 57 | |
---|
[4074] | 58 | def timed(Closure c){ |
---|
| 59 | long before = System.currentTimeMillis() |
---|
| 60 | c() |
---|
| 61 | long after = System.currentTimeMillis() |
---|
| 62 | return after - before |
---|
| 63 | } |
---|
[7068] | 64 | |
---|
[7142] | 65 | def loadStyle() { |
---|
[4074] | 66 | print "Loading style '$STYLE_FILE' ..." |
---|
| 67 | MapCSSStyleSource source = new MapCSSStyleSource( |
---|
| 68 | new SourceEntry( |
---|
[7141] | 69 | STYLE_FILE, |
---|
[4074] | 70 | "test style", |
---|
| 71 | "a test style", |
---|
| 72 | true // active |
---|
| 73 | ) |
---|
| 74 | ) |
---|
| 75 | source.loadStyleSource() |
---|
| 76 | if (!source.errors.isEmpty()) { |
---|
| 77 | fail("Failed to load style file ''${STYLE_FILE}''. Errors: ${source.errors}") |
---|
| 78 | } |
---|
| 79 | MapPaintStyles.getStyles().clear() |
---|
| 80 | MapPaintStyles.getStyles().add(source) |
---|
| 81 | println "DONE" |
---|
| 82 | } |
---|
[7068] | 83 | |
---|
[4074] | 84 | def loadData() { |
---|
| 85 | print "Loading data file '$DATA_FILE' ..." |
---|
[7141] | 86 | ds = OsmReader.parseDataSet(Compression.getUncompressedFileInputStream(new File(DATA_FILE)), null); |
---|
[4074] | 87 | println "DONE" |
---|
| 88 | } |
---|
[7068] | 89 | |
---|
[4074] | 90 | @Test |
---|
| 91 | public void measureTimeForStylePreparation() { |
---|
| 92 | loadStyle() |
---|
| 93 | loadData() |
---|
[7068] | 94 | |
---|
[7142] | 95 | NavigatableComponent mv = new NavigatableComponent(); |
---|
| 96 | mv.setBounds(0, 0, 1024, 768) |
---|
[7109] | 97 | BufferedImage img = new BufferedImage(mv.getWidth(), mv.getHeight(), BufferedImage.TYPE_3BYTE_BGR) |
---|
[4074] | 98 | Graphics2D g = img.createGraphics() |
---|
| 99 | g.setClip(0,0, mv.getWidth(), mv.getHeight()) |
---|
[7142] | 100 | StyledMapRenderer visitor = new StyledMapRenderer(g, mv, false) |
---|
[4074] | 101 | |
---|
| 102 | print "Rendering ..." |
---|
| 103 | long time = timed { |
---|
[4087] | 104 | visitor.render(ds, false, new Bounds(-90,-180,90,180)) |
---|
[4074] | 105 | } |
---|
| 106 | println "DONE" |
---|
| 107 | println "data file : ${DATA_FILE}" |
---|
| 108 | println "style file: ${STYLE_FILE}" |
---|
| 109 | println "" |
---|
[7068] | 110 | println "Rendering took $time ms." |
---|
[4074] | 111 | } |
---|
| 112 | } |
---|