Issue #2211 Fix data mapped sampling.

Former-commit-id: 3d76d6655b [formerly 724bb85676 [formerly aec317f506eb940e843a0c3cf4ffa55a83eb186b]]
Former-commit-id: 724bb85676
Former-commit-id: d219a687c9
This commit is contained in:
Ben Steffensmeier 2014-02-07 12:59:34 -06:00
parent c275da6725
commit e7baa5b186
3 changed files with 96 additions and 69 deletions

View file

@ -36,6 +36,7 @@ import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
import com.raytheon.uf.common.colormap.prefs.ColorMapParameters;
import com.raytheon.uf.common.geospatial.CRSCache;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
@ -63,14 +64,17 @@ import com.vividsolutions.jts.geom.Coordinate;
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 8, 2012 mschenke Initial creation
* May 28, 2013 2037 njensen Made imageMap concurrent to fix leak
* Jun 20, 2013 2122 mschenke Fixed null pointer in interrogate and made
* canceling jobs safer
* Oct 16, 2013 2333 mschenke Added auto NaN checking for interrogation
* Nov 14, 2013 2492 mschenke Added more interrogate methods that take units
* Date Ticket# Engineer Description
* ------------- -------- ----------- -----------------------------------------
* Aug 08, 2012 mschenke Initial creation
* May 28, 2013 2037 njensen Made imageMap concurrent to fix leak
* Jun 20, 2013 2122 mschenke Fixed null pointer in interrogate and
* made canceling jobs safer
* Oct 16, 2013 2333 mschenke Added auto NaN checking for interrogation
* Nov 14, 2013 2492 mschenke Added more interrogate methods that take
* units
* Feb 07, 2014 2211 bsteffen Fix sampling units when data mapping is
* enabled.
*
* </pre>
*
@ -539,55 +543,65 @@ public class TileSetRenderable implements IRenderable {
public double interrogate(Coordinate coordinate, Unit<?> resultUnit,
double nanValue) throws VizException {
double dataValue = Double.NaN;
TileLevel level = tileSet.getTileLevel(lastPaintedLevel);
double[] grid = null;
try {
double[] local = new double[2];
llToLocalProj
.transform(new double[] { coordinate.x, coordinate.y }, 0,
local, 0, 1);
double localX = local[0];
double localY = local[1];
TileLevel level = tileSet.getTileLevel(lastPaintedLevel);
double[] grid = level.crsToGrid(localX, localY);
Tile tile = level.getTile(grid[0], grid[1]);
if (tile != null) {
DrawableImage di = imageMap.get(tile);
if (di != null) {
IImage image = di.getImage();
if (image instanceof IColormappedImage) {
IColormappedImage cmapImage = (IColormappedImage) image;
dataValue = cmapImage.getValue(
(int) grid[0] % tileSize, (int) grid[1]
% tileSize);
if (dataValue == nanValue) {
dataValue = Double.NaN;
} else {
Unit<?> dataUnit = cmapImage.getDataUnit();
if (resultUnit != null && dataUnit != null
&& dataUnit.equals(resultUnit) == false) {
if (resultUnit.isCompatible(dataUnit)) {
dataValue = dataUnit.getConverterTo(
resultUnit).convert(dataValue);
} else {
throw new IllegalArgumentException(
"Unable to interrogate tile set. "
+ String.format(
"Desired unit (%s) is not compatible with data unit (%s).",
UnitFormat
.getUCUMInstance()
.format(resultUnit),
UnitFormat
.getUCUMInstance()
.format(dataUnit)));
}
}
}
}
}
}
grid = level.crsToGrid(local[0], local[1]);
} catch (TransformException e) {
throw new VizException("Error interrogating ", e);
}
IColormappedImage cmapImage = null;
Tile tile = level.getTile(grid[0], grid[1]);
if (tile != null) {
DrawableImage di = imageMap.get(tile);
if (di != null) {
IImage image = di.getImage();
if (image instanceof IColormappedImage) {
cmapImage = (IColormappedImage) image;
}
}
}
if (cmapImage != null) {
dataValue = cmapImage.getValue((int) grid[0] % tileSize,
(int) grid[1] % tileSize);
if (dataValue == nanValue) {
dataValue = Double.NaN;
} else {
ColorMapParameters parameters = cmapImage
.getColorMapParameters();
Unit<?> dataUnit = cmapImage.getDataUnit();
if (parameters.getDataMapping() != null) {
/*
* Ignore dataUnit, use colorMapUnit which is derived from
* the data mapping
*/
dataUnit = parameters.getColorMapUnit();
}
if (resultUnit != null && dataUnit != null
&& dataUnit.equals(resultUnit) == false) {
if (resultUnit.isCompatible(dataUnit)) {
dataValue = dataUnit.getConverterTo(resultUnit)
.convert(dataValue);
} else {
UnitFormat uf = UnitFormat.getUCUMInstance();
String message = String
.format("Unable to interrogate tile set. Desired unit (%s) is not compatible with data unit (%s).",
uf.format(resultUnit),
uf.format(dataUnit));
throw new IllegalArgumentException(message);
}
}
}
}
return dataValue;
}
}

