From 7900e78944e002073e1c6d4e140bf19e5c139720 Mon Sep 17 00:00:00 2001 From: Max Schenkelberg Date: Thu, 12 Apr 2012 14:46:08 -0500 Subject: [PATCH] Issue #239 Added wireframe shape capability Former-commit-id: 5be2b4e7458654cf0af86f0ed76530a1ed992da4 [formerly f56dd661225103b08b1d51a9f0cb174bd73340eb] Former-commit-id: 12dcb4b04475f9c3d60920ca3f87dff6486a3515 --- .../ui/rsc/CollaborationRenderingHandler.java | 97 +++++++++++++++++++ .../raytheon/uf/viz/core/IGraphicsTarget.java | 14 +++ .../graphics/DispatchGraphicsTarget.java | 24 ++++- .../wireframe/CreateWireframeShapeEvent.java | 12 +-- .../wireframe/RenderWireframeShapeEvent.java | 6 +- .../events/wireframe/WireframeShapeData.java | 67 ++++++++++++- .../viz/core/gl/internal/GLTarget.java | 17 ++++ .../IDeserializationContext.java | 8 ++ .../serialization/ISerializationContext.java | 9 ++ .../thrift/ThriftSerializationContext.java | 35 +++++++ 10 files changed, 278 insertions(+), 11 deletions(-) diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/rsc/CollaborationRenderingHandler.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/rsc/CollaborationRenderingHandler.java index 0717e98a88..429f6629ea 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/rsc/CollaborationRenderingHandler.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/rsc/CollaborationRenderingHandler.java @@ -35,7 +35,9 @@ import com.raytheon.uf.viz.core.PixelCoverage; import com.raytheon.uf.viz.core.data.IColorMapDataRetrievalCallback; import com.raytheon.uf.viz.core.drawables.ColorMapParameters; import com.raytheon.uf.viz.core.drawables.IColormappedImage; +import com.raytheon.uf.viz.core.drawables.IFont; import com.raytheon.uf.viz.core.drawables.IImage; +import com.raytheon.uf.viz.core.drawables.IWireframeShape; import com.raytheon.uf.viz.core.drawables.PaintProperties; import com.raytheon.uf.viz.core.drawables.ext.IOffscreenRenderingExtension; import com.raytheon.uf.viz.core.drawables.ext.colormap.IColormappedImageExtension; @@ -54,6 +56,13 @@ import com.raytheon.uf.viz.remote.graphics.events.mesh.ReprojectMeshEvent; import com.raytheon.uf.viz.remote.graphics.events.offscreen.CreateOffscreenImageEvent; import com.raytheon.uf.viz.remote.graphics.events.offscreen.RenderOffscreenEvent; import com.raytheon.uf.viz.remote.graphics.events.offscreen.RenderOnscreenEvent; +import com.raytheon.uf.viz.remote.graphics.events.wireframe.AllocatePointsEvent; +import com.raytheon.uf.viz.remote.graphics.events.wireframe.CreateWireframeShapeEvent; +import com.raytheon.uf.viz.remote.graphics.events.wireframe.RenderWireframeShapeEvent; +import com.raytheon.uf.viz.remote.graphics.events.wireframe.SimpleWireframeShapeEvent; +import com.raytheon.uf.viz.remote.graphics.events.wireframe.UpdateWireframeShapeEvent; +import com.raytheon.uf.viz.remote.graphics.events.wireframe.WireframeShapeData; +import com.raytheon.uf.viz.remote.graphics.events.wireframe.WireframeShapeData.Label; /** * Class that handles rendering events for collaboration resource @@ -365,4 +374,92 @@ public class CollaborationRenderingHandler { .renderOnscreen(); } + // ================== Wireframe shape events ================== + + @Subscribe + public void createWireframeShape(CreateWireframeShapeEvent event) { + int shapeId = event.getObjectId(); + IWireframeShape shape = null; + if (event.getSimplificationLevel() != null) { + if (event.isSpatialChopFlag() != null) { + shape = target.createWireframeShape(event.isMutable(), + event.getGridGeometry(), + event.getSimplificationLevel(), + event.isSpatialChopFlag(), event.getIExtent()); + } else { + shape = target + .createWireframeShape(event.isMutable(), + event.getGridGeometry(), + event.getSimplificationLevel()); + } + } else { + shape = target.createWireframeShape(event.isMutable(), + event.getGridGeometry()); + } + putRenderableObject(shapeId, shape); + } + + @Subscribe + public void allocatePointsForShape(AllocatePointsEvent event) { + IWireframeShape shape = getRenderableObject(event.getObjectId(), + IWireframeShape.class); + if (shape != null) { + shape.allocate(event.getNumberOfPoints()); + } + } + + @Subscribe + public void updateWireframeShapeData(UpdateWireframeShapeEvent event) { + IWireframeShape shape = getRenderableObject(event.getObjectId(), + IWireframeShape.class); + if (shape != null) { + WireframeShapeData data = event.getWireframeData(); + for (Label label : data.getLabels()) { + shape.addLabel(label.getText(), label.getPoint()); + } + for (double[][] coords : data.getCoordinates()) { + shape.addLineSegment(coords); + } + } + } + + @Subscribe + public void handleSimpleWireframeShapeEvent(SimpleWireframeShapeEvent event) { + IWireframeShape shape = getRenderableObject(event.getObjectId(), + IWireframeShape.class); + if (shape != null) { + switch (event.getAction()) { + case CLEAR_LABELS: + shape.clearLabels(); + break; + case COMPILE: + shape.compile(); + break; + case RESET: + shape.reset(); + break; + } + } + } + + @Subscribe + public void renderWireframeShape(RenderWireframeShapeEvent event) + throws VizException { + IWireframeShape shape = getRenderableObject(event.getObjectId(), + IWireframeShape.class); + if (shape != null) { + IFont font = null; + if (event.getFontId() != null) { + font = getRenderableObject(event.getFontId(), IFont.class); + } + if (event.getAlpha() == null) { + target.drawWireframeShape(shape, event.getColor(), + event.getLineWidth(), event.getLineStyle(), font); + } else { + target.drawWireframeShape(shape, event.getColor(), + event.getLineWidth(), event.getLineStyle(), font, + event.getAlpha()); + } + } + } } diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java index 4065439081..5833534599 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java @@ -529,6 +529,20 @@ public interface IGraphicsTarget extends IImagingExtension { public abstract IWireframeShape createWireframeShape(boolean mutable, IDescriptor descriptor, float simplificationLevel); + /** + * Create a wireframe shape object + * + * @param mutable + * whether the shape changes after creation + * @param descriptor + * the geometry for the shape + * @param simplificationLevel + * the simplification level + * @return a wireframe shape object + */ + public abstract IWireframeShape createWireframeShape(boolean mutable, + GeneralGridGeometry geom, float simplificationLevel); + /** * Create a wireframe shape object with options * diff --git a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/DispatchGraphicsTarget.java b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/DispatchGraphicsTarget.java index dec44d12ab..5bc64b0d4c 100644 --- a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/DispatchGraphicsTarget.java +++ b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/DispatchGraphicsTarget.java @@ -433,7 +433,7 @@ public class DispatchGraphicsTarget extends DispatchingObject } private void sendDrawWireframeShapeEvent(DispatchingWireframeShape shape, - RGB color, Float lineWidth, LineStyle lineStyle, IFont font, + RGB color, float lineWidth, LineStyle lineStyle, IFont font, Float alpha) { RenderWireframeShapeEvent event = RemoteGraphicsEventFactory .createEvent(RenderWireframeShapeEvent.class, shape); @@ -586,6 +586,28 @@ public class DispatchGraphicsTarget extends DispatchingObject return dispatching; } + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.core.IGraphicsTarget#createWireframeShape(boolean, + * org.geotools.coverage.grid.GeneralGridGeometry, float) + */ + @Override + public IWireframeShape createWireframeShape(boolean mutable, + GeneralGridGeometry geom, float simplificationLevel) { + // Create original + IWireframeShape targetShape = wrappedObject.createWireframeShape( + mutable, geom, simplificationLevel); + // Create wrapped + DispatchingWireframeShape dispatching = new DispatchingWireframeShape( + targetShape, getDispatcher(), geom); + // Dispatch creation event + sendCreateWireframeShapeEvent(dispatching, mutable, geom, + simplificationLevel, null, null); + return dispatching; + } + /** * @param mutable * @param descriptor diff --git a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/wireframe/CreateWireframeShapeEvent.java b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/wireframe/CreateWireframeShapeEvent.java index fe2aa84a86..152e489164 100644 --- a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/wireframe/CreateWireframeShapeEvent.java +++ b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/wireframe/CreateWireframeShapeEvent.java @@ -28,7 +28,7 @@ import com.raytheon.uf.viz.core.PixelExtent; import com.raytheon.uf.viz.remote.graphics.events.AbstractDispatchingObjectEvent; /** - * TODO Add Description + * Event to create a new wireframe shape object * *
  * 
