Issue #1954 Speed up creation of GLColormapShadedShapes.

Former-commit-id: eaeb2f1671 [formerly 5db31ee9fe] [formerly eaeb2f1671 [formerly 5db31ee9fe] [formerly 46e080a447 [formerly 52636fb962871f995a9d4c23050d588d78476776]]]
Former-commit-id: 46e080a447
Former-commit-id: 3fbb68732e [formerly d33d62f9b5]
Former-commit-id: c651968a8c
This commit is contained in:
Ben Steffensmeier 2013-04-25 14:34:14 -05:00
parent 0e5af7d05a
commit 6914f62fca

View file

@ -24,7 +24,6 @@ import java.nio.ByteOrder;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.media.opengl.GL; 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.
* *
* <pre> * <pre>
* *
@ -57,6 +57,8 @@ import com.vividsolutions.jts.geom.LineString;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Sep 3, 2011 bsteffen Initial creation * Sep 3, 2011 bsteffen Initial creation
* Apr 25, 2013 1954 bsteffen Speed up creation of
* GLColormapShadedShapes.
* *
* </pre> * </pre>
* *
@ -116,32 +118,22 @@ public class GLShadedShapeBase implements IShape {
for (int i = 0; i < lineString.length; i++) { for (int i = 0; i < lineString.length; i++) {
buffers[i] = FloatBuffer.allocate(lineString[i].getNumPoints() * 2); buffers[i] = FloatBuffer.allocate(lineString[i].getNumPoints() * 2);
for (Coordinate c : lineString[i].getCoordinates()) { for (Coordinate c : lineString[i].getCoordinates()) {
double[] loc = { c.x, c.y }; buffers[i].put((float) c.x);
loc = worldToPixel(loc); buffers[i].put((float) c.y);
buffers[i].put((float) loc[0]);
buffers[i].put((float) loc[1]);
numVertices += 1; numVertices += 1;
} }
try {
float[] array = buffers[i].array();
worldToPixel.transform(array, 0, array, 0,
lineString[i].getNumPoints());
} catch (TransformException e) {
// Ignore...
}
numContours += 1; numContours += 1;
} }
polygons.add(buffers); 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) { public synchronized void addPolygonPixelSpace(LineString[] contours) {
FloatBuffer[] buffers = new FloatBuffer[contours.length]; FloatBuffer[] buffers = new FloatBuffer[contours.length];
for (int i = 0; i < contours.length; i++) { for (int i = 0; i < contours.length; i++) {
@ -239,10 +231,10 @@ public class GLShadedShapeBase implements IShape {
if (tessellate) { if (tessellate) {
// This over allocates to avoid future resizing // This over allocates to avoid future resizing
if (vertexBuffer == null) { if (vertexBuffer == null) {
vertexBuffer = FloatBuffer.allocate(numVertices * 2); vertexBuffer = FloatBuffer.allocate(numVertices * 2 * 3);
} else { } else {
FloatBuffer vertexBuffer = FloatBuffer.allocate(numVertices * 2 FloatBuffer vertexBuffer = FloatBuffer.allocate(numVertices * 2
+ this.vertexBuffer.capacity()); * 3 + this.vertexBuffer.capacity());
this.vertexBuffer.rewind(); this.vertexBuffer.rewind();
vertexBuffer.put(this.vertexBuffer); vertexBuffer.put(this.vertexBuffer);
this.vertexBuffer = vertexBuffer; this.vertexBuffer = vertexBuffer;