From 086f6aabe93719403e07206d87aab4e767d53004 Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Thu, 14 Feb 2013 15:06:11 -0600 Subject: [PATCH] Issue #1616 Add option for interpolation of colormap parameters, disable colormap interpolation by default. Change-Id: I48738965df0da9052f810dfc1f312ed032693390 Former-commit-id: 1940a9259616581ac812e2d4ea8a75873248d1e7 [formerly aa4c7526ff0330b11cc588a9a56dcc4ad6155afd] [formerly 8c0e9d3d9e6a453c5b58f6574026b9574ef3c5e6 [formerly ccf08fbd82aac8b1ae1d4f42b455ec7c3f995970]] Former-commit-id: 8c0e9d3d9e6a453c5b58f6574026b9574ef3c5e6 Former-commit-id: 455aa4628fe8a7b0e17d02e8c2863fe08e84b99d --- .../uf/viz/core/DrawableColorMap.java | 6 +-- .../core/drawables/ColorMapParameters.java | 43 +++++++++++++++---- .../ext/GeneralCanvasRenderingExtension.java | 4 +- .../events/colormap/DrawColorRampEvent.java | 5 ++- .../viz/core/gl/internal/GLTarget.java | 6 ++- .../ext/GLColormappedImageExtension.java | 5 ++- .../gfe/rsc/colorbar/ContinuousColorbar.java | 8 ++-- .../hydro/colorbar/HydroColorBarResource.java | 5 ++- .../resource/MPELegendResource.java | 4 +- .../viz/mpe/ui/rsc/MPELegendResource.java | 5 ++- 10 files changed, 64 insertions(+), 27 deletions(-) diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/DrawableColorMap.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/DrawableColorMap.java index c4eb952b65..afee782066 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/DrawableColorMap.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/DrawableColorMap.java @@ -33,6 +33,9 @@ import com.raytheon.uf.viz.core.drawables.ColorMapParameters; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jan 20, 2011 mschenke Initial creation + * Feb 14, 2013 1616 bsteffen Add option for interpolation of colormap + * parameters, disable colormap interpolation + * by default. * * * @@ -56,9 +59,6 @@ public class DrawableColorMap { /** The contrast to draw at */ public float contrast = 1.0f; - /** Specify whether the colormap should be interpolated */ - public boolean interpolate = true; - /** * Uses the ColorMapParameters passed in for drawing color map * diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapParameters.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapParameters.java index 1cd8a2f8d5..a36f234fac 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapParameters.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapParameters.java @@ -53,6 +53,9 @@ import com.raytheon.uf.viz.core.style.DataMappingPreferences.DataMappingEntry; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jul 24, 2007 chammack Initial Creation. + * Feb 14, 2013 1616 bsteffen Add option for interpolation of + * colormap parameters, disable colormap + * interpolation by default. * * * @@ -195,6 +198,9 @@ public class ColorMapParameters implements Cloneable, ISerializableObject { /** Values >0 enable log scaling of the colormap. */ private float logFactor = -1.0f; + /** Specify whether the colormap should be interpolated */ + protected boolean interpolate = false; + public static class LabelEntry { private float location; @@ -933,14 +939,7 @@ public class ColorMapParameters implements Cloneable, ISerializableObject { * @return */ public RGB getRGBByValue(float value) { - float index = getIndexByValue(value); - if (index < 0.0f) { - index = 0.0f; - } else if (index > 1.0f) { - index = 1.0f; - } - return colorToRGB(colorMap.getColors().get( - (int) (index * (colorMap.getSize()-1)))); + return colorToRGB(getColorByValue(value)); } /** @@ -956,7 +955,25 @@ public class ColorMapParameters implements Cloneable, ISerializableObject { } else if (index > 1.0f) { index = 1.0f; } - return colorMap.getColors().get((int) (index * (colorMap.getSize()-1))); + if (isInterpolate()) { + index = 0.5f; + index = (index * (colorMap.getSize() - 1)); + int lowIndex = (int) Math.floor(index); + int highIndex = (int) Math.ceil(index); + float lowWeight = highIndex - index; + float highWeight = 1.0f - lowWeight; + Color low = colorMap.getColors().get(lowIndex); + Color high = colorMap.getColors().get(highIndex); + float r = lowWeight * low.getRed() + highWeight * high.getRed(); + float g = lowWeight * low.getGreen() + highWeight * high.getGreen(); + float b = lowWeight * low.getBlue() + highWeight * high.getBlue(); + float a = lowWeight * low.getAlpha() + highWeight * high.getAlpha(); + return new Color(r, g, b, a); + } else { + return colorMap.getColors().get( + (int) (index * (colorMap.getSize() - 1))); + + } } public static RGB colorToRGB(Color c) { @@ -1027,4 +1044,12 @@ public class ColorMapParameters implements Cloneable, ISerializableObject { this.noDataValue = noDataValue; } + public boolean isInterpolate() { + return interpolate; + } + + public void setInterpolate(boolean interpolate) { + this.interpolate = interpolate; + } + } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GeneralCanvasRenderingExtension.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GeneralCanvasRenderingExtension.java index 7c88e974af..3cbb52dbd6 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GeneralCanvasRenderingExtension.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ext/GeneralCanvasRenderingExtension.java @@ -42,6 +42,9 @@ import com.raytheon.uf.viz.core.exception.VizException; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jun 26, 2012 bsteffen Initial creation + * Feb 14, 2013 1616 bsteffen Add option for interpolation of colormap + * parameters, disable colormap interpolation + * by default. * * * @@ -128,7 +131,6 @@ public class GeneralCanvasRenderingExtension extends newColorMap.alpha = colorMap.alpha; newColorMap.brightness = colorMap.brightness; newColorMap.contrast = colorMap.contrast; - newColorMap.interpolate = colorMap.interpolate; double x1 = colorMap.extent.getMinX(); double y1 = colorMap.extent.getMinY(); double x2 = colorMap.extent.getMaxX(); diff --git a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/colormap/DrawColorRampEvent.java b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/colormap/DrawColorRampEvent.java index ae6cde51e1..f4ed6fbf8b 100644 --- a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/colormap/DrawColorRampEvent.java +++ b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/colormap/DrawColorRampEvent.java @@ -37,6 +37,9 @@ import com.raytheon.uf.viz.remote.graphics.events.rendering.IRenderEvent; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * May 3, 2012 mschenke Initial creation + * Feb 14, 2013 1616 bsteffen Add option for interpolation of colormap + * parameters, disable colormap interpolation + * by default. * * * @@ -120,7 +123,6 @@ public class DrawColorRampEvent extends AbstractRemoteGraphicsRenderEvent { this.alpha = colorMap.alpha; this.brightness = colorMap.brightness; this.contrast = colorMap.contrast; - this.interpolate = colorMap.interpolate; this.extent = colorMap.extent; } @@ -129,7 +131,6 @@ public class DrawColorRampEvent extends AbstractRemoteGraphicsRenderEvent { colorMap.alpha = alpha; colorMap.brightness = brightness; colorMap.contrast = contrast; - colorMap.interpolate = interpolate; colorMap.extent = extent; return colorMap; } diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java index 9ad596ed53..5d75ebcd13 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java @@ -119,6 +119,10 @@ import com.sun.opengl.util.j2d.TextRenderer; * 07/19/10 5952 bkowal GLTarget will now check for the existence of updated extents * before drawing. A method has also been added to notify * GLTarget of when there are updated extents to load. + * Feb 14, 2013 1616 bsteffen Add option for interpolation of colormap + * parameters, disable colormap + * interpolation by default. + * * * * @@ -539,7 +543,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { gl.glActiveTexture(GL.GL_TEXTURE0); i.bind(gl, GL.GL_TEXTURE_1D); - if (drawableColorMap.interpolate) { + if (colorMapParams.isInterpolate()) { gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER, diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormappedImageExtension.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormappedImageExtension.java index a0f8b7a01b..57b0d317f8 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormappedImageExtension.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/ext/GLColormappedImageExtension.java @@ -48,6 +48,9 @@ import com.raytheon.viz.core.gl.objects.GLTextureObject; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Nov 18, 2011 mschenke Initial creation + * Feb 14, 2013 1616 bsteffen Add option for interpolation of colormap + * parameters, disable colormap interpolation + * by default. * * * @@ -130,7 +133,7 @@ public class GLColormappedImageExtension extends AbstractGLSLImagingExtension gl.glActiveTexture(GL.GL_TEXTURE1); cmapTexture.bind(gl, GL.GL_TEXTURE_1D); - if (glImage.isInterpolated()) { + if (usedColorMapParameters.isInterpolate()) { gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_1D, GL.GL_TEXTURE_MAG_FILTER, diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/rsc/colorbar/ContinuousColorbar.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/rsc/colorbar/ContinuousColorbar.java index 7a3c82f3c0..1ce662db15 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/rsc/colorbar/ContinuousColorbar.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/rsc/colorbar/ContinuousColorbar.java @@ -24,7 +24,6 @@ import org.eclipse.swt.graphics.RGB; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord.GridType; 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.viz.core.DrawableColorMap; import com.raytheon.uf.viz.core.DrawableLine; import com.raytheon.uf.viz.core.DrawableString; @@ -38,9 +37,7 @@ import com.raytheon.uf.viz.core.drawables.PaintProperties; import com.raytheon.uf.viz.core.drawables.ResourcePair; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.rsc.capabilities.ColorMapCapability; -import com.raytheon.uf.viz.core.rsc.capabilities.ImagingCapability; import com.raytheon.viz.gfe.Activator; -import com.raytheon.viz.gfe.GFEOperationFailedException; import com.raytheon.viz.gfe.core.DataManager; import com.raytheon.viz.gfe.core.ISpatialDisplayManager; import com.raytheon.viz.gfe.core.parm.Parm; @@ -59,6 +56,9 @@ import com.raytheon.viz.gfe.rsc.GFEResource; * 03/26/2008 chammack Initial Creation. * 04/13/2009 2092 njensen Support for custom labels * 08/20/2012 #1083 randerso Fixed user defined labels + * Feb 14, 2013 1616 bsteffen Add option for interpolation of colormap + * parameters, disable colormap interpolation + * by default. * * * @@ -144,8 +144,6 @@ public class ContinuousColorbar implements IColorBarDisplay { DrawableColorMap dcm = new DrawableColorMap(cmap); dcm.alpha = 1.0f; dcm.extent = pe; - dcm.interpolate = rscPair.getResource() - .getCapability(ImagingCapability.class).isInterpolationState(); target.drawColorRamp(dcm); GFEResource rsc = (GFEResource) rscPair.getResource(); diff --git a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/colorbar/HydroColorBarResource.java b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/colorbar/HydroColorBarResource.java index 4c480b7d69..2eab58ddd0 100644 --- a/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/colorbar/HydroColorBarResource.java +++ b/cave/com.raytheon.viz.hydro/src/com/raytheon/viz/hydro/colorbar/HydroColorBarResource.java @@ -62,6 +62,9 @@ import com.raytheon.viz.ui.cmenu.IContextMenuContributor; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Feb 20, 2009 mpduff Initial creation + * Feb 14, 2013 1616 bsteffen Add option for interpolation of colormap + * parameters, disable colormap interpolation + * by default. * * * @@ -193,8 +196,6 @@ public class HydroColorBarResource extends .getCapability(ColorMapCapability.class); DrawableColorMap cmap = new DrawableColorMap(rsc.getCapability( ColorMapCapability.class).getColorMapParameters()); - ; - cmap.interpolate = false; cmap.alpha = 1.0f; // The y value to use for drawing diff --git a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/MPELegendResource.java b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/MPELegendResource.java index f7deaab822..6b9b4003a8 100644 --- a/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/MPELegendResource.java +++ b/cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/resource/MPELegendResource.java @@ -51,6 +51,9 @@ import com.raytheon.viz.hydrocommon.HydroDisplayManager; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Nov 19, 2008 randerso Initial creation + * Feb 14, 2013 1616 bsteffen Add option for interpolation of colormap + * parameters, disable colormap interpolation + * by default. * * * @@ -157,7 +160,6 @@ public class MPELegendResource extends DrawableColorMap cmap = new DrawableColorMap(rsc.getCapability( ColorMapCapability.class).getColorMapParameters()); - cmap.interpolate = false; cmap.alpha = alpha; IColorMap cm = cmap.getColorMapParams().getColorMap(); diff --git a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/MPELegendResource.java b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/MPELegendResource.java index c31242ce49..d4ffd896ec 100644 --- a/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/MPELegendResource.java +++ b/cave/com.raytheon.viz.mpe.ui/src/com/raytheon/viz/mpe/ui/rsc/MPELegendResource.java @@ -92,6 +92,9 @@ import com.vividsolutions.jts.geom.GeometryFactory; * Nov 19, 2008 randerso Initial creation * Dec 02, 2009 3237 snaples Added options for 6/24 hour * display filtering. + * Feb 14, 2013 1616 bsteffen Add option for interpolation of colormap + * parameters, disable colormap interpolation + * by default. * * * @@ -273,7 +276,6 @@ public class MPELegendResource extends DrawableColorMap cmap = new DrawableColorMap(rsc.getCapability( ColorMapCapability.class).getColorMapParameters()); - cmap.interpolate = false; cmap.alpha = alpha; IColorMap cm = cmap.getColorMapParams().getColorMap(); @@ -377,7 +379,6 @@ public class MPELegendResource extends if (rsc.getStatus().equals(ResourceStatus.INITIALIZED)) { cmap = new DrawableColorMap(rsc.getCapability( ColorMapCapability.class).getColorMapParameters()); - cmap.interpolate = false; cmap.alpha = alpha; cmapSize = cmap.getColorMapParams().getColorMap().getSize();