Omaha #2913 Remove dead code using JAI
Former-commit-id:d48333444c
[formerlyd5d3f5605a
[formerly 767fc083618827ad06beff9f6728ea9dd42528f6]] Former-commit-id:d5d3f5605a
Former-commit-id:59a108822e
This commit is contained in:
parent
8adbef2eb1
commit
f010aa30b4
3 changed files with 23 additions and 246 deletions
|
@ -19,11 +19,7 @@
|
|||
**/
|
||||
package com.raytheon.viz.grid.util;
|
||||
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -31,27 +27,12 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.media.jai.BorderExtender;
|
||||
import javax.media.jai.Interpolation;
|
||||
import javax.media.jai.JAI;
|
||||
import javax.media.jai.ParameterBlockJAI;
|
||||
import javax.media.jai.PlanarImage;
|
||||
|
||||
import org.geotools.coverage.grid.GridCoverage2D;
|
||||
import org.geotools.coverage.grid.GridCoverageFactory;
|
||||
import org.geotools.coverage.grid.GridGeometry2D;
|
||||
import org.geotools.coverage.grid.ViewType;
|
||||
import org.geotools.coverage.processing.Operations;
|
||||
import org.opengis.geometry.Envelope;
|
||||
|
||||
import com.raytheon.uf.common.dataplugin.grid.GridConstants;
|
||||
import com.raytheon.uf.common.dataplugin.grid.GridInfoConstants;
|
||||
import com.raytheon.uf.common.dataplugin.grid.GridInfoRecord;
|
||||
import com.raytheon.uf.common.dataquery.requests.DbQueryRequest;
|
||||
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
|
||||
import com.raytheon.uf.common.dataquery.responses.DbQueryResponse;
|
||||
import com.raytheon.uf.common.datastorage.records.FloatDataRecord;
|
||||
import com.raytheon.uf.common.geospatial.MapUtil;
|
||||
import com.raytheon.uf.common.gridcoverage.GridCoverage;
|
||||
import com.raytheon.uf.common.gridcoverage.lookup.GridCoverageLookup;
|
||||
import com.raytheon.uf.viz.core.alerts.AlertMessage;
|
||||
|
@ -66,10 +47,12 @@ import com.raytheon.viz.alerts.observers.ProductAlertObserver;
|
|||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jan 08, 2010 rjpeter Initial creation
|
||||
* Jul 25, 2013 2112 bsteffen Fix volume browser sounding errors.
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------- -------- ----------- --------------------------
|
||||
* Jan 08, 2010 rjpeter Initial creation
|
||||
* Jul 25, 2013 2112 bsteffen Fix volume browser sounding errors.
|
||||
* May 19, 2014 2913 bsteffen Remove dead code.
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -183,62 +166,6 @@ public class CoverageUtils implements IAlertObserver {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resamples the grid to a new resolution using scale values
|
||||
*
|
||||
* @param img
|
||||
* The image to scale
|
||||
* @param xScale
|
||||
* The new horizontal resolution
|
||||
* @param yScale
|
||||
* The new vertical resolution
|
||||
* @return The resampled image
|
||||
*/
|
||||
public GridCoverage2D cropGrid(GridCoverage2D inputCoverage,
|
||||
GridGeometry2D outputGeometry, Interpolation interpolation) {
|
||||
RenderingHints hint = new RenderingHints(JAI.KEY_BORDER_EXTENDER,
|
||||
BorderExtender.createInstance(BorderExtender.BORDER_COPY));
|
||||
Operations oper = new Operations(hint);
|
||||
return (GridCoverage2D) oper.resample(
|
||||
inputCoverage.view(ViewType.GEOPHYSICS),
|
||||
outputGeometry.getCoordinateReferenceSystem(),
|
||||
outputGeometry,
|
||||
interpolation == null ? Interpolation
|
||||
.getInstance(Interpolation.INTERP_BICUBIC)
|
||||
: interpolation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resamples the grid to a new resolution using scale values
|
||||
*
|
||||
* @param img
|
||||
* The image to scale
|
||||
* @param xScale
|
||||
* The new horizontal resolution
|
||||
* @param yScale
|
||||
* The new vertical resolution
|
||||
* @return The resampled image
|
||||
*/
|
||||
private PlanarImage scaleGrid(RenderedImage img, float xScale, float yScale) {
|
||||
|
||||
PlanarImage scaledImg;
|
||||
|
||||
ParameterBlockJAI param = new ParameterBlockJAI("Scale");
|
||||
param.addSource(img);
|
||||
param.setParameter("xScale", xScale);
|
||||
param.setParameter("yScale", yScale);
|
||||
Interpolation interpol = Interpolation
|
||||
.getInstance(Interpolation.INTERP_BICUBIC_2);
|
||||
RenderingHints hint = new RenderingHints(JAI.KEY_BORDER_EXTENDER,
|
||||
BorderExtender.createInstance(BorderExtender.BORDER_COPY));
|
||||
|
||||
param.setParameter("interpolation", interpol);
|
||||
|
||||
scaledImg = JAI.create("Scale", param, hint).getRendering();
|
||||
|
||||
return scaledImg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void alertArrived(Collection<AlertMessage> alertMessages) {
|
||||
for (AlertMessage alertMessage : alertMessages) {
|
||||
|
|
|
@ -20,24 +20,12 @@
|
|||
|
||||
package com.raytheon.uf.common.dataplugin.gfe;
|
||||
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import javax.media.jai.BorderExtender;
|
||||
import javax.media.jai.Interpolation;
|
||||
import javax.media.jai.JAI;
|
||||
import javax.media.jai.ParameterBlockJAI;
|
||||
import javax.media.jai.PlanarImage;
|
||||
|
||||
import org.geotools.coverage.grid.GridCoverage2D;
|
||||
import org.geotools.coverage.grid.GridCoverageFactory;
|
||||
import org.geotools.coverage.grid.GridEnvelope2D;
|
||||
import org.geotools.coverage.grid.GridGeometry2D;
|
||||
import org.opengis.geometry.Envelope;
|
||||
import org.opengis.referencing.FactoryException;
|
||||
import org.opengis.referencing.operation.TransformException;
|
||||
|
||||
|
@ -78,6 +66,8 @@ import com.vividsolutions.jts.geom.Coordinate;
|
|||
* 07/17/13 #2185 bsteffen Cache computed grid reprojections.
|
||||
* 08/13/13 #1571 randerso Passed fill values into interpolator.
|
||||
* 03/07/14 #2791 bsteffen Move Data Source/Destination to numeric plugin.
|
||||
* 05/19/14 #2913 bsteffen Remove rescale option.
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -91,8 +81,6 @@ public class RemapGrid {
|
|||
/** The output grid location describing the destination data */
|
||||
private GridLocation destinationGloc;
|
||||
|
||||
private boolean rescale = false;
|
||||
|
||||
private SoftReference<Grid2DFloat> rotationRef;
|
||||
|
||||
/**
|
||||
|
@ -104,24 +92,8 @@ public class RemapGrid {
|
|||
* The destination grid location describing the destination data
|
||||
*/
|
||||
public RemapGrid(GridLocation sourceGloc, GridLocation destinationGloc) {
|
||||
this(sourceGloc, destinationGloc, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new RemapGrid with the given input and output grid locations
|
||||
*
|
||||
* @param sourceGloc
|
||||
* The source grid location describing the source data
|
||||
* @param destinationGloc
|
||||
* The destination grid location describing the destination data
|
||||
* @param rescale
|
||||
* true if data is to be rescaled
|
||||
*/
|
||||
public RemapGrid(GridLocation sourceGloc, GridLocation destinationGloc,
|
||||
boolean rescale) {
|
||||
this.sourceGloc = sourceGloc;
|
||||
this.destinationGloc = destinationGloc;
|
||||
this.rescale = rescale;
|
||||
this.rotationRef = new SoftReference<Grid2DFloat>(null);
|
||||
}
|
||||
|
||||
|
@ -549,67 +521,25 @@ public class RemapGrid {
|
|||
GridGeometry2D sourceGeometry = MapUtil.getGridGeometry(sourceGloc);
|
||||
|
||||
float[] data = input.getFloats();
|
||||
float[] f1 = null;
|
||||
|
||||
/*
|
||||
* Checks the CRSs to see if they are the same. If they are, then
|
||||
* reprojection is not necessary, only resampling
|
||||
*/
|
||||
if (rescale
|
||||
&& sourceGeometry.getCoordinateReferenceSystem().toWKT()
|
||||
.equals(destinationGloc.getCrsWKT())) {
|
||||
GridGeometry2D destGeometry = MapUtil.getGridGeometry(destinationGloc);
|
||||
|
||||
GridCoverageFactory factory = new GridCoverageFactory();
|
||||
GridReprojection interp = PrecomputedGridReprojection.getReprojection(
|
||||
sourceGeometry, destGeometry);
|
||||
|
||||
Envelope inputEnvelope = sourceGeometry.getEnvelope();
|
||||
DataSource source = new GeographicDataSource(FloatBuffer.wrap(data),
|
||||
sourceGeometry);
|
||||
source = FillValueFilter.apply(source, inputFill);
|
||||
;
|
||||
|
||||
// Map the data into an array
|
||||
float[][] dataPoints = new float[input.getYdim()][input.getXdim()];
|
||||
FloatBufferWrapper rawDest = new FloatBufferWrapper(
|
||||
destGeometry.getGridRange2D());
|
||||
DataDestination dest = InverseFillValueFilter.apply(
|
||||
(DataDestination) rawDest, outputFill);
|
||||
|
||||
int i = 0;
|
||||
for (int y = 0; y < input.getYdim(); y++) {
|
||||
for (int x = 0; x < input.getXdim(); x++) {
|
||||
dataPoints[y][x] = data[i++];
|
||||
}
|
||||
}
|
||||
interp.reprojectedGrid(new BilinearInterpolation(), source, dest);
|
||||
|
||||
// Construct the source grid coverage object
|
||||
GridCoverage2D inputGC = factory.create("in", dataPoints,
|
||||
inputEnvelope);
|
||||
|
||||
float scaleX = ((float) destinationGloc.getNx() / (float) sourceGloc
|
||||
.getNx());
|
||||
float scaleY = ((float) destinationGloc.getNy() / (float) sourceGloc
|
||||
.getNy());
|
||||
PlanarImage image = scaleGrid(inputGC.getRenderedImage(), scaleX,
|
||||
scaleY);
|
||||
Raster rasterData = image.getData();
|
||||
f1 = rasterData.getPixels(rasterData.getMinX(),
|
||||
rasterData.getMinY(), rasterData.getWidth(),
|
||||
rasterData.getHeight(), f1);
|
||||
|
||||
JAI.getDefaultInstance().getTileCache().flush();
|
||||
} else {
|
||||
GridGeometry2D destGeometry = MapUtil
|
||||
.getGridGeometry(destinationGloc);
|
||||
|
||||
GridReprojection interp = PrecomputedGridReprojection
|
||||
.getReprojection(sourceGeometry, destGeometry);
|
||||
|
||||
DataSource source = new GeographicDataSource(
|
||||
FloatBuffer.wrap(data), sourceGeometry);
|
||||
source = FillValueFilter.apply(source, inputFill);
|
||||
;
|
||||
|
||||
FloatBufferWrapper rawDest = new FloatBufferWrapper(
|
||||
destGeometry.getGridRange2D());
|
||||
DataDestination dest = InverseFillValueFilter.apply(
|
||||
(DataDestination) rawDest, outputFill);
|
||||
|
||||
interp.reprojectedGrid(new BilinearInterpolation(), source, dest);
|
||||
|
||||
f1 = rawDest.getArray();
|
||||
}
|
||||
float[] f1 = rawDest.getArray();
|
||||
|
||||
// Remap the the output data into a Grid2DFloat object
|
||||
|
||||
|
@ -619,37 +549,6 @@ public class RemapGrid {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resamples the grid to a new resolution using scale values
|
||||
*
|
||||
* @param img
|
||||
* The image to scale
|
||||
* @param xScale
|
||||
* The new horizontal resolution
|
||||
* @param yScale
|
||||
* The new vertical resolution
|
||||
* @return The resampled image
|
||||
*/
|
||||
private PlanarImage scaleGrid(RenderedImage img, float xScale, float yScale) {
|
||||
|
||||
PlanarImage scaledImg;
|
||||
|
||||
ParameterBlockJAI param = new ParameterBlockJAI("Scale");
|
||||
param.addSource(img);
|
||||
param.setParameter("xScale", xScale);
|
||||
param.setParameter("yScale", yScale);
|
||||
Interpolation interpol = Interpolation
|
||||
.getInstance(Interpolation.INTERP_BICUBIC);
|
||||
RenderingHints hint = new RenderingHints(JAI.KEY_BORDER_EXTENDER,
|
||||
BorderExtender.createInstance(BorderExtender.BORDER_COPY));
|
||||
|
||||
param.setParameter("interpolation", interpol);
|
||||
|
||||
scaledImg = JAI.create("Scale", param, hint);
|
||||
|
||||
return scaledImg;
|
||||
|
||||
}
|
||||
|
||||
private float getRot(int x, int y) {
|
||||
Grid2DFloat rotation;
|
||||
|
|
|
@ -20,9 +20,6 @@
|
|||
package com.raytheon.uf.common.mpe.util;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferUShort;
|
||||
import java.awt.image.Raster;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -37,8 +34,6 @@ import java.util.Arrays;
|
|||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.media.jai.RasterFactory;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
@ -51,6 +46,8 @@ import javax.xml.bind.annotation.XmlElement;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 30, 2008 randerso Initial creation
|
||||
* May 20, 2014 2913 bsteffen Remove main
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author randerso
|
||||
|
@ -447,52 +444,6 @@ public class XmrgFile {
|
|||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
XmrgFile xFile = new XmrgFile(
|
||||
// "/home/randerso/oaxData/precip_proc/local/data/mpe/rmosaic/RMOSAIC2008092213z");
|
||||
"/home/randerso/oaxData/precip_proc/local/data/app/mpe/prism/prism_mean_precip_oax_sep");
|
||||
// "/home/randerso/MPE/RMOSAIC2008102315z");
|
||||
xFile.load();
|
||||
Rectangle extent = xFile.getHrapExtent();
|
||||
|
||||
XmrgHeader header = xFile.getHeader();
|
||||
|
||||
short[] data = xFile.getData();
|
||||
|
||||
System.out.println(extent);
|
||||
System.out.println(header);
|
||||
|
||||
DataBufferUShort dataBuffer = new DataBufferUShort(data,
|
||||
data.length);
|
||||
|
||||
int[] bandMasks = new int[] { 0xf800, 0x07e0, 0x001f };
|
||||
Raster raster = RasterFactory.createPackedRaster(dataBuffer,
|
||||
extent.width, extent.height, extent.width, bandMasks, null);
|
||||
|
||||
BufferedImage bi = new BufferedImage(extent.width, extent.height,
|
||||
BufferedImage.TYPE_USHORT_565_RGB);
|
||||
bi.setData(raster);
|
||||
ImageIO.write(bi, "png", new File("/tmp/xxx.png"));
|
||||
|
||||
xFile.save("/tmp/xmrg.dat");
|
||||
|
||||
Rectangle rect = new Rectangle(
|
||||
//
|
||||
// extent.x, extent.y, 7, 7);
|
||||
extent.x + extent.width - 7, extent.y + extent.height - 7,
|
||||
7, 7);
|
||||
short[][] subData = xFile.getData(rect);
|
||||
for (int i = 0; i < rect.height; i++) {
|
||||
System.out.println(Arrays.toString(subData[i]));
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the file
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue