Issue #239 Added wireframe shape capability

Former-commit-id: 5be2b4e745 [formerly f56dd661225103b08b1d51a9f0cb174bd73340eb]
Former-commit-id: 12dcb4b044
This commit is contained in:
Max Schenkelberg 2012-04-12 14:46:08 -05:00
parent fec2d463b0
commit 7900e78944
10 changed files with 278 additions and 11 deletions

View file

@ -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.data.IColorMapDataRetrievalCallback;
import com.raytheon.uf.viz.core.drawables.ColorMapParameters; import com.raytheon.uf.viz.core.drawables.ColorMapParameters;
import com.raytheon.uf.viz.core.drawables.IColormappedImage; 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.IImage;
import com.raytheon.uf.viz.core.drawables.IWireframeShape;
import com.raytheon.uf.viz.core.drawables.PaintProperties; 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.IOffscreenRenderingExtension;
import com.raytheon.uf.viz.core.drawables.ext.colormap.IColormappedImageExtension; 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.CreateOffscreenImageEvent;
import com.raytheon.uf.viz.remote.graphics.events.offscreen.RenderOffscreenEvent; 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.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 * Class that handles rendering events for collaboration resource
@ -365,4 +374,92 @@ public class CollaborationRenderingHandler {
.renderOnscreen(); .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());
}
}
}
} }

View file

@ -529,6 +529,20 @@ public interface IGraphicsTarget extends IImagingExtension {
public abstract IWireframeShape createWireframeShape(boolean mutable, public abstract IWireframeShape createWireframeShape(boolean mutable,
IDescriptor descriptor, float simplificationLevel); 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 * Create a wireframe shape object with options
* *

View file

@ -433,7 +433,7 @@ public class DispatchGraphicsTarget extends DispatchingObject<IGraphicsTarget>
} }
private void sendDrawWireframeShapeEvent(DispatchingWireframeShape shape, private void sendDrawWireframeShapeEvent(DispatchingWireframeShape shape,
RGB color, Float lineWidth, LineStyle lineStyle, IFont font, RGB color, float lineWidth, LineStyle lineStyle, IFont font,
Float alpha) { Float alpha) {
RenderWireframeShapeEvent event = RemoteGraphicsEventFactory RenderWireframeShapeEvent event = RemoteGraphicsEventFactory
.createEvent(RenderWireframeShapeEvent.class, shape); .createEvent(RenderWireframeShapeEvent.class, shape);
@ -586,6 +586,28 @@ public class DispatchGraphicsTarget extends DispatchingObject<IGraphicsTarget>
return dispatching; 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 mutable
* @param descriptor * @param descriptor

View file

@ -28,7 +28,7 @@ import com.raytheon.uf.viz.core.PixelExtent;
import com.raytheon.uf.viz.remote.graphics.events.AbstractDispatchingObjectEvent; import com.raytheon.uf.viz.remote.graphics.events.AbstractDispatchingObjectEvent;
/** /**
* TODO Add Description * Event to create a new wireframe shape object
* *
* <pre> * <pre>
* *
@ -50,7 +50,7 @@ public class CreateWireframeShapeEvent extends AbstractDispatchingObjectEvent {
private GeneralGridGeometry gridGeometry; private GeneralGridGeometry gridGeometry;
@DynamicSerializeElement @DynamicSerializeElement
private Boolean mutable; private boolean mutable;
@DynamicSerializeElement @DynamicSerializeElement
private Float simplificationLevel; private Float simplificationLevel;
@ -94,7 +94,7 @@ public class CreateWireframeShapeEvent extends AbstractDispatchingObjectEvent {
/** /**
* @return the simplificationLevel * @return the simplificationLevel
*/ */
public float getSimplificationLevel() { public Float getSimplificationLevel() {
return simplificationLevel; return simplificationLevel;
} }
@ -102,14 +102,14 @@ public class CreateWireframeShapeEvent extends AbstractDispatchingObjectEvent {
* @param simplificationLevel * @param simplificationLevel
* the simplificationLevel to set * the simplificationLevel to set
*/ */
public void setSimplificationLevel(float simplificationLevel) { public void setSimplificationLevel(Float simplificationLevel) {
this.simplificationLevel = simplificationLevel; this.simplificationLevel = simplificationLevel;
} }
/** /**
* @return the spatialChopFlag * @return the spatialChopFlag
*/ */
public boolean isSpatialChopFlag() { public Boolean isSpatialChopFlag() {
return spatialChopFlag; return spatialChopFlag;
} }
@ -117,7 +117,7 @@ public class CreateWireframeShapeEvent extends AbstractDispatchingObjectEvent {
* @param spatialChopFlag * @param spatialChopFlag
* the spatialChopFlag to set * the spatialChopFlag to set
*/ */
public void setSpatialChopFlag(boolean spatialChopFlag) { public void setSpatialChopFlag(Boolean spatialChopFlag) {
this.spatialChopFlag = spatialChopFlag; this.spatialChopFlag = spatialChopFlag;
} }

View file

@ -57,7 +57,7 @@ public class RenderWireframeShapeEvent extends AbstractDispatchingObjectEvent
private Integer blue; private Integer blue;
@DynamicSerializeElement @DynamicSerializeElement
private Float lineWidth; private float lineWidth;
@DynamicSerializeElement @DynamicSerializeElement
private LineStyle lineStyle; private LineStyle lineStyle;
@ -116,7 +116,7 @@ public class RenderWireframeShapeEvent extends AbstractDispatchingObjectEvent
/** /**
* @return the lineWidth * @return the lineWidth
*/ */
public Float getLineWidth() { public float getLineWidth() {
return lineWidth; return lineWidth;
} }
@ -124,7 +124,7 @@ public class RenderWireframeShapeEvent extends AbstractDispatchingObjectEvent
* @param lineWidth * @param lineWidth
* the lineWidth to set * the lineWidth to set
*/ */
public void setLineWidth(Float lineWidth) { public void setLineWidth(float lineWidth) {
this.lineWidth = lineWidth; this.lineWidth = lineWidth;
} }

View file

@ -22,11 +22,18 @@ package com.raytheon.uf.viz.remote.graphics.events.wireframe;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; 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.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; 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
* *
* <pre> * <pre>
* *
@ -42,8 +49,66 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
* @version 1.0 * @version 1.0
*/ */
@DynamicSerialize @DynamicSerialize
@DynamicSerializeTypeAdapter(factory = WireframeShapeDataAdapter.class)
public class WireframeShapeData { public class WireframeShapeData {
public static class WireframeShapeDataAdapter implements
ISerializationTypeAdapter<WireframeShapeData> {
/*
* (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 @DynamicSerialize
public static class Label { public static class Label {

View file

@ -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) * (non-Javadoc)
* *

View file

@ -83,6 +83,14 @@ public interface IDeserializationContext {
*/ */
public abstract double readDouble() throws SerializationException; public abstract double readDouble() throws SerializationException;
/**
* Read a double array
*
* @return
* @throws SerializationException
*/
public abstract double[] readDoubleArray() throws SerializationException;
/** /**
* Read a float * Read a float
* *

View file

@ -84,6 +84,15 @@ public interface ISerializationContext {
*/ */
public abstract void writeDouble(double dub) throws SerializationException; 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 * Write a float
* *

View file

@ -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) * (non-Javadoc)
* *
@ -1329,4 +1346,22 @@ public class ThriftSerializationContext implements ISerializationContext,
throw new SerializationException(e); 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);
}
}
} }