@@ -50,7 +50,7 @@ public class CreateWireframeShapeEvent extends AbstractDispatchingObjectEvent {
     private GeneralGridGeometry gridGeometry;
 
     @DynamicSerializeElement
-    private Boolean mutable;
+    private boolean mutable;
 
     @DynamicSerializeElement
     private Float simplificationLevel;
@@ -94,7 +94,7 @@ public class CreateWireframeShapeEvent extends AbstractDispatchingObjectEvent {
     /**
      * @return the simplificationLevel
      */
-    public float getSimplificationLevel() {
+    public Float getSimplificationLevel() {
         return simplificationLevel;
     }
 
@@ -102,14 +102,14 @@ public class CreateWireframeShapeEvent extends AbstractDispatchingObjectEvent {
      * @param simplificationLevel
      *            the simplificationLevel to set
      */
-    public void setSimplificationLevel(float simplificationLevel) {
+    public void setSimplificationLevel(Float simplificationLevel) {
         this.simplificationLevel = simplificationLevel;
     }
 
     /**
      * @return the spatialChopFlag
      */
-    public boolean isSpatialChopFlag() {
+    public Boolean isSpatialChopFlag() {
         return spatialChopFlag;
     }
 
@@ -117,7 +117,7 @@ public class CreateWireframeShapeEvent extends AbstractDispatchingObjectEvent {
      * @param spatialChopFlag
      *            the spatialChopFlag to set
      */
-    public void setSpatialChopFlag(boolean spatialChopFlag) {
+    public void setSpatialChopFlag(Boolean spatialChopFlag) {
         this.spatialChopFlag = spatialChopFlag;
     }
 
diff --git a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/wireframe/RenderWireframeShapeEvent.java b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/wireframe/RenderWireframeShapeEvent.java
index 82f7c01351..5a94a87a81 100644
--- a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/wireframe/RenderWireframeShapeEvent.java
+++ b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/wireframe/RenderWireframeShapeEvent.java
@@ -57,7 +57,7 @@ public class RenderWireframeShapeEvent extends AbstractDispatchingObjectEvent
     private Integer blue;
 
     @DynamicSerializeElement
-    private Float lineWidth;
+    private float lineWidth;
 
     @DynamicSerializeElement
     private LineStyle lineStyle;
@@ -116,7 +116,7 @@ public class RenderWireframeShapeEvent extends AbstractDispatchingObjectEvent
     /**
      * @return the lineWidth
      */
-    public Float getLineWidth() {
+    public float getLineWidth() {
         return lineWidth;
     }
 
@@ -124,7 +124,7 @@ public class RenderWireframeShapeEvent extends AbstractDispatchingObjectEvent
      * @param lineWidth
      *            the lineWidth to set
      */
-    public void setLineWidth(Float lineWidth) {
+    public void setLineWidth(float lineWidth) {
         this.lineWidth = lineWidth;
     }
 
diff --git a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/wireframe/WireframeShapeData.java b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/wireframe/WireframeShapeData.java
index c24204af94..1649d8bcc2 100644
--- a/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/wireframe/WireframeShapeData.java
+++ b/cave/com.raytheon.uf.viz.remote.graphics/src/com/raytheon/uf/viz/remote/graphics/events/wireframe/WireframeShapeData.java
@@ -22,11 +22,18 @@ package com.raytheon.uf.viz.remote.graphics.events.wireframe;
 import java.util.LinkedList;
 import java.util.List;
 
+import com.raytheon.uf.common.serialization.IDeserializationContext;
+import com.raytheon.uf.common.serialization.ISerializationContext;
+import com.raytheon.uf.common.serialization.ISerializationTypeAdapter;
+import com.raytheon.uf.common.serialization.SerializationException;
 import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
 import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
+import com.raytheon.uf.common.serialization.annotations.DynamicSerializeTypeAdapter;
+import com.raytheon.uf.viz.remote.graphics.events.wireframe.WireframeShapeData.WireframeShapeDataAdapter;
 
 /**
- * TODO Add Description
+ * Wireframe shape data event which contains coordinates and labels to add to
+ * the wireframe shape referenced by this event
  * 
  * 
  * 
@@ -42,8 +49,66 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
  * @version 1.0
  */
 @DynamicSerialize
+@DynamicSerializeTypeAdapter(factory = WireframeShapeDataAdapter.class)
 public class WireframeShapeData {
 
+    public static class WireframeShapeDataAdapter implements
+            ISerializationTypeAdapter {
+        /*
+         * (non-Javadoc)
+         * 
+         * @see
+         * com.raytheon.uf.common.serialization.ISerializationTypeAdapter#serialize
+         * (com.raytheon.uf.common.serialization.ISerializationContext,
+         * java.lang.Object)
+         */
+        @Override
+        public void serialize(ISerializationContext serializer,
+                WireframeShapeData object) throws SerializationException {
+            serializer.writeI32(object.labels.size());
+            for (Label l : object.labels) {
+                serializer.writeString(l.getText());
+                serializer.writeDoubleArray(l.getPoint());
+            }
+            serializer.writeI32(object.coordinates.size());
+            for (double[][] coords : object.coordinates) {
+                serializer.writeI32(coords.length);
+                for (double[] coord : coords) {
+                    serializer.writeDoubleArray(coord);
+                }
+            }
+        }
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see com.raytheon.uf.common.serialization.ISerializationTypeAdapter#
+         * deserialize
+         * (com.raytheon.uf.common.serialization.IDeserializationContext)
+         */
+        @Override
+        public WireframeShapeData deserialize(
+                IDeserializationContext deserializer)
+                throws SerializationException {
+            WireframeShapeData data = new WireframeShapeData();
+            int size = deserializer.readI32();
+            for (int i = 0; i < size; ++i) {
+                data.addLabel(deserializer.readString(),
+                        deserializer.readDoubleArray());
+            }
+            size = deserializer.readI32();
+            for (int i = 0; i < size; ++i) {
+                int size2 = deserializer.readI32();
+                double[][] coords = new double[size2][];
+                for (int j = 0; j < size2; ++j) {
+                    coords[j] = deserializer.readDoubleArray();
+                }
+                data.addCoordinates(coords);
+            }
+            return data;
+        }
+    }
+
     @DynamicSerialize
     public static class Label {
 
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 1fe163aa1d..0c7cb09e3a 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
@@ -517,6 +517,23 @@ public class GLTarget implements IGLTarget {
         }
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * com.raytheon.uf.viz.core.IGraphicsTarget#createWireframeShape(boolean,
+     * org.geotools.coverage.grid.GeneralGridGeometry, float)
+     */
+    @Override
+    public IWireframeShape createWireframeShape(boolean mutable,
+            GeneralGridGeometry geom, float simplificationLevel) {
+        if (simplificationLevel > 0.0) {
+            return new GLWireframeShape(geom, mutable, simplificationLevel);
+        } else {
+            return new GLWireframeShape2D(geom, mutable);
+        }
+    }
+
     /*
      * (non-Javadoc)
      * 
diff --git a/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/IDeserializationContext.java b/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/IDeserializationContext.java
index 940105003e..5e546f9200 100644
--- a/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/IDeserializationContext.java
+++ b/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/IDeserializationContext.java
@@ -83,6 +83,14 @@ public interface IDeserializationContext {
      */
     public abstract double readDouble() throws SerializationException;
 
+    /**
+     * Read a double array
+     * 
+     * @return
+     * @throws SerializationException
+     */
+    public abstract double[] readDoubleArray() throws SerializationException;
+
     /**
      * Read a float
      * 
diff --git a/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/ISerializationContext.java b/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/ISerializationContext.java
index a56a6eb005..5fda8c537a 100644
--- a/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/ISerializationContext.java
+++ b/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/ISerializationContext.java
@@ -84,6 +84,15 @@ public interface ISerializationContext {
      */
     public abstract void writeDouble(double dub) throws SerializationException;
 
+    /**
+     * Write a double array
+     * 
+     * @param dub
+     * @throws SerializationException
+     */
+    public abstract void writeDoubleArray(double[] dubs)
+            throws SerializationException;
+
     /**
      * Write a float
      * 
diff --git a/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/thrift/ThriftSerializationContext.java b/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/thrift/ThriftSerializationContext.java
index 5c524912e1..6a96c50acc 100644
--- a/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/thrift/ThriftSerializationContext.java
+++ b/edexOsgi/com.raytheon.uf.common.serialization/src/com/raytheon/uf/common/serialization/thrift/ThriftSerializationContext.java
@@ -1313,6 +1313,23 @@ public class ThriftSerializationContext implements ISerializationContext,
         }
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * com.raytheon.uf.common.serialization.IDeserializationContext#readDoubleArray
+     * ()
+     */
+    @Override
+    public double[] readDoubleArray() throws SerializationException {
+        try {
+            int sz = this.protocol.readI32();
+            return this.protocol.readD64List(sz);
+        } catch (TException e) {
+            throw new SerializationException(e);
+        }
+    }
+
     /*
      * (non-Javadoc)
      * 
@@ -1329,4 +1346,22 @@ public class ThriftSerializationContext implements ISerializationContext,
             throw new SerializationException(e);
         }
     }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * com.raytheon.uf.common.serialization.ISerializationContext#writeDoubleArray
+     * (double[])
+     */
+    @Override
+    public void writeDoubleArray(double[] dubs) throws SerializationException {
+        try {
+            this.protocol.writeI32(dubs.length);
+            this.protocol.writeD64List(dubs);
+        } catch (TException e) {
+            throw new SerializationException(e);
+        }
+    }
+
 }
\ No newline at end of file