| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.gui.mappaint.mapcss;
|
|---|
| 3 |
|
|---|
| 4 | import static org.junit.Assert.*
|
|---|
| 5 |
|
|---|
| 6 | import java.awt.Graphics2D
|
|---|
| 7 | import java.awt.image.BufferedImage
|
|---|
| 8 |
|
|---|
| 9 | import org.junit.*
|
|---|
| 10 | import org.openstreetmap.josm.JOSMFixture
|
|---|
| 11 | import org.openstreetmap.josm.Main
|
|---|
| 12 | import org.openstreetmap.josm.data.Bounds
|
|---|
| 13 | import org.openstreetmap.josm.data.osm.DataSet
|
|---|
| 14 | import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer
|
|---|
| 15 | import org.openstreetmap.josm.gui.MainApplication
|
|---|
| 16 | import org.openstreetmap.josm.gui.NavigatableComponent
|
|---|
| 17 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles
|
|---|
| 18 | import org.openstreetmap.josm.gui.preferences.SourceEntry
|
|---|
| 19 | import org.openstreetmap.josm.gui.preferences.ToolbarPreferences
|
|---|
| 20 | import org.openstreetmap.josm.io.Compression
|
|---|
| 21 | import org.openstreetmap.josm.io.OsmReader
|
|---|
| 22 |
|
|---|
| 23 | /**
|
|---|
| 24 | * This performance test measures the time for a full run of MapPaintVisitor.visitAll()
|
|---|
| 25 | * against a test data set using a test style.
|
|---|
| 26 | *
|
|---|
| 27 | */
|
|---|
| 28 | class MapCSSPerformanceTest {
|
|---|
| 29 |
|
|---|
| 30 | /* ------------------------ configuration section ---------------------------- */
|
|---|
| 31 | /**
|
|---|
| 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 | */
|
|---|
| 39 | def static DATA_FILE = "data_nodist/neubrandenburg.osm.bz2"
|
|---|
| 40 | /* ------------------------ / configuration section ---------------------------- */
|
|---|
| 41 |
|
|---|
| 42 | def DataSet ds
|
|---|
| 43 |
|
|---|
| 44 | def static boolean checkTestEnvironment() {
|
|---|
| 45 | File f = new File(STYLE_FILE);
|
|---|
| 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 | }
|
|---|
| 50 |
|
|---|
| 51 | @BeforeClass
|
|---|
| 52 | public static void createJOSMFixture() {
|
|---|
| 53 | JOSMFixture.createPerformanceTestFixture().init();
|
|---|
| 54 | Main.toolbar = new ToolbarPreferences();
|
|---|
| 55 | new MainApplication();
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | def timed(Closure c){
|
|---|
| 59 | long before = System.currentTimeMillis()
|
|---|
| 60 | c()
|
|---|
| 61 | long after = System.currentTimeMillis()
|
|---|
| 62 | return after - before
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | def loadStyle() {
|
|---|
| 66 | print "Loading style '$STYLE_FILE' ..."
|
|---|
| 67 | MapCSSStyleSource source = new MapCSSStyleSource(
|
|---|
| 68 | new SourceEntry(
|
|---|
| 69 | STYLE_FILE,
|
|---|
| 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 | }
|
|---|
| 83 |
|
|---|
| 84 | def loadData() {
|
|---|
| 85 | print "Loading data file '$DATA_FILE' ..."
|
|---|
| 86 | ds = OsmReader.parseDataSet(Compression.getUncompressedFileInputStream(new File(DATA_FILE)), null);
|
|---|
| 87 | println "DONE"
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | @Test
|
|---|
| 91 | public void measureTimeForStylePreparation() {
|
|---|
| 92 | loadStyle()
|
|---|
| 93 | loadData()
|
|---|
| 94 |
|
|---|
| 95 | NavigatableComponent mv = new NavigatableComponent();
|
|---|
| 96 | mv.setBounds(0, 0, 1024, 768)
|
|---|
| 97 | BufferedImage img = new BufferedImage(mv.getWidth(), mv.getHeight(), BufferedImage.TYPE_3BYTE_BGR)
|
|---|
| 98 | Graphics2D g = img.createGraphics()
|
|---|
| 99 | g.setClip(0,0, mv.getWidth(), mv.getHeight())
|
|---|
| 100 | StyledMapRenderer visitor = new StyledMapRenderer(g, mv, false)
|
|---|
| 101 |
|
|---|
| 102 | print "Rendering ..."
|
|---|
| 103 | long time = timed {
|
|---|
| 104 | visitor.render(ds, false, new Bounds(-90,-180,90,180))
|
|---|
| 105 | }
|
|---|
| 106 | println "DONE"
|
|---|
| 107 | println "data file : ${DATA_FILE}"
|
|---|
| 108 | println "style file: ${STYLE_FILE}"
|
|---|
| 109 | println ""
|
|---|
| 110 | println "Rendering took $time ms."
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|