Issue #239 Cleaned up DispatchingWireframeShape code to send world coordinates separate from pixel coordinates

Change-Id: I1c7eb9b19ea8d816eb3e81901ecf5574877a5212

Former-commit-id: 9c1f14a0a6 [formerly 0a3d69b5bb8ca31d8db8148225f7e1ef85778919]
Former-commit-id: 2bc9a18957
This commit is contained in:
Max Schenkelberg 2012-05-21 14:57:37 -05:00
parent b6134f482f
commit 084511ab6a
8 changed files with 303 additions and 71 deletions

View file

@ -40,6 +40,7 @@ import com.raytheon.uf.viz.remote.graphics.events.shapes.ShadedShapeDataEvent.Da
import com.raytheon.uf.viz.remote.graphics.events.shapes.ShadedShapeDataEvent.ShadedShapeData;
import com.raytheon.uf.viz.remote.graphics.events.shapes.WireframeShapeDataEvent;
import com.raytheon.uf.viz.remote.graphics.events.shapes.WireframeShapeDataEvent.Label;
import com.vividsolutions.jts.geom.Coordinate;
/**
* Handles render events for IShapes
@ -111,7 +112,10 @@ public class ShapeRenderingHandler extends CollaborationRenderingHandler {
for (Label label : event.getLabels()) {
shape.addLabel(label.getText(), label.getPoint());
}
for (double[][] coords : event.getCoordinates()) {
for (double[][] coords : event.getPixelCoordinates()) {
shape.addLineSegment(coords);
}
for (Coordinate[] coords : event.getWorldCoordiantes()) {
shape.addLineSegment(coords);
}
if (event.isCompile()) {

View file

@ -871,7 +871,7 @@ public class DispatchGraphicsTarget extends DispatchingObject<IGraphicsTarget>
GeneralGridGeometry targetGeometry, boolean tesselate) {
DispatchingShadedShape shape = new DispatchingShadedShape(
wrappedObject.createShadedShape(mutable, targetGeometry,
tesselate), getDispatcher(), targetGeometry);
tesselate), getDispatcher());
// Send creation event
CreateShadedShapeEvent event = RemoteGraphicsEventFactory.createEvent(
CreateShadedShapeEvent.class, shape);

View file

@ -31,6 +31,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeTypeAdapter;
import com.raytheon.uf.viz.remote.graphics.events.AbstractDispatchingObjectEvent;
import com.raytheon.uf.viz.remote.graphics.events.shapes.WireframeShapeDataEvent.WireframeShapeDataAdapter;
import com.vividsolutions.jts.geom.Coordinate;
/**
* Wireframe shape data event which contains coordinates and labels to add to
@ -73,13 +74,24 @@ public class WireframeShapeDataEvent extends AbstractDispatchingObjectEvent {
serializer.writeString(l.getText());
serializer.writeDoubleArray(l.getPoint());
}
serializer.writeI32(object.coordinates.size());
for (double[][] coords : object.coordinates) {
serializer.writeI32(object.pixelCoordinates.size());
for (double[][] coords : object.pixelCoordinates) {
serializer.writeI32(coords.length);
for (double[] coord : coords) {
serializer.writeDoubleArray(coord);
}
}
serializer.writeI32(object.worldCoordiantes.size());
for (Coordinate[] coordArray : object.worldCoordiantes) {
double[] packedCoords = new double[coordArray.length * 3];
int i = 0;
for (Coordinate coord : coordArray) {
packedCoords[i++] = coord.x;
packedCoords[i++] = coord.y;
packedCoords[i++] = coord.z;
}
serializer.writeDoubleArray(packedCoords);
}
}
/*
@ -101,6 +113,7 @@ public class WireframeShapeDataEvent extends AbstractDispatchingObjectEvent {
data.addLabel(deserializer.readString(),
deserializer.readDoubleArray());
}
size = deserializer.readI32();
for (int i = 0; i < size; ++i) {
int size2 = deserializer.readI32();
@ -108,8 +121,20 @@ public class WireframeShapeDataEvent extends AbstractDispatchingObjectEvent {
for (int j = 0; j < size2; ++j) {
coords[j] = deserializer.readDoubleArray();
}
data.addCoordinates(coords);
data.addPixelCoordinates(coords);
}
size = deserializer.readI32();
for (int i = 0; i < size; ++i) {
double[] packedCoords = deserializer.readDoubleArray();
Coordinate[] worldCoords = new Coordinate[packedCoords.length / 3];
for (int j = 0, k = 0; j < worldCoords.length; j++) {
worldCoords[j] = new Coordinate(packedCoords[k++],
packedCoords[k++], packedCoords[k++]);
}
data.addWorldCoordinates(worldCoords);
}
return data;
}
}
@ -164,7 +189,10 @@ public class WireframeShapeDataEvent extends AbstractDispatchingObjectEvent {
}
@DynamicSerializeElement
private List<double[][]> coordinates = new LinkedList<double[][]>();
private List<double[][]> pixelCoordinates = new LinkedList<double[][]>();
@DynamicSerializeElement
private List<Coordinate[]> worldCoordiantes = new LinkedList<Coordinate[]>();
@DynamicSerializeElement
private List<Label> labels = new LinkedList<Label>();
@ -188,18 +216,33 @@ public class WireframeShapeDataEvent extends AbstractDispatchingObjectEvent {
}
/**
* @return the coordinates
* @return the pixelCoordinates
*/
public List<double[][]> getCoordinates() {
return coordinates;
public List<double[][]> getPixelCoordinates() {
return pixelCoordinates;
}
/**
* @param coordinates
* the coordinates to set
* @param pixelCoordinates
* the pixelCoordinates to set
*/
public void setCoordinates(List<double[][]> coordinates) {
this.coordinates = coordinates;
public void setPixelCoordinates(List<double[][]> pixelCoordinates) {
this.pixelCoordinates = pixelCoordinates;
}
/**
* @return the worldCoordiantes
*/
public List<Coordinate[]> getWorldCoordiantes() {
return worldCoordiantes;
}
/**
* @param worldCoordiantes
* the worldCoordiantes to set
*/
public void setWorldCoordiantes(List<Coordinate[]> worldCoordiantes) {
this.worldCoordiantes = worldCoordiantes;
}
/**
@ -221,7 +264,11 @@ public class WireframeShapeDataEvent extends AbstractDispatchingObjectEvent {
labels.add(new Label(text, point));
}
public void addCoordinates(double[][] points) {
coordinates.add(points);
public void addPixelCoordinates(double[][] points) {
pixelCoordinates.add(points);
}
public void addWorldCoordinates(Coordinate[] points) {
worldCoordiantes.add(points);
}
}

View file

@ -0,0 +1,113 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.remote.graphics.extensions;
import java.util.Map;
import org.eclipse.swt.graphics.RGB;
import org.geotools.coverage.grid.GeneralGridGeometry;
import com.raytheon.uf.viz.core.drawables.IShadedShape;
import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension;
import com.raytheon.uf.viz.core.drawables.ext.colormap.IColormapShadedShapeExtension;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.remote.graphics.DispatchGraphicsTarget;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 18, 2012 mschenke Initial creation
*
* </pre>
*
* @author mschenke
* @version 1.0
*/
public class DispatchingColormappedShadedShapeExtension extends
GraphicsExtension<DispatchGraphicsTarget> implements
IColormapShadedShapeExtension {
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.core.drawables.ext.colormap.IColormapShadedShapeExtension
* #
* createColormapShadedShape(org.geotools.coverage.grid.GeneralGridGeometry,
* boolean)
*/
@Override
public IColormapShadedShape createColormapShadedShape(
GeneralGridGeometry targetGeometry, boolean tesselate) {
// TODO Auto-generated method stub
return null;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.core.drawables.ext.colormap.IColormapShadedShapeExtension
* #createShadedShape(com.raytheon.uf.viz.core.drawables.ext.colormap.
* IColormapShadedShapeExtension.IColormapShadedShape, java.util.Map)
*/
@Override
public IShadedShape createShadedShape(IColormapShadedShape baseShape,
Map<Object, RGB> colors) {
// TODO Auto-generated method stub
return null;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.core.drawables.ext.colormap.IColormapShadedShapeExtension
* #drawColormapShadedShape(com.raytheon.uf.viz.core.drawables.ext.colormap.
* IColormapShadedShapeExtension.IColormapShadedShape, java.util.Map, float,
* float)
*/
@Override
public void drawColormapShadedShape(IColormapShadedShape shape,
Map<Object, RGB> colors, float alpha, float brightness)
throws VizException {
// TODO Auto-generated method stub
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension#
* getCompatibilityValue(com.raytheon.uf.viz.core.IGraphicsTarget)
*/
@Override
public int getCompatibilityValue(DispatchGraphicsTarget target) {
return Compatibilty.TARGET_COMPATIBLE;
}
}

View file

@ -19,18 +19,7 @@
**/
package com.raytheon.uf.viz.remote.graphics.objects;
import java.util.Arrays;
import org.geotools.coverage.grid.GeneralGridGeometry;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.datum.PixelInCell;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
import com.raytheon.uf.common.geospatial.TransformFactory;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.drawables.IShape;
import com.raytheon.uf.viz.remote.graphics.Activator;
import com.raytheon.uf.viz.remote.graphics.Dispatcher;
import com.raytheon.uf.viz.remote.graphics.DispatchingObject;
import com.raytheon.uf.viz.remote.graphics.events.DisposeObjectEvent;
@ -56,24 +45,14 @@ import com.raytheon.uf.viz.remote.graphics.events.RemoteGraphicsEventFactory;
public abstract class AbstractDispatchingShape<T extends IShape> extends
DispatchingObject<T> implements IShape {
private MathTransform worldToTargetGrid;
private boolean dirty = true;
/**
* @param targetObject
* @param dispatcher
*/
public AbstractDispatchingShape(T targetObject, Dispatcher dispatcher,
GeneralGridGeometry targetGeometry) {
public AbstractDispatchingShape(T targetObject, Dispatcher dispatcher) {
super(targetObject, dispatcher);
try {
worldToTargetGrid = TransformFactory.worldToGrid(targetGeometry,
PixelInCell.CELL_CENTER);
} catch (FactoryException e) {
Activator.statusHandler.handle(Priority.PROBLEM,
"Error getting transform from base crs to target grid", e);
}
}
/**
@ -144,21 +123,4 @@ public abstract class AbstractDispatchingShape<T extends IShape> extends
*/
protected abstract void flushInternalState();
/**
* Convert a "world" pixel to the target geometry grid space
*
* @param world
* @return
* @throws TransformException
*/
protected double[] worldToPixel(double[] world) throws TransformException {
if (worldToTargetGrid != null) {
double[] out = new double[world.length];
worldToTargetGrid.transform(world, 0, out, 0, 1);
return out;
} else {
return Arrays.copyOf(world, world.length);
}
}
}

View file

@ -0,0 +1,112 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.remote.graphics.objects;
import java.util.Collection;
import com.raytheon.uf.viz.core.drawables.ext.colormap.IColormapShadedShapeExtension.IColormapShadedShape;
import com.raytheon.uf.viz.remote.graphics.Dispatcher;
import com.raytheon.uf.viz.remote.graphics.DispatchingObject;
import com.raytheon.uf.viz.remote.graphics.events.DisposeObjectEvent;
import com.raytheon.uf.viz.remote.graphics.events.RemoteGraphicsEventFactory;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 18, 2012 mschenke Initial creation
*
* </pre>
*
* @author mschenke
* @version 1.0
*/
public class DispatchingColormappedShadedShape extends
DispatchingObject<IColormapShadedShape> implements IColormapShadedShape {
private boolean dirty = true;
/**
* @param targetObject
* @param dispatcher
* @param targetGeometry
*/
public DispatchingColormappedShadedShape(IColormapShadedShape targetObject,
Dispatcher dispatcher) {
super(targetObject, dispatcher);
}
/**
* @return
* @see com.raytheon.uf.viz.core.drawables.ext.colormap.IColormapShadedShapeExtension.IColormapShadedShape#getColorKeys()
*/
public Collection<Object> getColorKeys() {
return wrappedObject.getColorKeys();
}
/**
* @param lineString
* @param colorKey
* @see com.raytheon.uf.viz.core.drawables.ext.colormap.IColormapShadedShapeExtension.IColormapShadedShape#addPolygon(com.vividsolutions.jts.geom.LineString[],
* java.lang.Object)
*/
public void addPolygon(LineString[] lineString, Object colorKey) {
wrappedObject.addPolygon(lineString, colorKey);
}
/**
* @param contours
* @param colorKey
* @see com.raytheon.uf.viz.core.drawables.ext.colormap.IColormapShadedShapeExtension.IColormapShadedShape#addPolygonPixelSpace(com.vividsolutions.jts.geom.LineString[],
* java.lang.Object)
*/
public void addPolygonPixelSpace(LineString[] contours, Object colorKey) {
wrappedObject.addPolygonPixelSpace(contours, colorKey);
}
/**
* @param geometry
* @param colorKey
* @see com.raytheon.uf.viz.core.drawables.ext.colormap.IColormapShadedShapeExtension.IColormapShadedShape#addGeometry(com.vividsolutions.jts.geom.Geometry,
* java.lang.Object)
*/
public void addGeometry(Geometry geometry, Object colorKey) {
wrappedObject.addGeometry(geometry, colorKey);
}
/**
*
* @see com.raytheon.uf.viz.core.drawables.ext.colormap.IColormapShadedShapeExtension.IColormapShadedShape#dispose()
*/
public void dispose() {
wrappedObject.dispose();
dispatch(RemoteGraphicsEventFactory.createEvent(
DisposeObjectEvent.class, this));
}
}

View file

@ -22,7 +22,6 @@ package com.raytheon.uf.viz.remote.graphics.objects;
import java.util.ArrayList;
import org.eclipse.swt.graphics.RGB;
import org.geotools.coverage.grid.GeneralGridGeometry;
import com.raytheon.uf.viz.core.drawables.IShadedShape;
import com.raytheon.uf.viz.remote.graphics.Dispatcher;
@ -60,8 +59,8 @@ public class DispatchingShadedShape extends
* @param dispatcher
*/
public DispatchingShadedShape(IShadedShape targetObject,
Dispatcher dispatcher, GeneralGridGeometry targetGeometry) {
super(targetObject, dispatcher, targetGeometry);
Dispatcher dispatcher) {
super(targetObject, dispatcher);
updateEvent = createNewUpdateEvent();
}

View file

@ -22,7 +22,6 @@ package com.raytheon.uf.viz.remote.graphics.objects;
import java.util.ArrayList;
import org.geotools.coverage.grid.GeneralGridGeometry;
import org.opengis.referencing.operation.TransformException;
import com.raytheon.uf.viz.core.drawables.IWireframeShape;
import com.raytheon.uf.viz.remote.graphics.Dispatcher;
@ -61,7 +60,7 @@ public class DispatchingWireframeShape extends
*/
public DispatchingWireframeShape(IWireframeShape targetObject,
Dispatcher dispatcher, GeneralGridGeometry targetGeometry) {
super(targetObject, dispatcher, targetGeometry);
super(targetObject, dispatcher);
this.updateEvent = createNewUpdateEvent();
}
@ -71,8 +70,10 @@ public class DispatchingWireframeShape extends
WireframeShapeDataEvent toSend = updateEvent;
if (wrappedObject.isMutable()) {
toSend = createNewUpdateEvent();
toSend.setCoordinates(new ArrayList<double[][]>(updateEvent
.getCoordinates()));
toSend.setPixelCoordinates(new ArrayList<double[][]>(
updateEvent.getPixelCoordinates()));
toSend.setWorldCoordiantes(new ArrayList<Coordinate[]>(
updateEvent.getWorldCoordiantes()));
toSend.setLabels(new ArrayList<Label>(updateEvent.getLabels()));
} else {
updateEvent = null;
@ -104,16 +105,10 @@ public class DispatchingWireframeShape extends
*/
public void addLineSegment(Coordinate[] latLong) {
wrappedObject.addLineSegment(latLong);
double[][] points = new double[latLong.length][];
for (int i = 0; i < latLong.length; ++i) {
try {
points[i] = worldToPixel(new double[] { latLong[i].x,
latLong[i].y });
} catch (TransformException e) {
// Ignore...
}
if (updateEvent != null) {
updateEvent.addWorldCoordinates(latLong);
markDirty();
}
addLineSegment(points);
}
/**
@ -123,7 +118,7 @@ public class DispatchingWireframeShape extends
public void addLineSegment(double[][] screenCoordinates) {
wrappedObject.addLineSegment(screenCoordinates);
if (updateEvent != null) {
updateEvent.addCoordinates(screenCoordinates);
updateEvent.addPixelCoordinates(screenCoordinates);
markDirty();
}
}