Omaha #4937 Extract SatRenderable from SatResource.

Former-commit-id: c09796530347215928aabcd7c15962060047a0dd
This commit is contained in:
Ben Steffensmeier 2015-10-12 11:10:44 -05:00
parent 6a14aab19c
commit 35258da67f
3 changed files with 240 additions and 174 deletions

View file

@ -19,10 +19,17 @@
**/
package com.raytheon.uf.viz.daylight.transition.resource;
import java.util.List;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.satellite.SatelliteRecord;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.viz.core.drawables.IRenderable;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.viz.daylight.transition.tileset.DaylightTransitionTileSetRenderable;
import com.raytheon.viz.satellite.rsc.SatResource;
import com.raytheon.viz.satellite.tileset.SatRenderable;
import com.raytheon.viz.satellite.tileset.SatTileSetRenderable;
/**
@ -38,6 +45,7 @@ import com.raytheon.viz.satellite.tileset.SatTileSetRenderable;
* Date Ticket# Engineer Description
* ------------- -------- ----------- --------------------------
* Jul 28, 2015 4633 bsteffen Initial creation
* Oct 12, 2015 4937 bsteffen Move SatRenderable to new class, extend it here.
*
* </pre>
*
@ -54,12 +62,30 @@ public class DaylightTransitionSatResource extends SatResource {
this.resourceData = data;
}
@Override
protected SatTileSetRenderable createTileSet(SatelliteRecord record) {
SatTileSetRenderable tileSet = new DaylightTransitionTileSetRenderable(
this, record, resourceData.getSunDelta());
tileSet.project(descriptor.getGridGeometry());
return tileSet;
protected IRenderable constructRenderable(DataTime time,
List<PluginDataObject> records) throws VizException {
SatRenderable renderable = new DaylightTransitionSatRenderable(time);
updateRenderable(renderable, records.toArray(new PluginDataObject[0]));
renderable.project();
return renderable;
}
private class DaylightTransitionSatRenderable extends SatRenderable {
public DaylightTransitionSatRenderable(DataTime renderableTime) {
super(DaylightTransitionSatResource.this, renderableTime);
}
@Override
protected SatTileSetRenderable createTileSet(SatelliteRecord record) {
SatTileSetRenderable tileSet = new DaylightTransitionTileSetRenderable(
DaylightTransitionSatResource.this, record,
resourceData.getSunDelta());
tileSet.project(descriptor.getGridGeometry());
return tileSet;
}
}
}

View file

@ -21,7 +21,6 @@ package com.raytheon.viz.satellite.rsc;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@ -45,7 +44,6 @@ import com.raytheon.uf.common.colormap.prefs.ColorMapParameters;
import com.raytheon.uf.common.colormap.prefs.ColorMapParameters.PersistedParameters;
import com.raytheon.uf.common.colormap.prefs.DataMappingPreferences;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.satellite.SatMapCoverage;
import com.raytheon.uf.common.dataplugin.satellite.SatelliteRecord;
import com.raytheon.uf.common.datastorage.DataStoreFactory;
import com.raytheon.uf.common.datastorage.Request;
@ -91,8 +89,8 @@ import com.raytheon.viz.awipstools.IToolChangedListener;
import com.raytheon.viz.satellite.SatelliteConstants;
import com.raytheon.viz.satellite.inventory.DerivedSatelliteRecord;
import com.raytheon.viz.satellite.tileset.SatDataRetriever;
import com.raytheon.viz.satellite.tileset.SatTileSetRenderable;
import com.vividsolutions.jts.geom.Coordinate;
import com.raytheon.viz.satellite.tileset.SatRenderable;
import com.raytheon.viz.satellite.tileset.SatRenderable.InterrogationResult;
/**
* Provides satellite raster rendering support
@ -138,6 +136,7 @@ import com.vividsolutions.jts.geom.Coordinate;
* Apr 15, 2014 4388 bsteffen Use fill value from record.
* Jul 28, 2015 4633 bsteffen Create tileset in resource so it can be
* overridden for daylight transition.
* Oct 08, 2015 4937 bsteffen Move SatRenderable to new class.
*
* </pre>
*
@ -168,128 +167,6 @@ public class SatResource extends
private static final InterrogationKey<GeographicDataSource> DATA_SOURCE_INTERROGATE_KEY = new ClassInterrogationKey<>(
GeographicDataSource.class);
private static class InterrogationResult {
private final SatTileSetRenderable renderable;
private final double value;
public InterrogationResult(SatTileSetRenderable renderable, double value) {
this.renderable = renderable;
this.value = value;
}
public SatelliteRecord getRecord() {
return renderable.getSatelliteRecord();
}
public double getValue() {
return value;
}
public GeographicDataSource getDataSource() {
return renderable.getCurrentLevelDataSource();
}
}
private class SatRenderable implements IRenderable {
private Map<SatMapCoverage, SatTileSetRenderable> tileMap = new HashMap<SatMapCoverage, SatTileSetRenderable>();
private DataTime renderableTime;
public SatRenderable(DataTime renderableTime) {
this.renderableTime = renderableTime;
}
@Override
public void paint(IGraphicsTarget target, PaintProperties paintProps)
throws VizException {
Collection<DrawableImage> images = getImagesToRender(target,
paintProps);
if (images.isEmpty() == false) {
target.drawRasters(paintProps,
images.toArray(new DrawableImage[0]));
}
}
public Collection<DrawableImage> getImagesToRender(
IGraphicsTarget target, PaintProperties paintProps)
throws VizException {
List<DrawableImage> images = new ArrayList<DrawableImage>();
synchronized (tileMap) {
for (SatTileSetRenderable renderable : tileMap.values()) {
images.addAll(renderable.getImagesToRender(target,
paintProps));
}
}
return images;
}
public void addRecord(SatelliteRecord record) {
synchronized (tileMap) {
SatTileSetRenderable tileSet = tileMap
.get(record.getCoverage());
if (tileSet != null) {
SatelliteRecord existingRecord = tileSet
.getSatelliteRecord();
if (existingRecord.equals(record) == false) {
// Different record, same spatial area for same frame
// Determine if new one is better than existing
long existingTimeMillis = existingRecord.getDataTime()
.getMatchRef();
long newRecordTimeMillis = record.getDataTime()
.getMatchRef();
long normalTimeMillis = renderableTime.getMatchRef();
if (Math.abs(normalTimeMillis - newRecordTimeMillis) < Math
.abs(normalTimeMillis - existingTimeMillis)) {
// New is better since it's data time is closer to
// the normal time than the existing record's time!
tileSet.dispose();
tileSet = null;
}
}
}
if (tileSet == null) {
tileSet = createTileSet(record);
tileMap.put(record.getCoverage(), tileSet);
}
}
}
public void project() {
synchronized (tileMap) {
for (SatTileSetRenderable renderable : tileMap.values()) {
renderable.project(descriptor.getGridGeometry());
}
}
}
public void dispose() {
synchronized (tileMap) {
for (SatTileSetRenderable renderable : tileMap.values()) {
renderable.dispose();
}
tileMap.clear();
}
}
public InterrogationResult interrogate(Coordinate latLon,
Unit<?> requestUnit) throws VizException {
InterrogationResult result = null;
synchronized (tileMap) {
for (SatTileSetRenderable renderable : tileMap.values()) {
double rValue = renderable.interrogate(latLon, requestUnit);
if (Double.isNaN(rValue) == false) {
result = new InterrogationResult(renderable, rValue);
}
}
}
return result;
}
}
protected String legend;
protected SamplePreferences sampleRange;
@ -307,13 +184,6 @@ public class SatResource extends
addDataObject(data.getRecords());
}
protected SatTileSetRenderable createTileSet(SatelliteRecord record) {
SatTileSetRenderable tileSet = new SatTileSetRenderable(
this, record);
tileSet.project(descriptor.getGridGeometry());
return tileSet;
}
@Override
protected DataTime getDataObjectTime(PluginDataObject pdo) {
if (initialized == false) {
@ -351,7 +221,6 @@ this, record);
}
Unit<?> unit = SatDataRetriever.getRecordUnit(record);
/*
* TODO default to NaN instead of 0. 0 is the default to support older
* data(before the gini decoder set a fill value), when all decoders and
@ -548,7 +417,8 @@ this, record);
if (dataMapping != null) {
// if the pixel value matches the data mapping entry use that
// label instead
String label = dataMapping.getSampleOrLabelValueForDataValue(measuredValue);
String label = dataMapping
.getSampleOrLabelValueForDataValue(measuredValue);
if (label != null) {
return label;
}
@ -603,37 +473,17 @@ this, record);
return Collections.emptyList();
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.core.rsc.AbstractPluginDataObjectResource#
* capabilityChanged(com.raytheon.uf.viz.core.drawables.IRenderable,
* com.raytheon.uf.viz.core.rsc.capabilities.AbstractCapability)
*/
@Override
protected void capabilityChanged(IRenderable renderable,
AbstractCapability capability) {
issueRefresh();
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.core.rsc.AbstractPluginDataObjectResource#
* disposeRenderable(com.raytheon.uf.viz.core.drawables.IRenderable)
*/
@Override
protected void disposeRenderable(IRenderable renderable) {
((SatRenderable) renderable).dispose();
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.core.rsc.AbstractPluginDataObjectResource#
* projectRenderable(com.raytheon.uf.viz.core.drawables.IRenderable,
* org.opengis.referencing.crs.CoordinateReferenceSystem)
*/
@Override
protected boolean projectRenderable(IRenderable renderable,
CoordinateReferenceSystem crs) throws VizException {
@ -641,28 +491,15 @@ this, record);
return true;
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.core.rsc.AbstractPluginDataObjectResource#
* constructRenderable(com.raytheon.uf.common.time.DataTime, java.util.List)
*/
@Override
protected IRenderable constructRenderable(DataTime time,
List<PluginDataObject> records) throws VizException {
SatRenderable renderable = new SatRenderable(time);
SatRenderable renderable = new SatRenderable(this, time);
updateRenderable(renderable, records.toArray(new PluginDataObject[0]));
renderable.project();
return renderable;
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.core.rsc.AbstractPluginDataObjectResource#
* updateRenderable(com.raytheon.uf.viz.core.drawables.IRenderable,
* com.raytheon.uf.common.dataplugin.PluginDataObject[])
*/
@Override
protected boolean updateRenderable(IRenderable renderable,
PluginDataObject... pdos) {

View file

@ -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.satellite.tileset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.measure.unit.Unit;
import com.raytheon.uf.common.dataplugin.satellite.SatMapCoverage;
import com.raytheon.uf.common.dataplugin.satellite.SatelliteRecord;
import com.raytheon.uf.common.geospatial.data.GeographicDataSource;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.viz.core.DrawableImage;
import com.raytheon.uf.viz.core.IGraphicsTarget;
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.AbstractVizResource;
import com.vividsolutions.jts.geom.Coordinate;
/**
*
* Renderable for displaying multiple {@link SatelliteRecord}s at the same time.
* Each SatelliteRecord is rendered using a {@link SatTileSetRenderable}. Only
* one record with the same {@link SatMapCoverage} can be contained in the
* renderable to prevent overlap. This renderable is not designed to handle
* overlapping records, it should be used for single records or multiple records
* from a pre-tiled source(such as GOES-R or Himawari CMI).
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------- -------- --------- --------------------------
* Oct 08, 2015 4937 bsteffen Extracted from SatResource
*
* </pre>
*
* @author bsteffen
* @version 1.0
*/
public class SatRenderable implements IRenderable {
private final AbstractVizResource<?, ?> resource;
private Map<SatMapCoverage, SatTileSetRenderable> tileMap = new HashMap<SatMapCoverage, SatTileSetRenderable>();
private DataTime renderableTime;
public SatRenderable(AbstractVizResource<?, ?> resource,
DataTime renderableTime) {
this.resource = resource;
this.renderableTime = renderableTime;
}
@Override
public void paint(IGraphicsTarget target, PaintProperties paintProps)
throws VizException {
Collection<DrawableImage> images = getImagesToRender(target,
paintProps);
if (images.isEmpty() == false) {
target.drawRasters(paintProps,
images.toArray(new DrawableImage[0]));
}
}
public Collection<DrawableImage> getImagesToRender(
IGraphicsTarget target, PaintProperties paintProps)
throws VizException {
List<DrawableImage> images = new ArrayList<DrawableImage>();
synchronized (tileMap) {
for (SatTileSetRenderable renderable : tileMap.values()) {
images.addAll(renderable.getImagesToRender(target,
paintProps));
}
}
return images;
}
public void addRecord(SatelliteRecord record) {
synchronized (tileMap) {
SatTileSetRenderable tileSet = tileMap
.get(record.getCoverage());
if (tileSet != null) {
SatelliteRecord existingRecord = tileSet
.getSatelliteRecord();
if (existingRecord.equals(record) == false) {
// Different record, same spatial area for same frame
// Determine if new one is better than existing
long existingTimeMillis = existingRecord.getDataTime()
.getMatchRef();
long newRecordTimeMillis = record.getDataTime()
.getMatchRef();
long normalTimeMillis = renderableTime.getMatchRef();
if (Math.abs(normalTimeMillis - newRecordTimeMillis) < Math
.abs(normalTimeMillis - existingTimeMillis)) {
// New is better since it's data time is closer to
// the normal time than the existing record's time!
tileSet.dispose();
tileSet = null;
}
}
}
if (tileSet == null) {
tileSet = createTileSet(record);
tileMap.put(record.getCoverage(), tileSet);
}
}
}
protected SatTileSetRenderable createTileSet(SatelliteRecord record) {
SatTileSetRenderable tileSet = new SatTileSetRenderable(resource,
record);
tileSet.project(resource.getDescriptor().getGridGeometry());
return tileSet;
}
public void project() {
synchronized (tileMap) {
for (SatTileSetRenderable renderable : tileMap.values()) {
renderable.project(resource.getDescriptor().getGridGeometry());
}
}
}
public void dispose() {
synchronized (tileMap) {
for (SatTileSetRenderable renderable : tileMap.values()) {
renderable.dispose();
}
tileMap.clear();
}
}
public InterrogationResult interrogate(Coordinate latLon,
Unit<?> requestUnit) throws VizException {
InterrogationResult result = null;
synchronized (tileMap) {
for (SatTileSetRenderable renderable : tileMap.values()) {
double rValue = renderable.interrogate(latLon, requestUnit);
if (Double.isNaN(rValue) == false) {
result = new InterrogationResult(renderable,
rValue);
}
}
}
return result;
}
/**
* The result of interrogating a {@link SatRenderable}. Usually the value is
* the only thing of interest to the caller but this object makes it
* possible to get more specific information from the specific
* {@link SatTileSetRenderable} that was used to get the value.
*/
public static class InterrogationResult {
private final SatTileSetRenderable renderable;
private final double value;
public InterrogationResult(SatTileSetRenderable renderable, double value) {
this.renderable = renderable;
this.value = value;
}
public SatelliteRecord getRecord() {
return renderable.getSatelliteRecord();
}
public double getValue() {
return value;
}
public GeographicDataSource getDataSource() {
return renderable.getCurrentLevelDataSource();
}
}
}