Issue #2791 Use Data Source for all grid data access.
Former-commit-id: 961c232e35da077ef4fc0b62cb04a8f4cb9fb6f0
This commit is contained in:
parent
45e8290111
commit
05770129c1
14 changed files with 650 additions and 297 deletions
|
@ -0,0 +1,133 @@
|
||||||
|
package com.raytheon.uf.viz.core.tile;
|
||||||
|
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.nio.Buffer;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.FloatBuffer;
|
||||||
|
import java.nio.IntBuffer;
|
||||||
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
|
import javax.measure.unit.Unit;
|
||||||
|
|
||||||
|
import org.geotools.coverage.grid.GeneralGridGeometry;
|
||||||
|
|
||||||
|
import com.raytheon.uf.common.colormap.image.ColorMapData;
|
||||||
|
import com.raytheon.uf.common.colormap.image.ColorMapData.ColorMapDataType;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.ByteBufferWrapper;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataDestination;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataUtilities;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.FloatBufferWrapper;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.IntBufferWrapper;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.OffsetDataSource;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.ShortBufferWrapper;
|
||||||
|
import com.raytheon.uf.viz.core.DrawableImage;
|
||||||
|
import com.raytheon.uf.viz.core.IGraphicsTarget;
|
||||||
|
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.data.IColorMapDataRetrievalCallback;
|
||||||
|
import com.raytheon.uf.viz.core.drawables.IImage;
|
||||||
|
import com.raytheon.uf.viz.core.drawables.ext.colormap.IColormappedImageExtension;
|
||||||
|
import com.raytheon.uf.viz.core.exception.VizException;
|
||||||
|
import com.raytheon.uf.viz.core.map.IMapMeshExtension;
|
||||||
|
import com.raytheon.uf.viz.core.rsc.capabilities.ColorMapCapability;
|
||||||
|
import com.raytheon.uf.viz.core.tile.TileSetRenderable.TileImageCreator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Create imagery from any source of numeric data.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------- -------- ----------- --------------------------
|
||||||
|
* Feb 25, 2014 2791 bsteffen Initial creation
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author bsteffen
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class DataSourceTileImageCreator implements TileImageCreator {
|
||||||
|
|
||||||
|
private class DataSourceColorMapRetrievalCallback implements
|
||||||
|
IColorMapDataRetrievalCallback {
|
||||||
|
|
||||||
|
private final Rectangle slice;
|
||||||
|
|
||||||
|
private DataSourceColorMapRetrievalCallback(Rectangle slice) {
|
||||||
|
this.slice = slice;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ColorMapData getColorMapData() throws VizException {
|
||||||
|
ColorMapData data = new ColorMapData(dataType, new int[] {
|
||||||
|
slice.width, slice.height });
|
||||||
|
Buffer buffer = data.getBuffer();
|
||||||
|
DataDestination dest = null;
|
||||||
|
if (buffer instanceof ByteBuffer) {
|
||||||
|
dest = new ByteBufferWrapper((ByteBuffer) buffer, slice.width,
|
||||||
|
slice.height);
|
||||||
|
} else if (buffer instanceof ShortBuffer) {
|
||||||
|
dest = new ShortBufferWrapper((ShortBuffer) buffer,
|
||||||
|
slice.width, slice.height);
|
||||||
|
} else if (buffer instanceof IntBuffer) {
|
||||||
|
dest = new IntBufferWrapper((IntBuffer) buffer, slice.width,
|
||||||
|
slice.height);
|
||||||
|
} else if (buffer instanceof FloatBuffer) {
|
||||||
|
dest = new FloatBufferWrapper((FloatBuffer) buffer,
|
||||||
|
slice.width, slice.height);
|
||||||
|
} else {
|
||||||
|
throw new VizException("Unsupported data type: "
|
||||||
|
+ dataType.toString());
|
||||||
|
}
|
||||||
|
DataSource sliceSource = source;
|
||||||
|
if (slice.x != 0 || slice.y != 0) {
|
||||||
|
sliceSource = new OffsetDataSource(source, slice.x, slice.y);
|
||||||
|
}
|
||||||
|
DataUtilities.copy(sliceSource, dest, slice.width, slice.height);
|
||||||
|
/* Add units */
|
||||||
|
return new ColorMapData(buffer, new int[] { slice.width,
|
||||||
|
slice.height }, dataType, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private final DataSource source;
|
||||||
|
|
||||||
|
private final Unit<?> unit;
|
||||||
|
|
||||||
|
private final ColorMapCapability cmapCapability;
|
||||||
|
|
||||||
|
private final ColorMapDataType dataType;
|
||||||
|
|
||||||
|
public DataSourceTileImageCreator(DataSource source, Unit<?> unit,
|
||||||
|
ColorMapDataType dataType, ColorMapCapability cmapCapability) {
|
||||||
|
this.source = source;
|
||||||
|
this.unit = unit;
|
||||||
|
this.dataType = dataType;
|
||||||
|
this.cmapCapability = cmapCapability;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DrawableImage createTileImage(IGraphicsTarget target, Tile tile,
|
||||||
|
GeneralGridGeometry targetGeometry) throws VizException {
|
||||||
|
if (tile.tileLevel != 0) {
|
||||||
|
throw new VizException(getClass().getSimpleName()
|
||||||
|
+ " only supports single level tiled data");
|
||||||
|
}
|
||||||
|
|
||||||
|
IImage image = target.getExtension(IColormappedImageExtension.class)
|
||||||
|
.initializeRaster(
|
||||||
|
new DataSourceColorMapRetrievalCallback(
|
||||||
|
tile.getRectangle()),
|
||||||
|
cmapCapability.getColorMapParameters());
|
||||||
|
IMesh mesh = target.getExtension(IMapMeshExtension.class)
|
||||||
|
.constructMesh(tile.tileGeometry, targetGeometry);
|
||||||
|
return new DrawableImage(image, new PixelCoverage(mesh),
|
||||||
|
RasterMode.ASYNCHRONOUS);
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,7 +32,7 @@ import org.opengis.coverage.grid.GridEnvelope;
|
||||||
import org.opengis.referencing.operation.MathTransform;
|
import org.opengis.referencing.operation.MathTransform;
|
||||||
|
|
||||||
import com.raytheon.uf.common.geospatial.MapUtil;
|
import com.raytheon.uf.common.geospatial.MapUtil;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.data.DataCopy;
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataUtilities;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.data.FloatArrayWrapper;
|
import com.raytheon.uf.common.geospatial.interpolation.data.FloatArrayWrapper;
|
||||||
import com.raytheon.uf.common.style.contour.ContourPreferences;
|
import com.raytheon.uf.common.style.contour.ContourPreferences;
|
||||||
|
@ -454,7 +454,7 @@ public abstract class ContourRenderable implements IRenderable {
|
||||||
* contourPrefs.getSmoothingDistance() / (distanceInM / 1000));
|
* contourPrefs.getSmoothingDistance() / (distanceInM / 1000));
|
||||||
FloatArrayWrapper data = new FloatArrayWrapper(gridGeometry);
|
FloatArrayWrapper data = new FloatArrayWrapper(gridGeometry);
|
||||||
data.setFillValue(Constants.LEGACY_NAN);
|
data.setFillValue(Constants.LEGACY_NAN);
|
||||||
DataCopy.copy(dataRecord[0], data, nx, ny);
|
DataUtilities.copy(dataRecord[0], data, nx, ny);
|
||||||
float[] dataArray = data.getArray();
|
float[] dataArray = data.getArray();
|
||||||
dataArray = DistFilter.filter(dataArray, npts, nx, ny, 1);
|
dataArray = DistFilter.filter(dataArray, npts, nx, ny, 1);
|
||||||
data = new FloatArrayWrapper(dataArray, gridGeometry);
|
data = new FloatArrayWrapper(dataArray, gridGeometry);
|
||||||
|
|
|
@ -44,8 +44,9 @@ import org.opengis.referencing.operation.TransformException;
|
||||||
|
|
||||||
import com.raytheon.uf.common.geospatial.CRSCache;
|
import com.raytheon.uf.common.geospatial.CRSCache;
|
||||||
import com.raytheon.uf.common.geospatial.MapUtil;
|
import com.raytheon.uf.common.geospatial.MapUtil;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.data.DataCopy;
|
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataUtilities;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataUtilities.MinMax;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.data.FloatArrayWrapper;
|
import com.raytheon.uf.common.geospatial.interpolation.data.FloatArrayWrapper;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.data.OffsetDataSource;
|
import com.raytheon.uf.common.geospatial.interpolation.data.OffsetDataSource;
|
||||||
import com.raytheon.uf.common.geospatial.util.GridGeometryWrapChecker;
|
import com.raytheon.uf.common.geospatial.util.GridGeometryWrapChecker;
|
||||||
|
@ -340,7 +341,7 @@ public class ContourSupport {
|
||||||
/* Make contours continous for world wrapping grids. */
|
/* Make contours continous for world wrapping grids. */
|
||||||
int wrapNumber = GridGeometryWrapChecker
|
int wrapNumber = GridGeometryWrapChecker
|
||||||
.checkForWrapping(imageGridGeometry);
|
.checkForWrapping(imageGridGeometry);
|
||||||
if (wrapNumber - 1 >= szX) {
|
if (wrapNumber >= szX - 1) {
|
||||||
szX = wrapNumber + 1;
|
szX = wrapNumber + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,7 +351,7 @@ public class ContourSupport {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copyData) {
|
if (copyData) {
|
||||||
subgridSource = DataCopy.copy(subgridSource,
|
subgridSource = DataUtilities.copy(subgridSource,
|
||||||
new FloatArrayWrapper(szX, szY), szX, szY);
|
new FloatArrayWrapper(szX, szY), szX, szY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,19 +382,9 @@ public class ContourSupport {
|
||||||
// If nothing provided, attempt to get approximately 50 contours
|
// If nothing provided, attempt to get approximately 50 contours
|
||||||
if (prefs == null || prefs.getContourLabeling() == null) {
|
if (prefs == null || prefs.getContourLabeling() == null) {
|
||||||
// TODO this is fairly inefficient to do every time.
|
// TODO this is fairly inefficient to do every time.
|
||||||
float min = Float.POSITIVE_INFINITY;
|
MinMax mm = DataUtilities.getMinMax(subgridSource, szX, szY);
|
||||||
float max = Float.NEGATIVE_INFINITY;
|
|
||||||
for (int j = 0; j < szY; j++) {
|
|
||||||
for (int i = 0; i < szX; i++) {
|
|
||||||
float f = (float) subgridSource.getDataValue(i, j);
|
|
||||||
if (!Float.isNaN(f)) {
|
|
||||||
min = Math.min(min, f);
|
|
||||||
max = Math.max(max, f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
float interval = XFormFunctions
|
float interval = XFormFunctions
|
||||||
.newDataIntervalFromZoom((max - min) / 50,
|
.newDataIntervalFromZoom((float) mm.getSpan() / 50,
|
||||||
(float) (contourGroup.lastDensity * zoom),
|
(float) (contourGroup.lastDensity * zoom),
|
||||||
true, "", 10);
|
true, "", 10);
|
||||||
config.seed = new float[] { interval };
|
config.seed = new float[] { interval };
|
||||||
|
@ -440,18 +431,9 @@ public class ContourSupport {
|
||||||
.getIncrement();
|
.getIncrement();
|
||||||
float interval;
|
float interval;
|
||||||
if (contourLabeling.getNumberOfContours() > 0) {
|
if (contourLabeling.getNumberOfContours() > 0) {
|
||||||
float minData = Float.POSITIVE_INFINITY;
|
MinMax mm = DataUtilities.getMinMax(subgridSource, szX,
|
||||||
float maxData = Float.NEGATIVE_INFINITY;
|
szY);
|
||||||
for (int j = 0; j < szY; j++) {
|
interval = (float) mm.getSpan()
|
||||||
for (int i = 0; i < szX; i++) {
|
|
||||||
float f = (float) subgridSource.getDataValue(i, j);
|
|
||||||
if (!Float.isNaN(f)) {
|
|
||||||
minData = Math.min(minData, f);
|
|
||||||
maxData = Math.max(maxData, f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
interval = (maxData - minData)
|
|
||||||
/ contourLabeling.getNumberOfContours();
|
/ contourLabeling.getNumberOfContours();
|
||||||
if (interval < 0) {
|
if (interval < 0) {
|
||||||
interval = -interval;
|
interval = -interval;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
**/
|
**/
|
||||||
package com.raytheon.viz.grid.rsc;
|
package com.raytheon.viz.grid.rsc;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.RenderedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -29,7 +29,8 @@ import java.util.Map;
|
||||||
import org.eclipse.swt.graphics.RGB;
|
import org.eclipse.swt.graphics.RGB;
|
||||||
import org.geotools.coverage.grid.GeneralGridGeometry;
|
import org.geotools.coverage.grid.GeneralGridGeometry;
|
||||||
|
|
||||||
import com.raytheon.uf.viz.core.data.prep.IODataPreparer;
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
|
||||||
|
import com.raytheon.uf.viz.core.data.IRenderedImageCallback;
|
||||||
import com.raytheon.uf.viz.core.drawables.IImage;
|
import com.raytheon.uf.viz.core.drawables.IImage;
|
||||||
import com.raytheon.uf.viz.core.drawables.PaintProperties;
|
import com.raytheon.uf.viz.core.drawables.PaintProperties;
|
||||||
import com.raytheon.uf.viz.core.exception.VizException;
|
import com.raytheon.uf.viz.core.exception.VizException;
|
||||||
|
@ -53,6 +54,9 @@ import com.vividsolutions.jts.geom.Coordinate;
|
||||||
* Aug 27, 2013 2287 randerso Added densityFactor to allow application
|
* Aug 27, 2013 2287 randerso Added densityFactor to allow application
|
||||||
* specific adjustment of density.
|
* specific adjustment of density.
|
||||||
* Sep 23, 2013 2363 bsteffen Add more vector configuration options.
|
* Sep 23, 2013 2363 bsteffen Add more vector configuration options.
|
||||||
|
* Feb 28, 2013 2791 bsteffen Use DataSource for data, custom callback
|
||||||
|
* for image.
|
||||||
|
*
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -62,7 +66,7 @@ import com.vividsolutions.jts.geom.Coordinate;
|
||||||
|
|
||||||
public class GriddedIconDisplay extends AbstractGriddedDisplay<IImage> {
|
public class GriddedIconDisplay extends AbstractGriddedDisplay<IImage> {
|
||||||
|
|
||||||
private float[] values;
|
private DataSource values;
|
||||||
|
|
||||||
private Map<Integer, IImage> images = new HashMap<Integer, IImage>();
|
private Map<Integer, IImage> images = new HashMap<Integer, IImage>();
|
||||||
|
|
||||||
|
@ -78,7 +82,7 @@ public class GriddedIconDisplay extends AbstractGriddedDisplay<IImage> {
|
||||||
* @param densityFactor
|
* @param densityFactor
|
||||||
* adjustment factor to make density match A1
|
* adjustment factor to make density match A1
|
||||||
*/
|
*/
|
||||||
public GriddedIconDisplay(float[] values, IMapDescriptor descriptor,
|
public GriddedIconDisplay(DataSource values, IMapDescriptor descriptor,
|
||||||
GeneralGridGeometry gridGeometryOfGrid, int imageSize,
|
GeneralGridGeometry gridGeometryOfGrid, int imageSize,
|
||||||
double densityFactor) {
|
double densityFactor) {
|
||||||
super(descriptor, gridGeometryOfGrid, imageSize, densityFactor);
|
super(descriptor, gridGeometryOfGrid, imageSize, densityFactor);
|
||||||
|
@ -115,9 +119,8 @@ public class GriddedIconDisplay extends AbstractGriddedDisplay<IImage> {
|
||||||
int i = getValue(coord);
|
int i = getValue(coord);
|
||||||
IImage image = images.get(i);
|
IImage image = images.get(i);
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
BufferedImage bImage = iconFactory.getIcon(i);
|
image = target.initializeRaster(new PointIconImageCallback(
|
||||||
image = target.initializeRaster(new IODataPreparer(bImage, "icon"
|
iconFactory, i));
|
||||||
+ bImage, 0), null);
|
|
||||||
images.put(i, image);
|
images.put(i, image);
|
||||||
// keep around the image that is entirely empty/transparent so we
|
// keep around the image that is entirely empty/transparent so we
|
||||||
// can match it up and don't waste time drawing it later
|
// can match it up and don't waste time drawing it later
|
||||||
|
@ -129,8 +132,7 @@ public class GriddedIconDisplay extends AbstractGriddedDisplay<IImage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getValue(Coordinate coord) {
|
private int getValue(Coordinate coord) {
|
||||||
int idx = (int) (coord.x + (coord.y * gridDims[0]));
|
return (int) values.getDataValue((int) coord.x, (int) coord.y);
|
||||||
return (int) values[idx];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -183,4 +185,22 @@ public class GriddedIconDisplay extends AbstractGriddedDisplay<IImage> {
|
||||||
paintProps, images);
|
paintProps, images);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static class PointIconImageCallback implements
|
||||||
|
IRenderedImageCallback {
|
||||||
|
private final PointIconFactory iconFactory;
|
||||||
|
|
||||||
|
private final int iconIndex;
|
||||||
|
|
||||||
|
private PointIconImageCallback(PointIconFactory iconFactory,
|
||||||
|
int iconIndex) {
|
||||||
|
this.iconFactory = iconFactory;
|
||||||
|
this.iconIndex = iconIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderedImage getImage() throws VizException {
|
||||||
|
return iconFactory.getIcon(iconIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
**/
|
**/
|
||||||
package com.raytheon.viz.grid.rsc;
|
package com.raytheon.viz.grid.rsc;
|
||||||
|
|
||||||
import java.nio.FloatBuffer;
|
|
||||||
import java.text.ParsePosition;
|
import java.text.ParsePosition;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -28,6 +27,7 @@ import javax.measure.unit.UnitFormat;
|
||||||
|
|
||||||
import com.raytheon.uf.common.dataplugin.grid.GridRecord;
|
import com.raytheon.uf.common.dataplugin.grid.GridRecord;
|
||||||
import com.raytheon.uf.common.geospatial.ReferencedCoordinate;
|
import com.raytheon.uf.common.geospatial.ReferencedCoordinate;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
|
||||||
import com.raytheon.uf.viz.core.exception.VizException;
|
import com.raytheon.uf.viz.core.exception.VizException;
|
||||||
import com.raytheon.uf.viz.core.rsc.LoadProperties;
|
import com.raytheon.uf.viz.core.rsc.LoadProperties;
|
||||||
import com.raytheon.viz.grid.rsc.general.D2DGridResource;
|
import com.raytheon.viz.grid.rsc.general.D2DGridResource;
|
||||||
|
@ -43,6 +43,7 @@ import com.raytheon.viz.grid.rsc.general.GeneralGridData;
|
||||||
* ------------- -------- ----------- --------------------------
|
* ------------- -------- ----------- --------------------------
|
||||||
* Dec 16, 2009 mnash Initial creation
|
* Dec 16, 2009 mnash Initial creation
|
||||||
* Feb 07, 2014 2211 bsteffen Fix sampling
|
* Feb 07, 2014 2211 bsteffen Fix sampling
|
||||||
|
* Feb 28, 2791 2211 bsteffen Move data conversion to DataSource
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -98,32 +99,41 @@ public class RcmResource extends D2DGridResource {
|
||||||
protected GeneralGridData getData(GridRecord gridRecord)
|
protected GeneralGridData getData(GridRecord gridRecord)
|
||||||
throws VizException {
|
throws VizException {
|
||||||
GeneralGridData data = super.getData(gridRecord);
|
GeneralGridData data = super.getData(gridRecord);
|
||||||
FloatBuffer floatData = data.getScalarData();
|
DataSource source = new RcmDataSource(data.getScalarData());
|
||||||
FloatBuffer newFloatData = FloatBuffer.allocate(floatData.capacity());
|
return GeneralGridData.createScalarData(data.getGridGeometry(), source,
|
||||||
floatData.rewind();
|
data.getDataUnit());
|
||||||
newFloatData.rewind();
|
}
|
||||||
while (floatData.hasRemaining()) {
|
|
||||||
float value = floatData.get();
|
private final class RcmDataSource implements DataSource {
|
||||||
if (value < 1f) {
|
|
||||||
newFloatData.put(1f);
|
private final DataSource wrappedSource;
|
||||||
|
|
||||||
|
public RcmDataSource(DataSource wrappedSource) {
|
||||||
|
this.wrappedSource = wrappedSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getDataValue(int x, int y) {
|
||||||
|
double value = wrappedSource.getDataValue(x, y);
|
||||||
|
if (value < 1) {
|
||||||
|
return 1;
|
||||||
} else if (value < 2) {
|
} else if (value < 2) {
|
||||||
newFloatData.put(48f);
|
return 48;
|
||||||
} else if (value < 3) {
|
} else if (value < 3) {
|
||||||
newFloatData.put(96f);
|
return 96;
|
||||||
} else if (value < 4) {
|
} else if (value < 4) {
|
||||||
newFloatData.put(128f);
|
return 128;
|
||||||
} else if (value < 5) {
|
} else if (value < 5) {
|
||||||
newFloatData.put(144f);
|
return 144;
|
||||||
} else if (value < 6) {
|
} else if (value < 6) {
|
||||||
newFloatData.put(160f);
|
return 160;
|
||||||
} else if (value < 7) {
|
} else if (value < 7) {
|
||||||
newFloatData.put(176f);
|
return 176;
|
||||||
} else {
|
} else {
|
||||||
newFloatData.put(0f);
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return GeneralGridData.createScalarData(data.getGridGeometry(),
|
|
||||||
newFloatData, data.getDataUnit());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,11 +31,13 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import javax.measure.unit.Unit;
|
import javax.measure.unit.Unit;
|
||||||
import javax.measure.unit.UnitFormat;
|
import javax.measure.unit.UnitFormat;
|
||||||
|
|
||||||
|
import org.geotools.coverage.grid.GridEnvelope2D;
|
||||||
import org.geotools.coverage.grid.GridGeometry2D;
|
import org.geotools.coverage.grid.GridGeometry2D;
|
||||||
import org.opengis.referencing.FactoryException;
|
import org.opengis.referencing.FactoryException;
|
||||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||||
import org.opengis.referencing.operation.TransformException;
|
import org.opengis.referencing.operation.TransformException;
|
||||||
|
|
||||||
|
import com.raytheon.uf.common.colormap.image.ColorMapData.ColorMapDataType;
|
||||||
import com.raytheon.uf.common.colormap.prefs.ColorMapParameters;
|
import com.raytheon.uf.common.colormap.prefs.ColorMapParameters;
|
||||||
import com.raytheon.uf.common.colormap.prefs.ColorMapParameters.PersistedParameters;
|
import com.raytheon.uf.common.colormap.prefs.ColorMapParameters.PersistedParameters;
|
||||||
import com.raytheon.uf.common.dataplugin.PluginDataObject;
|
import com.raytheon.uf.common.dataplugin.PluginDataObject;
|
||||||
|
@ -44,7 +46,9 @@ import com.raytheon.uf.common.geospatial.interpolation.BilinearInterpolation;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.GridSampler;
|
import com.raytheon.uf.common.geospatial.interpolation.GridSampler;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.Interpolation;
|
import com.raytheon.uf.common.geospatial.interpolation.Interpolation;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.NearestNeighborInterpolation;
|
import com.raytheon.uf.common.geospatial.interpolation.NearestNeighborInterpolation;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.data.FloatBufferWrapper;
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataUtilities;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataUtilities.MinMax;
|
||||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||||
import com.raytheon.uf.common.status.UFStatus;
|
import com.raytheon.uf.common.status.UFStatus;
|
||||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||||
|
@ -84,13 +88,15 @@ import com.raytheon.uf.viz.core.rsc.capabilities.DisplayTypeCapability;
|
||||||
import com.raytheon.uf.viz.core.rsc.capabilities.ImagingCapability;
|
import com.raytheon.uf.viz.core.rsc.capabilities.ImagingCapability;
|
||||||
import com.raytheon.uf.viz.core.rsc.capabilities.MagnificationCapability;
|
import com.raytheon.uf.viz.core.rsc.capabilities.MagnificationCapability;
|
||||||
import com.raytheon.uf.viz.core.rsc.capabilities.OutlineCapability;
|
import com.raytheon.uf.viz.core.rsc.capabilities.OutlineCapability;
|
||||||
|
import com.raytheon.uf.viz.core.tile.DataSourceTileImageCreator;
|
||||||
|
import com.raytheon.uf.viz.core.tile.TileSetRenderable;
|
||||||
|
import com.raytheon.uf.viz.core.tile.TileSetRenderable.TileImageCreator;
|
||||||
import com.raytheon.viz.core.contours.ContourRenderable;
|
import com.raytheon.viz.core.contours.ContourRenderable;
|
||||||
import com.raytheon.viz.core.contours.rsc.displays.AbstractGriddedDisplay;
|
import com.raytheon.viz.core.contours.rsc.displays.AbstractGriddedDisplay;
|
||||||
import com.raytheon.viz.core.contours.rsc.displays.GriddedContourDisplay;
|
import com.raytheon.viz.core.contours.rsc.displays.GriddedContourDisplay;
|
||||||
import com.raytheon.viz.core.contours.rsc.displays.GriddedStreamlineDisplay;
|
import com.raytheon.viz.core.contours.rsc.displays.GriddedStreamlineDisplay;
|
||||||
import com.raytheon.viz.core.contours.rsc.displays.GriddedVectorDisplay;
|
import com.raytheon.viz.core.contours.rsc.displays.GriddedVectorDisplay;
|
||||||
import com.raytheon.viz.core.contours.util.VectorGraphicsConfig;
|
import com.raytheon.viz.core.contours.util.VectorGraphicsConfig;
|
||||||
import com.raytheon.viz.core.rsc.displays.GriddedImageDisplay2;
|
|
||||||
import com.raytheon.viz.grid.rsc.GriddedIconDisplay;
|
import com.raytheon.viz.grid.rsc.GriddedIconDisplay;
|
||||||
import com.vividsolutions.jts.geom.Coordinate;
|
import com.vividsolutions.jts.geom.Coordinate;
|
||||||
|
|
||||||
|
@ -118,6 +124,7 @@ import com.vividsolutions.jts.geom.Coordinate;
|
||||||
* Sep 23, 2013 2363 bsteffen Add more vector configuration options.
|
* Sep 23, 2013 2363 bsteffen Add more vector configuration options.
|
||||||
* Jan 14, 2014 2594 bsteffen Switch vector mag/dir to use data source
|
* Jan 14, 2014 2594 bsteffen Switch vector mag/dir to use data source
|
||||||
* instead of raw float data.
|
* instead of raw float data.
|
||||||
|
* Feb 28, 2014 2791 bsteffen Switch all data to use data source.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
|
@ -137,6 +144,8 @@ public abstract class AbstractGridResource<T extends AbstractResourceData>
|
||||||
/* Unknown source, provides acceptable density. */
|
/* Unknown source, provides acceptable density. */
|
||||||
private static final double VECTOR_DENSITY_FACTOR = 1.875;
|
private static final double VECTOR_DENSITY_FACTOR = 1.875;
|
||||||
|
|
||||||
|
private static final int IMAGE_TILE_SIZE = 1024;
|
||||||
|
|
||||||
public static final String INTERROGATE_VALUE = "value";
|
public static final String INTERROGATE_VALUE = "value";
|
||||||
|
|
||||||
public static final String INTERROGATE_UNIT = "unit";
|
public static final String INTERROGATE_UNIT = "unit";
|
||||||
|
@ -485,6 +494,8 @@ public abstract class AbstractGridResource<T extends AbstractResourceData>
|
||||||
|
|
||||||
switch (displayType) {
|
switch (displayType) {
|
||||||
case IMAGE:
|
case IMAGE:
|
||||||
|
ColorMapCapability colorMapCap = getCapability(ColorMapCapability.class);
|
||||||
|
ImagingCapability imagingCap = getCapability(ImagingCapability.class);
|
||||||
if (renderableMap.isEmpty()) {
|
if (renderableMap.isEmpty()) {
|
||||||
ColorMapParameters params = createColorMapParameters(data);
|
ColorMapParameters params = createColorMapParameters(data);
|
||||||
if (params.getColorMap() == null) {
|
if (params.getColorMap() == null) {
|
||||||
|
@ -494,15 +505,15 @@ public abstract class AbstractGridResource<T extends AbstractResourceData>
|
||||||
params.setColorMap(ColorMapLoader.loadColorMap(params
|
params.setColorMap(ColorMapLoader.loadColorMap(params
|
||||||
.getColorMapName()));
|
.getColorMapName()));
|
||||||
}
|
}
|
||||||
this.getCapability(ColorMapCapability.class)
|
colorMapCap.setColorMapParameters(params);
|
||||||
.setColorMapParameters(params);
|
|
||||||
}
|
}
|
||||||
ColorMapParameters params = getCapability(ColorMapCapability.class)
|
TileImageCreator creator = new DataSourceTileImageCreator(
|
||||||
.getColorMapParameters();
|
data.getScalarData(), data.getDataUnit(),
|
||||||
data.convert(params.getImageUnit());
|
ColorMapDataType.FLOAT, colorMapCap);
|
||||||
GriddedImageDisplay2 imageRenderable = new GriddedImageDisplay2(
|
TileSetRenderable tsr = new TileSetRenderable(imagingCap,
|
||||||
data.getScalarData(), gridGeometry, this);
|
gridGeometry, creator, 1, IMAGE_TILE_SIZE);
|
||||||
renderable = imageRenderable;
|
tsr.project(descriptor.getGridGeometry());
|
||||||
|
renderable = tsr;
|
||||||
break;
|
break;
|
||||||
case BARB:
|
case BARB:
|
||||||
case ARROW:
|
case ARROW:
|
||||||
|
@ -545,9 +556,8 @@ public abstract class AbstractGridResource<T extends AbstractResourceData>
|
||||||
renderable = vectorDisplay;
|
renderable = vectorDisplay;
|
||||||
break;
|
break;
|
||||||
case ICON:
|
case ICON:
|
||||||
GriddedIconDisplay iconDisplay = new GriddedIconDisplay(data
|
GriddedIconDisplay iconDisplay = new GriddedIconDisplay(
|
||||||
.getScalarData().array(), descriptor, gridGeometry, 80,
|
data.getScalarData(), descriptor, gridGeometry, 80, 0.75);
|
||||||
0.75);
|
|
||||||
iconDisplay.setColor(getCapability(ColorableCapability.class)
|
iconDisplay.setColor(getCapability(ColorableCapability.class)
|
||||||
.getColor());
|
.getColor());
|
||||||
iconDisplay.setDensity(getCapability(DensityCapability.class)
|
iconDisplay.setDensity(getCapability(DensityCapability.class)
|
||||||
|
@ -608,17 +618,23 @@ public abstract class AbstractGridResource<T extends AbstractResourceData>
|
||||||
throws VizException {
|
throws VizException {
|
||||||
ParamLevelMatchCriteria criteria = getMatchCriteria();
|
ParamLevelMatchCriteria criteria = getMatchCriteria();
|
||||||
ColorMapParameters newParameters;
|
ColorMapParameters newParameters;
|
||||||
|
GridEnvelope2D range = data.getGridGeometry().getGridRange2D();
|
||||||
|
DataSource source = data.getScalarData();
|
||||||
|
MinMax mm = DataUtilities.getMinMax(source, range.getSpan(0),
|
||||||
|
range.getSpan(1));
|
||||||
try {
|
try {
|
||||||
newParameters = ColorMapParameterFactory.build(data.getScalarData()
|
newParameters = ColorMapParameterFactory.build((float) mm.getMin(),
|
||||||
.array(), data.getDataUnit(), criteria);
|
(float) mm.getMax(), data.getDataUnit(), criteria);
|
||||||
} catch (StyleException e) {
|
} catch (StyleException e) {
|
||||||
throw new VizException("Unable to build colormap parameters", e);
|
throw new VizException("Unable to build colormap parameters", e);
|
||||||
}
|
}
|
||||||
ColorMapParameters oldParameters = this.getCapability(
|
ColorMapParameters oldParameters = this.getCapability(
|
||||||
ColorMapCapability.class).getColorMapParameters();
|
ColorMapCapability.class).getColorMapParameters();
|
||||||
if (oldParameters != null
|
if (oldParameters != null
|
||||||
&& oldParameters.getDataMin() <= newParameters.getDataMin()
|
&& oldParameters.getColorMapMin() <= newParameters
|
||||||
&& oldParameters.getDataMax() >= newParameters.getDataMax()) {
|
.getColorMapMin()
|
||||||
|
&& oldParameters.getColorMapMax() >= newParameters
|
||||||
|
.getColorMapMax()) {
|
||||||
// if the oldParameters have a larger range than the new parameters,
|
// if the oldParameters have a larger range than the new parameters,
|
||||||
// reuse the old parameters. This is useful when the resource is
|
// reuse the old parameters. This is useful when the resource is
|
||||||
// sharing capabilities, for example in an FFGVizGroupResource.
|
// sharing capabilities, for example in an FFGVizGroupResource.
|
||||||
|
@ -684,6 +700,7 @@ public abstract class AbstractGridResource<T extends AbstractResourceData>
|
||||||
GeneralGridData merged = GeneralGridData
|
GeneralGridData merged = GeneralGridData
|
||||||
.mergeData(data1, data2);
|
.mergeData(data1, data2);
|
||||||
if (merged != null) {
|
if (merged != null) {
|
||||||
|
data1 = merged;
|
||||||
dataList.set(i, merged);
|
dataList.set(i, merged);
|
||||||
dataList.remove(j);
|
dataList.remove(j);
|
||||||
j -= 1;
|
j -= 1;
|
||||||
|
@ -709,8 +726,8 @@ public abstract class AbstractGridResource<T extends AbstractResourceData>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (renderable instanceof GriddedImageDisplay2) {
|
if (renderable instanceof TileSetRenderable) {
|
||||||
((GriddedImageDisplay2) renderable).dispose();
|
((TileSetRenderable) renderable).dispose();
|
||||||
} else if (renderable instanceof AbstractGriddedDisplay<?>) {
|
} else if (renderable instanceof AbstractGriddedDisplay<?>) {
|
||||||
((AbstractGriddedDisplay<?>) renderable).dispose();
|
((AbstractGriddedDisplay<?>) renderable).dispose();
|
||||||
} else if (renderable instanceof ContourRenderable) {
|
} else if (renderable instanceof ContourRenderable) {
|
||||||
|
@ -734,7 +751,7 @@ public abstract class AbstractGridResource<T extends AbstractResourceData>
|
||||||
List<IRenderable> renderableList = iter.next();
|
List<IRenderable> renderableList = iter.next();
|
||||||
boolean remove = false;
|
boolean remove = false;
|
||||||
for (IRenderable renderable : renderableList) {
|
for (IRenderable renderable : renderableList) {
|
||||||
if (!projectRenderable(renderable, crs)) {
|
if (!projectRenderable(renderable)) {
|
||||||
remove = true;
|
remove = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -757,14 +774,13 @@ public abstract class AbstractGridResource<T extends AbstractResourceData>
|
||||||
* the new projection.
|
* the new projection.
|
||||||
*
|
*
|
||||||
* @param renderable
|
* @param renderable
|
||||||
* @param crs
|
|
||||||
* @return
|
* @return
|
||||||
* @throws VizException
|
* @throws VizException
|
||||||
*/
|
*/
|
||||||
protected boolean projectRenderable(IRenderable renderable,
|
protected boolean projectRenderable(IRenderable renderable)
|
||||||
CoordinateReferenceSystem crs) throws VizException {
|
throws VizException {
|
||||||
if (renderable instanceof GriddedImageDisplay2) {
|
if (renderable instanceof TileSetRenderable) {
|
||||||
((GriddedImageDisplay2) renderable).project(descriptor
|
((TileSetRenderable) renderable).project(descriptor
|
||||||
.getGridGeometry());
|
.getGridGeometry());
|
||||||
return true;
|
return true;
|
||||||
} else if (renderable instanceof AbstractGriddedDisplay<?>) {
|
} else if (renderable instanceof AbstractGriddedDisplay<?>) {
|
||||||
|
@ -786,7 +802,7 @@ public abstract class AbstractGridResource<T extends AbstractResourceData>
|
||||||
return requestData(time);
|
return requestData(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Interpolation getInspectInterpolation(GeneralGridData data) {
|
protected Interpolation getInspectInterpolation() {
|
||||||
Interpolation sampleInterpolion = null;
|
Interpolation sampleInterpolion = null;
|
||||||
if (this.hasCapability(ImagingCapability.class)) {
|
if (this.hasCapability(ImagingCapability.class)) {
|
||||||
ImagingCapability imagingCap = this
|
ImagingCapability imagingCap = this
|
||||||
|
@ -847,13 +863,12 @@ public abstract class AbstractGridResource<T extends AbstractResourceData>
|
||||||
throw new VizException(
|
throw new VizException(
|
||||||
"Error transforming coordinate for interrogate", e);
|
"Error transforming coordinate for interrogate", e);
|
||||||
}
|
}
|
||||||
Interpolation interpolation = getInspectInterpolation(data);
|
Interpolation interpolation = getInspectInterpolation();
|
||||||
GridSampler sampler = null;
|
GridSampler sampler = null;
|
||||||
if (data.isVector()) {
|
if (data.isVector()) {
|
||||||
sampler = new GridSampler(data.getMagnitude(), interpolation);
|
sampler = new GridSampler(data.getMagnitude(), interpolation);
|
||||||
} else {
|
} else {
|
||||||
sampler = new GridSampler(new FloatBufferWrapper(
|
sampler = new GridSampler(data.getScalarData(), interpolation);
|
||||||
data.getScalarData(), data.getGridGeometry()), interpolation);
|
|
||||||
}
|
}
|
||||||
double value = sampler.sample(pixel.x, pixel.y);
|
double value = sampler.sample(pixel.x, pixel.y);
|
||||||
if (Double.isNaN(value)) {
|
if (Double.isNaN(value)) {
|
||||||
|
|
|
@ -45,6 +45,8 @@ import com.raytheon.uf.common.geospatial.ReferencedCoordinate;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.BilinearInterpolation;
|
import com.raytheon.uf.common.geospatial.interpolation.BilinearInterpolation;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.Interpolation;
|
import com.raytheon.uf.common.geospatial.interpolation.Interpolation;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.NearestNeighborInterpolation;
|
import com.raytheon.uf.common.geospatial.interpolation.NearestNeighborInterpolation;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.FloatBufferWrapper;
|
||||||
import com.raytheon.uf.common.geospatial.util.GridGeometryWrapChecker;
|
import com.raytheon.uf.common.geospatial.util.GridGeometryWrapChecker;
|
||||||
import com.raytheon.uf.common.geospatial.util.SubGridGeometryCalculator;
|
import com.raytheon.uf.common.geospatial.util.SubGridGeometryCalculator;
|
||||||
import com.raytheon.uf.common.gridcoverage.GridCoverage;
|
import com.raytheon.uf.common.gridcoverage.GridCoverage;
|
||||||
|
@ -93,6 +95,8 @@ import com.vividsolutions.jts.geom.Coordinate;
|
||||||
* world.
|
* world.
|
||||||
* Feb 04, 2014 2672 bsteffen Extract subgridding logic to geospatial
|
* Feb 04, 2014 2672 bsteffen Extract subgridding logic to geospatial
|
||||||
* plugin.
|
* plugin.
|
||||||
|
* Feb 28, 2013 2791 bsteffen Use DataSource instead of FloatBuffers
|
||||||
|
* for data access
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -227,22 +231,24 @@ public class D2DGridResource extends GridResource<GridResourceData> implements
|
||||||
MathTransform crs2ll = MapUtil
|
MathTransform crs2ll = MapUtil
|
||||||
.getTransformToLatLon(gridGeometry
|
.getTransformToLatLon(gridGeometry
|
||||||
.getCoordinateReferenceSystem());
|
.getCoordinateReferenceSystem());
|
||||||
|
DataSource oldScalar = data.getScalarData();
|
||||||
|
FloatBufferWrapper newScalar = new FloatBufferWrapper(
|
||||||
|
gridGeometry);
|
||||||
for (int i = 0; i < gridRange.width; i++) {
|
for (int i = 0; i < gridRange.width; i++) {
|
||||||
for (int j = 0; j < gridRange.height; j++) {
|
for (int j = 0; j < gridRange.height; j++) {
|
||||||
int index = i + (j * gridRange.width);
|
double dir = oldScalar.getDataValue(i, j);
|
||||||
float dir = data.getScalarData().get(index);
|
DirectPosition2D dp = new DirectPosition2D(i, j);
|
||||||
if (dir > -9999) {
|
grid2crs.transform(dp, dp);
|
||||||
DirectPosition2D dp = new DirectPosition2D(i, j);
|
crs2ll.transform(dp, dp);
|
||||||
grid2crs.transform(dp, dp);
|
Coordinate ll = new Coordinate(dp.x, dp.y);
|
||||||
crs2ll.transform(dp, dp);
|
float rot = (float) MapUtil.rotation(ll,
|
||||||
Coordinate ll = new Coordinate(dp.x, dp.y);
|
gridGeometry);
|
||||||
float rot = (float) MapUtil.rotation(ll,
|
dir = (dir + rot) % 360;
|
||||||
gridGeometry);
|
newScalar.setDataValue(dir, i, j);
|
||||||
dir = (dir + rot) % 360;
|
|
||||||
data.getScalarData().put(index, dir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
data = GeneralGridData.createScalarData(gridGeometry,
|
||||||
|
newScalar, data.getDataUnit());
|
||||||
} catch (TransformException e) {
|
} catch (TransformException e) {
|
||||||
throw new VizException(e);
|
throw new VizException(e);
|
||||||
} catch (InvalidGridGeometryException e) {
|
} catch (InvalidGridGeometryException e) {
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
**/
|
**/
|
||||||
package com.raytheon.viz.grid.rsc.general;
|
package com.raytheon.viz.grid.rsc.general;
|
||||||
|
|
||||||
import java.nio.FloatBuffer;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -32,12 +31,12 @@ import org.geotools.coverage.grid.GridGeometry2D;
|
||||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||||
import org.opengis.coverage.grid.GridEnvelope;
|
import org.opengis.coverage.grid.GridEnvelope;
|
||||||
import org.opengis.referencing.FactoryException;
|
import org.opengis.referencing.FactoryException;
|
||||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
|
||||||
import org.opengis.referencing.operation.TransformException;
|
import org.opengis.referencing.operation.TransformException;
|
||||||
|
|
||||||
import com.raytheon.uf.common.dataplugin.PluginDataObject;
|
import com.raytheon.uf.common.dataplugin.PluginDataObject;
|
||||||
import com.raytheon.uf.common.geospatial.ReferencedCoordinate;
|
import com.raytheon.uf.common.geospatial.ReferencedCoordinate;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.BilinearInterpolation;
|
import com.raytheon.uf.common.geospatial.interpolation.BilinearInterpolation;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
|
||||||
import com.raytheon.uf.common.style.ParamLevelMatchCriteria;
|
import com.raytheon.uf.common.style.ParamLevelMatchCriteria;
|
||||||
import com.raytheon.uf.common.time.CombinedDataTime;
|
import com.raytheon.uf.common.time.CombinedDataTime;
|
||||||
import com.raytheon.uf.common.time.DataTime;
|
import com.raytheon.uf.common.time.DataTime;
|
||||||
|
@ -61,9 +60,11 @@ import com.raytheon.viz.core.rsc.ICombinedResourceData.CombineUtil;
|
||||||
*
|
*
|
||||||
* SOFTWARE HISTORY
|
* SOFTWARE HISTORY
|
||||||
*
|
*
|
||||||
* Date Ticket# Engineer Description
|
* Date Ticket# Engineer Description
|
||||||
* ------------ ---------- ----------- --------------------------
|
* ------------- -------- ----------- --------------------------
|
||||||
* Mar 16, 2011 bsteffen Initial creation
|
* Mar 16, 2011 bsteffen Initial creation
|
||||||
|
* Feb 28, 2013 2791 bsteffen Use DataSource instead of FloatBuffers
|
||||||
|
* for data access
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -120,8 +121,8 @@ public class DifferenceGridResource extends
|
||||||
return super.interrogate(coord);
|
return super.interrogate(coord);
|
||||||
}
|
}
|
||||||
Map<String, Object> myMap = new HashMap<String, Object>();
|
Map<String, Object> myMap = new HashMap<String, Object>();
|
||||||
float oneVal = (Float) oneMap.get(INTERROGATE_VALUE);
|
double oneVal = ((Number) oneMap.get(INTERROGATE_VALUE)).doubleValue();
|
||||||
float twoVal = (Float) twoMap.get(INTERROGATE_VALUE);
|
double twoVal = ((Number) twoMap.get(INTERROGATE_VALUE)).doubleValue();
|
||||||
myMap.put(INTERROGATE_VALUE, oneVal - twoVal);
|
myMap.put(INTERROGATE_VALUE, oneVal - twoVal);
|
||||||
if (oneMap.get(INTERROGATE_UNIT).equals(twoMap.get(INTERROGATE_UNIT))) {
|
if (oneMap.get(INTERROGATE_UNIT).equals(twoMap.get(INTERROGATE_UNIT))) {
|
||||||
myMap.put(INTERROGATE_UNIT, oneMap.get(INTERROGATE_UNIT));
|
myMap.put(INTERROGATE_UNIT, oneMap.get(INTERROGATE_UNIT));
|
||||||
|
@ -221,28 +222,17 @@ public class DifferenceGridResource extends
|
||||||
oneData = oneData.reproject(newGeom, new BilinearInterpolation());
|
oneData = oneData.reproject(newGeom, new BilinearInterpolation());
|
||||||
twoData = twoData.reproject(newGeom, new BilinearInterpolation());
|
twoData = twoData.reproject(newGeom, new BilinearInterpolation());
|
||||||
if (oneData.isVector() && twoData.isVector()) {
|
if (oneData.isVector() && twoData.isVector()) {
|
||||||
float[] oneU = oneData.getUComponent().array();
|
DifferenceDataSource uComponent = new DifferenceDataSource(
|
||||||
float[] oneV = oneData.getVComponent().array();
|
oneData.getUComponent(), twoData.getUComponent());
|
||||||
float[] twoU = twoData.getUComponent().array();
|
DifferenceDataSource vComponent = new DifferenceDataSource(
|
||||||
float[] twoV = twoData.getVComponent().array();
|
oneData.getVComponent(), twoData.getVComponent());
|
||||||
float[] newU = new float[oneU.length];
|
newData = GeneralGridData.createVectorDataUV(newGeom,
|
||||||
float[] newV = new float[oneV.length];
|
uComponent, vComponent, newUnit);
|
||||||
for (int i = 0; i < newU.length; i++) {
|
|
||||||
newU[i] = oneU[i] - twoU[i];
|
|
||||||
newV[i] = oneV[i] - twoV[i];
|
|
||||||
}
|
|
||||||
newData = GeneralGridData
|
|
||||||
.createVectorDataUV(newGeom, FloatBuffer.wrap(newU),
|
|
||||||
FloatBuffer.wrap(newV), newUnit);
|
|
||||||
} else {
|
} else {
|
||||||
float[] oneScalar = oneData.getScalarData().array();
|
DifferenceDataSource data = new DifferenceDataSource(
|
||||||
float[] twoScalar = twoData.getScalarData().array();
|
oneData.getScalarData(), twoData.getScalarData());
|
||||||
float[] newScalar = new float[oneScalar.length];
|
newData = GeneralGridData.createScalarData(newGeom, data,
|
||||||
for (int i = 0; i < newScalar.length; i++) {
|
newUnit);
|
||||||
newScalar[i] = oneScalar[i] - twoScalar[i];
|
|
||||||
}
|
|
||||||
newData = GeneralGridData.createScalarData(newGeom,
|
|
||||||
FloatBuffer.wrap(newScalar), newUnit);
|
|
||||||
}
|
}
|
||||||
} catch (FactoryException e) {
|
} catch (FactoryException e) {
|
||||||
throw new VizException(e);
|
throw new VizException(e);
|
||||||
|
@ -279,12 +269,32 @@ public class DifferenceGridResource extends
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean projectRenderable(IRenderable renderable,
|
protected boolean projectRenderable(IRenderable renderable) {
|
||||||
CoordinateReferenceSystem crs) throws VizException {
|
|
||||||
// Always rebuild the renderables in case we projected into descriptor
|
// Always rebuild the renderables in case we projected into descriptor
|
||||||
// space.
|
// space.
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static class DifferenceDataSource implements DataSource {
|
||||||
|
|
||||||
|
private final DataSource one;
|
||||||
|
|
||||||
|
private final DataSource two;
|
||||||
|
|
||||||
|
private DifferenceDataSource(DataSource one, DataSource two) {
|
||||||
|
super();
|
||||||
|
this.one = one;
|
||||||
|
this.two = two;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getDataValue(int x, int y) {
|
||||||
|
double oneVal = one.getDataValue(x, y);
|
||||||
|
double twoVal = two.getDataValue(x, y);
|
||||||
|
return oneVal - twoVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,12 +39,15 @@ import org.opengis.referencing.operation.TransformException;
|
||||||
|
|
||||||
import com.raytheon.uf.common.geospatial.MapUtil;
|
import com.raytheon.uf.common.geospatial.MapUtil;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.GridReprojection;
|
import com.raytheon.uf.common.geospatial.interpolation.GridReprojection;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.GridReprojectionDataSource;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.GridSampler;
|
import com.raytheon.uf.common.geospatial.interpolation.GridSampler;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.Interpolation;
|
import com.raytheon.uf.common.geospatial.interpolation.Interpolation;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.PrecomputedGridReprojection;
|
import com.raytheon.uf.common.geospatial.interpolation.PrecomputedGridReprojection;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.data.FloatArrayWrapper;
|
import com.raytheon.uf.common.geospatial.interpolation.data.FloatArrayWrapper;
|
||||||
import com.raytheon.uf.common.geospatial.interpolation.data.FloatBufferWrapper;
|
import com.raytheon.uf.common.geospatial.interpolation.data.FloatBufferWrapper;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.OffsetDataSource;
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.UnitConvertingDataSource;
|
||||||
import com.vividsolutions.jts.geom.Coordinate;
|
import com.vividsolutions.jts.geom.Coordinate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,8 +71,10 @@ import com.vividsolutions.jts.geom.Coordinate;
|
||||||
* Jan 14, 2014 2661 bsteffen For vectors only keep uComponent and
|
* Jan 14, 2014 2661 bsteffen For vectors only keep uComponent and
|
||||||
* vComponent, calculate magnitude and
|
* vComponent, calculate magnitude and
|
||||||
* direction on demand.
|
* direction on demand.
|
||||||
* Feb 03, 2013 2764 bsteffen Ensure that internal buffers are array
|
* Feb 03, 2014 2764 bsteffen Ensure that internal buffers are array
|
||||||
* backed heap buffers.
|
* backed heap buffers.
|
||||||
|
* Feb 28, 2013 2791 bsteffen Use DataSource instead of FloatBuffers
|
||||||
|
* for data access
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -80,16 +85,16 @@ public class GeneralGridData {
|
||||||
|
|
||||||
private GridGeometry2D gridGeometry;
|
private GridGeometry2D gridGeometry;
|
||||||
|
|
||||||
private FloatBufferWrapper scalarData;
|
private DataSource scalarData;
|
||||||
|
|
||||||
private FloatBufferWrapper uComponent = null;
|
private DataSource uComponent = null;
|
||||||
|
|
||||||
private FloatBufferWrapper vComponent = null;
|
private DataSource vComponent = null;
|
||||||
|
|
||||||
private Unit<?> dataUnit;
|
private Unit<?> dataUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a scalar grid Data object.
|
* Create a scalar grid data object from float data.
|
||||||
*
|
*
|
||||||
* @param scalarData
|
* @param scalarData
|
||||||
* @param dataUnit
|
* @param dataUnit
|
||||||
|
@ -98,31 +103,27 @@ public class GeneralGridData {
|
||||||
public static GeneralGridData createScalarData(
|
public static GeneralGridData createScalarData(
|
||||||
GeneralGridGeometry gridGeometry, FloatBuffer scalarData,
|
GeneralGridGeometry gridGeometry, FloatBuffer scalarData,
|
||||||
Unit<?> dataUnit) {
|
Unit<?> dataUnit) {
|
||||||
|
DataSource scalarSource = new FloatBufferWrapper(scalarData,
|
||||||
|
gridGeometry);
|
||||||
|
return createScalarData(gridGeometry, scalarSource, dataUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a scalar grid data object from any data source
|
||||||
|
*
|
||||||
|
* @param scalarData
|
||||||
|
* @param dataUnit
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static GeneralGridData createScalarData(
|
||||||
|
GeneralGridGeometry gridGeometry, DataSource scalarData,
|
||||||
|
Unit<?> dataUnit) {
|
||||||
return new GeneralGridData(gridGeometry, scalarData, dataUnit);
|
return new GeneralGridData(gridGeometry, scalarData, dataUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create GridData for a vector. Providing (u,v) and (mag,dir) is redundant
|
|
||||||
* and it will be assumed that these are equivalent. This should only be
|
|
||||||
* used when both these representations are readily available to save time
|
|
||||||
* if one or the other is needed later.
|
|
||||||
*
|
|
||||||
* @deprecated Magnitude and direction are ignored, use
|
|
||||||
* {@link #createVectorDataUV(GeneralGridGeometry, FloatBuffer, FloatBuffer, Unit)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public static GeneralGridData createVectorData(
|
|
||||||
GeneralGridGeometry gridGeometry, FloatBuffer magnitude,
|
|
||||||
FloatBuffer direction, FloatBuffer uComponent,
|
|
||||||
FloatBuffer vComponent, Unit<?> dataUnit) {
|
|
||||||
return new GeneralGridData(gridGeometry,
|
|
||||||
uComponent, vComponent, dataUnit);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create gridData for a vector by providing the magnitude and direction of
|
* Create gridData for a vector by providing the magnitude and direction of
|
||||||
* the vector.
|
* the vector as floats.
|
||||||
*
|
*
|
||||||
* @param magnitude
|
* @param magnitude
|
||||||
* @param direction
|
* @param direction
|
||||||
|
@ -138,16 +139,17 @@ public class GeneralGridData {
|
||||||
FloatBuffer uComponent = FloatBuffer.allocate(magnitude.capacity());
|
FloatBuffer uComponent = FloatBuffer.allocate(magnitude.capacity());
|
||||||
while (magnitude.hasRemaining()) {
|
while (magnitude.hasRemaining()) {
|
||||||
double angle = Math.toRadians(direction.get());
|
double angle = Math.toRadians(direction.get());
|
||||||
vComponent.put((float) (Math.cos(angle) * magnitude.get()));
|
double mag = magnitude.get();
|
||||||
uComponent.put((float) (Math.sin(angle) * magnitude.get()));
|
vComponent.put((float) (Math.cos(angle) * mag));
|
||||||
|
uComponent.put((float) (Math.sin(angle) * mag));
|
||||||
}
|
}
|
||||||
return new GeneralGridData(gridGeometry, uComponent, vComponent,
|
return createVectorDataUV(gridGeometry, uComponent, vComponent,
|
||||||
dataUnit);
|
dataUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create gridData for a vector by providing the u and v components of the
|
* Create gridData for a vector by providing the u and v components of the
|
||||||
* vector
|
* vector as floats.
|
||||||
*
|
*
|
||||||
* @param uComponent
|
* @param uComponent
|
||||||
* @param vComponent
|
* @param vComponent
|
||||||
|
@ -157,32 +159,39 @@ public class GeneralGridData {
|
||||||
public static GeneralGridData createVectorDataUV(
|
public static GeneralGridData createVectorDataUV(
|
||||||
GeneralGridGeometry gridGeometry, FloatBuffer uComponent,
|
GeneralGridGeometry gridGeometry, FloatBuffer uComponent,
|
||||||
FloatBuffer vComponent, Unit<?> dataUnit) {
|
FloatBuffer vComponent, Unit<?> dataUnit) {
|
||||||
return new GeneralGridData(gridGeometry, uComponent,
|
DataSource uSource = new FloatBufferWrapper(uComponent, gridGeometry);
|
||||||
vComponent, dataUnit);
|
DataSource vSource = new FloatBufferWrapper(vComponent, gridGeometry);
|
||||||
|
return createVectorDataUV(gridGeometry, uSource, vSource, dataUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create gridData for a vector by providing the u and v components of the
|
||||||
|
* vector as any data source.
|
||||||
|
*
|
||||||
|
* @param uComponent
|
||||||
|
* @param vComponent
|
||||||
|
* @param dataUnit
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static GeneralGridData createVectorDataUV(
|
||||||
|
GeneralGridGeometry gridGeometry, DataSource uComponent,
|
||||||
|
DataSource vComponent, Unit<?> dataUnit) {
|
||||||
|
return new GeneralGridData(gridGeometry, uComponent, vComponent,
|
||||||
|
dataUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GeneralGridData(GeneralGridGeometry gridGeometry,
|
private GeneralGridData(GeneralGridGeometry gridGeometry,
|
||||||
FloatBuffer scalarData, Unit<?> dataUnit) {
|
DataSource scalarData, Unit<?> dataUnit) {
|
||||||
this.gridGeometry = GridGeometry2D.wrap(gridGeometry);
|
this.gridGeometry = GridGeometry2D.wrap(gridGeometry);
|
||||||
if (scalarData != null && !scalarData.hasArray()) {
|
this.scalarData = scalarData;
|
||||||
/*
|
|
||||||
* TODO refactor dispaly code so it doesn't need array instead of
|
|
||||||
* copying data.
|
|
||||||
*/
|
|
||||||
FloatBuffer copy = FloatBuffer.allocate(scalarData.capacity());
|
|
||||||
scalarData.rewind();
|
|
||||||
copy.put(scalarData);
|
|
||||||
scalarData = copy;
|
|
||||||
}
|
|
||||||
this.scalarData = new FloatBufferWrapper(scalarData, this.gridGeometry);
|
|
||||||
this.dataUnit = dataUnit;
|
this.dataUnit = dataUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GeneralGridData(GeneralGridGeometry gridGeometry,
|
private GeneralGridData(GeneralGridGeometry gridGeometry,
|
||||||
FloatBuffer uComponent, FloatBuffer vComponent, Unit<?> dataUnit) {
|
DataSource uComponent, DataSource vComponent, Unit<?> dataUnit) {
|
||||||
this.gridGeometry = GridGeometry2D.wrap(gridGeometry);
|
this.gridGeometry = GridGeometry2D.wrap(gridGeometry);
|
||||||
this.uComponent = new FloatBufferWrapper(uComponent, this.gridGeometry);
|
this.uComponent = uComponent;
|
||||||
this.vComponent = new FloatBufferWrapper(vComponent, this.gridGeometry);
|
this.vComponent = vComponent;
|
||||||
this.dataUnit = dataUnit;
|
this.dataUnit = dataUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,39 +217,28 @@ public class GeneralGridData {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (scalarData != null) {
|
if (scalarData != null) {
|
||||||
FloatBuffer oldData = scalarData.getBuffer();
|
scalarData = new UnitConvertingDataSource(converter, scalarData);
|
||||||
oldData.rewind();
|
|
||||||
FloatBuffer newData = FloatBuffer.allocate(oldData.capacity());
|
|
||||||
while (oldData.hasRemaining()) {
|
|
||||||
newData.put((float) converter.convert(oldData.get()));
|
|
||||||
}
|
|
||||||
newData.rewind();
|
|
||||||
scalarData = new FloatBufferWrapper(newData, gridGeometry);
|
|
||||||
}
|
}
|
||||||
if (uComponent != null) {
|
if (uComponent != null) {
|
||||||
FloatBuffer oldData = uComponent.getBuffer();
|
uComponent = new UnitConvertingDataSource(converter, uComponent);
|
||||||
oldData.rewind();
|
|
||||||
FloatBuffer newData = FloatBuffer.allocate(oldData.capacity());
|
|
||||||
while (oldData.hasRemaining()) {
|
|
||||||
newData.put((float) converter.convert(oldData.get()));
|
|
||||||
}
|
|
||||||
newData.rewind();
|
|
||||||
uComponent = new FloatBufferWrapper(newData, gridGeometry);
|
|
||||||
}
|
}
|
||||||
if (vComponent != null) {
|
if (vComponent != null) {
|
||||||
FloatBuffer oldData = vComponent.getBuffer();
|
vComponent = new UnitConvertingDataSource(converter, vComponent);
|
||||||
oldData.rewind();
|
|
||||||
FloatBuffer newData = FloatBuffer.allocate(oldData.capacity());
|
|
||||||
while (oldData.hasRemaining()) {
|
|
||||||
newData.put((float) converter.convert(oldData.get()));
|
|
||||||
}
|
|
||||||
newData.rewind();
|
|
||||||
vComponent = new FloatBufferWrapper(newData, gridGeometry);
|
|
||||||
}
|
}
|
||||||
dataUnit = unit;
|
dataUnit = unit;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new GeneralGridData that is a reprojected version of this data.
|
||||||
|
*
|
||||||
|
* @param newGridGeometry
|
||||||
|
* @param interpolation
|
||||||
|
* @return
|
||||||
|
* @throws FactoryException
|
||||||
|
* @throws TransformException
|
||||||
|
*/
|
||||||
public GeneralGridData reproject(GeneralGridGeometry newGridGeometry,
|
public GeneralGridData reproject(GeneralGridGeometry newGridGeometry,
|
||||||
Interpolation interpolation) throws FactoryException,
|
Interpolation interpolation) throws FactoryException,
|
||||||
TransformException {
|
TransformException {
|
||||||
|
@ -249,12 +247,10 @@ public class GeneralGridData {
|
||||||
gridGeometry, newGeom);
|
gridGeometry, newGeom);
|
||||||
GridSampler sampler = new GridSampler(interpolation);
|
GridSampler sampler = new GridSampler(interpolation);
|
||||||
if (isVector()) {
|
if (isVector()) {
|
||||||
sampler.setSource(new FloatBufferWrapper(getUComponent(),
|
sampler.setSource(getUComponent());
|
||||||
gridGeometry));
|
|
||||||
float[] udata = reproj.reprojectedGrid(sampler,
|
float[] udata = reproj.reprojectedGrid(sampler,
|
||||||
new FloatArrayWrapper(newGeom)).getArray();
|
new FloatArrayWrapper(newGeom)).getArray();
|
||||||
sampler.setSource(new FloatBufferWrapper(getVComponent(),
|
sampler.setSource(getVComponent());
|
||||||
gridGeometry));
|
|
||||||
float[] vdata = reproj.reprojectedGrid(sampler,
|
float[] vdata = reproj.reprojectedGrid(sampler,
|
||||||
new FloatArrayWrapper(newGeom)).getArray();
|
new FloatArrayWrapper(newGeom)).getArray();
|
||||||
// When reprojecting it is necessary to recalculate the
|
// When reprojecting it is necessary to recalculate the
|
||||||
|
@ -276,29 +272,8 @@ public class GeneralGridData {
|
||||||
Coordinate ll = new Coordinate(dp.x, dp.y);
|
Coordinate ll = new Coordinate(dp.x, dp.y);
|
||||||
double rot = MapUtil.rotation(ll, newGeom);
|
double rot = MapUtil.rotation(ll, newGeom);
|
||||||
double rot2 = MapUtil.rotation(ll, gridGeometry);
|
double rot2 = MapUtil.rotation(ll, gridGeometry);
|
||||||
/*
|
double cos = Math.cos(Math.toRadians(rot - rot2));
|
||||||
* When code calls into this method, the observed state
|
double sin = Math.sin(Math.toRadians(rot - rot2));
|
||||||
* of things is that u and v represent the direction
|
|
||||||
* the vector is going while mag and dir represent
|
|
||||||
* the direction the vector is coming from. The extra
|
|
||||||
* 180 here makes everything consistently represent the
|
|
||||||
* direction the vector is coming from so that when the
|
|
||||||
* barbs or arrows are rendered the mag and dir are
|
|
||||||
* calculated as expected. Overall this is a completely
|
|
||||||
* rediculous way of doing things. During construction
|
|
||||||
* everything should be forced to represent the vector
|
|
||||||
* consistently and we should only be keeping either
|
|
||||||
* u/v or mag/dir to minimize memory consumption.
|
|
||||||
* Unfortunately that is a significant change which is
|
|
||||||
* made high risk by the fact no one documents which
|
|
||||||
* areas are expecting vectors oriented to vs from. So
|
|
||||||
* for now I(bsteffen) have chosen to simply add in 180
|
|
||||||
* so that the behavior will be exactly as it was before
|
|
||||||
* 2287 because even though it is rediculous it is a well
|
|
||||||
* tested rediculous(theoretically).
|
|
||||||
*/
|
|
||||||
double cos = Math.cos(Math.toRadians(rot - rot2 + 180));
|
|
||||||
double sin = Math.sin(Math.toRadians(rot - rot2 + 180));
|
|
||||||
double u = udata[index];
|
double u = udata[index];
|
||||||
double v = vdata[index];
|
double v = vdata[index];
|
||||||
udata[index] = (float) (cos * u - sin * v);
|
udata[index] = (float) (cos * u - sin * v);
|
||||||
|
@ -309,11 +284,9 @@ public class GeneralGridData {
|
||||||
return createVectorDataUV(newGridGeometry, FloatBuffer.wrap(udata),
|
return createVectorDataUV(newGridGeometry, FloatBuffer.wrap(udata),
|
||||||
FloatBuffer.wrap(vdata), dataUnit);
|
FloatBuffer.wrap(vdata), dataUnit);
|
||||||
} else {
|
} else {
|
||||||
sampler.setSource(new FloatBufferWrapper(getScalarData(),
|
sampler.setSource(getScalarData());
|
||||||
gridGeometry));
|
return createScalarData(newGridGeometry,
|
||||||
FloatBuffer data = reproj.reprojectedGrid(sampler,
|
new GridReprojectionDataSource(reproj, sampler), dataUnit);
|
||||||
new FloatBufferWrapper(newGeom)).getBuffer();
|
|
||||||
return createScalarData(newGridGeometry, data, dataUnit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -330,20 +303,11 @@ public class GeneralGridData {
|
||||||
return new MagnitudeDataSource(uComponent, vComponent);
|
return new MagnitudeDataSource(uComponent, vComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FloatBuffer getScalarData() {
|
public DataSource getScalarData() {
|
||||||
if (isVector()) {
|
if (isVector()) {
|
||||||
FloatBufferWrapper tmp = new FloatBufferWrapper(gridGeometry);
|
return getMagnitude();
|
||||||
DataSource mag = getMagnitude();
|
|
||||||
int w = gridGeometry.getGridRange2D().width;
|
|
||||||
int h = gridGeometry.getGridRange2D().height;
|
|
||||||
for (int i = 0; i < w; i += 1) {
|
|
||||||
for (int j = 0; j < h; j += 1) {
|
|
||||||
tmp.setDataValue(mag.getDataValue(i, j), i, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tmp.getBuffer();
|
|
||||||
} else {
|
} else {
|
||||||
return scalarData.getBuffer();
|
return scalarData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,12 +331,12 @@ public class GeneralGridData {
|
||||||
return new DirectionToDataSource(uComponent, vComponent);
|
return new DirectionToDataSource(uComponent, vComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FloatBuffer getUComponent() {
|
public DataSource getUComponent() {
|
||||||
return uComponent.getBuffer();
|
return uComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FloatBuffer getVComponent() {
|
public DataSource getVComponent() {
|
||||||
return vComponent.getBuffer();
|
return vComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Unit<?> getDataUnit() {
|
public Unit<?> getDataUnit() {
|
||||||
|
@ -452,48 +416,27 @@ public class GeneralGridData {
|
||||||
range2.y = (int) Math.round((envelope.getMaxY() - envelope2.getMaxY())
|
range2.y = (int) Math.round((envelope.getMaxY() - envelope2.getMaxY())
|
||||||
/ dy);
|
/ dy);
|
||||||
if (data1.isVector() && data2.isVector()) {
|
if (data1.isVector() && data2.isVector()) {
|
||||||
FloatBuffer newU = FloatBuffer.allocate(nx * ny);
|
DataSource newU = mergeData(data1.getUComponent(), range1,
|
||||||
mergeData(data1.getUComponent(), range1, data2.getUComponent(),
|
data2.getUComponent(), range2);
|
||||||
range2, newU, range);
|
DataSource newV = mergeData(data1.getVComponent(), range1,
|
||||||
FloatBuffer newV = FloatBuffer.allocate(nx * ny);
|
data2.getVComponent(), range2);
|
||||||
mergeData(data1.getVComponent(), range1, data2.getVComponent(),
|
|
||||||
range2, newV, range);
|
|
||||||
return createVectorDataUV(geometry, newU, newV, data1.getDataUnit());
|
return createVectorDataUV(geometry, newU, newV, data1.getDataUnit());
|
||||||
} else {
|
} else {
|
||||||
FloatBuffer newData = FloatBuffer.allocate(nx * ny);
|
DataSource newData = mergeData(data1.getScalarData(), range1,
|
||||||
mergeData(data1.getScalarData(), range1, data2.getScalarData(),
|
data2.getScalarData(), range2);
|
||||||
range2, newData, range);
|
|
||||||
return createScalarData(geometry, newData, data1.getDataUnit());
|
return createScalarData(geometry, newData, data1.getDataUnit());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void mergeData(FloatBuffer data1, GridEnvelope2D env1,
|
private static DataSource mergeData(DataSource data1, GridEnvelope2D env1,
|
||||||
FloatBuffer data2, GridEnvelope2D env2, FloatBuffer destData,
|
DataSource data2, GridEnvelope2D env2) {
|
||||||
GridEnvelope2D destEnv) {
|
if (env1.x != 0 || env1.y != 0) {
|
||||||
data1.rewind();
|
data1 = new OffsetDataSource(data1, -env1.x, -env1.y);
|
||||||
data2.rewind();
|
|
||||||
destData.rewind();
|
|
||||||
for (int y = 0; y < destEnv.height; y++) {
|
|
||||||
for (int x = 0; x < destEnv.width; x++) {
|
|
||||||
float v1 = Float.NaN;
|
|
||||||
float v2 = Float.NaN;
|
|
||||||
if (env1.contains(x, y)) {
|
|
||||||
v1 = data1.get();
|
|
||||||
}
|
|
||||||
if (env2.contains(x, y)) {
|
|
||||||
v2 = data2.get();
|
|
||||||
}
|
|
||||||
if (Float.isNaN(v1) && Float.isNaN(v2)) {
|
|
||||||
destData.put(Float.NaN);
|
|
||||||
} else if (Float.isNaN(v1)) {
|
|
||||||
destData.put(v2);
|
|
||||||
} else if (Float.isNaN(v2)) {
|
|
||||||
destData.put(v1);
|
|
||||||
} else {
|
|
||||||
destData.put((v1 + v2) / 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (env2.x != 0 || env2.y != 0) {
|
||||||
|
data2 = new OffsetDataSource(data2, -env2.x, -env2.y);
|
||||||
|
}
|
||||||
|
return new MergedDataSource(data1, data2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static abstract class VectorDataSource implements DataSource {
|
private static abstract class VectorDataSource implements DataSource {
|
||||||
|
@ -524,7 +467,8 @@ public class GeneralGridData {
|
||||||
|
|
||||||
private static final class DirectionFromDataSource extends VectorDataSource {
|
private static final class DirectionFromDataSource extends VectorDataSource {
|
||||||
|
|
||||||
public DirectionFromDataSource(DataSource uComponent, DataSource vComponent) {
|
public DirectionFromDataSource(DataSource uComponent,
|
||||||
|
DataSource vComponent) {
|
||||||
super(uComponent, vComponent);
|
super(uComponent, vComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,8 +479,7 @@ public class GeneralGridData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class DirectionToDataSource extends
|
private static final class DirectionToDataSource extends VectorDataSource {
|
||||||
VectorDataSource {
|
|
||||||
|
|
||||||
public DirectionToDataSource(DataSource uComponent,
|
public DirectionToDataSource(DataSource uComponent,
|
||||||
DataSource vComponent) {
|
DataSource vComponent) {
|
||||||
|
@ -549,4 +492,31 @@ public class GeneralGridData {
|
||||||
vComponent.getDataValue(x, y)));
|
vComponent.getDataValue(x, y)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class MergedDataSource implements DataSource {
|
||||||
|
|
||||||
|
DataSource[] sources;
|
||||||
|
|
||||||
|
public MergedDataSource(DataSource... sources) {
|
||||||
|
this.sources = sources;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getDataValue(int x, int y) {
|
||||||
|
int count = 0;
|
||||||
|
double total = 0;
|
||||||
|
for (DataSource source : sources) {
|
||||||
|
double val = source.getDataValue(x, y);
|
||||||
|
if (Double.isNaN(val) == false) {
|
||||||
|
total += val;
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count == 0) {
|
||||||
|
return Double.NaN;
|
||||||
|
} else {
|
||||||
|
return total / count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,10 @@ package com.raytheon.uf.common.colormap;
|
||||||
*
|
*
|
||||||
* SOFTWARE HISTORY
|
* SOFTWARE HISTORY
|
||||||
*
|
*
|
||||||
* Date Ticket# Engineer Description
|
* Date Ticket# Engineer Description
|
||||||
* ------------ ---------- ----------- --------------------------
|
* ------------- -------- ----------- --------------------------
|
||||||
* Nov 7, 2013 2492 mschenke Initial creation
|
* Nov 07, 2013 2492 mschenke Initial creation
|
||||||
|
* Feb 28, 2013 2791 bsteffen Make EFFECTIVE_ZERO consistent with gl version.
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -39,7 +40,7 @@ package com.raytheon.uf.common.colormap;
|
||||||
|
|
||||||
public class LogConverter {
|
public class LogConverter {
|
||||||
|
|
||||||
private static double EFFECTIVE_ZERO = Double.MIN_VALUE;
|
private static double EFFECTIVE_ZERO = 0.0000001;
|
||||||
|
|
||||||
public static double valueToIndex(double value, double rangeMin,
|
public static double valueToIndex(double value, double rangeMin,
|
||||||
double rangeMax) {
|
double rangeMax) {
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
/**
|
||||||
|
* 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.common.geospatial.interpolation;
|
||||||
|
|
||||||
|
import org.opengis.referencing.FactoryException;
|
||||||
|
import org.opengis.referencing.operation.TransformException;
|
||||||
|
|
||||||
|
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
|
||||||
|
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||||
|
import com.raytheon.uf.common.status.UFStatus;
|
||||||
|
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data Source that reprojects from another grid.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------- -------- ----------- --------------------------
|
||||||
|
* Feb 28, 2014 2791 bsteffen Initial creation
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author bsteffen
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class GridReprojectionDataSource implements DataSource {
|
||||||
|
|
||||||
|
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||||
|
.getHandler(GridReprojectionDataSource.class);
|
||||||
|
|
||||||
|
private final GridReprojection reprojection;
|
||||||
|
|
||||||
|
private final GridSampler sampler;
|
||||||
|
|
||||||
|
public GridReprojectionDataSource(GridReprojection reprojection,
|
||||||
|
GridSampler sampler) {
|
||||||
|
super();
|
||||||
|
this.reprojection = reprojection;
|
||||||
|
this.sampler = sampler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getDataValue(int x, int y) {
|
||||||
|
try {
|
||||||
|
return reprojection.reprojectedGridCell(sampler, x, y);
|
||||||
|
} catch (FactoryException e) {
|
||||||
|
statusHandler.handle(Priority.DEBUG, e.getLocalizedMessage(), e);
|
||||||
|
return Double.NaN;
|
||||||
|
} catch (TransformException e) {
|
||||||
|
statusHandler.handle(Priority.DEBUG, e.getLocalizedMessage(), e);
|
||||||
|
return Double.NaN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -37,7 +37,7 @@ package com.raytheon.uf.common.geospatial.interpolation.data;
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class DataCopy {
|
public class DataUtilities {
|
||||||
|
|
||||||
public static final <D extends DataDestination> D copy(DataSource source,
|
public static final <D extends DataDestination> D copy(DataSource source,
|
||||||
D destination, int nx, int ny) {
|
D destination, int nx, int ny) {
|
||||||
|
@ -48,4 +48,50 @@ public class DataCopy {
|
||||||
}
|
}
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final MinMax getMinMax(DataSource source, int nx, int ny) {
|
||||||
|
double minValue = Double.POSITIVE_INFINITY;
|
||||||
|
double maxValue = Double.NEGATIVE_INFINITY;
|
||||||
|
for (int i = 0; i < nx; i += 1) {
|
||||||
|
for (int j = 0; j < ny; j += 1) {
|
||||||
|
double val = source.getDataValue(i, j);
|
||||||
|
if (Double.isNaN(val)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (val < minValue) {
|
||||||
|
minValue = val;
|
||||||
|
}
|
||||||
|
if (val > maxValue) {
|
||||||
|
maxValue = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new MinMax(minValue, maxValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MinMax {
|
||||||
|
|
||||||
|
private final double min;
|
||||||
|
|
||||||
|
private final double max;
|
||||||
|
|
||||||
|
private MinMax(double min, double max) {
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMin() {
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMax() {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getSpan() {
|
||||||
|
return max - min;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
/**
|
||||||
|
* 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.common.geospatial.interpolation.data;
|
||||||
|
|
||||||
|
import javax.measure.converter.UnitConverter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Source which wraps another source and converts data on demand.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------- -------- ----------- --------------------------
|
||||||
|
* Feb 25, 2014 2791 bsteffen Initial creation
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author bsteffen
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
public class UnitConvertingDataSource implements DataSource {
|
||||||
|
|
||||||
|
protected UnitConverter unitConverter;
|
||||||
|
|
||||||
|
protected DataSource wrappedSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param converter
|
||||||
|
* the unit converter to apply when setting the values in the
|
||||||
|
* destination
|
||||||
|
* @param source
|
||||||
|
* the source to get values from
|
||||||
|
*/
|
||||||
|
public UnitConvertingDataSource(UnitConverter converter, DataSource source) {
|
||||||
|
this.unitConverter = converter;
|
||||||
|
this.wrappedSource = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getDataValue(int x, int y) {
|
||||||
|
double val = unitConverter.convert(wrappedSource.getDataValue(x, y));
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -51,14 +51,24 @@ import com.raytheon.uf.common.util.GridUtil;
|
||||||
*
|
*
|
||||||
* SOFTWARE HISTORY
|
* SOFTWARE HISTORY
|
||||||
*
|
*
|
||||||
* Date Ticket# Engineer Description
|
* Date Ticket# Engineer Description
|
||||||
* ------------ ---------- ----------- --------------------------
|
* ------------- -------- ----------- -----------------------------------------
|
||||||
* Jul 25, 2007 chammack Initial Creation.
|
* Jul 25, 2007 chammack Initial Creation.
|
||||||
* Mar 26, 2009 2086 jsanchez Added a entityList to the match criteria.
|
* Mar 26, 2009 2086 jsanchez Added a entityList to the match criteria.
|
||||||
* Feb 15, 2013 1638 mschenke Moved GRID_FILL_VALUE from edex.common Util into GridUtil
|
* Feb 15, 2013 1638 mschenke Moved GRID_FILL_VALUE from edex.common
|
||||||
* Jun 24, 2013 2122 mschenke Added method for constructing {@link ColorMapParameters} from {@link StyleRule}
|
* Util into GridUtil
|
||||||
* Sep 24, 2013 2404 bclement moved to common.style from viz.core, added build method that takes ParamLevelMatchCriteria, removed unused methods
|
* Jun 24, 2013 2122 mschenke Added method for constructing
|
||||||
* Nov 13, 2013 2492 mschenke Create build that does not take data for adaptive building
|
* {@link ColorMapParameters} from
|
||||||
|
* {@link StyleRule}
|
||||||
|
* Sep 24, 2013 2404 bclement moved to common.style from viz.core,
|
||||||
|
* added build method that takes
|
||||||
|
* ParamLevelMatchCriteria, removed unused
|
||||||
|
* methods
|
||||||
|
* Nov 13, 2013 2492 mschenke Create build that does not take data for
|
||||||
|
* adaptive building
|
||||||
|
* Feb 28, 2014 2791 bsteffen Add a build method that takes min/max
|
||||||
|
* data values.
|
||||||
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author chammack
|
* @author chammack
|
||||||
|
@ -118,7 +128,14 @@ public class ColorMapParameterFactory {
|
||||||
return build(sr, data, level, parameterUnits);
|
return build(sr, data, level, parameterUnits);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ColorMapParameters build(StyleRule sr, Object data,
|
public static ColorMapParameters build(float minValue, float maxValue,
|
||||||
|
Unit<?> parameterUnits, ParamLevelMatchCriteria match)
|
||||||
|
throws StyleException {
|
||||||
|
float[] data = { minValue, maxValue };
|
||||||
|
return build(data, parameterUnits, match);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static ColorMapParameters build(StyleRule sr, Object data,
|
||||||
SingleLevel level, Unit<?> parameterUnits) {
|
SingleLevel level, Unit<?> parameterUnits) {
|
||||||
|
|
||||||
ColorMapParameters params = new ColorMapParameters();
|
ColorMapParameters params = new ColorMapParameters();
|
||||||
|
|
Loading…
Add table
Reference in a new issue