From edb9a87c564fbe9a254c9fa5ece9f53a15c364dd Mon Sep 17 00:00:00 2001 From: Nate Jensen Date: Thu, 18 Apr 2013 12:15:18 -0500 Subject: [PATCH] Issue #1916 fast rendering of CWAT Local Threat Change-Id: Ia8129ac6a81f35b1ed4aca19edfb21022cee2344 Former-commit-id: 91fbdd4ad1338d30708369d1f4ebd42274d96c92 [formerly 91fbdd4ad1338d30708369d1f4ebd42274d96c92 [formerly 66a036b90f75a844cbeed3eb1a483ccdc72ec11d]] Former-commit-id: 74edcf77066b8e20ad5e58b3c9e3ccf32542dd06 Former-commit-id: 22f54ab95ee0d496ce6eb8cf5e79526a405ee8ef --- .../resource/CWATLocalThreatResource.java | 111 ++++++++---------- 1 file changed, 48 insertions(+), 63 deletions(-) diff --git a/cave/com.raytheon.uf.viz.monitor.scan/src/com/raytheon/uf/viz/monitor/scan/resource/CWATLocalThreatResource.java b/cave/com.raytheon.uf.viz.monitor.scan/src/com/raytheon/uf/viz/monitor/scan/resource/CWATLocalThreatResource.java index 5dd252a0d7..50ca859700 100644 --- a/cave/com.raytheon.uf.viz.monitor.scan/src/com/raytheon/uf/viz/monitor/scan/resource/CWATLocalThreatResource.java +++ b/cave/com.raytheon.uf.viz.monitor.scan/src/com/raytheon/uf/viz/monitor/scan/resource/CWATLocalThreatResource.java @@ -19,7 +19,11 @@ **/ package com.raytheon.uf.viz.monitor.scan.resource; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.eclipse.swt.graphics.RGB; import org.opengis.referencing.FactoryException; @@ -28,9 +32,11 @@ import org.opengis.referencing.operation.TransformException; import com.raytheon.uf.common.dataplugin.cwat.CWATRecord; import com.raytheon.uf.common.geospatial.ReferencedCoordinate; import com.raytheon.uf.common.monitor.scan.ThreatLocation; +import com.raytheon.uf.common.monitor.scan.ThreatReport; +import com.raytheon.uf.viz.core.DrawableString; import com.raytheon.uf.viz.core.IGraphicsTarget; import com.raytheon.uf.viz.core.IGraphicsTarget.HorizontalAlignment; -import com.raytheon.uf.viz.core.IGraphicsTarget.LineStyle; +import com.raytheon.uf.viz.core.IGraphicsTarget.PointStyle; import com.raytheon.uf.viz.core.IGraphicsTarget.TextStyle; import com.raytheon.uf.viz.core.IGraphicsTarget.VerticalAlignment; import com.raytheon.uf.viz.core.PixelCoverage; @@ -39,7 +45,6 @@ import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.rsc.LoadProperties; import com.raytheon.uf.viz.core.rsc.capabilities.ColorableCapability; import com.raytheon.uf.viz.core.rsc.capabilities.MagnificationCapability; -import com.raytheon.uf.viz.core.rsc.capabilities.OutlineCapability; import com.raytheon.uf.viz.cwat.CWATResource; import com.vividsolutions.jts.geom.Coordinate; @@ -52,6 +57,8 @@ import com.vividsolutions.jts.geom.Coordinate; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Oct 13, 2009 2307 dhladky Initial creation + * Apr 18, 2013 1916 njensen Bulk rendering + * * * * @@ -61,36 +68,27 @@ import com.vividsolutions.jts.geom.Coordinate; public class CWATLocalThreatResource extends CWATResource { - private int lineWidth = 0; - private static final int BOX_HEIGHT = 10; private static final int BOX_WIDTH = 10; private RGB color; - private double previousZoom = 0.0; - private PaintProperties myPaintProps; - protected HashMap drawables = new HashMap(); + protected Map drawables = new HashMap(); public CWATLocalThreatResource(CWATLocalThreatResourceData data, LoadProperties props) { - super(data, props); } @Override protected void paintInternal(IGraphicsTarget target, PaintProperties paintProps) throws VizException { - this.displayedDataTime = paintProps.getDataTime(); this.myPaintProps = paintProps; this.record = resourceData.dataObjectMap.get(this.displayedDataTime); - - this.lineWidth = this.getCapability(OutlineCapability.class) - .getOutlineWidth(); this.color = this.getCapability(ColorableCapability.class).getColor(); if (record == null) { @@ -103,26 +101,12 @@ public class CWATLocalThreatResource extends CWATResource { } if (record.getThreats() != null && drawables != null) { - drawables.clear(); - previousZoom = myPaintProps.getZoomLevel(); - this.previousDataTime = displayedDataTime; - - for (ThreatLocation loc : record.getThreats().keySet()) { + Set keyset = record.getThreats().keySet(); + for (ThreatLocation loc : keyset) { drawables.put(loc, getPixelCoverage(loc)); } - - if (record != null && drawables != null && target != null) { - for (ThreatLocation loc : record.getThreats().keySet()) { - if (drawables.containsKey(loc)) { - drawSquare(loc, drawables.get(loc), target); - } else { - PixelCoverage pc = getPixelCoverage(loc); - drawables.put(loc, pc); - drawSquare(loc, pc, target); - } - } - } + drawSquares(keyset, target); } } @@ -182,47 +166,48 @@ public class CWATLocalThreatResource extends CWATResource { } /** - * Draw the square and whatever else it needs + * Draws all the squares and selectively draws the location names if there + * is a threat * - * @param loc - * @param pc + * @param locs * @param target - * @param paintProps * @throws VizException */ - private void drawSquare(ThreatLocation loc, PixelCoverage pc, - IGraphicsTarget target) throws VizException { - font.setMagnification(getCapability(MagnificationCapability.class) - .getMagnification().floatValue()); - if (record.getThreats() != null && record.getThreats().containsKey(loc)) { + private void drawSquares(Set locs, IGraphicsTarget target) + throws VizException { + float mag = getCapability(MagnificationCapability.class) + .getMagnification().floatValue(); + font.setMagnification(mag); + Map recordThreats = record.getThreats(); + List points = new ArrayList(locs.size()); + List strings = new ArrayList( + locs.size()); + for (ThreatLocation loc : locs) { + // get the point for drawing in bulk + PixelCoverage pc = drawables.get(loc); if (pc != null) { - if (!record.getThreats().get(loc).isThreat()) { - target.drawLine(pc.getLl().x, pc.getLl().y, 0.0, - pc.getUl().x, pc.getUl().y, 0.0, color, lineWidth, - LineStyle.SOLID); - target.drawLine(pc.getUl().x, pc.getUl().y, 0.0, - pc.getUr().x, pc.getUr().y, 0.0, color, lineWidth, - LineStyle.SOLID); - target.drawLine(pc.getUr().x, pc.getUr().y, 0.0, - pc.getLr().x, pc.getLr().y, 0.0, color, lineWidth, - LineStyle.SOLID); - target.drawLine(pc.getLr().x, pc.getLr().y, 0.0, - pc.getLl().x, pc.getLl().y, 0.0, color, lineWidth, - LineStyle.SOLID); - } - // System.out.p - if (record.getThreats().get(loc) != null) { - if (record.getThreats().get(loc).isThreat()) { - double[] center = descriptor.worldToPixel(new double[] { - loc.getLon(), loc.getLat() }); - target.drawString(font, loc.getLocationName(), - center[0], center[1], 0.0, TextStyle.BOXED, - color, HorizontalAlignment.CENTER, - VerticalAlignment.MIDDLE, 0.0); - } - } + points.add(pc.getExtent().getCenter()); + } + + // if a threat, prepare it to draw in bulk + ThreatReport report = recordThreats.get(loc); + if (report != null && report.isThreat()) { + DrawableString ds = new DrawableString(loc.getLocationName(), + color); + ds.horizontalAlignment = HorizontalAlignment.CENTER; + ds.font = font; + ds.textStyle = TextStyle.BOXED; + ds.verticallAlignment = VerticalAlignment.MIDDLE; + double[] center = descriptor.worldToPixel(new double[] { + loc.getLon(), loc.getLat() }); + ds.setCoordinates(center[0], center[1]); + strings.add(ds); } } + + // now draw everything in bulk + target.drawPoints(points, color, PointStyle.BOX, mag); + target.drawStrings(strings); } /**