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