From 86f8bf3c15f869d825dcd571c17e4b07d877cda1 Mon Sep 17 00:00:00 2001 From: David Gillingham Date: Fri, 23 Aug 2013 13:39:12 -0500 Subject: [PATCH] Issue #2157: Remove meteolib dependencies from viz.core.contours plugin. Change-Id: Id749151ca9af702614a4b0a8fa7d037c71576e6f Former-commit-id: 75eb97823545d4f08f9a5660a24dd93763f43fc5 [formerly 1d46060cd07892056e300cec15fa40e07e21ab4e] [formerly ba076176d0bc1ef6edfff9cb792e916b1a0e7872] [formerly bc84e874a40205db024f52437d14db1411dede63 [formerly ba076176d0bc1ef6edfff9cb792e916b1a0e7872 [formerly b25274c599179eea5bc07d76bc369b0d0e934237]]] Former-commit-id: bc84e874a40205db024f52437d14db1411dede63 Former-commit-id: 6ca441fefd10c5c73165fd524fad4eb3a002faad [formerly be6130be9470209a599f47987701b875d922dda3] Former-commit-id: ca6ef12164244808df4ad2e85a5584184a0a83a7 --- .../META-INF/MANIFEST.MF | 2 +- .../viz/core/contours/ContourRenderable.java | 5 +- .../viz/core/contours/ContourSupport.java | 175 +----------------- 3 files changed, 11 insertions(+), 171 deletions(-) diff --git a/cave/com.raytheon.viz.core.contours/META-INF/MANIFEST.MF b/cave/com.raytheon.viz.core.contours/META-INF/MANIFEST.MF index 427203b977..53a4e5d92e 100644 --- a/cave/com.raytheon.viz.core.contours/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.viz.core.contours/META-INF/MANIFEST.MF @@ -12,7 +12,7 @@ Require-Bundle: org.eclipse.core.runtime, com.raytheon.uf.common.status;bundle-version="1.12.1174", com.raytheon.uf.common.util;bundle-version="1.12.1174", com.raytheon.uf.viz.core;bundle-version="1.12.1174", - com.raytheon.edex.meteolib;bundle-version="1.12.1174" + com.raytheon.uf.common.wxmath;bundle-version="1.0.0" Bundle-ActivationPolicy: lazy Export-Package: com.raytheon.viz.core.contours, com.raytheon.viz.core.contours.rsc.displays, diff --git a/cave/com.raytheon.viz.core.contours/src/com/raytheon/viz/core/contours/ContourRenderable.java b/cave/com.raytheon.viz.core.contours/src/com/raytheon/viz/core/contours/ContourRenderable.java index bf77b34700..37f4402c12 100644 --- a/cave/com.raytheon.viz.core.contours/src/com/raytheon/viz/core/contours/ContourRenderable.java +++ b/cave/com.raytheon.viz.core.contours/src/com/raytheon/viz/core/contours/ContourRenderable.java @@ -30,10 +30,10 @@ import org.geotools.geometry.DirectPosition2D; import org.geotools.geometry.jts.JTS; import org.opengis.referencing.operation.MathTransform; -import com.raytheon.edex.meteoLib.Controller; import com.raytheon.uf.common.datastorage.records.FloatDataRecord; import com.raytheon.uf.common.datastorage.records.IDataRecord; import com.raytheon.uf.common.geospatial.MapUtil; +import com.raytheon.uf.common.wxmath.DistFilter; import com.raytheon.uf.viz.core.IGraphicsTarget; import com.raytheon.uf.viz.core.IGraphicsTarget.LineStyle; import com.raytheon.uf.viz.core.PixelExtent; @@ -60,6 +60,7 @@ import com.vividsolutions.jts.geom.Coordinate; * ------------ ---------- ----------- -------------------------- * Jul 10, 2008 #1233 chammack Initial creation * Jul 18, 2013 #2199 mschenke Made code only smooth data once + * Aug 23, 2013 #2157 dgilling Remove meteolib dependency. * * * @@ -439,7 +440,7 @@ public abstract class ContourRenderable implements IRenderable { data[j] = 1.0E37f; } } - data = Controller.dist_filter(data, npts, nx, 0, 0, nx, ny); + data = DistFilter.filter(data, npts, nx, ny, 1); // Replace their NaN with our NaN for (int j = 0; j < data.length; j++) { if (data[j] == 1.0E37f) { diff --git a/cave/com.raytheon.viz.core.contours/src/com/raytheon/viz/core/contours/ContourSupport.java b/cave/com.raytheon.viz.core.contours/src/com/raytheon/viz/core/contours/ContourSupport.java index d34e643243..8fdbb44f7c 100644 --- a/cave/com.raytheon.viz.core.contours/src/com/raytheon/viz/core/contours/ContourSupport.java +++ b/cave/com.raytheon.viz.core.contours/src/com/raytheon/viz/core/contours/ContourSupport.java @@ -41,7 +41,6 @@ import org.opengis.referencing.datum.PixelInCell; import org.opengis.referencing.operation.MathTransform; import org.opengis.referencing.operation.TransformException; -import com.raytheon.edex.meteoLib.Controller; import com.raytheon.uf.common.datastorage.records.ByteDataRecord; import com.raytheon.uf.common.datastorage.records.FloatDataRecord; import com.raytheon.uf.common.datastorage.records.IDataRecord; @@ -51,7 +50,6 @@ import com.raytheon.uf.common.geospatial.util.WorldWrapChecker; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; -import com.raytheon.uf.common.util.ArraysUtil; import com.raytheon.uf.common.util.GridUtil; import com.raytheon.uf.viz.core.DrawableString; import com.raytheon.uf.viz.core.IExtent; @@ -96,6 +94,7 @@ import com.vividsolutions.jts.geom.Geometry; * with java port. * * Jul 18, 2013 2199 mschenke Ensured contouring is only occurring over visible area + * Jul 23, 2013 #2157 dgilling Remove legacy stream line drawing code. * * * @author chammack @@ -107,13 +106,6 @@ public class ContourSupport { .getHandler(ContourSupport.class); private static float smallestContourValue = GridUtil.GRID_FILL_VALUE - 1; - - private static final String STREAM_LINES_PROPERTY_NAME = "viz.use.legacy.streamlines"; - - private static final String LEGACY_STEAMLINES_ON = "true"; - - private static final String LEGACY_STEAMLINES_OFF = "false"; - private static float largestContourValue = GridUtil.GRID_FILL_VALUE + 1; @@ -642,17 +634,9 @@ public class ContourSupport { int maxX = (int) Math.ceil(Math.min(env.getMaximum(0), sz[0] - 1)); int maxY = (int) Math.ceil(Math.min(env.getMaximum(1), sz[1] - 1)); - if (LEGACY_STEAMLINES_ON.equals(System.getProperty( - STREAM_LINES_PROPERTY_NAME, LEGACY_STEAMLINES_OFF) - .toLowerCase())) { - makeStreamLinesLegacy(uW, vW, minX, minY, maxX, maxY, sz, - contourGroup, currentMagnification, zoom, - contourGroup.lastDensity, rastPosToWorldGrid); - } else { - makeStreamLinesNew(uW, vW, minX, minY, maxX, maxY, sz, - contourGroup, currentMagnification, zoom, - contourGroup.lastDensity, rastPosToWorldGrid); - } + makeStreamLines(uW, vW, minX, minY, maxX, maxY, sz, contourGroup, + currentMagnification, zoom, contourGroup.lastDensity, + rastPosToWorldGrid); } return contourGroup; @@ -1103,17 +1087,8 @@ public class ContourSupport { int maxX = (int) (sz[0] - 1); int maxY = (int) (sz[1] - 1); - if (LEGACY_STEAMLINES_ON.equals(System.getProperty( - STREAM_LINES_PROPERTY_NAME, LEGACY_STEAMLINES_OFF) - .toLowerCase())) { - makeStreamLinesLegacy(uW, vW, minX, minY, maxX, maxY, sz, - contourGroup, 1, 1, contourGroup.lastDensity * 2, - gridToPixel); - } else { - makeStreamLinesNew(uW, vW, minX, minY, maxX, maxY, sz, - contourGroup, 1, 1, contourGroup.lastDensity * 2, - gridToPixel); - } + makeStreamLines(uW, vW, minX, minY, maxX, maxY, sz, contourGroup, + 1, 1, contourGroup.lastDensity * 2, gridToPixel); return contourGroup; } else { @@ -1124,143 +1099,7 @@ public class ContourSupport { } - // TODO Remove this function once use of Java ported version of this - // algorithm is accepted by end-users - private static void makeStreamLinesLegacy(float[] uW, float[] vW, int minX, - int minY, int maxX, int maxY, long[] sz, ContourGroup contourGroup, - double currentMagnification, float zoom, double density, - MathTransform rastPosToWorldGrid) throws VizException { - - int szX = (maxX - minX) + 1; - int szY = (maxY - minY) + 1; - int totalSz = szX * szY; - if (totalSz <= 0) { - return; - } - int x = (int) sz[0]; - int y = (int) sz[1]; - - float[] adjustedUw = new float[totalSz]; - float[] adjustedVw = new float[totalSz]; - - int n = 0; - - for (int j = 0; j < szY; j++) { - for (int i = 0; i < szX; i++) { - - adjustedUw[n] = uW[(x * (j + minY)) + (i + minX)]; - adjustedVw[n] = vW[(x * (j + minY)) + (i + minX)]; - n++; - } - } - - ArraysUtil.flipVert(adjustedUw, szY, szX); - ArraysUtil.flipVert(adjustedVw, szY, szX); - - int arrSz = Math.max(10 * adjustedUw.length, uW.length); - - int[] work = new int[arrSz]; - float[] xPoints = new float[arrSz]; - float[] yPoints = new float[arrSz]; - int[] numPoints = new int[1]; - - // Use ported legacy code to determine contour interval - long t0 = System.currentTimeMillis(); - - double[] center = new double[2]; - double[] offCenter = new double[2]; - - try { - rastPosToWorldGrid.transform(new double[] { x / 2.0, y / 2.0 }, 0, - center, 0, 1); - rastPosToWorldGrid.transform(new double[] { (x / 2.0) + 1.0, - y / 2.0 }, 0, offCenter, 0, 1); - } catch (TransformException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - double gridPixelSize = offCenter[0] - center[0]; - double gridPixelMax = 2000.; - - // If gridPixelSize is large, arrows on streamline will be too small, so - // adjust here - if (gridPixelSize > gridPixelMax) { - gridPixelSize = gridPixelSize / 5; - } - float arrowSize = (float) (currentMagnification * 5 / zoom / gridPixelSize); - - double spadiv = zoom * density * gridPixelSize / 25; - - double minSpacing = 1.0 / spadiv; - double maxSpacing = 3.0 / spadiv; - float minspc = 0; - float maxspc = 0; - - if (minSpacing > 1) { - minspc = (float) Math.sqrt(minSpacing); - } - if (minspc < 0.1) { - minspc = 0.1f; - } - if (maxSpacing > 1) { - maxspc = (float) Math.sqrt(maxSpacing); - } - if (maxspc < 0.25) { - maxspc = 0.25f; - } - - Controller.strmpak(adjustedUw, adjustedVw, work, szX, szX, szY, - arrowSize, xPoints, yPoints, numPoints, minspc, maxspc, - -1000000f, -999998f); - - long t1 = System.currentTimeMillis(); - System.out.println("Contouring took: " + (t1 - t0)); - - List vals = new ArrayList(); - - long tAccum = 0; - - try { - for (int i = 0; i < numPoints[0] && i < xPoints.length; i++) { - if (xPoints[i] == -99999.0) { - if (vals.size() > 0) { - double[][] valsArr = vals.toArray(new double[vals - .size()][2]); - contourGroup.posValueShape.addLineSegment(valsArr); - vals.clear(); - } - } else { - double[] out = new double[2]; - try { - long tZ0 = System.currentTimeMillis(); - rastPosToWorldGrid.transform(new double[] { - maxX - xPoints[i] + 1, yPoints[i] + minY - 1 }, - 0, out, 0, 1); - long tZ1 = System.currentTimeMillis(); - tAccum += (tZ1 - tZ0); - } catch (TransformException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - vals.add(out); - } - } - - System.out.println("streamline transformation time: " + tAccum); - - if (vals.size() > 0) { - - double[][] valsArr = vals.toArray(new double[vals.size()][2]); - contourGroup.posValueShape.addLineSegment(valsArr); - vals.clear(); - } - } catch (Throwable e) { - throw new VizException("Error postprocessing contours", e); - } - } - - private static void makeStreamLinesNew(float[] uW, float[] vW, int minX, + private static void makeStreamLines(float[] uW, float[] vW, int minX, int minY, int maxX, int maxY, long[] sz, ContourGroup contourGroup, double currentMagnification, float zoom, double density, MathTransform rastPosToWorldGrid) throws VizException {