View file

@ -21,7 +21,10 @@ package com.raytheon.viz.grid.rsc;
import java.util.Map;
import javax.measure.converter.UnitConverter;
import com.raytheon.uf.common.colormap.prefs.ColorMapParameters;
import com.raytheon.uf.common.colormap.prefs.DataMappingPreferences;
import com.raytheon.uf.common.colormap.prefs.DataMappingPreferences.DataMappingEntry;
import com.raytheon.uf.common.geospatial.ReferencedCoordinate;
import com.raytheon.uf.viz.core.exception.VizException;
@ -39,9 +42,11 @@ import com.raytheon.viz.grid.rsc.general.GeneralGridData;
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 13, 2010 bsteffen Initial creation
* Date Ticket# Engineer Description
* ------------- -------- ----------- --------------------------
* Oct 13, 2010 bsteffen Initial creation
* Feb 07, 2014 2211 bsteffen Fix sampling
*
*
* </pre>
*
@ -71,29 +76,36 @@ public class DataMappedGridResource extends D2DGridResource {
if (map == null) {
return "NO DATA";
}
Double val = ((Float) map.get(INTERROGATE_VALUE)).doubleValue();
Double val = ((Number) map.get(INTERROGATE_VALUE)).doubleValue();
if (val.isNaN() || val <= -9999) {
return "No Data";
}
ColorMapParameters params = getCapability(ColorMapCapability.class)
.getColorMapParameters();
if (params != null) {
UnitConverter d2cm = params.getDisplayToColorMapConverter();
if (d2cm != null) {
val = d2cm.convert(val);
}
val = params.getDisplayToImageConverter().convert(val);
DataMappingPreferences dataMapping = params.getDataMapping();
if (dataMapping != null) {
for (DataMappingEntry entry : dataMapping.getEntries()) {
double pixelValue = entry.getPixelValue();
double relError = Math.abs((pixelValue - val) / val);
String text = entry.getLabel();
if (relError < 0.00001 && text != null) {
return text;
}
}
}
for (DataMappingEntry entry : params.getDataMapping().getEntries()) {
double pixelValue = entry.getPixelValue();
double relError = Math.abs((pixelValue - val) / val);
String text = entry.getLabel();
if (relError < 0.00001 && text != null) {
return text;
UnitConverter cm2d = params.getColorMapToDisplayConverter();
if (cm2d != null) {
val = cm2d.convert(val);
}
}
if (params != null && params.getImageToDisplayConverter() != null) {
val = params.getImageToDisplayConverter().convert(val);
}
return ((DataMappedGridResourceData) this.getResourceData())
.getSampleFormat().format(val) + map.get(INTERROGATE_UNIT);
}

View file

@ -39,9 +39,10 @@ import com.raytheon.viz.grid.rsc.general.GeneralGridData;
* <pre>
*
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 16, 2009 mnash Initial creation
* Date Ticket# Engineer Description
* ------------- -------- ----------- --------------------------
* Dec 16, 2009 mnash Initial creation
* Feb 07, 2014 2211 bsteffen Fix sampling
*
* </pre>
*
@ -71,7 +72,7 @@ public class RcmResource extends D2DGridResource {
if (map == null) {
return "NO DATA";
}
float val = (Float) map.get(INTERROGATE_VALUE);
float val = ((Number) map.get(INTERROGATE_VALUE)).floatValue();
String sampleVal = "";
if (val < 1f) {
sampleVal = "No Data";