From 6914f62fcad9bf4875d2561ed510363acc43ef7f Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Thu, 25 Apr 2013 14:34:14 -0500 Subject: [PATCH] Issue #1954 Speed up creation of GLColormapShadedShapes. Former-commit-id: eaeb2f1671ae692e1c85a73cc540b9e5af4e3432 [formerly 5db31ee9fe30e3e1b36f40a878e385e3678555e5] [formerly eaeb2f1671ae692e1c85a73cc540b9e5af4e3432 [formerly 5db31ee9fe30e3e1b36f40a878e385e3678555e5] [formerly 46e080a447f01cff549d458132e9a219ad4384be [formerly 52636fb962871f995a9d4c23050d588d78476776]]] Former-commit-id: 46e080a447f01cff549d458132e9a219ad4384be Former-commit-id: 3fbb68732e069670256e05656c2cd5289d276456 [formerly d33d62f9b56398b078870c5490600124718c802f] Former-commit-id: c651968a8cf944d82131667aabdb6df993fd525b --- .../core/gl/internal/GLShadedShapeBase.java | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLShadedShapeBase.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLShadedShapeBase.java index 26776a1a4b..94c4373a16 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLShadedShapeBase.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLShadedShapeBase.java @@ -24,7 +24,6 @@ import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import javax.media.opengl.GL; @@ -48,7 +47,8 @@ import com.vividsolutions.jts.geom.LineString; /** * - * TODO Add Description + * Provides base implementation of shaded shapes in openGL that can be easily + * extended to implement IShadedShape or IColormapShadedShape. * *
  * 
@@ -57,6 +57,8 @@ import com.vividsolutions.jts.geom.LineString;
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Sep 3, 2011            bsteffen     Initial creation
+ * Apr 25, 2013 1954       bsteffen    Speed up creation of      
+ *                                     GLColormapShadedShapes.
  * 
  * 
* @@ -116,32 +118,22 @@ public class GLShadedShapeBase implements IShape { for (int i = 0; i < lineString.length; i++) { buffers[i] = FloatBuffer.allocate(lineString[i].getNumPoints() * 2); for (Coordinate c : lineString[i].getCoordinates()) { - double[] loc = { c.x, c.y }; - loc = worldToPixel(loc); - buffers[i].put((float) loc[0]); - buffers[i].put((float) loc[1]); + buffers[i].put((float) c.x); + buffers[i].put((float) c.y); numVertices += 1; } + try { + float[] array = buffers[i].array(); + worldToPixel.transform(array, 0, array, 0, + lineString[i].getNumPoints()); + } catch (TransformException e) { + // Ignore... + } numContours += 1; } polygons.add(buffers); } - protected double[] worldToPixel(double[] world) { - if (worldToPixel != null) { - try { - double[] out = new double[world.length]; - worldToPixel.transform(world, 0, out, 0, 1); - return out; - } catch (TransformException e) { - // Ignore... - } - return null; - } else { - return Arrays.copyOf(world, world.length); - } - } - public synchronized void addPolygonPixelSpace(LineString[] contours) { FloatBuffer[] buffers = new FloatBuffer[contours.length]; for (int i = 0; i < contours.length; i++) { @@ -239,10 +231,10 @@ public class GLShadedShapeBase implements IShape { if (tessellate) { // This over allocates to avoid future resizing if (vertexBuffer == null) { - vertexBuffer = FloatBuffer.allocate(numVertices * 2); + vertexBuffer = FloatBuffer.allocate(numVertices * 2 * 3); } else { FloatBuffer vertexBuffer = FloatBuffer.allocate(numVertices * 2 - + this.vertexBuffer.capacity()); + * 3 + this.vertexBuffer.capacity()); this.vertexBuffer.rewind(); vertexBuffer.put(this.vertexBuffer); this.vertexBuffer = vertexBuffer;