diff --git a/cave/com.raytheon.uf.viz.acarssounding/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.acarssounding/META-INF/MANIFEST.MF index 79b138768d..f9312037eb 100644 --- a/cave/com.raytheon.uf.viz.acarssounding/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.uf.viz.acarssounding/META-INF/MANIFEST.MF @@ -20,6 +20,7 @@ Import-Package: com.raytheon.edex.meteoLib, com.raytheon.uf.common.pointdata, com.raytheon.uf.common.pointdata.spatial, com.raytheon.uf.common.serialization, + com.raytheon.uf.common.status, com.raytheon.uf.common.time, com.raytheon.uf.viz.core.alerts, com.raytheon.uf.viz.core.catalog, diff --git a/cave/com.raytheon.uf.viz.acarssounding/src/com/raytheon/uf/viz/acarssounding/ACARSSoundingDataCubeAdapter.java b/cave/com.raytheon.uf.viz.acarssounding/src/com/raytheon/uf/viz/acarssounding/ACARSSoundingDataCubeAdapter.java index c72f63b943..b1ce8f2863 100644 --- a/cave/com.raytheon.uf.viz.acarssounding/src/com/raytheon/uf/viz/acarssounding/ACARSSoundingDataCubeAdapter.java +++ b/cave/com.raytheon.uf.viz.acarssounding/src/com/raytheon/uf/viz/acarssounding/ACARSSoundingDataCubeAdapter.java @@ -39,14 +39,19 @@ import com.raytheon.uf.common.datastorage.records.IntegerDataRecord; import com.raytheon.uf.common.datastorage.records.LongDataRecord; import com.raytheon.uf.common.datastorage.records.StringDataRecord; import com.raytheon.uf.common.pointdata.PointDataContainer; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.catalog.ScriptCreator; import com.raytheon.uf.viz.core.comm.Loader; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.derivparam.library.DerivedParameterGenerator; -import com.raytheon.viz.pointdata.util.PointDataCubeAdapter; import com.raytheon.viz.pointdata.util.AbstractPointDataInventory; +import com.raytheon.viz.pointdata.util.PointDataCubeAdapter; public class ACARSSoundingDataCubeAdapter extends PointDataCubeAdapter { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(ACARSSoundingDataCubeAdapter.class); protected static final String REFTIME = AcarsSoundingInventory.REFTIME; @@ -101,11 +106,16 @@ public class ACARSSoundingDataCubeAdapter extends PointDataCubeAdapter { @Override public void initInventory() { - derParLibrary = DerivedParameterGenerator.getDerParLibrary(); if (inventory == null) { AbstractPointDataInventory pointInventory = new AcarsSoundingInventory(); - pointInventory.initTree(derParLibrary); - this.inventory = pointInventory; + try { + pointInventory.initTree(DerivedParameterGenerator + .getDerParLibrary()); + this.inventory = pointInventory; + } catch (VizException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); + } } } diff --git a/cave/com.raytheon.uf.viz.coopprecip/src/com/raytheon/uf/viz/coopprecip/CoopPrecipDataCubeAdapter.java b/cave/com.raytheon.uf.viz.coopprecip/src/com/raytheon/uf/viz/coopprecip/CoopPrecipDataCubeAdapter.java index 854a2afb51..06e022dc1c 100644 --- a/cave/com.raytheon.uf.viz.coopprecip/src/com/raytheon/uf/viz/coopprecip/CoopPrecipDataCubeAdapter.java +++ b/cave/com.raytheon.uf.viz.coopprecip/src/com/raytheon/uf/viz/coopprecip/CoopPrecipDataCubeAdapter.java @@ -82,7 +82,7 @@ public class CoopPrecipDataCubeAdapter implements IDataCubeAdapter { private static final PointDataDescription rtpDescription = new PointDataDescription(); static { - ffgDescription.parameters = new ParameterDescription[8]; + ffgDescription.parameters = new ParameterDescription[9]; ffgDescription.parameters[0] = new ParameterDescription("time", Type.LONG); ffgDescription.parameters[1] = new ParameterDescription("latitude", @@ -98,8 +98,9 @@ public class CoopPrecipDataCubeAdapter implements IDataCubeAdapter { ffgDescription.parameters[6] = new ParameterDescription("stationId", Type.STRING); ffgDescription.parameters[7] = new ParameterDescription("id", Type.INT); + ffgDescription.parameters[8] = new ParameterDescription("dataURI", Type.STRING); - rtpDescription.parameters = new ParameterDescription[6]; + rtpDescription.parameters = new ParameterDescription[7]; rtpDescription.parameters[0] = new ParameterDescription("time", Type.LONG); rtpDescription.parameters[1] = new ParameterDescription("latitude", @@ -111,6 +112,8 @@ public class CoopPrecipDataCubeAdapter implements IDataCubeAdapter { rtpDescription.parameters[4] = new ParameterDescription("stationId", Type.STRING); rtpDescription.parameters[5] = new ParameterDescription("id", Type.INT); + rtpDescription.parameters[6] = new ParameterDescription("dataURI", Type.STRING); + } @Override @@ -238,6 +241,7 @@ public class CoopPrecipDataCubeAdapter implements IDataCubeAdapter { pdv.setFloat("3hr", Float.valueOf(parts[1])); pdv.setFloat("6hr", Float.valueOf(parts[2])); pdv.setString("stationId", station); + pdv.setString("dataURI", "/textPoints/" + station + "/" + time); // TODO this id is not really guaranteed to be unique pdv.setInt("id", ((int) time) + station.hashCode()); } @@ -315,6 +319,7 @@ public class CoopPrecipDataCubeAdapter implements IDataCubeAdapter { pdv.setFloat("latitude", (float) coord.latlon.y); pdv.setFloat("precip", precip); pdv.setString("stationId", station); + pdv.setString("dataURI", "/textPoints/" + station + "/" + time); // TODO this id is not really guaranteed to be unique pdv.setInt("id", ((int) time) + station.hashCode()); } @@ -402,12 +407,6 @@ public class CoopPrecipDataCubeAdapter implements IDataCubeAdapter { return null; } - @Override - public String recordKeyGenerator(PluginDataObject pdo) { - // TODO Auto-generated method stub - return null; - } - @Override public void initInventory() { // TODO Auto-generated method stub diff --git a/cave/com.raytheon.uf.viz.coopprecip/src/com/raytheon/uf/viz/coopprecip/CoopPrecipPlotInfoRetriever.java b/cave/com.raytheon.uf.viz.coopprecip/src/com/raytheon/uf/viz/coopprecip/CoopPrecipPlotInfoRetriever.java index 9c87024166..41b3400cf1 100644 --- a/cave/com.raytheon.uf.viz.coopprecip/src/com/raytheon/uf/viz/coopprecip/CoopPrecipPlotInfoRetriever.java +++ b/cave/com.raytheon.uf.viz.coopprecip/src/com/raytheon/uf/viz/coopprecip/CoopPrecipPlotInfoRetriever.java @@ -69,7 +69,6 @@ public class CoopPrecipPlotInfoRetriever extends AbstractPlotInfoRetriever { for (int uriCounter = 0; uriCounter < pdc.getCurrentSz(); uriCounter++) { PointDataView pdv = pdc.readRandom(uriCounter); PlotInfo stationInfo = new PlotInfo(); - stationInfo.id = pdv.getInt("id"); stationInfo.latitude = pdv.getNumber("latitude").doubleValue(); stationInfo.longitude = pdv.getNumber("longitude") .doubleValue(); @@ -80,6 +79,7 @@ public class CoopPrecipPlotInfoRetriever extends AbstractPlotInfoRetriever { stationInfo.pdv = new PlotData(); } stationInfo.pdv.addData(pdv); + stationInfo.dataURI = pdv.getString("dataURI"); info.add(stationInfo); } } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/AbstractGraphicsFactoryAdapter.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/AbstractGraphicsFactoryAdapter.java index 96dd082b19..56b367fac9 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/AbstractGraphicsFactoryAdapter.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/AbstractGraphicsFactoryAdapter.java @@ -133,11 +133,4 @@ public abstract class AbstractGraphicsFactoryAdapter { public abstract Canvas constrcutCanvas(Composite canvasComp) throws VizException; - /** - * Dispose of the canvas, it can be assumed the canvas is the same type - * created from constructCanvas - * - * @param canvas - */ - public abstract void disposeCanvas(Canvas canvas); } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/DrawableImage.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/DrawableImage.java index 9bb35e7b4e..a562e93c2c 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/DrawableImage.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/DrawableImage.java @@ -45,11 +45,16 @@ public class DrawableImage { private PixelCoverage coverage; - private RasterMode mode = RasterMode.SYNCHRONOUS; + private RasterMode mode; public DrawableImage(IImage image, PixelCoverage coverage) { + this(image, coverage, RasterMode.SYNCHRONOUS); + } + + public DrawableImage(IImage image, PixelCoverage coverage, RasterMode mode) { this.image = image; this.coverage = coverage; + this.mode = mode; } public IImage getImage() { diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java index 5c86a49fdb..172b057d06 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java @@ -39,6 +39,8 @@ import com.raytheon.uf.viz.core.drawables.IRenderableDisplay; import com.raytheon.uf.viz.core.drawables.IShadedShape; import com.raytheon.uf.viz.core.drawables.IWireframeShape; import com.raytheon.uf.viz.core.drawables.PaintProperties; +import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension.IGraphicsExtensionInterface; +import com.raytheon.uf.viz.core.drawables.ext.IImagingExtension; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.geom.PixelCoordinate; import com.vividsolutions.jts.geom.LinearRing; @@ -64,7 +66,7 @@ import com.vividsolutions.jts.geom.LinearRing; * @author chammack * @version 1 */ -public interface IGraphicsTarget { +public interface IGraphicsTarget extends IImagingExtension { /** Defines alignment characteristics */ public static enum HorizontalAlignment { @@ -189,24 +191,6 @@ public interface IGraphicsTarget { public abstract boolean drawRaster(IImage image, PixelCoverage extent, PaintProperties paintProps) throws VizException; - /** - * Draw a raster to a target, given an extent and an alpha (transparency) - * value. Assumes synchronous operation. - * - * This operation will block on unavailable data. - * - * @param image - * the image reference object to draw - * @param extent - * the extent of the drawable area - * @param paintProps - * the paint properties - * @return status whether the raster was able to be drawn - * @throws VizException - */ - public abstract boolean drawRasters(PaintProperties paintProps, - DrawableImage... images) throws VizException; - /** * Draw a raster to a target, given an extent and an alpha (transparency) * value @@ -662,15 +646,6 @@ public interface IGraphicsTarget { */ public abstract boolean isNeedsRefresh(); - /** - * Stage an image - * - * @param image - * the image to stage - * @throws VizException - */ - public abstract void stage(final IImage image) throws VizException; - /** * Sets the background color of the panes. * @@ -680,6 +655,10 @@ public interface IGraphicsTarget { public abstract void setBackgroundColor(RGB backgroundColor); /** + * DEPRECATED: This method has no effect. IGraphicsTargets are not + * responsible to drawing a colorbar. Use method drawColorRamp to draw a + * color ramp + * * Sets whether to display a builtin colorbar when displaying colormapped * images (Defaults to true) * @@ -687,6 +666,7 @@ public interface IGraphicsTarget { * boolean flag indicating whether to display the built in * colorbar */ + @Deprecated public abstract void setUseBuiltinColorbar(boolean isColorbarDisplayed); /** @@ -1044,6 +1024,6 @@ public interface IGraphicsTarget { * @param extensionClass * @return */ - public abstract T getExtension(Class extensionClass) - throws VizException; + public abstract T getExtension( + Class extensionClass) throws VizException; } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/alerts/AlertMessage.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/alerts/AlertMessage.java index ac40526860..8bb925b571 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/alerts/AlertMessage.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/alerts/AlertMessage.java @@ -38,8 +38,6 @@ import java.util.Map; */ public class AlertMessage { - /** The id of the alert */ - public Integer id; /** The raw string dataURI */ public String dataURI; diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/data/prep/Colormapper.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/data/prep/Colormapper.java index 4ad86cc5ba..dcd3e9c86d 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/data/prep/Colormapper.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/data/prep/Colormapper.java @@ -77,8 +77,6 @@ public class Colormapper { boolean log = parameters.isLogarithmic(); double logFactor = parameters.getLogFactor(); boolean mirror = parameters.isMirror(); - double naturalMin = parameters.getDataMin(); - double naturalMax = parameters.getDataMax(); double cmapMin = parameters.getColorMapMin(); double cmapMax = parameters.getColorMapMax(); int colorMapSz = parameters.getColorMap().getSize(); diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/DataCubeContainer.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/DataCubeContainer.java index ab9d43aef9..80ed0d1195 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/DataCubeContainer.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/DataCubeContainer.java @@ -34,7 +34,6 @@ import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataquery.requests.RequestConstraint; import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintType; import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; -import com.raytheon.uf.common.dataquery.requests.TimeQueryRequestSet; import com.raytheon.uf.common.datastorage.Request; import com.raytheon.uf.common.datastorage.StorageException; import com.raytheon.uf.common.datastorage.records.IDataRecord; @@ -42,10 +41,7 @@ import com.raytheon.uf.common.pointdata.PointDataContainer; import com.raytheon.uf.common.time.BinOffset; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.catalog.LayerProperty; -import com.raytheon.uf.viz.core.catalog.ScriptCreator; -import com.raytheon.uf.viz.core.comm.Loader; import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.uf.viz.core.requests.ThriftClient; /** * The DataCubeContainer is responsible for handling requests for data times, @@ -101,7 +97,7 @@ public class DataCubeContainer { if (container.adapter != null) { synchronized (container.adapter) { Boolean initialized = initializedMap.get(container.adapter); - if (!initialized) { + if (initialized == null || !initialized) { container.adapter.initInventory(); initializedMap.put(container.adapter, true); } @@ -121,21 +117,9 @@ public class DataCubeContainer { } } } - } - - private IDataRecord[] getDataRecordInternal(PluginDataObject obj) - throws VizDataCubeException { - if (adapter != null) { - return adapter.getRecord(obj); - } else { - IDataRecord record = null; - try { - record = CubeUtil.retrieveData(obj, pluginName); - } catch (VizException e) { - throw new VizDataCubeException( - "Error retrieving 2D grid record.", e); - } - return new IDataRecord[] { record }; + if (adapter == null) { + // Construct default adapter for plugin if none found + adapter = new DefaultDataCubeAdapter(plugin); } } @@ -153,23 +137,7 @@ public class DataCubeContainer { */ public static IDataRecord[] getDataRecord(PluginDataObject obj) throws VizDataCubeException { - return getInstance(obj.getPluginName()).getDataRecordInternal(obj); - } - - private IDataRecord[] getDataRecordInternal(PluginDataObject obj, - Request req, String dataset) throws VizDataCubeException { - if (adapter != null) { - return adapter.getRecord(obj, req, dataset); - } else { - IDataRecord record = null; - try { - record = CubeUtil.retrieveData(obj, pluginName, req, dataset); - } catch (VizException e) { - throw new VizDataCubeException( - "Error retrieving 2D grid record.", e); - } - return new IDataRecord[] { record }; - } + return getInstance(obj.getPluginName()).adapter.getRecord(obj); } /** @@ -188,29 +156,10 @@ public class DataCubeContainer { */ public static IDataRecord[] getDataRecord(PluginDataObject obj, Request req, String dataset) throws VizDataCubeException { - return getInstance(obj.getPluginName()).getDataRecordInternal(obj, req, + return getInstance(obj.getPluginName()).adapter.getRecord(obj, req, dataset); } - private void getDataRecordsInternal(List objs, - Request req, String dataset) throws VizDataCubeException { - if (adapter != null) { - adapter.getRecords(objs, req, dataset); - } else { - for (PluginDataObject obj : objs) { - IDataRecord record = null; - try { - record = CubeUtil.retrieveData(obj, pluginName, req, - dataset); - } catch (VizException e) { - throw new VizDataCubeException( - "Error retrieving 2D grid record.", e); - } - obj.setMessageData(record); - } - } - } - /** * For each PluginDataObject requests the DataRecords specified by Request * and dataSet and stores those DataRecords in the PluginDataObject message @@ -238,41 +187,25 @@ public class DataCubeContainer { "All PluginDataObjects must be for the same plugin"); } } - getInstance(pluginName).getDataRecordsInternal(objs, req, dataset); - } - - private PointDataContainer getPointDataInternal(String[] params, - Map map) throws VizException { - if (adapter != null) { - return adapter.getPoints(pluginName, params, map); - } else { - return null; - } + getInstance(pluginName).adapter.getRecords(objs, req, dataset); } public static PointDataContainer getPointData(String plugin, String[] params, Map map) throws VizException { - return getInstance(plugin).getPointDataInternal(params, map); - } - - private PointDataContainer getPointDataInternal(String[] params, - String levelKey, Map map) - throws VizException { - if (levelKey == null) { - return getPointData(pluginName, params, map); - } - if (adapter != null) { - return adapter.getPoints(pluginName, params, levelKey, map); - } else { - return null; - } + DataCubeContainer container = getInstance(plugin); + return container.adapter.getPoints(container.pluginName, params, map); } public static PointDataContainer getPointData(String plugin, String[] params, String levelKey, Map map) throws VizException { - return getInstance(plugin).getPointDataInternal(params, levelKey, map); + DataCubeContainer container = getInstance(plugin); + if (levelKey == null) { + return getPointData(container.pluginName, params, map); + } + return container.adapter.getPoints(container.pluginName, params, + levelKey, map); } public static DataTime[] performTimeQuery( @@ -308,20 +241,6 @@ public class DataCubeContainer { new DataTime[0]); } - public List> performTimeQueriesInternal( - List requests) throws VizException { - if (adapter == null) { - TimeQueryRequestSet set = new TimeQueryRequestSet(); - set.setRequests(requests.toArray(new TimeQueryRequest[0])); - @SuppressWarnings("unchecked") - List> result = (List>) ThriftClient - .sendRequest(set); - return result; - } else { - return adapter.timeQuery(requests); - } - } - /** * Perform a bulk time query request when all requests have the same plugin * type. @@ -334,7 +253,7 @@ public class DataCubeContainer { if (requests.isEmpty()) { return Collections.emptyList(); } - return getInstance(pluginName).performTimeQueriesInternal(requests); + return getInstance(pluginName).adapter.timeQuery(requests); } /** @@ -346,8 +265,8 @@ public class DataCubeContainer { */ public static List> performTimeQueries(String pluginName, TimeQueryRequest... requests) throws VizException { - return getInstance(pluginName).performTimeQueriesInternal( - Arrays.asList(requests)); + return getInstance(pluginName).adapter.timeQuery(Arrays + .asList(requests)); } /** @@ -403,17 +322,6 @@ public class DataCubeContainer { return result; } - private synchronized List getDataInternal(LayerProperty property, - int timeOut) throws VizException { - if (adapter == null) { - String scriptToExecute = ScriptCreator.createScript(property); - return Loader - .loadScripts(new String[] { scriptToExecute }, timeOut); - } else { - return adapter.getData(property, timeOut); - } - } - /** * Returns a list of responses for the requested layer property. If a * derived parameter, this will piece together the base parameteters. @@ -432,31 +340,11 @@ public class DataCubeContainer { .getEntryQueryParameters(false); String pluginName = originalQuery.get("pluginName") .getConstraintValue(); - return getInstance(pluginName).getDataInternal(property, timeOut); - } - - private Object getInventoryInternal() { - if (adapter != null) { - return adapter.getInventory(); - } else { - return null; - } + return getInstance(pluginName).adapter.getData(property, timeOut); } public static Object getInventory(String plugin) { - return getInstance(plugin).getInventoryInternal(); - } - - private List> getBaseUpdateConstraintsInternal( - Map constraints) { - if (adapter != null) { - return adapter.getBaseUpdateConstraints(constraints); - } else { - List> result = new ArrayList>( - 1); - result.add(constraints); - return result; - } + return getInstance(plugin).adapter.getInventory(); } public static List> getBaseUpdateConstraints( @@ -467,8 +355,8 @@ public class DataCubeContainer { && pluginRC.getConstraintType() == ConstraintType.EQUALS) { plugin = pluginRC.getConstraintValue(); } - return getInstance(plugin) - .getBaseUpdateConstraintsInternal(constraints); + return getInstance(plugin).adapter + .getBaseUpdateConstraints(constraints); } } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/DecisionTree.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/DecisionTree.java index 66904c0467..2277a48f69 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/DecisionTree.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/DecisionTree.java @@ -383,7 +383,7 @@ public class DecisionTree { } protected List getDataPairs() { - return dataPairs; + return new ArrayList.DataPair>(dataPairs); } private static double calcEntropy(int numExamples, Integer[] values) { diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/DefaultDataCubeAdapter.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/DefaultDataCubeAdapter.java new file mode 100644 index 0000000000..c76bd0db1b --- /dev/null +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/DefaultDataCubeAdapter.java @@ -0,0 +1,239 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.core.datastructure; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.raytheon.uf.common.dataplugin.PluginDataObject; +import com.raytheon.uf.common.dataquery.requests.RequestConstraint; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequestSet; +import com.raytheon.uf.common.datastorage.Request; +import com.raytheon.uf.common.datastorage.records.IDataRecord; +import com.raytheon.uf.common.pointdata.PointDataContainer; +import com.raytheon.uf.common.time.DataTime; +import com.raytheon.uf.viz.core.catalog.LayerProperty; +import com.raytheon.uf.viz.core.catalog.ScriptCreator; +import com.raytheon.uf.viz.core.comm.Loader; +import com.raytheon.uf.viz.core.exception.VizException; +import com.raytheon.uf.viz.core.requests.ThriftClient; + +/** + * Default implementation of IDataCubeAdapter, function implementations were + * moved from DataCubeContainer into here + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 7, 2011            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public class DefaultDataCubeAdapter implements IDataCubeAdapter { + + private String pluginName; + + public DefaultDataCubeAdapter(String pluginName) { + this.pluginName = pluginName; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getSupportedPlugins + * () + */ + @Override + public String[] getSupportedPlugins() { + return new String[] { pluginName }; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#timeQuery(java + * .util.List) + */ + @Override + public List> timeQuery(List requests) + throws VizException { + TimeQueryRequestSet set = new TimeQueryRequestSet(); + set.setRequests(requests.toArray(new TimeQueryRequest[0])); + @SuppressWarnings("unchecked") + List> result = (List>) ThriftClient + .sendRequest(set); + return result; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getPoints(java + * .lang.String, java.lang.String[], java.util.Map) + */ + @Override + public PointDataContainer getPoints(String plugin, String[] parameters, + Map queryParams) throws VizException { + return null; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getPoints(java + * .lang.String, java.lang.String[], java.lang.String, java.util.Map) + */ + @Override + public PointDataContainer getPoints(String plugin, String[] parameters, + String levelKey, Map queryParams) + throws VizException { + return null; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getRecord(com + * .raytheon.uf.common.dataplugin.PluginDataObject) + */ + @Override + public IDataRecord[] getRecord(PluginDataObject obj) + throws VizDataCubeException { + IDataRecord record = null; + try { + record = CubeUtil.retrieveData(obj, pluginName); + } catch (VizException e) { + throw new VizDataCubeException("Error retrieving 2D data record.", + e); + } + return new IDataRecord[] { record }; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getRecord(com + * .raytheon.uf.common.dataplugin.PluginDataObject, + * com.raytheon.uf.common.datastorage.Request, java.lang.String) + */ + @Override + public IDataRecord[] getRecord(PluginDataObject obj, Request req, + String dataset) throws VizDataCubeException { + IDataRecord record = null; + try { + record = CubeUtil.retrieveData(obj, pluginName, req, dataset); + } catch (VizException e) { + throw new VizDataCubeException("Error retrieving 2D data record.", + e); + } + return new IDataRecord[] { record }; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getRecords(java + * .util.List, com.raytheon.uf.common.datastorage.Request, java.lang.String) + */ + @Override + public void getRecords(List objs, Request req, + String dataset) throws VizDataCubeException { + for (PluginDataObject obj : objs) { + IDataRecord record = null; + try { + record = CubeUtil.retrieveData(obj, pluginName, req, dataset); + } catch (VizException e) { + throw new VizDataCubeException( + "Error retrieving 2D grid record.", e); + } + obj.setMessageData(record); + } + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getData(com.raytheon + * .uf.viz.core.catalog.LayerProperty, int) + */ + @Override + public List getData(LayerProperty property, int timeOut) + throws VizException { + String scriptToExecute = ScriptCreator.createScript(property); + return Loader.loadScripts(new String[] { scriptToExecute }, timeOut); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#initInventory() + */ + @Override + public void initInventory() { + // TODO Auto-generated method stub + + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getInventory() + */ + @Override + public Object getInventory() { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter# + * getBaseUpdateConstraints(java.util.Map) + */ + @Override + public List> getBaseUpdateConstraints( + Map constraints) { + List> result = new ArrayList>( + 1); + result.add(constraints); + return result; + } + +} diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/IDataCubeAdapter.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/IDataCubeAdapter.java index 9a46c46216..bfe563f73a 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/IDataCubeAdapter.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/datastructure/IDataCubeAdapter.java @@ -145,16 +145,6 @@ public interface IDataCubeAdapter { public List getData(LayerProperty property, int timeOut) throws VizException; - /** - * A simple method that will create a unique string based on the information - * in the PluginDataObject passed in. - * - * @param pdo - * The PDO to generate a unique name from - * @return A string unique to that PDO - */ - public String recordKeyGenerator(PluginDataObject pdo); - /** * If the inventory for a particular data type is large (for example, Grib), * a call to this method should get a copy of that data type's inventory diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapLoader.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapLoader.java index 51c67cf27a..2de903912e 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapLoader.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapLoader.java @@ -206,8 +206,8 @@ public class ColorMapLoader { ColorMap cm = (ColorMap) SerializationUtil .jaxbUnmarshalFromXmlFile(colorMapFile.getFile() .getAbsolutePath()); - cm.setName(name); + cm.setChanged(false); return cm; } else { return null; diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapParameters.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapParameters.java index e3ea7f9db0..c3cd3ee7bc 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapParameters.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapParameters.java @@ -22,6 +22,8 @@ package com.raytheon.uf.viz.core.drawables; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; import javax.measure.converter.UnitConverter; import javax.measure.unit.Unit; @@ -116,7 +118,7 @@ public class ColorMapParameters implements Cloneable, ISerializableObject { } - protected IColorMapParametersListener listener; + protected Set listeners = new HashSet(); /** Units of the colormap parameters (min/max) */ protected Unit displayUnit; @@ -714,13 +716,19 @@ public class ColorMapParameters implements Cloneable, ISerializableObject { } private void notifyListener() { - if (listener != null) { + for (IColorMapParametersListener listener : listeners) { listener.colorMapChanged(); } } - public void setListener(IColorMapParametersListener listener) { - this.listener = listener; + public void addListener(IColorMapParametersListener listener) { + if (listener != null) { + listeners.add(listener); + } + } + + public void removeListener(IColorMapParametersListener listener) { + listeners.remove(listener); } public void setAlphaMask(byte[] alphaMask) { @@ -741,8 +749,8 @@ public class ColorMapParameters implements Cloneable, ISerializableObject { @Override public int hashCode() { - if (listener != null) { - return listener.hashCode(); + if (listeners.size() > 0) { + return listeners.hashCode(); } else if (colorMap != null) { return colorMap.hashCode(); } else { diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/IImage.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/IImage.java index 4169563fcf..b6ce410f25 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/IImage.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/IImage.java @@ -20,6 +20,9 @@ package com.raytheon.uf.viz.core.drawables; +import com.raytheon.uf.viz.core.drawables.ext.IImagingExtension; +import com.raytheon.uf.viz.core.exception.VizException; + /** * Describes a generic Image resource. The IImage resource is an interface * handle to an image. The image resource manages the lifecycle of the @@ -63,6 +66,11 @@ public interface IImage { UNLOADED, STAGED, LOADED, LOADING, FAILED, INVALID }; + /** + * Stages any data required for the image to load/draw + */ + public abstract void stage() throws VizException; + /** * @return the status */ @@ -106,4 +114,10 @@ public interface IImage { */ public abstract void setContrast(float contrast); + /** + * Gets the extension class for this image + * + * @return + */ + public abstract Class getExtensionClass(); } \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/SingleColorImage.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/SingleColorImage.java deleted file mode 100644 index 44ed0d2e9b..0000000000 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/SingleColorImage.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.raytheon.uf.viz.core.drawables; - -import org.eclipse.swt.graphics.RGB; - -public class SingleColorImage implements IImage { - - private IImage image = null; - - private RGB color = null; - - public IImage getWrappedImage() { - return image; - } - - public void setWrappedImage(IImage image) { - this.image = image; - } - - public void setColor(RGB color) { - this.color = color; - } - - public RGB getColor() { - return color; - } - - public SingleColorImage(IImage image) { - this.image = image; - } - - @Override - public Status getStatus() { - return image.getStatus(); - } - - @Override - public void setInterpolated(boolean isInterpolated) { - image.setInterpolated(isInterpolated); - } - - @Override - public void dispose() { - image.dispose(); - } - - @Override - public int getWidth() { - return image.getWidth(); - } - - @Override - public int getHeight() { - return image.getHeight(); - } - - @Override - public void setBrightness(float brightness) { - image.setBrightness(brightness); - } - - @Override - public void setContrast(float contrast) { - image.setContrast(contrast); - } - -} diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GraphicsExtension.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GraphicsExtension.java index 9e0a79bdd7..7797b6fc56 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GraphicsExtension.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GraphicsExtension.java @@ -40,15 +40,22 @@ import com.raytheon.uf.viz.core.IGraphicsTarget; */ public abstract class GraphicsExtension { - public static enum Compatibilty { - INCOMPATIBLE(-1), GENERIC(0), TARGET_COMPATIBLE(1000), ENHANCED_TARGET_COMPATIBLE( - 2000); + /** + * Interface that other interfaces should extend if they want to be used as + * a graphics extension + */ + public static interface IGraphicsExtensionInterface { - public int value; + } - private Compatibilty(int value) { - this.value = value; - } + public static class Compatibilty { + public static final int INCOMPATIBLE = -1; + + public static final int GENERIC = 0; + + public static final int TARGET_COMPATIBLE = 1000; + + public static final int ENHANCED_TARGET_COMPATIBLE = 2000; } protected T target; @@ -70,7 +77,7 @@ public abstract class GraphicsExtension { try { this.target = (T) target; } catch (ClassCastException e) { - return Compatibilty.INCOMPATIBLE.value; + return Compatibilty.INCOMPATIBLE; } return getCompatibilityValue(this.target); } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GraphicsExtensionManager.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GraphicsExtensionManager.java index a33b5b85b4..1e6baf1694 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GraphicsExtensionManager.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GraphicsExtensionManager.java @@ -15,6 +15,7 @@ import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.IGraphicsTarget; +import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension.IGraphicsExtensionInterface; import com.raytheon.uf.viz.core.exception.VizException; public class GraphicsExtensionManager { @@ -67,8 +68,8 @@ public class GraphicsExtensionManager { * @return * @throws VizException */ - public synchronized T getExtension(Class extensionClass) - throws VizException { + public synchronized T getExtension( + Class extensionClass) throws VizException { if (cached.containsKey(extensionClass)) { return extensionClass.cast(cached.get(extensionClass)); } diff --git a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/CompReflShaderLoader.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/IImagingExtension.java similarity index 53% rename from cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/CompReflShaderLoader.java rename to cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/IImagingExtension.java index ccf30b9e6b..c5ce18bde2 100644 --- a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/CompReflShaderLoader.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/IImagingExtension.java @@ -17,24 +17,23 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.uf.viz.radar.gl.mosaic; +package com.raytheon.uf.viz.core.drawables.ext; -import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.DrawableImage; import com.raytheon.uf.viz.core.drawables.PaintProperties; +import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension.IGraphicsExtensionInterface; import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.viz.core.gl.IGLTarget; -import com.raytheon.viz.core.gl.glsl.AbstractShaderLoader; -import com.raytheon.viz.core.gl.glsl.GLShaderProgram; /** - * TODO Add Description + * Interface extensions that return IImage objects should implement * *
  * 
  * SOFTWARE HISTORY
+ * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * Sep 20, 2010            mschenke     Initial creation
+ * Dec 15, 2011            mschenke     Initial creation
  * 
  * 
* @@ -42,22 +41,17 @@ import com.raytheon.viz.core.gl.glsl.GLShaderProgram; * @version 1.0 */ -public class CompReflShaderLoader extends AbstractShaderLoader { +public interface IImagingExtension extends IGraphicsExtensionInterface { - /* - * (non-Javadoc) + /** + * Draw the images passed in * - * @see - * com.raytheon.viz.core.gl.glsl.IShaderLoader#loadData(com.raytheon.viz - * .core.gl.IGLTarget, com.raytheon.viz.core.gl.glsl.GLShaderProgram, - * com.raytheon.uf.viz.core.drawables.IImage, - * com.raytheon.uf.viz.core.drawables.PaintProperties) + * @param paintProps + * @param images + * @return whether all images were drawn or not + * @throws VizException */ - @Override - public void loadData(IGLTarget target, GLShaderProgram program, - IImage image, PaintProperties paintProps) throws VizException { - // load radar data to GL_TEXTURE0 (bound in drawRaster) - program.setUniform("radarData", 0); - } + public boolean drawRasters(PaintProperties paintProps, + DrawableImage... images) throws VizException; } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/IOffscreenRenderingExtension.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/IOffscreenRenderingExtension.java index 3afc85fd54..778028c21f 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/IOffscreenRenderingExtension.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/IOffscreenRenderingExtension.java @@ -4,9 +4,11 @@ import java.nio.Buffer; import com.raytheon.uf.viz.core.drawables.ColorMapParameters; import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension.IGraphicsExtensionInterface; import com.raytheon.uf.viz.core.exception.VizException; -public interface IOffscreenRenderingExtension { +public interface IOffscreenRenderingExtension extends + IGraphicsExtensionInterface { /** * All drawing between a call to renderOffscreen and the next call to * renderOnscreen will be drawn to offscreenImage rather than to the screen. diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/IShaderLoader.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/ISingleColorImageExtension.java similarity index 62% rename from cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/IShaderLoader.java rename to cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/ISingleColorImageExtension.java index 6d8a0533d8..7040c52203 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/IShaderLoader.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/ISingleColorImageExtension.java @@ -17,52 +17,49 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ +package com.raytheon.uf.viz.core.drawables.ext; -package com.raytheon.viz.core.gl.glsl; +import java.awt.image.RenderedImage; + +import org.eclipse.swt.graphics.RGB; + +import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.exception.VizException; /** - * Define common interface for vertex and fragement shaders. + * Extension for creating images that should be mapped to a single color * *
+ * 
  * SOFTWARE HISTORY
+ * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- *  
+ * Dec 15, 2011            mschenke     Initial creation
  * 
  * 
* - * @author estrabal + * @author mschenke * @version 1.0 */ -import com.raytheon.uf.viz.core.drawables.IImage; -import com.raytheon.uf.viz.core.drawables.PaintProperties; -import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.viz.core.gl.IGLTarget; +public interface ISingleColorImageExtension extends IImagingExtension { -public interface IShaderLoader { + public static interface ISingleColorImage extends IImage { + + public void setColor(RGB color); + + } /** + * Construct an ISingleColorImage image that maps the image passed into to + * the single color value * - * @return - */ - public abstract String getName(); - - /** - * - * @param name - */ - public abstract void setName(String name); - - /** - * load shader variables using IImage and PaintProperties - * - * @param target - * @param program * @param image - * @param paintProps + * @param color + * @return * @throws VizException */ - public abstract void loadData(IGLTarget target, GLShaderProgram program, - IImage image, PaintProperties paintProps) throws VizException; + public ISingleColorImage constructImage(RenderedImage image, RGB color); + } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/ColormappedImage.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/ColormappedImage.java new file mode 100644 index 0000000000..465f2c3ecd --- /dev/null +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/ColormappedImage.java @@ -0,0 +1,240 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.core.drawables.ext.colormap; + +import java.awt.image.RenderedImage; + +import com.raytheon.uf.viz.core.IGraphicsTarget; +import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback; +import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback.ColorMapData; +import com.raytheon.uf.viz.core.data.IRenderedImageCallback; +import com.raytheon.uf.viz.core.data.prep.Colormapper; +import com.raytheon.uf.viz.core.drawables.ColorMapParameters; +import com.raytheon.uf.viz.core.drawables.IColorMapParametersListener; +import com.raytheon.uf.viz.core.drawables.IColormappedImage; +import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.drawables.ext.IImagingExtension; +import com.raytheon.uf.viz.core.exception.VizException; + +/** + * General colormapped image, regenerates image if parameters change + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 16, 2011            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public class ColormappedImage implements IColormappedImage, + IRenderedImageCallback, IColorMapParametersListener { + + private IImage image; + + private IColorMapDataRetrievalCallback callback; + + private ColorMapParameters parameters; + + public ColormappedImage(IGraphicsTarget target, + IColorMapDataRetrievalCallback callback, + ColorMapParameters parameters) { + this.callback = callback; + setColorMapParameters(parameters); + image = target.initializeRaster(this); + } + + /** + * Get the wrapped image for the colormapped image + * + * @return + */ + public IImage getWrappedImage() { + return image; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IImage#getStatus() + */ + @Override + public Status getStatus() { + return image.getStatus(); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IImage#setInterpolated(boolean) + */ + @Override + public void setInterpolated(boolean isInterpolated) { + image.setInterpolated(isInterpolated); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IImage#dispose() + */ + @Override + public void dispose() { + if (image != null) { + image.dispose(); + } + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IImage#getWidth() + */ + @Override + public int getWidth() { + return image.getWidth(); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IImage#getHeight() + */ + @Override + public int getHeight() { + return image.getHeight(); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IImage#setBrightness(float) + */ + @Override + public void setBrightness(float brightness) { + image.setBrightness(brightness); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IImage#setContrast(float) + */ + @Override + public void setContrast(float contrast) { + image.setContrast(contrast); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IImage#getExtensionClass() + */ + @Override + public Class getExtensionClass() { + return GeneralColormappedImageExtension.class; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.drawables.IColormappedImage#getColorMapParameters + * () + */ + @Override + public ColorMapParameters getColorMapParameters() { + return parameters; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.drawables.IColormappedImage#setColorMapParameters + * (com.raytheon.uf.viz.core.drawables.ColorMapParameters) + */ + @Override + public void setColorMapParameters(ColorMapParameters params) { + if (params != this.parameters) { + if (this.parameters != null) { + this.parameters.removeListener(this); + } + this.parameters = params; + if (this.parameters != null) { + this.parameters.addListener(this); + } + dispose(); + } + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IColormappedImage#getValue(int, + * int) + */ + @Override + public double getValue(int x, int y) { + return Double.NaN; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.data.IRenderedImageCallback#getImage() + */ + @Override + public RenderedImage getImage() throws VizException { + if (parameters == null || parameters.getColorMap() == null) { + return null; + } + ColorMapData colorMapData = callback.getColorMapData(); + return Colormapper.colorMap(colorMapData, parameters); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IColorMapParametersListener# + * colorMapChanged() + */ + @Override + public void colorMapChanged() { + dispose(); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IImage#stage() + */ + @Override + public void stage() throws VizException { + image.stage(); + } + +} diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/ColormappedRenderedImageCallback.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/ColormappedRenderedImageCallback.java deleted file mode 100644 index 69f039b12d..0000000000 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/ColormappedRenderedImageCallback.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ -package com.raytheon.uf.viz.core.drawables.ext.colormap; - -import java.awt.image.RenderedImage; - -import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback; -import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback.ColorMapData; -import com.raytheon.uf.viz.core.data.IRenderedImageCallback; -import com.raytheon.uf.viz.core.data.prep.Colormapper; -import com.raytheon.uf.viz.core.drawables.ColorMapParameters; -import com.raytheon.uf.viz.core.exception.VizException; - -/** - * General {@link IRenderedImageCallback} that takes a - * {@link IColorMapDataRetrievalCallback} and {@link ColorMapParameters} and - * will colormap the data returned from the callback into a - * {@link RenderedImage} - * - *
- * 
- * SOFTWARE HISTORY
- * 
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * Nov 22, 2011            mschenke     Initial creation
- * 
- * 
- * - * @author mschenke - * @version 1.0 - */ - -public class ColormappedRenderedImageCallback implements IRenderedImageCallback { - - private IColorMapDataRetrievalCallback callback; - - private ColorMapParameters parameters; - - /** - * Construct a ColormappedRenderedImageCallback for the colormap data - * callback and parameters - * - * @param dataCallback - * @param parameters - */ - public ColormappedRenderedImageCallback( - IColorMapDataRetrievalCallback dataCallback, - ColorMapParameters parameters) { - this.callback = dataCallback; - this.parameters = parameters; - } - - /* - * (non-Javadoc) - * - * @see com.raytheon.uf.viz.core.data.IRenderedImageCallback#getImage() - */ - @Override - public RenderedImage getImage() throws VizException { - ColorMapData colorMapData = callback.getColorMapData(); - return Colormapper.colorMap(colorMapData, parameters); - } -} diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/GeneralColormappedImageExtension.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/GeneralColormappedImageExtension.java index c2d8f4d59a..ed10191d42 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/GeneralColormappedImageExtension.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/GeneralColormappedImageExtension.java @@ -19,11 +19,17 @@ **/ package com.raytheon.uf.viz.core.drawables.ext.colormap; +import java.util.ArrayList; +import java.util.List; + +import com.raytheon.uf.viz.core.DrawableImage; import com.raytheon.uf.viz.core.IGraphicsTarget; import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback; import com.raytheon.uf.viz.core.drawables.ColorMapParameters; -import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.drawables.IColormappedImage; +import com.raytheon.uf.viz.core.drawables.PaintProperties; import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension; +import com.raytheon.uf.viz.core.exception.VizException; /** * General colormapped image extension. Uses @@ -56,10 +62,10 @@ public class GeneralColormappedImageExtension extends * com.raytheon.uf.viz.core.drawables.ColorMapParameters) */ @Override - public IImage initializeRaster(IColorMapDataRetrievalCallback dataCallback, + public IColormappedImage initializeRaster( + IColorMapDataRetrievalCallback dataCallback, ColorMapParameters colorMapParameters) { - return target.initializeRaster(new ColormappedRenderedImageCallback( - dataCallback, colorMapParameters)); + return new ColormappedImage(target, dataCallback, colorMapParameters); } /* @@ -70,7 +76,29 @@ public class GeneralColormappedImageExtension extends */ @Override public int getCompatibilityValue(IGraphicsTarget target) { - return Compatibilty.GENERIC.value; + return Compatibilty.GENERIC; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.drawables.ext.IImagingExtension#drawRasters( + * com.raytheon.uf.viz.core.drawables.PaintProperties, + * com.raytheon.uf.viz.core.DrawableImage[]) + */ + @Override + public boolean drawRasters(PaintProperties paintProps, + DrawableImage... images) throws VizException { + List renderables = new ArrayList(); + for (DrawableImage di : images) { + if (di.getImage() instanceof ColormappedImage) { + renderables.add(new DrawableImage(((ColormappedImage) di + .getImage()).getWrappedImage(), di.getCoverage())); + } + } + return target.drawRasters(paintProps, + renderables.toArray(new DrawableImage[renderables.size()])); } } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/IColormapShadedShapeExtension.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/IColormapShadedShapeExtension.java index 0860efeddb..7ecf788352 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/IColormapShadedShapeExtension.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/IColormapShadedShapeExtension.java @@ -26,6 +26,7 @@ import org.eclipse.swt.graphics.RGB; import com.raytheon.uf.viz.core.drawables.IDescriptor; import com.raytheon.uf.viz.core.drawables.IShadedShape; +import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension.IGraphicsExtensionInterface; import com.raytheon.uf.viz.core.exception.VizException; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.LineString; @@ -53,7 +54,8 @@ import com.vividsolutions.jts.geom.LineString; * @author bsteffen * @version 1.0 */ -public interface IColormapShadedShapeExtension { +public interface IColormapShadedShapeExtension extends + IGraphicsExtensionInterface { public interface IColormapShadedShape { diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/IColormappedImageExtension.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/IColormappedImageExtension.java index 2270e74972..fb63e8ea8e 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/IColormappedImageExtension.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/colormap/IColormappedImageExtension.java @@ -22,7 +22,7 @@ package com.raytheon.uf.viz.core.drawables.ext.colormap; import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback; import com.raytheon.uf.viz.core.drawables.ColorMapParameters; import com.raytheon.uf.viz.core.drawables.IColormappedImage; -import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.drawables.ext.IImagingExtension; /** * Extension for creating {@link IColormappedImage} objects @@ -41,7 +41,7 @@ import com.raytheon.uf.viz.core.drawables.IImage; * @version 1.0 */ -public interface IColormappedImageExtension { +public interface IColormappedImageExtension extends IImagingExtension { /** * Initializes an IColormappedImage given the dataCallback and colormap @@ -51,6 +51,7 @@ public interface IColormappedImageExtension { * @param colorMapParameters * @return */ - public IImage initializeRaster(IColorMapDataRetrievalCallback dataCallback, + public IColormappedImage initializeRaster( + IColorMapDataRetrievalCallback dataCallback, ColorMapParameters colorMapParameters); } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/jobs/JobPool.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/jobs/JobPool.java index 4f51545b73..536ba25252 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/jobs/JobPool.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/jobs/JobPool.java @@ -34,7 +34,7 @@ import org.eclipse.core.runtime.jobs.Job; * if you have dozens or hundreds of tasks that each take a short time. Creating * a job for each task can result in more threads than is useful. If you instead * use a JobPool it reduces the number of threads by limiting the number of - * eclipse jobs that are created. For many tasks a JobPool may perform faster + * eclipse jobs tBhat are created. For many tasks a JobPool may perform faster * than using eclipse Jobs directly because thread creation and context * switching are reduced. * @@ -113,6 +113,18 @@ public class JobPool { join(); } + /** + * Cancels the specified runnable. Returns true if the provided runnable was + * waiting to be run but now is now. Returns false if the provided runnable + * is already running or if it was not enqueued to begin with. + * + * @param runnable + * @return + */ + public synchronized boolean cancel(Runnable runnable) { + return workQueue.remove(runnable); + } + protected class PooledJob extends Job { public PooledJob(String name) { diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/DatabaseLevelMapping.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/DatabaseLevelMapping.java index 3a6d686744..592fa8ec11 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/DatabaseLevelMapping.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/DatabaseLevelMapping.java @@ -27,13 +27,13 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.level.LevelFactory; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; -import com.raytheon.uf.viz.core.Activator; -import com.raytheon.uf.viz.core.status.StatusConstants; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; /** * Class defines a database level @@ -55,7 +55,9 @@ import com.raytheon.uf.viz.core.status.StatusConstants; @XmlAccessorType(XmlAccessType.NONE) @XmlRootElement public class DatabaseLevelMapping { - private static final transient IUFStatusHandler statusHandler = UFStatus.getHandler(DatabaseLevelMapping.class); + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(DatabaseLevelMapping.class); + @XmlAttribute private String levelName = null; @@ -100,7 +102,7 @@ public class DatabaseLevelMapping { this.unit = unit; } - public List getLevels() { + public List getLevels() throws VizCommunicationException { String[] levelOneValues = new String[0]; String[] levelTwoValues = new String[0]; @@ -143,12 +145,16 @@ public class DatabaseLevelMapping { } // handle any aliasing etc - Level level = LevelFactory.getInstance().getLevel(levelName, lvl1, - lvl2, unit); - - if (level != null) { - rval.add(level); + try { + Level level = LevelFactory.getInstance().getLevel(levelName, + lvl1, lvl2, unit); + if (level != null) { + rval.add(level); + } + } catch (CommunicationException e) { + throw new VizCommunicationException(e); } + } return rval; diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelMapping.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelMapping.java index 15ad9695bf..9bb7d5c2dc 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelMapping.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelMapping.java @@ -31,6 +31,7 @@ import javax.xml.bind.annotation.XmlRootElement; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.serialization.ISerializableObject; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; /** * Class defines a mapping from a display level to one or more database levels. @@ -38,14 +39,14 @@ import com.raytheon.uf.common.serialization.ISerializableObject; * *
  * 
- * SOFTWARE HISTORY
- * 
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * 11/01/2007    #518      S.Manoj     Initial version
- * 11/16/2009    #3120     rjpeter     Modifed to better integrate with level framework.
- * 11/21/2009    #3576     rjpeter     Added group
- *
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * 11/01/2007    #518      S.Manoj     Initial version
+ * 11/16/2009    #3120     rjpeter     Modifed to better integrate with level framework.
+ * 11/21/2009    #3576     rjpeter     Added group
+ * 
  * @author smanoj
  * @version 1.0
  */
@@ -118,12 +119,13 @@ public class LevelMapping implements ISerializableObject {
         this.databaseLevels = databaseLevels;
     }
 
-    public List getLevels() {
+    public List getLevels() throws VizCommunicationException {
         if (levelList == null) {
-            levelList = new ArrayList();
+            List levelList = new ArrayList();
             for (DatabaseLevelMapping mapping : databaseLevels) {
                 levelList.addAll(mapping.getLevels());
             }
+            this.levelList = levelList;
         }
 
         return levelList;
diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelMappingFactory.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelMappingFactory.java
index 482bbfd467..234bec3cd1 100644
--- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelMappingFactory.java
+++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelMappingFactory.java
@@ -35,6 +35,7 @@ import com.raytheon.uf.common.localization.PathManagerFactory;
 import com.raytheon.uf.common.status.IUFStatusHandler;
 import com.raytheon.uf.common.status.UFStatus;
 import com.raytheon.uf.common.status.UFStatus.Priority;
+import com.raytheon.uf.viz.core.exception.VizCommunicationException;
 
 /**
  * Factory for getting level mappings
@@ -56,15 +57,22 @@ public class LevelMappingFactory {
     private static final transient IUFStatusHandler statusHandler = UFStatus
             .getHandler(LevelMappingFactory.class);
 
-    private static LevelMappingFactory instance = new LevelMappingFactory();
+    private static LevelMappingFactory instance = null;
 
     private Map keyToLevelMappings = new HashMap();
 
+    private boolean levelToLevelMappingsInitialized = false;
+
     private Map levelToLevelMappings = new HashMap();
 
+    private boolean groupToMasterLevelsInitialized = false;
+
     private Map>> groupToMasterLevels = new HashMap>>();
 
-    public static LevelMappingFactory getInstance() {
+    public synchronized static LevelMappingFactory getInstance() {
+        if (instance == null) {
+            instance = new LevelMappingFactory();
+        }
         return instance;
     }
 
@@ -96,47 +104,6 @@ public class LevelMappingFactory {
                 }
             }
 
-            for (LevelMapping mapping : keyToLevelMappings.values()) {
-                String group = mapping.getGroup();
-                Map> masterLevels = null;
-
-                if (group != null) {
-                    masterLevels = groupToMasterLevels.get(mapping.getGroup());
-                    if (masterLevels == null) {
-                        masterLevels = new HashMap>();
-                        groupToMasterLevels.put(group, masterLevels);
-                    }
-                }
-
-                for (Level l : mapping.getLevels()) {
-                    if (levelToLevelMappings.containsKey(l)) {
-                        LevelMapping oldMapping = levelToLevelMappings.get(l);
-                        // Only replace the old level mapping if we have less
-                        // levels than the old mapping
-                        // This should cause the most specific mapping to be
-                        // used
-                        if (mapping.getLevels().size() < oldMapping.getLevels()
-                                .size()) {
-                            levelToLevelMappings.put(l, mapping);
-                        }
-                    } else {
-                        levelToLevelMappings.put(l, mapping);
-                    }
-
-                    // populate grouping map
-                    if (masterLevels != null) {
-                        MasterLevel ml = l.getMasterLevel();
-                        Set levels = masterLevels.get(ml);
-
-                        if (levels == null) {
-                            levels = new HashSet();
-                            masterLevels.put(ml, levels);
-                        }
-
-                        levels.add(l);
-                    }
-                }
-            }
         }
         long finish = System.currentTimeMillis();
         System.out.println("LevelMappingFactory initialization took ["
@@ -147,7 +114,11 @@ public class LevelMappingFactory {
         return keyToLevelMappings.get(key);
     }
 
-    public LevelMapping getLevelMappingForLevel(Level level) {
+    public LevelMapping getLevelMappingForLevel(Level level)
+            throws VizCommunicationException {
+        if (!levelToLevelMappingsInitialized) {
+            initializeLevelToLevelMappings();
+        }
         return levelToLevelMappings.get(level);
     }
 
@@ -155,11 +126,75 @@ public class LevelMappingFactory {
         return keyToLevelMappings.values();
     }
 
-    public Set getAllLevels() {
+    public Set getAllLevels() throws VizCommunicationException {
+        if (!levelToLevelMappingsInitialized) {
+            initializeLevelToLevelMappings();
+        }
         return levelToLevelMappings.keySet();
     }
 
-    public Map> getLevelMapForGroup(String group) {
+    public Map> getLevelMapForGroup(String group)
+            throws VizCommunicationException {
+        if (!groupToMasterLevelsInitialized) {
+            initializeGroupToMasterLevels();
+        }
         return groupToMasterLevels.get(group);
     }
+
+    private void initializeLevelToLevelMappings()
+            throws VizCommunicationException {
+        for (LevelMapping mapping : keyToLevelMappings.values()) {
+            String group = mapping.getGroup();
+
+            for (Level l : mapping.getLevels()) {
+                if (levelToLevelMappings.containsKey(l)) {
+                    LevelMapping oldMapping = levelToLevelMappings.get(l);
+                    // Only replace the old level mapping if we have less
+                    // levels than the old mapping
+                    // This should cause the most specific mapping to be
+                    // used
+                    if (mapping.getLevels().size() < oldMapping.getLevels()
+                            .size()) {
+                        levelToLevelMappings.put(l, mapping);
+                    }
+                } else {
+                    levelToLevelMappings.put(l, mapping);
+                }
+            }
+        }
+        levelToLevelMappingsInitialized = true;
+    }
+
+    private void initializeGroupToMasterLevels()
+            throws VizCommunicationException {
+        for (LevelMapping mapping : keyToLevelMappings.values()) {
+            String group = mapping.getGroup();
+            Map> masterLevels = null;
+
+            if (group != null) {
+                masterLevels = groupToMasterLevels.get(mapping.getGroup());
+                if (masterLevels == null) {
+                    masterLevels = new HashMap>();
+                    groupToMasterLevels.put(group, masterLevels);
+                }
+            }
+
+            for (Level l : mapping.getLevels()) {
+
+                // populate grouping map
+                if (masterLevels != null) {
+                    MasterLevel ml = l.getMasterLevel();
+                    Set levels = masterLevels.get(ml);
+
+                    if (levels == null) {
+                        levels = new HashSet();
+                        masterLevels.put(ml, levels);
+                    }
+
+                    levels.add(l);
+                }
+            }
+        }
+        groupToMasterLevelsInitialized = true;
+    }
 }
diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelRetrievalAdapter.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelRetrievalAdapter.java
index bcd824dad0..c1d3c57745 100644
--- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelRetrievalAdapter.java
+++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelRetrievalAdapter.java
@@ -22,6 +22,7 @@ package com.raytheon.uf.viz.core.level;
 import java.util.HashMap;
 import java.util.Map;
 
+import com.raytheon.uf.common.comm.CommunicationException;
 import com.raytheon.uf.common.dataplugin.level.Level;
 import com.raytheon.uf.common.dataplugin.level.LevelContainer;
 import com.raytheon.uf.common.dataplugin.level.MasterLevel;
@@ -37,6 +38,7 @@ import com.raytheon.uf.common.dataquery.responses.DbQueryResponse;
 import com.raytheon.uf.common.status.IUFStatusHandler;
 import com.raytheon.uf.common.status.UFStatus;
 import com.raytheon.uf.common.status.UFStatus.Priority;
+import com.raytheon.uf.viz.core.exception.VizCommunicationException;
 import com.raytheon.uf.viz.core.exception.VizException;
 import com.raytheon.uf.viz.core.requests.ThriftClient;
 
@@ -45,11 +47,14 @@ public class LevelRetrievalAdapter implements ILevelRetrievalAdapter {
             .getHandler(LevelRetrievalAdapter.class);
 
     @Override
-    public Level getLevel(GetLevelRequest request) {
+    public Level getLevel(GetLevelRequest request)
+            throws CommunicationException {
         Level rval = null;
 
         try {
             rval = (Level) ThriftClient.sendRequest(request);
+        } catch (VizCommunicationException e) {
+            throw new CommunicationException(e);
         } catch (VizException e) {
             statusHandler.handle(Priority.PROBLEM,
                     "Error occurred retrieving level information from server.",
@@ -60,11 +65,14 @@ public class LevelRetrievalAdapter implements ILevelRetrievalAdapter {
     }
 
     @Override
-    public Level getLevel(GetLevelByIdRequest request) {
+    public Level getLevel(GetLevelByIdRequest request)
+            throws CommunicationException {
         Level rval = null;
 
         try {
             rval = (Level) ThriftClient.sendRequest(request);
+        } catch (VizCommunicationException e) {
+            throw new CommunicationException(e);
         } catch (VizException e) {
             statusHandler.handle(Priority.PROBLEM,
                     "Error occurred retrieving level information from server.",
@@ -75,10 +83,13 @@ public class LevelRetrievalAdapter implements ILevelRetrievalAdapter {
     }
 
     @Override
-    public MasterLevel getMasterLevel(GetMasterLevelRequest request) {
+    public MasterLevel getMasterLevel(GetMasterLevelRequest request)
+            throws CommunicationException {
         MasterLevel rval = null;
         try {
             rval = (MasterLevel) ThriftClient.sendRequest(request);
+        } catch (VizCommunicationException e) {
+            throw new CommunicationException(e);
         } catch (VizException e) {
             statusHandler.handle(Priority.PROBLEM,
                     "Error occurred retrieving level information from server.",
@@ -89,10 +100,13 @@ public class LevelRetrievalAdapter implements ILevelRetrievalAdapter {
 
     @Override
     public LevelContainer getAllLevelsForMasterLevel(
-            GetAllLevelsForMasterLevelRequest request) {
+            GetAllLevelsForMasterLevelRequest request)
+            throws CommunicationException {
         LevelContainer rval = null;
         try {
             rval = (LevelContainer) ThriftClient.sendRequest(request);
+        } catch (VizCommunicationException e) {
+            throw new CommunicationException(e);
         } catch (VizException e) {
             statusHandler.handle(Priority.PROBLEM,
                     "Error occurred retrieving level information from server.",
@@ -102,7 +116,7 @@ public class LevelRetrievalAdapter implements ILevelRetrievalAdapter {
     }
 
     @Override
-    public LevelContainer getAllLevels() {
+    public LevelContainer getAllLevels() throws CommunicationException {
         LevelContainer rval = null;
         DbQueryRequest query = new DbQueryRequest();
         query.setConstraints(new HashMap());
@@ -114,6 +128,8 @@ public class LevelRetrievalAdapter implements ILevelRetrievalAdapter {
             for (Map result : resp.getResults()) {
                 rval.add((Level) result.get(null));
             }
+        } catch (VizCommunicationException e) {
+            throw new CommunicationException(e);
         } catch (VizException e) {
             statusHandler.handle(Priority.PROBLEM,
                     "Error occurred retrieving level information from server.",
@@ -123,7 +139,8 @@ public class LevelRetrievalAdapter implements ILevelRetrievalAdapter {
     }
 
     @Override
-    public MasterLevelContainer getAllMasterLevels() {
+    public MasterLevelContainer getAllMasterLevels()
+            throws CommunicationException {
         MasterLevelContainer rval = null;
         DbQueryRequest query = new DbQueryRequest();
         query.setConstraints(new HashMap());
@@ -135,6 +152,8 @@ public class LevelRetrievalAdapter implements ILevelRetrievalAdapter {
             for (Map result : resp.getResults()) {
                 rval.add((MasterLevel) result.get(null));
             }
+        } catch (VizCommunicationException e) {
+            throw new CommunicationException(e);
         } catch (VizException e) {
             statusHandler
                     .handle(Priority.PROBLEM,
diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelUtilities.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelUtilities.java
index cb92905a99..f6cf111c91 100644
--- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelUtilities.java
+++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/level/LevelUtilities.java
@@ -29,10 +29,12 @@ import java.util.TreeSet;
 import javax.measure.unit.Unit;
 import javax.measure.unit.UnitFormat;
 
+import com.raytheon.uf.common.comm.CommunicationException;
 import com.raytheon.uf.common.dataplugin.level.CompareType;
 import com.raytheon.uf.common.dataplugin.level.Level;
 import com.raytheon.uf.common.dataplugin.level.LevelFactory;
 import com.raytheon.uf.common.dataplugin.level.MasterLevel;
+import com.raytheon.uf.viz.core.exception.VizCommunicationException;
 
 /**
  * Level utilities
@@ -62,14 +64,24 @@ public class LevelUtilities {
         }
     }
 
-    public static boolean isPressureLevel(long levelId) {
-        return isPressureLevel(LevelFactory.getInstance().getLevel(levelId)
-                .getMasterLevel());
+    public static boolean isPressureLevel(long levelId)
+            throws VizCommunicationException {
+        try {
+            return isPressureLevel(LevelFactory.getInstance().getLevel(levelId)
+                    .getMasterLevel());
+        } catch (CommunicationException e) {
+            throw new VizCommunicationException(e);
+        }
     }
 
-    public static boolean isPressureLevel(String masterLevelName) {
-        return isPressureLevel(LevelFactory.getInstance().getMasterLevel(
-                masterLevelName));
+    public static boolean isPressureLevel(String masterLevelName)
+            throws VizCommunicationException {
+        try {
+            return isPressureLevel(LevelFactory.getInstance().getMasterLevel(
+                    masterLevelName));
+        } catch (CommunicationException e) {
+            throw new VizCommunicationException(e);
+        }
     }
 
     public static boolean isPressureLevel(Level level) {
@@ -89,9 +101,10 @@ public class LevelUtilities {
      * 
      * @param masterLevelName
      * @return
+     * @throws CommunicationException
      */
     public synchronized static NavigableSet getOrderedSetOfStandardLevels(
-            String masterLevelName) {
+            String masterLevelName) throws VizCommunicationException {
         if (masterLevelToOrderedSet == null) {
             Comparator levelComparator = new Comparator() {
 
@@ -108,7 +121,7 @@ public class LevelUtilities {
                 }
 
             };
-            masterLevelToOrderedSet = new HashMap>();
+            Map> masterLevelToOrderedSet = new HashMap>();
             for (Level level : LevelMappingFactory.getInstance().getAllLevels()) {
                 NavigableSet levels = masterLevelToOrderedSet.get(level
                         .getMasterLevel().getName());
@@ -118,12 +131,18 @@ public class LevelUtilities {
                             .getName(), levels);
                 }
                 if (level.isRangeLevel()) {
-                    levels.add(level.getUpperLevel());
-                    levels.add(level.getLowerLevel());
+
+                    try {
+                        levels.add(level.getUpperLevel());
+                        levels.add(level.getLowerLevel());
+                    } catch (CommunicationException e) {
+                        throw new VizCommunicationException(e);
+                    }
                 } else {
                     levels.add(level);
                 }
             }
+            LevelUtilities.masterLevelToOrderedSet = masterLevelToOrderedSet;
         }
         return masterLevelToOrderedSet.get(masterLevelName);
 
diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/map/IMapMeshExtension.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/map/IMapMeshExtension.java
index 431084a4d3..b50ff96013 100644
--- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/map/IMapMeshExtension.java
+++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/map/IMapMeshExtension.java
@@ -20,6 +20,7 @@
 package com.raytheon.uf.viz.core.map;
 
 import com.raytheon.uf.viz.core.IMesh;
+import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension.IGraphicsExtensionInterface;
 import com.raytheon.uf.viz.core.exception.VizException;
 
 /**
@@ -39,7 +40,7 @@ import com.raytheon.uf.viz.core.exception.VizException;
  * @version 1.0
  */
 
-public interface IMapMeshExtension {
+public interface IMapMeshExtension extends IGraphicsExtensionInterface {
 
     /**
      * Create a mesh
diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/notification/jobs/NotificationManagerJob.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/notification/jobs/NotificationManagerJob.java
index 34ebe129a5..b671c659b6 100644
--- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/notification/jobs/NotificationManagerJob.java
+++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/notification/jobs/NotificationManagerJob.java
@@ -193,29 +193,7 @@ public class NotificationManagerJob implements ExceptionListener, IDisposable {
         try {
             ConnectionFactory connectionFactory = JMSConnection.getInstance()
                     .getFactory();
-            if (connection != null) {
-                try {
-                    connection.stop();
-                } catch (Exception e) {
-                    if (notifyError) {
-                        statusHandler
-                                .handle(Priority.SIGNIFICANT,
-                                        "NotificationManager failed to stop a connection.",
-                                        e);
-                    }
-                }
-                try {
-                    connection.close();
-                } catch (Exception e) {
-                    if (notifyError) {
-                        statusHandler
-                                .handle(Priority.SIGNIFICANT,
-                                        "NotificationManager failed to close a connection.",
-                                        e);
-                    }
-                }
-                connection = null;
-            }
+            disconnect(notifyError);
 
             // Create a Connection
             connection = connectionFactory.createConnection();
@@ -250,6 +228,31 @@ public class NotificationManagerJob implements ExceptionListener, IDisposable {
         }
     }
 
+    protected void disconnect(boolean notifyError) {
+        if (connection != null) {
+            try {
+                connection.stop();
+            } catch (Exception e) {
+                if (notifyError) {
+                    statusHandler.handle(Priority.SIGNIFICANT,
+                            "NotificationManager failed to stop a connection.",
+                            e);
+                }
+            }
+            try {
+                connection.close();
+            } catch (Exception e) {
+                if (notifyError) {
+                    statusHandler
+                            .handle(Priority.SIGNIFICANT,
+                                    "NotificationManager failed to close a connection.",
+                                    e);
+                }
+            }
+            connection = null;
+        }
+    }
+
     private TimerTask task = null;
 
     @Override
diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/requests/ThriftClient.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/requests/ThriftClient.java
index db130f35d6..c75e8c66d7 100644
--- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/requests/ThriftClient.java
+++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/requests/ThriftClient.java
@@ -1,5 +1,6 @@
 package com.raytheon.uf.viz.core.requests;
 
+import java.io.IOException;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
@@ -12,6 +13,7 @@ import com.raytheon.uf.common.auth.req.AbstractPrivilegedRequest;
 import com.raytheon.uf.common.auth.resp.SuccessfulExecution;
 import com.raytheon.uf.common.auth.resp.UserNotAuthenticated;
 import com.raytheon.uf.common.auth.resp.UserNotAuthorized;
+import com.raytheon.uf.common.comm.CommunicationException;
 import com.raytheon.uf.common.comm.HttpClient;
 import com.raytheon.uf.common.comm.NetworkStatistics;
 import com.raytheon.uf.common.serialization.SerializationException;
@@ -23,6 +25,7 @@ import com.raytheon.uf.common.serialization.comm.response.ServerErrorResponse;
 import com.raytheon.uf.common.serialization.comm.util.ExceptionWrapper;
 import com.raytheon.uf.viz.core.VizApp;
 import com.raytheon.uf.viz.core.auth.UserController;
+import com.raytheon.uf.viz.core.exception.VizCommunicationException;
 import com.raytheon.uf.viz.core.exception.VizException;
 import com.raytheon.uf.viz.core.localization.LocalizationManager;
 
@@ -311,6 +314,12 @@ public class ThriftClient {
             // Log request stats
             stats.log(request.getClass().getSimpleName(), message.length,
                     responseLen);
+        } catch (IOException e) {
+            throw new VizCommunicationException(
+                    "unable to post request to server", e);
+        } catch (CommunicationException e) {
+            throw new VizCommunicationException(
+                    "unable to post request to server", e);
         } catch (Exception e) {
             throw new VizException("unable to post request to server", e);
         }
diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/AbstractPluginDataObjectResource.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/AbstractPluginDataObjectResource.java
new file mode 100644
index 0000000000..6348c19966
--- /dev/null
+++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/AbstractPluginDataObjectResource.java
@@ -0,0 +1,340 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ * 
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ * 
+ * Contractor Name:        Raytheon Company
+ * Contractor Address:     6825 Pine Street, Suite 340
+ *                         Mail Stop B8
+ *                         Omaha, NE 68106
+ *                         402.291.0100
+ * 
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.uf.viz.core.rsc;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+
+import com.raytheon.uf.common.dataplugin.PluginDataObject;
+import com.raytheon.uf.common.time.DataTime;
+import com.raytheon.uf.viz.core.IGraphicsTarget;
+import com.raytheon.uf.viz.core.VizApp;
+import com.raytheon.uf.viz.core.drawables.IDescriptor;
+import com.raytheon.uf.viz.core.drawables.IRenderable;
+import com.raytheon.uf.viz.core.drawables.PaintProperties;
+import com.raytheon.uf.viz.core.exception.VizException;
+import com.raytheon.uf.viz.core.rsc.capabilities.AbstractCapability;
+
+/**
+ * Abstract resource class that manages frames with renderable objects
+ * 
+ * 
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 21, 2011            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public abstract class AbstractPluginDataObjectResource + extends AbstractVizResource { + + private static class Frame { + List records = new ArrayList(); + + IRenderable renderable; + } + + private Map frames = new HashMap(); + + private Object lock = new Object(); + + /** + * @param resourceData + * @param loadProperties + */ + protected AbstractPluginDataObjectResource(T resourceData, + LoadProperties loadProperties) { + super(resourceData, loadProperties); + dataTimes = new ArrayList(); + resourceData.addChangeListener(new IResourceDataChanged() { + @Override + public void resourceChanged(ChangeType type, Object object) { + if (type == ChangeType.DATA_UPDATE) { + if (object instanceof PluginDataObject) { + addDataObject((PluginDataObject) object); + } else if (object instanceof PluginDataObject[]) { + for (PluginDataObject pdo : (PluginDataObject[]) object) { + addDataObject((PluginDataObject) pdo); + } + } else if (object instanceof Object[]) { + for (Object obj : (Object[]) object) { + if (obj instanceof PluginDataObject) { + addDataObject((PluginDataObject) obj); + } + } + } + } else if (type == ChangeType.CAPABILITY) { + if (object instanceof AbstractCapability) { + AbstractCapability capability = (AbstractCapability) object; + for (Frame frame : frames.values()) { + if (frame.renderable != null) { + capabilityChanged(frame.renderable, capability); + } + } + } + } + } + }); + } + + /** + * Adds the pdo to the appropriate time and removes any renderable or data + * cached for that time. + * + * @param pdo + */ + protected final void addDataObject(PluginDataObject pdo) { + synchronized (lock) { + if (frames == null) { + // Check for null in case we were waiting for lock from + // disposeInternal in which case we shouldn't process add + return; + } + DataTime time = getDataObjectTime(pdo); + Frame frame = frames.get(time); + if (frame == null) { + frame = new Frame(); + frames.put(time, frame); + } + if (frame.records.contains(pdo)) { + frame.records.remove(pdo); + } + frame.records.add(pdo); + if (frame.renderable != null) { + if (updateRenderable(frame.renderable, pdo) == false) { + dispose(frame.renderable); + } + } + if (!dataTimes.contains(dataTimes)) { + dataTimes.add(time); + } + } + } + + /** + * Return the DataTime to be associated with this record. Default returns + * PluginDataObject.getDataTime() + * + * @param pdo + * @return + */ + protected DataTime getDataObjectTime(PluginDataObject pdo) { + return pdo.getDataTime(); + } + + /** + * Get the records for the given time. Empty list will be returned if no + * frame for time + * + * @param time + * @return + */ + protected List getPluginDataObjects(DataTime time) { + Frame frame = frames.get(time); + if (frame != null) { + return frame.records; + } + return new ArrayList(); + } + + /** + * Get the current time for the resource, default calls + * descriptor.getTimeForResoruce(this) + * + * @return the current time + */ + protected DataTime getTimeForResource() { + return descriptor.getTimeForResource(this); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.rsc.AbstractVizResource#remove(com.raytheon. + * uf.common.time.DataTime) + */ + @Override + public final void remove(DataTime dataTime) { + synchronized (lock) { + super.remove(dataTime); + Frame frame = frames.remove(dataTime); + if (frame != null && frame.renderable != null) { + IRenderable dispose = frame.renderable; + frame.renderable = null; + dispose(dispose); + } + } + } + + /** + * Dispose of a renderable. + * + * @param renderable + */ + private void dispose(final IRenderable renderable) { + VizApp.runAsync(new Runnable() { + @Override + public void run() { + disposeRenderable(renderable); + } + }); + } + + @Override + public final void project(CoordinateReferenceSystem crs) + throws VizException { + Iterator iter = frames.values().iterator(); + while (iter.hasNext()) { + Frame frame = iter.next(); + IRenderable renderable = frame.renderable; + if (renderable != null) { + if (!projectRenderable(renderable, crs)) { + frame.renderable = null; + dispose(renderable); + } + } + } + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.rsc.AbstractVizResource#paintInternal(com.raytheon + * .uf.viz.core.IGraphicsTarget, + * com.raytheon.uf.viz.core.drawables.PaintProperties) + */ + @Override + protected final void paintInternal(IGraphicsTarget target, + PaintProperties paintProps) throws VizException { + DataTime time = paintProps.getDataTime(); + if (time == null) { + time = getTimeForResource(); + } + Frame currFrame = frames.get(time); + if (currFrame != null) { + IRenderable renderable = currFrame.renderable; + if (renderable == null) { + currFrame.renderable = renderable = constructRenderable(currFrame.records); + } + + if (renderable != null) { + renderable.paint(target, paintProps); + } + } + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.rsc.AbstractVizResource#disposeInternal() + */ + @Override + protected final void disposeInternal() { + synchronized (lock) { + for (Frame frame : frames.values()) { + if (frame.renderable != null) { + disposeRenderable(frame.renderable); + } + } + frames.clear(); + frames = null; + } + disposeResource(); + } + + /** + * Dispose method for the resource to dispose any data not tied to a + * renderable. Called after all renderables have been disposed. Default impl + * does nothing + */ + protected void disposeResource() { + + } + + /** + * Notification that a capability has changed and the renderable should be + * updated + * + * @param renderable + * @param capability + */ + protected abstract void capabilityChanged(IRenderable renderable, + AbstractCapability capability); + + /** + * Dispose the renderable object + * + * @param renderable + */ + protected abstract void disposeRenderable(IRenderable renderable); + + /** + * Attempt to reproject the renderable object into this specified + * projection. If unable to reproject, return false and renderable will be + * recreated next paint + * + * @param renderable + * @param crs + * @return + */ + protected abstract boolean projectRenderable(IRenderable renderable, + CoordinateReferenceSystem crs) throws VizException; + + /** + * Construct a renderable object for the given records. This method is + * called from paintInternal. Null can be returned and this method will be + * called next paintInternal. That can be used if requesting data that is + * required for the renderable asynchronously. + * + * NOTE: The size of the pdo list will only grow so it can be used to + * determine if new data has arrived since last call + * + * @param records + * @return + */ + protected abstract IRenderable constructRenderable( + List records) throws VizException; + + /** + * Update the renderable with the new pdo, if the renderable is updatable, + * return true. If the renderable needs to be recreated from scratch, return + * false + * + * @param renderable + * @param pdo + * @return + */ + protected abstract boolean updateRenderable(IRenderable renderable, + PluginDataObject pdo); +} diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/AbstractRequestableResourceData.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/AbstractRequestableResourceData.java index 717e5125fe..84c79a96cd 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/AbstractRequestableResourceData.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/AbstractRequestableResourceData.java @@ -21,6 +21,7 @@ package com.raytheon.uf.viz.core.rsc; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; @@ -385,11 +386,6 @@ public abstract class AbstractRequestableResourceData extends Set currentSet = new HashSet(Arrays.asList(current)); - boolean initialLoad = false; - if (currentSet.size() == 0) { - initialLoad = true; - } - Set loadSet = new HashSet(); for (DataTime t : desiredSet) { boolean found = false; @@ -409,6 +405,21 @@ public abstract class AbstractRequestableResourceData extends return new PluginDataObject[0]; } + return requestPluginDataObjects(loadSet); + } + + /** + * Request plugin data objects for the passed in times. This method is + * called from getLatestPluginDataObjects(DataTime[],DataTime[]) after time + * filter from desired and current has been done. The times passed in is a + * collection of new times needed + * + * @param loadSet + * @return + * @throws VizException + */ + protected PluginDataObject[] requestPluginDataObjects( + Collection loadSet) throws VizException { LayerProperty property = new LayerProperty(); // TODO fix? property.setDesiredProduct(ResourceType.PLAN_VIEW); @@ -476,7 +487,7 @@ public abstract class AbstractRequestableResourceData extends /** * Comparator for response array. */ - private static Comparator layerComparator = new Comparator() { + protected static Comparator layerComparator = new Comparator() { @Override public int compare(PluginDataObject arg0, PluginDataObject arg1) { diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/AbstractVizResource.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/AbstractVizResource.java index dfc7ff82e8..a50fa00daf 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/AbstractVizResource.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/AbstractVizResource.java @@ -20,10 +20,10 @@ package com.raytheon.uf.viz.core.rsc; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -152,11 +152,11 @@ public abstract class AbstractVizResource(); - initListeners = new HashSet(); - paintListeners = new HashSet(); - paintStatusListeners = new HashSet(); - disposeListeners = new HashSet(); + refreshListeners = new CopyOnWriteArraySet(); + initListeners = new CopyOnWriteArraySet(); + paintListeners = new CopyOnWriteArraySet(); + paintStatusListeners = new CopyOnWriteArraySet(); + disposeListeners = new CopyOnWriteArraySet(); if (resourceData != null) { resourceData.addChangeListener(new IResourceDataChanged() { diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/URICatalog.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/URICatalog.java index 93f5e0edfd..7adfe28169 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/URICatalog.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/URICatalog.java @@ -83,7 +83,12 @@ public class URICatalog extends DecisionTree> { } protected static synchronized void setCustomInstance(URICatalog catalog) { - // TODO what to do if there already is an isntance. + if (instance != null) { + for (DataPair pair : instance.getDataPairs()) { + catalog.insertCriteria(pair.metadata, pair.data, false); + } + catalog.rebuildTree(); + } instance = catalog; } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/capabilities/ColorMapCapability.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/capabilities/ColorMapCapability.java index ec52372b43..6ddae40950 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/capabilities/ColorMapCapability.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/capabilities/ColorMapCapability.java @@ -73,6 +73,9 @@ public class ColorMapCapability extends AbstractCapability implements public void setColorMapParameters(ColorMapParameters colorMapParameters, boolean notify) { if (this.colorMapParameters != colorMapParameters) { + if (this.colorMapParameters != null) { + this.colorMapParameters.removeListener(this); + } this.colorMapParameters = colorMapParameters; if (notify) { capabilityChanged(); @@ -80,7 +83,7 @@ public class ColorMapCapability extends AbstractCapability implements } if (this.colorMapParameters != null) { - this.colorMapParameters.setListener(this); + this.colorMapParameters.addListener(this); } } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/updater/DataUpdateTree.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/updater/DataUpdateTree.java index d5826f08d7..0cbea7e3bd 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/updater/DataUpdateTree.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/updater/DataUpdateTree.java @@ -50,7 +50,17 @@ public class DataUpdateTree extends DecisionTree> { return instance; } - public DataUpdateTree() { + protected static synchronized void setCustomInstance(DataUpdateTree tree) { + if (instance != null) { + for (DataPair pair : instance.getDataPairs()) { + tree.insertCriteria(pair.metadata, pair.data, false); + } + tree.rebuildTree(); + } + instance = tree; + } + + protected DataUpdateTree() { super(); } diff --git a/cave/com.raytheon.uf.viz.d2d.xy.adapters/src/com/raytheon/uf/viz/d2d/xy/adapters/timeseries/PointDataTimeSeriesAdapter.java b/cave/com.raytheon.uf.viz.d2d.xy.adapters/src/com/raytheon/uf/viz/d2d/xy/adapters/timeseries/PointDataTimeSeriesAdapter.java index 7f69de5004..8ad51cafd0 100644 --- a/cave/com.raytheon.uf.viz.d2d.xy.adapters/src/com/raytheon/uf/viz/d2d/xy/adapters/timeseries/PointDataTimeSeriesAdapter.java +++ b/cave/com.raytheon.uf.viz.d2d.xy.adapters/src/com/raytheon/uf/viz/d2d/xy/adapters/timeseries/PointDataTimeSeriesAdapter.java @@ -245,19 +245,23 @@ public class PointDataTimeSeriesAdapter extends // The level mapping for surface has way to much junk in it. return level; } - LevelMapping mapping = LevelMappingFactory.getInstance() - .getLevelMappingForKey(resourceData.getLevelKey()); - for (Level l : mapping.getLevels()) { - if (LevelUtilities.isPressureLevel(l)) { - try { - level = new SingleLevel(l.getMasterLevel().getName()); - level.setValue(l.getLevelonevalue()); - break; - } catch (IllegalArgumentException e) { - level = new SingleLevel("SURFACE"); - level.setValue(0.0); + try { + LevelMapping mapping = LevelMappingFactory.getInstance() + .getLevelMappingForKey(resourceData.getLevelKey()); + for (Level l : mapping.getLevels()) { + if (LevelUtilities.isPressureLevel(l)) { + try { + level = new SingleLevel(l.getMasterLevel().getName()); + level.setValue(l.getLevelonevalue()); + break; + } catch (IllegalArgumentException e) { + level = new SingleLevel("SURFACE"); + level.setValue(0.0); + } } } + } catch (VizException e) { + // return the default } return level; } diff --git a/cave/com.raytheon.uf.viz.derivparam/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.derivparam/META-INF/MANIFEST.MF index 6af06d9017..f3db5554a2 100644 --- a/cave/com.raytheon.uf.viz.derivparam/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.uf.viz.derivparam/META-INF/MANIFEST.MF @@ -7,30 +7,26 @@ Bundle-Activator: com.raytheon.uf.viz.derivparam.Activator Bundle-Vendor: RAYTHEON Require-Bundle: org.eclipse.core.runtime, javax.measure, - com.raytheon.uf.common.dataquery + com.raytheon.uf.common.dataquery, + com.raytheon.uf.viz.core;bundle-version="1.12.1174", + com.raytheon.uf.common.datastorage;bundle-version="1.12.1174", + com.raytheon.uf.common.pointdata;bundle-version="1.12.1174" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Eclipse-RegisterBuddy: com.raytheon.uf.common.serialization Import-Package: com.raytheon.edex.meteoLib, com.raytheon.edex.util, + com.raytheon.uf.common.comm, com.raytheon.uf.common.dataplugin, com.raytheon.uf.common.dataplugin.level, com.raytheon.uf.common.dataplugin.persist, - com.raytheon.uf.common.datastorage.records, com.raytheon.uf.common.derivparam.tree, com.raytheon.uf.common.localization, com.raytheon.uf.common.message.response, com.raytheon.uf.common.serialization, com.raytheon.uf.common.serialization.adapters, com.raytheon.uf.common.status, - com.raytheon.uf.common.time, - com.raytheon.uf.viz.core, - com.raytheon.uf.viz.core.catalog, - com.raytheon.uf.viz.core.comm, - com.raytheon.uf.viz.core.exception, - com.raytheon.uf.viz.core.level, - com.raytheon.uf.viz.core.localization, - com.raytheon.uf.viz.core.status + com.raytheon.uf.common.time Export-Package: com.raytheon.uf.viz.derivparam, com.raytheon.uf.viz.derivparam.data, com.raytheon.uf.viz.derivparam.inv, diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/data/AbstractDataCubeAdapter.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/data/AbstractDataCubeAdapter.java new file mode 100644 index 0000000000..2d61a7c8aa --- /dev/null +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/data/AbstractDataCubeAdapter.java @@ -0,0 +1,394 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.derivparam.data; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.regex.Pattern; + +import com.raytheon.uf.common.dataplugin.PluginDataObject; +import com.raytheon.uf.common.dataquery.requests.DbQueryRequest; +import com.raytheon.uf.common.dataquery.requests.DbQueryRequestSet; +import com.raytheon.uf.common.dataquery.requests.RequestConstraint; +import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintType; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequestSet; +import com.raytheon.uf.common.dataquery.responses.DbQueryResponse; +import com.raytheon.uf.common.dataquery.responses.DbQueryResponseSet; +import com.raytheon.uf.common.datastorage.Request; +import com.raytheon.uf.common.datastorage.records.IDataRecord; +import com.raytheon.uf.common.pointdata.PointDataContainer; +import com.raytheon.uf.common.time.DataTime; +import com.raytheon.uf.viz.core.catalog.LayerProperty; +import com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter; +import com.raytheon.uf.viz.core.datastructure.VizDataCubeException; +import com.raytheon.uf.viz.core.exception.VizException; +import com.raytheon.uf.viz.core.requests.ThriftClient; +import com.raytheon.uf.viz.derivparam.tree.AbstractRequestableLevelNode; +import com.raytheon.uf.viz.derivparam.tree.AbstractRequestableLevelNode.Dependency; + +/** + * Abstract data cube adapter for standard data type that uses derived + * parameters + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 30, 2012            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public abstract class AbstractDataCubeAdapter implements IDataCubeAdapter { + + private String[] supportedPlugins; + + protected AbstractDataCubeAdapter(String[] supportedPlugins) { + this.supportedPlugins = supportedPlugins; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getSupportedPlugins + * () + */ + @Override + public String[] getSupportedPlugins() { + return supportedPlugins; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#timeQuery(java + * .util.List) + */ + @Override + public List> timeQuery(List requests) + throws VizException { + int mapSize = (int) (requests.size() * 1) + 1; + Map> cache = new HashMap>( + mapSize); + LinkedHashMap queries = new LinkedHashMap( + mapSize); + + for (TimeQueryRequest request : requests) { + List requestNodes = evaluateRequestConstraints(request + .getQueryTerms()); + // pull out time queries and bulk submit + for (AbstractRequestableLevelNode requestNode : requestNodes) { + getTimeQuery(request, requestNode, false, queries, cache, null); + } + } + + // set the results back into the cache's + TimeQueryRequestSet reqSet = new TimeQueryRequestSet(); + reqSet.setRequests(queries.values().toArray( + new TimeQueryRequest[queries.size()])); + @SuppressWarnings("unchecked") + List> qResponses = (List>) ThriftClient + .sendRequest(reqSet); + int index = 0; + for (AbstractRequestableLevelNode node : queries.keySet()) { + // put results into cache + node.setTimeQueryResults(false, qResponses.get(index++), cache, + null); + } + List> finalResponse = new ArrayList>( + requests.size()); + for (TimeQueryRequest request : requests) { + List requestNodes = evaluateRequestConstraints(request + .getQueryTerms()); + // pull the actual results from the cache + Set results = new HashSet(64); + for (AbstractRequestableLevelNode requestNode : requestNodes) { + Set times = requestNode.timeQuery(request, false, + cache, null); + if (times == AbstractRequestableLevelNode.TIME_AGNOSTIC) { + // TODO: include time agnostic query in main bulk query as + // each pressure level will cause a separate query + List temp = timeAgnosticQuery(request + .getQueryTerms()); + if (temp != null) { + results.addAll(temp); + } + break; + } else { + results.addAll(times); + } + } + if (!request.isMaxQuery() || results.isEmpty()) { + finalResponse.add(new ArrayList(results)); + } else { + ArrayList response = new ArrayList(results); + Collections.sort(response); + finalResponse + .add(Arrays.asList(response.get(response.size() - 1))); + } + } + return finalResponse; + } + + protected void getTimeQuery( + TimeQueryRequest originalRequest, + AbstractRequestableLevelNode req, + boolean latestOnly, + LinkedHashMap queries, + Map> cache, + Map> latestOnlyCache) + throws VizException { + List depends = req.getDependencies(); + if (depends.isEmpty()) { + // is source node + TimeQueryRequest myQ = req.getTimeQuery(originalRequest, + latestOnly, cache, latestOnlyCache); + if (myQ != null) { + // no need to merge timeQueries + queries.put(req, myQ); + } + } else { + for (Dependency dep : depends) { + // TODO: Optimize dTime/fTime to use bulk query mechanism, + // small case that is a not easy to get right with a bulk + // query + if (dep.timeOffset == 0 || !latestOnly) { + getTimeQuery(originalRequest, dep.node, latestOnly, + queries, cache, latestOnlyCache); + } + } + } + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getPoints(java + * .lang.String, java.lang.String[], java.util.Map) + */ + @Override + public PointDataContainer getPoints(String plugin, String[] parameters, + Map queryParams) throws VizException { + // TODO Someday we should put objective analysis code + // into this area + return null; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getPoints(java + * .lang.String, java.lang.String[], java.lang.String, java.util.Map) + */ + @Override + public PointDataContainer getPoints(String plugin, String[] parameters, + String levelKey, Map queryParams) + throws VizException { + // TODO Someday we should put objective analysis code + // into this area + return null; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getData(com.raytheon + * .uf.viz.core.catalog.LayerProperty, int) + */ + @Override + public List getData(LayerProperty property, int timeOut) + throws VizException { + List requests = evaluateRequestConstraints(property + .getEntryQueryParameters(false)); + int mapSize = (int) (requests.size() * 1.25) + 1; + Map> cache = new HashMap>( + mapSize); + LinkedHashMap queries = new LinkedHashMap( + mapSize); + for (AbstractRequestableLevelNode req : requests) { + getDataQuery(req, property, timeOut, queries, cache); + } + DbQueryRequestSet reqSet = new DbQueryRequestSet(); + reqSet.setQueries(queries.values().toArray( + new DbQueryRequest[queries.size()])); + DbQueryResponseSet qSetResponse = (DbQueryResponseSet) ThriftClient + .sendRequest(reqSet); + DbQueryResponse[] qResponses = qSetResponse.getResults(); + int index = 0; + for (AbstractRequestableLevelNode node : queries.keySet()) { + // put results into cache + node.setDataQueryResults(qResponses[index++], cache); + } + + // pull the actual results from the cache + List requesters = new ArrayList( + requests.size()); + for (AbstractRequestableLevelNode request : requests) { + requesters.addAll(request.getData(property, timeOut, cache)); + } + + return getData(property, requesters); + } + + protected void getDataQuery( + AbstractRequestableLevelNode req, + LayerProperty property, + int timeOut, + LinkedHashMap queries, + Map> cache) + throws VizException { + List depends = req.getDependencies(); + if (depends.isEmpty()) { + // is source node + DbQueryRequest myQ = req.getDataQuery(property, timeOut, cache); + if (myQ != null) { + addDataQuery(req, myQ, queries); + } + } else { + for (Dependency dep : depends) { + // TODO: Optimize dTime/fTime to use bulk query mechanism, + // small case that is a not easy to get right with a bulk + // query + if (dep.timeOffset == 0) { + getDataQuery(dep.node, property, timeOut, queries, cache); + } + } + } + } + + private void addDataQuery(AbstractRequestableLevelNode req, + DbQueryRequest query, + LinkedHashMap queries) { + DbQueryRequest curQuery = queries.get(req); + if (curQuery == null) { + queries.put(req, query); + } else { + // merge + // assume same DB, fields, etc, should only be different + // time constraints since its the same node + RequestConstraint curDTs = curQuery.getConstraints() + .get("dataTime"); + RequestConstraint myDTs = query.getConstraints().get("dataTime"); + if (curDTs != null && myDTs != null) { + // only merge if both require dataTimes, otherwise one + // would be constrained when it needs everything, also + // assuming both to be in lists and needing to be merged + curDTs.setConstraintType(ConstraintType.IN); + Pattern split = Pattern.compile(","); + + String[] curVals = split.split(curDTs.getConstraintValue()); + String[] myVals = split.split(myDTs.getConstraintValue()); + HashSet dups = new HashSet(curVals.length + + myVals.length); + dups.addAll(Arrays.asList(curVals)); + dups.addAll(Arrays.asList(myVals)); + curDTs.setConstraintValueList(dups.toArray(new String[dups + .size()])); + } + } + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter# + * getBaseUpdateConstraints(java.util.Map) + */ + @Override + public List> getBaseUpdateConstraints( + Map constraints) { + List> result = new ArrayList>( + 1); + result.add(constraints); + return result; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getRecord(com + * .raytheon.uf.common.dataplugin.PluginDataObject) + */ + @Override + public IDataRecord[] getRecord(PluginDataObject obj) + throws VizDataCubeException { + return getRecord(obj, Request.ALL, null); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#getRecord(com + * .raytheon.uf.common.dataplugin.PluginDataObject, + * com.raytheon.uf.common.datastorage.Request, java.lang.String) + */ + @Override + public IDataRecord[] getRecord(PluginDataObject obj, Request req, + String dataset) throws VizDataCubeException { + getRecords(Arrays.asList(obj), req, dataset); + IDataRecord[] result = (IDataRecord[]) obj.getMessageData(); + obj.setMessageData(null); + return result; + } + + /** + * Scan the inventory for AbstractRequestableLevelNodes that match the + * request constraints + * + * @param constraints + * @return + */ + protected abstract List evaluateRequestConstraints( + Map constraints); + + /** + * @param queryTerms + * @return + */ + protected abstract List timeAgnosticQuery( + Map queryTerms) throws VizException; + + /** + * @param requesters + * @return + */ + protected abstract List getData(LayerProperty property, + List requesters) throws VizException; +} diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/inv/AbstractInventory.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/inv/AbstractInventory.java index cd8b274578..7046d034fa 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/inv/AbstractInventory.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/inv/AbstractInventory.java @@ -22,6 +22,7 @@ package com.raytheon.uf.viz.derivparam.inv; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Deque; import java.util.HashMap; import java.util.HashSet; @@ -32,6 +33,7 @@ import java.util.Set; import java.util.SortedSet; import java.util.concurrent.BlockingQueue; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataquery.requests.RequestConstraint; import com.raytheon.uf.common.derivparam.tree.AbstractNode; @@ -43,6 +45,7 @@ import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.time.DataTime; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.level.LevelMappingFactory; import com.raytheon.uf.viz.core.level.LevelUtilities; @@ -179,9 +182,12 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { * tree and populates it with available derived parameters based on what is * available from the base parameters. * + * @throws VizException + * * */ - public synchronized void initTree(Map derParLibrary) { + public synchronized void initTree(Map derParLibrary) + throws VizException { DerivedParameterGenerator.registerUpdateListener(this); if (derParLibrary == null) { this.derParLibrary = new HashMap(0); @@ -189,7 +195,8 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { this.derParLibrary = derParLibrary; } long startTime = System.currentTimeMillis(); - DataTree newTree = createBaseTree(); + DataTree newTree = null; + newTree = createBaseTree(); if (newTree == null) { return; } @@ -198,7 +205,13 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { allLevels = null; dataTree = newTree; for (SourceNode sourceNode : dataTree.getSourceNodes().values()) { - doSupplement(sourceNode); + try { + doSupplement(sourceNode); + } catch (VizCommunicationException e) { + // TODO need to recover from this + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); + } for (ParameterNode parameterNode : sourceNode.getChildNodes() .values()) { String value = parameterNode.getValue(); @@ -216,7 +229,11 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { @Override public void updateDerParLibrary(Map derParLibrary) { - initTree(derParLibrary); + try { + initTree(derParLibrary); + } catch (VizException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + } } public String getParameterUnit(String source, String parameter) { @@ -254,8 +271,10 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { * Resolve any Supplement Derived Parameters. * * @param sNode + * @throws VizCommunicationException */ - private void doSupplement(SourceNode sNode) { + private void doSupplement(SourceNode sNode) + throws VizCommunicationException { Set nodata = new HashSet(); Deque stack = new ArrayDeque(); for (DerivParamDesc desc : derParLibrary.values()) { @@ -300,7 +319,7 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { } } - protected abstract DataTree createBaseTree(); + protected abstract DataTree createBaseTree() throws VizException; /** * Handle a query for a time agnostic node. @@ -320,7 +339,7 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { protected Collection getAllSources() { if (allSources == null) { if (dataTree == null) { - return null; + return Collections.emptyList(); } else { return new ArrayList(dataTree.getSources()); } @@ -452,10 +471,18 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { * See get allSources, same function but for levels * * @return + * @throws VizCommunicationException */ protected Collection getAllLevels() { if (allLevels == null) { - return LevelMappingFactory.getInstance().getAllLevels(); + try { + return LevelMappingFactory.getInstance().getAllLevels(); + } catch (VizCommunicationException e) { + // TODO recover from this. + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); + return Collections.emptyList(); + } } else { return allLevels; } @@ -552,7 +579,7 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { || levelsToProcess == null || sourcesToProcess.isEmpty() || paramsToProcess.isEmpty() || levelsToProcess.isEmpty() || derParLibrary == null) { - return null; + return Collections.emptyList(); } if (clazz != null) { // when clazz == null we need to link the aliases to the source @@ -605,8 +632,13 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { Level level = lit.next(); AbstractRequestableLevelNode result = null; if (derive) { - result = resolveNode(node, param, level, stack, - nodata); + try { + result = resolveNode(node, param, level, stack, + nodata); + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, + e.getLocalizedMessage(), e); + } } else { ParameterNode pNode = node.getChildNode(param); result = (AbstractRequestableLevelNode) (pNode == null ? null @@ -654,11 +686,17 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { List choices = new ArrayList(); for (String aliasModel : sourceAliases .get(source)) { - AbstractRequestableLevelNode alias; + AbstractRequestableLevelNode alias = null; if (derive) { - alias = resolveNode( - dataTree.getSourceNode(aliasModel), - param, level, stack, nodata); + try { + alias = resolveNode( + dataTree.getSourceNode(aliasModel), + param, level, stack, nodata); + } catch (VizCommunicationException e) { + statusHandler.handle( + Priority.PROBLEM, + e.getLocalizedMessage(), e); + } } else { ParameterNode pNode = node .getChildNode(param); @@ -722,10 +760,12 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { * @param stack * @param nodata * @return + * @throws VizCommunicationException */ protected synchronized AbstractRequestableLevelNode resolveNode( SourceNode sourceNode, String param, Level level, - Deque stack, Set nodata) { + Deque stack, Set nodata) + throws VizCommunicationException { ParameterNode pNode = sourceNode.getChildNode(param); LevelNode lNode = pNode == null ? null : pNode.getChildNode(Long .toString(level.getId())); @@ -861,8 +901,14 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { }// method loop } if (level.isRangeLevel()) { - Level upperLevel = level.getUpperLevel(); - Level lowerLevel = level.getLowerLevel(); + Level upperLevel; + Level lowerLevel; + try { + upperLevel = level.getUpperLevel(); + lowerLevel = level.getLowerLevel(); + } catch (CommunicationException e) { + throw new VizCommunicationException(e); + } List nodes = new ArrayList(); int endCount = 0; @@ -956,10 +1002,11 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { * @param nodata * @return Should be Either some IStaticData or an * AbstractRequestableLevelNode + * @throws VizCommunicationException */ private synchronized Object resolveField(SourceNode sourceNode, Level level, IDerivParamField ifield, Deque stack, - Set nodata) { + Set nodata) throws VizCommunicationException { // process the next field if (ifield.getClass() == DerivParamConstantField.class) { return new FloatRequestableData( @@ -1004,10 +1051,14 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { if (type == null) { fieldLevel = level; } else if (level.isRangeLevel()) { - if (type == LevelType.Upper) { - fieldLevel = level.getUpperLevel(); - } else { - fieldLevel = level.getLowerLevel(); + try { + if (type == LevelType.Upper) { + fieldLevel = level.getUpperLevel(); + } else { + fieldLevel = level.getLowerLevel(); + } + } catch (CommunicationException e) { + throw new VizCommunicationException(e); } } else { SortedSet levels = null; @@ -1067,7 +1118,7 @@ public abstract class AbstractInventory implements DerivParamUpdateListener { protected abstract LevelNode getCubeNode(SourceNode sNode, DerivParamField field, Deque stack, - Set nodata); + Set nodata) throws VizCommunicationException; protected abstract AbstractDerivedLevelNode getImportNode( AbstractRequestableData nodeToImport, SourceNode destSourceNode, diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/DerivParamField.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/DerivParamField.java index 7ecc6b23c9..7f1859e02a 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/DerivParamField.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/DerivParamField.java @@ -29,6 +29,7 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.adapters.UnitAdapter; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; import com.raytheon.uf.viz.core.level.LevelMapping; import com.raytheon.uf.viz.core.level.LevelMappingFactory; @@ -82,14 +83,14 @@ public class DerivParamField implements ISerializableObject, IDerivParamField { this.param = param; } - public LevelMapping getLevelMapping() { + public LevelMapping getLevelMapping() throws VizCommunicationException { if (levelType == null && level != null) { setLevel(level); } return levelMapping; } - public LevelType getLevelType() { + public LevelType getLevelType() throws VizCommunicationException { if (levelType == null && level != null) { setLevel(level); } @@ -125,8 +126,9 @@ public class DerivParamField implements ISerializableObject, IDerivParamField { * @param level * @return true upon success, false if the token is not recognized, in which * case levelType and levelMapping will both be reset to null + * @throws VizCommunicationException */ - public boolean setLevel(String level) { + public boolean setLevel(String level) throws VizCommunicationException { levelType = LevelType.parseLevel(level); if (levelType == LevelType.LevelMapping) { levelMapping = LevelMappingFactory.getInstance() diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/DerivParamMethod.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/DerivParamMethod.java index 508177bc7f..d4945a3cbf 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/DerivParamMethod.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/DerivParamMethod.java @@ -38,9 +38,8 @@ import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.uf.viz.core.status.StatusConstants; -import com.raytheon.uf.viz.derivparam.Activator; /** * Metadata about a derived parameter method. @@ -61,7 +60,8 @@ import com.raytheon.uf.viz.derivparam.Activator; @XmlAccessorType(XmlAccessType.NONE) @XmlRootElement public class DerivParamMethod implements ISerializableObject { - private static final transient IUFStatusHandler statusHandler = UFStatus.getHandler(DerivParamMethod.class); + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(DerivParamMethod.class); public enum FrameworkMethod { ALIAS, MODELRUN, TIMERANGE, OR, UNION, SUPPLEMENT, IMPORT, NODERIVATION; @@ -149,7 +149,7 @@ public class DerivParamMethod implements ISerializableObject { fields.add(field); } - public Set getValidLevels() { + public Set getValidLevels() throws VizCommunicationException { if (validLevels == null && levels != null && levels.length() > 0) { ValidLevelGenerator lvlGen = new ValidLevelGenerator(); validLevels = lvlGen.generateLevels(levels); @@ -253,13 +253,13 @@ public class DerivParamMethod implements ISerializableObject { tmp.append(pFieldTokens[k]); } - statusHandler.handle( - Priority.SIGNIFICANT, - "Derived parameter [" - + "field [" - + field.getParam() - + "], contains unknown parameter modifier [" - + tmp.toString() + "]"); + statusHandler + .handle(Priority.SIGNIFICANT, + "Derived parameter [" + + "field [" + + field.getParam() + + "], contains unknown parameter modifier [" + + tmp.toString() + "]"); } } } diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/ValidLevelGenerator.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/ValidLevelGenerator.java index c63deba983..2e7888f7a6 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/ValidLevelGenerator.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/library/ValidLevelGenerator.java @@ -28,10 +28,12 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.level.CompareType; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.level.LevelFactory; import com.raytheon.uf.common.dataplugin.level.MasterLevel; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; import com.raytheon.uf.viz.core.level.LevelMapping; import com.raytheon.uf.viz.core.level.LevelMappingFactory; @@ -72,7 +74,7 @@ public class ValidLevelGenerator { } public Set generateLevels(String validLevelsString) - throws IllegalArgumentException { + throws IllegalArgumentException, VizCommunicationException { masterLevels = new HashMap>(); validLevels = new HashSet(); masterLevelsHandled = new HashSet(); @@ -121,7 +123,11 @@ public class ValidLevelGenerator { if (tokensToProcess.size() > 0) { for (String token : tokensToProcess) { - processLevelToken(token); + try { + processLevelToken(token); + } catch (CommunicationException e) { + throw new VizCommunicationException(e); + } } } else { for (Set levels : masterLevels.values()) { @@ -133,7 +139,8 @@ public class ValidLevelGenerator { return validLevels; } - private void processLevelToken(String token) { + private void processLevelToken(String token) + throws VizCommunicationException, CommunicationException { boolean negate = token.charAt(0) == '!'; int rangeIndex = token.indexOf('>'); @@ -318,7 +325,8 @@ public class ValidLevelGenerator { } } - private Type determineType(String token) { + private Type determineType(String token) throws CommunicationException, + VizCommunicationException { Type rval = null; LevelMapping mapping = lmf.getLevelMappingForKey(token); diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractAliasLevelNode.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractAliasLevelNode.java index 299dc63a20..6ba0fd2526 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractAliasLevelNode.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractAliasLevelNode.java @@ -26,6 +26,7 @@ import java.util.Set; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataquery.requests.RequestConstraint; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.derivparam.library.DerivParamDesc; @@ -67,11 +68,13 @@ public abstract class AbstractAliasLevelNode extends AbstractDerivedLevelNode { } @Override - public Set timeQueryInternal(boolean latestOnly, + public Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { - return sourceNode.timeQuery(latestOnly, cache, latestOnlyCache); + return sourceNode.timeQuery(originalRequest, latestOnly, cache, + latestOnlyCache); } @Override diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractCubeLevelNode.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractCubeLevelNode.java index 7273561c1f..fbe71d0063 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractCubeLevelNode.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractCubeLevelNode.java @@ -31,6 +31,7 @@ import java.util.Set; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataquery.requests.RequestConstraint; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.catalog.CatalogQuery; import com.raytheon.uf.viz.core.catalog.LayerProperty; @@ -270,7 +271,8 @@ public abstract class AbstractCubeLevelNode extends AbstractDerivedLevelNode { Map requestContraintsToFilter); @Override - public Set timeQueryInternal(boolean latestOnly, + public Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { @@ -299,8 +301,8 @@ public abstract class AbstractCubeLevelNode extends AbstractDerivedLevelNode { results.addAll(mergedTimeQuery(merge(requests), latestOnly)); for (AbstractRequestableLevelNode request : requests) { - results.addAll(request - .timeQuery(latestOnly, cache, latestOnlyCache)); + results.addAll(request.timeQuery(originalRequest, latestOnly, + cache, latestOnlyCache)); } return results; } diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractDerivedLevelNode.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractDerivedLevelNode.java index 3c0899c34e..777a6d39a9 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractDerivedLevelNode.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractDerivedLevelNode.java @@ -243,7 +243,8 @@ public abstract class AbstractDerivedLevelNode extends } @Override - protected TimeQueryRequest getTimeQueryInternal(boolean latestOnly, + protected TimeQueryRequest getTimeQueryInternal( + TimeQueryRequest originalRequest, boolean latestOnly, Map> cache) throws VizException { throw new UnsupportedOperationException( diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractRequestableLevelNode.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractRequestableLevelNode.java index 050d89cda7..2a4d8040c9 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractRequestableLevelNode.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/AbstractRequestableLevelNode.java @@ -205,7 +205,8 @@ public abstract class AbstractRequestableLevelNode extends LevelNode { protected abstract List processDataQueryResults( DbQueryResponse queryResponse) throws VizException; - public Set timeQuery(boolean latestOnly, + public Set timeQuery(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { @@ -215,15 +216,16 @@ public abstract class AbstractRequestableLevelNode extends LevelNode { return latestOnlyCache.get(this); } - Set results = timeQueryInternal(latestOnly, cache, - latestOnlyCache); + Set results = timeQueryInternal(originalRequest, latestOnly, + cache, latestOnlyCache); if (cache != null && !latestOnly) { cache.put(this, results); } return results; } - public TimeQueryRequest getTimeQuery(boolean latestOnly, + public TimeQueryRequest getTimeQuery(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { @@ -233,7 +235,7 @@ public abstract class AbstractRequestableLevelNode extends LevelNode { return null; } - return getTimeQueryInternal(latestOnly, cache); + return getTimeQueryInternal(originalRequest, latestOnly, cache); } public void setTimeQueryResults(boolean latestOnly, @@ -386,13 +388,14 @@ public abstract class AbstractRequestableLevelNode extends LevelNode { return rval; } - protected abstract Set timeQueryInternal(boolean latestOnly, + protected abstract Set timeQueryInternal( + TimeQueryRequest originalRequest, boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException; protected abstract TimeQueryRequest getTimeQueryInternal( - boolean latestOnly, + TimeQueryRequest originalRequest, boolean latestOnly, Map> cache) throws VizException; @@ -408,8 +411,9 @@ public abstract class AbstractRequestableLevelNode extends LevelNode { Map> cache) throws VizException; - protected Set timeQuery(boolean latestOnly) throws VizException { - return timeQuery(latestOnly, + protected Set timeQuery(TimeQueryRequest originalRequest, + boolean latestOnly) throws VizException { + return timeQuery(originalRequest, latestOnly, new HashMap>(), new HashMap>()); } diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/CompositeAverageLevelNode.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/CompositeAverageLevelNode.java index 2fced96c35..abc78c6142 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/CompositeAverageLevelNode.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/CompositeAverageLevelNode.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Set; import com.raytheon.uf.common.dataplugin.level.Level; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.catalog.LayerProperty; import com.raytheon.uf.viz.core.exception.VizException; @@ -102,7 +103,8 @@ public class CompositeAverageLevelNode extends UnionLevelNode { * boolean, java.util.Map) */ @Override - public Set timeQueryInternal(boolean latestOnly, + public Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { @@ -114,8 +116,8 @@ public class CompositeAverageLevelNode extends UnionLevelNode { for (AbstractRequestableLevelNode request : requests) { // Do not request just latest only because if two nodes have // different latests than this will return no times - Set times = request.timeQuery(false, cache, - latestOnlyCache); + Set times = request.timeQuery(originalRequest, false, + cache, latestOnlyCache); if (times == TIME_AGNOSTIC) { continue; } else if (results == TIME_AGNOSTIC) { diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/DerivedLevelNode.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/DerivedLevelNode.java index cd831997bc..220f9fa03a 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/DerivedLevelNode.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/DerivedLevelNode.java @@ -32,6 +32,7 @@ import java.util.Map.Entry; import java.util.Set; import com.raytheon.uf.common.dataplugin.level.Level; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.common.time.DataTime.FLAG; import com.raytheon.uf.viz.core.catalog.LayerProperty; @@ -65,6 +66,8 @@ import com.raytheon.uf.viz.derivparam.library.IDerivParamField; public class DerivedLevelNode extends AbstractDerivedLevelNode { + private static final int TIME_QUERY_CACHE_TIME = 30000; + private Map fieldStaticData = null; private Map fields = null; @@ -75,6 +78,8 @@ public class DerivedLevelNode extends AbstractDerivedLevelNode { */ private Map> timeCache = null; + private long lastTimeQuery = 0; + private int dt; public DerivedLevelNode(Level level, DerivParamDesc desc, @@ -145,10 +150,12 @@ public class DerivedLevelNode extends AbstractDerivedLevelNode { } @Override - public Set timeQueryInternal(boolean latestOnly, + public Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { + this.lastTimeQuery = System.currentTimeMillis(); Map> timeCache = new HashMap>(); // We have a derived parameter for the requested grid Set availableDataTimes = null; @@ -171,8 +178,8 @@ public class DerivedLevelNode extends AbstractDerivedLevelNode { } for (DerivParamField field : fieldsKeys) { AbstractRequestableLevelNode node = fields.get(field); - Set queryDataTimes = node.timeQuery(false, cache, - latestOnlyCache); + Set queryDataTimes = node.timeQuery(originalRequest, + false, cache, latestOnlyCache); timeCache.put(field, queryDataTimes); if (queryDataTimes == TIME_AGNOSTIC) { if (availableDataTimes == null) { @@ -277,8 +284,10 @@ public class DerivedLevelNode extends AbstractDerivedLevelNode { int timeOut, Map> cache) throws VizException { - if (this.timeCache == null) { - this.timeQuery(false); + if (this.timeCache == null + || this.lastTimeQuery + TIME_QUERY_CACHE_TIME < System + .currentTimeMillis()) { + this.timeQuery(null, false); } // keep a reference for scope of method diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/ModelRunLevelNode.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/ModelRunLevelNode.java index e6ca35a9ca..bb847c456b 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/ModelRunLevelNode.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/ModelRunLevelNode.java @@ -24,8 +24,8 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.time.DataTime; @@ -70,7 +70,7 @@ public class ModelRunLevelNode extends AbstractAliasLevelNode { int timeOut, Map> cache) throws VizException { - Set allTimes = this.timeQuery(false); + Set allTimes = this.timeQuery(null, false); Set neededTimes = null; DataTime[] requestedTimes = property.getSelectedEntryTime(); if (requestedTimes == null) { diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/OrLevelNode.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/OrLevelNode.java index c021879be6..370c16b9a0 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/OrLevelNode.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/OrLevelNode.java @@ -28,6 +28,7 @@ import java.util.Set; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataquery.requests.RequestConstraint; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.catalog.LayerProperty; import com.raytheon.uf.viz.core.exception.VizException; @@ -116,7 +117,7 @@ public class OrLevelNode extends AbstractDerivedLevelNode { Set requestedTimes = null; DataTime[] requestedTimesArr = property.getSelectedEntryTime(); if (requestedTimesArr == null) { - requestedTimes = this.timeQuery(false); + requestedTimes = this.timeQuery(null, false); } else { requestedTimes = new HashSet( Arrays.asList(requestedTimesArr)); @@ -144,14 +145,15 @@ public class OrLevelNode extends AbstractDerivedLevelNode { } @Override - protected Set timeQueryInternal(boolean latestOnly, + protected Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { Set results = new HashSet(); for (AbstractRequestableLevelNode node : nodes) { - Set times = node.timeQuery(latestOnly, cache, - latestOnlyCache); + Set times = node.timeQuery(originalRequest, latestOnly, + cache, latestOnlyCache); if (times == AbstractRequestableLevelNode.TIME_AGNOSTIC) { return times; } else { diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/StaticDataLevelNode.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/StaticDataLevelNode.java index 433117e4d1..8fd9ff5528 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/StaticDataLevelNode.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/StaticDataLevelNode.java @@ -99,7 +99,8 @@ public class StaticDataLevelNode extends AbstractDerivedLevelNode { } @Override - public Set timeQueryInternal(boolean latestOnly, + public Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { @@ -107,7 +108,8 @@ public class StaticDataLevelNode extends AbstractDerivedLevelNode { } @Override - protected TimeQueryRequest getTimeQueryInternal(boolean latestOnly, + protected TimeQueryRequest getTimeQueryInternal( + TimeQueryRequest originalRequest, boolean latestOnly, Map> cache) throws VizException { return null; diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/TimeRangeLevelNode.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/TimeRangeLevelNode.java index 336e32ecc8..466fd8bee5 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/TimeRangeLevelNode.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/TimeRangeLevelNode.java @@ -28,6 +28,7 @@ import java.util.Map.Entry; import java.util.Set; import com.raytheon.uf.common.dataplugin.level.Level; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.catalog.LayerProperty; import com.raytheon.uf.viz.core.exception.VizException; @@ -82,7 +83,7 @@ public class TimeRangeLevelNode extends AbstractAliasLevelNode { int timeOut, Map> cache) throws VizException { - Set allTime = sourceNode.timeQuery(false); + Set allTime = sourceNode.timeQuery(null, false); Map> goodTimes = new HashMap>(); Set timesToRequest = new HashSet(); for (DataTime time : allTime) { @@ -126,12 +127,13 @@ public class TimeRangeLevelNode extends AbstractAliasLevelNode { } @Override - public Set timeQueryInternal(boolean latestOnly, + public Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { - Set allTime = sourceNode.timeQuery(false, cache, - latestOnlyCache); + Set allTime = sourceNode.timeQuery(originalRequest, false, + cache, latestOnlyCache); Set goodTimes = new HashSet(); for (DataTime time : allTime) { if (allTime.containsAll(calculateNeededTimes(time))) { diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/UnionLevelNode.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/UnionLevelNode.java index dc1bdbf4b9..4db0ae9216 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/UnionLevelNode.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/UnionLevelNode.java @@ -30,6 +30,7 @@ import java.util.Map.Entry; import java.util.Set; import com.raytheon.uf.common.dataplugin.level.Level; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.catalog.LayerProperty; import com.raytheon.uf.viz.core.exception.VizException; @@ -142,7 +143,8 @@ public class UnionLevelNode extends AbstractDerivedLevelNode { } @Override - public Set timeQueryInternal(boolean latestOnly, + public Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { @@ -153,8 +155,8 @@ public class UnionLevelNode extends AbstractDerivedLevelNode { List requests = new ArrayList( nodes); for (AbstractRequestableLevelNode request : requests) { - Set times = request.timeQuery(latestOnly, cache, - latestOnlyCache); + Set times = request.timeQuery(originalRequest, + latestOnly, cache, latestOnlyCache); if (times == TIME_AGNOSTIC) { continue; } else if (results == TIME_AGNOSTIC) { diff --git a/cave/com.raytheon.uf.viz.objectiveanalysis/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.objectiveanalysis/META-INF/MANIFEST.MF index df29ed5ed1..5f8f57f3fd 100644 --- a/cave/com.raytheon.uf.viz.objectiveanalysis/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.uf.viz.objectiveanalysis/META-INF/MANIFEST.MF @@ -27,8 +27,10 @@ Require-Bundle: org.eclipse.ui, Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Export-Package: com.raytheon.uf.viz.objectiveanalysis.rsc -Import-Package: com.raytheon.uf.common.dataplugin.grib.spatial.projections, +Import-Package: com.raytheon.uf.common.comm, + com.raytheon.uf.common.dataplugin.grib.spatial.projections, com.raytheon.uf.common.dataplugin.level, + com.raytheon.uf.common.dataplugin.radar, com.raytheon.uf.viz.derivparam.library, com.raytheon.uf.viz.derivparam.tree, com.raytheon.viz.ui, diff --git a/cave/com.raytheon.uf.viz.objectiveanalysis/src/com/raytheon/uf/viz/objectiveanalysis/rsc/OAResourceData.java b/cave/com.raytheon.uf.viz.objectiveanalysis/src/com/raytheon/uf/viz/objectiveanalysis/rsc/OAResourceData.java index 0f7b26f8bb..63c9cd9839 100644 --- a/cave/com.raytheon.uf.viz.objectiveanalysis/src/com/raytheon/uf/viz/objectiveanalysis/rsc/OAResourceData.java +++ b/cave/com.raytheon.uf.viz.objectiveanalysis/src/com/raytheon/uf/viz/objectiveanalysis/rsc/OAResourceData.java @@ -27,18 +27,20 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.level.LevelFactory; import com.raytheon.uf.common.dataplugin.level.MasterLevel; import com.raytheon.uf.common.time.DataTime; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.level.LevelMappingFactory; import com.raytheon.uf.viz.core.rsc.AbstractRequestableResourceData; import com.raytheon.uf.viz.core.rsc.AbstractVizResource; import com.raytheon.uf.viz.core.rsc.LoadProperties; -import com.raytheon.uf.viz.core.style.level.SingleLevel; import com.raytheon.uf.viz.core.style.level.Level.LevelType; +import com.raytheon.uf.viz.core.style.level.SingleLevel; /** * Resource Data for Objective Analysis @@ -161,8 +163,8 @@ public class OAResourceData extends AbstractRequestableResourceData { throw new UnsupportedOperationException("Unsupported level for OA " + levelKey); } - level.setValue(Double.parseDouble(levelKey.substring(0, levelKey - .length() - 2))); + level.setValue(Double.parseDouble(levelKey.substring(0, + levelKey.length() - 2))); return level; } @@ -194,7 +196,12 @@ public class OAResourceData extends AbstractRequestableResourceData { DataTime[] times = super.getAvailableTimes(); if (this.levelKey.equals(ALL_TILTS)) { LevelFactory factory = LevelFactory.getInstance(); - MasterLevel ml = factory.getMasterLevel("TILT"); + MasterLevel ml; + try { + ml = factory.getMasterLevel("TILT"); + } catch (CommunicationException e) { + throw new VizCommunicationException(e); + } Set allLevels = LevelMappingFactory.getInstance() .getAllLevels(); List levels = new ArrayList(); diff --git a/cave/com.raytheon.uf.viz.radar.gl/localization/glsl/mosaicMaxVal.glsl b/cave/com.raytheon.uf.viz.radar.gl/localization/glsl/mosaicMaxVal.glsl index d8c52b9b0b..c6268a397a 100644 --- a/cave/com.raytheon.uf.viz.radar.gl/localization/glsl/mosaicMaxVal.glsl +++ b/cave/com.raytheon.uf.viz.radar.gl/localization/glsl/mosaicMaxVal.glsl @@ -10,7 +10,7 @@ void main(void) { vec2 xy = gl_FragCoord.xy; vec4 radarVal = texture2D(radarData,gl_TexCoord[0].st); - vec4 curVal = texture2D(mosaicTexture, vec2((xy.x / width), (xy.y / height))); + vec4 curVal = texture2D(mosaicTexture, vec2((xy.x / float(width)), (xy.y / float(height)))); if ( radarVal.r > curVal.r ) { gl_FragColor = vec4(radarVal.r,0.0,0.0,1.0); } else { diff --git a/cave/com.raytheon.uf.viz.radar.gl/localization/glsl/mosaicMinDist.glsl b/cave/com.raytheon.uf.viz.radar.gl/localization/glsl/mosaicMinDist.glsl deleted file mode 100644 index 95a78bd7aa..0000000000 --- a/cave/com.raytheon.uf.viz.radar.gl/localization/glsl/mosaicMinDist.glsl +++ /dev/null @@ -1,16 +0,0 @@ -// this shader program sets values into a mosaic texture -// which is the same size as the screen (frame buffer) -// Use depth buffer texture - -uniform sampler2D radarData; -uniform sampler2D mosaicTexture; -uniform sampler2D depthTexture; -uniform int height; -uniform int width; - -void main(void) -{ - // TODO: Mimic mosaicMax except use depthTexture to look up current - // depth buffer info (which will actually store the current distance - -} \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.radar.gl/localization/glsl/mostRecentVal.glsl b/cave/com.raytheon.uf.viz.radar.gl/localization/glsl/mostRecentVal.glsl deleted file mode 100644 index 70a7843250..0000000000 --- a/cave/com.raytheon.uf.viz.radar.gl/localization/glsl/mostRecentVal.glsl +++ /dev/null @@ -1,10 +0,0 @@ -// this shader program sets values into a mosaic texture -// which is the same size as the screen (frame buffer) - -uniform sampler2D radarData; - -void main(void) -{ - vec4 radarVal = texture2D(radarData,gl_TexCoord[0].st); - gl_FragColor = vec4(radarVal.r,0.0,0.0,1.0); -} \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.radar.gl/plugin.xml b/cave/com.raytheon.uf.viz.radar.gl/plugin.xml index 703eeba965..aa3f2181c6 100644 --- a/cave/com.raytheon.uf.viz.radar.gl/plugin.xml +++ b/cave/com.raytheon.uf.viz.radar.gl/plugin.xml @@ -1,24 +1,13 @@ - - - - - - + class="com.raytheon.uf.viz.radar.gl.mosaic.GLRadarMosaicImageExtension"> diff --git a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/GLRadialMeshExtension.java b/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/GLRadialMeshExtension.java index b6e5df604a..177a2a3492 100644 --- a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/GLRadialMeshExtension.java +++ b/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/GLRadialMeshExtension.java @@ -74,6 +74,6 @@ public class GLRadialMeshExtension extends GraphicsExtension */ @Override public int getCompatibilityValue(IGLTarget target) { - return Compatibilty.TARGET_COMPATIBLE.value; + return Compatibilty.TARGET_COMPATIBLE; } } diff --git a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/MosaicGLTarget.java b/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/MosaicGLTarget.java deleted file mode 100644 index 246905cde0..0000000000 --- a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/MosaicGLTarget.java +++ /dev/null @@ -1,559 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ -package com.raytheon.uf.viz.radar.gl; - -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import java.io.File; -import java.util.Collection; - -import org.eclipse.swt.graphics.RGB; -import org.geotools.coverage.grid.GeneralGridGeometry; - -import com.raytheon.uf.common.colormap.IColorMap; -import com.raytheon.uf.viz.core.DrawableCircle; -import com.raytheon.uf.viz.core.DrawableColorMap; -import com.raytheon.uf.viz.core.DrawableImage; -import com.raytheon.uf.viz.core.DrawableLine; -import com.raytheon.uf.viz.core.DrawableString; -import com.raytheon.uf.viz.core.IExtent; -import com.raytheon.uf.viz.core.IGraphicsTarget; -import com.raytheon.uf.viz.core.PixelCoverage; -import com.raytheon.uf.viz.core.data.IDataPreparer; -import com.raytheon.uf.viz.core.data.IRenderedImageCallback; -import com.raytheon.uf.viz.core.drawables.ColorMapParameters; -import com.raytheon.uf.viz.core.drawables.IDescriptor; -import com.raytheon.uf.viz.core.drawables.IFont; -import com.raytheon.uf.viz.core.drawables.IFont.Style; -import com.raytheon.uf.viz.core.drawables.IImage; -import com.raytheon.uf.viz.core.drawables.IRenderableDisplay; -import com.raytheon.uf.viz.core.drawables.IShadedShape; -import com.raytheon.uf.viz.core.drawables.IWireframeShape; -import com.raytheon.uf.viz.core.drawables.PaintProperties; -import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.uf.viz.core.geom.PixelCoordinate; -import com.raytheon.viz.core.gl.IGLTarget; -import com.vividsolutions.jts.geom.LinearRing; - -/** - * IGraphicsTarget for mosaicing radar data, delegates all calls to an IGLTarget - * - *
- * 
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * Jun 22, 2010            mschenke     Initial creation
- * Jul 19, 2010 #5952      bkowal       Defined the 'updateExtent' method.
- * 
- * 
- * - * @author mschenke - * @version 1.0 - */ - -public class MosaicGLTarget implements IGraphicsTarget { - - private IGLTarget delegate; - - public MosaicGLTarget(IGLTarget delegateTarget) { - this.delegate = delegateTarget; - } - - /* Important functions!!! */ - public boolean drawRaster(IImage image, PixelCoverage extent, - PaintProperties paintProps, RasterMode mode) throws VizException { - return delegate.drawRaster(image, extent, paintProps, mode, - "mosaicMaxVal"); - } - - public boolean drawRaster(IImage image, PixelCoverage extent, - PaintProperties paintProps) throws VizException { - return delegate.drawRaster(image, extent, paintProps, "mosaicMaxVal"); - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.IGraphicsTarget#drawRasters(com.raytheon.uf. - * viz.core.drawables.PaintProperties, - * com.raytheon.uf.viz.core.DrawableImage[]) - */ - @Override - public boolean drawRasters(PaintProperties paintProps, - DrawableImage... images) throws VizException { - return delegate.drawRasters("mosaicMaxVal", paintProps, images); - } - - /* Standard delegate functions */ - public void beginFrame(IRenderableDisplay display, boolean isClearBackground) { - delegate.beginFrame(display, isClearBackground); - } - - public IColorMap buildColorMap(String name) throws VizException { - return delegate.buildColorMap(name); - } - - public void clearClippingPlane() { - delegate.clearClippingPlane(); - } - - public IShadedShape createShadedShape(boolean mutable, - IDescriptor descriptor, boolean tesselate) { - return delegate.createShadedShape(mutable, descriptor, tesselate); - } - - public IWireframeShape createWireframeShape(boolean mutable, - GeneralGridGeometry geom, float simplificationLevel, - boolean spatialChopFlag, IExtent extent) { - return delegate.createWireframeShape(mutable, geom, - simplificationLevel, spatialChopFlag, extent); - } - - public IWireframeShape createWireframeShape(boolean mutableFlag, - GeneralGridGeometry geom) { - return delegate.createWireframeShape(mutableFlag, geom); - } - - public IWireframeShape createWireframeShape(boolean mutable, - IDescriptor descriptor, float simplificationLevel, - boolean spatialChopFlag, IExtent extent) { - return delegate.createWireframeShape(mutable, descriptor, - simplificationLevel, spatialChopFlag, extent); - } - - public IWireframeShape createWireframeShape(boolean mutable, - IDescriptor descriptor, float simplificationLevel) { - return delegate.createWireframeShape(mutable, descriptor, - simplificationLevel); - } - - public IWireframeShape createWireframeShape(boolean mutable, - IDescriptor descriptor) { - return delegate.createWireframeShape(mutable, descriptor); - } - - public void dispose() { - delegate.dispose(); - } - - public void drawArc(double x1, double y1, double z1, double radius, - RGB color, float width, int startAzimuth, int arcWidth, - LineStyle lineStyle, boolean includeSides) throws VizException { - delegate.drawArc(x1, y1, z1, radius, color, width, startAzimuth, - arcWidth, lineStyle, includeSides); - } - - public void drawCircle(double x1, double y1, double z1, double radius, - RGB color, float width) throws VizException { - delegate.drawCircle(x1, y1, z1, radius, color, width); - } - - public void drawColorRamp(IColorMap colorMap, IExtent pixelExtent, - float blendAlpha) throws VizException { - delegate.drawColorRamp(colorMap, pixelExtent, blendAlpha); - } - - public void drawCylinder(PixelCoordinate coord, RGB color, float alpha, - double height, double baseRadius, double topRadius, int sideCount, - int sliceCount, double rotation, double lean) { - delegate.drawCylinder(coord, color, alpha, height, baseRadius, - topRadius, sideCount, sliceCount, rotation, lean); - } - - public void drawFilledCircle(double x, double y, double z, double radius, - RGB color) throws VizException { - delegate.drawFilledCircle(x, y, z, radius, color); - } - - public void drawLine(double x1, double y1, double z1, double x2, double y2, - double z2, RGB color, float width, LineStyle lineStyle) - throws VizException { - delegate.drawLine(x1, y1, z1, x2, y2, z2, color, width, lineStyle); - } - - public void drawLine(double x1, double y1, double z1, double x2, double y2, - double z2, RGB color, float width) throws VizException { - delegate.drawLine(x1, y1, z1, x2, y2, z2, color, width); - } - - public void drawPoint(double x, double y, double z, RGB color, - PointStyle pointStyle) throws VizException { - delegate.drawPoint(x, y, z, color, pointStyle); - } - - public void drawRect(IExtent pe, RGB color, float lineWidth, double alpha) - throws VizException { - delegate.drawRect(pe, color, lineWidth, alpha); - } - - public void drawShadedPolygon(LinearRing poly, RGB color, double alpha, - byte[] pattern) throws VizException { - delegate.drawShadedPolygon(poly, color, alpha, pattern); - } - - public void drawShadedRect(IExtent pe, RGB color, double alpha, - byte[] pattern) throws VizException { - delegate.drawShadedRect(pe, color, alpha, pattern); - } - - public void drawShadedShape(IShadedShape shape, float alpha) - throws VizException { - delegate.drawShadedShape(shape, alpha); - } - - public void drawString(IFont font, String text, double x, double y, - double z, TextStyle textStyle, RGB color, - HorizontalAlignment horizontalAlignment, Double rotation) - throws VizException { - delegate.drawString(font, text, x, y, z, textStyle, color, - horizontalAlignment, rotation); - } - - public void drawString(IFont font, String text, double x, double y, - double z, TextStyle textStyle, RGB color, - HorizontalAlignment horizontalAlignment, - VerticalAlignment verticalAlignment, Double rotation) - throws VizException { - delegate.drawString(font, text, x, y, z, textStyle, color, - horizontalAlignment, verticalAlignment, rotation); - } - - public void drawStrings(IFont font, String[] text, double x, double y, - double z, TextStyle textStyle, RGB[] colors, - HorizontalAlignment horizontalAlignment, - VerticalAlignment verticalAlignment) throws VizException { - delegate.drawStrings(font, text, x, y, z, textStyle, colors, - horizontalAlignment, verticalAlignment); - } - - public void drawString(IFont font, String string, double xPos, double yPos, - double zPos, TextStyle textStyle, RGB color, - HorizontalAlignment horizontalAlignment, - VerticalAlignment verticalAlignment, Double rotation, float alpha, - double magnification) throws VizException { - // not implemented - } - - public void drawWireframeShape(IWireframeShape shape, RGB color, - float lineWidth, LineStyle lineStyle, IFont font) - throws VizException { - delegate.drawWireframeShape(shape, color, lineWidth, lineStyle, font); - } - - public void drawWireframeShape(IWireframeShape shape, RGB color, - float lineWidth, LineStyle lineStyle, IFont font, float alpha) - throws VizException { - delegate.drawWireframeShape(shape, color, lineWidth, lineStyle, font, - alpha); - } - - public void drawWireframeShape(IWireframeShape shape, RGB color, - float lineWidth, LineStyle lineStyle) throws VizException { - delegate.drawWireframeShape(shape, color, lineWidth, lineStyle); - } - - public void drawWireframeShape(IWireframeShape shape, RGB color, - float lineWidth, LineStyle lineStyle, float alpha) - throws VizException { - delegate.drawWireframeShape(shape, color, lineWidth, lineStyle, alpha); - } - - public void drawWireframeShape(IWireframeShape shape, RGB color, - float lineWidth) throws VizException { - delegate.drawWireframeShape(shape, color, lineWidth); - } - - public void endFrame() { - delegate.endFrame(); - } - - public IFont getDefaultFont() { - return delegate.getDefaultFont(); - } - - public double[] getPointOnCircle(double x1, double y1, double z1, - double radius, double angle) throws VizException { - return delegate.getPointOnCircle(x1, y1, z1, radius, angle); - } - - public Rectangle2D getStringBounds(IFont font, String text) { - return delegate.getStringBounds(font, text); - } - - public String getViewType() { - return delegate.getViewType(); - } - - public void init() { - delegate.init(); - } - - public IFont initializeFont(File fontFile, float size, Style[] styles) { - return delegate.initializeFont(fontFile, size, styles); - } - - public IFont initializeFont(String fontName, float size, Style[] styles) { - return delegate.initializeFont(fontName, size, styles); - } - - public IFont initializeFont(String font) { - return delegate.initializeFont(font); - } - - @Deprecated - public IImage initializeRaster(IDataPreparer preparer, - ColorMapParameters optionalParams) { - return delegate.initializeRaster(preparer, optionalParams); - } - - public IImage initializeRaster(IRenderedImageCallback imageCallback) { - return delegate.initializeRaster(imageCallback); - } - - public boolean isNeedsRefresh() { - return delegate.isNeedsRefresh(); - } - - public void resize() { - delegate.resize(); - } - - public BufferedImage screenshot() { - return delegate.screenshot(); - } - - public void setBackgroundColor(RGB backgroundColor) { - delegate.setBackgroundColor(backgroundColor); - } - - public void setNeedsRefresh(boolean needsRefresh) { - delegate.setNeedsRefresh(needsRefresh); - } - - public void setupClippingPlane(IExtent extent) { - delegate.setupClippingPlane(extent); - } - - public void setUseBuiltinColorbar(boolean isColorbarDisplayed) { - delegate.setUseBuiltinColorbar(isColorbarDisplayed); - } - - public void stage(IImage image) throws VizException { - delegate.stage(image); - } - - public void updateExtent(IExtent updatedExtent) { - /* Do Nothing */ - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.IGraphicsTarget#getStringBounds(com.raytheon - * .uf.viz.core.drawables.IFont, java.lang.String[], - * com.raytheon.uf.viz.core.IGraphicsTarget.TextStyle) - */ - @Override - public Rectangle2D getStringBounds(IFont font, String[] text, - TextStyle style) { - return delegate.getStringBounds(font, text, style); - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.IGraphicsTarget#drawColorRamp(com.raytheon.uf - * .common.colormap.IColorMap, com.raytheon.uf.viz.core.IExtent, float, - * float, float) - */ - @Override - public void drawColorRamp(IColorMap colorMap, IExtent pixelExtent, - float blendAlpha, float brightness, float contrast) - throws VizException { - delegate.drawColorRamp(colorMap, pixelExtent, blendAlpha, brightness, - contrast); - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.IGraphicsTarget#drawShadedShape(com.raytheon - * .uf.viz.core.drawables.IShadedShape, float, float) - */ - @Override - public void drawShadedShape(IShadedShape shape, float alpha, - float brightness) throws VizException { - delegate.drawShadedShape(shape, alpha, brightness); - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.IGraphicsTarget#drawColorRamp(com.raytheon.uf - * .viz.core.drawables.ColorMapParameters, com.raytheon.uf.viz.core.IExtent, - * float) - */ - @Override - public void drawColorRamp(ColorMapParameters colorMapParams, - IExtent pixelExtent, float blendAlpha) throws VizException { - - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.IGraphicsTarget#drawColorRamp(com.raytheon.uf - * .viz.core.drawables.ColorMapParameters, com.raytheon.uf.viz.core.IExtent, - * float, float, float) - */ - @Override - public void drawColorRamp(ColorMapParameters colorMapParams, - IExtent pixelExtent, float blendAlpha, float brightness, - float contrast) throws VizException { - - } - - /* - * (non-Javadoc) - * - * @see com.raytheon.uf.viz.core.IGraphicsTarget#drawPoint(double, double, - * double, org.eclipse.swt.graphics.RGB, - * com.raytheon.uf.viz.core.IGraphicsTarget.PointStyle, float) - */ - @Override - public void drawPoint(double x, double y, double z, RGB color, - PointStyle pointStyle, float magnification) throws VizException { - - } - - @Override - public void renderOffscreen(IImage offscreenImage) throws VizException { - delegate.renderOffscreen(offscreenImage); - - } - - @Override - public void renderOnscreen() throws VizException { - delegate.renderOnscreen(); - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.IGraphicsTarget#getStringsBounds(com.raytheon - * .uf.viz.core.DrawStringsParameters) - */ - @Override - public Rectangle2D getStringsBounds(DrawableString parameters) { - return null; - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.IGraphicsTarget#getStringsBounds(com.raytheon - * .uf.viz.core.DrawStringsParameters, java.lang.String) - */ - @Override - public Rectangle2D getStringsBounds(DrawableString parameters, String string) { - return null; - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.IGraphicsTarget#drawStrings(com.raytheon.uf. - * viz.core.DrawStringsParameters) - */ - @Override - public void drawStrings(DrawableString... parameters) throws VizException { - - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.IGraphicsTarget#drawColorRamp(com.raytheon.uf - * .viz.core.DrawableColorMap) - */ - @Override - public void drawColorRamp(DrawableColorMap colorMap) throws VizException { - - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.IGraphicsTarget#drawCircle(com.raytheon.uf.viz - * .core.DrawableCircle) - */ - @Override - public void drawCircle(DrawableCircle... circle) throws VizException { - - } - - @Override - public void drawStrings(Collection parameters) - throws VizException { - - } - - @Override - public void drawPoints(Collection locations, RGB color, - PointStyle pointStyle, float magnification) throws VizException { - - } - - @Override - public void drawShadedShapes(float alpha, float brightness, - IShadedShape... shapes) throws VizException { - delegate.drawShadedShapes(alpha, brightness, shapes); - } - - @Override - public T getExtension(Class extensionClass) throws VizException { - return delegate.getExtension(extensionClass); - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.IGraphicsTarget#drawLine(com.raytheon.uf.viz - * .core.DrawableLine[]) - */ - @Override - public void drawLine(DrawableLine... lines) throws VizException { - delegate.drawLine(lines); - } - -} diff --git a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/RadarRadialMesh.java b/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/RadarRadialMesh.java index 642d049b73..e0e1714b6d 100644 --- a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/RadarRadialMesh.java +++ b/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/RadarRadialMesh.java @@ -71,10 +71,10 @@ public class RadarRadialMesh extends AbstractGLMesh { throws TransformException { int horizontalDivisions = key.horizontalDivisions; - int verticalDivisions = key.verticalDivisions; + int verticalDivisions = key.verticalDivisions + 1; // get dx and dy for texture points - float dX = (1.0f / (horizontalDivisions)); + float dX = (1.0f / (key.horizontalDivisions)); vertexCoords = new GLGeometryObject2D(new GLGeometryObjectData( GL.GL_TRIANGLE_STRIP, GL.GL_VERTEX_ARRAY)); @@ -168,7 +168,7 @@ public class RadarRadialMesh extends AbstractGLMesh { @Override protected SharedCoordinateKey generateKey(ImageTile tile, MathTransform mt) { try { - return new SharedCoordinateKey(record.getNumRadials() + 1, + return new SharedCoordinateKey(record.getNumRadials(), getNumVerticalDivisions(mt, record)); } catch (Exception e) { statusHandler diff --git a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/GLMosaicImage.java b/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/GLMosaicImage.java new file mode 100644 index 0000000000..6f67c77685 --- /dev/null +++ b/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/GLMosaicImage.java @@ -0,0 +1,99 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.radar.gl.mosaic; + +import com.raytheon.uf.viz.core.DrawableImage; +import com.raytheon.viz.core.gl.images.AbstractGLImage; +import com.raytheon.viz.core.gl.images.GLDelegateImage; +import com.raytheon.viz.radar.rsc.mosaic.ext.IRadarMosaicImageExtension.IMosaicImage; + +/** + * GL implementation of IMosaicImage, wraps an offscreen image and contains + * other DrawableImages to mosaic + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 16, 2011            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public class GLMosaicImage extends GLDelegateImage implements + IMosaicImage { + + private DrawableImage[] images; + + private boolean repaint; + + private int[] bounds; + + /** + * @param target + * @param image + * @param extensionClass + */ + public GLMosaicImage(AbstractGLImage image, int[] bounds) { + super(image, GLRadarMosaicImageExtension.class); + this.bounds = bounds; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.images.GLDelegateImage#getWidth() + */ + @Override + public int getWidth() { + return bounds[0]; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.images.GLDelegateImage#getHeight() + */ + @Override + public int getHeight() { + return bounds[1]; + } + + /** + * @return the repaint + */ + public boolean isRepaint() { + return repaint; + } + + public DrawableImage[] getImagesToMosaic() { + return images; + } + + public void setImagesToMosaic(DrawableImage... images) { + this.images = images; + repaint = true; + } +} diff --git a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/GLRadarMosaicImageExtension.java b/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/GLRadarMosaicImageExtension.java new file mode 100644 index 0000000000..7e586ecb93 --- /dev/null +++ b/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/GLRadarMosaicImageExtension.java @@ -0,0 +1,157 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.radar.gl.mosaic; + +import java.nio.ByteBuffer; + +import javax.media.opengl.GL; + +import com.raytheon.uf.viz.core.DrawableImage; +import com.raytheon.uf.viz.core.PixelCoverage; +import com.raytheon.uf.viz.core.drawables.ColorMapParameters; +import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.drawables.PaintProperties; +import com.raytheon.uf.viz.core.drawables.ext.IOffscreenRenderingExtension; +import com.raytheon.uf.viz.core.exception.VizException; +import com.raytheon.viz.core.gl.ext.GLOffscreenRenderingExtension; +import com.raytheon.viz.core.gl.glsl.AbstractGLSLImagingExtension; +import com.raytheon.viz.core.gl.glsl.GLShaderProgram; +import com.raytheon.viz.core.gl.images.AbstractGLImage; +import com.raytheon.viz.radar.rsc.mosaic.ext.IRadarMosaicImageExtension; + +/** + * Extension used for rendering radar mosaic images + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 16, 2011            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public class GLRadarMosaicImageExtension extends AbstractGLSLImagingExtension + implements IRadarMosaicImageExtension { + + private AbstractGLImage writeToImage; + + public GLMosaicImage initializeRaster(int[] imageBounds, + ColorMapParameters params) throws VizException { + return new GLMosaicImage(target.getExtension( + GLOffscreenRenderingExtension.class).constructOffscreenImage( + ByteBuffer.class, imageBounds, params), imageBounds); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension#getShaderProgramName + * () + */ + @Override + public String getShaderProgramName() { + return "mosaicMaxVal"; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension#preImageRender + * (com.raytheon.uf.viz.core.drawables.PaintProperties, + * com.raytheon.viz.core.gl.images.AbstractGLImage) + */ + @Override + public synchronized Object preImageRender(PaintProperties paintProps, + AbstractGLImage image, PixelCoverage coverage) throws VizException { + if (image instanceof GLMosaicImage) { + GLMosaicImage mosaicImage = (GLMosaicImage) image; + if (mosaicImage.isRepaint()) { + writeToImage = mosaicImage.getWrappedImage(); + IOffscreenRenderingExtension extension = target + .getExtension(IOffscreenRenderingExtension.class); + try { + extension.renderOffscreen(mosaicImage); + drawRasters(paintProps, mosaicImage.getImagesToMosaic()); + } finally { + extension.renderOnscreen(); + } + writeToImage = null; + } + + target.drawRasters(paintProps, + new DrawableImage(mosaicImage.getWrappedImage(), coverage)); + // Don't actually render this image now since we just did it + return null; + } else { + GL gl = target.getGl(); + // activate on texture2 as 0 is radar image and 1 is colormap + gl.glActiveTexture(GL.GL_TEXTURE2); + gl.glBindTexture(writeToImage.getTextureStorageType(), + writeToImage.getTextureid()); + return image; + } + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension#postImageRender + * (com.raytheon.uf.viz.core.drawables.PaintProperties, + * com.raytheon.viz.core.gl.images.AbstractGLImage, java.lang.Object) + */ + @Override + public void postImageRender(PaintProperties paintProps, + AbstractGLImage image, Object data) throws VizException { + GL gl = target.getGl(); + // activate on texture2 as 0 is radar image and 1 is colormap + gl.glActiveTexture(GL.GL_TEXTURE2); + gl.glBindTexture(writeToImage.getTextureStorageType(), 0); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension#loadShaderData + * (com.raytheon.viz.core.gl.glsl.GLShaderProgram, + * com.raytheon.uf.viz.core.drawables.IImage, + * com.raytheon.uf.viz.core.drawables.PaintProperties) + */ + @Override + public void loadShaderData(GLShaderProgram program, IImage image, + PaintProperties paintProps) throws VizException { + program.setUniform("radarData", 0); + program.setUniform("mosaicTexture", 2); + + // pass in width and height + program.setUniform("height", (paintProps.getCanvasBounds().height)); + program.setUniform("width", (paintProps.getCanvasBounds().width)); + } + +} diff --git a/cave/com.raytheon.viz.alerts/src/com/raytheon/viz/alerts/observers/ProductAlertObserver.java b/cave/com.raytheon.viz.alerts/src/com/raytheon/viz/alerts/observers/ProductAlertObserver.java index 12ad3ca272..c83bf232d9 100644 --- a/cave/com.raytheon.viz.alerts/src/com/raytheon/viz/alerts/observers/ProductAlertObserver.java +++ b/cave/com.raytheon.viz.alerts/src/com/raytheon/viz/alerts/observers/ProductAlertObserver.java @@ -299,20 +299,16 @@ public class ProductAlertObserver implements INotificationObserver { if ((payLoad instanceof DataURINotificationMessage) || (CAVEMode.getMode().equals(CAVEMode.PRACTICE) && payLoad instanceof PracticeDataURINotificationMessage)) { String[] dataURIs = null; - int[] ids = null; if (payLoad instanceof DataURINotificationMessage) { DataURINotificationMessage uriMsg = (DataURINotificationMessage) payLoad; dataURIs = uriMsg.getDataURIs(); - ids = uriMsg.getIds(); } else { PracticeDataURINotificationMessage uriMsg = (PracticeDataURINotificationMessage) payLoad; dataURIs = uriMsg.getDataURIs(); - ids = uriMsg.getIds(); } for (int i = 0; i < dataURIs.length; ++i) { String str = dataURIs[i]; - Integer id = ids[i]; - processDataURI(str, id); + processDataURI(str); } startWrappers(); @@ -338,12 +334,12 @@ public class ProductAlertObserver implements INotificationObserver { public static void processDerivedAlerts(Collection datauris) { for (String datauri : datauris) { - getInstance().processDataURI(datauri, 0); + getInstance().processDataURI(datauri); } getInstance().startWrappers(); } - private void processDataURI(String datauri, int id) { + private void processDataURI(String datauri) { if (datauri == null) return; try { @@ -363,7 +359,6 @@ public class ProductAlertObserver implements INotificationObserver { } AlertMessage am = new AlertMessage(); - am.id = id; am.dataURI = datauri; am.decodedAlert = Collections.unmodifiableMap(attribs); List obsList = observers.get(NO_FILTER_CONSTANT); diff --git a/cave/com.raytheon.viz.core.gl/META-INF/MANIFEST.MF b/cave/com.raytheon.viz.core.gl/META-INF/MANIFEST.MF index 21c0bf1aee..6629b1d411 100644 --- a/cave/com.raytheon.viz.core.gl/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.viz.core.gl/META-INF/MANIFEST.MF @@ -21,6 +21,7 @@ Require-Bundle: org.eclipse.ui, Bundle-ActivationPolicy: lazy Export-Package: com.raytheon.viz.core.gl, com.raytheon.viz.core.gl.dataformat, + com.raytheon.viz.core.gl.ext, com.raytheon.viz.core.gl.glsl, com.raytheon.viz.core.gl.images Import-Package: com.raytheon.uf.common.status, diff --git a/cave/com.raytheon.viz.core.gl/localization/glsl/colormap.glsl b/cave/com.raytheon.viz.core.gl/localization/glsl/colormap.glsl index 8c5a291b2a..677106250b 100644 --- a/cave/com.raytheon.viz.core.gl/localization/glsl/colormap.glsl +++ b/cave/com.raytheon.viz.core.gl/localization/glsl/colormap.glsl @@ -1,6 +1,9 @@ // Simple shader program for applying alpha,brightness, and contrast to the // colormap in the same way they are applied to data +#include +#include + uniform float brightness; uniform float contrast; uniform float alphaVal; @@ -15,25 +18,15 @@ uniform sampler2D alphaMask; uniform int applyMask; uniform float logFactor; -vec3 AvgLuminance = vec3(0.5, 0.5, 0.5); - -// Given an index(0-1) find the color in the colormap -vec4 findColor(float index){ - if (logFactor > 0.0){ - float minLog = log(logFactor); - float maxLog = log(logFactor + 1.0); - - float lg = log(logFactor + index); - - index = (lg - minLog) / (maxLog - minLog); - if (index < 0.0){ - index = 0.0; - } - else if (index > 1.0){ - index = 1.0; - } +void main(void){ + // Lookup color in colorMap for index + float index = gl_TexCoord[0].s; + if ( logFactor > 0.0 ) { + index = getLogFactorIndex(index, logFactor); } - vec4 color = texture1D(colorMap, index).rgba; + vec4 color = texture1D(colorMap, index).rgba; + + // Apply alpha mask if set float alpha = color.a; if ( applyMask == 1 ) { if ( texture2D(alphaMask , vec2(index,index) ).r != 0.0 ) { @@ -48,18 +41,6 @@ vec4 findColor(float index){ color.b*color.a + bkgrndBlue*(1.0 - color.a), alpha); } - return vec4(color.rgb, alpha); -} -// Apply the preferences for contrast, alpha, and brightness -vec4 applyContrastAlphaBrightness(vec4 color){ - vec3 textureColor3 = vec3(color); - vec3 adjustedColor = mix(AvgLuminance, textureColor3, contrast); - float curAlpha = min(color.a, alphaVal); - return vec4(adjustedColor.r * brightness, adjustedColor.g * brightness, adjustedColor.b * brightness, curAlpha); -} - -void main(void){ - vec4 textureColor = findColor(gl_TexCoord[0].s); - gl_FragColor = applyContrastAlphaBrightness(textureColor); + gl_FragColor = applyContrastAlphaBrightness(color, alphaVal, brightness, contrast); } \ No newline at end of file diff --git a/cave/com.raytheon.viz.core.gl/localization/glsl/colormapRaster.glsl b/cave/com.raytheon.viz.core.gl/localization/glsl/colormapRaster.glsl new file mode 100644 index 0000000000..611851ddf7 --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/localization/glsl/colormapRaster.glsl @@ -0,0 +1,56 @@ +#include +#include + +uniform float alpha; +uniform float brightness; +uniform float contrast; +uniform int applyMask; +uniform float naturalMin; +uniform float naturalMax; +uniform float cmapMin; +uniform float cmapMax; +uniform sampler1D colorMap; +uniform sampler2D alphaMask; +uniform sampler2D rawTex; +uniform float colorMapSz; +uniform int isFloat; +uniform int logarithmic; +uniform int mirror; +uniform float logFactor; + +void main(void) { + vec4 textureColor = texture2D(rawTex, gl_TexCoord[0].st); + float index = 0.0; + float rawValue = textureColor.r; + if ( isFloat == 1 ) { + if ( logarithmic == 1 ) { + index = findFloatIndexLog(rawValue, cmapMin, cmapMax, mirror); + } else { + index = findFloatIndex(rawValue, cmapMin, cmapMax); + } + + // Special float handling, -1.0 is NaN + if (index == -1.0){ + gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); + return; + } + } else { + float naturalValue = ((rawValue * (naturalMax - naturalMin)) + naturalMin); + index = findIndex(naturalValue, cmapMin, cmapMax); + } + + // Lookup color in colorMap for index + if ( logFactor > 0.0 ) { + index = getLogFactorIndex(index, logFactor); + } + textureColor = texture1D(colorMap, index).rgba; + + // Apply alpha mask + if ( applyMask == 1 ) { + if ( texture2D(alphaMask , vec2(index,index) ).r != 0.0 ) { + textureColor = vec4(textureColor.rgb, 0.0); + } + } + + gl_FragColor = applyContrastAlphaBrightness(textureColor, alpha, brightness, contrast); +} \ No newline at end of file diff --git a/cave/com.raytheon.viz.core.gl/localization/glsl/include/colorUtil.glsl b/cave/com.raytheon.viz.core.gl/localization/glsl/include/colorUtil.glsl new file mode 100644 index 0000000000..a448be537d --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/localization/glsl/include/colorUtil.glsl @@ -0,0 +1,34 @@ + +vec3 AvgLuminance = vec3(0.5, 0.5, 0.5); + +/** + * This function applies the specified alpha, brightness, and contrast values + * to the color passed in + */ +vec4 applyContrastAlphaBrightness(vec4 color, float alpha, float brightness, float contrast){ + vec3 textureColor3 = vec3(color); + vec3 adjustedColor = mix(AvgLuminance, textureColor3, contrast); + float curAlpha = min(color.a, alpha); + return vec4(adjustedColor.r * brightness, adjustedColor.g * brightness, adjustedColor.b * brightness, curAlpha); +} + +/** + * This function calculates a new index to use based on the logFactor + */ +float getLogFactorIndex(float index, float logFactor) { + if (logFactor > 0.0){ + float minLog = log(logFactor); + float maxLog = log(logFactor + 1.0); + + float lg = log(logFactor + index); + + index = (lg - minLog) / (maxLog - minLog); + if (index < 0.0){ + index = 0.0; + } + else if (index > 1.0){ + index = 1.0; + } + } + return index; +} \ No newline at end of file diff --git a/cave/com.raytheon.viz.core.gl/localization/glsl/include/indexing.glsl b/cave/com.raytheon.viz.core.gl/localization/glsl/include/indexing.glsl new file mode 100644 index 0000000000..151107d561 --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/localization/glsl/include/indexing.glsl @@ -0,0 +1,104 @@ + +float HALF_FLOAT_NaN = 65504.0; + +/** + * This function takes an index number and caps it to the range 0-1 + */ +float capIndex(float index) { + if ( index < 0.0 ) { + index = 0.0; + } else if ( index > 1.0 ) { + index = 1.0; + } + return index; +} + +/** + * This function linearly finds the index for the rawValue into cmapMin/cmapMax. + * 65504.0 is treated as NaN for half floats and -1 is returned as special case + */ +float findFloatIndex(float rawValue, float cmapMin, float cmapMax) { + if ( rawValue == HALF_FLOAT_NaN ) { + return -1.0; + } + float index = ((rawValue - cmapMin) / abs(cmapMax-cmapMin)); + return capIndex(index); +} + +/** + * This function logarithmically finds the index for the rawValue into cmapMin/cmapMax. + * 65504.0 is treated as NaN for half floats and -1 is returned as special case + */ +float findFloatIndexLog(float rawValue, float cmapMin, float cmapMax, int mirror) { + if ( rawValue == HALF_FLOAT_NaN ) { + return -1.0; + } + + float index = 0.0; + // is this strictly negative, strictly positive or neg to pos scaling? + if ( cmapMin >= 0.0 && cmapMax >= 0.0 && mirror!=1) { + if(rawValue < cmapMin){ + index = 0.0; + }else{ + // simple calculation + index = ((log(rawValue) - log(cmapMin)) / abs(log(cmapMax)-log(cmapMin))); + } + } else if (cmapMin <= 0.0 && cmapMax <= 0.0 && mirror!=1) { + index = ((log(rawValue) - log(cmapMax)) / abs(log(cmapMin)-log(cmapMax))); + } else { + // special case, neg to pos: + float colorMapMin = cmapMin; + float colorMapMax = cmapMax; + float zeroVal = max(colorMapMax, abs(colorMapMin)) * 0.0001; + if (mirror==1 && (colorMapMin > 0.0 || colorMapMax < 0.0)) { + if (colorMapMax < 0.0) { + colorMapMax = -cmapMax; + rawValue = -rawValue; + zeroVal = -colorMapMin; + } else { + zeroVal = cmapMin; + } + colorMapMin = -cmapMax; + } + float leftZero = 0.0; + float rightZero = 0.0; + float absLogZeroVal = abs(log(zeroVal)); + + rightZero = absLogZeroVal + log(colorMapMax); + + float cmapMax2 = abs(colorMapMin); + + leftZero = absLogZeroVal + log(cmapMax2); + + float zeroIndex = leftZero / (leftZero + rightZero); + + // figure out index for texture val + float absTextureColor = abs(rawValue); + if (absTextureColor <= zeroVal) { + index = zeroIndex; + } else if (rawValue > 0.0) { + // positive texture color value, find index from 0 to + // cmapMax: + float logTexColor = absLogZeroVal + log(rawValue); + + float texIndex = logTexColor / rightZero; + index = (zeroIndex + ((1.0 - zeroIndex) * texIndex)); + } else { + // negative texture color value, find index from 0 to + // cmapMax: + float logTexColor = absLogZeroVal + log(absTextureColor); + + float texIndex = logTexColor / leftZero; + index = (zeroIndex - (zeroIndex * texIndex)); + } + } + return capIndex(index); +} + +/** + * Given a raw data value linearly determine the index(0-1) into cmapMin/cmapMax + */ +float findIndex(float rawValue, float cmapMin, float cmapMax) { + float index = ((rawValue - cmapMin) / abs(cmapMax-cmapMin)); + return capIndex(index); +} diff --git a/cave/com.raytheon.viz.core.gl/localization/glsl/raster.glsl b/cave/com.raytheon.viz.core.gl/localization/glsl/raster.glsl index 961d5a4225..a682fb1742 100644 --- a/cave/com.raytheon.viz.core.gl/localization/glsl/raster.glsl +++ b/cave/com.raytheon.viz.core.gl/localization/glsl/raster.glsl @@ -1,172 +1,11 @@ -// NOTE: 65504.0 is the maximum half precision float value -// it is used to do masking of GFE grids since NaNs are not supported -// in NVIDIA cards prior to the 8000 series -// The check for textureColor.r == 65504.0 can be replaced by -// isnan(textureColor.r) if support for cards prior to the 8000 series -// is not required. - -// NOTE: there is a corresponding conversion from NaN to 65504.0 in -// FloatDataPreparer that will also need to be changed +#include uniform float brightness; uniform float contrast; -uniform int doColorMap; -uniform int applyMask; -uniform float naturalMin; -uniform float naturalMax; -uniform float cmapMin; -uniform float cmapMax; -uniform sampler1D colorMap; +uniform float alpha; uniform sampler2D rawTex; -uniform sampler2D alphaMask; -uniform float alphaVal; -uniform float colorMapSz; -uniform int isFloat; -uniform int logarithmic; -uniform int mirror; -uniform float logFactor; -uniform int doSingleColor; -uniform vec3 singleColor; -vec3 AvgLuminance = vec3(0.5, 0.5, 0.5); - -// Given a raw data value determine the index(0-1) into the colormap using log scaling -float findIndexLog(float rawValue){ - float index = 0.0; - // is this strictly negative, strictly positive or neg to pos scaling? - if ( cmapMin >= 0.0 && cmapMax >= 0.0 && mirror!=1) { - if(rawValue < cmapMin){ - index = 0.0; - }else{ - // simple calculation - index = ((log(rawValue) - log(cmapMin)) / abs(log(cmapMax)-log(cmapMin))); - } - } else if (cmapMin <= 0.0 && cmapMax <= 0.0 && mirror!=1) { - index = ((log(rawValue) - log(cmapMax)) / abs(log(cmapMin)-log(cmapMax))); - } else { - // special case, neg to pos: - float colorMapMin = cmapMin; - float colorMapMax = cmapMax; - float zeroVal = max(colorMapMax, abs(colorMapMin)) * 0.0001; - if (mirror==1 && (colorMapMin > 0.0 || colorMapMax < 0.0)) { - if (colorMapMax < 0.0) { - colorMapMax = -cmapMax; - rawValue = -rawValue; - zeroVal = -colorMapMin; - } else { - zeroVal = cmapMin; - } - colorMapMin = -cmapMax; - } - float leftZero = 0.0; - float rightZero = 0.0; - float absLogZeroVal = abs(log(zeroVal)); - - rightZero = absLogZeroVal + log(colorMapMax); - - float cmapMax2 = abs(colorMapMin); - - leftZero = absLogZeroVal + log(cmapMax2); - - float zeroIndex = leftZero / (leftZero + rightZero); - - // figure out index for texture val - float absTextureColor = abs(rawValue); - if (absTextureColor <= zeroVal) { - index = zeroIndex; - } else if (rawValue > 0.0) { - // positive texture color value, find index from 0 to - // cmapMax: - float logTexColor = absLogZeroVal + log(rawValue); - - float texIndex = logTexColor / rightZero; - index = (zeroIndex + ((1.0 - zeroIndex) * texIndex)); - } else { - // negative texture color value, find index from 0 to - // cmapMax: - float logTexColor = absLogZeroVal + log(absTextureColor); - - float texIndex = logTexColor / leftZero; - index = (zeroIndex - (zeroIndex * texIndex)); - } - } - return index; -} - -// Given a raw data value determine the index(0-1) into the colormap -float findIndex(float rawValue) -{ - float index = 0.0; - if (isFloat == 1) { - if (rawValue == 65504.0) { - return -1.0; - } - if (logarithmic == 1){ - index = findIndexLog(rawValue); - }else{ - index = ((rawValue - cmapMin) / abs(cmapMax-cmapMin)); - } - } else { - float naturalValue = ((rawValue * (naturalMax - naturalMin)) + naturalMin); - index = ((naturalValue - cmapMin) / abs(cmapMax-cmapMin)); - } - if(index < 0.0) { - index = 0.0; - } else if(index > 1.0) { - index = 1.0; - } - return index; -} - -// Given an index(0-1) find the color in the colormap -vec4 findColor(float index){ - if (logFactor > 0.0){ - float minLog = log(logFactor); - float maxLog = log(logFactor + 1.0); - - float lg = log(logFactor + index); - - index = (lg - minLog) / (maxLog - minLog); - if (index < 0.0){ - index = 0.0; - } - else if (index > 1.0){ - index = 1.0; - } - } - vec4 color = texture1D(colorMap, index).rgba; - float alpha = color.a; - if ( applyMask == 1 ) { - if ( texture2D(alphaMask , vec2(index,index) ).r != 0.0 ) { - alpha = 0.0; - } - } - return vec4(color.rgb, alpha); -} - -// Apply the preferences for contrast, alpha, and brightness -vec4 applyContrastAlphaBrightness(vec4 color){ - vec3 textureColor3 = vec3(color); - vec3 adjustedColor = mix(AvgLuminance, textureColor3, contrast); - float curAlpha = min(color.a, alphaVal); - return vec4(adjustedColor.r * brightness, adjustedColor.g * brightness, adjustedColor.b * brightness, curAlpha); -} - -void main(void) -{ +void main(void) { vec4 textureColor = texture2D(rawTex, gl_TexCoord[0].st); - float alpha = textureColor.a; - if(doColorMap == 1) { - float index = findIndex(textureColor.r); - if (index == -1.0){ - gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); - return; - } - textureColor = findColor(index); - } - - if ( doSingleColor == 1 ) { - textureColor.rgb = singleColor; - } - gl_FragColor = applyContrastAlphaBrightness(textureColor); + gl_FragColor = applyContrastAlphaBrightness(textureColor, alpha, brightness, contrast); } \ No newline at end of file diff --git a/cave/com.raytheon.viz.core.gl/localization/glsl/singleColor.glsl b/cave/com.raytheon.viz.core.gl/localization/glsl/singleColor.glsl new file mode 100644 index 0000000000..c1b999b79a --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/localization/glsl/singleColor.glsl @@ -0,0 +1,13 @@ +#include + +uniform float brightness; +uniform float contrast; +uniform float alpha; +uniform sampler2D rawTex; +uniform vec3 color; + +void main(void) { + vec4 textureColor = texture2D(rawTex, gl_TexCoord[0].st); + textureColor.rgb = color; + gl_FragColor = applyContrastAlphaBrightness(textureColor, alpha, brightness, contrast); +} \ No newline at end of file diff --git a/cave/com.raytheon.viz.core.gl/localization/glsl_old/clouds.glsl b/cave/com.raytheon.viz.core.gl/localization/glsl_old/clouds.glsl deleted file mode 100644 index 1a6bde0b6f..0000000000 --- a/cave/com.raytheon.viz.core.gl/localization/glsl_old/clouds.glsl +++ /dev/null @@ -1,59 +0,0 @@ -uniform float brightness; -uniform float contrast; -uniform sampler1D colorMap; -uniform int textureType; -uniform sampler2D cloudTexture2D; -uniform sampler3D cloudTexture3D; -uniform float glaze; -uniform float rime; -uniform float alphaVal; -uniform int clwSize; -uniform float clwRange[8]; -uniform float naturalValues[2]; -uniform float cmap[]; - -vec3 AvgLuminance = vec3(0.5, 0.5, 0.5); - -float getValue(sampler2D s2D, sampler3D s3D, float max, float min) { - - float value; - if(textureType == 3) { - value = texture3D(s3D, vec3(gl_TexCoord[0])).r; - }else { - value = texture2D(s2D, vec2(gl_TexCoord[0])).r; - } - - // scale the value - value = (value *(max-min)) + min; - return value; - -} - -void main(void) -{ - gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0 ); - - float temp = getValue(cloudTexture2D, cloudTexture3D, naturalValues[1], naturalValues[0] ); - - float index = ((temp - cmap[0]) / (cmap[1]-cmap[0])); - if(index < 0.0) { - index = 0.0; - } else if(index > 1.0) { - index = 1.0; - } - - vec4 color = texture1D(colorMap, index).rgba; - - float alpha = color.a; - vec4 textureColor = vec4(color.rgb, 1.0); - - vec3 adjustedColor = mix(AvgLuminance, color.rgb, contrast); - float curAlpha = min(alpha, alphaVal); - -//// if(curAlpha > 0.0) { - gl_FragColor = vec4(adjustedColor.r * brightness, adjustedColor.g * brightness, adjustedColor.b * brightness, curAlpha); - // } else { - // discard; - // } - -} diff --git a/cave/com.raytheon.viz.core.gl/localization/glsl_old/drawRaster.glsl b/cave/com.raytheon.viz.core.gl/localization/glsl_old/drawRaster.glsl deleted file mode 100644 index 14a4d8060e..0000000000 --- a/cave/com.raytheon.viz.core.gl/localization/glsl_old/drawRaster.glsl +++ /dev/null @@ -1,37 +0,0 @@ -uniform sampler2D tex; -uniform float brightness; -uniform float contrast; -uniform int doColorMap; -uniform float naturalMin; -uniform float naturalMax; -uniform float cmapMin; -uniform float cmapMax; -uniform sampler1D colorMap; -uniform sampler2D rawTex; -uniform float alphaVal; -uniform float colorMapSz; -vec3 AvgLuminance = vec3(0.5, 0.5, 0.5); - -void main(void) -{ - vec4 textureColor = texture2D(rawTex, gl_TexCoord[0].st); - float alpha = textureColor.a; - if(doColorMap == 1) { - // + " float naturalValue = ((textureColor.r * (20000)) - 10000); - float naturalValue = ((textureColor.r * (naturalMax - naturalMin)) + naturalMin); - float index = ((naturalValue - cmapMin) / abs(cmapMax-cmapMin)); - if(index < 0.0) { - index = 0.0; - } else if(index > 1.0) { - index = 1.0; - } - vec4 color = texture1D(colorMap, index).rgba; - alpha = color.a; - textureColor = vec4(color.rgb, 1.0); - } - vec3 textureColor3 = vec3(textureColor); - vec3 adjustedColor = mix(AvgLuminance, textureColor3, contrast); - float curAlpha = min(alpha, alphaVal); - gl_FragColor = vec4(adjustedColor.r * brightness, adjustedColor.g * brightness, adjustedColor.b * brightness, curAlpha); - -} diff --git a/cave/com.raytheon.viz.core.gl/localization/glsl_old/drawRaster3D.glsl b/cave/com.raytheon.viz.core.gl/localization/glsl_old/drawRaster3D.glsl deleted file mode 100644 index 67d61ef624..0000000000 --- a/cave/com.raytheon.viz.core.gl/localization/glsl_old/drawRaster3D.glsl +++ /dev/null @@ -1,98 +0,0 @@ -uniform sampler3D tex; -uniform float brightness; -uniform float contrast; -uniform int doColorMap; -uniform float naturalMin; -uniform float naturalMax; -uniform float cmapMin; -uniform float cmapMax; -uniform sampler1D colorMap; -uniform sampler3D rawTex; -uniform float alphaVal; -uniform float colorMapSz; -uniform sampler2D grids[8]; -uniform int enabledImpacts[8]; -uniform int numberEnabled; - -//// actuall pressure levels -//uniform float pressures[20]; -//uniform int layers; -// -// -//uniform float texturePres[30]; - -vec3 AvgLuminance = vec3(0.5, 0.5, 0.5); - -//float interp1(float y1, float y3, float x1, float x2, float x3) { -// if(x3 == x1) { -// x1 += 0.01; -// } -// -// return y1+((y3-y1) *((x2-x1)/(x3-x1))); -// -//} -// -//// based on metolib pvalue.f -//float pvalue() { -// -// float z = vec3(gl_TexCoord[0].xyz).z; -// int j = int(z *float(layers-1)); -// vec3 lower = gl_TexCoord[0].xyz; -// vec3 upper = gl_TexCoord[0].xyz; -// -// -// float lowerVal = texture3D(rawTex, lower).r; -// float uperVal = texture3D(rawTex, upper).r; -// -// for(int i = 0; i < layers; ++i) { -// -// if(pressures[i] < texturePres[j]) { -// -// // assuming texture coordinates are 0-1 -// lower.z += 1/(layers-1); -// upper.z -= 1/(layers-1); -// -// float lowerVal = texture3D(rawTex, lower).r; -// float upperVal = texture3D(rawTex, upper).r; -// -// float p1 = log(pressures[i-1]); -// float p2 = log(texturePres[j]); -// float p3 = log(pressures[i]); -// -// return interp1(lowerVal, upperVal, p1, p2, p3 ); -// } -// } -// -//} - - -void main(void) -{ - float textureValue = texture3D(rawTex, gl_TexCoord[0].xyz).r; - - float naturalValue = ((textureValue * (naturalMax - naturalMin)) + naturalMin); - float index = ((naturalValue - cmapMin) / (cmapMax-cmapMin)); - if(index < 0.0) { - index = 0.0; - } else if(index > 1.0) { - index = 1.0; - } - vec4 color = texture1D(colorMap, index).rgba; - float alpha = color.a; - vec4 textureColor = vec4(color.rgb, 1.0); - - - vec3 textureColor3 = vec3(textureColor); - vec3 adjustedColor = mix(AvgLuminance, textureColor3, contrast); -// - float curAlpha = min(alpha, alphaVal); - - if(curAlpha > 0.0){ - gl_FragColor = vec4(adjustedColor.r * brightness, adjustedColor.g * brightness, adjustedColor.b * brightness, curAlpha); - } - else { - discard; - } - - -} diff --git a/cave/com.raytheon.viz.core.gl/localization/glsl_old/heatIndex.glsl b/cave/com.raytheon.viz.core.gl/localization/glsl_old/heatIndex.glsl deleted file mode 100644 index aab680e130..0000000000 --- a/cave/com.raytheon.viz.core.gl/localization/glsl_old/heatIndex.glsl +++ /dev/null @@ -1,56 +0,0 @@ -uniform sampler2D temp2D; -uniform sampler3D temp3D; -uniform sampler2D rh2D; -uniform sampler3D rh3D; -uniform int textureType; -uniform float naturalMin[2]; -uniform float naturalMax[2]; -uniform float severeThreshold; -uniform float moderateThreshold; - -float getValue(sampler2D s2D, sampler3D s3D, float max, float min) { - - float value; - if(textureType == 3) { - value = texture3D(s3D, vec3(gl_TexCoord[0])).r; - }else { - value = texture2D(s2D, vec2(gl_TexCoord[0])).r; - } - - // scale the value - value = (value *(max-min)) + min; - return value; -} - - -void main(void) -{ - - - float kelvin = getValue(temp2D, temp3D, naturalMax[0], naturalMin[0]); - - float t = (((kelvin - 273.15) * 1.8) + 32.0); - - float rh = getValue(rh2D, rh3D, naturalMax[1], naturalMin[1]); - - - float hi = t; - if(t >= 57.0) { - hi = -42.379 + (2.04901523*t) + (10.14333127*rh) - (0.22475541*t*rh) - (0.00683783*t*t) - (0.05481717*rh*rh) + (0.00122874*t*t*rh)+ (0.00085282*t*rh*rh) - (0.00000199*((t*rh)*(t*rh))); - } - - gl_FragColor =vec4(1.0, 0.0, 1.0, 1.0); - // convert threshold values to fahenheit - if(hi > (severeThreshold *9.0/5.0 -459.67)) { - gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); - - } else if(hi > (moderateThreshold *9.0/5.0 -459.67)) { - gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); - } - else { - discard; -// gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); - - } - -} diff --git a/cave/com.raytheon.viz.core.gl/localization/glsl_old/icing.glsl b/cave/com.raytheon.viz.core.gl/localization/glsl_old/icing.glsl deleted file mode 100644 index 1e05d56572..0000000000 --- a/cave/com.raytheon.viz.core.gl/localization/glsl_old/icing.glsl +++ /dev/null @@ -1,125 +0,0 @@ -uniform float brightness; -uniform float contrast; -uniform sampler1D colorMap; -uniform sampler3D tempTex3D; -uniform sampler3D clwTex3D; -uniform sampler2D tempTex2D; -uniform sampler2D clwTex2D; -uniform sampler2D tempTex; -uniform sampler2D clwTex; -uniform float glaze; -uniform float rime; -uniform float alphaVal; -uniform int clwSize; -uniform float clwRange[4]; -uniform float naturalMin[2]; -uniform float naturalMax[2]; -uniform int textureType; -vec3 AvgLuminance = vec3(0.5, 0.5, 0.5); - -// shader based on icing algorithm found at -// http://aoaws.caa.gov.tw/htdocs/projects/aoaws/model/icing/algorithm -// - - -// get the scaled value from either the 2D or 3D texture -float getValue(sampler2D s2D, sampler3D s3D, float max, float min) { - - float value; - if(textureType == 3) { - value = texture3D(s3D, vec3(gl_TexCoord[0])).r; - }else { - value = texture2D(s2D, vec2(gl_TexCoord[0])).r; - } - - // scale the value - value = (value *(max-min)) + min; - return value; -} - - - -float getIcing() -{ - - float value = 0.0; - - float temp = getValue(tempTex2D, tempTex3D, naturalMax[0], naturalMin[0]); - - // clw - cloud liquid water - float clw = getValue(clwTex2D, clwTex3D, naturalMax[1], naturalMin[1]); - - if(temp > glaze || clw < clwRange[0]) { - // no icing - value = 0.0; - } - else { - - if(temp < rime){ - value = 1.0; - } - else { - value = 2.0; - } - - float x = 0.0; - for(int i = 0; i < 4; i++) { - if(clw > clwRange[i] ){ - x += 1.0 ; - - } - } - value += x; - } - - return value; -} - - -void main(void) -{ - gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0 ); - -// vec4 textureColor = texture2D(tempTex, gl_TexCoord[0].st); -// float alpha = textureColor.a; - - float index1 = getIcing(); - -// if(index1 == 900.0 ) { -// gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0 ); -// -// } -// else if(index1 == 10000.0) { -// gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0 ); -// -// } else if(index1 == 999.0) { -// gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0 ); -// -// } -// else { - - float index = (index1 / 5.0); - if(index < 0.0) { - index = 0.0; - } else if(index > 1.0) { - index = 1.0; - } - - vec4 color = texture1D(colorMap, index).rgba; - - float alpha = color.a; - vec4 textureColor = vec4(color.rgb, 1.0); - - vec3 textureColor3 = vec3(textureColor); - - vec3 adjustedColor = mix(AvgLuminance, textureColor3, contrast); - float curAlpha = min(alpha, alphaVal); - - if(alpha > 0.0) { - gl_FragColor = vec4(adjustedColor.r * brightness, adjustedColor.g * brightness, adjustedColor.b * brightness, alpha); - } - else { - discard; - } - -} diff --git a/cave/com.raytheon.viz.core.gl/localization/glsl_old/main.glsl b/cave/com.raytheon.viz.core.gl/localization/glsl_old/main.glsl deleted file mode 100644 index 0d35401419..0000000000 --- a/cave/com.raytheon.viz.core.gl/localization/glsl_old/main.glsl +++ /dev/null @@ -1,157 +0,0 @@ -uniform sampler2D tex; -uniform float brightness; -uniform float contrast; -uniform int doColorMap; -uniform float naturalMin; -uniform float naturalMax; -uniform float cmapMin; -uniform float cmapMax; -uniform sampler1D colorMap; -uniform sampler2D rawTex; -uniform float alphaVal; -uniform float colorMapSz; -uniform int doImpact; -uniform int upperThreshold; -uniform int numberGrids; -uniform float severeThreshold[8]; -uniform float moderateThreshold[8]; -uniform float naturalMins[8]; -uniform float naturalMaxes[8]; -uniform sampler2D grids[8]; -uniform int enabledImpacts[8]; -uniform int numberEnabled; -vec3 AvgLuminance = vec3(0.5, 0.5, 0.5); - -float impactAnd() -{ - float impactVal = 3.0; - for(int x=0; x < 8; x++) - { - if(x >= numberGrids) - { - break; - } - if(enabledImpacts[x] == 1) - { - vec4 textureColor = texture2D(grids[x], gl_TexCoord[0].st); - float naturalValue = ((textureColor.r * (naturalMaxes[x] - naturalMins[x])) + naturalMins[x]); - if(upperThreshold == 1) - { - if(naturalValue < moderateThreshold[x]) - { - impactVal = 0.0; - } - else if(naturalValue < severeThreshold[x]) - { - if(impactVal == 3.0) - { - impactVal = 2.0; - } - } - } - else - { - if(naturalValue > moderateThreshold[x]) - { - impactVal = 0.0; - } - else if(naturalValue > severeThreshold[x]) - { - if(impactVal == 3.0) - { - impactVal = 2.0; - } - } - } - } - } - - return impactVal; -} - -float impactOr() -{ - float impactVal = 0.0; - for(int x=0; x < 8; x++) - { - if(x >= numberGrids) - { - break; - } - if(enabledImpacts[x] == 1) - { - vec4 textureColor = texture2D(grids[x], gl_TexCoord[0].st); - float naturalValue = ((textureColor.r * (naturalMaxes[x] - naturalMins[x])) + naturalMins[x]); - if(upperThreshold == 1) - { - if(naturalValue > severeThreshold[x]) - { - impactVal = 3.0; - } - else if(naturalValue > moderateThreshold[x]) - { - impactVal = 2.0; - } - } - else - { - if(naturalValue < severeThreshold[x]) - { - impactVal = 3.0; - } - else if(naturalValue < moderateThreshold[x]) - { - impactVal = 2.0; - } - } - } - } - - return impactVal; -} - - -void main(void) -{ - vec4 textureColor = texture2D(rawTex, gl_TexCoord[0].st); - float alpha = textureColor.a; - if(doImpact == 1) - { - float impactVal = 0.0; - if(numberEnabled > 0) - { - impactVal = impactAnd(); - } - else - { - impactVal = 0.0; - } - - float index = (impactVal / 3.0); - if(index < 0.0) { - index = 0.0; - } else if(index > 1.0) { - index = 1.0; - } - vec4 color = texture1D(colorMap, index).rgba; - alpha = color.a; - textureColor = vec4(color.rgb, 1.0); - } - else if(doColorMap == 1) { - float naturalValue = ((textureColor.r * (naturalMax - naturalMin)) + naturalMin); - float index = ((naturalValue - cmapMin) / (cmapMax-cmapMin)); - if(index < 0.0) { - index = 0.0; - } else if(index > 1.0) { - index = 1.0; - } - vec4 color = texture1D(colorMap, index).rgba; - alpha = color.a; - textureColor = vec4(color.rgb, 1.0); - } - vec3 textureColor3 = vec3(textureColor); - vec3 adjustedColor = mix(AvgLuminance, textureColor3, contrast); - float curAlpha = min(alpha, alphaVal); - gl_FragColor = vec4(adjustedColor.r * brightness, adjustedColor.g * brightness, adjustedColor.b * brightness, curAlpha); - -} diff --git a/cave/com.raytheon.viz.core.gl/localization/glsl_old/terrain.glsl b/cave/com.raytheon.viz.core.gl/localization/glsl_old/terrain.glsl deleted file mode 100644 index d18b4dc4c4..0000000000 --- a/cave/com.raytheon.viz.core.gl/localization/glsl_old/terrain.glsl +++ /dev/null @@ -1,19 +0,0 @@ -uniform sampler2D terrainMap; -uniform float exaggeration; -uniform int layer; - -void main(void) -{ - vec4 newVertexPos; - float df; - - gl_TexCoord[0].xy = gl_MultiTexCoord0.xy; - vec3 normal = normalize(gl_Normal); - df = texture2D( terrainMap, gl_TexCoord[0].xy ).r; - if(layer > 0){ - exaggeration *= layer; - } - newVertexPos = vec4(normal *df* exaggeration , 0.0) + gl_Vertex; - - gl_Position = gl_ModelViewProjectionMatrix * newVertexPos; -} \ No newline at end of file diff --git a/cave/com.raytheon.viz.core.gl/plugin.xml b/cave/com.raytheon.viz.core.gl/plugin.xml index c79f6296dd..fd854f43c2 100644 --- a/cave/com.raytheon.viz.core.gl/plugin.xml +++ b/cave/com.raytheon.viz.core.gl/plugin.xml @@ -20,13 +20,8 @@ --> - - - - - @@ -44,7 +39,7 @@ class="com.raytheon.viz.core.gl.internal.ext.GLColormapShadedShapeExtension"> + class="com.raytheon.viz.core.gl.ext.GLOffscreenRenderingExtension"> @@ -52,5 +47,11 @@ + + + + diff --git a/cave/com.raytheon.viz.core.gl/schema/shader.exsd b/cave/com.raytheon.viz.core.gl/schema/shader.exsd deleted file mode 100644 index ec795ae0f1..0000000000 --- a/cave/com.raytheon.viz.core.gl/schema/shader.exsd +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - This extension point is used to identify shader programs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0.1 - - - - - - - - diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/AbstractGLMesh.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/AbstractGLMesh.java index e250f57b1a..7ef7c820eb 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/AbstractGLMesh.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/AbstractGLMesh.java @@ -106,12 +106,11 @@ public abstract class AbstractGLMesh implements IMesh { } if (!compiled) { - vertexCoords.setTarget(glTarget); - vertexCoords.compile(); + vertexCoords.compile(glTarget.getGl()); compiled = true; } - GLGeometryPainter.paintGeometries(glTarget, vertexCoords, + GLGeometryPainter.paintGeometries(glTarget.getGl(), vertexCoords, sharedTextureCoords.getTextureCoords()); } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/Activator.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/Activator.java index 0a21f5e45f..a792741e48 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/Activator.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/Activator.java @@ -19,7 +19,6 @@ **/ package com.raytheon.viz.core.gl; -import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.preference.IPersistentPreferenceStore; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -62,12 +61,6 @@ public class Activator extends AbstractUIPlugin { */ public void start(BundleContext context) throws Exception { super.start(context); - // Start the texture loader job - TextureLoaderJob textureLoader = TextureLoaderJob.getInstance(); - if (textureLoader.getState() != Job.RUNNING) { - textureLoader.setSystem(true); - textureLoader.schedule(); - } } /* @@ -81,10 +74,7 @@ public class Activator extends AbstractUIPlugin { plugin = null; super.stop(context); // Start the texture loader job - TextureLoaderJob textureLoader = TextureLoaderJob.getInstance(); - if (textureLoader.getState() == Job.RUNNING) { - textureLoader.shutdown(); - } + TextureLoader.getInstance().shutdown(); } /** diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLContextBridge.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLContextBridge.java new file mode 100644 index 0000000000..21edf4d966 --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLContextBridge.java @@ -0,0 +1,203 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.core.gl; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLPbuffer; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.opengl.GLCanvas; +import org.eclipse.swt.opengl.GLData; +import org.eclipse.swt.widgets.Shell; + +import com.raytheon.uf.viz.core.exception.VizException; + +/** + * + * Provide a mechanism for keeping JOGL GLContext in sync with the SWT GLCanvas + * context. The JOGL GLContext has most of the logic needed to manage contexts, + * except for when the context is external. Since our context is created by the + * SWT GLCanvas the JOGL GLContext does not actually control the active context + * in GL. This class contains a GLCanvas and a GLContext and keeps the active + * context in sync between the two. + * + * This class also provides static access to the "Master Context" which is a + * context with which all other contexts are sharing data. Ideally we would not + * need to use the master context however there is a bug in some Windows/Intel + * drivers which causes crashes if a texture is created on a context, then the + * context is deleted, then the texture is deleted on a different context. To + * resolve this all textures should be created and deleted on the master + * context. This is done by calling makeMasterContextCurrent before calling + * glGenTexture or glDeleteTexture and then calling releaseMasterContext + * immediately after to restore the previous context. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 17, 2012            bsteffen     Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class GLContextBridge { + + private static GLContextBridge activeContext; + + private static GLContextBridge masterContext; + + private static GLContextBridge previousContext; + + private final GLCanvas canvas; + + private final GLContext context; + + public GLContextBridge(int width, int height) throws VizException { + GLCapabilities glCap = new GLCapabilities(); + if (!GLDrawableFactory.getFactory().canCreateGLPbuffer()) { + throw new VizException( + "Graphics card does not support GLPbuffer and " + + "therefore does not support offscreen rendering."); + } + GLPbuffer buf = GLDrawableFactory.getFactory().createGLPbuffer(glCap, + null, width, height, null); + this.context = buf.createContext(null); + this.canvas = null; + activeContext = this; + releaseContext(); + } + + public GLContextBridge(GLCanvas canvas) { + this.canvas = canvas; + this.canvas.setCurrent(); + this.context = GLDrawableFactory.getFactory().createExternalGLContext(); + activeContext = this; + releaseContext(); + } + + /** + * Make this context current for any GL Operations and release any + * previously active context. + * + * @return true if this context was not previously active and should + * therefore be released when you are done performing gl operations + */ + public boolean makeContextCurrent() { + if (canvas != null && !canvas.isDisposed()) { + canvas.setCurrent(); + } else if (canvas != null) { + throw new RuntimeException( + "Cannot make gl context current, GLCanvas is disposed"); + } + GLContext oldContext = GLContext.getCurrent(); + if (context != oldContext) { + if (oldContext != null) { + oldContext.release(); + } + if (context.makeCurrent() == GLContext.CONTEXT_NOT_CURRENT) { + throw new RuntimeException( + "Cannot make gl context current, Unknown error occured."); + } + } + boolean retVal = (activeContext != this); + activeContext = this; + return retVal; + } + + public void releaseContext() { + if (context == GLContext.getCurrent()) { + context.release(); + } + if (activeContext == this) { + activeContext = null; + } + } + + public void destroyContext() { + releaseContext(); + context.destroy(); + } + + /** + * get the GLData to use when creating a new GLCanvas, data.shareContext + * will contain the canvas for the "Master Context" + * + * @return + */ + public static GLData getGLData() { + return getGLData(true); + } + + private static GLData getGLData(boolean setContext) { + GLData data = new GLData(); + data.stencilSize = 1; + data.depthSize = 1; + data.doubleBuffer = true; + if (setContext) { + data.shareContext = getMasterContext().canvas; + } + return data; + } + + private static GLContextBridge getMasterContext() { + if (masterContext == null) { + GLCanvas canvas = new GLCanvas(new Shell(), SWT.NONE, + getGLData(false)); + masterContext = new GLContextBridge(canvas); + } + return masterContext; + } + + /** + * This method makes the shared master context the active contexts, it also + * stores the current active context to be restored on release. + * + */ + public static void makeMasterContextCurrent() { + if (masterContext != null) { + if (activeContext != null) { + previousContext = activeContext; + activeContext.releaseContext(); + } + masterContext.makeContextCurrent(); + } + } + + /** + * Releases the master context and restores the context that was active + * before makeMasterContextCurrent was called. + */ + public static void releaseMasterContext() { + if (masterContext != null) { + masterContext.releaseContext(); + if (previousContext != null) { + previousContext.makeContextCurrent(); + previousContext = null; + } + } + } + +} diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLDisposalManager.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLDisposalManager.java new file mode 100644 index 0000000000..aefaaceff8 --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLDisposalManager.java @@ -0,0 +1,127 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.core.gl; + +import java.lang.ref.ReferenceQueue; +import java.lang.ref.WeakReference; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.concurrent.LinkedBlockingQueue; + +import javax.media.opengl.GL; + +/** + * + * This class provides a convenient way of disposing of GL resources on an + * active GLContext. + * + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 17, 2012            bsteffen     Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class GLDisposalManager { + + private static ReferenceQueue refQueue = new ReferenceQueue(); + + private static List autoDisposers = new LinkedList(); + + private static Queue disposeQueue = new LinkedBlockingQueue(); + + /** + * This method should be used to dispose of a GL resource, at the end of a + * frame the target will make the context current and dispose of all + * resources. + * + * @param disposer + * a disposer object that is ready to dispose of a gl resource. + */ + private static void dispose(GLDisposer disposer) { + disposeQueue.add(disposer); + } + + /** + * Provide a backup mechanism to dispose. This uses WeakReference objects to + * call the disposer after the object is garbage collected. For this to work + * the disposer must have no references to object. Object should be the only + * thing using these GL resources, this will not work for anything which + * might be shared by multiple objects. This will also result in the dispose + * method of the disposer being called more than once so it should clear any + * + * @param disposer + * - a disposer that will be called when object is garbage + * collected + * @param object + * - an object which uses a gl resource. + */ + public static void autoDispose(GLDisposer disposer, Object object) { + autoDisposers.add(new GLAutoDisposer(object, disposer)); + } + + /** + * For use by the target only, the target should call this to dispose all + * unneeded resources + * + * @param gl + */ + public static void performDispose(GL gl) { + GLDisposer disposer = disposeQueue.poll(); + while (disposer != null) { + disposer.dispose(gl); + disposer = disposeQueue.poll(); + } + GLAutoDisposer autoDisposer = (GLAutoDisposer) refQueue.poll(); + while (autoDisposer != null) { + autoDisposers.remove(autoDisposer); + autoDisposer.disposer.dispose(); + autoDisposer = (GLAutoDisposer) refQueue.poll(); + } + } + + public static abstract class GLDisposer { + protected abstract void dispose(GL gl); + + final public void dispose() { + GLDisposalManager.dispose(this); + } + } + + private static class GLAutoDisposer extends WeakReference { + + private final GLDisposer disposer; + + public GLAutoDisposer(Object referent, GLDisposer disposer) { + super(referent, refQueue); + this.disposer = disposer; + } + + } + +} diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLFactoryAdapter.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLFactoryAdapter.java index 533a2eb94d..8886c02d86 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLFactoryAdapter.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLFactoryAdapter.java @@ -26,7 +26,6 @@ import org.eclipse.swt.opengl.GLCanvas; import org.eclipse.swt.opengl.GLData; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Shell; import org.opengis.coverage.grid.GridEnvelope; import com.raytheon.uf.viz.core.AbstractGraphicsFactoryAdapter; @@ -145,37 +144,11 @@ public class GLFactoryAdapter extends AbstractGraphicsFactoryAdapter { @Override public Canvas constrcutCanvas(Composite canvasComp) throws VizException { GLCanvas canvas; - GLData data = new GLData(); - data.stencilSize = 1; - data.depthSize = 1; - data.doubleBuffer = true; - GLCanvas cachedCanvas = GLCanvasCache.getInstance().getCanvas(); - if (cachedCanvas == null) { - Shell invisibleShell = new Shell(); - cachedCanvas = new GLCanvas(invisibleShell, SWT.NONE, data); - GLCanvasCache.getInstance().setCanvas(cachedCanvas); - cachedCanvas.setCurrent(); - } - - data.shareContext = cachedCanvas; + GLData data = GLContextBridge.getGLData(); canvas = new GLCanvas(canvasComp, SWT.NONE, data); canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); return canvas; } - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.AbstractGraphicsFactoryAdapter#disposeCanvas - * (org.eclipse.swt.widgets.Canvas) - */ - @Override - public void disposeCanvas(Canvas canvas) { - GLCanvas cachedCanvas = GLCanvasCache.getInstance().getCanvas(); - if (cachedCanvas != canvas && !canvas.isDisposed()) { - canvas.getParent().dispose(); - } - } } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLGeometryObject2D.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLGeometryObject2D.java index 33d0ad5235..2ae8676f91 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLGeometryObject2D.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLGeometryObject2D.java @@ -29,8 +29,8 @@ import java.util.List; import javax.media.opengl.GL; import com.raytheon.uf.viz.core.IExtent; -import com.raytheon.uf.viz.core.VizApp; import com.raytheon.uf.viz.core.exception.VizException; +import com.raytheon.viz.core.gl.objects.GLVertexBufferObject; /** * GL Geometry object, supports compiling into VBOs. Coordinates passed in will @@ -53,9 +53,6 @@ import com.raytheon.uf.viz.core.exception.VizException; public class GLGeometryObject2D { public static class GLGeometryObjectData { - private IGLTarget target; - - private GL gl; public IExtent worldExtent; @@ -72,12 +69,6 @@ public class GLGeometryObject2D { this.coordType = coordType; } - public void setTarget(IGLTarget target) { - this.target = target; - if (target != null) { - gl = target.getGl(); - } - } } protected static enum State { @@ -96,7 +87,7 @@ public class GLGeometryObject2D { protected int points; - protected int vboId; + protected GLVertexBufferObject vbo; protected State state; @@ -104,8 +95,6 @@ public class GLGeometryObject2D { public GLGeometryObject2D(GLGeometryObjectData data) { this.data = new GLGeometryObjectData(data.geometryType, data.coordType); - this.data.gl = data.gl; - this.data.target = data.target; this.data.manageIndicies = data.manageIndicies; this.data.mutable = data.mutable; this.data.worldExtent = data.worldExtent; @@ -119,16 +108,16 @@ public class GLGeometryObject2D { } compiledIndicies = null; points = 0; - vboId = -1; + vbo = null; state = State.MUTABLE; } - public void compile() throws VizException { + public void compile(GL gl) throws VizException { // We will use glMultiDrawArrays if the cardSupportsHighEndFeatures, so // we will keep track of a lenghts buffer state = State.COMPILED; int add = 1; - if (GLCapabilities.getInstance(data.gl).cardSupportsHighEndFeatures) { + if (GLCapabilities.getInstance(gl).cardSupportsHighEndFeatures) { state = State.COMPILED_HIGH_END; add = 0; } @@ -169,24 +158,21 @@ public class GLGeometryObject2D { copy.put(data.get()); } - GL gl = this.data.gl; - // clear the error bit. - this.data.target.makeContextCurrent(); gl.glGetError(); // generate vbo - vboId = GLVBOCleaner.allocateVBO(this, this.data.target); + vbo = new GLVertexBufferObject(this); // verify successful - if (vboId <= 0) { - vboId = -1; + if (!vbo.isValid()) { + vbo = null; throw new VizException("Error compiling wireframe shape, " + "could not generate vertex buffer object"); } // bind and load - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboId); + vbo.bind(gl, GL.GL_ARRAY_BUFFER); gl.glBufferData(GL.GL_ARRAY_BUFFER, copy.capacity() * 4, copy.rewind(), GL.GL_STATIC_DRAW); gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); @@ -223,16 +209,8 @@ public class GLGeometryObject2D { compiledLengths = null; state = State.INVALID; - if (vboId > -1) { - final int vbo = vboId; - vboId = -1; - VizApp.runAsync(new Runnable() { - @Override - public void run() { - GLVBOCleaner.unallocateVBO(GLGeometryObject2D.this, vbo, - data.target); - } - }); + if (vbo != null && vbo.isValid()) { + vbo.dispose(); } } @@ -368,15 +346,8 @@ public class GLGeometryObject2D { } } - public synchronized void paint() throws VizException { - GLGeometryPainter.paintGeometries(data.target, this); - } - - public void setTarget(IGLTarget target) { - data.target = target; - if (data.target != null) { - data.gl = target.getGl(); - } + public synchronized void paint(GL gl) throws VizException { + GLGeometryPainter.paintGeometries(gl, this); } // 2D specific functions, override for 3D support diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLGeometryPainter.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLGeometryPainter.java index 280afafdcb..8f125409d1 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLGeometryPainter.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLGeometryPainter.java @@ -48,11 +48,8 @@ import com.raytheon.viz.core.gl.GLGeometryObject2D.State; public class GLGeometryPainter { - private static int maxVertices = -1; - - public static void paintGeometries(IGLTarget target, - GLGeometryObject2D... geoms) throws VizException { - GL gl = target.getGl(); + public static void paintGeometries(GL gl, GLGeometryObject2D... geoms) + throws VizException { State state = State.INVALID; Set states = new HashSet(); for (GLGeometryObject2D geom : geoms) { @@ -131,11 +128,11 @@ public class GLGeometryPainter { case COMPILED: case COMPILED_HIGH_END: { for (GLGeometryObject2D geom : geoms) { - if (geom.vboId <= 0) { + if (!geom.vbo.isValid()) { throw new VizException( "Could not paint geometry, VBO not set!"); } - gl.glBindBuffer(GL.GL_ARRAY_BUFFER, geom.vboId); + geom.vbo.bind(gl, GL.GL_ARRAY_BUFFER); switch (geom.data.coordType) { case GL.GL_VERTEX_ARRAY: { gl.glVertexPointer(geom.pointsPerCoordinate(), GL.GL_FLOAT, @@ -199,7 +196,7 @@ public class GLGeometryPainter { */ private static void drawArrays(GL gl, int mode, int first, int count) throws VizException { - if (first > -1 && count > 0 && (first + count < getMaxVertices(gl))) { + if (first > -1 && count > 0) { gl.glDrawArrays(mode, first, count); } else { throw new VizException( @@ -220,12 +217,4 @@ public class GLGeometryPainter { } } - private static int getMaxVertices(GL gl) { - if (maxVertices < 0) { - IntBuffer ib = IntBuffer.allocate(1); - gl.glGetIntegerv(GL.GL_MAX_ELEMENTS_VERTICES, ib); - maxVertices = ib.get(0); - } - return maxVertices; - } } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLVBOCleaner.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLVBOCleaner.java deleted file mode 100644 index 7bc0fd186c..0000000000 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLVBOCleaner.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ -package com.raytheon.viz.core.gl; - -import java.lang.ref.ReferenceQueue; -import java.lang.ref.WeakReference; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import javax.media.opengl.GL; - -/** - * - * This class uses WeakReference to guarantee that all vbos are deallocated even - * if dispose is never called. It is still better to call dispose to avoid - * having "dead" vbos on the graphics card, which can slow down rendering. - * - *
- * 
- * SOFTWARE HISTORY
- * 
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * Jun 9, 2011            bsteffen     Initial creation
- * 
- * 
- * - * @author bsteffen - * @version 1.0 - */ -public class GLVBOCleaner extends WeakReference { - - /** - * This is needed so when unallocate is called we can set the vboId to -1 - * and stop it from being redeleted - */ - private static List cleaners = new LinkedList(); - - /** - * THis queue will contain all garbage collected vbo objects, if everyone - * deallocates all vboIds will be -1. - */ - private static ReferenceQueue queue = new ReferenceQueue(); - - /** - * get a new vboId from gl which will be linked to object, if object is - * garbage collected then the vbo will still be freed. This should only be - * called on the main thread. - * - * @param object - * @param target - * @return - */ - public static int allocateVBO(Object object, IGLTarget target) { - target.makeContextCurrent(); - clean(target.getGl()); - GLVBOCleaner cleaner = new GLVBOCleaner(object, target.getGl()); - - target.handleError(target.getGl().glGetError()); - - // verify successful - if (cleaner.vboId > 0) { - cleaners.add(cleaner); - } - return cleaner.vboId; - } - - /** - * Immediately free a vbo which has been allocated, any method that uses - * allocate should also use deallocate. object must be the same as the - * object passed to allocate. - * - * @param object - * @param vboId - * @param target - */ - public static void unallocateVBO(Object object, int vboId, IGLTarget target) { - target.makeContextCurrent(); - clean(target.getGl()); - if (vboId <= 0) { - return; - } - Iterator iter = cleaners.iterator(); - while (iter.hasNext()) { - GLVBOCleaner cleaner = iter.next(); - if (cleaner.get() == object && cleaner.vboId == vboId) { - cleaner.freeVbo(target.getGl()); - iter.remove(); - } - } - } - - private static void clean(GL gl) { - GLVBOCleaner cleaner = (GLVBOCleaner) queue.poll(); - while (cleaner != null) { - if (cleaner.vboId > 0) { - System.err - .println("An object with a gl vertex buffer object has been garbage collected without being disposed. This can cause a delay in freeing vbos which can cause severe performance problems."); - cleaner.freeVbo(gl); - } - cleaners.remove(cleaner); - cleaner = (GLVBOCleaner) queue.poll(); - } - } - - private int vboId; - - private GLVBOCleaner(Object referent, GL gl) { - super(referent, queue); - int[] vbos = new int[1]; - gl.glGenBuffers(1, vbos, 0); - this.vboId = vbos[0]; - } - - private void freeVbo(GL gl) { - gl.glDeleteBuffers(1, new int[] { this.vboId }, 0); - this.vboId = -1; - } - -} diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/IGLFont.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/IGLFont.java index 1b445ed87b..e3e05e8ab5 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/IGLFont.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/IGLFont.java @@ -20,7 +20,6 @@ package com.raytheon.viz.core.gl; import com.raytheon.uf.viz.core.drawables.IFont; -import com.raytheon.viz.core.gl.internal.GLTarget; import com.sun.opengl.util.j2d.TextRenderer; /** @@ -49,13 +48,6 @@ public interface IGLFont extends IFont { */ public TextRenderer getTextRenderer(); - /** - * Get the target for the font - * - * @return - */ - public GLTarget getTarget(); - /** * Force a dispose */ diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/IGLTarget.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/IGLTarget.java index 99e05b48fe..a2d2dea427 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/IGLTarget.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/IGLTarget.java @@ -20,19 +20,13 @@ package com.raytheon.viz.core.gl; import javax.media.opengl.GL; -import javax.media.opengl.GLContext; import javax.media.opengl.glu.GLU; import org.eclipse.swt.graphics.Rectangle; -import com.raytheon.uf.viz.core.DrawableImage; import com.raytheon.uf.viz.core.IGraphicsTarget; -import com.raytheon.uf.viz.core.PixelCoverage; -import com.raytheon.uf.viz.core.drawables.IImage; -import com.raytheon.uf.viz.core.drawables.IRenderableDisplay; -import com.raytheon.uf.viz.core.drawables.PaintProperties; -import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.viz.core.gl.images.GLColormappedImage; +import com.raytheon.uf.viz.core.drawables.ColorMapParameters; +import com.raytheon.viz.core.gl.objects.GLTextureObject; public interface IGLTarget extends IGraphicsTarget { @@ -40,13 +34,9 @@ public interface IGLTarget extends IGraphicsTarget { public abstract GLU getGlu(); - /** - * Active texture unit and bind a texture - * - * @param textureUnit - * @param GLImage - */ - public abstract void bindTexture(int textureUnit, GLColormappedImage image); + public abstract void pushGLState(); + + public abstract void popGLState(); /** * @@ -54,6 +44,12 @@ public interface IGLTarget extends IGraphicsTarget { */ public abstract boolean makeContextCurrent(); + /** + * + * @return + */ + public abstract void releaseContext(); + /** * Get the modle view matrix settings * @@ -102,88 +98,17 @@ public interface IGLTarget extends IGraphicsTarget { public abstract Rectangle getBounds(); /** - * Get the gl context + * Get a colormap texture id for the specified parameters * + * @param cmapParams * @return */ - public abstract GLContext getContext(); - - /** - * Dispose luminance texture - * - * @param id - * @param pboID - */ - public abstract void disposeLuminanceTexture(int id, int pboID); - - /** - * Dispose a vbo - * - * @param id - * the vbo id - */ - public abstract void disposeVBO(int id); - - /** - * Dispose the occlusion query - * - * @param id - */ - public abstract void disposeOcclusionQueries(int[] id); - - /** - * - * @param display - * @throws VizException - */ - public void beginOcclusionTest(IRenderableDisplay display) - throws VizException; - - /** - * End the occlusion test. Commands will update the framebuffer - * - * @throws VizException - */ - public void endOcclusionTest() throws VizException; - - /** - * call drawRaster using a specified shader program - * - * @param image - * @param extent - * @param paintProps - * @param shaderProgram - * @return - * @throws VizException - */ - public abstract boolean drawRaster(IImage image, PixelCoverage extent, - PaintProperties paintProps, String shaderProgram) - throws VizException; - - /** - * call drawRaster with a specified shader program - * - * @param image - * the image reference object to draw - * @param extent - * the extent of the drawable area - * @param paintProps - * the paint properties - * @param mode - * the drawing mode (synchronous, asynchronous) - * @return status whether the raster was able to be drawn - * @throws VizException - */ - public abstract boolean drawRaster(IImage image, PixelCoverage extent, - PaintProperties paintProps, RasterMode mode, String shaderProgram) - throws VizException; - - public abstract boolean drawRasters(String shader, - PaintProperties paintProps, DrawableImage... images) - throws VizException; + public abstract GLTextureObject getColorMapTexture( + ColorMapParameters cmapParams); /** * Checks the glError state and does a UFStatus message */ public abstract void handleError(int errorid); + } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/SharedCoordMap.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/SharedCoordMap.java index dd726c215a..68d79d72f1 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/SharedCoordMap.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/SharedCoordMap.java @@ -98,9 +98,8 @@ public class SharedCoordMap { GL.GL_TRIANGLE_STRIP, GL.GL_TEXTURE_COORD_ARRAY); data.manageIndicies = false; textureCoords = new GLGeometryObject2D(data); - textureCoords.setTarget(glTarget); populateTextureGeom(key, textureCoords); - textureCoords.compile(); + textureCoords.compile(glTarget.getGl()); } private void incRef() { @@ -154,14 +153,13 @@ public class SharedCoordMap { */ private static void populateTextureGeom(SharedCoordinateKey key, GLGeometryObject2D geom) { - geom.allocate(key.verticalDivisions * key.horizontalDivisions * 2); - - int height = 2 * key.verticalDivisions; + int height = 2 * (key.verticalDivisions + 1); int width = key.horizontalDivisions; + geom.allocate(width * height * 2); // get dx and dy for texture points float dX = (1.0f / (key.horizontalDivisions)); - float dY = (1.0f / (key.verticalDivisions - 1)); + float dY = (1.0f / (key.verticalDivisions)); float xLow, xHigh = 0; diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/TextureLoader.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/TextureLoader.java new file mode 100644 index 0000000000..5972874986 --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/TextureLoader.java @@ -0,0 +1,121 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ + +package com.raytheon.viz.core.gl; + +import java.util.ArrayList; +import java.util.List; + +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; +import com.raytheon.uf.viz.core.drawables.IImage.Status; +import com.raytheon.uf.viz.core.jobs.JobPool; +import com.raytheon.viz.core.gl.images.AbstractGLImage; + +/** + * Class that loads data for AbstractGLImages asynchronously + * + *
+ * 
+ *    SOFTWARE HISTORY
+ *   
+ *    Date          Ticket#     Engineer    Description
+ *    ------------	----------	-----------	--------------------------
+ *    7/1/06                    chammack    Initial Creation.
+ * 
+ * 
+ * + * @author chammack + * + */ +public class TextureLoader { + + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(TextureLoader.class); + + /** The instance */ + private static TextureLoader instance; + + private JobPool loaderPool; + + private List texturesToLoad; + + /** + * Get the currently running instance of the texture loader + * + * @return + */ + public static synchronized TextureLoader getInstance() { + if (instance == null) { + instance = new TextureLoader(); + } + return instance; + } + + /** + * Use getInstance() instead of constructor + * + */ + private TextureLoader() { + this.texturesToLoad = new ArrayList(); + this.loaderPool = new JobPool("Texture Loader", Runtime.getRuntime() + .availableProcessors(), true); + } + + /** + * Request an image to be loaded + * + * @param img + * the image + */ + public void requestLoad(final AbstractGLImage img) { + if (!texturesToLoad.contains(img)) { + texturesToLoad.add(img); + loaderPool.schedule(new Runnable() { + @Override + public void run() { + try { + try { + img.stage(); + } catch (Throwable t) { + img.setStatus(Status.FAILED); + statusHandler.handle( + Priority.PROBLEM, + "Error staging texture: " + + t.getLocalizedMessage(), t); + } + } finally { + texturesToLoad.remove(img); + } + } + }); + } + } + + /** + * Request the job to be shut down + * + */ + public void shutdown() { + loaderPool.cancel(); + } + +} diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/TextureLoaderJob.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/TextureLoaderJob.java deleted file mode 100644 index 8a40d526a4..0000000000 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/TextureLoaderJob.java +++ /dev/null @@ -1,210 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ - -package com.raytheon.viz.core.gl; - -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.LinkedBlockingQueue; - -import javax.media.opengl.GLContext; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; - -import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.viz.core.gl.images.AbstractGLImage; - -/** - * Job that demand-loads textures into GL. - *

- * - * If a multiple ImageIO.reads are incurred simultaneously, the performance is - * horrible. By having only one texture load occur at a time in a different - * (non-blocking) thread, with adequate pause between texture loads, this - * problem is alleviated. - * - *

- * 
- *    SOFTWARE HISTORY
- *   
- *    Date          Ticket#     Engineer    Description
- *    ------------	----------	-----------	--------------------------
- *    7/1/06                    chammack    Initial Creation.
- * 
- * 
- * - * @author chammack - * - */ -public class TextureLoaderJob extends Job { - - /** Number of things to keep on the queue before starting to remove some */ - private static final int MAX_QUEUE_SIZE = 256; - - /** The instance */ - private static TextureLoaderJob instance; - - /** Time (in ms) for the texture job to sleep (NEVER SET TO ZERO) */ - private static final int TEXTURE_JOB_SLEEP_TIME = 2; - - /** A flag to indicate whether the job should continue running */ - private boolean isRunning = true; - - /** A queue of images to load */ - private final Queue texturesToLoad; - - /** A thread safe list of images to load */ - private final ConcurrentLinkedQueue texturesToLoadToGPU; - - /** - * Internal datastructure: used to populate the queues - */ - private class Request { - public AbstractGLImage image; - - public GLContext ctx; - } - - /** - * Get the currently running instance of the texture loader - * - * @return - */ - public static TextureLoaderJob getInstance() { - if (instance == null) { - instance = new TextureLoaderJob(); - } - return instance; - } - - /** - * Use getInstance() instead of constructor - * - */ - private TextureLoaderJob() { - super("Texture Loader"); - this.texturesToLoad = new LinkedBlockingQueue(); - this.texturesToLoadToGPU = new ConcurrentLinkedQueue(); - } - - /** - * Request an image to be loaded - * - * @param img - * the image - */ - public void requestLoad(AbstractGLImage img) { - if (!this.texturesToLoad.contains(img)) - this.texturesToLoad.add(img); - } - - public void requestLoadIntoTexture(AbstractGLImage img, GLContext ctx) { - Request req = new Request(); - req.image = img; - req.ctx = ctx; - - this.texturesToLoadToGPU.add(req); - - } - - /* - * (non-Javadoc) - * - * @seeorg.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime. - * IProgressMonitor) - */ - @Override - protected IStatus run(IProgressMonitor monitor) { - - while (this.isRunning) { - while (this.texturesToLoad.size() > MAX_QUEUE_SIZE) { - this.texturesToLoad.poll(); - } - - while (this.texturesToLoad.size() > 0) { - AbstractGLImage image = this.texturesToLoad.remove(); - if (image.getStatus() == com.raytheon.uf.viz.core.drawables.IImage.Status.STAGED - || image.getStatus() == com.raytheon.uf.viz.core.drawables.IImage.Status.LOADED) { - continue; - } - try { - image.stageTexture(); - } catch (VizException e) { - Activator - .getDefault() - .getLog() - .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, - "Staging texture failed", e)); - } - } - try { - Thread.sleep(TEXTURE_JOB_SLEEP_TIME); - } catch (InterruptedException e) { - } - - // while (this.texturesToLoadToGPU.size() > MAX_QUEUE_SIZE) { - // this.texturesToLoadToGPU.remove(); - // } - // - // while (this.texturesToLoadToGPU.size() > 0) { - // final Request request = this.texturesToLoadToGPU.remove(); - // - // if (request.image.getStatus() == IImage.Status.LOADED - // || request.image.getStatus() == IImage.Status.FAILED) { - // continue; - // } - // VizApp.runSync(new Runnable() { - // - // public void run() { - // try { - // request.image.loadTexture(request.ctx); - // } catch (VizException e) { - // // Set an exception that the drawing subsystem will - // // pick - // // up and log properly/display to user - // request.image.setStatus(IImage.Status.FAILED); - // request.image.setFailedMessage(e); - // } - // } - // - // }); - // - // } - // try { - // Thread.sleep(TEXTURE_JOB_SLEEP_TIME); - // } catch (InterruptedException e) { - // } - - } - return Status.OK_STATUS; - } - - /** - * Request the job to be shut down - * - */ - public void shutdown() { - this.isRunning = false; - } - -} diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/AbstractGLColorMapDataFormat.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/AbstractGLColorMapDataFormat.java index a2ba29df01..678072b0eb 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/AbstractGLColorMapDataFormat.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/AbstractGLColorMapDataFormat.java @@ -158,7 +158,7 @@ public abstract class AbstractGLColorMapDataFormat { */ protected Buffer handleBufferSizing(GLColorMapData data, Buffer buffer, int[] dimensions) { - int sliceWidth = dimensions[0]; + int sliceWidth = dimensions[0] * getValuesPerPixel(); int sliceHeight = dimensions[1]; int paddedSliceWidth = getAlignedWidth(sliceWidth); @@ -169,7 +169,7 @@ public abstract class AbstractGLColorMapDataFormat { // Im not sure what shape this data is in, so just panic. throw new IllegalStateException("Buffer is wrong size(" + totalDataSize + ") for data dimensions(" + sliceWidth - + "x" + sliceWidth + ")"); + + "x" + sliceHeight + ")"); } Buffer newBuffer = getCopybackBuffer(data); diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLByteDataFormat.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLByteDataFormat.java index 43c8e409fa..85f46d781b 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLByteDataFormat.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLByteDataFormat.java @@ -74,7 +74,8 @@ public class GLByteDataFormat extends AbstractGLColorMapDataFormat { */ @Override public Buffer getCopybackBuffer(GLColorMapData data) { - int width = getAlignedWidth(data.getDimensionSize(0)); + int width = getAlignedWidth(data.getDimensionSize(0) + * getValuesPerPixel()); int height = data.getDimensionSize(1); return ByteBuffer.allocate(height * width); } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLShortDataFormat.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLShortDataFormat.java index 19c692b852..bcbb01caa1 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLShortDataFormat.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLShortDataFormat.java @@ -83,7 +83,7 @@ public class GLShortDataFormat extends AbstractGLColorMapDataFormat { * (int, int, com.raytheon.viz.core.gl.dataprep.GLColorMapData) */ @Override - public Short getValue(int x, int y, GLColorMapData data) { + public Number getValue(int x, int y, GLColorMapData data) { if (!(data.getData() instanceof ShortBuffer)) { throw new IllegalArgumentException( "Expecting data to contain a ShortBuffer but instead it is a " diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLUnsignedShortDataFormat.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLUnsignedShortDataFormat.java index 88d6c7b702..8f430b8054 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLUnsignedShortDataFormat.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/dataformat/GLUnsignedShortDataFormat.java @@ -60,7 +60,7 @@ public class GLUnsignedShortDataFormat extends GLShortDataFormat { * int, com.raytheon.viz.core.gl.dataformat.GLColorMapData) */ @Override - public Short getValue(int x, int y, GLColorMapData data) { + public Number getValue(int x, int y, GLColorMapData data) { if (!(data.getData() instanceof ShortBuffer)) { throw new IllegalArgumentException( "Expecting data to contain a ShortBuffer but instead it is a " @@ -69,7 +69,7 @@ public class GLUnsignedShortDataFormat extends GLShortDataFormat { int width = getAlignedWidth(data.getDimensionSize(0)); int index = y * width + x; ShortBuffer buffer = (ShortBuffer) data.getData(); - return buffer.get(index); + return (buffer.get(index) & 0xFFFF); } } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/ext/AbstractGLImagingExtension.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/ext/AbstractGLImagingExtension.java new file mode 100644 index 0000000000..02e0b16caf --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/ext/AbstractGLImagingExtension.java @@ -0,0 +1,402 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.core.gl.ext; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.media.opengl.GL; + +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; +import com.raytheon.uf.viz.core.DrawableImage; +import com.raytheon.uf.viz.core.IGraphicsTarget.RasterMode; +import com.raytheon.uf.viz.core.IMesh; +import com.raytheon.uf.viz.core.PixelCoverage; +import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.drawables.IImage.Status; +import com.raytheon.uf.viz.core.drawables.PaintProperties; +import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension; +import com.raytheon.uf.viz.core.drawables.ext.IImagingExtension; +import com.raytheon.uf.viz.core.exception.VizException; +import com.raytheon.viz.core.gl.GLCapabilities; +import com.raytheon.viz.core.gl.IGLTarget; +import com.raytheon.viz.core.gl.TextureLoader; +import com.raytheon.viz.core.gl.glsl.GLSLFactory; +import com.raytheon.viz.core.gl.glsl.GLShaderProgram; +import com.raytheon.viz.core.gl.images.AbstractGLImage; +import com.sun.opengl.util.texture.TextureCoords; +import com.vividsolutions.jts.geom.Coordinate; + +/** + * Abstract GL Imaging extension class + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 15, 2011            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public abstract class AbstractGLImagingExtension extends + GraphicsExtension implements IImagingExtension { + + protected static final IUFStatusHandler statusHandler = UFStatus + .getHandler(AbstractGLImagingExtension.class); + + protected static final TextureLoader textureLoader = TextureLoader + .getInstance(); + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.drawables.ext.IImagingExtension#drawRasters( + * com.raytheon.uf.viz.core.drawables.PaintProperties, + * com.raytheon.uf.viz.core.DrawableImage[]) + */ + @Override + public final boolean drawRasters(PaintProperties paintProps, + DrawableImage... images) throws VizException { + GL gl = target.getGl(); + boolean rval = true; + gl.glGetError(); + + target.pushGLState(); + try { + gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL); + List renderable = new ArrayList( + images.length); + + for (DrawableImage di : images) { + IImage image = di.getImage(); + if (image instanceof AbstractGLImage) { + AbstractGLImage glImage = (AbstractGLImage) image; + RasterMode mode = di.getMode(); + + if (glImage.getStatus() != Status.LOADED) { + if (glImage.getStatus() != Status.STAGED) { + if (mode == RasterMode.ASYNCHRONOUS) { + textureLoader.requestLoad(glImage); + target.setNeedsRefresh(true); + } else if (mode == RasterMode.SYNCHRONOUS) { + glImage.stage(); + } + } + + if (glImage.getStatus() == Status.STAGED) { + glImage.target(target); + } + } + + if (glImage.getStatus() == IImage.Status.LOADED) { + renderable.add(di); + } + } else { + statusHandler + .handle(Priority.PROBLEM, + "Can only draw AbstractGLImages on AbstractGLImagingExtension"); + } + } + + rval = drawRastersInternal(paintProps, + renderable.toArray(new DrawableImage[renderable.size()])) + && (renderable.size() == images.length); + + gl.glPolygonMode(GL.GL_BACK, GL.GL_LINE); + gl.glDisable(GL.GL_BLEND); + } finally { + target.popGLState(); + } + + target.handleError(gl.glGetError()); + return rval; + } + + protected boolean drawRastersInternal(PaintProperties paintProps, + DrawableImage... images) throws VizException { + GL gl = target.getGl(); + GLCapabilities capabilities = GLCapabilities.getInstance(gl); + // Get shader program extension uses + String shaderProgram = getShaderProgramName(); + + int continues = 0; + Set errorMsgs = new HashSet(); + List notDrawn = new ArrayList(); + + GLShaderProgram program = null; + boolean attemptedToLoadShader = false; + int lastTextureType = -1; + + for (DrawableImage di : images) { + AbstractGLImage glImage = (AbstractGLImage) di.getImage(); + PixelCoverage extent = di.getCoverage(); + + synchronized (glImage) { + int textureType = glImage.getTextureStorageType(); + + if (lastTextureType != textureType) { + if (lastTextureType != -1) { + gl.glDisable(lastTextureType); + } + gl.glEnable(textureType); + lastTextureType = textureType; + } + + Object dataObj = null; + + if (glImage.bind(gl)) { + // Notify extension image is about to be rendered + dataObj = preImageRender(paintProps, glImage, extent); + + if (dataObj == null) { + continues++; + continue; + } + + if (shaderProgram != null + && capabilities.cardSupportsShaders) { + if (program == null && !attemptedToLoadShader) { + attemptedToLoadShader = true; + program = GLSLFactory.getInstance() + .getShaderProgram(target, null, + shaderProgram); + if (program != null) { + program.startShader(); + } + + gl.glTexEnvi(GL.GL_TEXTURE_ENV, + GL.GL_TEXTURE_ENV_MODE, GL.GL_ADD); + gl.glEnable(GL.GL_BLEND); + gl.glTexEnvi(GL.GL_TEXTURE_ENV, + GL.GL_TEXTURE_ENV_MODE, GL.GL_BLEND); + gl.glBlendFunc(GL.GL_SRC_ALPHA, + GL.GL_ONE_MINUS_SRC_ALPHA); + + gl.glColor4f(0.0f, 0.0f, 0.0f, + paintProps.getAlpha()); + } + + if (program != null) { + loadShaderData(program, glImage, paintProps); + } + } else { + gl.glEnable(GL.GL_BLEND); + gl.glBlendFunc(GL.GL_SRC_ALPHA, + GL.GL_ONE_MINUS_SRC_ALPHA); + gl.glColor4f(1.0f, 1.0f, 1.0f, paintProps.getAlpha()); + } + + drawCoverage(paintProps, extent, + glImage.getTextureCoords(), 0); + + gl.glActiveTexture(GL.GL_TEXTURE0); + gl.glBindTexture(textureType, 0); + + // Notify extension image has been rendered + postImageRender(paintProps, glImage, dataObj); + + // Enable if you want to see mesh drawn + if (false) { + if (program != null) { + program.endShader(); + } + gl.glDisable(GL.GL_BLEND); + gl.glColor3f(0.0f, 1.0f, 0.0f); + gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE); + drawCoverage(paintProps, extent, + glImage.getTextureCoords(), 0); + gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL); + gl.glEnable(GL.GL_BLEND); + if (program != null) { + program.startShader(); + } + } + } else { + errorMsgs.add("Texture did not bind"); + continues++; + notDrawn.add(di); + continue; + } + } + } + + if (lastTextureType != -1) { + gl.glDisable(lastTextureType); + } + + if (program != null) { + program.endShader(); + } + + if (errorMsgs.size() > 0) { + throw new VizException("Error rendering " + errorMsgs.size() + + " images: " + errorMsgs); + } + + boolean allDrawn = continues == 0; + if (!allDrawn) { + target.setNeedsRefresh(true); + } + + return allDrawn; + } + + /** + * Draw an image coverage object + * + * @param paintProps + * @param pc + * @param coords + * @param corrFactor + * @throws VizException + */ + protected void drawCoverage(PaintProperties paintProps, PixelCoverage pc, + TextureCoords coords, float corrFactor) throws VizException { + GL gl = target.getGl(); + if (pc == null) { + return; + } + // gl.glPolygonMode(GL.GL_BACK, GL.GL_FILL); + // gl.glColor3d(1.0, 0.0, 0.0); + // } + + // boolean useNormals = false; + IMesh mesh = pc.getMesh(); + + // if mesh exists, use it + if (mesh != null) { + mesh.paint(target, paintProps); + } else if (coords != null) { + FloatBuffer fb = ByteBuffer.allocateDirect(4 * 5 * 4) + .order(ByteOrder.nativeOrder()).asFloatBuffer(); + + Coordinate ul = pc.getUl(); + Coordinate ur = pc.getUr(); + Coordinate lr = pc.getLr(); + Coordinate ll = pc.getLl(); + + fb.put(new float[] { coords.left() + corrFactor, + coords.bottom() + corrFactor }); + fb.put(new float[] { (float) ll.x, (float) ll.y, (float) ll.z }); + + fb.put(new float[] { coords.right() - corrFactor, + coords.bottom() + corrFactor }); + fb.put(new float[] { (float) lr.x, (float) lr.y, (float) lr.z }); + + fb.put(new float[] { coords.left() + corrFactor, + coords.top() - corrFactor }); + fb.put(new float[] { (float) ul.x, (float) ul.y, (float) ul.z }); + + fb.put(new float[] { coords.right() - corrFactor, + coords.top() - corrFactor }); + fb.put(new float[] { (float) ur.x, (float) ur.y, (float) ur.z }); + + // Clear error bit + gl.glGetError(); + + gl.glEnableClientState(GL.GL_VERTEX_ARRAY); + gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); + + gl.glInterleavedArrays(GL.GL_T2F_V3F, 0, fb.rewind()); + int error = gl.glGetError(); + if (error == GL.GL_NO_ERROR) { + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); + } else { + target.handleError(error); + } + + gl.glDisableClientState(GL.GL_VERTEX_ARRAY); + gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY); + } + } + + /** + * Setup anything that is required pre image rendering. Object returned is a + * state object and will be passed in to postImageRender. If the image + * should not be drawn, return null + * + * @param paintProps + * @param image + * @return + * @throws VizException + */ + public Object preImageRender(PaintProperties paintProps, + AbstractGLImage image, PixelCoverage imageCoverage) + throws VizException { + return this; + } + + /** + * Post image rendering method, can be used to change any state required. + * Return object from preImageRender is passed in as data argument + * + * @param paintProps + * @param image + * @param data + * @throws VizException + */ + public void postImageRender(PaintProperties paintProps, + AbstractGLImage image, Object data) throws VizException { + + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension# + * getCompatibilityValue(com.raytheon.uf.viz.core.IGraphicsTarget) + */ + @Override + public int getCompatibilityValue(IGLTarget target) { + return Compatibilty.TARGET_COMPATIBLE; + } + + /** + * The shader program name to execute for this extension + * + * @return + */ + public abstract String getShaderProgramName(); + + /** + * Populate the shader program with data required for execution + * + * @param program + * @param image + * @param paintProps + * @throws VizException + */ + public abstract void loadShaderData(GLShaderProgram program, IImage image, + PaintProperties paintProps) throws VizException; +} diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLOffscreenRenderingExtension.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/ext/GLOffscreenRenderingExtension.java similarity index 83% rename from cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLOffscreenRenderingExtension.java rename to cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/ext/GLOffscreenRenderingExtension.java index 8cf5e6605c..90f77f275e 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLOffscreenRenderingExtension.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/ext/GLOffscreenRenderingExtension.java @@ -1,4 +1,4 @@ -package com.raytheon.viz.core.gl.internal.ext; +package com.raytheon.viz.core.gl.ext; import java.nio.Buffer; import java.nio.ByteBuffer; @@ -12,14 +12,13 @@ import com.raytheon.uf.viz.core.drawables.ColorMapParameters; import com.raytheon.uf.viz.core.drawables.IImage; import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension; import com.raytheon.uf.viz.core.drawables.ext.IOffscreenRenderingExtension; -import com.raytheon.uf.viz.core.drawables.ext.colormap.IColormappedImageExtension; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.viz.core.gl.IGLTarget; import com.raytheon.viz.core.gl.dataformat.AbstractGLColorMapDataFormat; import com.raytheon.viz.core.gl.dataformat.GLByteDataFormat; -import com.raytheon.viz.core.gl.dataformat.GLColorMapData; import com.raytheon.viz.core.gl.dataformat.IGLColorMapDataFormatProvider; import com.raytheon.viz.core.gl.images.AbstractGLImage; +import com.raytheon.viz.core.gl.internal.ext.GLColormappedImageExtension; public class GLOffscreenRenderingExtension extends GraphicsExtension implements IOffscreenRenderingExtension { @@ -34,12 +33,11 @@ public class GLOffscreenRenderingExtension extends GraphicsExtension throw new VizException( "Can only use GLImages as offscreen frameBuffer on GLTarget"); } - target.makeContextCurrent(); AbstractGLImage glImage = (AbstractGLImage) offscreenImage; if (glImage.getStatus() == IImage.Status.UNLOADED || glImage.getStatus() == IImage.Status.LOADING) { glImage.setStatus(IImage.Status.LOADING); - glImage.stageTexture(); + glImage.stage(); } if (glImage.getStatus() == IImage.Status.STAGED) { @@ -52,7 +50,6 @@ public class GLOffscreenRenderingExtension extends GraphicsExtension @Override public void renderOnscreen() throws VizException { - target.makeContextCurrent(); Rectangle canvasSize = target.getBounds(); target.getGl().glViewport(0, 0, canvasSize.width, canvasSize.height); target.getGl().glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0); @@ -66,7 +63,7 @@ public class GLOffscreenRenderingExtension extends GraphicsExtension */ @Override public int getCompatibilityValue(IGLTarget target) { - return Compatibilty.TARGET_COMPATIBLE.value; + return Compatibilty.TARGET_COMPATIBLE; } /* @@ -76,8 +73,9 @@ public class GLOffscreenRenderingExtension extends GraphicsExtension * constructOffscreenImage(java.lang.Class, java.awt.Rectangle) */ @Override - public IImage constructOffscreenImage(Class dataType, - int[] dimensions) throws VizException { + public AbstractGLImage constructOffscreenImage( + Class dataType, int[] dimensions) + throws VizException { return constructOffscreenImage(dataType, dimensions, null); } @@ -88,9 +86,9 @@ public class GLOffscreenRenderingExtension extends GraphicsExtension * constructOffscreenImage(java.lang.Class, java.awt.Rectangle) */ @Override - public IImage constructOffscreenImage(Class dataType, - final int[] dimensions, ColorMapParameters parameters) - throws VizException { + public AbstractGLImage constructOffscreenImage( + Class dataType, final int[] dimensions, + ColorMapParameters parameters) throws VizException { int width = dimensions[0]; int height = dimensions[1]; // Need to add support for multiple buffer types @@ -105,10 +103,10 @@ public class GLOffscreenRenderingExtension extends GraphicsExtension } if (imageBuffer != null) { - IImage image = null; + AbstractGLImage image = null; final Buffer buffer = imageBuffer; - IColormappedImageExtension cmapExt = target - .getExtension(IColormappedImageExtension.class); + GLColormappedImageExtension cmapExt = target + .getExtension(GLColormappedImageExtension.class); if (supportsLuminance) { image = cmapExt.initializeRaster( new IColorMapDataRetrievalCallback() { @@ -121,7 +119,7 @@ public class GLOffscreenRenderingExtension extends GraphicsExtension }, parameters); } else { image = cmapExt.initializeRaster(new GLOffscreenDataCallback( - buffer, dimensions), null); + buffer, dimensions), parameters); } if (!checkedLuminance) { checkedLuminance = true; @@ -132,7 +130,8 @@ public class GLOffscreenRenderingExtension extends GraphicsExtension // assume we don't support luminance supportsLuminance = false; // Reconstruct image - image = constructOffscreenImage(dataType, dimensions); + image = constructOffscreenImage(dataType, dimensions, + parameters); } } return image; @@ -178,19 +177,6 @@ public class GLOffscreenRenderingExtension extends GraphicsExtension return GL.GL_RGB8; } - /* - * (non-Javadoc) - * - * @see com.raytheon.viz.core.gl.dataprep.GLByteDataFormat# - * getCopybackBuffer(java.awt.Rectangle) - */ - @Override - public Buffer getCopybackBuffer(GLColorMapData data) { - int width = getAlignedWidth(data.getDimensionSize(0)) * 3; - int height = data.getDimensionSize(1) * 3; - return ByteBuffer.allocate(height * width); - } - /* * (non-Javadoc) * diff --git a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/GLRadarMosaicRendererFactory.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/AbstractGLSLImagingExtension.java similarity index 52% rename from cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/GLRadarMosaicRendererFactory.java rename to cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/AbstractGLSLImagingExtension.java index 70a7d8009e..058ec899f7 100644 --- a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/GLRadarMosaicRendererFactory.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/AbstractGLSLImagingExtension.java @@ -17,16 +17,15 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.uf.viz.radar.gl.mosaic; +package com.raytheon.viz.core.gl.glsl; -import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension; -import com.raytheon.uf.viz.core.exception.VizException; +import com.raytheon.viz.core.gl.GLCapabilities; import com.raytheon.viz.core.gl.IGLTarget; -import com.raytheon.viz.radar.rsc.mosaic.MergeRasterRadarMosaicRenderer; -import com.raytheon.viz.radar.rsc.mosaic.ext.IRadarMosaicRendererFactoryExtension; +import com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension; +import com.raytheon.viz.core.gl.internal.GLTarget; /** - * Radar mosaic renderer factory for IGLTarget + * Abstract GL Extension that requires shader to work properly * *
  * 
@@ -34,7 +33,7 @@ import com.raytheon.viz.radar.rsc.mosaic.ext.IRadarMosaicRendererFactoryExtensio
  * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * Nov 22, 2011            mschenke     Initial creation
+ * Dec 15, 2011            mschenke     Initial creation
  * 
  * 
* @@ -42,28 +41,8 @@ import com.raytheon.viz.radar.rsc.mosaic.ext.IRadarMosaicRendererFactoryExtensio * @version 1.0 */ -public class GLRadarMosaicRendererFactory extends GraphicsExtension - implements IRadarMosaicRendererFactoryExtension { - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.viz.radar.rsc.mosaic.ext.IRadarMosaicRendererFactoryExtension - * #createNewRenderer() - */ - @Override - public IRadarMosaicRenderer createNewRenderer(MosaicType mosaicType) - throws VizException { - switch (mosaicType) { - case MergeRaster: - return new MergeRasterRadarMosaicRenderer(); - case MaxValue: - return new RadarMosaicRenderer(); - } - throw new VizException("Could not find mosaic renderer for type = " - + mosaicType); - } +public abstract class AbstractGLSLImagingExtension extends + AbstractGLImagingExtension { /* * (non-Javadoc) @@ -73,7 +52,12 @@ public class GLRadarMosaicRendererFactory extends GraphicsExtension */ @Override public int getCompatibilityValue(IGLTarget target) { - return Compatibilty.TARGET_COMPATIBLE.value; + if (GLCapabilities.getInstance(target.getGl()).cardSupportsShaders + && GLTarget.FORCE_NO_SHADER == false) { + return Compatibilty.ENHANCED_TARGET_COMPATIBLE; + } else { + return Compatibilty.INCOMPATIBLE; + } } } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/GLSLFactory.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/GLSLFactory.java index ff676ac70b..445e9804b8 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/GLSLFactory.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/GLSLFactory.java @@ -22,15 +22,6 @@ package com.raytheon.viz.core.gl.glsl; import java.util.HashMap; import java.util.Map; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; - -import com.raytheon.uf.viz.core.drawables.IImage; -import com.raytheon.uf.viz.core.drawables.PaintProperties; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.viz.core.gl.IGLTarget; import com.raytheon.viz.core.gl.glsl.internal.GLProgramManager; @@ -58,45 +49,7 @@ public class GLSLFactory { private final Map shadersPrograms = new HashMap(); - private static final Map shaderProgramMap = new HashMap(); - - static { - // Construct the resource mapping from Eclipse plugins - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint point = registry - .getExtensionPoint("com.raytheon.viz.core.gl.shader"); - if (point != null) { - IExtension[] extensions = point.getExtensions(); - - for (int i = 0; i < extensions.length; ++i) { - IConfigurationElement[] config = extensions[i] - .getConfigurationElements(); - - for (int j = 0; j < config.length; j++) { - String name = config[j].getAttribute("programName"); - shaderProgramMap.put(name, config[j]); - } - } - - } - } - - public static void registerProgramLoader(String name, IShaderLoader loader) { - shaderProgramMap.put(name, loader); - } - private GLSLFactory() { - // Register vetex.glsl as the default vertex program loader - IShaderLoader loader = new AbstractShaderLoader() { - @Override - public void loadData(IGLTarget target, GLShaderProgram program, - IImage image, PaintProperties paintProps) - throws VizException { - // does nothing - } - }; - loader.setName(DEFAULT_VERTEX); - registerProgramLoader(loader.getName(), loader); } /** @@ -133,68 +86,17 @@ public class GLSLFactory { String shaderName = new String(vertexName + "_" + fragName); GLShaderProgram shader = shadersPrograms.get(shaderName); if (shader == null - || GLProgramManager.getInstance().hasBeenModified(fragName, - false) - || GLProgramManager.getInstance().hasBeenModified(vertexName, - false)) { + || GLProgramManager.getInstance().hasBeenModified(fragName) + || GLProgramManager.getInstance().hasBeenModified(vertexName)) { if (shader != null) { shader.dispose(); } - // program object not cached, construct - IShaderLoader vertexShader = null; - if (vertexName != null) { - vertexShader = getShaderLoaderInstance(shaderProgramMap - .get(vertexName)); - } - IShaderLoader fragmentShader = null; - if (fragName != null) { - fragmentShader = getShaderLoaderInstance(shaderProgramMap - .get(fragName)); - fragmentShader.setName(fragName); - } - shader = new GLShaderProgram(target, shaderName, vertexShader, - fragmentShader); + shader = new GLShaderProgram(target, shaderName, vertexName, + fragName); shadersPrograms.put(shaderName, shader); } - if (shader != null) { - Object fshader = shaderProgramMap.get(fragName); - Object vshader = shaderProgramMap.get(vertexName); - if (fshader != null && fshader instanceof IShaderLoader - && shader.getFragmentShader() != fshader) { - shader.updateFragmentShader((IShaderLoader) fshader); - } - if (vshader != null && vshader instanceof IShaderLoader - && shader.getVertexShader() != vshader) { - shader.updateVertexShader((IShaderLoader) vshader); - } - } - return shader; } - - /** - * Construct an instance of the shader loader class - * - * @param className - * @return - */ - private IShaderLoader getShaderLoaderInstance(Object object) - throws VizException { - if (object instanceof IConfigurationElement) { - IConfigurationElement configElement = (IConfigurationElement) object; - try { - return (IShaderLoader) configElement - .createExecutableExtension("loaderClass"); - } catch (CoreException e) { - throw new VizException( - "Error constructing instance of loader class: " - + configElement.getAttribute("loaderClass"), e); - } - } else if (object instanceof IShaderLoader) { - return (IShaderLoader) object; - } - return null; - } } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/GLSLRasterProgramLoader.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/GLSLRasterProgramLoader.java deleted file mode 100644 index 8a8c22e78c..0000000000 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/GLSLRasterProgramLoader.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ -package com.raytheon.viz.core.gl.glsl; - -import javax.media.opengl.GL; - -import com.raytheon.uf.viz.core.drawables.ColorMapParameters; -import com.raytheon.uf.viz.core.drawables.IImage; -import com.raytheon.uf.viz.core.drawables.PaintProperties; -import com.raytheon.uf.viz.core.drawables.SingleColorImage; -import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.viz.core.gl.IGLTarget; -import com.raytheon.viz.core.gl.images.AbstractGLImage; -import com.raytheon.viz.core.gl.images.GLColormappedImage; - -/** - * Shader loader for rasters - * - *
- * 
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * May 25, 2010            mschenke     Initial creation
- * 
- * 
- * - * @author mschenke - * @version 1.0 - */ - -public class GLSLRasterProgramLoader extends AbstractShaderLoader { - - /* - * (non-Javadoc - * - * @see - * com.raytheon.viz.core.gl.glsl.IShaderLoader#loadData(com.raytheon.viz - * .core.gl.IGLTarget, com.raytheon.viz.core.gl.glsl.GLShaderProgram, - * com.raytheon.uf.viz.core.drawables.IImage, - * com.raytheon.uf.viz.core.drawables.PaintProperties) - */ - @Override - public void loadData(IGLTarget target, GLShaderProgram program, - IImage iimage, PaintProperties paintProps) throws VizException { - // Check for single color image - if (iimage instanceof SingleColorImage) { - program.setUniform("doSingleColor", 1); - program.setUniform("singleColor", - ((SingleColorImage) iimage).getColor()); - iimage = ((SingleColorImage) iimage).getWrappedImage(); - } else { - program.setUniform("doSingleColor", 0); - } - - // Get image as AbstractGLImage - AbstractGLImage image = null; - if (iimage instanceof AbstractGLImage == false) { - throw new VizException( - "Cannot apply glsl raster shader to non gl image"); - } - image = (AbstractGLImage) iimage; - - program.setUniform("brightness", image.getBrightness()); - program.setUniform("contrast", image.getContrast()); - - int texId = image instanceof GLColormappedImage ? ((GLColormappedImage) image) - .getTextureid() : -1; - if (texId > -1) { - program.setUniform("doColorMap", 1); - } else { - program.setUniform("doColorMap", 0); - } - - float naturalMin = 0; - float naturalMax = 0; - - float cmapMin = 0; - float cmapMax = 0; - - if (texId > 0) { - GLColormappedImage colormappedImg = (GLColormappedImage) image; - ColorMapParameters colorMapParameters = colormappedImg - .getColorMapParameters(); - - naturalMin = colorMapParameters.getDataMin(); - naturalMax = colorMapParameters.getDataMax(); - cmapMin = colorMapParameters.getColorMapMin(); - cmapMax = colorMapParameters.getColorMapMax(); - - program.setUniform("colorMapSz", colorMapParameters.getColorMap() - .getSize()); - int textureType = ((GLColormappedImage) image).getTextureType(); - program.setUniform("isFloat", textureType == GL.GL_FLOAT - || textureType == GL.GL_HALF_FLOAT_ARB ? 1 : 0); - program.setUniform("logarithmic", - colorMapParameters.isLogarithmic() ? 1 : 0); - program.setUniform("logFactor", colorMapParameters.getLogFactor()); - program.setUniform("mirror", colorMapParameters.isMirror() ? 1 : 0); - - program.setUniform("applyMask", colorMapParameters.isUseMask() ? 1 - : 0); - } - - program.setUniform("naturalMin", naturalMin); - program.setUniform("naturalMax", naturalMax); - program.setUniform("cmapMin", cmapMin); - program.setUniform("cmapMax", cmapMax); - - program.setUniform("alphaMask", 2); - program.setUniform("colorMap", 1); - program.setUniform("rawText", 0); - - program.setUniform("alphaVal", paintProps.getAlpha()); - } -} diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/GLShaderProgram.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/GLShaderProgram.java index 9e70031e2d..7a4b7aae73 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/GLShaderProgram.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/GLShaderProgram.java @@ -21,7 +21,9 @@ package com.raytheon.viz.core.gl.glsl; import java.nio.ByteBuffer; import java.nio.IntBuffer; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.media.opengl.GL; @@ -31,8 +33,6 @@ import org.eclipse.swt.graphics.RGB; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; -import com.raytheon.uf.viz.core.drawables.IImage; -import com.raytheon.uf.viz.core.drawables.PaintProperties; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.viz.core.gl.IGLTarget; import com.raytheon.viz.core.gl.glsl.internal.GLProgramManager; @@ -68,14 +68,6 @@ public class GLShaderProgram { private int glslContext = -1; - private int vertexShaderId = -1; - - private int fragmentShaderId = -1; - - private IShaderLoader vertexShader; - - private IShaderLoader fragmentShader; - private State state = State.INVALID; // Declaring and using variables in GLSL is similar to using variables in C. @@ -111,28 +103,36 @@ public class GLShaderProgram { * @param fragmentShader * - can be null (but not if vertexShader == null) */ - GLShaderProgram(IGLTarget target, String name, IShaderLoader vertexShader, - IShaderLoader fragmentShader) throws VizException { + GLShaderProgram(IGLTarget target, String name, String vertexShader, + String fragmentShader) throws VizException { gl = target.getGl(); - glslContext = gl.glCreateProgramObjectARB(); + glslContext = gl.glCreateProgram(); if (glslContext < 1) { throw new VizException( "Error creating glsl program, could not create program object"); } - vertexShaderId = -1; - fragmentShaderId = -1; - + List shaderIds = new ArrayList(2); if (vertexShader != null) { - this.setVertexShader(vertexShader); + shaderIds.add(addShader(vertexShader, GL.GL_VERTEX_SHADER)); } if (fragmentShader != null) { - this.setFragmentShader(fragmentShader); + shaderIds.add(addShader(fragmentShader, GL.GL_FRAGMENT_SHADER)); } - gl.glLinkProgramARB(glslContext); + + for (Integer shaderId : shaderIds) { + gl.glAttachShader(glslContext, shaderId); + } + gl.glLinkProgram(glslContext); if (!checkForLinkingErrors(gl)) { state = State.INITIALIZED; + for (Integer shaderId : shaderIds) { + gl.glDeleteShader(shaderId); + } + } else { + throw new VizException( + "Error creating glsl shader program, could not link"); } this.name = name; } @@ -142,7 +142,7 @@ public class GLShaderProgram { */ public void startShader() { if (state == State.INITIALIZED) { - gl.glUseProgramObjectARB(glslContext); + gl.glUseProgram(glslContext); state = State.IN_USE; } loadedUniforms.clear(); @@ -153,7 +153,7 @@ public class GLShaderProgram { */ public void endShader() { if (state == State.IN_USE) { - gl.glUseProgramObjectARB(0); + gl.glUseProgram(0); state = State.INITIALIZED; } loadedUniforms.clear(); @@ -168,53 +168,18 @@ public class GLShaderProgram { } /** - * Load data into the shader program + * Load, and compile the shader program * - * @param target - * @param image - * @param paintProps - * @throws VizException + * @param shader */ - public void loadData(IGLTarget target, IImage image, - PaintProperties paintProps) throws VizException { - if (state == State.IN_USE) { - if (vertexShader != null) { - vertexShader.loadData(target, this, image, paintProps); - } - if (fragmentShader != null) { - fragmentShader.loadData(target, this, image, paintProps); - } - } - } - - /** - * Set, load, and compile the vertex shader program - * - * @param vshader - */ - private void setVertexShader(IShaderLoader vshader) throws VizException { - this.vertexShader = vshader; - vertexShaderId = loadShaderProgram(GLProgramManager.getInstance() - .getProgramCode(vshader.getName()), GL.GL_VERTEX_SHADER); - if (vertexShaderId < 0) { + private int addShader(String shaderName, int shaderType) + throws VizException { + int shaderId = loadShaderProgram(shaderName, shaderType); + if (shaderId < 1) { throw new VizException( - "Error creating vertex shader, object not allocated"); - } - } - - /** - * Set, load, and compile the fragment shader program - * - * @param fshader - */ - private void setFragmentShader(IShaderLoader fshader) throws VizException { - this.fragmentShader = fshader; - fragmentShaderId = loadShaderProgram(GLProgramManager.getInstance() - .getProgramCode(fshader.getName()), GL.GL_FRAGMENT_SHADER); - if (fragmentShaderId < 0) { - throw new VizException( - "Error creating fragment shader, object not allocated"); + "Error creating shader, object not allocated"); } + return shaderId; } /** @@ -224,54 +189,20 @@ public class GLShaderProgram { * @param glShaderId * @return the shader program id */ - private int loadShaderProgram(String program, int glShaderId) { - int shaderId = gl.glCreateShaderObjectARB(glShaderId); + private int loadShaderProgram(String programName, int glShaderId) + throws VizException { + String program = GLProgramManager.getInstance().getProgramCode( + programName); + int shaderId = gl.glCreateShader(glShaderId); if (shaderId >= 0) { - gl.glShaderSourceARB(shaderId, 1, new String[] { program }, + gl.glShaderSource(shaderId, 1, new String[] { program }, (int[]) null, 0); - gl.glCompileShaderARB(shaderId); - checkForCompileErrors(gl, shaderId, glShaderId); - gl.glAttachObjectARB(glslContext, shaderId); + gl.glCompileShader(shaderId); + checkForCompileErrors(gl, shaderId, glShaderId, programName); } return shaderId; } - /** - * Updates the fragment shader's loader object - * - * @param fshader - */ - public void updateFragmentShader(IShaderLoader fshader) { - this.fragmentShader = fshader; - } - - /** - * Update the vertex shader loader - * - * @param vshader - */ - public void updateVertexShader(IShaderLoader vshader) { - this.vertexShader = vshader; - } - - /** - * Get the shader loader - * - * @return - */ - IShaderLoader getVertexShader() { - return vertexShader; - } - - /** - * Get the fragment loader - * - * @return - */ - IShaderLoader getFragmentShader() { - return fragmentShader; - } - /** * Set the uniform variable for the shader program * @@ -283,6 +214,9 @@ public class GLShaderProgram { gl.glUniform1f(getUniformLocation(uniformName), (Float) value); } else if (value instanceof Integer) { gl.glUniform1i(getUniformLocation(uniformName), (Integer) value); + } else if (value instanceof Boolean) { + gl.glUniform1i(getUniformLocation(uniformName), + ((Boolean) value) == true ? 1 : 0); } else if (value instanceof int[]) { gl.glUniform1iv(getUniformLocation(uniformName), MAX_MULTIGRIDS, (int[]) value, 0); @@ -306,7 +240,7 @@ public class GLShaderProgram { * @param value */ public void setUniform(String key, Object value) { - if (value != null) { + if (value != null && state == State.IN_USE) { if (loadedUniforms.containsKey(key) == false || value.equals(loadedUniforms.get(key)) == false) { // we haven't loaded this uniform yet or it is different @@ -324,7 +258,7 @@ public class GLShaderProgram { * @return */ private int getUniformLocation(String name) { - return (gl.glGetUniformLocationARB(glslContext, name)); + return (gl.glGetUniformLocation(glslContext, name)); } /** @@ -334,23 +268,22 @@ public class GLShaderProgram { * @param shader * @return */ - private boolean checkForCompileErrors(GL gl, int shader, int glId) { + private boolean checkForCompileErrors(GL gl, int shader, int glId, + String name) { String type = "unknown"; - String fileName = "unkown"; if (glId == GL.GL_FRAGMENT_SHADER) { type = "fragment"; - fileName = fragmentShader.getName(); } else if (glId == GL.GL_VERTEX_SHADER) { type = "vertex"; - fileName = vertexShader.getName(); } + boolean rval = false; int[] compilecheck = new int[1]; gl.glGetObjectParameterivARB(shader, GL.GL_OBJECT_COMPILE_STATUS_ARB, compilecheck, 0); if (compilecheck[0] == GL.GL_FALSE) { System.err.println("A compilation error occured in the " + type - + " shader source file (" + fileName + ".glsl)"); + + " shader source file (" + name + ")"); IntBuffer iVal = BufferUtil.newIntBuffer(1); gl.glGetObjectParameterivARB(shader, @@ -367,8 +300,8 @@ public class GLShaderProgram { byte[] infoBytes = new byte[length - 1]; infoLog.get(infoBytes); statusHandler.handle(Priority.CRITICAL, "Problem occured during " - + type + " shader initialization of file " + fileName - + ".glsl: " + new String(infoBytes)); + + type + " shader initialization of " + name + ": " + + new String(infoBytes)); System.err.println(new String(infoBytes)); rval = true; } @@ -417,18 +350,6 @@ public class GLShaderProgram { endShader(); } if (state == State.INITIALIZED) { - if (fragmentShader != null) { - gl.glDetachShader(glslContext, fragmentShaderId); - gl.glDeleteShader(fragmentShaderId); - fragmentShaderId = -1; - } - - if (vertexShader != null) { - gl.glDetachShader(glslContext, vertexShaderId); - gl.glDeleteShader(vertexShaderId); - vertexShaderId = -1; - } - gl.glDeleteProgram(glslContext); glslContext = -1; } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/internal/GLProgramManager.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/internal/GLProgramManager.java index b0559aeac5..7b4c6d1389 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/internal/GLProgramManager.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/internal/GLProgramManager.java @@ -23,11 +23,18 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import com.raytheon.uf.common.localization.IPathManager; +import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.exception.VizException; /** @@ -43,16 +50,44 @@ import com.raytheon.uf.viz.core.exception.VizException; */ public class GLProgramManager { + private static final String GLSL_FOLDER = "glsl"; + + private static final String GLSL_INCLUDE_FOLDER = GLSL_FOLDER + + IPathManager.SEPARATOR + "include"; + + private static final String GLSL_EXTENSION = ".glsl"; + + private static final String GLSL_HEADER_EXTENSION = ".glh"; + + private static final Pattern INCLUDE_PATTERN = Pattern + .compile("^#include\\s*<([a-zA-z0-9_]*)>.*"); + private static GLProgramManager instance; + private final Map includeCode = new HashMap(); + private final Map programsCode = new HashMap(); - private Map fileMap = new HashMap(); + private final Map headerFiles = new HashMap(); - private Map modificationMap = new HashMap(); + private final Map includeFiles = new HashMap(); + + private final Map programFiles = new HashMap(); + + private final IPathManager pm; private GLProgramManager() { + pm = PathManagerFactory.getPathManager(); + // Lookup available main programs (will be in glsl directory) + LocalizationFile[] files = pm.listStaticFiles(GLSL_FOLDER, + new String[] { GLSL_EXTENSION }, false, true); + for (LocalizationFile file : files) { + File fileObj = file.getFile(); + String name = fileObj.getName(); + programFiles.put(name, fileObj); + programsCode.put(name, readProgramContents(fileObj)); + } } public static GLProgramManager getInstance() { @@ -63,67 +98,151 @@ public class GLProgramManager { return instance; } + /** + * Get program code for the program name specified, these files live in glsl + * directory in localization. + * + * @param aProgramName + * @return + * @throws VizException + */ public String getProgramCode(String aProgramName) throws VizException { - String program = programsCode.get(aProgramName); - String searchPath = "glsl" + File.separator + aProgramName + ".glsl"; - if (hasBeenModified(searchPath, true) || program == null) { - File file = fileMap.get(searchPath); - modificationMap.put(file, file.lastModified()); - try { - program = readFile(file); - programsCode.put(aProgramName, program); - } catch (IOException e) { - throw new VizException("Error loading program code for: " - + aProgramName, e); - } - } - - return program; + String fileName = aProgramName + GLSL_EXTENSION; + hasBeenModified(aProgramName); + return programsCode.get(fileName); } - public boolean hasBeenModified(String searchPath, boolean path) { - if (searchPath == null) { - return false; - } - - if (!path) { - searchPath = "glsl" + File.separator + searchPath + ".glsl"; - } - - File file = fileMap.get(searchPath); - if (file == null) { - IPathManager pm = PathManagerFactory.getPathManager(); - file = pm.getStaticFile(searchPath); - fileMap.put(searchPath, file); - } - - if (file.exists() == false) { - return false; - } - - Long lastMod = modificationMap.get(file); - if (lastMod == null || file.lastModified() > lastMod) { - return true; - } + /** + * Checks if program has been modified + * + * @param programName + * @return + */ + public boolean hasBeenModified(String programName) { + // TODO: Check file modification time and reload contents. Should also + // check modification times of files depends on and reload if any + // changes return false; } - private String readFile(File aFile) throws IOException { + /** + * Reads program contends for file, will recursively load all #includes as + * well + * + * @param aFile + * @return + */ + private String readProgramContents(File aFile) { + try { + StringBuffer buffer = new StringBuffer(); + + List toInclude = new ArrayList(); + getIncludes(aFile, toInclude); + + for (String include : toInclude) { + // look for header file first + File header = getIncludeFile(include, true); + if (header != null) { + String name = header.getName(); + String contents = includeCode.get(name); + if (contents == null) { + contents = readFileContents(header); + includeCode.put(name, contents); + } + buffer.append(contents); + } + } + + for (String include : toInclude) { + // look for glsl files next + File header = getIncludeFile(include, false); + if (header != null) { + String name = header.getName(); + String contents = includeCode.get(name); + if (contents == null) { + contents = readFileContents(header); + includeCode.put(name, contents); + } + buffer.append(contents); + } + } + + // Read program file contents + buffer.append(readFileContents(aFile)); + return buffer.toString(); + } catch (IOException e) { + UFStatus.getHandler().handle(Priority.PROBLEM, + "Error reading glsl program code from file system", e); + } + return null; + } + + /** + * Read file contents off file system + * + * @param file + * @param includeCode + * @return + * @throws IOException + */ + private String readFileContents(File file) throws IOException { StringBuffer buffer = new StringBuffer(); - FileReader fr = new FileReader(aFile); - BufferedReader reader = new BufferedReader(fr); - String line = ""; - while (line != null) { - buffer.append(line); - buffer.append("\n"); - line = reader.readLine(); + BufferedReader reader = new BufferedReader(new FileReader(file)); + + String line = null; + while ((line = reader.readLine()) != null) { + Matcher match = INCLUDE_PATTERN.matcher(line); + if (match.find() == false) { + buffer.append(line).append("\n"); + } + } + + return buffer.toString(); + } + + private void getIncludes(File file, List toInclude) + throws IOException { + List newIncludes = new ArrayList(); + BufferedReader reader = new BufferedReader(new FileReader(file)); + String line = null; + while ((line = reader.readLine()) != null) { + Matcher match = INCLUDE_PATTERN.matcher(line); + if (match.find()) { + String include = match.group(1); + if (toInclude.contains(include) == false + && newIncludes.contains(include) == false) { + newIncludes.add(include); + toInclude.add(include); + } + } } reader.close(); - fr.close(); - String text = buffer.toString(); - return text; + // Recursively get all include files + for (String newInclude : newIncludes) { + getIncludes(getIncludeFile(newInclude, false), toInclude); + } } + private File getIncludeFile(String name, boolean header) { + String fileName = name + + (header ? GLSL_HEADER_EXTENSION : GLSL_EXTENSION); + + Map toUse = null; + if (header) { + toUse = headerFiles; + } else { + toUse = includeFiles; + } + + File file = toUse.get(name); + if (file == null) { + file = pm.getStaticFile(GLSL_INCLUDE_FOLDER + + IPathManager.SEPARATOR + fileName); + toUse.put(name, file); + } + + return file; + } } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/AbstractGLImage.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/AbstractGLImage.java index 76b19a1513..9e9ae61845 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/AbstractGLImage.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/AbstractGLImage.java @@ -20,14 +20,16 @@ package com.raytheon.viz.core.gl.images; import javax.media.opengl.GL; -import javax.media.opengl.GLContext; +import javax.media.opengl.glu.GLU; import com.raytheon.uf.viz.core.IGraphicsTarget; -import com.raytheon.uf.viz.core.VizApp; import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.drawables.ext.IImagingExtension; import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.viz.core.gl.IGLTarget; -import com.raytheon.viz.core.gl.internal.GLTarget; +import com.raytheon.viz.core.gl.GLContextBridge; +import com.raytheon.viz.core.gl.objects.GLFrameBufferObject; +import com.raytheon.viz.core.gl.objects.GLRenderBuffer; +import com.sun.opengl.util.texture.TextureCoords; /** * @@ -48,9 +50,6 @@ import com.raytheon.viz.core.gl.internal.GLTarget; */ public abstract class AbstractGLImage implements IImage { - /** The GL graphics target */ - protected IGLTarget theTarget; - /** The brightness of the image */ private float brightness = 1.0f; @@ -67,13 +66,15 @@ public abstract class AbstractGLImage implements IImage { protected Throwable throwable; // Used for offscreen rendering - private int fbo = -1; + private GLFrameBufferObject fbo; // Used for offscreen rendering - private int rbuf = -1; + private GLRenderBuffer rbuf; - protected AbstractGLImage(IGLTarget target) { - this.theTarget = target; + private Class extensionClass; + + protected AbstractGLImage(Class extensionClass) { + this.extensionClass = extensionClass; } /** @@ -113,10 +114,10 @@ public abstract class AbstractGLImage implements IImage { * IGraphicsTarget) */ public void target(IGraphicsTarget target) throws VizException { - theTarget = (GLTarget) target; - GLContext ctx = theTarget.getContext(); // TextureLoaderJob.getInstance().requestLoadIntoTexture(this, ctx); - this.loadTexture(ctx); + GLContextBridge.makeMasterContextCurrent(); + this.loadTexture(GLU.getCurrentGL()); + GLContextBridge.releaseMasterContext(); } /* @@ -158,123 +159,139 @@ public abstract class AbstractGLImage implements IImage { } public void dispose() { - if (fbo > 0 || rbuf > 0) { - final int[] bufs = new int[] { -1, -1 }; - if (fbo > 0) { - bufs[0] = fbo; - fbo = -1; - } - if (rbuf > 0) { - bufs[1] = rbuf; - rbuf = -1; - } - - VizApp.runAsync(new Runnable() { - @Override - public void run() { - theTarget.makeContextCurrent(); - if (bufs[0] > 0) { - theTarget.getGl().glDeleteFramebuffersEXT(1, - new int[] { bufs[0] }, 0); - } - if (bufs[1] > 0) { - theTarget.getGl().glDeleteRenderbuffersEXT(1, - new int[] { bufs[1] }, 0); - } - } - }); + if (fbo != null) { + fbo.dispose(); + fbo = null; + } + if (rbuf != null) { + rbuf.dispose(); + rbuf = null; } } public void usaAsFrameBuffer() throws VizException { - GL gl = theTarget.getGl(); - if (fbo != -1 && rbuf != -1) { - gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, fbo); + GL gl = GLU.getCurrentGL(); + if (fbo != null && fbo.isValid()) { + fbo.bind(gl); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + if (rbuf != null && rbuf.isValid()) { + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + } else { + gl.glClear(GL.GL_COLOR_BUFFER_BIT); + } return; } + gl = GLU.getCurrentGL(); + gl.glBindTexture(getTextureStorageType(), 0); - int[] ids = new int[1]; - gl.glGenFramebuffersEXT(1, ids, 0); - fbo = ids[0]; - gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, fbo); + fbo = new GLFrameBufferObject(this); + fbo.bind(gl); - // Generate and bind a render buffer for the depth component - gl.glGenRenderbuffersEXT(1, ids, 0); - rbuf = ids[0]; - gl.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, rbuf); - gl.glRenderbufferStorageEXT(GL.GL_RENDERBUFFER_EXT, - GL.GL_DEPTH_COMPONENT, getWidth(), getHeight()); - gl.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, 0); - - // Attach render buffer to depth of fbo - gl.glFramebufferRenderbufferEXT(GL.GL_FRAMEBUFFER_EXT, - GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_RENDERBUFFER_EXT, rbuf); + if (gl.glIsEnabled(GL.GL_DEPTH_TEST)) { + // Generate and bind a render buffer for the depth component + rbuf = new GLRenderBuffer(this); + rbuf.bind(gl); + rbuf.createStorage(gl, GL.GL_DEPTH_COMPONENT, getWidth(), + getHeight()); + gl.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, 0); + // Attach render buffer to depth of fbo + gl.glFramebufferRenderbufferEXT(GL.GL_FRAMEBUFFER_EXT, + GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_RENDERBUFFER_EXT, + rbuf.getId()); + } // Attach texture to color attachement on fbo gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT, getTextureStorageType(), getTextureid(), 0); - String errorMessage = null; - - switch (gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_EXT)) { - case GL.GL_FRAMEBUFFER_COMPLETE_EXT: { - // Everything is ok. - break; - } - case GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: { - errorMessage = "Error: Framebuffer incomplete, fbo attachement is NOT complete"; - break; - } - case GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: { - errorMessage = "Error: Framebuffer incomplete, no image is attached to FBO"; - break; - } - case GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: { - errorMessage = "Error: Framebuffer incomplete, attached images have different dimensions"; - break; - } - case GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: { - errorMessage = "Error: Framebuffer incomplete, color attached images have different internal formats"; - break; - } - case GL.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: { - errorMessage = "Error: Framebuffer incomplete, draw buffer"; - break; - } - case GL.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: { - errorMessage = "Error: Framebuffer incomplete, read buffer"; - break; - } - case GL.GL_FRAMEBUFFER_UNSUPPORTED_EXT: { - errorMessage = "Error: Framebuffer not supported by hardware/drivers"; - break; - } - } + String errorMessage = fbo.checkStatus(gl); // use the window buffer if (errorMessage != null) { gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0); - if (fbo != -1) { - gl.glDeleteFramebuffersEXT(1, new int[] { fbo }, 0); - fbo = -1; + if (fbo != null) { + fbo.dispose(); + fbo = null; } - if (rbuf != -1) { - gl.glDeleteRenderbuffersEXT(1, new int[] { rbuf }, 0); - rbuf = -1; + if (rbuf != null) { + rbuf.dispose(); + rbuf = null; } throw new VizException(errorMessage); } } + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IImage#getExtensionClass() + */ + @Override + public Class getExtensionClass() { + return extensionClass; + } + + /** + * Binds the texture. Default implementation takes the textureId and binds + * to GL_TEXTURE0. Use bind(int) for more control + * + * @return + */ + public boolean bind(GL gl) { + return bind(gl, GL.GL_TEXTURE0); + } + + public boolean bind(GL gl, int texture) { + int texId = getTextureid(); + if (texId > 0) { + int textureType = getTextureStorageType(); + gl.glActiveTexture(texture); + gl.glBindTexture(textureType, texId); + + // Apply interpolation + if (isInterpolated()) { + gl.glTexParameteri(textureType, GL.GL_TEXTURE_MIN_FILTER, + GL.GL_LINEAR); + gl.glTexParameteri(textureType, GL.GL_TEXTURE_MAG_FILTER, + GL.GL_LINEAR); + } else { + gl.glTexParameteri(textureType, GL.GL_TEXTURE_MIN_FILTER, + GL.GL_NEAREST); + gl.glTexParameteri(textureType, GL.GL_TEXTURE_MAG_FILTER, + GL.GL_NEAREST); + } + return true; + } + return false; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IImage#stage() + */ + @Override + public final void stage() throws VizException { + Status status = getStatus(); + if (status != Status.LOADED && status != Status.STAGED) { + setStatus(Status.LOADING); + if (stageTexture()) { + setStatus(Status.STAGED); + } else { + setStatus(Status.FAILED); + } + } + } + + public abstract TextureCoords getTextureCoords(); + public abstract int getTextureid(); public abstract int getTextureStorageType(); - public abstract void stageTexture() throws VizException; + public abstract boolean stageTexture() throws VizException; - public abstract void loadTexture(GLContext ctx) throws VizException; + public abstract void loadTexture(GL gl) throws VizException; } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLCMTextureData.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLCMTextureData.java index 54dd5c8051..4d7b046f17 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLCMTextureData.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLCMTextureData.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.Map; import javax.media.opengl.GL; +import javax.media.opengl.glu.GLU; import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback; import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback.ColorMapData; @@ -33,6 +34,7 @@ import com.raytheon.viz.core.gl.dataformat.IGLColorMapDataFormatProvider; import com.raytheon.viz.core.gl.internal.cache.IImageCacheable; import com.raytheon.viz.core.gl.internal.cache.ImageCache; import com.raytheon.viz.core.gl.internal.cache.ImageCache.CacheType; +import com.raytheon.viz.core.gl.objects.GLTextureObject; /** * @@ -54,7 +56,7 @@ import com.raytheon.viz.core.gl.internal.cache.ImageCache.CacheType; */ public class GLCMTextureData implements IImageCacheable { - private int texId = -1; + private GLTextureObject tex; private final IColorMapDataRetrievalCallback callback; @@ -83,8 +85,8 @@ public class GLCMTextureData implements IImageCacheable { public synchronized void disposeTexture(GL gl) { if (isLoaded()) { - gl.glDeleteTextures(1, new int[] { texId }, 0); - texId = -1; + tex.dispose(); + tex = null; } ImageCache.getInstance(CacheType.TEXTURE).remove(this); } @@ -131,13 +133,10 @@ public class GLCMTextureData implements IImageCacheable { if (!stageTexture()) { return false; } - int type = getTextureStorageType(); - int[] t = null; - t = new int[1]; - gl.glGenTextures(1, t, 0); - gl.glBindTexture(type, t[0]); + tex = new GLTextureObject(this); + tex.bind(gl, type); gl.glTexParameteri(type, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); gl.glTexParameteri(type, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); @@ -162,9 +161,7 @@ public class GLCMTextureData implements IImageCacheable { getTextureFormat(), getTextureType(), data.getData().rewind()); gl.glPixelTransferf(GL.GL_RED_SCALE, 1.0f); gl.glPixelTransferf(GL.GL_RED_BIAS, 0.0f); - texId = t[0]; ImageCache.getInstance(CacheType.TEXTURE).put(this); - return true; } @@ -173,7 +170,7 @@ public class GLCMTextureData implements IImageCacheable { } public boolean isLoaded() { - return texId > 0; + return tex != null && tex.isValid(); } public int getDimensionSize(int dimension) { @@ -196,21 +193,22 @@ public class GLCMTextureData implements IImageCacheable { if (isLoaded()) { ImageCache.getInstance(CacheType.TEXTURE).put(this); } - return texId; + return tex.getId(); } public int getTextureStorageType() { return GL.GL_TEXTURE_2D; } - public double getValue(GL gl, int x, int y, float dataMin, float dataMax) { + public double getValue(int x, int y) { if (!isStaged() && isLoaded()) { + GL gl = GLU.getCurrentGL(); int textureStorageType = getTextureStorageType(); int copybackTextureType = data.getCopyBackTextureType(); Buffer copybackBuffer = data.getCopybackBuffer(); gl.glEnable(textureStorageType); gl.glActiveTexture(GL.GL_TEXTURE0); - gl.glBindTexture(textureStorageType, texId); + tex.bind(gl, textureStorageType); gl.glGetTexImage(textureStorageType, 0, getTextureFormat(), copybackTextureType, copybackBuffer.rewind()); gl.glActiveTexture(GL.GL_TEXTURE0); diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLColormappedImage.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLColormappedImage.java index 550d62fe63..fdc594669b 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLColormappedImage.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLColormappedImage.java @@ -19,13 +19,14 @@ **/ package com.raytheon.viz.core.gl.images; -import javax.media.opengl.GLContext; +import javax.media.opengl.GL; import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback; import com.raytheon.uf.viz.core.drawables.ColorMapParameters; import com.raytheon.uf.viz.core.drawables.IColormappedImage; +import com.raytheon.uf.viz.core.drawables.ext.IImagingExtension; import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.viz.core.gl.IGLTarget; +import com.sun.opengl.util.texture.TextureCoords; /** * @@ -51,24 +52,30 @@ public class GLColormappedImage extends AbstractGLImage implements protected GLCMTextureData data; public GLColormappedImage(IColorMapDataRetrievalCallback dataCallback, - ColorMapParameters params, IGLTarget target) { - super(target); + ColorMapParameters params, + Class extensionClass) { + super(extensionClass); this.data = GLCMTextureData.getGlTextureId(dataCallback); this.colorMapParameters = params; + if (data.isLoaded()) { + setStatus(Status.LOADED); + } else if (data.isStaged()) { + setStatus(Status.STAGED); + } } /* * (non-Javadoc) * - * @see com.raytheon.viz.core.gl.GLImage#stageTexture() + * @see com.raytheon.viz.core.gl.images.AbstractGLImage#stageTexture() */ @Override - public void stageTexture() throws VizException { - if (data.stageTexture()) { - setStatus(Status.STAGED); - } else { - setStatus(Status.FAILED); + public boolean stageTexture() throws VizException { + if (data == null) { + throw new VizException( + "Cannot stage texture, image has been disposed"); } + return data.stageTexture(); } /* @@ -79,8 +86,8 @@ public class GLColormappedImage extends AbstractGLImage implements * .GLContext) */ @Override - public void loadTexture(GLContext ctx) throws VizException { - if (data.loadTexture(ctx.getGL())) { + public void loadTexture(GL gl) throws VizException { + if (data.loadTexture(gl)) { // Add to texture cache setStatus(Status.LOADED); data.disposeTextureData(); @@ -169,13 +176,10 @@ public class GLColormappedImage extends AbstractGLImage implements @Override public double getValue(int x, int y) { - double val = 0; - if (theTarget == null || data == null) { - return Double.NaN; + double val = Double.NaN; + if (data != null) { + val = data.getValue(x, y); } - val = data.getValue(theTarget.getGl(), x, y, - colorMapParameters.getDataMin(), - colorMapParameters.getDataMax()); return val; } @@ -227,7 +231,11 @@ public class GLColormappedImage extends AbstractGLImage implements @Override public Status getStatus() { Status status = super.getStatus(); - if (data.isLoaded()) { + if (data == null) { + if (status != Status.UNLOADED) { + setStatus(Status.UNLOADED); + } + } else if (data.isLoaded()) { if (status != Status.LOADED) { setStatus(Status.LOADED); } @@ -247,4 +255,14 @@ public class GLColormappedImage extends AbstractGLImage implements return super.getStatus(); } + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.images.AbstractGLImage#getTextureCoords() + */ + @Override + public TextureCoords getTextureCoords() { + return new TextureCoords(0, 1, 1, 0); + } + } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLDelegateImage.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLDelegateImage.java new file mode 100644 index 0000000000..dfd6a56c41 --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLDelegateImage.java @@ -0,0 +1,176 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.core.gl.images; + +import javax.media.opengl.GL; + +import com.raytheon.uf.viz.core.IGraphicsTarget; +import com.raytheon.uf.viz.core.drawables.ext.IImagingExtension; +import com.raytheon.uf.viz.core.exception.VizException; +import com.sun.opengl.util.texture.TextureCoords; + +/** + * GL image that wraps another gl image + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 16, 2011            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public class GLDelegateImage extends AbstractGLImage { + + protected T image; + + public GLDelegateImage(T image, + Class extensionClass) { + super(extensionClass); + this.image = image; + } + + public T getWrappedImage() { + return image; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IImage#getWidth() + */ + @Override + public int getWidth() { + return image.getWidth(); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.IImage#getHeight() + */ + @Override + public int getHeight() { + return image.getHeight(); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.images.AbstractGLImage#getTextureCoords() + */ + @Override + public TextureCoords getTextureCoords() { + return image.getTextureCoords(); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.images.AbstractGLImage#getTextureid() + */ + @Override + public int getTextureid() { + return image.getTextureid(); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.images.AbstractGLImage#getTextureStorageType () + */ + @Override + public int getTextureStorageType() { + return image.getTextureStorageType(); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.images.AbstractGLImage#stageTexture() + */ + @Override + public boolean stageTexture() throws VizException { + return image.stageTexture(); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.images.AbstractGLImage#loadTexture(javax + * .media.opengl.GLContext) + */ + @Override + public void loadTexture(GL gl) throws VizException { + image.loadTexture(gl); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.images.AbstractGLImage#target(com.raytheon.uf + * .viz.core.IGraphicsTarget) + */ + @Override + public void target(IGraphicsTarget target) throws VizException { + image.target(target); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.images.AbstractGLImage#getStatus() + */ + @Override + public Status getStatus() { + return image.getStatus(); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.images.AbstractGLImage#setStatus(com.raytheon + * .uf.viz.core.drawables.IImage.Status) + */ + @Override + public void setStatus(Status status) { + image.setStatus(status); + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.images.AbstractGLImage#usaAsFrameBuffer() + */ + @Override + public void usaAsFrameBuffer() throws VizException { + image.usaAsFrameBuffer(); + } + +} diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLImage.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLImage.java index 0b335bee24..28d71155c4 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLImage.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLImage.java @@ -28,21 +28,20 @@ import java.util.Hashtable; import javax.media.jai.PlanarImage; import javax.media.opengl.GL; -import javax.media.opengl.GLContext; -import com.raytheon.uf.viz.core.VizApp; import com.raytheon.uf.viz.core.data.IRenderedImageCallback; +import com.raytheon.uf.viz.core.drawables.ext.IImagingExtension; import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.viz.core.gl.IGLTarget; import com.raytheon.viz.core.gl.internal.cache.IImageCacheable; import com.raytheon.viz.core.gl.internal.cache.ImageCache; import com.raytheon.viz.core.gl.internal.cache.ImageCache.CacheType; import com.sun.opengl.util.texture.Texture; +import com.sun.opengl.util.texture.TextureCoords; import com.sun.opengl.util.texture.TextureData; import com.sun.opengl.util.texture.TextureIO; /** - * Represents a GL "Image" + * Represents a GL "RenderedImage" * *
  * 
@@ -72,8 +71,8 @@ public class GLImage extends AbstractGLImage implements IImageCacheable {
 
     protected int size;
 
-    public GLImage(IRenderedImageCallback preparer, IGLTarget target) {
-        super(target);
+    public GLImage(IRenderedImageCallback preparer, Class extensionClass) {
+        super(extensionClass);
         theTexture = null;
         this.imagePreparer = preparer;
     }
@@ -113,15 +112,8 @@ public class GLImage extends AbstractGLImage implements IImageCacheable {
 
             if (getStatus() == Status.LOADED) {
                 if (theTexture != null) {
-                    final Texture tex = theTexture;
+                    theTexture.dispose();
                     theTexture = null;
-                    VizApp.runAsync(new Runnable() {
-                        @Override
-                        public void run() {
-                            theTarget.makeContextCurrent();
-                            tex.dispose();
-                        }
-                    });
                 }
                 if (theStagedData != null) {
                     setStatus(Status.STAGED);
@@ -134,17 +126,20 @@ public class GLImage extends AbstractGLImage implements IImageCacheable {
 
     }
 
-    /**
-     * Stage the texture in memory
+    /*
+     * (non-Javadoc)
      * 
-     * The texture will then be ready to load into the video card
-     * 
-     * @throws VizException
+     * @see com.raytheon.viz.core.gl.images.AbstractGLImage#stageTexture()
      */
-    public void stageTexture() throws VizException {
-        generateTextureData();
-        ImageCache.getInstance(CacheType.MEMORY).put(this); // Add to
-        // memory
+    @Override
+    public boolean stageTexture() throws VizException {
+        if (theImage == null) {
+            theImage = imagePreparer.getImage();
+        }
+        boolean rval = generateTextureData(theImage);
+        // Add to memory cache
+        ImageCache.getInstance(CacheType.MEMORY).put(this);
+        return rval;
     }
 
     /**
@@ -154,7 +149,7 @@ public class GLImage extends AbstractGLImage implements IImageCacheable {
      *            the OpenGL context
      * @throws VizException
      */
-    public void loadTexture(GLContext ctx) throws VizException {
+    public void loadTexture(GL gl) throws VizException {
         synchronized (this) {
             Texture tex = TextureIO.newTexture(theStagedData);
 
@@ -186,9 +181,9 @@ public class GLImage extends AbstractGLImage implements IImageCacheable {
      * @param rendImg
      *            the rendered image to load
      */
-    private void generateTextureData(RenderedImage rendImg) {
+    private boolean generateTextureData(RenderedImage rendImg) {
         if (rendImg == null) {
-            return;
+            return false;
         }
 
         if (rendImg instanceof BufferedImage) {
@@ -205,18 +200,7 @@ public class GLImage extends AbstractGLImage implements IImageCacheable {
 
         this.size = rendImg.getHeight() * rendImg.getWidth() * 4
                 * rendImg.getColorModel().getNumColorComponents();
-        setStatus(Status.STAGED);
-    }
-
-    private void generateTextureData() {
-        if (theImage == null) {
-            try {
-                theImage = imagePreparer.getImage();
-            } catch (VizException e) {
-                e.printStackTrace();
-            }
-        }
-        generateTextureData(theImage);
+        return true;
     }
 
     /**
@@ -259,6 +243,9 @@ public class GLImage extends AbstractGLImage implements IImageCacheable {
      * @see com.raytheon.viz.core.drawables.IImage#getHeight()
      */
     public int getHeight() {
+        if (theImage != null) {
+            return theImage.getHeight();
+        }
         if (theTexture != null) {
             return theTexture.getImageHeight();
         }
@@ -272,6 +259,9 @@ public class GLImage extends AbstractGLImage implements IImageCacheable {
      * @see com.raytheon.viz.core.drawables.IImage#getWidth()
      */
     public int getWidth() {
+        if (theImage != null) {
+            return theImage.getWidth();
+        }
         if (theTexture != null) {
             return theTexture.getImageWidth();
         }
@@ -314,4 +304,14 @@ public class GLImage extends AbstractGLImage implements IImageCacheable {
         return getTexture().getTextureObject();
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.raytheon.viz.core.gl.images.AbstractGLImage#getTextureCoords()
+     */
+    @Override
+    public TextureCoords getTextureCoords() {
+        return theTexture.getImageTexCoords();
+    }
+
 }
diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLSingleColorImage.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLSingleColorImage.java
new file mode 100644
index 0000000000..ce8361b49d
--- /dev/null
+++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/images/GLSingleColorImage.java
@@ -0,0 +1,70 @@
+/**
+ * This software was developed and / or modified by Raytheon Company,
+ * pursuant to Contract DG133W-05-CQ-1067 with the US Government.
+ * 
+ * U.S. EXPORT CONTROLLED TECHNICAL DATA
+ * This software product contains export-restricted data whose
+ * export/transfer/disclosure is restricted by U.S. law. Dissemination
+ * to non-U.S. persons whether in the United States or abroad requires
+ * an export license or other authorization.
+ * 
+ * Contractor Name:        Raytheon Company
+ * Contractor Address:     6825 Pine Street, Suite 340
+ *                         Mail Stop B8
+ *                         Omaha, NE 68106
+ *                         402.291.0100
+ * 
+ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
+ * further licensing information.
+ **/
+package com.raytheon.viz.core.gl.images;
+
+import org.eclipse.swt.graphics.RGB;
+
+import com.raytheon.uf.viz.core.drawables.ext.ISingleColorImageExtension.ISingleColorImage;
+import com.raytheon.viz.core.gl.internal.ext.GLSingleColorImageExtension;
+
+/**
+ * GL Image object that all non-zero values should be mapped to a single color
+ * value
+ * 
+ * 
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 15, 2011            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public class GLSingleColorImage extends GLDelegateImage + implements ISingleColorImage { + + private RGB color; + + public GLSingleColorImage(AbstractGLImage image, RGB color) { + super(image, GLSingleColorImageExtension.class); + this.color = color; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.ext.ISingleColorImageExtension + * .ISingleColorImage#setColor(org.eclipse.swt.graphics.RGB) + */ + @Override + public void setColor(RGB color) { + this.color = color; + } + + public RGB getColor() { + return color; + } + +} \ No newline at end of file diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/FontFactory.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/FontFactory.java index 7a9cb7ab94..5db3be2865 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/FontFactory.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/FontFactory.java @@ -54,7 +54,8 @@ import com.raytheon.viz.core.gl.IGLFont; */ public class FontFactory { - private static final transient IUFStatusHandler statusHandler = UFStatus.getHandler(FontFactory.class); + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(FontFactory.class); public static final String DEFAULT_FONT_ID = "com.raytheon.uf.viz.core.defaultFont"; @@ -85,7 +86,7 @@ public class FontFactory { * @param target * @return The font to use, never null */ - public IGLFont getFont(String fontId, GLTarget target) { + public IGLFont getFont(String fontId) { if (!registry.hasValueFor(fontId)) { statusHandler.handle(Priority.PROBLEM, "No font registered with id: " + fontId); @@ -108,7 +109,7 @@ public class FontFactory { styles.add(IFont.Style.ITALIC); } - IGLFont font = new GLFont(target, name, size, + IGLFont font = new GLFont(name, size, styles.toArray(new IFont.Style[styles.size()])); if (fontId.equals(DEFAULT_FONT_ID)) { font = new UnmodifiableGLFont(font); diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLAbstractView.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLAbstractView.java index 386a3d14dd..9efb3dd254 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLAbstractView.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLAbstractView.java @@ -112,7 +112,7 @@ public abstract class GLAbstractView implements IView, Cloneable { public void setupView(IGraphicsTarget target) { IGLTarget glTarget = asIGLTarget(target); - glTarget.makeContextCurrent(); + boolean release = glTarget.makeContextCurrent(); glTarget.getGl().glMatrixMode(GL.GL_PROJECTION); glTarget.getGl().glLoadIdentity(); setProjectionMatrix(glTarget); @@ -126,6 +126,9 @@ public abstract class GLAbstractView implements IView, Cloneable { setViewArea(glTarget); // glTarget.setupClippingPlane(getClippingPlanes()); + if (release) { + glTarget.releaseContext(); + } } protected IGLTarget asIGLTarget(IGraphicsTarget target) { diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLFont.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLFont.java index 5ae746f4df..d5723118fd 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLFont.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLFont.java @@ -67,14 +67,11 @@ public class GLFont implements IGLFont { private boolean scaleFont = true; - private GLTarget target; - public GLFont() { ; } - public GLFont(GLTarget target, File font, float fontSize, Style[] styles) { - this.target = target; + public GLFont(File font, float fontSize, Style[] styles) { try { this.font = Font.createFont(Font.TRUETYPE_FONT, font).deriveFont( fontSize); @@ -98,9 +95,7 @@ public class GLFont implements IGLFont { this.textRenderer = TextRendererCache.getRenderer(this.font); } - public GLFont(GLTarget target, String fontName, float fontSize, - Style[] styles) { - this.target = target; + public GLFont(String fontName, float fontSize, Style[] styles) { this.fontName = fontName; this.currentFontSize = this.fontSize = fontSize; this.styles = styles; @@ -172,9 +167,9 @@ public class GLFont implements IGLFont { GLFont newFont = null; if (this.fontFile != null) { // File based construction - newFont = new GLFont(this.target, this.fontFile, size, styles); + newFont = new GLFont(this.fontFile, size, styles); } else { - newFont = new GLFont(this.target, this.fontName, size, styles); + newFont = new GLFont(this.fontName, size, styles); } return newFont; @@ -259,16 +254,6 @@ public class GLFont implements IGLFont { this.scaleFont = scaleFont; } - /* - * (non-Javadoc) - * - * @see com.raytheon.viz.core.gl.IGLFont#getTarget() - */ - @Override - public GLTarget getTarget() { - return target; - } - /* * (non-Javadoc) * @@ -278,15 +263,11 @@ public class GLFont implements IGLFont { public void disposeInternal() { if (!disposed) { if (this.textRenderer != null) { - boolean release = target.makeContextCurrent(); TextRendererCache.releaseRenderer(this.font); this.textRenderer = null; disposed = true; - if (release) { - target.releaseContext(); - } } } } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLMesh2DStrips.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLMesh2DStrips.java index 0cd09510f8..a97b23326e 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLMesh2DStrips.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLMesh2DStrips.java @@ -77,9 +77,9 @@ public class GLMesh2DStrips extends AbstractGLMesh { // get dx and dy for texture points double dXWorld = worldWidth / (key.horizontalDivisions); - double dYWorld = worldHeight / (key.verticalDivisions - 1); + double dYWorld = worldHeight / (key.verticalDivisions); - double[][][] worldCoordinates = new double[key.horizontalDivisions][2 * key.verticalDivisions][2]; + double[][][] worldCoordinates = new double[key.horizontalDivisions][2 * (key.verticalDivisions + 1)][2]; int width = worldCoordinates.length; int height = worldCoordinates[0].length; @@ -136,60 +136,63 @@ public class GLMesh2DStrips extends AbstractGLMesh { return worldCoordinates; } + private static final int MIN_HORZ_DIVS = 1; + + private static final int MIN_VERT_DIVS = 1; + @Override protected SharedCoordinateKey generateKey(ImageTile tile, MathTransform mt) { try { - int maxHorzDiv = tile.rect.width / 4; - int maxVertDiv = tile.rect.height / 4; + int maxHorzDiv = Math.max(tile.rect.width / 4, MIN_HORZ_DIVS); + int maxVertDiv = Math.max(tile.rect.height / 4, MIN_VERT_DIVS); + Envelope envelope = tile.envelope; double[] tl = { envelope.getMinX(), envelope.getMaxY() }; double[] tr = { envelope.getMaxX(), envelope.getMaxY() }; double[] bl = { envelope.getMinX(), envelope.getMinY() }; double[] br = { envelope.getMaxX(), envelope.getMinY() }; - // start off estimating the number of horzintal divisions by using - // only the top and bottom. - int horzDivTop = 1 + getNumDivisions(tl, null, tr, null, - maxHorzDiv, mt); - int horzDivBot = 1 + getNumDivisions(bl, null, br, null, - maxHorzDiv, mt); - int horzDiv = Math.max(horzDivTop, horzDivBot); + + int horzDiv = MIN_HORZ_DIVS; + if (maxHorzDiv > MIN_HORZ_DIVS) { + // start off estimating the number of horzintal divisions by + // using only the top and bottom. + int horzDivTop = getNumDivisions(tl, null, tr, null, + maxHorzDiv, mt); + int horzDivBot = getNumDivisions(bl, null, br, null, + maxHorzDiv, mt); + horzDiv = Math.max(horzDivTop, horzDivBot); + } // Next get the number of vertical divisions by finding the maximum // needed in every horizontal row. - int vertDiv = 2; - for (int i = 1; i <= horzDiv; i++) { - double topX = tl[0] + (tr[0] - tl[0]) * i / horzDiv; - double topY = tl[1] + (tr[1] - tl[1]) * i / horzDiv; - double botX = bl[0] + (br[0] - bl[0]) * i / horzDiv; - double botY = bl[1] + (br[1] - bl[1]) * i / horzDiv; - double[] top = { topX, topY }; - double[] bot = { botX, botY }; - int vertDivTest = 1 + getNumDivisions(top, null, bot, null, - maxVertDiv, mt); - vertDiv = Math.max(vertDiv, vertDivTest); - if (vertDiv >= maxVertDiv) { - vertDiv = maxVertDiv; - break; + int vertDiv = MIN_VERT_DIVS; + if (maxVertDiv > MIN_VERT_DIVS) { + for (int i = 1; i <= horzDiv; i++) { + double topX = tl[0] + (tr[0] - tl[0]) * i / horzDiv; + double topY = tl[1] + (tr[1] - tl[1]) * i / horzDiv; + double botX = bl[0] + (br[0] - bl[0]) * i / horzDiv; + double botY = bl[1] + (br[1] - bl[1]) * i / horzDiv; + double[] top = { topX, topY }; + double[] bot = { botX, botY }; + int vertDivTest = getNumDivisions(top, null, bot, null, + maxVertDiv, mt); + vertDiv = Math.max(vertDiv, vertDivTest); } } + // Now fill in the actual number of horzontal divisions incase // distortion increases towards the middle. - for (int i = 2; i < vertDiv; i++) { + for (int i = MIN_VERT_DIVS; i < vertDiv; i++) { double leftX = bl[0] + (tl[0] - bl[0]) * i / vertDiv; double leftY = bl[1] + (tl[1] - bl[1]) * i / vertDiv; double rightX = br[0] + (tr[0] - br[0]) * i / vertDiv; double rightY = br[1] + (tr[1] - br[1]) * i / vertDiv; double[] left = { leftX, leftY }; double[] right = { rightX, rightY }; - int horzDivTest = 1 + getNumDivisions(left, null, right, null, + int horzDivTest = getNumDivisions(left, null, right, null, maxHorzDiv, mt); horzDiv = Math.max(horzDiv, horzDivTest); - if (horzDiv >= maxHorzDiv) { - horzDiv = maxHorzDiv; - break; - } } - horzDiv = Math.max(2, horzDiv); - vertDiv = Math.max(2, vertDiv); + return new SharedCoordinateKey(vertDiv, horzDiv); } catch (Exception e) { statusHandler diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java index 5162894458..fac418e7ba 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java @@ -32,7 +32,6 @@ import java.nio.IntBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -40,10 +39,6 @@ import java.util.Map.Entry; import java.util.Set; import javax.media.opengl.GL; -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLContext; -import javax.media.opengl.GLDrawableFactory; -import javax.media.opengl.GLPbuffer; import javax.media.opengl.glu.GLU; import javax.media.opengl.glu.GLUquadric; import javax.vecmath.Vector3d; @@ -72,21 +67,16 @@ import com.raytheon.uf.viz.core.DrawableLine; import com.raytheon.uf.viz.core.DrawableString; import com.raytheon.uf.viz.core.IExtent; import com.raytheon.uf.viz.core.IGraphicsTarget; -import com.raytheon.uf.viz.core.IMesh; import com.raytheon.uf.viz.core.PixelCoverage; -import com.raytheon.uf.viz.core.PixelExtent; import com.raytheon.uf.viz.core.VizConstants; import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback; import com.raytheon.uf.viz.core.data.IColormappedDataPreparer; import com.raytheon.uf.viz.core.data.IDataPreparer; import com.raytheon.uf.viz.core.data.IImageDataPreparer; import com.raytheon.uf.viz.core.data.IRenderedImageCallback; -import com.raytheon.uf.viz.core.data.prep.CMDataPreparerManager; import com.raytheon.uf.viz.core.data.resp.NumericImageData; import com.raytheon.uf.viz.core.drawables.ColorMapLoader; import com.raytheon.uf.viz.core.drawables.ColorMapParameters; -import com.raytheon.uf.viz.core.drawables.ColorMapParameters.LabelEntry; -import com.raytheon.uf.viz.core.drawables.IColormappedImage; import com.raytheon.uf.viz.core.drawables.IDescriptor; import com.raytheon.uf.viz.core.drawables.IFont; import com.raytheon.uf.viz.core.drawables.IFont.Style; @@ -95,29 +85,28 @@ import com.raytheon.uf.viz.core.drawables.IRenderableDisplay; import com.raytheon.uf.viz.core.drawables.IShadedShape; import com.raytheon.uf.viz.core.drawables.IWireframeShape; import com.raytheon.uf.viz.core.drawables.PaintProperties; -import com.raytheon.uf.viz.core.drawables.SingleColorImage; +import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension.IGraphicsExtensionInterface; import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtensionManager; +import com.raytheon.uf.viz.core.drawables.ext.IImagingExtension; import com.raytheon.uf.viz.core.drawables.ext.IOffscreenRenderingExtension; import com.raytheon.uf.viz.core.drawables.ext.colormap.IColormappedImageExtension; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.geom.PixelCoordinate; import com.raytheon.uf.viz.core.preferences.PreferenceConstants; +import com.raytheon.viz.core.gl.GLContextBridge; +import com.raytheon.viz.core.gl.GLDisposalManager; import com.raytheon.viz.core.gl.IGLFont; import com.raytheon.viz.core.gl.IGLTarget; -import com.raytheon.viz.core.gl.TextureLoaderJob; -import com.raytheon.viz.core.gl.glsl.AbstractShaderLoader; import com.raytheon.viz.core.gl.glsl.GLSLFactory; import com.raytheon.viz.core.gl.glsl.GLShaderProgram; import com.raytheon.viz.core.gl.images.AbstractGLImage; import com.raytheon.viz.core.gl.images.GLColormappedImage; import com.raytheon.viz.core.gl.images.GLImage; -import com.raytheon.viz.core.gl.internal.cache.IImageCacheable; -import com.raytheon.viz.core.gl.internal.cache.ImageCache; -import com.raytheon.viz.core.gl.internal.cache.ImageCache.CacheType; +import com.raytheon.viz.core.gl.internal.ext.GLColormappedImageExtension; +import com.raytheon.viz.core.gl.internal.ext.GLDefaultImagingExtension; +import com.raytheon.viz.core.gl.objects.GLTextureObject; import com.sun.opengl.util.Screenshot; import com.sun.opengl.util.j2d.TextRenderer; -import com.sun.opengl.util.texture.Texture; -import com.sun.opengl.util.texture.TextureCoords; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.LinearRing; @@ -173,8 +162,6 @@ public class GLTarget implements IGLTarget { protected static final int maxColorMapCacheSize = com.raytheon.viz.core.gl.Activator .getDefault().getPreferenceStore().getInt("colorMapCacheSize"); - protected static GLTarget currentGl; - /** The gl context */ protected final GL gl; @@ -182,7 +169,7 @@ public class GLTarget implements IGLTarget { protected final GLCanvas theCanvas; /** the GLContext */ - protected final GLContext theContext; + protected final GLContextBridge theContext; /** Has a texure load occurred during a draw operation */ protected boolean hasLoadedTextureOnLoop = false; @@ -210,18 +197,16 @@ public class GLTarget implements IGLTarget { /** The current Zoom level */ protected double theCurrentZoom; - /** Display a built-in colorbar when displaying colormapped images */ - protected boolean useBuiltinColorbar = false; - /** The GLU object */ protected final GLU glu = new GLU(); - protected static final Map loadedColorMaps = new LinkedHashMap() { + protected static final Map loadedColorMaps = new LinkedHashMap() { private static final long serialVersionUID = 1L; @Override - protected boolean removeEldestEntry(Entry eldest) { + protected boolean removeEldestEntry( + Entry eldest) { if (size() > maxColorMapCacheSize) { handleRemove(eldest.getValue()); return true; @@ -231,15 +216,15 @@ public class GLTarget implements IGLTarget { } @Override - public Integer remove(Object key) { - Integer id = super.remove(key); + public GLTextureObject remove(Object key) { + GLTextureObject id = super.remove(key); handleRemove(id); return id; } - private void handleRemove(Integer value) { - if (value != null) { - currentGl.disposeLuminanceTexture(value, 0); + private void handleRemove(GLTextureObject value) { + if (value != null && value.isValid()) { + value.dispose(); } } @@ -257,12 +242,6 @@ public class GLTarget implements IGLTarget { protected final float textMagnification; - protected final GLContext sharedContext; - - protected ColorMapParameters lastColormapUsed; - - protected double lastAlphaUsed = 1.0f; - protected final RGB DEFAULT_LABEL_COLOR = new RGB(255, 255, 255); protected Listener canvasResizeListener; @@ -311,14 +290,11 @@ public class GLTarget implements IGLTarget { theCanvas = (GLCanvas) canvas; theCanvas.setCurrent(); - theContext = GLDrawableFactory.getFactory().createExternalGLContext(); + theContext = new GLContextBridge(theCanvas); - sharedContext = theContext; // extDrawable.createContext(theContext); - // sharedContext.makeCurrent(); + theContext.makeContextCurrent(); - makeContextCurrent(); - - gl = theContext.getGL(); + gl = GLU.getCurrentGL(); theWidth = width; theHeight = width; @@ -359,22 +335,11 @@ public class GLTarget implements IGLTarget { public GLTarget(float width, float height) throws VizException { theCanvas = null; canvasSize = new Rectangle(0, 0, (int) width, (int) height); - GLCapabilities glCap = new GLCapabilities(); - if (!GLDrawableFactory.getFactory().canCreateGLPbuffer()) { - throw new VizException( - "Graphics card does not support GLPbuffer and " - + "therefore does not support offscreen rendering."); - } - GLPbuffer buf = GLDrawableFactory.getFactory().createGLPbuffer(glCap, - null, (int) width, (int) height, null); - theContext = buf.createContext(null); + theContext = new GLContextBridge((int) width, (int) height); - sharedContext = theContext; - - makeContextCurrent(); - - gl = theContext.getGL(); + theContext.makeContextCurrent(); + gl = GLU.getCurrentGL(); theWidth = width; theHeight = width; @@ -441,7 +406,6 @@ public class GLTarget implements IGLTarget { display.setup(this); hasLoadedTextureOnLoop = false; - lastColormapUsed = null; synchronized (this) { if (refreshCount > 0) { refreshCount--; @@ -473,7 +437,6 @@ public class GLTarget implements IGLTarget { */ @Override public void clearClippingPlane() { - this.makeContextCurrent(); gl.glDisable(GL.GL_CLIP_PLANE0); gl.glDisable(GL.GL_CLIP_PLANE1); gl.glDisable(GL.GL_CLIP_PLANE2); @@ -501,7 +464,7 @@ public class GLTarget implements IGLTarget { @Override public IWireframeShape createWireframeShape(boolean mutableFlag, GeneralGridGeometry geom) { - return new GLWireframeShape2D(this, geom, mutableFlag); + return new GLWireframeShape2D(geom, mutableFlag); } /* @@ -519,7 +482,7 @@ public class GLTarget implements IGLTarget { return new GLWireframeShape(null, geom, mutable, simplificationLevel, spatialChopFlag, extent); } else { - return new GLWireframeShape2D(this, geom, mutable); + return new GLWireframeShape2D(geom, mutable); } } @@ -532,7 +495,7 @@ public class GLTarget implements IGLTarget { @Override public IWireframeShape createWireframeShape(boolean mutable, IDescriptor descriptor) { - return new GLWireframeShape2D(this, descriptor, mutable); + return new GLWireframeShape2D(descriptor, mutable); } /* @@ -548,7 +511,7 @@ public class GLTarget implements IGLTarget { return new GLWireframeShape(descriptor, mutable, simplificationLevel); } else { - return new GLWireframeShape2D(this, descriptor, mutable); + return new GLWireframeShape2D(descriptor, mutable); } } @@ -567,7 +530,7 @@ public class GLTarget implements IGLTarget { return new GLWireframeShape(descriptor, null, mutable, simplificationLevel, spatialChopFlag, extent); } else { - return new GLWireframeShape2D(this, descriptor, mutable); + return new GLWireframeShape2D(descriptor, mutable); } } @@ -578,7 +541,7 @@ public class GLTarget implements IGLTarget { */ @Override public void dispose() { - makeContextCurrent(); + if (defaultFont != null) { defaultFont.disposeInternal(); } @@ -586,24 +549,14 @@ public class GLTarget implements IGLTarget { colorbarFont.disposeInternal(); } - theContext.release(); - theContext.destroy(); + theContext.destroyContext(); + if (theCanvas != null && theCanvas.isDisposed() == false) { theCanvas.removeListener(SWT.Resize, this.canvasResizeListener); } - lastColormapUsed = null; extensionManager.dispose(); } - public void disposeLuminanceTexture(int id, int pboID) { - makeContextCurrent(); - - gl.glDeleteTextures(1, new int[] { id }, 0); - if (pboID > 0) { - gl.glDeleteBuffers(1, new int[] { pboID }, 0); - } - } - /** * Dispose a vbo * @@ -661,48 +614,6 @@ public class GLTarget implements IGLTarget { drawCircle(circle); } - protected void drawColorbar(ColorMapParameters colorMapParameters) - throws VizException { - if (GLTarget.loadedColorMaps == null) { - return; - } - - this.clearClippingPlane(); - this.makeContextCurrent(); - this.pushGLState(); - try { - - double x1 = this.viewExtent.getMinX(); - double x2 = x1 + ((this.viewExtent.getMaxX() - x1) / 2.0); - double y1 = this.viewExtent.getMinY(); - double y2 = y1 + ((x2 - x1) / 20.0); - - PixelExtent pixelExtent = new PixelExtent(x1, x2, y1, y2); - this.drawColorRamp(colorMapParameters.getColorMap(), pixelExtent, - (float) this.lastAlphaUsed); - - double yPos = y1 + (y2 - y1) / 2.0; - double zPos = 0; // draw the colorbar on the plane z = 0 - - List labels = colorMapParameters.getLabels(); - if (labels != null) { - for (LabelEntry label : labels) { - double xPos = x1 + ((x2 - x1) * label.getLocation()); - - String s = label.getText(); - - this.drawString(this.colorbarFont, s, xPos, yPos, zPos, - TextStyle.BLANKED, DEFAULT_LABEL_COLOR, - IGraphicsTarget.HorizontalAlignment.CENTER, - IGraphicsTarget.VerticalAlignment.MIDDLE, null); - } - } - - } finally { - this.popGLState(); - } - } - /* * (non-Javadoc) * @@ -726,16 +637,15 @@ public class GLTarget implements IGLTarget { @Override public void drawColorRamp(DrawableColorMap drawableColorMap) throws VizException { - this.makeContextCurrent(); this.pushGLState(); try { - final ColorMapParameters colorMapParams = drawableColorMap + ColorMapParameters colorMapParams = drawableColorMap .getColorMapParams(); IExtent pixelExtent = drawableColorMap.extent; - final float blendAlpha = drawableColorMap.alpha; - final float brightness = drawableColorMap.brightness; - final float contrast = drawableColorMap.contrast; - final float logFactor = drawableColorMap.getColorMapParams() + float blendAlpha = drawableColorMap.alpha; + float brightness = drawableColorMap.brightness; + float contrast = drawableColorMap.contrast; + float logFactor = drawableColorMap.getColorMapParams() .getLogFactor(); double x1 = pixelExtent.getMinX(); @@ -743,16 +653,23 @@ public class GLTarget implements IGLTarget { double y1 = pixelExtent.getMinY(); double y2 = pixelExtent.getMaxY(); - Integer i = getColorMapTexture(colorMapParams); + GLTextureObject i = getColorMapTexture(colorMapParams); GLColormappedImage alphaMaskTexture = null; if (colorMapParams.isUseMask() && capabilities.cardSupportsShaders) { - byte[] mask = colorMapParams.getAlphaMask(); - alphaMaskTexture = (GLColormappedImage) initializeRaster( - CMDataPreparerManager.getDataPreparer(mask, - new java.awt.Rectangle(0, 0, mask.length, 1), - new int[] { mask.length, 1 }), colorMapParams); - alphaMaskTexture.stageTexture(); + final byte[] mask = colorMapParams.getAlphaMask(); + alphaMaskTexture = getExtension( + GLColormappedImageExtension.class).initializeRaster( + new IColorMapDataRetrievalCallback() { + @Override + public ColorMapData getColorMapData() + throws VizException { + return new ColorMapData(ByteBuffer.wrap(mask), + new int[] { mask.length, 1 }); + } + + }, colorMapParams); + alphaMaskTexture.stage(); alphaMaskTexture.target(this); } @@ -767,7 +684,7 @@ public class GLTarget implements IGLTarget { gl.glEnable(GL.GL_TEXTURE_1D); gl.glActiveTexture(GL.GL_TEXTURE0); - gl.glBindTexture(GL.GL_TEXTURE_1D, i); + i.bind(gl, GL.GL_TEXTURE_1D); if (drawableColorMap.interpolate) { gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER, @@ -790,36 +707,24 @@ public class GLTarget implements IGLTarget { GLShaderProgram program = null; if (capabilities.cardSupportsShaders) { - synchronized (GLSLFactory.class) { - GLSLFactory.registerProgramLoader("colormap", - new AbstractShaderLoader() { - @Override - public void loadData(IGLTarget target, - GLShaderProgram program, IImage image, - PaintProperties paintProps) - throws VizException { - program.setUniform("alphaVal", blendAlpha); - program.setUniform("brightness", brightness); - program.setUniform("contrast", contrast); - program.setUniform("colorMap", 0); - program.setUniform("logFactor", logFactor); - program.setUniform("alphaMask", 1); - program.setUniform("applyMask", - colorMapParams.isUseMask() ? 1 : 0); - program.setUniform("bkgrndRed", - backgroundColor.red / 255.0f); - program.setUniform("bkgrndGreen", - backgroundColor.green / 255.0f); - program.setUniform("bkgrndBlue", - backgroundColor.blue / 255.0f); - } - }); - program = GLSLFactory.getInstance().getShaderProgram(this, - null, "colormap"); - if (program != null) { - program.startShader(); - program.loadData(this, null, null); - } + program = GLSLFactory.getInstance().getShaderProgram(this, + null, "colormap"); + if (program != null) { + program.startShader(); + program.setUniform("alphaVal", blendAlpha); + program.setUniform("brightness", brightness); + program.setUniform("contrast", contrast); + program.setUniform("colorMap", 0); + program.setUniform("logFactor", logFactor); + program.setUniform("alphaMask", 1); + program.setUniform("applyMask", + colorMapParams.isUseMask() ? 1 : 0); + program.setUniform("bkgrndRed", + backgroundColor.red / 255.0f); + program.setUniform("bkgrndGreen", + backgroundColor.green / 255.0f); + program.setUniform("bkgrndBlue", + backgroundColor.blue / 255.0f); } gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, @@ -923,11 +828,6 @@ public class GLTarget implements IGLTarget { } } - private float log(float f) { - // TODO Auto-generated method stub - return 0; - } - /* * (non-Javadoc) * @@ -1040,7 +940,6 @@ public class GLTarget implements IGLTarget { */ @Override public void drawLine(DrawableLine... lines) throws VizException { - this.makeContextCurrent(); this.pushGLState(); try { RGB prevColor = null; @@ -1138,428 +1037,41 @@ public class GLTarget implements IGLTarget { * (non-Javadoc) * * @see - * com.raytheon.viz.core.gl.IGLTarget#drawRaster(com.raytheon.uf.viz.core - * .drawables.IImage, com.raytheon.uf.viz.core.PixelCoverage, - * com.raytheon.uf.viz.core.drawables.PaintProperties, java.lang.String) - */ - @Override - public boolean drawRaster(IImage image, PixelCoverage extent, - PaintProperties paintProps, String shaderProgram) - throws VizException { - return drawRaster(image, extent, paintProps, RasterMode.SYNCHRONOUS, - shaderProgram); - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.viz.core.gl.IGLTarget#drawRaster(com.raytheon.uf.viz.core - * .drawables.IImage, com.raytheon.uf.viz.core.PixelCoverage, + * com.raytheon.uf.viz.core.drawables.ext.IImagingExtension#drawRasters( * com.raytheon.uf.viz.core.drawables.PaintProperties, - * com.raytheon.uf.viz.core.IGraphicsTarget.RasterMode, java.lang.String) - */ - @Override - public boolean drawRaster(IImage argImage, PixelCoverage extent, - PaintProperties paintProps, RasterMode mode, String shaderProgram) - throws VizException { - DrawableImage image = new DrawableImage(argImage, extent); - image.setMode(mode); - return drawRasters(shaderProgram, paintProps, image); - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.IGraphicsTarget#drawRaster(com.raytheon.uf.viz - * .core.drawables.PaintProperties, * com.raytheon.uf.viz.core.DrawableImage[]) */ @Override public boolean drawRasters(PaintProperties paintProps, DrawableImage... images) throws VizException { - return drawRasters("raster", paintProps, images); - } - - public boolean drawRasters(String shaderProgram, - PaintProperties paintProps, DrawableImage... images) - throws VizException { - gl.glGetError(); - int continues = 0; - int imgErrors = 0; - Set errorMsgs = new HashSet(); - List notDrawn = new ArrayList(); - - this.makeContextCurrent(); - this.pushGLState(); - try { - gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL); - - Texture tex = null; - int texId = -1; - GLShaderProgram program = null; - boolean attemptedToLoadShader = false; - int lastTextureType = -1; - // Only kept track for GLImage types - Boolean lastInterpState = null; - - for (DrawableImage di : images) { - IImage argImage = di.getImage(); - IImage image = argImage; - PixelCoverage extent = di.getCoverage(); - RasterMode mode = di.getMode(); - - if (argImage instanceof SingleColorImage) { - image = ((SingleColorImage) argImage).getWrappedImage(); - } - - if (!(image instanceof AbstractGLImage)) { - ++continues; - ++imgErrors; - errorMsgs.add("Can only draw GLImages on GLTarget"); - notDrawn.add(di); - continue; - } - - final AbstractGLImage glImage = (AbstractGLImage) image; - - synchronized (glImage) { - if (glImage.getStatus() == IImage.Status.UNLOADED - || glImage.getStatus() == IImage.Status.LOADING) { - glImage.setStatus(IImage.Status.LOADING); - if (mode == RasterMode.ASYNCHRONOUS) { - stage(glImage); - } else if (mode == RasterMode.SYNCHRONOUS) { - glImage.stageTexture(); - } - } - - if (glImage.getStatus() == IImage.Status.STAGED) { - glImage.target(this); - } - - if (glImage.getStatus() != IImage.Status.LOADED) { - ++continues; - notDrawn.add(di); - continue; - } - - ColorMapParameters usedColorMapParameters = null; - int textureType = glImage.getTextureStorageType(); - if (image instanceof GLColormappedImage) { - texId = ((GLColormappedImage) image).getTextureid(); - } else if (image instanceof GLImage) { - tex = ((GLImage) glImage).getTexture(); - } - - if (tex == null && texId <= 0) { - errorMsgs.add("Texture not loaded"); - continues++; - notDrawn.add(di); - continue; - } - - if (lastTextureType != textureType) { - if (lastTextureType != -1) { - gl.glDisable(lastTextureType); - } - gl.glEnable(textureType); - lastTextureType = textureType; - } - - GLColormappedImage alphaMaskTexture = null; - if (texId > 0) { - // First see if the colormap has been loaded - usedColorMapParameters = ((IColormappedImage) glImage) - .getColorMapParameters(); - if (usedColorMapParameters == null - || usedColorMapParameters.getColorMap() == null) { - ++continues; - continue; - } - - if (usedColorMapParameters.isUseMask() - && capabilities.cardSupportsShaders) { - byte[] mask = usedColorMapParameters.getAlphaMask(); - alphaMaskTexture = (GLColormappedImage) initializeRaster( - CMDataPreparerManager.getDataPreparer(mask, - new java.awt.Rectangle(0, 0, - mask.length, 1), new int[] { - mask.length, 1 }), - usedColorMapParameters); - alphaMaskTexture.stageTexture(); - alphaMaskTexture.target(this); - } - - // Get and stage colormap texture - Integer cmapTexture = getColorMapTexture(usedColorMapParameters); - - if (alphaMaskTexture != null) { - gl.glActiveTexture(GL.GL_TEXTURE2); - gl.glBindTexture( - alphaMaskTexture.getTextureStorageType(), - alphaMaskTexture.getTextureid()); - } - - gl.glActiveTexture(GL.GL_TEXTURE1); - gl.glBindTexture(GL.GL_TEXTURE_1D, cmapTexture); - - if (glImage.isInterpolated()) { - gl.glTexParameteri(GL.GL_TEXTURE_1D, - GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); - gl.glTexParameteri(GL.GL_TEXTURE_1D, - GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); - } else { - gl.glTexParameteri(GL.GL_TEXTURE_1D, - GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); - gl.glTexParameteri(GL.GL_TEXTURE_1D, - GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); - } - - gl.glActiveTexture(GL.GL_TEXTURE0); - gl.glBindTexture(textureType, texId); - - if (glImage.isInterpolated()) { - gl.glTexParameteri(textureType, - GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); - gl.glTexParameteri(textureType, - GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); - } else { - gl.glTexParameteri(textureType, - GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); - gl.glTexParameteri(textureType, - GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); - } - lastInterpState = null; - } else { - tex.bind(); - boolean interp = glImage.isInterpolated(); - if (lastInterpState == null - || lastInterpState != interp) { - lastInterpState = interp; - if (glImage.isInterpolated()) { - tex.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, - GL.GL_LINEAR); - tex.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, - GL.GL_LINEAR); - } else { - tex.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, - GL.GL_NEAREST); - tex.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, - GL.GL_NEAREST); - } - } - } - - if (capabilities.cardSupportsShaders) { - if (program == null && !attemptedToLoadShader) { - attemptedToLoadShader = true; - program = GLSLFactory - .getInstance() - .getShaderProgram(this, null, shaderProgram); - if (program != null) { - program.startShader(); - } - - gl.glTexEnvi(GL.GL_TEXTURE_ENV, - GL.GL_TEXTURE_ENV_MODE, GL.GL_ADD); - gl.glEnable(GL.GL_BLEND); - gl.glTexEnvi(GL.GL_TEXTURE_ENV, - GL.GL_TEXTURE_ENV_MODE, GL.GL_BLEND); - gl.glBlendFunc(GL.GL_SRC_ALPHA, - GL.GL_ONE_MINUS_SRC_ALPHA); - - gl.glColor4f(0.0f, 0.0f, 0.0f, - paintProps.getAlpha()); - } - - if (program != null) { - program.loadData(this, argImage, paintProps); - } - } else { - gl.glEnable(GL.GL_BLEND); - gl.glBlendFunc(GL.GL_SRC_ALPHA, - GL.GL_ONE_MINUS_SRC_ALPHA); - gl.glColor4f(1.0f, 1.0f, 1.0f, paintProps.getAlpha()); - } - - TextureCoords coords; - if (texId == -1) { - coords = tex.getImageTexCoords(); - } else { - coords = new TextureCoords(0, 1, 1, 0); - } - - drawCoverage(paintProps, extent, coords, 0); - - if (alphaMaskTexture != null) { - gl.glActiveTexture(GL.GL_TEXTURE2); - gl.glBindTexture( - alphaMaskTexture.getTextureStorageType(), 0); - } - - gl.glActiveTexture(GL.GL_TEXTURE1); - gl.glBindTexture(GL.GL_TEXTURE_1D, 0); - gl.glActiveTexture(GL.GL_TEXTURE0); - gl.glBindTexture(textureType, 0); - - if (usedColorMapParameters != null) { - this.lastColormapUsed = usedColorMapParameters; - } - this.lastAlphaUsed = paintProps.getAlpha(); - - if (alphaMaskTexture != null) { - alphaMaskTexture.dispose(); - } - - // Enable if you want to see mesh drawn - if (false) { - if (program != null) { - program.endShader(); - } - gl.glDisable(GL.GL_BLEND); - gl.glColor3f(0.0f, 1.0f, 0.0f); - gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE); - drawCoverage(paintProps, extent, new TextureCoords(0, - 1, 1, 0), 0.0f); - gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL); - gl.glEnable(GL.GL_BLEND); - if (program != null) { - program.startShader(); - } - - } - } + boolean rval = true; + List bulk = new ArrayList(); + Class lastExt = null; + for (DrawableImage di : images) { + IImage image = di.getImage(); + Class imageExt = image + .getExtensionClass(); + if (imageExt.equals(lastExt) == false && bulk.size() > 0) { + DrawableImage[] extImages = bulk.toArray(new DrawableImage[bulk + .size()]); + // Render what we have + IImagingExtension impl = getExtension(lastExt); + rval &= impl.drawRasters(paintProps, extImages); + bulk.clear(); } - if (lastTextureType != -1) { - gl.glDisable(lastTextureType); - } - - if (program != null) { - program.endShader(); - } - - gl.glPolygonMode(GL.GL_BACK, GL.GL_LINE); - - gl.glDisable(GL.GL_BLEND); - - for (DrawableImage di : notDrawn) { - if (drawTileBoundaries) { - gl.glColor3f(0.0f, 1.0f, 0.0f); - gl.glPolygonMode(GL.GL_FRONT, GL.GL_LINE); - drawCoverage(paintProps, di.getCoverage(), - new TextureCoords(0, 1, 1, 0), 0.0f); - gl.glPolygonMode(GL.GL_FRONT, GL.GL_FILL); - } - } - - } finally { - this.popGLState(); + bulk.add(di); + lastExt = imageExt; } - handleError(gl.glGetError()); - - IImageCacheable[] pending = ImageCache.getInstance(CacheType.TEXTURE) - .getImagesWaitingToDispose(); - - if (pending != null) { - for (IImageCacheable glI : pending) { - glI.disposeTexture(getGl()); - } + if (bulk.size() > 0) { + // Render what is left + IImagingExtension impl = getExtension(lastExt); + rval &= impl.drawRasters(paintProps, + bulk.toArray(new DrawableImage[bulk.size()])); } - // Delete any pending resources - pending = ImageCache.getInstance(CacheType.MEMORY) - .getImagesWaitingToDispose(); - - if (pending != null) { - for (IImageCacheable glI : pending) { - glI.disposeTextureData(); - } - } - - if (errorMsgs.size() > 0) { - throw new VizException("Error rendering " + errorMsgs.size() - + " images: " + errorMsgs); - } - - boolean allDrawn = continues == 0; - if (!allDrawn) { - this.setNeedsRefresh(true); - synchronized (this) { - if (refreshCount <= 1) { - refreshCount++; - } - } - } - - return allDrawn; - } - - public void drawCoverage(PaintProperties paintProps, PixelCoverage pc, - TextureCoords coords, float corrFactor) throws VizException { - if (pc == null) { - return; - } - this.pushGLState(); - try { - // gl.glPolygonMode(GL.GL_BACK, GL.GL_FILL); - // gl.glColor3d(1.0, 0.0, 0.0); - // } - - // boolean useNormals = false; - IMesh mesh = pc.getMesh(); - - // if mesh exists, use it - if (mesh != null) { - mesh.paint(this, paintProps); - } else if (coords != null) { - FloatBuffer fb = ByteBuffer.allocateDirect(4 * 5 * 4) - .order(ByteOrder.nativeOrder()).asFloatBuffer(); - - Coordinate ul = pc.getUl(); - Coordinate ur = pc.getUr(); - Coordinate lr = pc.getLr(); - Coordinate ll = pc.getLl(); - - fb.put(new float[] { coords.left() + corrFactor, - coords.bottom() + corrFactor }); - fb.put(new float[] { (float) ll.x, (float) ll.y, (float) ll.z }); - - fb.put(new float[] { coords.right() - corrFactor, - coords.bottom() + corrFactor }); - fb.put(new float[] { (float) lr.x, (float) lr.y, (float) lr.z }); - - fb.put(new float[] { coords.left() + corrFactor, - coords.top() - corrFactor }); - fb.put(new float[] { (float) ul.x, (float) ul.y, (float) ul.z }); - - fb.put(new float[] { coords.right() - corrFactor, - coords.top() - corrFactor }); - fb.put(new float[] { (float) ur.x, (float) ur.y, (float) ur.z }); - - // Clear error bit - gl.glGetError(); - - gl.glEnableClientState(GL.GL_VERTEX_ARRAY); - gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); - - gl.glInterleavedArrays(GL.GL_T2F_V3F, 0, fb.rewind()); - int error = gl.glGetError(); - if (error == GL.GL_NO_ERROR) { - gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); - } else { - handleError(error); - } - - gl.glDisableClientState(GL.GL_VERTEX_ARRAY); - gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY); - } - } finally { - this.popGLState(); - } + return rval; } /* @@ -1572,7 +1084,6 @@ public class GLTarget implements IGLTarget { @Override public void drawRect(IExtent extent, RGB color, float lineWidth, double alpha) { - this.makeContextCurrent(); this.pushGLState(); try { gl.glPolygonMode(GL.GL_BACK, GL.GL_LINE); @@ -1605,7 +1116,6 @@ public class GLTarget implements IGLTarget { @Override public void drawShadedRect(IExtent pe, RGB color, double alpha, byte[] stipple) throws VizException { - this.makeContextCurrent(); this.pushGLState(); try { @@ -1644,7 +1154,6 @@ public class GLTarget implements IGLTarget { */ public void drawRect(PixelCoverage coverage, RGB color, float lineWidth, double alpha) { - this.makeContextCurrent(); this.pushGLState(); try { gl.glPolygonMode(GL.GL_FRONT, GL.GL_LINE); @@ -1718,7 +1227,6 @@ public class GLTarget implements IGLTarget { brightness = Math.max(brightness, 0.0f); brightness = Math.min(brightness, 1.0f); - this.makeContextCurrent(); pushGLState(); try { gl.glPolygonMode(GL.GL_BACK, GL.GL_FILL); @@ -1916,11 +1424,10 @@ public class GLTarget implements IGLTarget { float lineWidth, IGraphicsTarget.LineStyle lineStyle, IFont font, float alpha) throws VizException { if (shape instanceof GLWireframeShape2D) { - makeContextCurrent(); pushGLState(); try { - ((GLWireframeShape2D) shape).paint(viewExtent, canvasSize, - aColor, lineWidth, lineStyle, font, alpha); + ((GLWireframeShape2D) shape).paint(this, viewExtent, + canvasSize, aColor, lineWidth, lineStyle, font, alpha); } finally { popGLState(); } @@ -1933,8 +1440,6 @@ public class GLTarget implements IGLTarget { private void drawWireframeShapeInternal(GLWireframeShape shape, RGB color, float lineWidth, LineStyle lineStyle, IGLFont font, float alpha) throws VizException { - - this.makeContextCurrent(); this.pushGLState(); try { @@ -2085,57 +1590,19 @@ public class GLTarget implements IGLTarget { */ @Override public void endFrame() { - - try { - if (this.lastColormapUsed != null && this.useBuiltinColorbar) { - this.drawColorbar(this.lastColormapUsed); - } - } catch (VizException e) { - e.printStackTrace(); - } - - if (theCanvas != null && theCanvas.isDisposed()) { - return; - } - makeContextCurrent(); - // Delete any pending resources - IImageCacheable[] pending = ImageCache.getInstance(CacheType.MEMORY) - .getImagesWaitingToDispose(); - - if (pending != null) { - for (IImageCacheable glI : pending) { - glI.disposeTextureData(); - } - } - - pending = ImageCache.getInstance(CacheType.TEXTURE) - .getImagesWaitingToDispose(); - - if (pending != null) { - for (IImageCacheable glI : pending) { - glI.disposeTexture(getGl()); - } - } - gl.glFinish(); - if (theCanvas != null) { - // if (allImagesSuccessfullyDrawn || redrawRetries > 0) { + if (theCanvas != null && theCanvas.isDisposed() == false) { theCanvas.swapBuffers(); - // redrawRetries = 0; - // } else { - // redrawRetries++; - // } } - if (GLContext.getCurrent() == theContext) { - theContext.release(); - } - } + GLContextBridge.makeMasterContextCurrent(); - public GLContext getContext() { - return this.theContext; + GLDisposalManager.performDispose(GLU.getCurrentGL()); + + GLContextBridge.releaseMasterContext(); + releaseContext(); } /* @@ -2184,10 +1651,6 @@ public class GLTarget implements IGLTarget { } - public GLContext getSharedContext() { - return this.sharedContext; - } - /* * (non-Javadoc) * @@ -2328,16 +1791,16 @@ public class GLTarget implements IGLTarget { gl.glLoadIdentity(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - this.colorbarFont = new UnmodifiableGLFont(new GLFont(this, - DEFAULT_FONT, (10 * textMagnification), null)); + this.colorbarFont = new UnmodifiableGLFont(new GLFont(DEFAULT_FONT, + (10 * textMagnification), null)); if (PlatformUI.isWorkbenchRunning()) { fontFactory = FontFactory.getInstance(); - this.defaultFont = new UnmodifiableGLFont(fontFactory.getFont( - FontFactory.DEFAULT_FONT_ID, this)); + this.defaultFont = new UnmodifiableGLFont( + fontFactory.getFont(FontFactory.DEFAULT_FONT_ID)); } else { this.defaultFont = new UnmodifiableGLFont( - new GLFont(this, java.awt.Font.MONOSPACED, 14.0f, + new GLFont(java.awt.Font.MONOSPACED, 14.0f, new Style[] { Style.BOLD })); } releaseContext(); @@ -2352,9 +1815,10 @@ public class GLTarget implements IGLTarget { */ @Override public AbstractGLImage initializeRaster(IRenderedImageCallback imageCallback) { - GLImage image = new GLImage(imageCallback, this); + GLImage image = new GLImage(imageCallback, + GLDefaultImagingExtension.class); try { - image.stageTexture(); + image.stage(); } catch (VizException e) { statusHandler.handle(Priority.PROBLEM, "Error staging texture", e); } @@ -2418,7 +1882,7 @@ public class GLTarget implements IGLTarget { */ @Override public IFont initializeFont(File fontFile, float size, Style[] styles) { - return new GLFont(this, fontFile, size, styles); + return new GLFont(fontFile, size, styles); } /* @@ -2430,7 +1894,7 @@ public class GLTarget implements IGLTarget { */ @Override public IFont initializeFont(String fontName, float size, Style[] styles) { - return new GLFont(this, fontName, size, styles); + return new GLFont(fontName, size, styles); } /* @@ -2442,7 +1906,7 @@ public class GLTarget implements IGLTarget { @Override public IFont initializeFont(String font) { if (fontFactory != null && fontFactory.hasId(font)) { - return fontFactory.getFont(font, this); + return fontFactory.getFont(font); } return defaultFont.deriveWithSize(defaultFont.getFontSize()); } @@ -2457,16 +1921,16 @@ public class GLTarget implements IGLTarget { return needsRefresh; } - protected int loadColormapIntoTexture(ColorMap glColorMap) { + protected GLTextureObject loadColormapIntoTexture(ColorMap glColorMap) { Buffer bb = glColorMap.getColorMap(); - - int[] t = new int[2]; - gl.glGenTextures(1, t, 0); + GLContextBridge.makeMasterContextCurrent(); + GLTextureObject t = new GLTextureObject(); + GLContextBridge.releaseMasterContext(); if (gl.isFunctionAvailable("glActiveTexture")) { gl.glActiveTexture(GL.GL_TEXTURE1); } gl.glEnable(GL.GL_TEXTURE_1D); - gl.glBindTexture(GL.GL_TEXTURE_1D, t[0]); + t.bind(gl, GL.GL_TEXTURE_1D); bb.rewind(); gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); @@ -2487,7 +1951,7 @@ public class GLTarget implements IGLTarget { 0, GL.GL_RGBA, GL.GL_FLOAT, bb); gl.glDisable(GL.GL_TEXTURE_1D); - return t[0]; + return t; } /* @@ -2496,22 +1960,7 @@ public class GLTarget implements IGLTarget { * @see com.raytheon.viz.core.gl.IGLTarget#makeContextCurrent() */ public boolean makeContextCurrent() { - boolean releaseContext = false; - - if (theContext != (GLContext.getCurrent())) { - GLContext oldContext = GLContext.getCurrent(); - if (oldContext != null) { - oldContext.release(); - } - - if (theCanvas != null && !theCanvas.isDisposed()) { - theCanvas.setCurrent(); - } - theContext.makeCurrent(); - currentGl = this; - releaseContext = true; - } - return releaseContext; + return theContext.makeContextCurrent(); } /** @@ -2521,7 +1970,7 @@ public class GLTarget implements IGLTarget { * */ public void releaseContext() { - theContext.release(); + theContext.releaseContext(); } /* @@ -2537,7 +1986,7 @@ public class GLTarget implements IGLTarget { Rectangle bounds = theCanvas.getClientArea(); - boolean needsDispose = makeContextCurrent(); + makeContextCurrent(); gl.glViewport(0, 0, bounds.width, bounds.height); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); @@ -2545,9 +1994,7 @@ public class GLTarget implements IGLTarget { gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); - if (needsDispose) { - releaseContext(); - } + releaseContext(); } @@ -2559,7 +2006,7 @@ public class GLTarget implements IGLTarget { @Override public BufferedImage screenshot() { - boolean grabbedContext = makeContextCurrent(); + makeContextCurrent(); if (theCanvas != null) { theCanvas.swapBuffers(); } @@ -2570,9 +2017,7 @@ public class GLTarget implements IGLTarget { theCanvas.swapBuffers(); } - if (grabbedContext) { - releaseContext(); - } + releaseContext(); return bi; } @@ -2621,7 +2066,6 @@ public class GLTarget implements IGLTarget { if (extent == null) { return; } - this.makeContextCurrent(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); @@ -2661,33 +2105,6 @@ public class GLTarget implements IGLTarget { gl.glPopMatrix(); } - /* - * (non-Javadoc) - * - * @see com.raytheon.viz.core.IGraphicsTarget#setUseBuiltinColorbar(boolean) - */ - @Override - public void setUseBuiltinColorbar(boolean isColorbarDisplayed) { - this.useBuiltinColorbar = isColorbarDisplayed; - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.viz.core.IGraphicsTarget#stage(com.raytheon.viz.core.drawables - * .IImage) - */ - @Override - public void stage(final IImage image) throws VizException { - if (!(image instanceof AbstractGLImage)) { - throw new VizException("Must pass GLImages to GLTarget"); - } - - TextureLoaderJob.getInstance().requestLoad((AbstractGLImage) image); - - } - /** * (non-Javadoc) * @@ -2795,67 +2212,6 @@ public class GLTarget implements IGLTarget { return this.canvasSize; } - /* - * (non-Javadoc) - * - * @see com.raytheon.viz.core.gl.IGLTarget#bindTexture(int, - * com.raytheon.viz.core.gl.internal.images.AbstractGLColormappedImage) - */ - @Override - public void bindTexture(int textureUnit, GLColormappedImage image) { - gl.glActiveTexture(textureUnit); - gl.glBindTexture(image.getTextureStorageType(), image.getTextureid()); - } - - /* - * (non-Javadoc) - * - * @see com.raytheon.viz.core.gl.IGLTarget#disposeOcclusionQuery(int) - */ - @Override - public void disposeOcclusionQueries(int[] id) { - gl.glDeleteQueriesARB(id.length, id, 0); - - } - - /* - * (non-Javadoc) - * - * @see - * com.raytheon.viz.core.gl.IGLTarget#beginOcclusionTest(com.raytheon.viz - * .core.IRenderableDisplay) - */ - @Override - public void beginOcclusionTest(IRenderableDisplay display) - throws VizException { - beginFrame(display, true); - - // don't actually update framebuffer - gl.glColorMask(false, false, false, false); - gl.glDisable(GL.GL_CULL_FACE); - gl.glDisable(GL.GL_NORMALIZE); - - gl.glDisable(GL.GL_STENCIL_TEST); - } - - /* - * (non-Javadoc) - * - * @see com.raytheon.viz.core.gl.IGLTarget#endOcclusionTest() - */ - @Override - public void endOcclusionTest() throws VizException { - - // don't actually update framebuffer - gl.glColorMask(true, true, true, true); - // gl.glEnable(GL.GL_CULL_FACE); - // gl.glEnable(GL.GL_NORMALIZE); - - gl.glDepthFunc(GL.GL_LESS); - gl.glEnable(GL.GL_STENCIL_TEST); - - } - public void drawCylinder(PixelCoordinate coord, RGB color, float alpha, double height, double baseRadius, double topRadius, int sideCount, int sliceCount, double rotation, double lean) { @@ -2917,7 +2273,6 @@ public class GLTarget implements IGLTarget { @Override public void drawShadedPolygon(LinearRing poly, RGB color, double alpha, byte[] stipple) throws VizException { - this.makeContextCurrent(); this.pushGLState(); try { // set the shading and alpha @@ -2952,12 +2307,24 @@ public class GLTarget implements IGLTarget { return VizConstants.VIEW_2D; } - private void pushGLState() { + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.IGLTarget#pushGLState() + */ + @Override + public void pushGLState() { gl.glPushAttrib(GL.GL_COLOR_BUFFER_BIT | GL.GL_CURRENT_BIT | GL.GL_ENABLE_BIT | GL.GL_TEXTURE_BIT | GL.GL_LINE_BIT); } - private void popGLState() { + /* + * (non-Javadoc) + * + * @see com.raytheon.viz.core.gl.IGLTarget#popGLState() + */ + @Override + public void popGLState() { gl.glPopAttrib(); } @@ -2966,7 +2333,15 @@ public class GLTarget implements IGLTarget { this.updatedExtent = updatedExtent; } - private Integer getColorMapTexture(ColorMapParameters cmapParams) { + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.IGLTarget#getColorMapTexture(com.raytheon.uf + * .viz.core.drawables.ColorMapParameters) + */ + @Override + public GLTextureObject getColorMapTexture(ColorMapParameters cmapParams) { IColorMap cmap = cmapParams.getColorMap(); String name = cmap.getName(); if (name == null) { @@ -2974,7 +2349,7 @@ public class GLTarget implements IGLTarget { + cmapParams.hashCode(); } - Integer i = loadedColorMaps.get(name); + GLTextureObject i = loadedColorMaps.get(name); if (i == null || cmap.isChanged()) { if (i != null) { loadedColorMaps.remove(name); @@ -3220,7 +2595,6 @@ public class GLTarget implements IGLTarget { // function ends up calling begin/end rendering lots which slows it down // to the speed of a not bulk operation TextRenderer textRenderer = null; - makeContextCurrent(); pushGLState(); gl.glMatrixMode(GL.GL_MODELVIEW); @@ -3558,7 +2932,6 @@ public class GLTarget implements IGLTarget { return; } - this.makeContextCurrent(); this.pushGLState(); try { int pointsPerLocation = 1; @@ -3777,9 +3150,25 @@ public class GLTarget implements IGLTarget { } @Override - public final T getExtension(Class extensionClass) - throws VizException { - return extensionManager.getExtension(extensionClass); + public final T getExtension( + Class extensionClass) throws VizException { + Class toUse = extensionClass; + if (extensionClass == IImagingExtension.class) { + toUse = GLDefaultImagingExtension.class; + } + return extensionClass.cast(extensionManager.getExtension(toUse)); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.IGraphicsTarget#setUseBuiltinColorbar(boolean) + */ + @Override + @Deprecated + public void setUseBuiltinColorbar(boolean isColorbarDisplayed) { + // No effect } } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLWireframeShape.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLWireframeShape.java index 6026310930..98212d2d16 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLWireframeShape.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLWireframeShape.java @@ -802,7 +802,8 @@ public class GLWireframeShape implements IWireframeShape { recursiveDispose(baseLevel); if (vboAssociatedTarget != null && vboID > 0) { - vboAssociatedTarget.disposeVBO(vboID); + vboAssociatedTarget.getGl().glDeleteBuffers(1, new int[] { vboID }, + 0); vboID = 0; vboAssociatedTarget = null; } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLWireframeShape2D.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLWireframeShape2D.java index 29092b6f92..cc6e7b756f 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLWireframeShape2D.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLWireframeShape2D.java @@ -73,26 +73,20 @@ public class GLWireframeShape2D implements IWireframeShape { private boolean compiled = false; - private IGLTarget target; - private GLGeometryObject2D geometry; private GLGeometryObjectData geomData; - public GLWireframeShape2D(IGLTarget target, - GeneralGridGeometry gridGeometry, boolean mutable) { - this.target = target; + public GLWireframeShape2D(GeneralGridGeometry gridGeometry, boolean mutable) { geomData = new GLGeometryObjectData(GL.GL_LINE_STRIP, GL.GL_VERTEX_ARRAY); - geomData.setTarget(target); geomData.mutable = mutable; geomData.worldExtent = new PixelExtent(gridGeometry.getGridRange()); initialize(); } - public GLWireframeShape2D(IGLTarget target, IDescriptor descriptor, - boolean mutable) { - this(target, descriptor.getGridGeometry(), mutable); + public GLWireframeShape2D(IDescriptor descriptor, boolean mutable) { + this(descriptor.getGridGeometry(), mutable); this.descriptor = descriptor; } @@ -230,16 +224,16 @@ public class GLWireframeShape2D implements IWireframeShape { geometry.allocate(points); } - public synchronized void paint(IExtent viewExtent, Rectangle canvasSize, - RGB color, float lineWidth, LineStyle lineStyle, IFont font, - float alpha) throws VizException { + public synchronized void paint(IGLTarget target, IExtent viewExtent, + Rectangle canvasSize, RGB color, float lineWidth, + LineStyle lineStyle, IFont font, float alpha) throws VizException { if (isDrawable() == false) { return; } if (!geomData.mutable && !compiled) { compiled = true; - geometry.compile(); + geometry.compile(target.getGl()); } GL gl = target.getGl(); @@ -321,7 +315,7 @@ public class GLWireframeShape2D implements IWireframeShape { gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP); } - geometry.paint(); + geometry.paint(target.getGl()); gl.glDisable(GL.GL_BLEND); diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/PreferenceBasedGLFont.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/PreferenceBasedGLFont.java index 70020f6edf..7c9ccf5767 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/PreferenceBasedGLFont.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/PreferenceBasedGLFont.java @@ -135,22 +135,10 @@ public class PreferenceBasedGLFont implements IGLFont, IPropertyChangeListener { public void propertyChange(PropertyChangeEvent event) { if (propertyName.equals(event.getProperty())) { preferenceFont.disposeInternal(); - preferenceFont = FontFactory.getInstance().getFont(propertyName, - preferenceFont.getTarget()); - preferenceFont.getTarget().setNeedsRefresh(true); + preferenceFont = FontFactory.getInstance().getFont(propertyName); } } - /* - * (non-Javadoc) - * - * @see com.raytheon.viz.core.gl.IGLFont#getTarget() - */ - @Override - public GLTarget getTarget() { - return preferenceFont.getTarget(); - } - /* * (non-Javadoc) * diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/TextRendererCache.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/TextRendererCache.java index b5ba4be74d..7b98400691 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/TextRendererCache.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/TextRendererCache.java @@ -25,6 +25,9 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; +import javax.media.opengl.GL; + +import com.raytheon.viz.core.gl.GLDisposalManager.GLDisposer; import com.sun.opengl.util.j2d.TextRenderer; /** @@ -60,7 +63,14 @@ public class TextRendererCache { @Override protected boolean removeEldestEntry(Entry eldest) { if (size() > UNUSED_RENDERER_SIZE) { - eldest.getValue().dispose(); + final TextRenderer renderer = eldest.getValue(); + new GLDisposer() { + @Override + protected void dispose(GL gl) { + renderer.dispose(); + + } + }.dispose(); return true; } return false; diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/UnmodifiableGLFont.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/UnmodifiableGLFont.java index 1159528209..971f7e2732 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/UnmodifiableGLFont.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/UnmodifiableGLFont.java @@ -23,8 +23,6 @@ import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.drawables.IFont; -import com.raytheon.uf.viz.core.status.StatusConstants; -import com.raytheon.viz.core.gl.Activator; import com.raytheon.viz.core.gl.IGLFont; import com.sun.opengl.util.j2d.TextRenderer; @@ -47,7 +45,8 @@ import com.sun.opengl.util.j2d.TextRenderer; */ public class UnmodifiableGLFont implements IGLFont { - private static final transient IUFStatusHandler statusHandler = UFStatus.getHandler(UnmodifiableGLFont.class); + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(UnmodifiableGLFont.class); private IGLFont unmodifiableFont; @@ -146,14 +145,4 @@ public class UnmodifiableGLFont implements IGLFont { return unmodifiableFont.toString(); } - /* - * (non-Javadoc) - * - * @see com.raytheon.viz.core.gl.IGLFont#getTarget() - */ - @Override - public GLTarget getTarget() { - return unmodifiableFont.getTarget(); - } - } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/cache/ImageCache.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/cache/ImageCache.java index f55ec418db..f956533d01 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/cache/ImageCache.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/cache/ImageCache.java @@ -20,12 +20,12 @@ package com.raytheon.viz.core.gl.internal.cache; -import java.util.ArrayList; -import java.util.List; +import javax.media.opengl.GL; import com.raytheon.uf.common.util.cache.LRUCache; import com.raytheon.uf.viz.core.Activator; import com.raytheon.uf.viz.core.preferences.PreferenceConstants; +import com.raytheon.viz.core.gl.GLDisposalManager.GLDisposer; /** * Cache for GLImages, one for memory and one fore texture @@ -77,8 +77,6 @@ public class ImageCache extends LRUCache implements /** The instance of the memory cache */ private static ImageCache memoryCache; - private List waitingToDispose; - /** * Get Singletons * @@ -116,7 +114,6 @@ public class ImageCache extends LRUCache implements */ private ImageCache(long maxSz) { super(maxSz); - this.waitingToDispose = new ArrayList(); } public void put(IImageCacheable image) { @@ -126,13 +123,16 @@ public class ImageCache extends LRUCache implements @Override protected void removeItem(Item item) { super.removeItem(item); - waitingToDispose.add(item.value); - } - - public IImageCacheable[] getImagesWaitingToDispose() { - IImageCacheable[] arr = this.waitingToDispose - .toArray(new IImageCacheable[waitingToDispose.size()]); - this.waitingToDispose.clear(); - return arr; + final IImageCacheable i = item.value; + if (this == memoryCache) { + i.disposeTextureData(); + } else if (this == textureCache) { + new GLDisposer() { + @Override + protected void dispose(GL gl) { + i.disposeTexture(gl); + } + }.dispose(); + } } } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormapShadedShapeExtension.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormapShadedShapeExtension.java index b15f789f78..ef79916243 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormapShadedShapeExtension.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormapShadedShapeExtension.java @@ -97,7 +97,6 @@ public class GLColormapShadedShapeExtension extends throws VizException { if (shape instanceof GLColormapShadedShape) { GLColormapShadedShape glBaseShape = (GLColormapShadedShape) shape; - target.makeContextCurrent(); GL gl = target.getGl(); gl.glPolygonMode(GL.GL_BACK, GL.GL_FILL); gl.glEnableClientState(GL.GL_VERTEX_ARRAY); @@ -247,7 +246,7 @@ public class GLColormapShadedShapeExtension extends */ @Override public int getCompatibilityValue(IGLTarget target) { - return Compatibilty.TARGET_COMPATIBLE.value; + return Compatibilty.TARGET_COMPATIBLE; } } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormappedImageExtension.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormappedImageExtension.java index 9c2b26a3de..8b15f26afe 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormappedImageExtension.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormappedImageExtension.java @@ -19,19 +19,23 @@ **/ package com.raytheon.viz.core.gl.internal.ext; -import com.raytheon.uf.common.status.IUFStatusHandler; -import com.raytheon.uf.common.status.UFStatus; -import com.raytheon.uf.common.status.UFStatus.Priority; +import java.nio.ByteBuffer; + +import javax.media.opengl.GL; + +import com.raytheon.uf.viz.core.PixelCoverage; import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback; import com.raytheon.uf.viz.core.drawables.ColorMapParameters; import com.raytheon.uf.viz.core.drawables.IColormappedImage; -import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension; +import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.drawables.PaintProperties; import com.raytheon.uf.viz.core.drawables.ext.colormap.IColormappedImageExtension; import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.viz.core.gl.GLCapabilities; -import com.raytheon.viz.core.gl.IGLTarget; +import com.raytheon.viz.core.gl.glsl.AbstractGLSLImagingExtension; +import com.raytheon.viz.core.gl.glsl.GLShaderProgram; +import com.raytheon.viz.core.gl.images.AbstractGLImage; import com.raytheon.viz.core.gl.images.GLColormappedImage; -import com.raytheon.viz.core.gl.internal.GLTarget; +import com.raytheon.viz.core.gl.objects.GLTextureObject; /** * GL {@link IColormappedImageExtension} implementation, creates @@ -51,11 +55,12 @@ import com.raytheon.viz.core.gl.internal.GLTarget; * @version 1.0 */ -public class GLColormappedImageExtension extends GraphicsExtension +public class GLColormappedImageExtension extends AbstractGLSLImagingExtension implements IColormappedImageExtension { - private static final transient IUFStatusHandler statusHandler = UFStatus - .getHandler(GLColormappedImageExtension.class); + private static class GLColormappedImageExtensionData { + public GLColormappedImage alphaMaskTexture; + } /* * (non-Javadoc) @@ -66,33 +71,165 @@ public class GLColormappedImageExtension extends GraphicsExtension * com.raytheon.uf.viz.core.drawables.ColorMapParameters) */ @Override - public IColormappedImage initializeRaster( + public GLColormappedImage initializeRaster( IColorMapDataRetrievalCallback dataCallback, ColorMapParameters colorMapParameters) { - GLColormappedImage image = new GLColormappedImage(dataCallback, - colorMapParameters, target); - try { - image.stageTexture(); - } catch (VizException e) { - statusHandler.handle(Priority.PROBLEM, "Error staging texture", e); - } - return image; + return new GLColormappedImage(dataCallback, colorMapParameters, + GLColormappedImageExtension.class); } /* * (non-Javadoc) * - * @see com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension# - * getCompatibilityValue(com.raytheon.uf.viz.core.IGraphicsTarget) + * @see + * com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension#preImageRender + * (com.raytheon.uf.viz.core.drawables.PaintProperties, + * com.raytheon.viz.core.gl.images.AbstractGLImage) */ @Override - public int getCompatibilityValue(IGLTarget target) { - if (GLCapabilities.getInstance(target.getGl()).cardSupportsShaders - && GLTarget.FORCE_NO_SHADER == false) { - return Compatibilty.ENHANCED_TARGET_COMPATIBLE.value; - } else { - return Compatibilty.INCOMPATIBLE.value; + public Object preImageRender(PaintProperties paintProps, + AbstractGLImage image, PixelCoverage coverage) throws VizException { + GLColormappedImageExtensionData data = null; + if (image instanceof GLColormappedImage) { + data = new GLColormappedImageExtensionData(); + GL gl = target.getGl(); + GLColormappedImage glImage = (GLColormappedImage) image; + // First see if the colormap has been loaded + ColorMapParameters usedColorMapParameters = ((IColormappedImage) glImage) + .getColorMapParameters(); + if (usedColorMapParameters == null + || usedColorMapParameters.getColorMap() == null) { + return null; + } + + if (usedColorMapParameters.isUseMask()) { + final byte[] mask = usedColorMapParameters.getAlphaMask(); + data.alphaMaskTexture = initializeRaster( + new IColorMapDataRetrievalCallback() { + @Override + public ColorMapData getColorMapData() + throws VizException { + return new ColorMapData(ByteBuffer.wrap(mask), + new int[] { mask.length, 1 }); + } + }, usedColorMapParameters); + data.alphaMaskTexture.stage(); + data.alphaMaskTexture.target(target); + } + + // Get and stage colormap texture + GLTextureObject cmapTexture = target + .getColorMapTexture(usedColorMapParameters); + + if (data.alphaMaskTexture != null) { + gl.glActiveTexture(GL.GL_TEXTURE2); + gl.glBindTexture(data.alphaMaskTexture.getTextureStorageType(), + data.alphaMaskTexture.getTextureid()); + } + + gl.glActiveTexture(GL.GL_TEXTURE1); + cmapTexture.bind(gl, GL.GL_TEXTURE_1D); + + if (glImage.isInterpolated()) { + gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER, + GL.GL_LINEAR); + gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER, + GL.GL_LINEAR); + } else { + gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER, + GL.GL_NEAREST); + gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER, + GL.GL_NEAREST); + } } + return data; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension#postImageRender + * (com.raytheon.uf.viz.core.drawables.PaintProperties, + * com.raytheon.viz.core.gl.images.AbstractGLImage, java.lang.Object) + */ + @Override + public void postImageRender(PaintProperties paintProps, + AbstractGLImage image, Object data) throws VizException { + GLColormappedImageExtensionData imageData = (GLColormappedImageExtensionData) data; + GL gl = target.getGl(); + if (imageData.alphaMaskTexture != null) { + gl.glActiveTexture(GL.GL_TEXTURE2); + gl.glBindTexture( + imageData.alphaMaskTexture.getTextureStorageType(), 0); + + imageData.alphaMaskTexture.dispose(); + } + + gl.glActiveTexture(GL.GL_TEXTURE1); + gl.glBindTexture(GL.GL_TEXTURE_1D, 0); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension#getShaderProgramName + * () + */ + @Override + public String getShaderProgramName() { + return "colormapRaster"; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension#loadShaderData + * (com.raytheon.viz.core.gl.glsl.GLShaderProgram, + * com.raytheon.uf.viz.core.drawables.IImage, + * com.raytheon.uf.viz.core.drawables.PaintProperties) + */ + @Override + public void loadShaderData(GLShaderProgram program, IImage iimage, + PaintProperties paintProps) throws VizException { + // Get image as AbstractGLImage + GLColormappedImage image = null; + if (iimage instanceof GLColormappedImage == false) { + throw new VizException( + "Cannot apply glsl colormap raster shader to non gl colormap image"); + } + image = (GLColormappedImage) iimage; + + GLColormappedImage colormappedImg = (GLColormappedImage) image; + ColorMapParameters colorMapParameters = colormappedImg + .getColorMapParameters(); + + program.setUniform("colorMapSz", colorMapParameters.getColorMap() + .getSize()); + int textureType = ((GLColormappedImage) image).getTextureType(); + program.setUniform("isFloat", textureType == GL.GL_FLOAT + || textureType == GL.GL_HALF_FLOAT_ARB ? 1 : 0); + program.setUniform("logarithmic", + colorMapParameters.isLogarithmic() ? 1 : 0); + program.setUniform("logFactor", colorMapParameters.getLogFactor()); + program.setUniform("mirror", colorMapParameters.isMirror() ? 1 : 0); + + program.setUniform("applyMask", colorMapParameters.isUseMask() ? 1 : 0); + + program.setUniform("naturalMin", colorMapParameters.getDataMin()); + program.setUniform("naturalMax", colorMapParameters.getDataMax()); + program.setUniform("cmapMin", colorMapParameters.getColorMapMin()); + program.setUniform("cmapMax", colorMapParameters.getColorMapMax()); + + program.setUniform("alphaMask", 2); + program.setUniform("colorMap", 1); + program.setUniform("rawText", 0); + + program.setUniform("brightness", image.getBrightness()); + program.setUniform("contrast", image.getContrast()); + program.setUniform("alpha", paintProps.getAlpha()); } } diff --git a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/MosaicShaderLoader.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLDefaultImagingExtension.java similarity index 51% rename from cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/MosaicShaderLoader.java rename to cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLDefaultImagingExtension.java index 9fff8ae853..83b6fba72a 100644 --- a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/MosaicShaderLoader.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLDefaultImagingExtension.java @@ -17,27 +17,25 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.uf.viz.radar.gl.mosaic; - -import javax.media.opengl.GL; +package com.raytheon.viz.core.gl.internal.ext; import com.raytheon.uf.viz.core.drawables.IImage; import com.raytheon.uf.viz.core.drawables.PaintProperties; import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.viz.core.gl.IGLTarget; -import com.raytheon.viz.core.gl.glsl.AbstractShaderLoader; +import com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension; import com.raytheon.viz.core.gl.glsl.GLShaderProgram; import com.raytheon.viz.core.gl.images.AbstractGLImage; /** - * Loads variables for mosiac fragment shader + * TODO Add Description * *
  * 
  * SOFTWARE HISTORY
+ * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * Jun 10, 2010            mschenke     Initial creation
+ * Dec 16, 2011            mschenke     Initial creation
  * 
  * 
* @@ -45,39 +43,44 @@ import com.raytheon.viz.core.gl.images.AbstractGLImage; * @version 1.0 */ -public class MosaicShaderLoader extends AbstractShaderLoader { +public class GLDefaultImagingExtension extends AbstractGLImagingExtension { /* * (non-Javadoc) * * @see - * com.raytheon.viz.core.gl.glsl.IShaderLoader#loadData(com.raytheon.viz - * .core.gl.IGLTarget, com.raytheon.viz.core.gl.glsl.GLShaderProgram, + * com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension#getShaderProgramName + * () + */ + @Override + public String getShaderProgramName() { + return "raster"; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension#loadShaderData + * (com.raytheon.viz.core.gl.glsl.GLShaderProgram, * com.raytheon.uf.viz.core.drawables.IImage, * com.raytheon.uf.viz.core.drawables.PaintProperties) */ @Override - public void loadData(IGLTarget target, GLShaderProgram program, - IImage image, PaintProperties paintProps) throws VizException { - // load radar data to GL_TEXTURE0 (bound in drawRaster) - program.setUniform("radarData", 0); + public void loadShaderData(GLShaderProgram program, IImage iimage, + PaintProperties paintProps) throws VizException { + // Get image as AbstractGLImage + AbstractGLImage image = null; + if (iimage instanceof AbstractGLImage == false) { + throw new VizException( + "Cannot apply glsl raster shader to non gl image"); + } + image = (AbstractGLImage) iimage; - GL gl = target.getGl(); - - // grab currently writting to texture - AbstractGLImage writeTo = (AbstractGLImage) RadarMosaicRenderer - .getCurrentMosaicImage(); - - // activate on texture2 as 0 is radar image and 1 is colormap - gl.glActiveTexture(GL.GL_TEXTURE2); - gl.glBindTexture(writeTo.getTextureStorageType(), - writeTo.getTextureid()); - - program.setUniform("mosaicTexture", 2); - - // pass in width and height - program.setUniform("height", (paintProps.getCanvasBounds().height)); - program.setUniform("width", (paintProps.getCanvasBounds().width)); + program.setUniform("alpha", paintProps.getAlpha()); + program.setUniform("brightness", image.getBrightness()); + program.setUniform("contrast", image.getContrast()); + program.setUniform("rawTex", 0); } } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLMapMeshExtension.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLMapMeshExtension.java index c6f4abf8b5..a4ed6fbcec 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLMapMeshExtension.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLMapMeshExtension.java @@ -67,7 +67,7 @@ public class GLMapMeshExtension extends GraphicsExtension implements */ @Override public int getCompatibilityValue(IGLTarget target) { - return Compatibilty.TARGET_COMPATIBLE.value; + return Compatibilty.TARGET_COMPATIBLE; } } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLSingleColorImageExtension.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLSingleColorImageExtension.java new file mode 100644 index 0000000000..480f06220f --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLSingleColorImageExtension.java @@ -0,0 +1,114 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.core.gl.internal.ext; + +import java.awt.image.RenderedImage; + +import org.eclipse.swt.graphics.RGB; + +import com.raytheon.uf.viz.core.data.IRenderedImageCallback; +import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.drawables.PaintProperties; +import com.raytheon.uf.viz.core.drawables.ext.ISingleColorImageExtension; +import com.raytheon.uf.viz.core.exception.VizException; +import com.raytheon.viz.core.gl.glsl.AbstractGLSLImagingExtension; +import com.raytheon.viz.core.gl.glsl.GLShaderProgram; +import com.raytheon.viz.core.gl.images.GLImage; +import com.raytheon.viz.core.gl.images.GLSingleColorImage; + +/** + * GL implementation of ISingleColorImageExtension, uses shader to assign color + * value + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 15, 2011            mschenke     Initial creation
+ * 
+ * 
+ * + * @author mschenke + * @version 1.0 + */ + +public class GLSingleColorImageExtension extends AbstractGLSLImagingExtension + implements ISingleColorImageExtension { + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension#getShaderProgramName + * () + */ + @Override + public String getShaderProgramName() { + return "singleColor"; + } + + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.core.drawables.ext.ISingleColorImageExtension# + * constructImage(com.raytheon.uf.viz.core.drawables.IImage, + * org.eclipse.swt.graphics.RGB) + */ + @Override + public ISingleColorImage constructImage(final RenderedImage image, RGB color) { + return new GLSingleColorImage(new GLImage(new IRenderedImageCallback() { + @Override + public RenderedImage getImage() throws VizException { + return image; + } + }, GLSingleColorImageExtension.class), color); + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.core.gl.ext.AbstractGLImagingExtension#loadShaderData + * (com.raytheon.viz.core.gl.glsl.GLShaderProgram, + * com.raytheon.uf.viz.core.drawables.IImage, + * com.raytheon.uf.viz.core.drawables.PaintProperties) + */ + @Override + public void loadShaderData(GLShaderProgram program, IImage iimage, + PaintProperties paintProps) throws VizException { + // Get image as AbstractGLImage + GLSingleColorImage image = null; + if (iimage instanceof GLSingleColorImage == false) { + throw new VizException( + "Cannot apply single color raster shader to non single color image"); + } + + image = (GLSingleColorImage) iimage; + + program.setUniform("brightness", image.getBrightness()); + program.setUniform("contrast", image.getContrast()); + program.setUniform("alpha", paintProps.getAlpha()); + program.setUniform("color", image.getColor()); + program.setUniform("rawTex", 0); + } + +} diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLFrameBufferObject.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLFrameBufferObject.java new file mode 100644 index 0000000000..6470a385f0 --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLFrameBufferObject.java @@ -0,0 +1,120 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.core.gl.objects; + +import javax.media.opengl.GL; + +/** + * + * A simple wrapper around a GL frameBuffer id that manages creation and + * disposal of frameBuffer ids. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 17, 2012            bsteffen     Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class GLFrameBufferObject extends GLIdWrapper { + + /** + * Create a new frameBuffer id in gl and register this frameBuffer to be + * disposed when parent is garbage collected. + * + * @param parent + * - the object that will be using the texture. + * @param gl + */ + public GLFrameBufferObject(Object parent) { + super(parent); + } + + /** + * Create a new frameBuffer id in gl + * + * @param gl + */ + public GLFrameBufferObject() { + super(); + } + + @Override + protected void genId(GL gl, int[] arr) { + gl.glGenFramebuffersEXT(1, arr, 0); + } + + @Override + protected void deleteId(GL gl, int[] arr) { + gl.glDeleteFramebuffersEXT(1, arr, 0); + + } + + public void bind(GL gl) { + gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, id); + } + + public String checkStatus(GL gl) { + String errorMessage = null; + + switch (gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_EXT)) { + case GL.GL_FRAMEBUFFER_COMPLETE_EXT: { + // Everything is ok. + break; + } + case GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: { + errorMessage = "Error: Framebuffer incomplete, fbo attachement is NOT complete"; + break; + } + case GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: { + errorMessage = "Error: Framebuffer incomplete, no image is attached to FBO"; + break; + } + case GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: { + errorMessage = "Error: Framebuffer incomplete, attached images have different dimensions"; + break; + } + case GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: { + errorMessage = "Error: Framebuffer incomplete, color attached images have different internal formats"; + break; + } + case GL.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: { + errorMessage = "Error: Framebuffer incomplete, draw buffer"; + break; + } + case GL.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: { + errorMessage = "Error: Framebuffer incomplete, read buffer"; + break; + } + case GL.GL_FRAMEBUFFER_UNSUPPORTED_EXT: { + errorMessage = "Error: Framebuffer not supported by hardware/drivers"; + break; + } + } + return errorMessage; + } + +} diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLIdWrapper.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLIdWrapper.java new file mode 100644 index 0000000000..bd87d164ed --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLIdWrapper.java @@ -0,0 +1,96 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.core.gl.objects; + +import javax.media.opengl.GL; +import javax.media.opengl.glu.GLU; + +import com.raytheon.viz.core.gl.GLDisposalManager; +import com.raytheon.viz.core.gl.GLDisposalManager.GLDisposer; + +/** + * + * Most objects in GL are represented in Java as an integer id. This class + * provides some of the generic code needed to manage these and dispose of these + * GL Objects + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 17, 2012            bsteffen     Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public abstract class GLIdWrapper extends GLDisposer { + + protected int id; + + public GLIdWrapper(Object parent) { + this(); + GLDisposalManager.autoDispose(this, parent); + } + + public GLIdWrapper() { + int[] arr = new int[1]; + genId(GLU.getCurrentGL(), arr); + this.id = arr[0]; + } + + public boolean isValid() { + return id != -1; + } + + public int getId() { + return id; + } + + @Override + protected void dispose(GL gl) { + if (id != -1) { + deleteId(gl, new int[] { id }); + } + this.id = -1; + } + + /** + * Generate an id for this object, arr is an array of length 1 and id should + * be set to the only element in the array + * + * @param gl + * @param arr + */ + protected abstract void genId(GL gl, int[] arr); + + /** + * Delete an id for this object, arr is an array of length 1 and will + * contain the id + * + * @param gl + * @param arr + */ + protected abstract void deleteId(GL gl, int[] arr); + +} diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLRenderBuffer.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLRenderBuffer.java new file mode 100644 index 0000000000..74d10d3191 --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLRenderBuffer.java @@ -0,0 +1,84 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.core.gl.objects; + +import javax.media.opengl.GL; + +/** + * + * A simple wrapper around a GL renderBuffer id that manages creation and + * disposal of renderBuffer ids. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 17, 2012            bsteffen     Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class GLRenderBuffer extends GLIdWrapper { + + /** + * Create a new renderBuffer id in gl and register this renderBuffer to be + * disposed when parent is garbage collected. + * + * @param parent + * - the object that will be using the texture. + * @param gl + */ + public GLRenderBuffer(Object parent) { + super(parent); + } + + /** + * Create a new renderBuffer id in gl + * + * @param gl + */ + public GLRenderBuffer() { + super(); + } + + @Override + protected void genId(GL gl, int[] arr) { + gl.glGenRenderbuffersEXT(1, arr, 0); + } + + @Override + protected void deleteId(GL gl, int[] arr) { + gl.glDeleteRenderbuffersEXT(1, arr, 0); + } + + public void bind(GL gl) { + gl.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, id); + } + + public void createStorage(GL gl, int internalFormat, int width, int height) { + gl.glRenderbufferStorageEXT(GL.GL_RENDERBUFFER_EXT, internalFormat, + width, height); + } + +} diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLTextureObject.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLTextureObject.java new file mode 100644 index 0000000000..6655978fdd --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLTextureObject.java @@ -0,0 +1,88 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.core.gl.objects; + +import javax.media.opengl.GL; + +/** + * + * A simple wrapper around a GLTextureId that manages creation and disposal of + * texture ids. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 17, 2012            bsteffen     Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class GLTextureObject extends GLIdWrapper { + + /** + * Create a new texture id in gl and register this texture to be disposed + * when parent is garbage collected. + * + * @param parent + * - the object that will be using the texture. + * @param gl + */ + public GLTextureObject(Object parent) { + super(parent); + } + + /** + * Create a new texture id in gl + * + * @param gl + */ + public GLTextureObject() { + super(); + } + + @Override + protected void genId(GL gl, int[] arr) { + gl.glGenTextures(1, arr, 0); + + } + + @Override + protected void deleteId(GL gl, int[] arr) { + gl.glDeleteTextures(1, arr, 0); + } + + /** + * + * @param gl + * @param target + * Specifies the target to which the texture is bound. Must be + * either GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, or + * GL_TEXTURE_CUBE_MAP. + */ + public void bind(GL gl, int target) { + gl.glBindTexture(target, id); + } + +} diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLVertexBufferObject.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLVertexBufferObject.java new file mode 100644 index 0000000000..e4ac6fa2be --- /dev/null +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/objects/GLVertexBufferObject.java @@ -0,0 +1,88 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.core.gl.objects; + +import javax.media.opengl.GL; + +/** + * + * A wrapper around a vbo id from gl. This object contains the logic to create + * and dispose vbo ids. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 17, 2012            bsteffen     Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class GLVertexBufferObject extends GLIdWrapper { + + /** + * Create a new vboId in gl and register this vbo to be disposed when parent + * is garbage collected. + * + * @param parent + * - the object that will be using the vbo. + * @param gl + */ + public GLVertexBufferObject(Object parent) { + super(parent); + } + + /** + * Create a new vboId in gl + * + * @param gl + */ + public GLVertexBufferObject() { + super(); + } + + @Override + protected void genId(GL gl, int[] arr) { + gl.glGenBuffers(1, arr, 0); + } + + @Override + protected void deleteId(GL gl, int[] arr) { + gl.glDeleteBuffers(1, arr, 0); + } + + /** + * + * @param gl + * @param target + * Specifies the target to which the buffer object is bound. The + * symbolic constant must be GL_ARRAY_BUFFER, + * GL_ELEMENT_ARRAY_BUFFER, GL_PIXEL_PACK_BUFFER, or + * GL_PIXEL_UNPACK_BUFFER + */ + public void bind(GL gl, int target) { + gl.glBindBuffer(target, id); + } + +} diff --git a/cave/com.raytheon.viz.grid/META-INF/MANIFEST.MF b/cave/com.raytheon.viz.grid/META-INF/MANIFEST.MF index 908cc9fbfa..d5e22ebb93 100644 --- a/cave/com.raytheon.viz.grid/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.viz.grid/META-INF/MANIFEST.MF @@ -32,6 +32,7 @@ Export-Package: com.raytheon.viz.grid, com.raytheon.viz.grid.xml Import-Package: com.raytheon.edex.scriptfactory, com.raytheon.uf.common.colormap, + com.raytheon.uf.common.comm, com.raytheon.uf.common.dataplugin.grib, com.raytheon.uf.common.dataplugin.grib.exception, com.raytheon.uf.common.dataplugin.grib.request, @@ -47,6 +48,7 @@ Import-Package: com.raytheon.edex.scriptfactory, com.raytheon.uf.common.serialization, com.raytheon.uf.common.time, com.raytheon.uf.common.topo, + com.raytheon.uf.viz.d2d.core.map, com.raytheon.uf.viz.d2d.core.time, com.raytheon.uf.viz.derivparam, com.raytheon.uf.viz.derivparam.data, diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/GridProductBrowserDataDefinition.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/GridProductBrowserDataDefinition.java index dd1a585fbf..ee963d6d51 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/GridProductBrowserDataDefinition.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/GridProductBrowserDataDefinition.java @@ -33,12 +33,16 @@ import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.grib.util.GribModelLookup; import com.raytheon.uf.common.dataplugin.grib.util.GridModel; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.level.LevelFactory; import com.raytheon.uf.common.dataplugin.level.MasterLevel; import com.raytheon.uf.common.dataquery.requests.RequestConstraint; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.datastructure.DataCubeContainer; import com.raytheon.uf.viz.core.rsc.DisplayType; import com.raytheon.uf.viz.core.rsc.LoadProperties; @@ -70,6 +74,8 @@ import com.raytheon.viz.grid.rsc.GridResourceData; */ public class GridProductBrowserDataDefinition extends AbstractRequestableProductBrowserDataDefinition { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(GridProductBrowserDataDefinition.class); private static final String SHOW_UNKNOWN_MODELS = "Show Unknown Models"; @@ -166,27 +172,32 @@ public class GridProductBrowserDataDefinition extends e.printStackTrace(); } LevelFactory lf = LevelFactory.getInstance(); - if (selection.length > 3) { - List availLevels = new ArrayList(); - for (String levelid : returnQueue) { - Level level = lf.getLevel(levelid); - if (level.getMasterLevel().getName().equals(selection[3])) { - availLevels.add(levelid); + try { + if (selection.length > 3) { + List availLevels = new ArrayList(); + for (String levelid : returnQueue) { + Level level = lf.getLevel(levelid); + if (level.getMasterLevel().getName().equals(selection[3])) { + availLevels.add(levelid); + } } + return formatData(GridInventory.LEVEL_ID_QUERY, + availLevels.toArray(new String[availLevels.size()])); + } else { + Set masterLevels = new HashSet(); + for (String levelid : returnQueue) { + Level level = lf.getLevel(levelid); + masterLevels.add(level.getMasterLevel().getName()); + } + List results = formatData( + GridInventory.MASTER_LEVEL_QUERY, + masterLevels.toArray(new String[masterLevels.size()])); + Collections.sort(results); + return results; } - return formatData(GridInventory.LEVEL_ID_QUERY, - availLevels.toArray(new String[availLevels.size()])); - } else { - Set masterLevels = new HashSet(); - for (String levelid : returnQueue) { - Level level = lf.getLevel(levelid); - masterLevels.add(level.getMasterLevel().getName()); - } - List results = formatData( - GridInventory.MASTER_LEVEL_QUERY, - masterLevels.toArray(new String[masterLevels.size()])); - Collections.sort(results); - return results; + } catch (CommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + return super.populateData(selection); } } @@ -249,8 +260,13 @@ public class GridProductBrowserDataDefinition extends } else if (GridInventory.LEVEL_ID_QUERY.equals(param)) { Level[] levels = new Level[parameters.length]; LevelFactory lf = LevelFactory.getInstance(); - for (int i = 0; i < levels.length; i++) { - levels[i] = lf.getLevel(parameters[i]); + try { + for (int i = 0; i < levels.length; i++) { + levels[i] = lf.getLevel(parameters[i]); + } + } catch (CommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); } Arrays.sort(levels, levelComparator); for (int i = 0; i < parameters.length; i++) { @@ -264,10 +280,15 @@ public class GridProductBrowserDataDefinition extends return labels; } else if (GridInventory.MASTER_LEVEL_QUERY.equals(param)) { LevelFactory lf = LevelFactory.getInstance(); - for (int i = 0; i < parameters.length; i++) { - MasterLevel masterLevel = lf.getMasterLevel(parameters[i]); - labels.add(new ProductBrowserLabel( - masterLevel.getDescription(), masterLevel.getName())); + try { + for (int i = 0; i < parameters.length; i++) { + MasterLevel masterLevel = lf.getMasterLevel(parameters[i]); + labels.add(new ProductBrowserLabel(masterLevel + .getDescription(), masterLevel.getName())); + } + } catch (CommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); } } return super.formatData(param, parameters); @@ -281,14 +302,18 @@ public class GridProductBrowserDataDefinition extends } HashMap queryList = super .getProductParameters(selection, order); + try { + // Convert Level id to level one and level two values. + Level level = LevelFactory.getInstance().getLevel(selection[4]); + queryList.put(GridInventory.LEVEL_ONE_QUERY, new RequestConstraint( + level.getLevelOneValueAsString())); + queryList.put(GridInventory.LEVEL_TWO_QUERY, new RequestConstraint( + level.getLevelTwoValueAsString())); + queryList.remove(order[4]); + } catch (CommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); - queryList.remove(order[4]); - // Convert Level id to level one and level two values. - Level level = LevelFactory.getInstance().getLevel(selection[4]); - queryList.put(GridInventory.LEVEL_ONE_QUERY, new RequestConstraint( - level.getLevelOneValueAsString())); - queryList.put(GridInventory.LEVEL_TWO_QUERY, new RequestConstraint( - level.getLevelTwoValueAsString())); + } return queryList; } diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/data/RadarRequestableData.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/data/RadarRequestableData.java index 9d13977ca6..df22c50f35 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/data/RadarRequestableData.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/data/RadarRequestableData.java @@ -25,6 +25,7 @@ import java.lang.ref.WeakReference; import javax.measure.converter.UnitConverter; import javax.measure.unit.Unit; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.grib.GribModel; import com.raytheon.uf.common.dataplugin.grib.GribRecord; import com.raytheon.uf.common.dataplugin.grib.spatial.projections.GridCoverage; @@ -37,6 +38,9 @@ import com.raytheon.uf.common.datastorage.IDataStore; import com.raytheon.uf.common.datastorage.Request; import com.raytheon.uf.common.datastorage.records.FloatDataRecord; import com.raytheon.uf.common.datastorage.records.IDataRecord; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.HDF5Util; import com.raytheon.uf.viz.core.drawables.ColorMapParameters; import com.raytheon.uf.viz.core.exception.VizException; @@ -61,6 +65,8 @@ import com.raytheon.viz.radar.util.DataUtilities; */ public class RadarRequestableData extends GribRequestableData { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(RadarRequestableData.class); private RadarRecord radarSource; @@ -80,8 +86,13 @@ public class RadarRequestableData extends GribRequestableData { RadarAdapter.getGridSpacing()); this.source = "radar"; this.dataTime = source.getDataTime(); - this.level = LevelFactory.getInstance().getLevel("TILT", - source.getPrimaryElevationAngle()); + try { + this.level = LevelFactory.getInstance().getLevel("TILT", + source.getPrimaryElevationAngle()); + } catch (CommunicationException e1) { + statusHandler + .handle(Priority.PROBLEM, e1.getLocalizedMessage(), e1); + } this.parameter = parameterAbbrev; this.parameterName = ""; this.unit = unit; @@ -146,14 +157,12 @@ public class RadarRequestableData extends GribRequestableData { fdr.setDimension(2); cache = new WeakReference(fdr); } - if (arg == null) { - return new IDataRecord[] { fdr }; - } else if (arg instanceof Request) { + if (arg instanceof Request) { fdr = SliceUtil.slice(fdr, (Request) arg); return new IDataRecord[] { fdr }; + } else { + return new IDataRecord[] { fdr }; } - throw new VizException(this.getClass().getSimpleName() - + " cannot process request of type: " - + arg.getClass().getSimpleName()); + } } diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/data/StaticGridRequestableData.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/data/StaticGridRequestableData.java index b1224e25db..a5a72b9e01 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/data/StaticGridRequestableData.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/data/StaticGridRequestableData.java @@ -21,6 +21,7 @@ package com.raytheon.viz.grid.data; import javax.measure.unit.SI; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.grib.spatial.projections.GridCoverage; import com.raytheon.uf.common.dataplugin.grib.util.GribModelLookup; import com.raytheon.uf.common.dataplugin.grib.util.GridModel; @@ -29,6 +30,9 @@ import com.raytheon.uf.common.dataplugin.grib.util.StaticGridDataType; import com.raytheon.uf.common.dataplugin.level.LevelFactory; import com.raytheon.uf.common.datastorage.Request; import com.raytheon.uf.common.datastorage.records.FloatDataRecord; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.derivparam.data.AbstractRequestableData; import com.raytheon.viz.grid.util.CoverageUtils; @@ -51,6 +55,9 @@ import com.raytheon.viz.grid.util.SliceUtil; */ public class StaticGridRequestableData extends AbstractRequestableData { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(StaticGridRequestableData.class); + private StaticGridDataType dataType; public StaticGridRequestableData(StaticGridDataType dataType, String source) { @@ -63,7 +70,11 @@ public class StaticGridRequestableData extends AbstractRequestableData { } else { this.unit = SI.METER; } - this.level = LevelFactory.getInstance().getLevel("SFC", 0.0); + try { + this.level = LevelFactory.getInstance().getLevel("SFC", 0.0); + } catch (CommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + } } /* @@ -107,13 +118,11 @@ public class StaticGridRequestableData extends AbstractRequestableData { break; } } - if (arg == null) { - return rval; - } else if (arg instanceof Request) { + if (arg instanceof Request) { return SliceUtil.slice(rval, (Request) arg); + } else { + return rval; } - throw new VizException(this.getClass().getSimpleName() - + " cannot process request of type: " - + arg.getClass().getSimpleName()); + } } \ No newline at end of file diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/data/TopoRequestableData.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/data/TopoRequestableData.java index 5ad8c7baca..8bf10dbf3d 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/data/TopoRequestableData.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/data/TopoRequestableData.java @@ -26,10 +26,14 @@ import javax.measure.unit.SI; import org.geotools.coverage.grid.GridGeometry2D; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.grib.spatial.projections.GridCoverage; import com.raytheon.uf.common.dataplugin.level.LevelFactory; import com.raytheon.uf.common.datastorage.Request; import com.raytheon.uf.common.datastorage.records.FloatDataRecord; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.topo.TopoQuery; import com.raytheon.uf.viz.derivparam.data.AbstractRequestableData; @@ -53,6 +57,9 @@ import com.raytheon.viz.grid.util.SliceUtil; */ public class TopoRequestableData extends AbstractRequestableData { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(TopoRequestableData.class); + // need to move to a static timed cache private static Map topoCache = new HashMap(); @@ -61,7 +68,11 @@ public class TopoRequestableData extends AbstractRequestableData { this.parameter = "staticTopo"; this.parameterName = "Topography"; this.unit = SI.METER; - this.level = LevelFactory.getInstance().getLevel("SFC", 0.0); + try { + this.level = LevelFactory.getInstance().getLevel("SFC", 0.0); + } catch (CommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + } } /* @@ -85,13 +96,10 @@ public class TopoRequestableData extends AbstractRequestableData { topoCache.put(coverage, rval); } } - if (arg == null) { - return rval; - } else if (arg instanceof Request) { + if (arg instanceof Request) { return SliceUtil.slice(rval, (Request) arg); + } else { + return rval; } - throw new VizException(this.getClass().getSimpleName() - + " cannot process request of type: " - + arg.getClass().getSimpleName()); } } diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/GribRequestableLevelNode.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/GribRequestableLevelNode.java index 3b3dfbf3d1..d3017cd74d 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/GribRequestableLevelNode.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/GribRequestableLevelNode.java @@ -116,7 +116,8 @@ public class GribRequestableLevelNode extends AbstractRequestableLevelNode { } @Override - public Set timeQueryInternal(boolean latestOnly, + public Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { @@ -145,7 +146,8 @@ public class GribRequestableLevelNode extends AbstractRequestableLevelNode { * getTimeQueryInternal(boolean, java.util.Map) */ @Override - protected TimeQueryRequest getTimeQueryInternal(boolean latestOnly, + protected TimeQueryRequest getTimeQueryInternal( + TimeQueryRequest originalRequest, boolean latestOnly, Map> cache) throws VizException { Set resultsSet = GribTimeCache.getInstance().getTimes(this); diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/GridInventory.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/GridInventory.java index 7f91e14869..ac9eb491c5 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/GridInventory.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/GridInventory.java @@ -131,7 +131,8 @@ public class GridInventory extends AbstractInventory implements private List> failedRequests = new ArrayList>(); @Override - public void initTree(Map derParLibrary) { + public void initTree(Map derParLibrary) + throws VizException { super.initTree(derParLibrary); if (updater == null) { updater = new GridUpdater(this); @@ -144,31 +145,28 @@ public class GridInventory extends AbstractInventory implements } public void reinitTree() { - initTree(derParLibrary); - // reprocess all failed requests to see if data has become available. - List> constraintsToTry = this.failedRequests; - this.failedRequests = new ArrayList>( - failedRequests.size()); - for (Map constraints : constraintsToTry) { - evaluateRequestConstraints(constraints); + try { + initTree(derParLibrary); + // reprocess all failed requests to see if data has become + // available. + List> constraintsToTry = this.failedRequests; + this.failedRequests = new ArrayList>( + failedRequests.size()); + for (Map constraints : constraintsToTry) { + evaluateRequestConstraints(constraints); + } + } catch (VizException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); } } - private DataTree getTreeFromEdex() { + private DataTree getTreeFromEdex() throws VizException { String request = "from com.raytheon.edex.uengine.tasks.grib import GridCatalog\n" + "from com.raytheon.uf.common.message.response import ResponseMessageGeneric\n" + "test = GridCatalog()\n" + "return ResponseMessageGeneric(test.execute())"; Object[] tree = null; - try { - tree = Connector.getInstance().connect(request, null, 60000); - } catch (VizCommunicationException e) { - statusHandler.handle(Priority.PROBLEM, - "Error communicating with server.", e); - } catch (VizException e) { - statusHandler.handle(Priority.PROBLEM, - "Error occurred while retrieving grid tree.", e); - } + tree = Connector.getInstance().connect(request, null, 60000); if (tree != null) { return (DataTree) tree[0]; } @@ -265,7 +263,7 @@ public class GridInventory extends AbstractInventory implements return null; } - protected DataTree createBaseTree() { + protected DataTree createBaseTree() throws VizException { DataTree newTree = getTreeFromEdex(); if (newTree == null) { return newTree; @@ -349,6 +347,7 @@ public class GridInventory extends AbstractInventory implements * @param newGridTree */ private void initAliasModels(DataTree newGridTree) { + Set allAliasModels = new HashSet(); sourceAliases.clear(); GribModelLookup lookup = GribModelLookup.getInstance(); for (String modelName : newGridTree.getSources()) { @@ -357,6 +356,8 @@ public class GridInventory extends AbstractInventory implements SourceNode source = newGridTree.getSourceNode(modelName); SourceNode dest = newGridTree.getSourceNode(model.getAlias()); if (source != null && dest != null) { + allAliasModels.add(source.getValue()); + allAliasModels.add(dest.getValue()); List aliases = sourceAliases.get(dest.getValue()); if (aliases == null) { aliases = new ArrayList(); @@ -367,28 +368,29 @@ public class GridInventory extends AbstractInventory implements } } } - for (Entry> aliases : sourceAliases.entrySet()) { - Collections.sort(aliases.getValue(), new Comparator() { + // Requesting coverages all at once is more efficient + try { + final Map coverages = CoverageUtils + .getInstance().getCoverages(allAliasModels); - @Override - public int compare(String model1, String model2) { - try { - GridCoverage coverage1 = CoverageUtils.getInstance() - .getCoverage(model1); + for (Entry> aliases : sourceAliases.entrySet()) { + Collections.sort(aliases.getValue(), new Comparator() { + + @Override + public int compare(String model1, String model2) { + GridCoverage coverage1 = coverages.get(model1); Integer res1 = coverage1.getNx() * coverage1.getNy(); - GridCoverage coverage2 = CoverageUtils.getInstance() - .getCoverage(model2); + GridCoverage coverage2 = coverages.get(model2); Integer res2 = coverage2.getNx() * coverage2.getNy(); return res2.compareTo(res1); - } catch (VizException e) { - statusHandler.handle(Priority.PROBLEM, - "Unable to create model aliases, problems with " - + model1 + " and " + model2, e); - return 0; } - } - }); + }); + } + } catch (VizException e) { + statusHandler.handle(Priority.PROBLEM, + "Unable to create model aliases", e); + return; } } @@ -449,6 +451,28 @@ public class GridInventory extends AbstractInventory implements public List getPerts(Map query) throws VizException { + RequestConstraint nameRC = query.get(MODEL_NAME_QUERY); + if (nameRC == null) { + // Only bother grabbing nodes with perts + nameRC = new RequestConstraint(null, ConstraintType.IN); + nameRC.setConstraintValueList(modelsWithPerts + .toArray(new String[0])); + query = new HashMap(query); + query.put(MODEL_NAME_QUERY, nameRC); + } else { + boolean hasPerts = false; + for (String modelName : modelsWithPerts) { + if (nameRC.evaluate(modelName)) { + hasPerts = true; + break; + } + } + // If this query is not valid for any models with perts then it has + // no perts, don't bother with a query. + if (!hasPerts) { + return Collections.emptyList(); + } + } Set perts = new HashSet(); for (AbstractRequestableLevelNode node : evaluateRequestConstraints(query)) { perts.addAll(getPerts(node)); @@ -459,7 +483,6 @@ public class GridInventory extends AbstractInventory implements protected static List getPerts(AbstractRequestableLevelNode node) throws VizException { - if (node instanceof GribRequestableLevelNode) { GribRequestableLevelNode gNode = (GribRequestableLevelNode) node; if (gNode.getPerts() != null) { @@ -613,7 +636,8 @@ public class GridInventory extends AbstractInventory implements @Override protected LevelNode getCubeNode(SourceNode sNode, DerivParamField field, - Deque stack, Set nodata) { + Deque stack, Set nodata) + throws VizCommunicationException { StackEntry se = new StackEntry(sNode.getValue(), field.getParam(), Long.MIN_VALUE); if (stack.contains(se)) { @@ -628,8 +652,14 @@ public class GridInventory extends AbstractInventory implements String masterLevelName = get3DMasterLevel(sNode.getValue()); boolean isRadar = sNode.getValue().equals(RadarAdapter.RADAR_SOURCE); - NavigableSet levels = LevelUtilities - .getOrderedSetOfStandardLevels(masterLevelName); + NavigableSet levels = null; + try { + levels = LevelUtilities + .getOrderedSetOfStandardLevels(masterLevelName); + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + return null; + } List> cubeLevels = new ArrayList>( levels.size()); diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/GridUpdater.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/GridUpdater.java index c89b400566..a828ac2f1b 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/GridUpdater.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/GridUpdater.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Set; import com.raytheon.edex.util.Util; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.PluginException; import com.raytheon.uf.common.dataplugin.grib.GribModel; import com.raytheon.uf.common.dataplugin.grib.GribRecord; @@ -215,11 +216,18 @@ public class GridUpdater implements IAlertObserver { } GribMapKey updateKey = new GribMapKey(alert.decodedAlert); GribTimeCache.getInstance().clearTimes(updateKey); - Level level = LevelFactory.getInstance().getLevel( - updateKey.masterLevel, updateKey.levelone, - updateKey.leveltwo); - LevelNode lNode = inventory.getNode(updateKey.modelName, - updateKey.parameter, level); + LevelNode lNode = null; + try { + Level level = LevelFactory.getInstance().getLevel( + updateKey.masterLevel, updateKey.levelone, + updateKey.leveltwo); + lNode = inventory.getNode(updateKey.modelName, + updateKey.parameter, level); + } catch (CommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); + } + if (lNode == null) { inventory.reinitTree(); // System.out.println(alert.dataURI); diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/ImportLevelNode.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/ImportLevelNode.java index 097b4f1832..14bc0db057 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/ImportLevelNode.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/ImportLevelNode.java @@ -31,6 +31,7 @@ import java.util.TreeSet; import com.raytheon.uf.common.dataplugin.grib.util.GribModelLookup; import com.raytheon.uf.common.dataplugin.grib.util.GridModel; import com.raytheon.uf.common.dataplugin.level.Level; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.catalog.LayerProperty; import com.raytheon.uf.viz.core.exception.VizException; @@ -148,7 +149,8 @@ public class ImportLevelNode extends AbstractAliasLevelNode { } @Override - public Set timeQueryInternal(boolean latestOnly, + public Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { @@ -158,7 +160,8 @@ public class ImportLevelNode extends AbstractAliasLevelNode { // then see what is available in the imported source, use time // interpolation to verify what data can be achieved NavigableSet sourceDataTimes = new TreeSet( - sourceNode.timeQuery(latestOnly, cache, latestOnlyCache)); + sourceNode.timeQuery(originalRequest, latestOnly, cache, + latestOnlyCache)); GridModel sourceModel = GribModelLookup.getInstance().getModelByName( sourceNodeModelName); long sourceDt = 0; diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/RadarRequestableLevelNode.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/RadarRequestableLevelNode.java index 443708f14e..371fc5cc46 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/RadarRequestableLevelNode.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/RadarRequestableLevelNode.java @@ -121,7 +121,8 @@ public class RadarRequestableLevelNode extends AbstractRequestableLevelNode { } @Override - public Set timeQueryInternal(boolean latestOnly, + public Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { @@ -147,7 +148,8 @@ public class RadarRequestableLevelNode extends AbstractRequestableLevelNode { } @Override - protected TimeQueryRequest getTimeQueryInternal(boolean latestOnly, + protected TimeQueryRequest getTimeQueryInternal( + TimeQueryRequest originalRequest, boolean latestOnly, Map> cache) throws VizException { // TODO Auto-generated method stub diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/RadarUpdater.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/RadarUpdater.java index 1476fd5dfd..2544f574d4 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/RadarUpdater.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/inv/RadarUpdater.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.PluginException; import com.raytheon.uf.common.dataplugin.grib.GribModel; import com.raytheon.uf.common.dataplugin.grib.GribRecord; @@ -157,8 +158,14 @@ public class RadarUpdater implements IAlertObserver { } Double elevationAngle = (Double) obj; cache.remove(new CacheKey(productCode, elevationAngle)); - Level level = LevelFactory.getInstance().getLevel( - RadarAdapter.CUBE_MASTER_LEVEL_NAME, elevationAngle); + Level level = null; + try { + level = LevelFactory.getInstance().getLevel( + RadarAdapter.CUBE_MASTER_LEVEL_NAME, elevationAngle); + } catch (CommunicationException e1) { + statusHandler.handle(Priority.PROBLEM, + e1.getLocalizedMessage(), e1); + } GribRecord fakeRec = new GribRecord(); fakeRec.setPluginName("grib"); fakeRec.setDataTime(time); diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/rsc/GridNameGenerator.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/rsc/GridNameGenerator.java index 5bd44574ec..325d21bc54 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/rsc/GridNameGenerator.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/rsc/GridNameGenerator.java @@ -22,6 +22,7 @@ package com.raytheon.viz.grid.rsc; import com.raytheon.uf.common.dataplugin.grib.GribModel; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.time.DataTime; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; import com.raytheon.uf.viz.core.level.LevelMapping; import com.raytheon.uf.viz.core.level.LevelMappingFactory; import com.raytheon.uf.viz.core.rsc.AbstractNameGenerator; @@ -118,12 +119,17 @@ public class GridNameGenerator extends AbstractNameGenerator { } private String lookupPlane(Level level) { - LevelMapping mapping = LevelMappingFactory.getInstance() - .getLevelMappingForLevel(level); - if (mapping == null) { + try { + LevelMapping mapping = LevelMappingFactory.getInstance() + .getLevelMappingForLevel(level); + if (mapping == null) { + return level.getMasterLevel().getName(); + } + return mapping.getDisplayName(); + } catch (VizCommunicationException e) { return level.getMasterLevel().getName(); + } - return mapping.getDisplayName(); } public void setPlaneLabelString(String planeLabelString) { diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/rsc/GriddedIconDisplay.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/rsc/GriddedIconDisplay.java index 76aeca74b4..7e27c43582 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/rsc/GriddedIconDisplay.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/rsc/GriddedIconDisplay.java @@ -29,8 +29,6 @@ import java.util.Map; import org.eclipse.swt.graphics.RGB; import org.geotools.coverage.grid.GeneralGridGeometry; -import com.raytheon.uf.viz.core.DrawableImage; -import com.raytheon.uf.viz.core.PixelCoverage; import com.raytheon.uf.viz.core.data.prep.IODataPreparer; import com.raytheon.uf.viz.core.drawables.IImage; import com.raytheon.uf.viz.core.drawables.PaintProperties; @@ -38,6 +36,8 @@ import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.map.IMapDescriptor; import com.raytheon.viz.core.contours.rsc.displays.AbstractGriddedDisplay; import com.raytheon.viz.pointdata.PointIconFactory; +import com.raytheon.viz.pointdata.drawables.IPointImageExtension; +import com.raytheon.viz.pointdata.drawables.IPointImageExtension.PointImage; import com.vividsolutions.jts.geom.Coordinate; /** @@ -160,17 +160,18 @@ public class GriddedIconDisplay extends AbstractGriddedDisplay { @Override protected void paint(PaintProperties paintProps, Collection renderables) throws VizException { - List images = new ArrayList(); + List images = new ArrayList(); for (GridCellRenderable renderable : renderables) { if (renderable.resource != empty) { - images.add(new DrawableImage(renderable.resource, - new PixelCoverage(renderable.plotLocation, - renderable.adjustedSize, - renderable.adjustedSize))); + PointImage image = new PointImage(renderable.resource, + renderable.plotLocation); + image.setHeight((double) size * magnification); + image.setWidth((double) size * magnification); + images.add(image); } } - target.drawRasters(paintProps, - images.toArray(new DrawableImage[images.size()])); + target.getExtension(IPointImageExtension.class).drawPointImages( + paintProps, images); } } diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/util/CoverageUtils.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/util/CoverageUtils.java index 9c1c11864f..adab327886 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/util/CoverageUtils.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/util/CoverageUtils.java @@ -22,8 +22,11 @@ package com.raytheon.viz.grid.util; import java.awt.RenderingHints; import java.awt.image.Raster; import java.awt.image.RenderedImage; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.media.jai.BorderExtender; @@ -40,6 +43,7 @@ import org.geotools.coverage.processing.Operations; import org.opengis.geometry.Envelope; import com.raytheon.uf.common.dataplugin.grib.request.GetCoverageRequest; +import com.raytheon.uf.common.dataplugin.grib.request.GetCoveragesRequest; import com.raytheon.uf.common.dataplugin.grib.spatial.projections.GridCoverage; import com.raytheon.uf.common.datastorage.records.FloatDataRecord; import com.raytheon.uf.common.geospatial.MapUtil; @@ -79,28 +83,56 @@ public class CoverageUtils { } public GridCoverage getCoverage(String modelName) throws VizException { - GridCoverage rval = coverageCache.get(modelName); + synchronized (coverageCache) { + GridCoverage rval = coverageCache.get(modelName); - if (rval == null) { - GetCoverageRequest request = new GetCoverageRequest(); - request.setModelName(modelName); - Object obj = ThriftClient.sendRequest(request); + if (rval == null) { + GetCoverageRequest request = new GetCoverageRequest(); + request.setModelName(modelName); + Object obj = ThriftClient.sendRequest(request); - if (obj != null) { - if (obj instanceof GridCoverage) { - rval = (GridCoverage) obj; - coverageCache.put(modelName, rval); + if (obj != null) { + if (obj instanceof GridCoverage) { + rval = (GridCoverage) obj; + coverageCache.put(modelName, rval); + } else { + throw new VizException( + "GetCoverageRequest returned object of type [" + + obj.getClass().getName() + + "], expected [" + + GridCoverage.class.getName() + "]"); + } + } + } + return rval; + } + } + + public Map getCoverages(Collection modelNames) + throws VizException { + Map coverages = new HashMap(); + List toRequest = new ArrayList(); + synchronized (coverageCache) { + for (String modelName : modelNames) { + GridCoverage coverage = coverageCache.get(modelName); + if (coverage == null) { + toRequest.add(modelName); } else { - throw new VizException( - "GetCoverageRequest returned object of type [" - + obj.getClass().getName() - + "], expected [" - + GridCoverage.class.getName() + "]"); + coverages.put(modelName, coverage); + } + } + if (!toRequest.isEmpty()) { + GetCoveragesRequest request = new GetCoveragesRequest(); + request.setModelNames(toRequest); + List list = (List) ThriftClient.sendRequest(request); + for (int i = 0; i < list.size(); i++) { + coverageCache.put(toRequest.get(i), + (GridCoverage) list.get(i)); + coverages.put(toRequest.get(i), (GridCoverage) list.get(i)); } } } - - return rval; + return coverages; } /** diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/util/GribDataCubeAdapter.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/util/GribDataCubeAdapter.java index 78ff2716ce..65d262f199 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/util/GribDataCubeAdapter.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/util/GribDataCubeAdapter.java @@ -24,30 +24,19 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import java.util.regex.Pattern; import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.PluginException; -import com.raytheon.uf.common.dataplugin.grib.GribModel; import com.raytheon.uf.common.dataplugin.grib.GribRecord; -import com.raytheon.uf.common.dataquery.requests.DbQueryRequest; -import com.raytheon.uf.common.dataquery.requests.DbQueryRequestSet; import com.raytheon.uf.common.dataquery.requests.RequestConstraint; -import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintType; -import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; -import com.raytheon.uf.common.dataquery.requests.TimeQueryRequestSet; -import com.raytheon.uf.common.dataquery.responses.DbQueryResponse; -import com.raytheon.uf.common.dataquery.responses.DbQueryResponseSet; import com.raytheon.uf.common.datastorage.DataStoreFactory; import com.raytheon.uf.common.datastorage.IDataStore; import com.raytheon.uf.common.datastorage.Request; @@ -55,20 +44,19 @@ import com.raytheon.uf.common.datastorage.records.FloatDataRecord; import com.raytheon.uf.common.datastorage.records.IDataRecord; import com.raytheon.uf.common.geospatial.ISpatialEnabled; import com.raytheon.uf.common.geospatial.ISpatialObject; -import com.raytheon.uf.common.pointdata.PointDataContainer; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.HDF5Util; import com.raytheon.uf.viz.core.catalog.LayerProperty; import com.raytheon.uf.viz.core.datastructure.CubeUtil; -import com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter; import com.raytheon.uf.viz.core.datastructure.VizDataCubeException; import com.raytheon.uf.viz.core.exception.VizException; -import com.raytheon.uf.viz.core.requests.ThriftClient; +import com.raytheon.uf.viz.derivparam.data.AbstractDataCubeAdapter; import com.raytheon.uf.viz.derivparam.data.AbstractRequestableData; -import com.raytheon.uf.viz.derivparam.library.DerivParamDesc; import com.raytheon.uf.viz.derivparam.library.DerivedParameterGenerator; import com.raytheon.uf.viz.derivparam.tree.AbstractRequestableLevelNode; -import com.raytheon.uf.viz.derivparam.tree.AbstractRequestableLevelNode.Dependency; import com.raytheon.viz.grid.data.GribRequestableData; import com.raytheon.viz.grid.inv.GridInventory; import com.raytheon.viz.grid.record.RequestableDataRecord; @@ -88,254 +76,43 @@ import com.raytheon.viz.grid.record.RequestableDataRecord; * @author brockwoo * @version 1.0 */ -public class GribDataCubeAdapter implements IDataCubeAdapter { +public class GribDataCubeAdapter extends AbstractDataCubeAdapter { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(GribDataCubeAdapter.class); - private static final String DERIVED = "DERIVED"; + public GribDataCubeAdapter() { + super(new String[] { "grib" }); + } private GridInventory gridInventory; - private Map derParLibrary; - - protected void getTimeQuery( - AbstractRequestableLevelNode req, - boolean latestOnly, - LinkedHashMap queries, - Map> cache, - Map> latestOnlyCache) - throws VizException { - List depends = req.getDependencies(); - if (depends.isEmpty()) { - // is source node - TimeQueryRequest myQ = req.getTimeQuery(latestOnly, cache, - latestOnlyCache); - if (myQ != null) { - // no need to merge timeQueries - queries.put(req, myQ); - } - } else { - for (Dependency dep : depends) { - // TODO: Optimize dTime/fTime to use bulk query mechanism, - // small case that is a not easy to get right with a bulk - // query - if (dep.timeOffset == 0 || !latestOnly) { - getTimeQuery(dep.node, latestOnly, queries, cache, - latestOnlyCache); - } - } - } - } - - @Override - public String[] getSupportedPlugins() { - return new String[] { "grib" }; - } - - @Override - public String recordKeyGenerator(PluginDataObject pdo) { - if (pdo instanceof GribRecord) { - GribModel modelInfo = ((GribRecord) pdo).getModelInfo(); - return DERIVED + modelInfo.getModelName() - + modelInfo.getParameterName() + modelInfo.getLevelName() - + modelInfo.getLevelInfo() + pdo.getDataTime().toString(); - } - return null; - } - - @Override - public IDataRecord[] getRecord(PluginDataObject obj) - throws VizDataCubeException { - return getRecord(obj, Request.ALL, null); - - } - - @Override - public List getData(LayerProperty property, int timeOut) - throws VizException { - List requests = gridInventory - .evaluateRequestConstraints(property - .getEntryQueryParameters(false)); - int mapSize = (int) (requests.size() * 1.25) + 1; - Map> cache = new HashMap>( - mapSize); - LinkedHashMap queries = new LinkedHashMap( - mapSize); - for (AbstractRequestableLevelNode req : requests) { - getDataQuery(req, property, timeOut, queries, cache); - } - DbQueryRequestSet reqSet = new DbQueryRequestSet(); - reqSet.setQueries(queries.values().toArray( - new DbQueryRequest[queries.size()])); - DbQueryResponseSet qSetResponse = (DbQueryResponseSet) ThriftClient - .sendRequest(reqSet); - DbQueryResponse[] qResponses = qSetResponse.getResults(); - int index = 0; - for (AbstractRequestableLevelNode node : queries.keySet()) { - // put results into cache - node.setDataQueryResults(qResponses[index++], cache); - } - - // pull the actual results from the cache - List requesters = new ArrayList( - requests.size()); - for (AbstractRequestableLevelNode request : requests) { - requesters.addAll(request.getData(property, timeOut, cache)); - } - - List results = new ArrayList(requesters.size()); - - for (AbstractRequestableData requester : requesters) { - if (requester.getDataTime() == null) { - DataTime[] entryTime = property.getSelectedEntryTime(); - if (entryTime != null && entryTime.length > 0) { - List entryTimes = new ArrayList( - Arrays.asList(entryTime)); - for (DataTime time : entryTimes) { - GribRecord rec = new RequestableDataRecord(requester); - rec.setDataTime(time.clone()); - try { - rec.setDataURI(null); - rec.constructDataURI(); - } catch (PluginException e) { - throw new VizException(e); - } - boolean n = true; - for (Object result : results) { - if (((GribRecord) result).getDataURI().equals( - rec.getDataURI())) { - n = false; - } - } - if (n) { - results.add(rec); - } - } - } else { - GribRecord rec = new RequestableDataRecord(requester); - rec.setDataTime(new DataTime(Calendar.getInstance())); - results.add(rec); - } - } else { - GribRecord rec = new RequestableDataRecord(requester); - results.add(rec); - } - } - if (property.getEntryQueryParameters(false).containsKey( - GridInventory.PERT_QUERY)) { - String pert = property.getEntryQueryParameters(false) - .get(GridInventory.PERT_QUERY).getConstraintValue(); - if (pert != null) { - for (Object rec : results) { - ((GribRecord) rec).getModelInfo().setPerturbationNumber( - Integer.parseInt(pert)); - } - } - } - return results; - } - - protected void getDataQuery( - AbstractRequestableLevelNode req, - LayerProperty property, - int timeOut, - LinkedHashMap queries, - Map> cache) - throws VizException { - List depends = req.getDependencies(); - if (depends.isEmpty()) { - // is source node - DbQueryRequest myQ = req.getDataQuery(property, timeOut, cache); - if (myQ != null) { - addDataQuery(req, myQ, queries); - } - } else { - for (Dependency dep : depends) { - // TODO: Optimize dTime/fTime to use bulk query mechanism, - // small case that is a not easy to get right with a bulk - // query - if (dep.timeOffset == 0) { - getDataQuery(dep.node, property, timeOut, queries, cache); - } - } - } - } - - private void addDataQuery(AbstractRequestableLevelNode req, - DbQueryRequest query, - LinkedHashMap queries) { - DbQueryRequest curQuery = queries.get(req); - if (curQuery == null) { - queries.put(req, query); - } else { - // merge - // assume same DB, fields, etc, should only be different - // time constraints since its the same node - RequestConstraint curDTs = curQuery.getConstraints() - .get("dataTime"); - RequestConstraint myDTs = query.getConstraints().get("dataTime"); - if (curDTs != null && myDTs != null) { - // only merge if both require dataTimes, otherwise one - // would be constrained when it needs everything, also - // assuming both to be in lists and needing to be merged - curDTs.setConstraintType(ConstraintType.IN); - Pattern split = Pattern.compile(","); - - String[] curVals = split.split(curDTs.getConstraintValue()); - String[] myVals = split.split(myDTs.getConstraintValue()); - HashSet dups = new HashSet(curVals.length - + myVals.length); - dups.addAll(Arrays.asList(curVals)); - dups.addAll(Arrays.asList(myVals)); - curDTs.setConstraintValueList(dups.toArray(new String[dups - .size()])); - } - } - } - @Override public void initInventory() { - derParLibrary = DerivedParameterGenerator.getDerParLibrary(); if (gridInventory == null) { GridInventory gridInventory = new GridInventory(); - gridInventory.initTree(derParLibrary); - this.gridInventory = gridInventory; + try { + gridInventory.initTree(DerivedParameterGenerator + .getDerParLibrary()); + this.gridInventory = gridInventory; + } catch (VizException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); + } } } @Override public Object getInventory() { + initInventory(); return gridInventory; } - @Override - public PointDataContainer getPoints(String plugin, String[] parameters, - Map queryParams) { - // TODO Someday we should put objective analysis code - // into this area - return null; - } - - @Override - public PointDataContainer getPoints(String plugin, String[] parameters, - String levelKey, Map queryParams) { - // TODO Someday we should put objective analysis code - // into this area - return null; - } - @Override public IDataRecord[] getRecord(PluginDataObject obj, Request req, String dataset) throws VizDataCubeException { if (obj instanceof RequestableDataRecord) { - try { - getRecords(Arrays.asList(obj), req, dataset); - IDataRecord[] result = (IDataRecord[]) obj.getMessageData(); - obj.setMessageData(null); - return result; - } catch (VizException e) { - throw new VizDataCubeException("Error retrieving grid record.", - e); - } + return super.getRecord(obj, req, dataset); } try { IDataRecord record = null; @@ -591,78 +368,90 @@ public class GribDataCubeAdapter implements IDataCubeAdapter { references.clear(); } + /* + * (non-Javadoc) + * + * @see com.raytheon.uf.viz.derivparam.data.AbstractDataCubeAdapter# + * evaluateRequestConstraints(java.util.Map) + */ @Override - public List> getBaseUpdateConstraints( + protected List evaluateRequestConstraints( Map constraints) { - List> result = new ArrayList>( - 1); - result.add(constraints); - return result; + return gridInventory.evaluateRequestConstraints(constraints); } + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.derivparam.data.AbstractDataCubeAdapter#timeAgnosticQuery + * (java.util.Map) + */ @Override - public List> timeQuery(List requests) - throws VizException { - int mapSize = (int) (requests.size() * 1) + 1; - Map> cache = new HashMap>( - mapSize); - LinkedHashMap queries = new LinkedHashMap( - mapSize); + protected List timeAgnosticQuery( + Map queryTerms) throws VizException { + return gridInventory.timeAgnosticQuery(queryTerms); + } - for (TimeQueryRequest request : requests) { - List requestNodes = gridInventory - .evaluateRequestConstraints(request.getQueryTerms()); - // pull out time queries and bulk submit - for (AbstractRequestableLevelNode requestNode : requestNodes) { - getTimeQuery(requestNode, false, queries, cache, null); + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.derivparam.data.AbstractDataCubeAdapter#getData(java + * .util.List) + */ + @Override + protected List getData(LayerProperty property, + List requesters) throws VizException { + List results = new ArrayList(requesters.size()); + for (AbstractRequestableData requester : requesters) { + if (requester.getDataTime() == null) { + DataTime[] entryTime = property.getSelectedEntryTime(); + if (entryTime != null && entryTime.length > 0) { + List entryTimes = new ArrayList( + Arrays.asList(entryTime)); + for (DataTime time : entryTimes) { + GribRecord rec = new RequestableDataRecord(requester); + rec.setDataTime(time.clone()); + try { + rec.setDataURI(null); + rec.constructDataURI(); + } catch (PluginException e) { + throw new VizException(e); + } + boolean n = true; + for (Object result : results) { + if (((GribRecord) result).getDataURI().equals( + rec.getDataURI())) { + n = false; + } + } + if (n) { + results.add(rec); + } + } + } else { + GribRecord rec = new RequestableDataRecord(requester); + rec.setDataTime(new DataTime(Calendar.getInstance())); + results.add(rec); + } + } else { + GribRecord rec = new RequestableDataRecord(requester); + results.add(rec); } } - - // set the results back into the cache's - TimeQueryRequestSet reqSet = new TimeQueryRequestSet(); - reqSet.setRequests(queries.values().toArray( - new TimeQueryRequest[queries.size()])); - @SuppressWarnings("unchecked") - List> qResponses = (List>) ThriftClient - .sendRequest(reqSet); - int index = 0; - for (AbstractRequestableLevelNode node : queries.keySet()) { - // put results into cache - node.setTimeQueryResults(false, qResponses.get(index++), cache, - null); - } - List> finalResponse = new ArrayList>( - requests.size()); - for (TimeQueryRequest request : requests) { - List requestNodes = gridInventory - .evaluateRequestConstraints(request.getQueryTerms()); - // pull the actual results from the cache - Set results = new HashSet(64); - for (AbstractRequestableLevelNode requestNode : requestNodes) { - Set times = requestNode.timeQuery(false, cache, null); - if (times == AbstractRequestableLevelNode.TIME_AGNOSTIC) { - // TODO: include time agnostic query in main bulk query as - // each - // pressure level will cause a separate query - List temp = gridInventory - .timeAgnosticQuery(request.getQueryTerms()); - if (temp != null) { - results.addAll(temp); - } - break; - } else { - results.addAll(times); + if (property.getEntryQueryParameters(false).containsKey( + GridInventory.PERT_QUERY)) { + String pert = property.getEntryQueryParameters(false) + .get(GridInventory.PERT_QUERY).getConstraintValue(); + if (pert != null) { + for (Object rec : results) { + ((GribRecord) rec).getModelInfo().setPerturbationNumber( + Integer.parseInt(pert)); } } - if (!request.isMaxQuery() || results.isEmpty()) { - finalResponse.add(new ArrayList(results)); - } else { - ArrayList response = new ArrayList(results); - Collections.sort(response); - finalResponse - .add(Arrays.asList(response.get(response.size() - 1))); - } } - return finalResponse; + return results; } + } diff --git a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/util/RadarAdapter.java b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/util/RadarAdapter.java index 78c0d75788..7d2c2b252a 100644 --- a/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/util/RadarAdapter.java +++ b/cave/com.raytheon.viz.grid/src/com/raytheon/viz/grid/util/RadarAdapter.java @@ -34,6 +34,7 @@ import org.opengis.geometry.DirectPosition; import org.opengis.referencing.crs.ProjectedCRS; import org.opengis.referencing.operation.MathTransform; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.level.LevelFactory; import com.raytheon.uf.common.dataplugin.radar.RadarRecord; @@ -309,7 +310,12 @@ public class RadarAdapter { * @param level */ private void initTopoParam(SourceNode modelNameNode) { - Level sfc = LevelFactory.getInstance().getLevel("SFC", 0.0); + Level sfc = null; + try { + sfc = LevelFactory.getInstance().getLevel("SFC", 0.0); + } catch (CommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + } DerivParamDesc topo = new DerivParamDesc(); topo.setAbbreviation("Topo"); topo.setName("Topography"); diff --git a/cave/com.raytheon.viz.pointdata/META-INF/MANIFEST.MF b/cave/com.raytheon.viz.pointdata/META-INF/MANIFEST.MF index c09543c2e8..5d52f067c9 100644 --- a/cave/com.raytheon.viz.pointdata/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.viz.pointdata/META-INF/MANIFEST.MF @@ -22,10 +22,12 @@ Require-Bundle: org.apache.batik, com.raytheon.uf.common.pointdata;bundle-version="1.12.1174" Bundle-ActivationPolicy: lazy Export-Package: com.raytheon.viz.pointdata, + com.raytheon.viz.pointdata.drawables, com.raytheon.viz.pointdata.rsc, com.raytheon.viz.pointdata.rsc.retrieve, com.raytheon.viz.pointdata.util Import-Package: com.raytheon.edex.meteoLib, + com.raytheon.uf.common.comm, com.raytheon.uf.common.dataplugin.level, com.raytheon.uf.common.derivparam.tree, com.raytheon.uf.common.message.response, diff --git a/cave/com.raytheon.viz.pointdata/plugin.xml b/cave/com.raytheon.viz.pointdata/plugin.xml index d2cd47c5bd..75332bb6e2 100644 --- a/cave/com.raytheon.viz.pointdata/plugin.xml +++ b/cave/com.raytheon.viz.pointdata/plugin.xml @@ -152,4 +152,10 @@ name="Plot Models" category="com.raytheon.uf.viz.productbrowser.productbrowserpreferencespage"/> + + + + diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/IPlotModelGeneratorCaller.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/IPlotModelGeneratorCaller.java index 4aa34375ae..db1ebce4d0 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/IPlotModelGeneratorCaller.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/IPlotModelGeneratorCaller.java @@ -42,5 +42,5 @@ public interface IPlotModelGeneratorCaller { public void clearImages(); - public void messageGenerated(int id, String message); + public void messageGenerated(String dataURI, String message); } diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotAlertParser.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotAlertParser.java index 89f7551497..00a582d0ea 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotAlertParser.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotAlertParser.java @@ -1,19 +1,19 @@ /** * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA * This software product contains export-restricted data whose * export/transfer/disclosure is restricted by U.S. law. Dissemination * to non-U.S. persons whether in the United States or abroad requires * an export license or other authorization. * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ @@ -54,7 +54,7 @@ public class PlotAlertParser extends AbstractAlertMessageParser { Double lat = (Double) message.decodedAlert.get("location.latitude"); Double lon = (Double) message.decodedAlert.get("location.longitude"); DataTime dataTime = (DataTime) message.decodedAlert.get("dataTime"); - return new PlotInfo(message.id, stationId, lat, lon, dataTime, + return new PlotInfo(stationId, lat, lon, dataTime, message.dataURI); } } diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotInfo.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotInfo.java index 9ad6e8d29b..196ec90e15 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotInfo.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotInfo.java @@ -39,8 +39,6 @@ import com.raytheon.uf.common.time.DataTime; public class PlotInfo { - public Integer id; - public String stationId; public Double latitude; @@ -68,9 +66,8 @@ public class PlotInfo { } - public PlotInfo(Integer id, String stationId, Double latitude, + public PlotInfo(String stationId, Double latitude, Double longitude, DataTime dataTime, String dataURI) { - this.id = id; this.stationId = stationId; this.latitude = latitude; this.longitude = longitude; diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelDataDefinition.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelDataDefinition.java index 1240785ba5..e7af85ceba 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelDataDefinition.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelDataDefinition.java @@ -15,6 +15,7 @@ import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.level.LevelFactory; import com.raytheon.uf.common.dataquery.requests.RequestConstraint; @@ -23,8 +24,12 @@ import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.time.BinOffset; import com.raytheon.uf.viz.core.datastructure.DataCubeContainer; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.level.LevelMappingFactory; import com.raytheon.uf.viz.core.map.MapDescriptor; @@ -39,6 +44,8 @@ import com.raytheon.viz.pointdata.util.PointDataInventory; public class PlotModelDataDefinition extends AbstractRequestableProductBrowserDataDefinition { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(PlotModelDataDefinition.class); private static final String PLOTLOCATION = "plotModels"; @@ -271,10 +278,18 @@ public class PlotModelDataDefinition extends } List validLevels = new ArrayList(); for (String levelid : possibleLevels) { - Level level = LevelFactory.getInstance().getLevel( - Long.parseLong(levelid)); - validLevels.add(LevelMappingFactory.getInstance() - .getLevelMappingForLevel(level).getDisplayName()); + try { + Level level = LevelFactory.getInstance().getLevel( + Long.parseLong(levelid)); + validLevels.add(LevelMappingFactory.getInstance() + .getLevelMappingForLevel(level).getDisplayName()); + } catch (CommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); + } } return validLevels.toArray(new String[0]); } diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelDataRequestJob.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelDataRequestJob.java index 03cd2352d4..6203e1cfc5 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelDataRequestJob.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelDataRequestJob.java @@ -166,14 +166,6 @@ public class PlotModelDataRequestJob extends Job { } } - // cleanup - for (PlotInfo[] plotInfoArray : stationQuery) { - for (int i = 0; i < plotInfoArray.length; i++) { - // currently the dataUris are never used again, clear - // them to free up as much memory as possible - plotInfoArray[i].dataURI = null; - } - } } // end of while !stationQueue.isEmpty() return Status.OK_STATUS; @@ -181,7 +173,7 @@ public class PlotModelDataRequestJob extends Job { private void requestData(List stationQuery, List pme) { - Map plotMap = new HashMap(); + Map plotMap = new HashMap(); List params = new ArrayList(); for (PlotModelElement p : pme) { @@ -194,6 +186,10 @@ public class PlotModelDataRequestJob extends Job { } } } + + if(!params.contains("dataURI")){ + params.add("dataURI"); + } Map map = new HashMap(); map.putAll(this.constraintMap); @@ -202,8 +198,8 @@ public class PlotModelDataRequestJob extends Job { List str = new ArrayList(stationQuery.size()); for (PlotInfo[] infos : stationQuery) { for (PlotInfo info : infos) { - str.add(Integer.toString(info.id)); - plotMap.put(info.id, info); + str.add(info.dataURI); + plotMap.put(info.dataURI, info); } } @@ -217,7 +213,7 @@ public class PlotModelDataRequestJob extends Job { index++; j++; } - map.put("id", rc); + map.put("dataURI", rc); try { // Try and get data from datacube long t0 = System.currentTimeMillis(); @@ -241,8 +237,8 @@ public class PlotModelDataRequestJob extends Job { for (int uriCounter = 0; uriCounter < pdc.getAllocatedSz(); uriCounter++) { PointDataView pdv = pdc.readRandom(uriCounter); if (pdv != null) { - int id = pdv.getInt("id"); - PlotInfo info = plotMap.get(id); + String dataURI = pdv.getString("dataURI"); + PlotInfo info = plotMap.get(dataURI); // If the id doesn't match, try to match by // location if (info == null) { @@ -255,8 +251,6 @@ public class PlotModelDataRequestJob extends Job { - pdv.getFloat("longitude")); if (diffLat < 0.01 && diffLon < 0.01) { info = pi; - pdv.setInt("id", pi.id); - id = pi.id; } } } diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelFactory2.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelFactory2.java index a5ae602663..ce0ac0a77e 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelFactory2.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelFactory2.java @@ -569,7 +569,7 @@ public class PlotModelFactory2 { * @return A buffered image representing the station data */ public synchronized BufferedImage getStationPlot(PlotData stationData, - int id, double latitude, double longitude) { + double latitude, double longitude) { double[] stationLocation = { longitude, latitude }; double[] stationPixelLocation = this.mapDescriptor .worldToPixel(stationLocation); @@ -701,7 +701,7 @@ public class PlotModelFactory2 { return null; } - public synchronized String getStationMessage(PlotData stationData, int id) { + public synchronized String getStationMessage(PlotData stationData, String dataURI) { PlotPythonScript script = null; StringBuilder sampleMessage = new StringBuilder(); try { diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelGeneratorJob.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelGeneratorJob.java index 80917adc72..9b9ad1c25d 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelGeneratorJob.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelGeneratorJob.java @@ -21,7 +21,6 @@ package com.raytheon.viz.pointdata; import java.awt.image.BufferedImage; import java.util.Map; -import java.util.UUID; import java.util.concurrent.ConcurrentLinkedQueue; import org.apache.commons.collections.map.LRUMap; @@ -33,8 +32,8 @@ import org.eclipse.core.runtime.jobs.Job; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.viz.core.IGraphicsTarget; -import com.raytheon.uf.viz.core.data.prep.IODataPreparer; import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.drawables.ext.ISingleColorImageExtension; /** * Job separated from PlotModelGenerator2 that creates the plot images. @@ -90,7 +89,7 @@ public class PlotModelGeneratorJob extends Job { try { PlotInfo[] infos = taskQueue.poll(); BufferedImage bImage = plotCreator.getStationPlot(infos[0].pdv, - infos[0].id, infos[0].latitude, infos[0].longitude); + infos[0].latitude, infos[0].longitude); IImage image = null; if (bImage != null) { if (imageCache.containsKey(bImage)) { @@ -102,8 +101,9 @@ public class PlotModelGeneratorJob extends Job { } } if (image == null) { - image = target.initializeRaster(new IODataPreparer( - bImage, UUID.randomUUID().toString(), 0), null); + image = target.getExtension( + ISingleColorImageExtension.class) + .constructImage(bImage, null); if (plotCreator.isCachingImages()) { imageCache.put(bImage, image); } diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/drawables/GeneralPointImageExtension.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/drawables/GeneralPointImageExtension.java new file mode 100644 index 0000000000..1a81bb63d1 --- /dev/null +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/drawables/GeneralPointImageExtension.java @@ -0,0 +1,111 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.pointdata.drawables; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import com.raytheon.uf.viz.core.DrawableImage; +import com.raytheon.uf.viz.core.IGraphicsTarget; +import com.raytheon.uf.viz.core.IGraphicsTarget.HorizontalAlignment; +import com.raytheon.uf.viz.core.IGraphicsTarget.VerticalAlignment; +import com.raytheon.uf.viz.core.PixelCoverage; +import com.raytheon.uf.viz.core.drawables.PaintProperties; +import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension; +import com.raytheon.uf.viz.core.exception.VizException; +import com.vividsolutions.jts.geom.Coordinate; + +/** + * TODO Add Description + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 7, 2011            bsteffen     Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ + +public class GeneralPointImageExtension extends + GraphicsExtension implements IPointImageExtension { + + @Override + public void drawPointImages(PaintProperties paintProps, + PointImage... images) throws VizException { + drawPointImages(paintProps, Arrays.asList(images)); + } + + @Override + public int getCompatibilityValue(IGraphicsTarget target) { + return Compatibilty.GENERIC; + } + + @Override + public void drawPointImages(PaintProperties paintProps, + Collection images) throws VizException { + List drawableImages = new ArrayList( + images.size()); + double xScale = paintProps.getView().getExtent().getWidth() + / paintProps.getCanvasBounds().width; + double yScale = paintProps.getView().getExtent().getHeight() + / paintProps.getCanvasBounds().height; + + for (PointImage image : images) { + Double width = image.getWidth(); + Double height = image.getHeight(); + if (width == null) { + width = (double) image.getImage().getWidth(); + } + if (height == null) { + height = (double) image.getImage().getHeight(); + } + width = width * xScale; + height = height * yScale; + Coordinate center = new Coordinate(image.getX(), image.getY()); + if (image.getHorizontalAlignment().equals(HorizontalAlignment.LEFT)) { + center.x += width / 2; + } else if (image.getHorizontalAlignment().equals( + HorizontalAlignment.RIGHT)) { + center.x -= width / 2; + } + if (image.getVerticalAlignment().equals(VerticalAlignment.TOP)) { + center.y += height / 2; + } else if (image.getVerticalAlignment().equals( + VerticalAlignment.BOTTOM)) { + center.y -= height / 2; + } + PixelCoverage coverage = new PixelCoverage(center, width, height); + DrawableImage drawableImage = new DrawableImage(image.getImage(), + coverage); + drawableImages.add(drawableImage); + } + + target.drawRasters(paintProps, + drawableImages.toArray(new DrawableImage[0])); + } +} diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/drawables/IPointImageExtension.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/drawables/IPointImageExtension.java new file mode 100644 index 0000000000..e164e01300 --- /dev/null +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/drawables/IPointImageExtension.java @@ -0,0 +1,182 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.viz.pointdata.drawables; + +import java.util.Collection; + +import com.raytheon.uf.viz.core.IGraphicsTarget.HorizontalAlignment; +import com.raytheon.uf.viz.core.IGraphicsTarget.VerticalAlignment; +import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.drawables.PaintProperties; +import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension.IGraphicsExtensionInterface; +import com.raytheon.uf.viz.core.exception.VizException; +import com.vividsolutions.jts.geom.Coordinate; + +/** + * An Extension for drawing images at a single point with a constant screen size + * that is independent of the zoom level. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 7, 2011            bsteffen     Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ + +public interface IPointImageExtension extends IGraphicsExtensionInterface { + + public static class PointImage { + + // The image to draw at this point + private IImage image; + + // anchor position x in target coordinates + private double x; + + // anchor position y in target coordinates + private double y; + + // height in screen pixels, if this is not provided the image height is + // used + private Double height = null; + + // width in screen pixels, if this is not provided the image width is + // used + private Double width = null; + + // The alignment relative to x,y + private HorizontalAlignment horizontalAlignment = HorizontalAlignment.CENTER; + + // The alignment relative to x,y + private VerticalAlignment verticalAlignment = VerticalAlignment.MIDDLE; + + // optional field, used to make prettier dispalys in some targets(kml) + private String siteId = null; + + public PointImage() { + + } + + public PointImage(IImage image, double x, double y) { + this.image = image; + this.x = x; + this.y = y; + } + + public PointImage(IImage image, Coordinate c) { + this.image = image; + this.x = c.x; + this.y = c.y; + } + + public Double getHeight() { + return height; + } + + public void setHeight(Double height) { + this.height = height; + } + + public Double getWidth() { + return width; + } + + public void setWidth(Double width) { + this.width = width; + } + + public HorizontalAlignment getHorizontalAlignment() { + return horizontalAlignment; + } + + public void setHorizontalAlignment( + HorizontalAlignment horizontalAlignment) { + this.horizontalAlignment = horizontalAlignment; + } + + public VerticalAlignment getVerticalAlignment() { + return verticalAlignment; + } + + public void setVerticalAlignment(VerticalAlignment verticalAlignment) { + this.verticalAlignment = verticalAlignment; + } + + public IImage getImage() { + return image; + } + + public void setImage(IImage image) { + this.image = image; + } + + public double getX() { + return x; + } + + public void setX(double x) { + this.x = x; + } + + public double getY() { + return y; + } + + public void setY(double y) { + this.y = y; + } + + public void setLocation(Coordinate c) { + this.x = c.x; + this.y = c.y; + } + + public void setLocation(double x, double y) { + this.x = x; + this.y = y; + } + + public String getSiteId() { + return siteId; + } + + public void setSiteId(String siteId) { + this.siteId = siteId; + } + + public boolean hasSiteId() { + return siteId != null; + } + + } + + public void drawPointImages(PaintProperties paintProps, + PointImage... images) throws VizException; + + public void drawPointImages(PaintProperties paintProps, + Collection images) throws VizException; +} diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/PlotResource.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/PlotResource.java index 1d7d3d983a..f787cc7d71 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/PlotResource.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/PlotResource.java @@ -46,8 +46,6 @@ import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.common.time.TimeRange; import com.raytheon.uf.viz.core.IExtent; import com.raytheon.uf.viz.core.IGraphicsTarget; -import com.raytheon.uf.viz.core.IGraphicsTarget.RasterMode; -import com.raytheon.uf.viz.core.PixelCoverage; import com.raytheon.uf.viz.core.PixelExtent; import com.raytheon.uf.viz.core.catalog.CatalogQuery; import com.raytheon.uf.viz.core.drawables.PaintProperties; @@ -65,6 +63,8 @@ import com.raytheon.uf.viz.core.rsc.capabilities.OutlineCapability; import com.raytheon.viz.pointdata.PlotModelGenerator; import com.raytheon.viz.pointdata.StaticPlotInfoPV; import com.raytheon.viz.pointdata.StaticPlotInfoPV.SPIEntry; +import com.raytheon.viz.pointdata.drawables.IPointImageExtension; +import com.raytheon.viz.pointdata.drawables.IPointImageExtension.PointImage; import com.raytheon.viz.pointdata.units.PlotUnits; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Envelope; @@ -328,33 +328,14 @@ public class PlotResource extends } continue; } - this.screenToWorldRatio = paintProps.getCanvasBounds().width - / paintProps.getView().getExtent().getWidth(); - double scaleValue = (this.plotWidth / 2.0) - / screenToWorldRatio; - double[] ul = new double[] { - stationPixelLocation[0] - scaleValue, - stationPixelLocation[1] - scaleValue, 0 }; - double[] ur = new double[] { - stationPixelLocation[0] + scaleValue, - stationPixelLocation[1] - scaleValue, 0 }; - - double[] lr = new double[] { - stationPixelLocation[0] + scaleValue, - stationPixelLocation[1] + scaleValue, 0 }; - - double[] ll = new double[] { - stationPixelLocation[0] - scaleValue, - stationPixelLocation[1] + scaleValue, 0 }; - - PixelCoverage pc = new PixelCoverage(new Coordinate(ul[0], - ul[1], ul[2]), new Coordinate(ur[0], ur[1], ur[2]), - new Coordinate(lr[0], lr[1], lr[2]), - new Coordinate(ll[0], ll[1], ll[2])); - - aTarget.drawRaster(generator.getStation(currentDataUri), - pc, paintProps, RasterMode.SYNCHRONOUS); + PointImage image = new PointImage( + generator.getStation(currentDataUri), + stationPixelLocation[0], stationPixelLocation[1]); + image.setHeight(this.plotWidth); + image.setWidth(this.plotWidth); + aTarget.getExtension(IPointImageExtension.class) + .drawPointImages(paintProps, image); } if (newStations.size() > 0) { generator.queueStations(newStations, paintProps diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/PlotResource2.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/PlotResource2.java index c80ec30d93..a1f15de6e8 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/PlotResource2.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/PlotResource2.java @@ -44,13 +44,11 @@ import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.time.BinOffset; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.common.time.TimeRange; -import com.raytheon.uf.viz.core.DrawableImage; import com.raytheon.uf.viz.core.IGraphicsTarget; -import com.raytheon.uf.viz.core.PixelCoverage; import com.raytheon.uf.viz.core.PixelExtent; import com.raytheon.uf.viz.core.drawables.IImage; import com.raytheon.uf.viz.core.drawables.PaintProperties; -import com.raytheon.uf.viz.core.drawables.SingleColorImage; +import com.raytheon.uf.viz.core.drawables.ext.ISingleColorImageExtension.ISingleColorImage; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.jobs.JobPool; import com.raytheon.uf.viz.core.map.MapDescriptor; @@ -65,6 +63,8 @@ import com.raytheon.viz.pointdata.IPlotModelGeneratorCaller; import com.raytheon.viz.pointdata.PlotAlertParser; import com.raytheon.viz.pointdata.PlotDataThreadPool; import com.raytheon.viz.pointdata.PlotInfo; +import com.raytheon.viz.pointdata.drawables.IPointImageExtension; +import com.raytheon.viz.pointdata.drawables.IPointImageExtension.PointImage; import com.raytheon.viz.pointdata.rsc.progdisc.AbstractProgDisclosure; import com.raytheon.viz.pointdata.rsc.progdisc.AbstractProgDisclosure.IProgDiscListener; import com.raytheon.viz.pointdata.rsc.progdisc.DynamicProgDisclosure; @@ -123,7 +123,7 @@ public class PlotResource2 extends private JobPool frameRetrievalPool = new JobPool("Retrieving plot frame", 8, true); - private TreeMap rawMessageMap = new TreeMap(); + private TreeMap rawMessageMap = new TreeMap(); private class FrameRetriever implements Runnable { @@ -145,7 +145,7 @@ public class PlotResource2 extends public static class Station { public PlotInfo[] info; - public DrawableImage plotImage; + public PointImage plotImage; public Object progDiscInfo; @@ -216,26 +216,19 @@ public class PlotResource2 extends return; } - double screenToWorldRatio = progressiveDisclosure - .getScreenToWorldRatio(); - double scaleValue = (this.plotWidth) / screenToWorldRatio; - - List images = new ArrayList( - stationList.size()); + List images = new ArrayList(stationList.size()); for (Station station : stationList) { if (station.plotImage == null) { continue; } - station.plotImage.setCoverage(new PixelCoverage( - station.pixelLocation, scaleValue, scaleValue)); // set image color so shader can draw in appropriate color - ((SingleColorImage) station.plotImage.getImage()) + ((ISingleColorImage) station.plotImage.getImage()) .setColor(imageColor); images.add(station.plotImage); } - aTarget.drawRasters(paintProps, - images.toArray(new DrawableImage[images.size()])); + aTarget.getExtension(IPointImageExtension.class).drawPointImages( + paintProps, images); } @Override @@ -337,12 +330,13 @@ public class PlotResource2 extends if (stationMap.containsKey(plot.stationId)) { Station existingStation = stationMap.get(plot.stationId); if (existingStation.plotImage != null) { - existingStation.plotImage.dispose(); + existingStation.plotImage.getImage().dispose(); existingStation.plotImage = null; } boolean dup = false; for (int i = 0; i < existingStation.info.length; i++) { - if (existingStation.info[i].id.equals(plot.id)) { + if (existingStation.info[i].dataURI + .equals(plot.dataURI)) { // existingStation.info[i] = plot; dup = true; break; @@ -501,15 +495,15 @@ public class PlotResource2 extends } if (inspectPlot != null) { - int id = inspectPlot[0].id; - if (rawMessageMap.containsKey(id)) { - if (rawMessageMap.get(id) != null) { - message = rawMessageMap.get(id); + String dataURI = inspectPlot[0].dataURI; + if (rawMessageMap.containsKey(dataURI)) { + if (rawMessageMap.get(dataURI) != null) { + message = rawMessageMap.get(dataURI); } } else { message = "Generating..."; synchronized (rawMessageMap) { - rawMessageMap.put(id, message); + rawMessageMap.put(dataURI, message); } List list = new ArrayList(); list.add(inspectPlot); @@ -623,7 +617,7 @@ public class PlotResource2 extends FrameInformation frameInfo = entry.getValue(); for (Station station : frameInfo.stationMap.values()) { if (station.plotImage != null) { - station.plotImage.dispose(); + station.plotImage.getImage().dispose(); station.plotImage = null; if (station.info != null) { @@ -645,8 +639,9 @@ public class PlotResource2 extends Station s = frameInfo.stationMap.get(key[0].stationId); if (s != null) { if (image != null) { - SingleColorImage si = new SingleColorImage(image); - s.plotImage = new DrawableImage(si, null); + ISingleColorImage si = (ISingleColorImage) image; + s.plotImage = new PointImage(si, s.pixelLocation); + s.plotImage.setSiteId(s.info[0].stationId); si.setColor(imageColor); } else { frameInfo.stationMap.remove(key[0].stationId); @@ -669,7 +664,7 @@ public class PlotResource2 extends if (frameInfo != null) { for (Station s : frameInfo.stationMap.values()) { if (s != null && s.plotImage != null) { - s.plotImage.dispose(); + s.plotImage.getImage().dispose(); s.plotImage = null; } } @@ -711,9 +706,9 @@ public class PlotResource2 extends } @Override - public void messageGenerated(int id, String message) { + public void messageGenerated(String dataURI, String message) { synchronized (rawMessageMap) { - rawMessageMap.put(id, message); + rawMessageMap.put(dataURI, message); } issueRefresh(); } diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/retrieve/FullDataPlotInfoRetriever.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/retrieve/FullDataPlotInfoRetriever.java index 0089edf5ad..2398054438 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/retrieve/FullDataPlotInfoRetriever.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/retrieve/FullDataPlotInfoRetriever.java @@ -56,9 +56,6 @@ public class FullDataPlotInfoRetriever extends AbstractPlotInfoRetriever { @XmlAttribute private String parameters; - @XmlAttribute - private String id = "id"; - @XmlAttribute private String stationId = null; @@ -77,7 +74,6 @@ public class FullDataPlotInfoRetriever extends AbstractPlotInfoRetriever { private String[] getParameters() { List parameters = new ArrayList(); parameters.addAll(Arrays.asList(this.parameters.split(","))); - parameters.add(id); if (stationId != null) { parameters.add(stationId); } @@ -86,7 +82,6 @@ public class FullDataPlotInfoRetriever extends AbstractPlotInfoRetriever { parameters.add(validTime); if (fcstTime != null) { parameters.add(fcstTime); - ; } parameters.add("dataURI"); return parameters.toArray(new String[0]); @@ -122,7 +117,6 @@ public class FullDataPlotInfoRetriever extends AbstractPlotInfoRetriever { PointDataView pdv = pdc.readRandom(uriCounter); PlotInfo info = new PlotInfo(); info.pdv.addData(pdv); - info.id = pdv.getInt(id); if (stationId != null) { info.stationId = pdv.getString(stationId); } diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/retrieve/PointDataPlotInfoRetriever.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/retrieve/PointDataPlotInfoRetriever.java index efb535ddb6..600c3861a3 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/retrieve/PointDataPlotInfoRetriever.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/retrieve/PointDataPlotInfoRetriever.java @@ -66,7 +66,7 @@ public class PointDataPlotInfoRetriever extends AbstractDbPlotInfoRetriever { @Override protected void addColumns(DbQuery dq) { - dq.addColumn("id"); + dq.addColumn("dataURI"); dq.addColumn("location.latitude"); dq.addColumn("location.longitude"); dq.addColumn("location.stationId"); @@ -81,7 +81,7 @@ public class PointDataPlotInfoRetriever extends AbstractDbPlotInfoRetriever { @Override protected PlotInfo getPlotInfo(Object[] data) { PlotInfo stationInfo = new PlotInfo(); - stationInfo.id = (Integer) data[0]; + stationInfo.dataURI = (String) data[0]; stationInfo.latitude = (Double) data[1]; stationInfo.longitude = (Double) data[2]; stationInfo.stationId = (String) data[3]; diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/retrieve/ScatterometerPlotInfoRetriever.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/retrieve/ScatterometerPlotInfoRetriever.java index 4b4fe77183..4907bfda2a 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/retrieve/ScatterometerPlotInfoRetriever.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/rsc/retrieve/ScatterometerPlotInfoRetriever.java @@ -139,8 +139,9 @@ public class ScatterometerPlotInfoRetriever extends PointDataPlotInfoRetriever { } if (stations != null && stations.size() == MAX_RESULT_SIZE) { for (PlotInfo station : stations) { - if (station.id < request.maxId) { - request.maxId = station.id; + int id = Integer.parseInt(station.stationId); + if (id < request.maxId) { + request.maxId = id; } } synchronized (screenQueue) { @@ -197,7 +198,22 @@ public class ScatterometerPlotInfoRetriever extends PointDataPlotInfoRetriever { dq.setOrderAscending(ResultOrder.DESC); dq.addOrderBy("id"); super.addColumns(dq); + dq.addColumn("id"); } + + + + /* (non-Javadoc) + * @see com.raytheon.viz.pointdata.rsc.retrieve.PointDataPlotInfoRetriever#getPlotInfo(java.lang.Object[]) + */ + @Override + protected PlotInfo getPlotInfo(Object[] data) { + PlotInfo info = super.getPlotInfo(data); + info.stationId = data[data.length - 1].toString(); + return info; + } + + public void getStations(IResourceDataChanged listener, DataTime time, HashMap metadataMap) throws VizException { diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/thread/PlotSampleGeneratorJob.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/thread/PlotSampleGeneratorJob.java index 677639c4bf..a1b8a02a1c 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/thread/PlotSampleGeneratorJob.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/thread/PlotSampleGeneratorJob.java @@ -80,9 +80,9 @@ public class PlotSampleGeneratorJob extends Job { try { PlotInfo[] infos = queue.poll(); String message = plotFactory.getStationMessage(infos[0].pdv, - infos[0].id); + infos[0].dataURI); - caller.messageGenerated(infos[0].id, message); + caller.messageGenerated(infos[0].dataURI, message); } catch (Exception e) { statusHandler.error("Error creating plot", e); } diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/AbstractPointDataInventory.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/AbstractPointDataInventory.java index 215d780b09..cec653fa2a 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/AbstractPointDataInventory.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/AbstractPointDataInventory.java @@ -40,6 +40,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.RecordFactory; import com.raytheon.uf.viz.core.catalog.CatalogQuery; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.level.LevelMappingFactory; import com.raytheon.uf.viz.derivparam.data.AbstractRequestableData; @@ -71,9 +72,6 @@ public abstract class AbstractPointDataInventory extends AbstractInventory { private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(AbstractPointDataInventory.class); - public static final Level STATION = LevelMappingFactory.getInstance() - .getLevelMappingForKey("Station").getLevels().get(0); - public static String PLUGIN_NAME = "pluginName"; protected List plugins; @@ -135,7 +133,7 @@ public abstract class AbstractPointDataInventory extends AbstractInventory { protected DataTree getInitialTree() { DataTree tree = new DataTree(); - String stationId = Long.toString(STATION.getId()); + String stationId = Long.toString(getStationLevel().getId()); for (String pluginName : plugins) { try { String[] types = getAvailableTypes(pluginName); @@ -276,4 +274,14 @@ public abstract class AbstractPointDataInventory extends AbstractInventory { return plugins; } + public static Level getStationLevel() { + try { + return LevelMappingFactory.getInstance() + .getLevelMappingForKey("Station").getLevels().get(0); + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + return null; + } + } + } diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/HeightOfLevelNode.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/HeightOfLevelNode.java index 38d2f329d4..42049dbc32 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/HeightOfLevelNode.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/HeightOfLevelNode.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Set; import com.raytheon.uf.common.dataplugin.level.Level; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.catalog.LayerProperty; import com.raytheon.uf.viz.core.exception.VizException; @@ -125,7 +126,8 @@ public class HeightOfLevelNode extends AbstractDerivedLevelNode { * timeQueryInternal(boolean, java.util.Map) */ @Override - protected Set timeQueryInternal(boolean latestOnly, + protected Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointAccumLevelNode.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointAccumLevelNode.java index 61c7d2c2b3..97ba8f5800 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointAccumLevelNode.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointAccumLevelNode.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.catalog.LayerProperty; import com.raytheon.uf.viz.core.exception.VizException; @@ -65,7 +66,7 @@ public class PointAccumLevelNode extends AbstractDerivedLevelNode { public PointAccumLevelNode(DerivParamDesc desc, DerivParamMethod method, List idNodes, AbstractRequestableLevelNode timeNode) { - super(PointDataInventory.STATION, desc, method, null); + super(PointDataInventory.getStationLevel(), desc, method, null); this.idNodes = idNodes; this.timeNode = timeNode; } @@ -121,7 +122,8 @@ public class PointAccumLevelNode extends AbstractDerivedLevelNode { * timeQueryInternal(boolean, java.util.Map) */ @Override - protected Set timeQueryInternal(boolean latestOnly, + protected Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointDataCubeAdapter.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointDataCubeAdapter.java index 27772327a4..597365dc22 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointDataCubeAdapter.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointDataCubeAdapter.java @@ -37,6 +37,9 @@ import com.raytheon.uf.common.datastorage.Request; import com.raytheon.uf.common.datastorage.records.FloatDataRecord; import com.raytheon.uf.common.datastorage.records.IDataRecord; import com.raytheon.uf.common.pointdata.PointDataContainer; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.RecordFactory; import com.raytheon.uf.viz.core.catalog.LayerProperty; @@ -49,7 +52,6 @@ import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.level.LevelMappingFactory; import com.raytheon.uf.viz.core.requests.ThriftClient; import com.raytheon.uf.viz.derivparam.data.AbstractRequestableData; -import com.raytheon.uf.viz.derivparam.library.DerivParamDesc; import com.raytheon.uf.viz.derivparam.library.DerivedParameterGenerator; import com.raytheon.uf.viz.derivparam.tree.AbstractRequestableLevelNode; import com.raytheon.uf.viz.derivparam.tree.AbstractRequestableLevelNode.Dependency; @@ -76,6 +78,8 @@ import com.raytheon.viz.pointdata.PointDataRequest; */ public class PointDataCubeAdapter implements IDataCubeAdapter { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(PointDataCubeAdapter.class); public static String PLUGIN_NAME = PointDataInventory.PLUGIN_NAME; @@ -88,8 +92,6 @@ public class PointDataCubeAdapter implements IDataCubeAdapter { protected AbstractPointDataInventory inventory; - protected Map derParLibrary; - /* * (non-Javadoc) * @@ -112,6 +114,9 @@ public class PointDataCubeAdapter implements IDataCubeAdapter { */ @Override public Object getInventory() { + if (inventory == null) { + initInventory(); + } return this.inventory; } @@ -301,28 +306,20 @@ public class PointDataCubeAdapter implements IDataCubeAdapter { */ @Override public void initInventory() { - derParLibrary = DerivedParameterGenerator.getDerParLibrary(); if (inventory == null) { PointDataInventory pointInventory = new PointDataInventory( Arrays.asList(supportedPlugins)); - pointInventory.initTree(derParLibrary); - this.inventory = pointInventory; + try { + pointInventory.initTree(DerivedParameterGenerator + .getDerParLibrary()); + this.inventory = pointInventory; + } catch (VizException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); + } } } - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.core.datastructure.IDataCubeAdapter#recordKeyGenerator - * (com.raytheon.uf.common.dataplugin.PluginDataObject) - */ - @Override - public String recordKeyGenerator(PluginDataObject pdo) { - // TODO Auto-generated method stub - return null; - } - @Override public IDataRecord[] getRecord(PluginDataObject obj, Request req, String dataset) throws VizDataCubeException { diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointDataInventory.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointDataInventory.java index 5b0b07c122..8b99479f3e 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointDataInventory.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointDataInventory.java @@ -112,7 +112,12 @@ public class PointDataInventory extends AbstractPointDataInventory implements } if (getAllSources() != null && !getAllSources().contains(source)) { - initTree(derParLibrary); + try { + initTree(derParLibrary); + } catch (VizException e) { + statusHandler.handle(Priority.PROBLEM, + e.getLocalizedMessage(), e); + } } } } diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointDataLevelNode.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointDataLevelNode.java index 860718a23c..6a12f9e190 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointDataLevelNode.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointDataLevelNode.java @@ -120,7 +120,8 @@ public class PointDataLevelNode extends AbstractRequestableLevelNode { } @Override - protected TimeQueryRequest getTimeQueryInternal(boolean latestOnly, + protected TimeQueryRequest getTimeQueryInternal( + TimeQueryRequest originalRequest, boolean latestOnly, Map> cache) throws VizException { throw new UnsupportedOperationException( @@ -145,7 +146,8 @@ public class PointDataLevelNode extends AbstractRequestableLevelNode { * timeQueryInternal(boolean, java.util.Map) */ @Override - protected Set timeQueryInternal(boolean latestOnly, + protected Set timeQueryInternal(TimeQueryRequest originalRequest, + boolean latestOnly, Map> cache, Map> latestOnlyCache) throws VizException { diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointRequestableData.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointRequestableData.java index ae1a4c015e..52b4fcc14c 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointRequestableData.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/util/PointRequestableData.java @@ -48,7 +48,7 @@ public class PointRequestableData extends AbstractRequestableData { public PointRequestableData(IDataRecord rec, Unit unit) { this.unit = unit; this.rec = rec; - this.level = PointDataInventory.STATION; + this.level = PointDataInventory.getStationLevel(); this.parameter = rec.getName(); } diff --git a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/RadarImageResource.java b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/RadarImageResource.java index da10c1e912..607da0b02a 100644 --- a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/RadarImageResource.java +++ b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/RadarImageResource.java @@ -408,40 +408,55 @@ public class RadarImageResource extends this.actualLevel = String.format("%1.1f", record.getTrueElevationAngle()); - try { - DrawableImage image = images.get(displayedDate); - if (image == null || image.getCoverage() == null) { - if (record.getStoredDataAsync() == null) { - issueRefresh(); - return; - } - createTile(target, record); - image = images.get(displayedDate); - } + DrawableImage image = getImage(target, displayedDate); + if (image != null) { + ImagingCapability cap = getCapability(ImagingCapability.class); + image.getImage().setBrightness(cap.getBrightness()); + image.getImage().setContrast(cap.getContrast()); + image.getImage().setInterpolated(cap.isInterpolationState()); + target.drawRasters(paintProps, image); + } - if (image != null) { - ImagingCapability cap = getCapability(ImagingCapability.class); - image.getImage().setBrightness(cap.getBrightness()); - image.getImage().setContrast(cap.getContrast()); - image.getImage() - .setInterpolated(cap.isInterpolationState()); - target.drawRasters(paintProps, image); - } - - if (image == null || image.getCoverage() == null - || image.getCoverage().getMesh() == null) { - issueRefresh(); - } - } catch (Exception e) { - String msg = e.getMessage(); - if (msg == null) { - msg = "Error rendering radar"; - } - throw new VizException(msg, e); + if (image == null || image.getCoverage() == null + || image.getCoverage().getMesh() == null) { + issueRefresh(); } } } + /** + * Get the radar image for the given time + * + * @param target + * @param dataTime + * @return + * @throws VizException + */ + public DrawableImage getImage(IGraphicsTarget target, DataTime dataTime) + throws VizException { + DrawableImage image = images.get(dataTime); + if (image == null || image.getCoverage() == null) { + VizRadarRecord record = getRadarRecord(dataTime); + if (record != null) { + if (record.getStoredDataAsync() == null) { + issueRefresh(); + } else { + try { + createTile(target, record); + image = images.get(dataTime); + } catch (Exception e) { + String msg = e.getMessage(); + if (msg == null) { + msg = "Error rendering radar"; + } + throw new VizException(msg, e); + } + } + } + } + return image; + } + /** * Shared by image and non-image * diff --git a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/graphic/RadarGraphicsPage.java b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/graphic/RadarGraphicsPage.java index 844c015f1c..34511c7b0f 100644 --- a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/graphic/RadarGraphicsPage.java +++ b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/graphic/RadarGraphicsPage.java @@ -72,11 +72,10 @@ import com.raytheon.uf.common.geospatial.ReferencedCoordinate; import com.raytheon.uf.common.geospatial.ReferencedGeometry; import com.raytheon.uf.common.geospatial.ReferencedObject.Type; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.viz.core.DrawableLine; +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.TextStyle; import com.raytheon.uf.viz.core.IGraphicsTarget.VerticalAlignment; -import com.raytheon.uf.viz.core.PixelCoverage; import com.raytheon.uf.viz.core.drawables.IDescriptor; import com.raytheon.uf.viz.core.drawables.IFont; import com.raytheon.uf.viz.core.drawables.IRenderable; @@ -84,6 +83,8 @@ import com.raytheon.uf.viz.core.drawables.IWireframeShape; import com.raytheon.uf.viz.core.drawables.PaintProperties; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.viz.core.rsc.jts.JTSCompiler; +import com.raytheon.viz.pointdata.drawables.IPointImageExtension; +import com.raytheon.viz.pointdata.drawables.IPointImageExtension.PointImage; import com.raytheon.viz.radar.RadarHelper; import com.raytheon.viz.radar.rsc.graphic.RadarGraphicFunctions.MesocycloneType; import com.raytheon.viz.radar.rsc.graphic.RadarGraphicFunctions.PlotObject; @@ -981,23 +982,6 @@ public class RadarGraphicsPage implements IRenderable { return images; } - public PixelCoverage getPixelCoverage(Coordinate c) { - int scaleWidth = 3; - - double[] centerpixels = this.descriptor.worldToPixel(new double[] { - c.x, c.y }); - Coordinate ul = new Coordinate(centerpixels[0] - scaleWidth, - centerpixels[1] - scaleWidth); - Coordinate ur = new Coordinate(centerpixels[0] + scaleWidth, - centerpixels[1] - scaleWidth); - Coordinate lr = new Coordinate(centerpixels[0] + scaleWidth, - centerpixels[1] + scaleWidth); - Coordinate ll = new Coordinate(centerpixels[0] - scaleWidth, - centerpixels[1] + scaleWidth); - - return new PixelCoverage(ul, ur, lr, ll); - } - public static Coordinate rectifyCoordinate(Coordinate c) { c.x += RadarGraphicsDisplay.X_OFFSET; c.y += RadarGraphicsDisplay.Y_OFFSET; @@ -1067,9 +1051,10 @@ public class RadarGraphicsPage implements IRenderable { // Paint map-relative text for (Coordinate c : this.localStringMap.keySet()) { String str = this.localStringMap.get(c); - - target.drawString(this.font, str, c.x, c.y, 0.0, TextStyle.NORMAL, - this.color, HorizontalAlignment.LEFT, null); + DrawableString string = new DrawableString(str, this.color); + string.font = this.font; + string.setCoordinates(c.x, c.y); + target.drawStrings(string); } // Paint screen-relative text @@ -1096,7 +1081,9 @@ public class RadarGraphicsPage implements IRenderable { // the target may have messes with our magnification value, // especially in smaller panes. - magnification = target.getStringBounds(font, "Hy").getHeight() / 14; + DrawableString testString = new DrawableString("hy", this.color); + testString.font = this.font; + magnification = target.getStringsBounds(testString).getHeight() / 14; double width = (maxx - minx) * magnification; // If the table wider than our canvas then shrink it if (width > paintProps.getCanvasBounds().width) { @@ -1104,7 +1091,7 @@ public class RadarGraphicsPage implements IRenderable { * paintProps.getCanvasBounds().width / (width + xOffset * 2); font.setMagnification((float) magnification, false); - magnification = target.getStringBounds(font, "Hy").getHeight() / 14; + magnification = target.getStringsBounds(testString).getHeight() / 14; width = (maxx - minx) * magnification; } xOffset = (paintProps.getCanvasBounds().width - width) / 2; @@ -1123,9 +1110,11 @@ public class RadarGraphicsPage implements IRenderable { new double[] { x1, y1 }, target); double[] pts2 = paintProps.getView().getDisplayCoords( new double[] { x2, y2 }, target); - - target.drawLine(pts1[0], pts1[1], 0, pts2[0], pts2[1], 0, - color, 1.0f); + DrawableLine line = new DrawableLine(); + line.addPoint(pts1[0], pts1[1]); + line.addPoint(pts2[0], pts2[1]); + line.basics.color = this.color; + target.drawLine(line); } } @@ -1145,9 +1134,11 @@ public class RadarGraphicsPage implements IRenderable { // } double[] pts = paintProps.getView().getDisplayCoords( new double[] { x, y }, target); - target.drawString(this.font, str, pts[0], pts[1], 0.0, - TextStyle.NORMAL, color, HorizontalAlignment.LEFT, - VerticalAlignment.TOP, null); + DrawableString string = new DrawableString(str, this.color); + string.font = this.font; + string.setCoordinates(pts[0], pts[1]); + string.verticallAlignment = VerticalAlignment.TOP; + target.drawStrings(string); } } @@ -1160,24 +1151,30 @@ public class RadarGraphicsPage implements IRenderable { // paint symbols on screen double ratio = (paintProps.getView().getExtent().getWidth() / paintProps .getCanvasBounds().width); - double pixels = 90 * ratio * magnification; + double pixels = 90 * magnification; for (PlotObject po : this.plotObjects) { Coordinate adjustedCoord = (Coordinate) po.coord.clone(); adjustedCoord.x += po.pixelOffset[0] * ratio * magnification; adjustedCoord.y += po.pixelOffset[1] * ratio * magnification; - target.drawRaster(po.image, new PixelCoverage(adjustedCoord, - pixels, pixels), paintProps); + PointImage image = new PointImage(po.image, adjustedCoord); + image.setHeight(pixels); + image.setWidth(pixels); if (po.label != null) { + image.setSiteId(po.label); // Place the label next to the image adjustedCoord.x += pixels / 20; - target.drawString(this.font, po.label, adjustedCoord.x, - adjustedCoord.y, 0.0, TextStyle.NORMAL, this.color, - HorizontalAlignment.LEFT, VerticalAlignment.BOTTOM, - null); + DrawableString string = new DrawableString(po.label, this.color); + string.font = this.font; + string.setCoordinates(adjustedCoord.x, adjustedCoord.y); + target.drawStrings(string); + } + target.getExtension(IPointImageExtension.class).drawPointImages( + paintProps, image); + } } diff --git a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/image/IRadialMeshExtension.java b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/image/IRadialMeshExtension.java index c60d493c0f..dec8810bb7 100644 --- a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/image/IRadialMeshExtension.java +++ b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/image/IRadialMeshExtension.java @@ -21,6 +21,7 @@ package com.raytheon.viz.radar.rsc.image; import com.raytheon.uf.common.dataplugin.radar.RadarRecord; import com.raytheon.uf.viz.core.IMesh; +import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension.IGraphicsExtensionInterface; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.map.IMapDescriptor; @@ -41,7 +42,7 @@ import com.raytheon.uf.viz.core.map.IMapDescriptor; * @version 1.0 */ -public interface IRadialMeshExtension { +public interface IRadialMeshExtension extends IGraphicsExtensionInterface { /** * Construct a mesh to be used for the radar record on the descriptor diff --git a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/MergeRasterRadarMosaicRenderer.java b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/MergeRasterRadarMosaicRenderer.java index dac7b28510..32407ba004 100644 --- a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/MergeRasterRadarMosaicRenderer.java +++ b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/MergeRasterRadarMosaicRenderer.java @@ -41,7 +41,7 @@ import com.raytheon.uf.viz.core.rsc.AbstractVizResource; import com.raytheon.viz.core.rsc.BestResResource; import com.raytheon.viz.radar.rsc.MosaicPaintProperties; import com.raytheon.viz.radar.rsc.RadarImageResource; -import com.raytheon.viz.radar.rsc.mosaic.ext.IRadarMosaicRendererFactoryExtension.IRadarMosaicRenderer; +import com.raytheon.viz.radar.rsc.mosaic.RadarMosaicRendererFactory.IRadarMosaicRenderer; import com.raytheon.viz.radar.util.DataUtilities; /** diff --git a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/RadarMosaicRenderer.java b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicRenderer.java similarity index 63% rename from cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/RadarMosaicRenderer.java rename to cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicRenderer.java index cbea81a810..e44bb780f5 100644 --- a/cave/com.raytheon.uf.viz.radar.gl/src/com/raytheon/uf/viz/radar/gl/mosaic/RadarMosaicRenderer.java +++ b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicRenderer.java @@ -17,39 +17,36 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.uf.viz.radar.gl.mosaic; +package com.raytheon.viz.radar.rsc.mosaic; -import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; -import com.raytheon.uf.common.status.IUFStatusHandler; -import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.time.DataTime; +import com.raytheon.uf.viz.core.DrawableImage; import com.raytheon.uf.viz.core.IExtent; import com.raytheon.uf.viz.core.IGraphicsTarget; import com.raytheon.uf.viz.core.PixelCoverage; import com.raytheon.uf.viz.core.drawables.ColorMapParameters; -import com.raytheon.uf.viz.core.drawables.IImage; import com.raytheon.uf.viz.core.drawables.PaintProperties; import com.raytheon.uf.viz.core.drawables.ResourcePair; -import com.raytheon.uf.viz.core.drawables.ext.IOffscreenRenderingExtension; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.rsc.AbstractVizResource; import com.raytheon.uf.viz.core.rsc.IRefreshListener; import com.raytheon.uf.viz.core.rsc.capabilities.ColorMapCapability; import com.raytheon.uf.viz.core.rsc.capabilities.ImagingCapability; -import com.raytheon.uf.viz.radar.gl.MosaicGLTarget; -import com.raytheon.viz.core.gl.IGLTarget; import com.raytheon.viz.core.rsc.BestResResource; import com.raytheon.viz.radar.rsc.MosaicPaintProperties; import com.raytheon.viz.radar.rsc.RadarImageResource; -import com.raytheon.viz.radar.rsc.mosaic.RadarMosaicResource; -import com.raytheon.viz.radar.rsc.mosaic.ext.IRadarMosaicRendererFactoryExtension.IRadarMosaicRenderer; +import com.raytheon.viz.radar.rsc.mosaic.RadarMosaicRendererFactory.IRadarMosaicRenderer; +import com.raytheon.viz.radar.rsc.mosaic.ext.IRadarMosaicImageExtension; +import com.raytheon.viz.radar.rsc.mosaic.ext.IRadarMosaicImageExtension.IMosaicImage; import com.vividsolutions.jts.geom.Coordinate; /** - * GL Mosaic rendering class using gl frame buffer objects and custom fragment - * shader. + * Radar Mosaic rendering class using IRadarMosaicImageExtension to render + * mosaic image * *
  * 
@@ -66,17 +63,9 @@ import com.vividsolutions.jts.geom.Coordinate;
 
 public class RadarMosaicRenderer implements IRadarMosaicRenderer,
         IRefreshListener {
-    private static final transient IUFStatusHandler statusHandler = UFStatus
-            .getHandler(RadarMosaicRenderer.class);
-
-    /** The current offscreen texture that is getting rendered to */
-    private static IImage currentWrite = null;
 
     /** This instances offscreen texture */
-    private IImage writeTo = null;
-
-    /** Bounds of the offscreen texture */
-    private int[] mosaicBounds = null;
+    private IMosaicImage writeTo = null;
 
     /** Last extent painted, if extent changes, repaint to texture */
     private IExtent lastExtent = null;
@@ -84,21 +73,6 @@ public class RadarMosaicRenderer implements IRadarMosaicRenderer,
     /** The coverage of the offscreen texture (used for drawing on screen) */
     private PixelCoverage writeToCoverage = null;
 
-    private IGraphicsTarget mosaicTarget = null;
-
-    private IGLTarget glTarget = null;
-
-    /**
-     * This function returns the current gl image that is being mosaic'd to. It
-     * depends on the fact that painting is a synchronous operation and no 2
-     * mosaics will be drawing at exactly the same time.
-     * 
-     * @return currently writing offscreen mosaic texture
-     */
-    public static IImage getCurrentMosaicImage() {
-        return currentWrite;
-    }
-
     /**
      * Default constructor, needed since class is instantiated through eclipse
      * extension point
@@ -124,13 +98,6 @@ public class RadarMosaicRenderer implements IRadarMosaicRenderer,
         ColorMapParameters params = mosaicToRender.getCapability(
                 ColorMapCapability.class).getColorMapParameters();
 
-        IGLTarget glTarget = (IGLTarget) target;
-
-        if (glTarget != this.glTarget) {
-            this.glTarget = glTarget;
-            this.mosaicTarget = new MosaicGLTarget(glTarget);
-        }
-
         // If first paint, initialize and wait for next paint
         if (writeTo == null) {
             init(target, paintProps, params);
@@ -142,13 +109,11 @@ public class RadarMosaicRenderer implements IRadarMosaicRenderer,
                 }
             }
             mosaicToRender.registerListener(this);
-        }
-
-        // If Window size changed, recreate the off screen buffer
-        if (Arrays.equals(
-                mosaicBounds,
+        } else if (Arrays.equals(
+                new int[] { writeTo.getWidth(), writeTo.getHeight() },
                 new int[] { paintProps.getCanvasBounds().width,
                         paintProps.getCanvasBounds().height }) == false) {
+            // If Window size changed, recreate the off screen buffer
             dispose();
             init(target, paintProps, params);
         }
@@ -158,29 +123,31 @@ public class RadarMosaicRenderer implements IRadarMosaicRenderer,
         synchronized (this) {
             if (props.isForceRepaint()
                     || paintProps.getView().getExtent().equals(lastExtent) == false) {
-                IOffscreenRenderingExtension offscreenExt = target
-                        .getExtension(IOffscreenRenderingExtension.class);
-                offscreenExt.renderOffscreen(writeTo);
-                try {
-                    currentWrite = writeTo;
-                    // paint radar using mosaic target
-                    for (ResourcePair rp : mosaicToRender.getResourceList()) {
-                        AbstractVizResource rsc = rp.getResource();
-                        DataTime time = mosaicToRender.getTimeForResource(rsc);
-                        if (rsc instanceof BestResResource) {
-                            rsc = ((BestResResource) rsc)
-                                    .getBestResResource(time);
-                        }
-                        if (rsc != null) {
-                            RadarImageResource rr = (RadarImageResource) rsc;
-                            paintProps.setDataTime(time);
-                            rr.paintRadar(mosaicTarget, paintProps);
+                List images = new ArrayList();
+
+                // paint radar using mosaic target
+                for (ResourcePair rp : mosaicToRender.getResourceList()) {
+                    AbstractVizResource rsc = rp.getResource();
+                    DataTime time = mosaicToRender.getTimeForResource(rsc);
+                    if (rsc instanceof BestResResource) {
+                        rsc = ((BestResResource) rsc).getBestResResource(time);
+                    }
+                    if (rsc != null && time != null) {
+                        RadarImageResource rr = (RadarImageResource) rsc;
+                        DrawableImage di = rr.getImage(target, time);
+                        if (di != null && di.getImage() != null
+                                && di.getCoverage() != null
+                                && di.getCoverage().getMesh() != null) {
+                            // If image is ready to go, add
+                            images.add(di);
+                        } else {
+                            mosaicToRender.issueRefresh();
                         }
                     }
-                } finally {
-                    offscreenExt.renderOnscreen();
                 }
 
+                writeTo.setImagesToMosaic(images
+                        .toArray(new DrawableImage[images.size()]));
                 lastExtent = paintProps.getView().getExtent().clone();
 
                 Coordinate ul = new Coordinate(lastExtent.getMinX(),
@@ -197,13 +164,10 @@ public class RadarMosaicRenderer implements IRadarMosaicRenderer,
 
             writeTo.setContrast(mosaicToRender.getCapability(
                     ImagingCapability.class).getContrast());
-
             writeTo.setBrightness(mosaicToRender.getCapability(
                     ImagingCapability.class).getBrightness());
 
             target.drawRaster(writeTo, writeToCoverage, paintProps);
-
-            currentWrite = null;
         }
     }
 
@@ -212,12 +176,11 @@ public class RadarMosaicRenderer implements IRadarMosaicRenderer,
      */
     private void init(IGraphicsTarget target, PaintProperties paintProps,
             ColorMapParameters params) throws VizException {
-        // Construct texture for offscreen rendering
-        mosaicBounds = new int[] { paintProps.getCanvasBounds().width,
-                paintProps.getCanvasBounds().height };
-        writeTo = target
-                .getExtension(IOffscreenRenderingExtension.class)
-                .constructOffscreenImage(ByteBuffer.class, mosaicBounds, params);
+        // Construct texture for mosaicing
+        writeTo = target.getExtension(IRadarMosaicImageExtension.class)
+                .initializeRaster(
+                        new int[] { paintProps.getCanvasBounds().width,
+                                paintProps.getCanvasBounds().height }, params);
     }
 
     @Override
diff --git a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/ext/IRadarMosaicRendererFactoryExtension.java b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicRendererFactory.java
similarity index 63%
rename from cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/ext/IRadarMosaicRendererFactoryExtension.java
rename to cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicRendererFactory.java
index 03a5043781..3feac88fd0 100644
--- a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/ext/IRadarMosaicRendererFactoryExtension.java
+++ b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicRendererFactory.java
@@ -17,16 +17,14 @@
  * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
  * further licensing information.
  **/
-package com.raytheon.viz.radar.rsc.mosaic.ext;
+package com.raytheon.viz.radar.rsc.mosaic;
 
 import com.raytheon.uf.viz.core.IGraphicsTarget;
 import com.raytheon.uf.viz.core.drawables.PaintProperties;
 import com.raytheon.uf.viz.core.exception.VizException;
-import com.raytheon.viz.radar.rsc.mosaic.RadarMosaicResource;
 
 /**
- * Mosaic Renderer factory extension. Implementers of this extension will
- * construct IRadarMosaicRenderers
+ * Radar mosaic renderer factory, creates mosaic renderers
  * 
  * 
  * 
@@ -42,7 +40,7 @@ import com.raytheon.viz.radar.rsc.mosaic.RadarMosaicResource;
  * @version 1.0
  */
 
-public interface IRadarMosaicRendererFactoryExtension {
+public class RadarMosaicRendererFactory {
 
     public static enum MosaicType {
         MergeRaster, MaxValue;
@@ -50,31 +48,23 @@ public interface IRadarMosaicRendererFactoryExtension {
 
     public static interface IRadarMosaicRenderer {
 
-        /**
-         * similar to the paint(...) call on IRenderable, this function tells
-         * the mosaic renderer to render the mosaic given the target,
-         * paintProperties, and mosaic resource
-         * 
-         * @param target
-         * @param paintProps
-         * @param mosaicToRender
-         * @throws VizException
-         */
         public void mosaic(IGraphicsTarget target, PaintProperties paintProps,
                 RadarMosaicResource mosaicToRender) throws VizException;
 
-        /**
-         * Dispose of any resources being used
-         */
         public void dispose();
+
     }
 
-    /**
-     * Create a new radar mosaic renderer
-     * 
-     * @return
-     */
-    public IRadarMosaicRenderer createNewRenderer(MosaicType mosaicType)
-            throws VizException;
+    public static IRadarMosaicRenderer createNewRenderer(MosaicType mosaicType)
+            throws VizException {
+        switch (mosaicType) {
+        case MergeRaster:
+            return new MergeRasterRadarMosaicRenderer();
+        case MaxValue:
+            return new RadarMosaicRenderer();
+        }
+        throw new VizException("Could not find mosaic renderer for type = "
+                + mosaicType);
+    }
 
 }
diff --git a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicResource.java b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicResource.java
index 79fbfd29d0..55ab5ae971 100644
--- a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicResource.java
+++ b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicResource.java
@@ -60,8 +60,7 @@ import com.raytheon.viz.radar.rsc.AbstractRadarResource;
 import com.raytheon.viz.radar.rsc.MosaicPaintProperties;
 import com.raytheon.viz.radar.rsc.RadarImageResource;
 import com.raytheon.viz.radar.rsc.RadarTextResource.IRadarTextGeneratingResource;
-import com.raytheon.viz.radar.rsc.mosaic.ext.IRadarMosaicRendererFactoryExtension;
-import com.raytheon.viz.radar.rsc.mosaic.ext.IRadarMosaicRendererFactoryExtension.IRadarMosaicRenderer;
+import com.raytheon.viz.radar.rsc.mosaic.RadarMosaicRendererFactory.IRadarMosaicRenderer;
 import com.vividsolutions.jts.geom.Coordinate;
 
 /**
@@ -153,10 +152,8 @@ public class RadarMosaicResource extends
      */
     @Override
     protected void initInternal(IGraphicsTarget target) throws VizException {
-
-        mosaicRenderer = target.getExtension(
-                IRadarMosaicRendererFactoryExtension.class).createNewRenderer(
-                resourceData.getMosaicType());
+        mosaicRenderer = RadarMosaicRendererFactory
+                .createNewRenderer(resourceData.getMosaicType());
 
         // We want to init the most severe resource first so the colormap
         // matches.
diff --git a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicResourceData.java b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicResourceData.java
index 85ae6a03b5..1cd2503287 100644
--- a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicResourceData.java
+++ b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/RadarMosaicResourceData.java
@@ -48,7 +48,7 @@ import com.raytheon.uf.viz.core.rsc.AbstractResourceData;
 import com.raytheon.uf.viz.core.rsc.AbstractVizResource;
 import com.raytheon.uf.viz.core.rsc.LoadProperties;
 import com.raytheon.uf.viz.core.rsc.ResourceList;
-import com.raytheon.viz.radar.rsc.mosaic.ext.IRadarMosaicRendererFactoryExtension.MosaicType;
+import com.raytheon.viz.radar.rsc.mosaic.RadarMosaicRendererFactory.MosaicType;
 
 /**
  * Provides the metadata and constructor for Radar
diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLCanvasCache.java b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/ext/IRadarMosaicImageExtension.java
similarity index 54%
rename from cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLCanvasCache.java
rename to cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/ext/IRadarMosaicImageExtension.java
index cdc95972d2..fe0ef14d81 100644
--- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLCanvasCache.java
+++ b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/rsc/mosaic/ext/IRadarMosaicImageExtension.java
@@ -17,57 +17,40 @@
  * See the AWIPS II Master Rights File ("Master Rights File.pdf") for
  * further licensing information.
  **/
+package com.raytheon.viz.radar.rsc.mosaic.ext;
 
-package com.raytheon.viz.core.gl;
-
-import org.eclipse.swt.opengl.GLCanvas;
+import com.raytheon.uf.viz.core.DrawableImage;
+import com.raytheon.uf.viz.core.drawables.ColorMapParameters;
+import com.raytheon.uf.viz.core.drawables.IImage;
+import com.raytheon.uf.viz.core.drawables.ext.IImagingExtension;
+import com.raytheon.uf.viz.core.exception.VizException;
 
 /**
- * 
- * Caches the initial GLCanvas
- * 
- * This is not ideal, since the SWT resources for the first canvas are always
- * left open after the map is disposed, but due to limitations in JOGL and
- * Eclipse, it is necessary.
+ * Radar mosaic image extension, creates IMosaicImages
  * 
  * 
+ * 
  * SOFTWARE HISTORY
+ * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * Jul 10, 2007            chammack    Initial Creation.	
+ * Dec 16, 2011            mschenke     Initial creation
  * 
  * 
* - * @author chammack + * @author mschenke * @version 1.0 */ -public class GLCanvasCache { +public interface IRadarMosaicImageExtension extends IImagingExtension { - private static GLCanvasCache instance; + public static interface IMosaicImage extends IImage { - private GLCanvas canvas; + public void setImagesToMosaic(DrawableImage... images); - public static synchronized GLCanvasCache getInstance() { - if (instance == null) { - instance = new GLCanvasCache(); - } - return instance; - } + } - /** - * @return the canvas - */ - public GLCanvas getCanvas() { - return canvas; - } - - /** - * @param canvas - * the canvas to set - */ - public void setCanvas(GLCanvas canvas) { - this.canvas = canvas; - } + public IMosaicImage initializeRaster(int[] imageBounds, + ColorMapParameters params) throws VizException; } diff --git a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/util/RadarDataCubeAdapter.java b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/util/RadarDataCubeAdapter.java index c13d3b4122..7bec38cf7c 100644 --- a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/util/RadarDataCubeAdapter.java +++ b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/util/RadarDataCubeAdapter.java @@ -35,6 +35,9 @@ import com.raytheon.uf.common.dataquery.requests.TimeQueryRequest; import com.raytheon.uf.common.dataquery.responses.DbQueryResponse; import com.raytheon.uf.common.dataquery.responses.DbQueryResponseSet; import com.raytheon.uf.common.pointdata.PointDataContainer; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.time.BinOffset; import com.raytheon.uf.common.time.DataTime; import com.raytheon.uf.viz.core.exception.VizException; @@ -61,6 +64,9 @@ import com.raytheon.viz.pointdata.util.PointDataCubeAdapter; * @version 1.0 */ public class RadarDataCubeAdapter extends PointDataCubeAdapter { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(RadarDataCubeAdapter.class); + private static final String DATA_TIME_FIELD = "dataTime"; private static final String LATEST_DATA_TIME_FIELD = "dataTime.refTime"; @@ -74,11 +80,16 @@ public class RadarDataCubeAdapter extends PointDataCubeAdapter { @Override public void initInventory() { - derParLibrary = DerivedParameterGenerator.getDerParLibrary(); if (inventory == null) { AbstractPointDataInventory pointInventory = new VwpInventory(); - pointInventory.initTree(derParLibrary); - this.inventory = pointInventory; + try { + pointInventory.initTree(DerivedParameterGenerator + .getDerParLibrary()); + this.inventory = pointInventory; + } catch (VizException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); + } } } diff --git a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/util/RadarPlotInfoRetriever.java b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/util/RadarPlotInfoRetriever.java index e3546535f3..69760501bb 100644 --- a/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/util/RadarPlotInfoRetriever.java +++ b/cave/com.raytheon.viz.radar/src/com/raytheon/viz/radar/util/RadarPlotInfoRetriever.java @@ -48,7 +48,6 @@ public class RadarPlotInfoRetriever extends AbstractDbPlotInfoRetriever { @Override protected void addColumns(DbQuery dq) { - dq.addColumn("id"); dq.addColumn("location.lat"); dq.addColumn("location.lon"); dq.addColumn("icao"); @@ -59,15 +58,14 @@ public class RadarPlotInfoRetriever extends AbstractDbPlotInfoRetriever { @Override protected PlotInfo getPlotInfo(Object[] data) { PlotInfo stationInfo = new PlotInfo(); - stationInfo.id = (Integer) data[0]; - stationInfo.latitude = ((Float) data[1]).doubleValue(); - stationInfo.longitude = ((Float) data[2]).doubleValue(); - stationInfo.stationId = (String) data[3]; + stationInfo.latitude = ((Float) data[0]).doubleValue(); + stationInfo.longitude = ((Float) data[1]).doubleValue(); + stationInfo.stationId = (String) data[2]; if (stationInfo.stationId == null) { - stationInfo.stationId = "" + data[1] + "#" + data[2]; + stationInfo.stationId = "" + data[0] + "#" + data[1]; } - stationInfo.dataTime = (DataTime) data[4]; - stationInfo.dataURI = (String) data[5]; + stationInfo.dataTime = (DataTime) data[3]; + stationInfo.dataURI = (String) data[4]; return stationInfo; } diff --git a/cave/com.raytheon.viz.redbook/src/com/raytheon/viz/redbookua/rsc/RedbookUpperAirResource.java b/cave/com.raytheon.viz.redbook/src/com/raytheon/viz/redbookua/rsc/RedbookUpperAirResource.java index ee5c148f1f..29ed4f61f7 100644 --- a/cave/com.raytheon.viz.redbook/src/com/raytheon/viz/redbookua/rsc/RedbookUpperAirResource.java +++ b/cave/com.raytheon.viz.redbook/src/com/raytheon/viz/redbookua/rsc/RedbookUpperAirResource.java @@ -398,7 +398,7 @@ public class RedbookUpperAirResource extends float lon = pdv.getFloat(RedbookUpperAirDecoder.P_LONGITUDE); PlotData pd = new PlotData(); pd.addData(pdv); - BufferedImage bImage = pmf.getStationPlot(pd, -1, lat, lon); + BufferedImage bImage = pmf.getStationPlot(pd, lat, lon); IImage image = null; if (bImage != null) image = target.initializeRaster(new IODataPreparer(bImage, diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/DrawCoordinatedPane.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/DrawCoordinatedPane.java index 1048b72f20..3fd6044a24 100644 --- a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/DrawCoordinatedPane.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/DrawCoordinatedPane.java @@ -183,8 +183,12 @@ public class DrawCoordinatedPane implements Comparable { && pane.isVisible()); } - for (VizDisplayPane pane : displayPanes) { - pane.drawEnd(); + if (actualDraw || loopProperties.isShouldDraw()) { + for (VizDisplayPane pane : displayPanes) { + if (pane.isVisible()) { + pane.drawEnd(); + } + } } // System.out.println("Time to draw = " diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/VizDisplayPane.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/VizDisplayPane.java index 7b4d5443f3..cbaed255b8 100644 --- a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/VizDisplayPane.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/panes/VizDisplayPane.java @@ -403,7 +403,9 @@ public class VizDisplayPane implements IDisplayPane { renderableDisplay, DisplayChangeType.REMOVE); } - graphicsAdapter.disposeCanvas(canvas); + if (canvas.isDisposed() == false) { + canvas.getParent().dispose(); + } } } diff --git a/cave/com.raytheon.viz.volumebrowser/META-INF/MANIFEST.MF b/cave/com.raytheon.viz.volumebrowser/META-INF/MANIFEST.MF index 81b5aae3a0..487536aafc 100644 --- a/cave/com.raytheon.viz.volumebrowser/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.viz.volumebrowser/META-INF/MANIFEST.MF @@ -38,7 +38,8 @@ Export-Package: com.raytheon.viz.volumebrowser, com.raytheon.viz.volumebrowser.datacatalog, com.raytheon.viz.volumebrowser.vbui, com.raytheon.viz.volumebrowser.xml -Import-Package: com.raytheon.uf.common.dataplugin.grib, +Import-Package: com.raytheon.uf.common.comm, + com.raytheon.uf.common.dataplugin.grib, com.raytheon.uf.common.dataplugin.grib.spatial.projections, com.raytheon.uf.common.dataplugin.grib.util, com.raytheon.uf.common.dataplugin.level, diff --git a/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/catalog/GridDataCatalog.java b/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/catalog/GridDataCatalog.java index c0985b8dad..afaf9cbc4a 100644 --- a/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/catalog/GridDataCatalog.java +++ b/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/catalog/GridDataCatalog.java @@ -40,6 +40,7 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Label; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.grib.util.GribModelLookup; import com.raytheon.uf.common.dataplugin.grib.util.GridModel; import com.raytheon.uf.common.dataplugin.level.Level; @@ -58,15 +59,15 @@ import com.raytheon.viz.grid.rsc.GridResourceData; * *
  * 
- * SOFTWARE HISTORY
- * 
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * 11/29/2006   #7         brockwoo    Initial creation
- * 12/05/2006   #98        brockwoo    Fix for the grid parameter list not
- *                                     updating when only the model time
- *                                     changes
- * Aug 27, 2008 1502       dglazesk    Updated to use JAXB marshalling
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * 11/29/2006   #7         brockwoo    Initial creation
+ * 12/05/2006   #98        brockwoo    Fix for the grid parameter list not
+ *                                     updating when only the model time
+ *                                     changes
+ * Aug 27, 2008 1502       dglazesk    Updated to use JAXB marshalling
  *                                     Switched to GridModel from plugin-grib
  * 
  * 
@@ -267,10 +268,14 @@ public class GridDataCatalog implements IDataCatalog { LevelFactory lf = LevelFactory.getInstance(); for (int i = 0; i < levelIds.length; i++) { - Level level = lf.getLevel(levelIds[i]); - levelNames[i] = level.getMasterLevel().getName() - + level.getLevelInfo(); - this.levelList.put(levelNames[i], level); + try { + Level level = lf.getLevel(levelIds[i]); + levelNames[i] = level.getMasterLevel().getName() + + level.getLevelInfo(); + this.levelList.put(levelNames[i], level); + } catch (CommunicationException e) { + e.printStackTrace(); + } } Arrays.sort(levelNames); diff --git a/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/AbstractDataCatalog.java b/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/AbstractDataCatalog.java index 17036f8dbb..2e7b82fb44 100644 --- a/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/AbstractDataCatalog.java +++ b/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/AbstractDataCatalog.java @@ -33,6 +33,7 @@ import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.drawables.ResourcePair; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; import com.raytheon.uf.viz.core.level.LevelMapping; import com.raytheon.uf.viz.core.level.LevelMappingFactory; import com.raytheon.uf.viz.core.level.LevelUtilities; @@ -345,15 +346,25 @@ public abstract class AbstractDataCatalog implements IDataCatalog { String planesKey = catalogEntry.getSelectedData().getPlanesKey(); - LevelMappingFactory lmf = LevelMappingFactory.getInstance(); Collection levels = Collections.emptyList(); if (planesKey.startsWith("spatial-")) { - levels = LevelUtilities.getOrderedSetOfStandardLevels(planesKey - .replace("spatial-", "")); + try { + levels = LevelUtilities.getOrderedSetOfStandardLevels(planesKey + .replace("spatial-", "")); + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); + } } else { - LevelMapping lm = lmf.getLevelMappingForKey(planesKey); - if (lm != null) { - levels = lm.getLevels(); + try { + LevelMappingFactory lmf = LevelMappingFactory.getInstance(); + LevelMapping lm = lmf.getLevelMappingForKey(planesKey); + if (lm != null) { + levels = lm.getLevels(); + } + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); } } ParamLevelMatchCriteria match = new ParamLevelMatchCriteria(); diff --git a/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/AbstractInventoryDataCatalog.java b/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/AbstractInventoryDataCatalog.java index 298771fa88..e4bc9d0202 100644 --- a/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/AbstractInventoryDataCatalog.java +++ b/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/AbstractInventoryDataCatalog.java @@ -35,16 +35,19 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.level.LevelFactory; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.datastructure.DataCubeContainer; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; import com.raytheon.uf.viz.core.level.LevelMapping; import com.raytheon.uf.viz.core.level.LevelMappingFactory; import com.raytheon.uf.viz.core.level.LevelUtilities; import com.raytheon.uf.viz.derivparam.inv.AbstractInventory; +import com.raytheon.viz.volumebrowser.vbui.DataListsProdTableComp.DataSelection; import com.raytheon.viz.volumebrowser.vbui.MenuItemManager; import com.raytheon.viz.volumebrowser.vbui.SelectedData; import com.raytheon.viz.volumebrowser.vbui.VBMenuBarItemsMgr.ViewMenu; @@ -171,20 +174,33 @@ public abstract class AbstractInventoryDataCatalog extends AbstractDataCatalog { String levelStr = levelQueue.poll(); while (levelStr != null) { // Convert levels into planes. - Level level = LevelFactory.getInstance().getLevel(levelStr); - if (levels3D.contains(level)) { - for (String plane : get3DPlanes(sourcesToProcess)) { - request.addAvailablePlane(plane); + try { + Level level = LevelFactory.getInstance().getLevel(levelStr); + + if (levels3D.contains(level)) { + for (String plane : get3DPlanes(sourcesToProcess)) { + request.addAvailablePlane(plane); + } } - } - request.addAvailablePlane("spatial-" - + level.getMasterLevel().getName()); - LevelMapping lm = LevelMappingFactory.getInstance() - .getLevelMappingForLevel(level); - if (lm != null) { - request.addAvailablePlane(lm.getKey()); + request.addAvailablePlane("spatial-" + + level.getMasterLevel().getName()); + try { + LevelMapping lm = LevelMappingFactory.getInstance() + .getLevelMappingForLevel(level); + + if (lm != null) { + request.addAvailablePlane(lm.getKey()); + } + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, + e.getLocalizedMessage(), e); + } + } catch (CommunicationException e) { + statusHandler.handle(Priority.PROBLEM, + e.getLocalizedMessage(), e); } levelStr = levelQueue.poll(); + } if (request.isCanceled()) { Thread thread = inventoryJob.getThread(); @@ -233,7 +249,10 @@ public abstract class AbstractInventoryDataCatalog extends AbstractDataCatalog { } catch (InterruptedException e) { statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); } - return new ArrayList(returnQueue); + List result = new ArrayList(returnQueue); + result.retainAll(MenuItemManager.getInstance() + .getMapOfKeys(DataSelection.SOURCES).keySet()); + return result; } public List getSupportedSources() { @@ -265,12 +284,23 @@ public abstract class AbstractInventoryDataCatalog extends AbstractDataCatalog { for (String plane : selectedPlanes) { Collection levels = Collections.emptyList(); if (plane.startsWith("spatial-")) { - levels = LevelUtilities.getOrderedSetOfStandardLevels(plane - .replace("spatial-", "")); + try { + levels = LevelUtilities + .getOrderedSetOfStandardLevels(plane.replace( + "spatial-", "")); + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, + e.getLocalizedMessage(), e); + } } else { LevelMapping lm = lmf.getLevelMappingForKey(plane); if (lm != null) { - levels = lm.getLevels(); + try { + levels = lm.getLevels(); + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, + e.getLocalizedMessage(), e); + } } } for (Level l : levels) { diff --git a/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/GribDataCatalog.java b/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/GribDataCatalog.java index 361986a151..9006de54e8 100644 --- a/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/GribDataCatalog.java +++ b/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/GribDataCatalog.java @@ -21,6 +21,7 @@ package com.raytheon.viz.volumebrowser.datacatalog; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -43,6 +44,7 @@ import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.core.drawables.ResourcePair; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.level.LevelMappingFactory; import com.raytheon.uf.viz.core.level.LevelUtilities; @@ -177,10 +179,16 @@ public class GribDataCatalog extends AbstractInventoryDataCatalog { .getInvalidLevelValueAsString())); } else { // Get all possible levels for the selected levels - LevelMappingFactory lmf = LevelMappingFactory.getInstance(); - List selectedLevels = new ArrayList(lmf - .getLevelMappingForKey(catalogEntry.selectedPlanesKey) - .getLevels()); + List selectedLevels = Collections.emptyList(); + try { + LevelMappingFactory lmf = LevelMappingFactory.getInstance(); + selectedLevels = new ArrayList(lmf + .getLevelMappingForKey( + catalogEntry.selectedPlanesKey).getLevels()); + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, + e.getLocalizedMessage(), e); + } RequestConstraint masterRC = new RequestConstraint(null, ConstraintType.IN); RequestConstraint oneRC = new RequestConstraint(null, @@ -353,22 +361,35 @@ public class GribDataCatalog extends AbstractInventoryDataCatalog { */ @Override protected Collection get3DLevels() { - NavigableSet tilts = LevelUtilities - .getOrderedSetOfStandardLevels("TILT"); - NavigableSet pres = LevelUtilities - .getOrderedSetOfStandardLevels("MB"); - NavigableSet theta = LevelUtilities - .getOrderedSetOfStandardLevels("K"); ArrayList all = new ArrayList(); - if (pres != null) { - all.addAll(pres); + try { + NavigableSet tilts = LevelUtilities + .getOrderedSetOfStandardLevels("TILT"); + if (tilts != null) { + all.addAll(tilts); + } + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); } - if (tilts != null) { - all.addAll(tilts); + try { + NavigableSet pres = LevelUtilities + .getOrderedSetOfStandardLevels("MB"); + if (pres != null) { + all.addAll(pres); + } + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); } - if (theta != null) { - all.addAll(theta); + try { + NavigableSet theta = LevelUtilities + .getOrderedSetOfStandardLevels("K"); + if (theta != null) { + all.addAll(theta); + } + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); } + return all; } @@ -409,11 +430,20 @@ public class GribDataCatalog extends AbstractInventoryDataCatalog { && lons.isEmpty()) { return null; } + List sources = getSupportedSourcesInternal(); + Map coverages = new HashMap(); + try { + coverages = CoverageUtils.getInstance().getCoverages(sources); + } catch (VizException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + } Set fileredSources = new HashSet(); - for (String source : getSupportedSourcesInternal()) { + for (String source : sources) { try { - GridCoverage coverage = CoverageUtils.getInstance() - .getCoverage(source); + GridCoverage coverage = coverages.get(source); + if (coverage == null) { + coverage = CoverageUtils.getInstance().getCoverage(source); + } if (coverage == null) { fileredSources.add(source); continue; @@ -489,11 +519,19 @@ public class GribDataCatalog extends AbstractInventoryDataCatalog { return results; } ToolsDataManager tdm = ToolsDataManager.getInstance(); + Map coverages = new HashMap(); + try { + coverages = CoverageUtils.getInstance().getCoverages(sources); + } catch (VizException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + } Set validPlanes = new HashSet(sources.size()); for (String source : sources) { try { - GridCoverage coverage = CoverageUtils.getInstance() - .getCoverage(source); + GridCoverage coverage = coverages.get(source); + if (coverage == null) { + coverage = CoverageUtils.getInstance().getCoverage(source); + } if (coverage == null) { Set results = new HashSet(); results.addAll(MenuItemManager.getInstance() diff --git a/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/PointDataCatalog.java b/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/PointDataCatalog.java index 298adadb7b..d0f3ded83e 100644 --- a/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/PointDataCatalog.java +++ b/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/datacatalog/PointDataCatalog.java @@ -41,6 +41,7 @@ import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.time.BinOffset; import com.raytheon.uf.viz.core.catalog.DbQuery; +import com.raytheon.uf.viz.core.exception.VizCommunicationException; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.level.LevelMappingFactory; import com.raytheon.uf.viz.core.rsc.AbstractRequestableResourceData; @@ -386,8 +387,13 @@ public class PointDataCatalog extends AbstractInventoryDataCatalog { */ @Override protected Collection get3DLevels() { - return LevelMappingFactory.getInstance() - .getLevelMappingForKey("Station").getLevels(); + try { + return LevelMappingFactory.getInstance() + .getLevelMappingForKey("Station").getLevels(); + } catch (VizCommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + return Collections.emptyList(); + } } @Override diff --git a/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/widget/MenuContributionItem.java b/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/widget/MenuContributionItem.java index c3b25e8eb0..6c37633d75 100644 --- a/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/widget/MenuContributionItem.java +++ b/cave/com.raytheon.viz.volumebrowser/src/com/raytheon/viz/volumebrowser/widget/MenuContributionItem.java @@ -39,6 +39,8 @@ public class MenuContributionItem extends ContributionItem { protected MenuContribution menuContribution; + protected Image image; + public MenuContributionItem(MenuContribution contribution) { this.menuContribution = contribution; } @@ -131,11 +133,18 @@ public class MenuContributionItem extends ContributionItem { widget.dispose(); widget = null; } + if (image != null) { + image.dispose(); + image = null; + } } public void markDataAvailable(boolean available) { if (available == true) { - createMenuImage(); + if (image == null) { + createMenuImage(); + } + widget.setImage(image); } else { widget.setImage(null); } @@ -145,16 +154,12 @@ public class MenuContributionItem extends ContributionItem { int imgWidth = 10; int imgHeight = 10; - Image menuImg = new Image(widget.getDisplay(), imgWidth, imgHeight); + image = new Image(widget.getDisplay(), imgWidth, imgHeight); - GC gc = new GC(menuImg); + GC gc = new GC(image); drawImage(gc, imgWidth, imgHeight); gc.dispose(); - - widget.setImage(menuImg); - - menuImg.dispose(); } private void drawImage(GC gc, int imgWidth, int imgHeight) { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.edex.plugin.gfe/META-INF/MANIFEST.MF index 0ce63b9f2b..507e7d408f 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/META-INF/MANIFEST.MF @@ -58,6 +58,7 @@ Import-Package: com.raytheon.edex.db.dao, com.raytheon.edex.util, com.raytheon.edex.util.grib, com.raytheon.uf.common.activetable, + com.raytheon.uf.common.comm, com.raytheon.uf.common.dataplugin, com.raytheon.uf.common.dataplugin.annotations, com.raytheon.uf.common.dataplugin.grib, diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java index feab28a660..778b373409 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java @@ -57,6 +57,7 @@ import com.raytheon.edex.plugin.gfe.server.GridParmManager; import com.raytheon.edex.plugin.gfe.server.database.GridDatabase; import com.raytheon.edex.plugin.gfe.util.GridTranslator; import com.raytheon.edex.plugin.gfe.util.SendNotifications; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.PluginException; import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory; @@ -651,16 +652,19 @@ public class GFEDao extends DefaultPluginDao { Level level = null; // to have a level 2, must have a level one - if (levelOnePresent && levelTwoPresent) { - level = LevelFactory.getInstance().getLevel(levelName, - levelValues[0], levelValues[1]); - } else if (levelOnePresent) { - level = LevelFactory.getInstance().getLevel(levelName, - levelValues[0]); - } else { - level = LevelFactory.getInstance().getLevel(levelName, 0.0); + try { + if (levelOnePresent && levelTwoPresent) { + level = LevelFactory.getInstance().getLevel(levelName, + levelValues[0], levelValues[1]); + } else if (levelOnePresent) { + level = LevelFactory.getInstance().getLevel(levelName, + levelValues[0]); + } else { + level = LevelFactory.getInstance().getLevel(levelName, 0.0); + } + } catch (CommunicationException e) { + logger.error(e.getLocalizedMessage(), e); } - if (level == null) { logger.warn("Unable to query D2D parms, ParmID " + id + " does not map to a level"); diff --git a/edexOsgi/com.raytheon.edex.plugin.grib/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.edex.plugin.grib/META-INF/MANIFEST.MF index 3c252d3631..d199bd7e6f 100644 --- a/edexOsgi/com.raytheon.edex.plugin.grib/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.edex.plugin.grib/META-INF/MANIFEST.MF @@ -24,6 +24,7 @@ Require-Bundle: javax.measure, com.raytheon.uf.common.awipstools;bundle-version="1.12.1174", ucar.nc2;bundle-version="1.0.0" Import-Package: com.raytheon.edex.exception, + com.raytheon.uf.common.comm, com.raytheon.uf.common.dataplugin.grib, com.raytheon.uf.common.dataplugin.grib.exception, com.raytheon.uf.common.dataplugin.grib.request, diff --git a/edexOsgi/com.raytheon.edex.plugin.grib/res/spring/grib-request.xml b/edexOsgi/com.raytheon.edex.plugin.grib/res/spring/grib-request.xml index cf55a193c8..4bbbb1e9cc 100644 --- a/edexOsgi/com.raytheon.edex.plugin.grib/res/spring/grib-request.xml +++ b/edexOsgi/com.raytheon.edex.plugin.grib/res/spring/grib-request.xml @@ -16,6 +16,12 @@ + + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/Grib1Decoder.java b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/Grib1Decoder.java index 79b335ed0c..0bdb716032 100644 --- a/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/Grib1Decoder.java +++ b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/Grib1Decoder.java @@ -53,6 +53,7 @@ import com.raytheon.edex.util.Util; import com.raytheon.edex.util.grib.Grib1TableMap; import com.raytheon.edex.util.grib.GribParamTranslator; import com.raytheon.edex.util.grib.GribTableLookup; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.PluginException; import com.raytheon.uf.common.dataplugin.grib.GribModel; import com.raytheon.uf.common.dataplugin.grib.GribRecord; @@ -1225,10 +1226,12 @@ public class Grib1Decoder extends AbstractDecoder { * The level two scale factor * @param value2 * The level two value + * @throws GribException */ private void getLevelInfo(GribModel model, int centerID, int subcenterID, float levelOneNumber, float scaleFactor1, float value1, - float levelTwoNumber, float scaleFactor2, float value2) { + float levelTwoNumber, float scaleFactor2, float value2) + throws GribException { String levelName = null; String levelUnit = null; double levelOneValue = Level.getInvalidLevelValue(); @@ -1281,9 +1284,13 @@ public class Grib1Decoder extends AbstractDecoder { levelOneValue = 0.0; levelTwoValue = Level.getInvalidLevelValue(); } - Level level = LevelFactory.getInstance().getLevel(levelName, - levelOneValue, levelTwoValue, levelUnit); - model.setLevel(level); + try { + Level level = LevelFactory.getInstance().getLevel(levelName, + levelOneValue, levelTwoValue, levelUnit); + model.setLevel(level); + } catch (CommunicationException e) { + throw new GribException("Error requesting levels", e); + } } /** @@ -1301,7 +1308,7 @@ public class Grib1Decoder extends AbstractDecoder { lon = lon % 360; } - if (lon > 180) { + if (lon >= 180) { lon = (180 - lon % 180) * -1; } else if (lon < -180) { lon = (180 - (-lon % 180)); diff --git a/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/decoderpostprocessors/LapsPostProcessor.java b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/decoderpostprocessors/LapsPostProcessor.java index fdb2824b5e..e7b7056919 100644 --- a/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/decoderpostprocessors/LapsPostProcessor.java +++ b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/decoderpostprocessors/LapsPostProcessor.java @@ -21,6 +21,7 @@ package com.raytheon.edex.plugin.grib.decoderpostprocessors; import com.raytheon.edex.plugin.grib.util.GribModelCache; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.grib.GribModel; import com.raytheon.uf.common.dataplugin.grib.GribRecord; import com.raytheon.uf.common.dataplugin.grib.exception.GribException; @@ -62,9 +63,13 @@ public class LapsPostProcessor implements IDecoderPostProcessor { GribModel gribModel = record.getModelInfo(); boolean modelInfoModified = false; if (levelName.equals(FHAG)) { - Level sfcLevel = LevelFactory.getInstance().getLevel(SFC, 0); - gribModel.setLevel(sfcLevel); - modelInfoModified = true; + try { + Level sfcLevel = LevelFactory.getInstance().getLevel(SFC, 0); + gribModel.setLevel(sfcLevel); + modelInfoModified = true; + } catch (CommunicationException e) { + throw new GribException("Error modifying LAPS records.", e); + } } if (gribModel.getParameterAbbreviation().equals(PMSL)) { diff --git a/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/handler/GetCoveragesHandler.java b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/handler/GetCoveragesHandler.java new file mode 100644 index 0000000000..4778a56a99 --- /dev/null +++ b/edexOsgi/com.raytheon.edex.plugin.grib/src/com/raytheon/edex/plugin/grib/handler/GetCoveragesHandler.java @@ -0,0 +1,58 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.edex.plugin.grib.handler; + +import java.util.ArrayList; +import java.util.List; + +import com.raytheon.edex.plugin.grib.spatial.GribSpatialCache; +import com.raytheon.uf.common.dataplugin.grib.request.GetCoveragesRequest; +import com.raytheon.uf.common.dataplugin.grib.spatial.projections.GridCoverage; +import com.raytheon.uf.common.serialization.comm.IRequestHandler; + +/** + * + * TODO Add Description + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Dec 20, 2011            bsteffen     Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class GetCoveragesHandler implements + IRequestHandler { + + @Override + public List handleRequest(GetCoveragesRequest request) { + List result = new ArrayList(); + for (String modelName : request.getModelNames()) { + result.add(GribSpatialCache.getInstance().getGrid(modelName)); + } + return result; + } +} diff --git a/edexOsgi/com.raytheon.edex.plugin.radar/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.edex.plugin.radar/META-INF/MANIFEST.MF index 7e1e3df782..4223f2e7f6 100644 --- a/edexOsgi/com.raytheon.edex.plugin.radar/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.edex.plugin.radar/META-INF/MANIFEST.MF @@ -21,7 +21,8 @@ Export-Package: com.raytheon.edex.plugin.radar, com.raytheon.edex.plugin.radar.level2, com.raytheon.edex.uengine.tasks.radar Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Import-Package: com.raytheon.uf.common.menus, +Import-Package: com.raytheon.uf.common.comm, + com.raytheon.uf.common.menus, com.raytheon.uf.common.menus.xml, com.raytheon.uf.common.site.ingest, org.apache.commons.logging, diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.grib/src/com/raytheon/uf/common/dataplugin/grib/GribRecord.java b/edexOsgi/com.raytheon.uf.common.dataplugin.grib/src/com/raytheon/uf/common/dataplugin/grib/GribRecord.java index 3e0e783317..dc13c6cad0 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.grib/src/com/raytheon/uf/common/dataplugin/grib/GribRecord.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.grib/src/com/raytheon/uf/common/dataplugin/grib/GribRecord.java @@ -22,8 +22,6 @@ package com.raytheon.uf.common.dataplugin.grib; import java.util.Arrays; import java.util.Calendar; -import java.util.Date; -import java.util.TimeZone; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -242,22 +240,6 @@ public class GribRecord extends PersistablePluginDataObject implements return null; } - @Override - public Date getPersistenceTime() { - Calendar c = getInsertTime(); - if (c == null) - return null; - - return c.getTime(); - } - - @Override - public void setPersistenceTime(Date persistTime) { - Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); - c.setTime(persistTime); - setInsertTime(c); - } - @Override public ISpatialObject getSpatialObject() { return modelInfo.getLocation(); @@ -493,6 +475,7 @@ public class GribRecord extends PersistablePluginDataObject implements this.resCompFlags = resCompFlags; } + @Override public void setId(int id) { this.id = id; } @@ -523,12 +506,15 @@ public class GribRecord extends PersistablePluginDataObject implements @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } GribRecord other = (GribRecord) obj; if (!this.dataTime.getRefTimeAsCalendar().equals( other.getDataTime().getRefTimeAsCalendar())) { @@ -541,42 +527,59 @@ public class GribRecord extends PersistablePluginDataObject implements return false; } - if (gridVersion != other.gridVersion) + if (gridVersion != other.gridVersion) { return false; - if (!Arrays.equals(hybridCoordList, other.hybridCoordList)) + } + if (!Arrays.equals(hybridCoordList, other.hybridCoordList)) { return false; - if (hybridGrid != other.hybridGrid) + } + if (hybridGrid != other.hybridGrid) { return false; - if (isVector != other.isVector) + } + if (isVector != other.isVector) { return false; - if (!Arrays.equals(localSection, other.localSection)) + } + if (!Arrays.equals(localSection, other.localSection)) { return false; - if (localSectionUsed != other.localSectionUsed) + } + if (localSectionUsed != other.localSectionUsed) { return false; - if (localTableVersion != other.localTableVersion) + } + if (localTableVersion != other.localTableVersion) { return false; - if (masterTableVersion != other.masterTableVersion) + } + if (masterTableVersion != other.masterTableVersion) { return false; + } if (modelInfo == null) { - if (other.modelInfo != null) + if (other.modelInfo != null) { return false; - } else if (!modelInfo.equals(other.modelInfo)) + } + } else if (!modelInfo.equals(other.modelInfo)) { return false; - if (processedDataType != other.processedDataType) + } + if (processedDataType != other.processedDataType) { return false; - if (productionStatus != other.productionStatus) + } + if (productionStatus != other.productionStatus) { return false; - if (refTimeSignificance != other.refTimeSignificance) + } + if (refTimeSignificance != other.refTimeSignificance) { return false; + } if (resCompFlags == null) { - if (other.resCompFlags != null) + if (other.resCompFlags != null) { return false; - } else if (!resCompFlags.equals(other.resCompFlags)) + } + } else if (!resCompFlags.equals(other.resCompFlags)) { return false; - if (thinnedGrid != other.thinnedGrid) + } + if (thinnedGrid != other.thinnedGrid) { return false; - if (!Arrays.equals(thinnedPts, other.thinnedPts)) + } + if (!Arrays.equals(thinnedPts, other.thinnedPts)) { return false; + } return true; } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/AbstractShaderLoader.java b/edexOsgi/com.raytheon.uf.common.dataplugin.grib/src/com/raytheon/uf/common/dataplugin/grib/request/GetCoveragesRequest.java similarity index 59% rename from cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/AbstractShaderLoader.java rename to edexOsgi/com.raytheon.uf.common.dataplugin.grib/src/com/raytheon/uf/common/dataplugin/grib/request/GetCoveragesRequest.java index 5652c0d8de..5d538a3118 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/glsl/AbstractShaderLoader.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.grib/src/com/raytheon/uf/common/dataplugin/grib/request/GetCoveragesRequest.java @@ -17,36 +17,42 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ -package com.raytheon.viz.core.gl.glsl; +package com.raytheon.uf.common.dataplugin.grib.request; + +import java.util.List; + +import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; +import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; +import com.raytheon.uf.common.serialization.comm.IServerRequest; /** + * * TODO Add Description * *
  * 
  * SOFTWARE HISTORY
+ * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * May 25, 2010            mschenke     Initial creation
+ * Dec 20, 2011            bsteffen     Initial creation
  * 
  * 
* - * @author mschenke + * @author bsteffen * @version 1.0 */ +@DynamicSerialize +public class GetCoveragesRequest implements IServerRequest { + @DynamicSerializeElement + private List modelNames; -public abstract class AbstractShaderLoader implements IShaderLoader { - - private String programName; - - @Override - public final String getName() { - return programName; + public List getModelNames() { + return modelNames; } - @Override - public final void setName(String name) { - this.programName = name; + public void setModelNames(List modelNames) { + this.modelNames = modelNames; } } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.level/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.common.dataplugin.level/META-INF/MANIFEST.MF index b8934fcc66..062600939d 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.level/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.level/META-INF/MANIFEST.MF @@ -19,4 +19,5 @@ Export-Package: com.raytheon.uf.common.dataplugin.level, com.raytheon.uf.common.dataplugin.level.request, com.raytheon.uf.common.dataplugin.level.xml Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Import-Package: org.hibernate.annotations +Import-Package: com.raytheon.uf.common.comm, + org.hibernate.annotations diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/Level.java b/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/Level.java index 3a10a8fa03..db553ce4bd 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/Level.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/Level.java @@ -38,8 +38,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.annotations.DataURI; -import com.raytheon.uf.common.dataplugin.level.util.Constants; import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject; import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; @@ -71,7 +71,8 @@ import com.raytheon.uf.common.status.UFStatus.Priority; @XmlRootElement @XmlType(namespace = "dataplugin-level") public class Level extends PersistableDataObject implements ISerializableObject { - private static final transient IUFStatusHandler statusHandler = UFStatus.getHandler(Level.class); + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(Level.class); public static final double INVALID_VALUE = -999999; @@ -216,7 +217,7 @@ public class Level extends PersistableDataObject implements ISerializableObject dirtyFlag = false; } - public Level getUpperLevel() { + public Level getUpperLevel() throws CommunicationException { Level rval = null; if (isRangeLevel()) { @@ -278,7 +279,7 @@ public class Level extends PersistableDataObject implements ISerializableObject return bestLevel; } - public Level getLowerLevel() { + public Level getLowerLevel() throws CommunicationException { Level rval = null; if (isRangeLevel()) { diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/LevelFactory.java b/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/LevelFactory.java index ed8008a3d0..0ccc5759c5 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/LevelFactory.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/LevelFactory.java @@ -37,6 +37,7 @@ import javax.xml.bind.JAXB; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.level.request.GetLevelByIdRequest; import com.raytheon.uf.common.dataplugin.level.request.GetLevelRequest; import com.raytheon.uf.common.dataplugin.level.request.GetMasterLevelRequest; @@ -98,6 +99,10 @@ public class LevelFactory { private ILevelRetrievalAdapter retrievalAdapter = null; + private boolean hasRequestedAllLevels = false; + + private boolean hasRequestedAllMasterLevels = false; + private static final double INVALID_LEVEL = Level.getInvalidLevelValue(); public static LevelFactory getInstance() { @@ -119,43 +124,58 @@ public class LevelFactory { } loadLevelAliases(); - LoadAllMasterLevels(); - loadMasterLevelFiles(); - loadAllLevels(); + try { + loadAllMasterLevels(); + } catch (CommunicationException e) { + ; // This is non-fatal, master levels should still be retrieved + // individually + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + } + try { + loadAllLevels(); + } catch (CommunicationException e) { + ; // This is non-fatal, master levels should still be retrieved + // individually + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + } } - public void checkMasterLevel(MasterLevel level) { + public void checkMasterLevel(MasterLevel level) + throws CommunicationException { loadMasterLevel(level, true); } - public MasterLevel getMasterLevel(String name) { + public MasterLevel getMasterLevel(String name) + throws CommunicationException { MasterLevel request = new MasterLevel(name); return loadMasterLevel(request, false); } - public Level getLevel(long id) { + public Level getLevel(long id) throws CommunicationException { return loadLevel(id); } - public Level getLevel(String name) { + public Level getLevel(String name) throws CommunicationException { return loadLevel(name); } - public Level getLevel(String name, double levelOneValue) { + public Level getLevel(String name, double levelOneValue) + throws CommunicationException { return getLevel(name, levelOneValue, INVALID_LEVEL, null); } - public Level getLevel(String name, double levelOneValue, String unit) { + public Level getLevel(String name, double levelOneValue, String unit) + throws CommunicationException { return getLevel(name, levelOneValue, INVALID_LEVEL, unit); } public Level getLevel(String name, double levelOneValue, - double levelTwoValue) { + double levelTwoValue) throws CommunicationException { return getLevel(name, levelOneValue, levelTwoValue, null); } public Level getLevel(String name, double levelOneValue, - double levelTwoValue, String unit) { + double levelTwoValue, String unit) throws CommunicationException { Level rval = null; // lookup master level @@ -204,7 +224,8 @@ public class LevelFactory { return rval; } - private MasterLevel loadMasterLevel(MasterLevel level, boolean createFlag) { + private MasterLevel loadMasterLevel(MasterLevel level, boolean createFlag) + throws CommunicationException { MasterLevel rval = null; String levelName = level.getName(); @@ -213,6 +234,9 @@ public class LevelFactory { levelName = levelAliasMap.get(levelName); } + if (!hasRequestedAllMasterLevels) { + loadAllMasterLevels(); + } if (masterLevelCache.containsKey(levelName)) { rval = masterLevelCache.get(levelName); } else if (retrievalAdapter != null) { @@ -243,7 +267,7 @@ public class LevelFactory { return rval; } - private Level loadLevel(Level level) { + private Level loadLevel(Level level) throws CommunicationException { // limit precision to 3 places past the decimal double levelone = ((int) (level.getLevelonevalue() * 1000)) / 1000.0; double leveltwo = ((int) (level.getLeveltwovalue() * 1000)) / 1000.0; @@ -259,6 +283,9 @@ public class LevelFactory { } level.setLevelonevalue(levelone); level.setLeveltwovalue(leveltwo); + if (!hasRequestedAllLevels) { + loadAllLevels(); + } // check if we have already loaded level Level rval = levelCache.get(level); @@ -280,7 +307,10 @@ public class LevelFactory { return rval; } - private Level loadLevel(long id) { + private Level loadLevel(long id) throws CommunicationException { + if (!hasRequestedAllLevels) { + loadAllLevels(); + } // check if we have already loaded level Level rval = levelCacheById.get(id); @@ -298,7 +328,10 @@ public class LevelFactory { return rval; } - private Level loadLevel(String id) { + private Level loadLevel(String id) throws CommunicationException { + if (!hasRequestedAllLevels) { + loadAllLevels(); + } // check if we have already loaded level Level rval = levelCacheByIdAsString.get(id); @@ -386,7 +419,7 @@ public class LevelFactory { } } - private void loadAllLevels() { + private void loadAllLevels() throws CommunicationException { if (retrievalAdapter != null) { LevelContainer container = retrievalAdapter.getAllLevels(); if (container != null) { @@ -408,10 +441,11 @@ public class LevelFactory { } } } + hasRequestedAllLevels = true; } } - private void LoadAllMasterLevels() { + private void loadAllMasterLevels() throws CommunicationException { if (retrievalAdapter != null) { MasterLevelContainer container = retrievalAdapter .getAllMasterLevels(); @@ -426,6 +460,8 @@ public class LevelFactory { } } } + hasRequestedAllMasterLevels = true; + loadMasterLevelFiles(); } } @@ -450,7 +486,7 @@ public class LevelFactory { } - private void loadMasterLevelFile(File file) { + private void loadMasterLevelFile(File file) throws CommunicationException { if (file == null || !file.exists()) { return; } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/MasterLevel.java b/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/MasterLevel.java index 2491294a09..55701cc22f 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/MasterLevel.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/MasterLevel.java @@ -34,11 +34,15 @@ import javax.xml.bind.annotation.XmlRootElement; import org.apache.commons.lang.builder.ToStringBuilder; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.annotations.DataURI; import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject; import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; /** * MasterLevel - once a field is set it cannot be changed. @@ -61,6 +65,9 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; @XmlRootElement public class MasterLevel extends PersistableDataObject implements ISerializableObject { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(MasterLevel.class); + private static final long serialVersionUID = 1L; @Id @@ -151,7 +158,12 @@ public class MasterLevel extends PersistableDataObject implements public Progression getProgression() { if (processType) { - processTypeField(); + try { + processTypeField(); + } catch (CommunicationException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), + e); + } } return progression; @@ -216,7 +228,7 @@ public class MasterLevel extends PersistableDataObject implements return rval; } - private void processTypeField() { + private void processTypeField() throws CommunicationException { if (type != null && type.trim().length() > 0) { try { setProgression(Progression.valueOf(type)); diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/request/ILevelRetrievalAdapter.java b/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/request/ILevelRetrievalAdapter.java index abaaa13b49..2b92acffd3 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/request/ILevelRetrievalAdapter.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.level/src/com/raytheon/uf/common/dataplugin/level/request/ILevelRetrievalAdapter.java @@ -19,6 +19,7 @@ **/ package com.raytheon.uf.common.dataplugin.level.request; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.level.LevelContainer; import com.raytheon.uf.common.dataplugin.level.MasterLevel; @@ -39,16 +40,21 @@ import com.raytheon.uf.common.dataplugin.level.MasterLevelContainer; * @version 1.0 */ public interface ILevelRetrievalAdapter { - public abstract Level getLevel(GetLevelRequest request); + public abstract Level getLevel(GetLevelRequest request) + throws CommunicationException; - public abstract Level getLevel(GetLevelByIdRequest request); + public abstract Level getLevel(GetLevelByIdRequest request) + throws CommunicationException; - public abstract MasterLevel getMasterLevel(GetMasterLevelRequest request); + public abstract MasterLevel getMasterLevel(GetMasterLevelRequest request) + throws CommunicationException; public abstract LevelContainer getAllLevelsForMasterLevel( - GetAllLevelsForMasterLevelRequest request); + GetAllLevelsForMasterLevelRequest request) + throws CommunicationException; - public abstract LevelContainer getAllLevels(); + public abstract LevelContainer getAllLevels() throws CommunicationException; - public abstract MasterLevelContainer getAllMasterLevels(); + public abstract MasterLevelContainer getAllMasterLevels() + throws CommunicationException; } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin/src/com/raytheon/uf/common/dataplugin/persist/DefaultPathProvider.java b/edexOsgi/com.raytheon.uf.common.dataplugin/src/com/raytheon/uf/common/dataplugin/persist/DefaultPathProvider.java index 6409d0f4b4..1cad2b4fba 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin/src/com/raytheon/uf/common/dataplugin/persist/DefaultPathProvider.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin/src/com/raytheon/uf/common/dataplugin/persist/DefaultPathProvider.java @@ -125,19 +125,23 @@ public class DefaultPathProvider implements IHDFFilePathProvider { // This key is not an embedded object meaning it is a field // in the class passed in. We can get the value directly. else { - property = PropertyUtils.getProperty(persistable, key); + try { + property = PropertyUtils.getProperty(persistable, + key); + } catch (Throwable t) { + // Ignore + property = null; + } } // For times and dates, we must format them correctly - if (property == null) { - pathBuilder.append("null"); - } else if (property instanceof Calendar) { + if (property instanceof Calendar) { pathBuilder.append(TimeUtil .formatCalendar((Calendar) property)); } else if (property instanceof Date) { pathBuilder .append(TimeUtil.formatDate((Date) property)); - } else { + } else if (property != null) { pathBuilder.append(property.toString()); } } catch (Exception e) { @@ -226,11 +230,7 @@ public class DefaultPathProvider implements IHDFFilePathProvider { @Override public String getHDFFileName(String pluginName, IPersistable persistable) { Integer partition = persistable.getHdfFileId(); - if (partition == null) { - throw new IllegalArgumentException( - "Expected argument hdfFileId not set on object " - + persistable.toString()); - } else if (pluginName == null) { + if (pluginName == null) { throw new IllegalArgumentException( "Expected argument pluginName not set on object " + persistable.toString()); @@ -262,12 +262,20 @@ public class DefaultPathProvider implements IHDFFilePathProvider { refTimeString = fileNameFormat.format(refTime); } sb.append(refTimeString); - sb.append("-"); - sb.append(partition); + + if (partition != null) { + sb.append("-"); + sb.append(partition); + } + sb.append(".h5"); return sb.toString(); } + if (partition == null) { + return pluginName + ".h5"; + } + return pluginName + "-" + partition + ".h5"; } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin/src/com/raytheon/uf/common/dataplugin/persist/PersistablePluginDataObject.java b/edexOsgi/com.raytheon.uf.common.dataplugin/src/com/raytheon/uf/common/dataplugin/persist/PersistablePluginDataObject.java index 71b7148710..070daa0b09 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin/src/com/raytheon/uf/common/dataplugin/persist/PersistablePluginDataObject.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin/src/com/raytheon/uf/common/dataplugin/persist/PersistablePluginDataObject.java @@ -19,6 +19,10 @@ **/ package com.raytheon.uf.common.dataplugin.persist; +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Inheritance; @@ -91,4 +95,32 @@ public abstract class PersistablePluginDataObject extends PluginDataObject public void setHdfFileId(Integer hdfFileId) { this.hdfFileId = hdfFileId; } + + /** + * Set the time to be used for the persistence time for this object. + * + * @param persistTime + * The persistence time to be used. + */ + @Override + public void setPersistenceTime(Date persistTime) { + Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + c.setTime(persistTime); + setInsertTime(c); + } + + /** + * Get the time to use for persisting this data. + * + * @return The persistence time for this data. + */ + @Override + public Date getPersistenceTime() { + Calendar c = getInsertTime(); + if (c == null) { + return null; + } + + return c.getTime(); + } } diff --git a/edexOsgi/com.raytheon.uf.common.derivparam/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.common.derivparam/META-INF/MANIFEST.MF index fb343199b5..b67a06b60c 100644 --- a/edexOsgi/com.raytheon.uf.common.derivparam/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.common.derivparam/META-INF/MANIFEST.MF @@ -9,6 +9,7 @@ Bundle-ActivationPolicy: lazy Eclipse-RegisterBuddy: com.raytheon.uf.common.serialization Eclipse-BuddyPolicy: registered, ext, global Import-Package: com.raytheon.edex.scriptfactory, + com.raytheon.uf.common.comm, com.raytheon.uf.common.dataplugin.level, com.raytheon.uf.common.serialization, com.raytheon.uf.common.serialization.annotations, diff --git a/edexOsgi/com.raytheon.uf.common.derivparam/src/com/raytheon/uf/common/derivparam/tree/LevelNode.java b/edexOsgi/com.raytheon.uf.common.derivparam/src/com/raytheon/uf/common/derivparam/tree/LevelNode.java index 611421be01..fa5f231a00 100644 --- a/edexOsgi/com.raytheon.uf.common.derivparam/src/com/raytheon/uf/common/derivparam/tree/LevelNode.java +++ b/edexOsgi/com.raytheon.uf.common.derivparam/src/com/raytheon/uf/common/derivparam/tree/LevelNode.java @@ -21,6 +21,7 @@ package com.raytheon.uf.common.derivparam.tree; import javax.persistence.Transient; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.level.LevelFactory; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; @@ -67,7 +68,11 @@ public class LevelNode extends AbstractNode { */ public Level getLevel() { if (value != null && level == null) { - level = LevelFactory.getInstance().getLevel(value); + try { + level = LevelFactory.getInstance().getLevel(value); + } catch (CommunicationException e) { + e.printStackTrace(); + } } return level; } diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.level.handler/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.edex.plugin.level.handler/META-INF/MANIFEST.MF index cf9c17493b..2437a39d63 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.level.handler/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.edex.plugin.level.handler/META-INF/MANIFEST.MF @@ -9,6 +9,7 @@ Require-Bundle: com.raytheon.uf.common.dataplugin, com.raytheon.uf.common.dataplugin.level, com.raytheon.uf.edex.plugin.level Import-Package: com.raytheon.edex.db.dao, + com.raytheon.uf.common.comm, com.raytheon.uf.common.serialization.comm, com.raytheon.uf.edex.database.plugin, org.apache.commons.logging, diff --git a/edexOsgi/com.raytheon.uf.edex.plugin.level/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.edex.plugin.level/META-INF/MANIFEST.MF index 4740682bd5..7687178a07 100644 --- a/edexOsgi/com.raytheon.uf.edex.plugin.level/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.edex.plugin.level/META-INF/MANIFEST.MF @@ -18,3 +18,4 @@ Require-Bundle: com.raytheon.edex.common, Export-Package: com.raytheon.uf.edex.plugin.level.adapter, com.raytheon.uf.edex.plugin.level.dao Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: com.raytheon.uf.common.comm diff --git a/edexOsgi/com.raytheon.uf.edex.pointdata/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.edex.pointdata/META-INF/MANIFEST.MF index c8af37a701..c301a3864f 100644 --- a/edexOsgi/com.raytheon.uf.edex.pointdata/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.edex.pointdata/META-INF/MANIFEST.MF @@ -10,6 +10,7 @@ Import-Package: com.raytheon.edex.db.dao, com.raytheon.edex.exception, com.raytheon.edex.plugin, com.raytheon.edex.uengine.tasks.query, + com.raytheon.uf.common.comm, com.raytheon.uf.common.dataplugin, com.raytheon.uf.common.dataplugin.level, com.raytheon.uf.common.dataplugin.persist, diff --git a/edexOsgi/com.raytheon.uf.edex.pointdata/src/com/raytheon/uf/edex/pointdata/GetPointDataTreeHandler.java b/edexOsgi/com.raytheon.uf.edex.pointdata/src/com/raytheon/uf/edex/pointdata/GetPointDataTreeHandler.java index 6a03fafd3f..5f148cde32 100644 --- a/edexOsgi/com.raytheon.uf.edex.pointdata/src/com/raytheon/uf/edex/pointdata/GetPointDataTreeHandler.java +++ b/edexOsgi/com.raytheon.uf.edex.pointdata/src/com/raytheon/uf/edex/pointdata/GetPointDataTreeHandler.java @@ -26,7 +26,6 @@ import java.util.Map.Entry; import com.raytheon.edex.uengine.tasks.query.CatalogQuery; import com.raytheon.edex.uengine.tasks.query.MetadataCatalogQuery; -import com.raytheon.uf.common.dataplugin.level.Level; import com.raytheon.uf.common.dataplugin.level.LevelFactory; import com.raytheon.uf.common.derivparam.tree.DataTree; import com.raytheon.uf.common.pointdata.GetPointDataTreeRequest; @@ -52,16 +51,14 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; public class GetPointDataTreeHandler implements IRequestHandler { - public static final Level STATION = LevelFactory.getInstance().getLevel( - LevelFactory.UNKNOWN_LEVEL, 0.0); - public static final String PLUGIN_NAME = "pluginName"; @Override public DataTree handleRequest(GetPointDataTreeRequest request) throws Exception { DataTree tree = new DataTree(); - String stationId = Long.toString(STATION.getId()); + String stationId = Long.toString(LevelFactory.getInstance() + .getLevel(LevelFactory.UNKNOWN_LEVEL, 0.0).getId()); for (Entry entry : request.getPluginTypeKeyMap() .entrySet()) { String[] types = getAvailableTypes(entry.getKey(), entry.getValue()); diff --git a/ncep/gov.noaa.nws.ncep.edex.plugin.ncgrib/META-INF/MANIFEST.MF b/ncep/gov.noaa.nws.ncep.edex.plugin.ncgrib/META-INF/MANIFEST.MF index e5844586eb..d5d48f949d 100644 --- a/ncep/gov.noaa.nws.ncep.edex.plugin.ncgrib/META-INF/MANIFEST.MF +++ b/ncep/gov.noaa.nws.ncep.edex.plugin.ncgrib/META-INF/MANIFEST.MF @@ -19,8 +19,9 @@ Require-Bundle: javax.measure, com.raytheon.uf.common.serialization.comm, com.raytheon.uf.edex.python.decoder;bundle-version="1.11.26", gov.noaa.nws.ncep.common.dataplugin.ncgrib;bundle-version="1.0.0", - ucar.nc2;bundle-version="1.0.0" -Import-Package: com.raytheon.uf.common.dataplugin.level, + ucar.nc2 +Import-Package: com.raytheon.uf.common.comm, + com.raytheon.uf.common.dataplugin.level, com.raytheon.uf.common.derivparam.tree, com.raytheon.uf.common.status, gov.noaa.nws.ncep.common.dataplugin.ncgrib, diff --git a/ncep/gov.noaa.nws.ncep.edex.plugin.ncgrib/src/gov/noaa/nws/ncep/edex/plugin/ncgrib/Ncgrib1Decoder.java b/ncep/gov.noaa.nws.ncep.edex.plugin.ncgrib/src/gov/noaa/nws/ncep/edex/plugin/ncgrib/Ncgrib1Decoder.java index 4db902642f..6205dd9227 100644 --- a/ncep/gov.noaa.nws.ncep.edex.plugin.ncgrib/src/gov/noaa/nws/ncep/edex/plugin/ncgrib/Ncgrib1Decoder.java +++ b/ncep/gov.noaa.nws.ncep.edex.plugin.ncgrib/src/gov/noaa/nws/ncep/edex/plugin/ncgrib/Ncgrib1Decoder.java @@ -67,6 +67,7 @@ import gov.noaa.nws.ncep.edex.util.grib2vars.Grib2VarsTableLookup; import gov.noaa.nws.ncep.edex.util.grib2vcrd.Grib2Vcrd; import com.raytheon.edex.util.Util; +import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.PluginException; import com.raytheon.edex.plugin.AbstractDecoder; import com.raytheon.uf.common.dataplugin.level.Level; @@ -1193,10 +1194,11 @@ public class Ncgrib1Decoder extends AbstractDecoder { * The level two scale factor * @param value2 * The level two value + * @throws GribException */ private void getLevelInfo(NcgribModel model, int centerID, int subcenterID, float levelOneNumber, float scaleFactor1, float value1, - float levelTwoNumber, float scaleFactor2, float value2) { + float levelTwoNumber, float scaleFactor2, float value2) throws GribException { String levelName = null; String levelUnit = null; double levelOneValue = Level.getInvalidLevelValue(); @@ -1246,9 +1248,13 @@ public class Ncgrib1Decoder extends AbstractDecoder { * -1)); } } - Level level = LevelFactory.getInstance().getLevel(levelName, - levelOneValue, levelTwoValue, levelUnit); - model.setLevel(level); + try { + Level level = LevelFactory.getInstance().getLevel(levelName, + levelOneValue, levelTwoValue, levelUnit); + model.setLevel(level); + } catch (CommunicationException e) { + throw new GribException("Error loading level.", e); + } } /** diff --git a/ncep/gov.noaa.nws.ncep.viz.rsc.plotdata/src/gov/noaa/nws/ncep/viz/rsc/plotdata/plotModels/PlotModelGenerator2.java b/ncep/gov.noaa.nws.ncep.viz.rsc.plotdata/src/gov/noaa/nws/ncep/viz/rsc/plotdata/plotModels/PlotModelGenerator2.java index 1833cd549b..db65376b78 100644 --- a/ncep/gov.noaa.nws.ncep.viz.rsc.plotdata/src/gov/noaa/nws/ncep/viz/rsc/plotdata/plotModels/PlotModelGenerator2.java +++ b/ncep/gov.noaa.nws.ncep.viz.rsc.plotdata/src/gov/noaa/nws/ncep/viz/rsc/plotdata/plotModels/PlotModelGenerator2.java @@ -446,12 +446,12 @@ public class PlotModelGenerator2 extends Job { // key is a formatted lat/lon string Map plotMap = new HashMap(); - Map timeMap = new HashMap(); + Map timeMap = new HashMap(); for( PlotInfo info : stationQueue ) { plotMap.put( formatLatLonKey(info.latitude, info.longitude ), info); - timeMap.put( info.id, info.dataTime); + timeMap.put( info.dataURI, info.dataTime); stationQuery.add(info); } @@ -490,7 +490,7 @@ public class PlotModelGenerator2 extends Job { String[] str = new String[stationQuery.size()]; for (int z = 0; z < str.length; z++) { - str[z] = "" + stationQuery.get(z).id; + str[z] = "" + stationQuery.get(z).dataURI; } int index = 0; @@ -509,7 +509,7 @@ public class PlotModelGenerator2 extends Job { j++; } - map.put("id", rc); + map.put("dataURI", rc); try { // Try and get data from datacube diff --git a/ncep/gov.noaa.nws.ncep.viz.rsc.plotdata/src/gov/noaa/nws/ncep/viz/rsc/plotdata/rsc/PlotResource2.java b/ncep/gov.noaa.nws.ncep.viz.rsc.plotdata/src/gov/noaa/nws/ncep/viz/rsc/plotdata/rsc/PlotResource2.java index 46f76d4ea6..d0a409c12c 100644 --- a/ncep/gov.noaa.nws.ncep.viz.rsc.plotdata/src/gov/noaa/nws/ncep/viz/rsc/plotdata/rsc/PlotResource2.java +++ b/ncep/gov.noaa.nws.ncep.viz.rsc.plotdata/src/gov/noaa/nws/ncep/viz/rsc/plotdata/rsc/PlotResource2.java @@ -952,7 +952,7 @@ public class PlotResource2 extends AbstractNatlCntrsResource