Issue #358 Made wireframe shapes rely more on the grid geoemtry of the
descriptor than the actual descriptor as the descriptor is used purely for convenience Former-commit-id:86d3763df0
[formerly66eaffb9ee
] [formerly15a9245592
] [formerly86d3763df0
[formerly66eaffb9ee
] [formerly15a9245592
] [formerlyf10f1a5319
[formerly15a9245592
[formerly 265ccb3e22aa0122dbd74e83d0af202596c1941c]]]] Former-commit-id:f10f1a5319
Former-commit-id:5fc757226e
[formerlybbab188fb9
] [formerly 6d1ea66ba9a1390c296443e20785aa9ef4a890fa [formerlyac11dd0c18
]] Former-commit-id: cb1bc79da744506da785204d429e696d9676fb32 [formerly2f3b9f0067
] Former-commit-id:e73e40dc78
This commit is contained in:
parent
893bc3d143
commit
e6fcc458e5
11 changed files with 275 additions and 320 deletions
|
@ -31,7 +31,22 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import org.geotools.coverage.grid.GeneralGridEnvelope;
|
||||
import org.geotools.coverage.grid.GeneralGridGeometry;
|
||||
import org.geotools.coverage.grid.GridGeometry2D;
|
||||
import org.geotools.geometry.GeneralEnvelope;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.geotools.referencing.operation.DefaultMathTransformFactory;
|
||||
import org.opengis.referencing.FactoryException;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.opengis.referencing.crs.GeneralDerivedCRS;
|
||||
import org.opengis.referencing.datum.PixelInCell;
|
||||
import org.opengis.referencing.operation.MathTransform;
|
||||
import org.opengis.referencing.operation.TransformException;
|
||||
|
||||
import com.raytheon.uf.common.serialization.adapters.GridGeometryAdapter;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
|
@ -39,6 +54,7 @@ import com.raytheon.uf.common.time.DataTime;
|
|||
import com.raytheon.uf.viz.core.AbstractTimeMatcher;
|
||||
import com.raytheon.uf.viz.core.IDisplayPane;
|
||||
import com.raytheon.uf.viz.core.IDisplayPaneContainer;
|
||||
import com.raytheon.uf.viz.core.IExtent;
|
||||
import com.raytheon.uf.viz.core.VizConstants;
|
||||
import com.raytheon.uf.viz.core.datastructure.LoopProperties;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
|
@ -111,6 +127,19 @@ public abstract class AbstractDescriptor extends ResourceGroup implements
|
|||
/** The frame coordination object */
|
||||
protected IFrameCoordinator frameCoordinator;
|
||||
|
||||
private MathTransform worldToPixel;
|
||||
|
||||
private MathTransform pixelToWorld;
|
||||
|
||||
/** The spatial grid for the descriptor */
|
||||
private GeneralGridGeometry gridGeometry;
|
||||
|
||||
public AbstractDescriptor(GeneralGridGeometry gridGeometry) {
|
||||
this();
|
||||
this.gridGeometry = gridGeometry;
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
@ -196,7 +225,8 @@ public abstract class AbstractDescriptor extends ResourceGroup implements
|
|||
protected void preAddListener(ResourcePair rp)
|
||||
throws WrongProjectionException {
|
||||
|
||||
AbstractVizResource resource = rp.getResource();
|
||||
AbstractVizResource<?, AbstractDescriptor> resource = (AbstractVizResource<?, AbstractDescriptor>) rp
|
||||
.getResource();
|
||||
|
||||
resource.setDescriptor(this);
|
||||
|
||||
|
@ -654,6 +684,119 @@ public abstract class AbstractDescriptor extends ResourceGroup implements
|
|||
return frameCoordinator;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
GeneralGridGeometry gridGeometry = getGridGeometry();
|
||||
MathTransform worldToCRS = getWorldToCRSTransform(gridGeometry);
|
||||
if (worldToCRS != null) {
|
||||
try {
|
||||
MathTransform crsToPixel = gridGeometry.getGridToCRS(
|
||||
PixelInCell.CELL_CENTER).inverse();
|
||||
worldToPixel = new DefaultMathTransformFactory()
|
||||
.createConcatenatedTransform(worldToCRS, crsToPixel);
|
||||
pixelToWorld = worldToPixel.inverse();
|
||||
} catch (Exception e) {
|
||||
statusHandler.handle(Priority.PROBLEM,
|
||||
"Error setting up Math Transforms,"
|
||||
+ " this descriptor may not work properly", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.uf.viz.core.drawables.IDescriptor#getCRS()
|
||||
*/
|
||||
@Override
|
||||
public final CoordinateReferenceSystem getCRS() {
|
||||
if (gridGeometry != null && gridGeometry.getEnvelope() != null) {
|
||||
return gridGeometry.getEnvelope().getCoordinateReferenceSystem();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.uf.viz.core.drawables.IDescriptor#getGridGeometry()
|
||||
*/
|
||||
@Override
|
||||
@XmlElement
|
||||
@XmlJavaTypeAdapter(value = GridGeometryAdapter.class)
|
||||
public final GeneralGridGeometry getGridGeometry() {
|
||||
return gridGeometry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the grid geometry
|
||||
*
|
||||
* @param gridGeometry
|
||||
* the gridGeometry to set
|
||||
* @throws VizException
|
||||
*/
|
||||
public void setGridGeometry(GeneralGridGeometry gridGeometry)
|
||||
throws VizException {
|
||||
this.gridGeometry = gridGeometry;
|
||||
init();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.uf.viz.core.drawables.IDescriptor#pixelToWorld(double[])
|
||||
*/
|
||||
@Override
|
||||
public final double[] pixelToWorld(double[] pixel) {
|
||||
double[] output = new double[3];
|
||||
double[] wpixel = pixel;
|
||||
|
||||
if (pixel.length == 2) {
|
||||
wpixel = new double[] { pixel[0], pixel[1], 0 };
|
||||
}
|
||||
|
||||
if (pixelToWorld != null) {
|
||||
try {
|
||||
pixelToWorld.transform(wpixel, 0, output, 0, 1);
|
||||
} catch (TransformException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
System.arraycopy(wpixel, 0, output, 0, wpixel.length);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.uf.viz.core.drawables.IDescriptor#worldToPixel(double[])
|
||||
*/
|
||||
@Override
|
||||
public final double[] worldToPixel(double[] world) {
|
||||
double[] output = new double[3];
|
||||
double[] input = world;
|
||||
if (world.length == 2) {
|
||||
input = new double[] { world[0], world[1], 0 };
|
||||
}
|
||||
|
||||
if (worldToPixel != null) {
|
||||
try {
|
||||
worldToPixel.transform(input, 0, output, 0, 1);
|
||||
} catch (TransformException e) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
System.arraycopy(input, 0, output, 0, input.length);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
@ -683,4 +826,40 @@ public abstract class AbstractDescriptor extends ResourceGroup implements
|
|||
getFrameCoordinator().changeFrame(loopProperties);
|
||||
}
|
||||
|
||||
protected static GeneralGridGeometry createGridGeometry(IExtent extent,
|
||||
CoordinateReferenceSystem crs) {
|
||||
GeneralEnvelope envelope = new GeneralEnvelope(2);
|
||||
envelope.setRange(0, extent.getMinX(), extent.getMaxX());
|
||||
envelope.setRange(1, extent.getMinY(), extent.getMaxY());
|
||||
envelope.setCoordinateReferenceSystem(crs);
|
||||
return new GridGeometry2D(
|
||||
new GeneralGridEnvelope(new int[] { 0, 0 }, new int[] {
|
||||
(int) extent.getWidth(), (int) extent.getHeight() },
|
||||
false), envelope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world to CRS transform used for {@link #worldToPixel(double[])}
|
||||
* and {@link #pixelToWorld(double[])}
|
||||
*
|
||||
* @param gridGeometry
|
||||
* @return The world to gridGeometry CRS transform or null if there is none
|
||||
*/
|
||||
public static MathTransform getWorldToCRSTransform(
|
||||
GeneralGridGeometry gridGeometry) {
|
||||
CoordinateReferenceSystem crs = gridGeometry.getEnvelope()
|
||||
.getCoordinateReferenceSystem();
|
||||
if (crs instanceof GeneralDerivedCRS) {
|
||||
GeneralDerivedCRS projCRS = (GeneralDerivedCRS) crs;
|
||||
CoordinateReferenceSystem worldCRS = projCRS.getBaseCRS();
|
||||
try {
|
||||
return CRS.findMathTransform(worldCRS, crs);
|
||||
} catch (FactoryException e) {
|
||||
statusHandler.handle(Priority.PROBLEM,
|
||||
"Error setting up Math Transforms,"
|
||||
+ " this descriptor may not work properly", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.geotools.coverage.grid.GeneralGridGeometry;
|
|||
import org.geotools.coverage.grid.GridGeometry2D;
|
||||
|
||||
import com.raytheon.uf.viz.core.IMesh;
|
||||
import com.raytheon.uf.viz.core.drawables.IDescriptor;
|
||||
import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension.IGraphicsExtensionInterface;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
|
||||
|
@ -56,4 +57,18 @@ public interface IMapMeshExtension extends IGraphicsExtensionInterface {
|
|||
public abstract IMesh constructMesh(GridGeometry2D imageGeometry,
|
||||
GeneralGridGeometry targetGeometry) throws VizException;
|
||||
|
||||
/**
|
||||
* Convenient method for constructing a mesh for mapping the imageGeometry
|
||||
* onto the targetDescriptor. Same as calling
|
||||
* {@link #constructMesh(GridGeometry2D, GeneralGridGeometry)} passing in
|
||||
* target.getGridGeometry()
|
||||
*
|
||||
* @param imageGeometry
|
||||
* @param targetDescriptor
|
||||
* @return
|
||||
* @throws VizException
|
||||
*/
|
||||
public abstract IMesh constructMesh(GridGeometry2D imageGeometry,
|
||||
IDescriptor targetDescriptor) throws VizException;
|
||||
|
||||
}
|
||||
|
|
|
@ -26,9 +26,7 @@ import java.util.ArrayList;
|
|||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.geotools.coverage.grid.GeneralGridEnvelope;
|
||||
|
@ -36,23 +34,16 @@ import org.geotools.coverage.grid.GeneralGridGeometry;
|
|||
import org.geotools.coverage.grid.GridGeometry2D;
|
||||
import org.geotools.geometry.DirectPosition2D;
|
||||
import org.geotools.geometry.GeneralEnvelope;
|
||||
import org.geotools.referencing.CRS;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import org.geotools.referencing.crs.DefaultGeocentricCRS;
|
||||
import org.geotools.referencing.crs.DefaultGeographicCRS;
|
||||
import org.geotools.referencing.operation.DefaultMathTransformFactory;
|
||||
import org.opengis.geometry.DirectPosition;
|
||||
import org.opengis.referencing.FactoryException;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
import org.opengis.referencing.datum.PixelInCell;
|
||||
import org.opengis.referencing.operation.MathTransform;
|
||||
import org.opengis.referencing.operation.MathTransformFactory;
|
||||
import org.opengis.referencing.operation.TransformException;
|
||||
|
||||
import com.raytheon.uf.common.geospatial.CRSCache;
|
||||
import com.raytheon.uf.common.geospatial.MapUtil;
|
||||
import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||
import com.raytheon.uf.common.serialization.adapters.GridGeometryAdapter;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
|
@ -196,24 +187,12 @@ public class MapDescriptor extends AbstractDescriptor implements
|
|||
return gridGeom;
|
||||
}
|
||||
|
||||
/** The transform from lat/lon to the current CRS */
|
||||
protected MathTransform coordinateTransform;
|
||||
|
||||
/** The transform from the current CRS to lat/lon */
|
||||
protected MathTransform inverseCoordinateTransform;
|
||||
|
||||
/** The mapping from grid to coordinate */
|
||||
protected MathTransform mapToCoordinateTransform;
|
||||
|
||||
/** The mapping from coordinate to grid */
|
||||
protected MathTransform coordinateToMapTransform;
|
||||
|
||||
/** The mapping from wgs84 to grid */
|
||||
protected MathTransform wgsToGridTransform;
|
||||
|
||||
/** The mapping from grid to wgs84 */
|
||||
protected MathTransform gridToWGSTransform;
|
||||
|
||||
/** The time in ms that the last blink state was used */
|
||||
protected long timeLastBlink;
|
||||
|
||||
|
@ -229,9 +208,6 @@ public class MapDescriptor extends AbstractDescriptor implements
|
|||
*/
|
||||
protected int mapWidth;
|
||||
|
||||
/** The geospatial descriptor for the grid */
|
||||
protected GeneralGridGeometry gridGeometry;
|
||||
|
||||
/** elevation exaggeration */
|
||||
protected double elevationExageration = 0;
|
||||
|
||||
|
@ -242,8 +218,6 @@ public class MapDescriptor extends AbstractDescriptor implements
|
|||
LAT_LON_FORMATTER.setMaximumFractionDigits(2);
|
||||
}
|
||||
|
||||
private String cloudSourceName;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
@ -274,49 +248,26 @@ public class MapDescriptor extends AbstractDescriptor implements
|
|||
*
|
||||
*/
|
||||
public MapDescriptor(GeneralGridGeometry gridGeometry) throws VizException {
|
||||
super();
|
||||
|
||||
this.gridGeometry = gridGeometry;
|
||||
super(gridGeometry);
|
||||
init();
|
||||
}
|
||||
|
||||
protected void init() throws VizException {
|
||||
MathTransformFactory mtf = new DefaultMathTransformFactory();
|
||||
|
||||
try {
|
||||
|
||||
mapToCoordinateTransform = this.gridGeometry
|
||||
GeneralGridGeometry gridGeometry = getGridGeometry();
|
||||
mapToCoordinateTransform = gridGeometry
|
||||
.getGridToCRS(PixelInCell.CELL_CENTER);
|
||||
coordinateToMapTransform = mapToCoordinateTransform.inverse();
|
||||
CoordinateReferenceSystem descriptorCRS = this.gridGeometry
|
||||
.getCoordinateReferenceSystem();
|
||||
if (descriptorCRS.toWKT().equals(
|
||||
DefaultGeocentricCRS.CARTESIAN.toWKT())) {
|
||||
inverseCoordinateTransform = CRS.findMathTransform(
|
||||
descriptorCRS, DefaultGeographicCRS.WGS84_3D);
|
||||
|
||||
coordinateTransform = inverseCoordinateTransform.inverse();
|
||||
|
||||
} else {
|
||||
inverseCoordinateTransform = CRSCache.getInstance()
|
||||
.getTransformToLatLon(descriptorCRS);
|
||||
coordinateTransform = inverseCoordinateTransform.inverse();
|
||||
}
|
||||
|
||||
wgsToGridTransform = mtf.createConcatenatedTransform(
|
||||
coordinateTransform, coordinateToMapTransform);
|
||||
gridToWGSTransform = mtf.createConcatenatedTransform(
|
||||
mapToCoordinateTransform, inverseCoordinateTransform);
|
||||
|
||||
CoordinateReferenceSystem crs = this.gridGeometry
|
||||
CoordinateReferenceSystem crs = gridGeometry
|
||||
.getCoordinateReferenceSystem();
|
||||
|
||||
DirectPosition s1, d1, s2, d2;
|
||||
if (crs.getCoordinateSystem().getDimension() == 2) {
|
||||
double centerX = (this.gridGeometry.getGridRange().getLow(0) + this.gridGeometry
|
||||
double centerX = (gridGeometry.getGridRange().getLow(0) + gridGeometry
|
||||
.getGridRange().getHigh(0)) / 2;
|
||||
|
||||
double centerY = (this.gridGeometry.getGridRange().getLow(1) + this.gridGeometry
|
||||
double centerY = (gridGeometry.getGridRange().getLow(1) + gridGeometry
|
||||
.getGridRange().getHigh(1)) / 2;
|
||||
|
||||
s1 = new DirectPosition2D(centerX, centerY);
|
||||
|
@ -367,43 +318,6 @@ public class MapDescriptor extends AbstractDescriptor implements
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.uf.viz.core.drawables.IDescriptor#pixelToWorld(double[])
|
||||
*/
|
||||
@Override
|
||||
public double[] pixelToWorld(final double[] pixel) {
|
||||
// if (pixel[0] < 1.0)
|
||||
// pixel[0] = 1;
|
||||
//
|
||||
// if (pixel[0] > theWorldWidth - 1.0)
|
||||
// pixel[0] = theWorldWidth - 1.0;
|
||||
//
|
||||
// if (pixel[1] < 1.0)
|
||||
// pixel[1] = 1;
|
||||
//
|
||||
// if (pixel[1] > theWorldHeight - 1.0)
|
||||
// pixel[1] = theWorldHeight;
|
||||
|
||||
double[] output = new double[3];
|
||||
double[] wpixel = pixel;
|
||||
|
||||
if (pixel.length == 2) {
|
||||
wpixel = new double[] { pixel[0], pixel[1], 0 };
|
||||
}
|
||||
|
||||
try {
|
||||
gridToWGSTransform.transform(wpixel, 0, output, 0, 1);
|
||||
} catch (TransformException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
@ -417,7 +331,7 @@ public class MapDescriptor extends AbstractDescriptor implements
|
|||
if (crs == MapUtil.LATLON_PROJECTION) {
|
||||
return pixelToWorld(pixel);
|
||||
} else if (!crs.getName().equals(
|
||||
this.gridGeometry.getCoordinateReferenceSystem().getName())) {
|
||||
getGridGeometry().getCoordinateReferenceSystem().getName())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -431,33 +345,6 @@ public class MapDescriptor extends AbstractDescriptor implements
|
|||
return output2;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.uf.viz.core.drawables.IDescriptor#worldToPixel(double[])
|
||||
*/
|
||||
@Override
|
||||
public double[] worldToPixel(double[] world) {
|
||||
|
||||
double[] output = new double[3];
|
||||
|
||||
double[] input = null;
|
||||
if (world.length == 2) {
|
||||
input = new double[] { world[0], world[1], 0 };
|
||||
} else {
|
||||
input = world;
|
||||
}
|
||||
|
||||
try {
|
||||
wgsToGridTransform.transform(input, 0, output, 0, 1);
|
||||
} catch (TransformException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
@ -466,11 +353,10 @@ public class MapDescriptor extends AbstractDescriptor implements
|
|||
*/
|
||||
@Override
|
||||
public double[] worldToPixel(double[] pixel, CoordinateReferenceSystem crs) {
|
||||
|
||||
if (crs == MapUtil.LATLON_PROJECTION) {
|
||||
return worldToPixel(pixel);
|
||||
} else if (!crs.getName().equals(
|
||||
this.gridGeometry.getCoordinateReferenceSystem().getName())) {
|
||||
getGridGeometry().getCoordinateReferenceSystem().getName())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -618,18 +504,6 @@ public class MapDescriptor extends AbstractDescriptor implements
|
|||
return pc;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.uf.viz.core.map.IMapDescriptor#getMapData()
|
||||
*/
|
||||
@Override
|
||||
@XmlElement
|
||||
@XmlJavaTypeAdapter(value = GridGeometryAdapter.class)
|
||||
public GeneralGridGeometry getGridGeometry() {
|
||||
return this.gridGeometry;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
@ -656,29 +530,10 @@ public class MapDescriptor extends AbstractDescriptor implements
|
|||
@Override
|
||||
public void setGridGeometry(GeneralGridGeometry gridGeometry)
|
||||
throws VizException {
|
||||
this.gridGeometry = gridGeometry;
|
||||
|
||||
super.setGridGeometry(gridGeometry);
|
||||
init();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.uf.viz.core.map.IMapDescriptor#getCRS()
|
||||
*/
|
||||
@Override
|
||||
public CoordinateReferenceSystem getCRS() {
|
||||
if (this.gridGeometry != null) {
|
||||
return this.gridGeometry.getCoordinateReferenceSystem();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public MathTransform getToGridTransform() {
|
||||
return this.wgsToGridTransform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current display width
|
||||
*
|
||||
|
|
|
@ -579,14 +579,14 @@ public class VarHeightResource extends
|
|||
XYWindImageData windData = (XYWindImageData) data;
|
||||
double dir = windData.getWindDir();
|
||||
double speed = windData.getWindSpd();
|
||||
double[] screen = hodoDescriptor.worldToPixel(new double[] {
|
||||
double[] screen = hodoDescriptor.polarToPixel(new double[] {
|
||||
speed, dir });
|
||||
line.addPoint(screen[0], screen[1]);
|
||||
}
|
||||
}
|
||||
if (!line.points.isEmpty()) {
|
||||
double[] screen = hodoDescriptor
|
||||
.worldToPixel(new double[] { 0, 0 });
|
||||
.polarToPixel(new double[] { 0, 0 });
|
||||
line.addPoint(screen[0], screen[1]);
|
||||
|
||||
target.drawLine(line);
|
||||
|
|
|
@ -23,18 +23,10 @@ import java.util.List;
|
|||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import org.geotools.coverage.grid.GeneralGridEnvelope;
|
||||
import org.geotools.coverage.grid.GeneralGridGeometry;
|
||||
import org.geotools.coverage.grid.GridGeometry2D;
|
||||
import org.geotools.geometry.GeneralEnvelope;
|
||||
import org.geotools.referencing.crs.DefaultEngineeringCRS;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||
import com.raytheon.uf.common.serialization.adapters.GridGeometryAdapter;
|
||||
import com.raytheon.uf.viz.core.PixelExtent;
|
||||
import com.raytheon.uf.viz.core.drawables.AbstractDescriptor;
|
||||
import com.raytheon.uf.viz.core.drawables.ResourcePair;
|
||||
|
@ -68,24 +60,12 @@ public class XyGraphDescriptor extends AbstractDescriptor implements
|
|||
|
||||
protected double zoomLevel = 1.0f;
|
||||
|
||||
@XmlElement
|
||||
@XmlJavaTypeAdapter(value = GridGeometryAdapter.class)
|
||||
protected GeneralGridGeometry geometry;
|
||||
|
||||
public XyGraphDescriptor() {
|
||||
this(new PixelExtent(0, 1000, 0, 1000));
|
||||
}
|
||||
|
||||
public XyGraphDescriptor(PixelExtent anExtent) {
|
||||
super();
|
||||
GeneralEnvelope envelope = new GeneralEnvelope(2);
|
||||
envelope.setRange(0, anExtent.getMinX(), anExtent.getMaxX());
|
||||
envelope.setRange(1, anExtent.getMinY(), anExtent.getMaxY());
|
||||
envelope.setCoordinateReferenceSystem(DefaultEngineeringCRS.CARTESIAN_2D);
|
||||
geometry = new GridGeometry2D(new GeneralGridEnvelope(
|
||||
new int[] { 0, 0 }, new int[] { (int) anExtent.getWidth(),
|
||||
(int) anExtent.getHeight() }, false), envelope);
|
||||
getResourceList().addPreRemoveListener(this);
|
||||
super(createGridGeometry(anExtent, DefaultEngineeringCRS.CARTESIAN_2D));
|
||||
}
|
||||
|
||||
public IGraph getGraph(IGraphableResource<?, ?> rsc) {
|
||||
|
@ -96,42 +76,6 @@ public class XyGraphDescriptor extends AbstractDescriptor implements
|
|||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.uf.viz.core.drawables.IDescriptor#getCRS()
|
||||
*/
|
||||
@Override
|
||||
public CoordinateReferenceSystem getCRS() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralGridGeometry getGridGeometry() {
|
||||
return geometry;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.viz.core.drawables.IDescriptor#pixelToWorld(double[])
|
||||
*/
|
||||
@Override
|
||||
public double[] pixelToWorld(double[] pixel) {
|
||||
return pixel;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.viz.core.drawables.IDescriptor#worldToPixel(double[])
|
||||
*/
|
||||
@Override
|
||||
public double[] worldToPixel(double[] worldPixel) {
|
||||
return worldPixel;
|
||||
}
|
||||
|
||||
public GraphResource getGraphResource() {
|
||||
List<GraphResource> rscs = resourceList
|
||||
.getResourcesByTypeAsType(GraphResource.class);
|
||||
|
|
|
@ -112,9 +112,9 @@ public class HodographBackgroundResource extends
|
|||
label.horizontalAlignment = HorizontalAlignment.CENTER;
|
||||
label.textStyle = TextStyle.BLANKED;
|
||||
double[] center = descriptor
|
||||
.worldToPixel(new double[] { 20, direction });
|
||||
.polarToPixel(new double[] { 20, direction });
|
||||
double[] point = descriptor
|
||||
.worldToPixel(new double[] { 400, direction });
|
||||
.polarToPixel(new double[] { 400, direction });
|
||||
LineSegment line = new LineSegment(center[0], center[1], point[0],
|
||||
point[1]);
|
||||
LineSegment bottom = new LineSegment(extent.getMinX(),
|
||||
|
@ -161,14 +161,14 @@ public class HodographBackgroundResource extends
|
|||
DrawableLine circle = new DrawableLine();
|
||||
circle.basics.color = GREY;
|
||||
for (int dir = 0; dir <= 36; dir += 1) {
|
||||
double[] screen = descriptor.worldToPixel(new double[] {
|
||||
double[] screen = descriptor.polarToPixel(new double[] {
|
||||
mag, dir * 10 });
|
||||
circle.addPoint(screen[0], screen[1]);
|
||||
}
|
||||
lineList.add(circle);
|
||||
DrawableString label = new DrawableString(String.valueOf(mag),
|
||||
GREY);
|
||||
double[] screen = descriptor.worldToPixel(new double[] { mag,
|
||||
double[] screen = descriptor.polarToPixel(new double[] { mag,
|
||||
225 });
|
||||
label.setCoordinates(screen[0], screen[1]);
|
||||
label.textStyle = TextStyle.BLANKED;
|
||||
|
@ -176,9 +176,9 @@ public class HodographBackgroundResource extends
|
|||
}
|
||||
// Add the lines
|
||||
for (int dir = 0; dir <= 8; dir += 1) {
|
||||
double[] screen1 = descriptor.worldToPixel(new double[] { 0,
|
||||
double[] screen1 = descriptor.polarToPixel(new double[] { 0,
|
||||
dir * 45 });
|
||||
double[] screen2 = descriptor.worldToPixel(new double[] { 500,
|
||||
double[] screen2 = descriptor.polarToPixel(new double[] { 500,
|
||||
dir * 45 });
|
||||
DrawableLine line = new DrawableLine();
|
||||
line.basics.color = GREY;
|
||||
|
|
|
@ -19,17 +19,9 @@
|
|||
**/
|
||||
package com.raytheon.uf.viz.xy.hodo;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import org.geotools.coverage.grid.GeneralGridEnvelope;
|
||||
import org.geotools.coverage.grid.GeneralGridGeometry;
|
||||
import org.geotools.coverage.grid.GridGeometry2D;
|
||||
import org.geotools.geometry.GeneralEnvelope;
|
||||
import org.geotools.referencing.crs.DefaultEngineeringCRS;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
import com.raytheon.uf.common.serialization.adapters.GridGeometryAdapter;
|
||||
import com.raytheon.uf.viz.core.IExtent;
|
||||
import com.raytheon.uf.viz.core.drawables.AbstractDescriptor;
|
||||
|
||||
|
@ -55,33 +47,14 @@ public class HodographDescriptor extends AbstractDescriptor {
|
|||
// The max distance of the hodograph
|
||||
private static final double MAX_RANGE = 140.0;
|
||||
|
||||
@XmlElement
|
||||
@XmlJavaTypeAdapter(value = GridGeometryAdapter.class)
|
||||
protected GeneralGridGeometry geometry;
|
||||
|
||||
public HodographDescriptor(IExtent anExtent) {
|
||||
super();
|
||||
GeneralEnvelope envelope = new GeneralEnvelope(2);
|
||||
envelope.setRange(0, anExtent.getMinX(), anExtent.getMaxX());
|
||||
envelope.setRange(1, anExtent.getMinY(), anExtent.getMaxY());
|
||||
envelope.setCoordinateReferenceSystem(DefaultEngineeringCRS.CARTESIAN_2D);
|
||||
geometry = new GridGeometry2D(new GeneralGridEnvelope(
|
||||
new int[] { 0, 0 }, new int[] { (int) anExtent.getWidth(),
|
||||
(int) anExtent.getHeight() }, false), envelope);
|
||||
super(createGridGeometry(anExtent, DefaultEngineeringCRS.CARTESIAN_2D));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoordinateReferenceSystem getCRS() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralGridGeometry getGridGeometry() {
|
||||
return geometry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] pixelToWorld(double[] pixel) {
|
||||
// Separate functions for polar transformations until we can get it working
|
||||
// in geotools framework
|
||||
public double[] pixelToPolar(double[] pixel) {
|
||||
GeneralGridGeometry geometry = getGridGeometry();
|
||||
double x = pixel[0];
|
||||
double y = pixel[1];
|
||||
int xRange = geometry.getGridRange().getSpan(0);
|
||||
|
@ -95,8 +68,8 @@ public class HodographDescriptor extends AbstractDescriptor {
|
|||
return new double[] { r, a, 0 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] worldToPixel(double[] world) {
|
||||
public double[] polarToPixel(double[] world) {
|
||||
GeneralGridGeometry geometry = getGridGeometry();
|
||||
double r = world[0];
|
||||
double a = world[1];
|
||||
int xRange = geometry.getGridRange().getSpan(0);
|
||||
|
|
|
@ -495,7 +495,7 @@ public class GLTarget implements IGLTarget {
|
|||
@Override
|
||||
public IWireframeShape createWireframeShape(boolean mutable,
|
||||
IDescriptor descriptor) {
|
||||
return new GLWireframeShape2D(descriptor, mutable);
|
||||
return new GLWireframeShape2D(descriptor.getGridGeometry(), mutable);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -511,7 +511,7 @@ public class GLTarget implements IGLTarget {
|
|||
return new GLWireframeShape(descriptor, mutable,
|
||||
simplificationLevel);
|
||||
} else {
|
||||
return new GLWireframeShape2D(descriptor, mutable);
|
||||
return new GLWireframeShape2D(descriptor.getGridGeometry(), mutable);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -530,7 +530,7 @@ public class GLTarget implements IGLTarget {
|
|||
return new GLWireframeShape(descriptor, null, mutable,
|
||||
simplificationLevel, spatialChopFlag, extent);
|
||||
} else {
|
||||
return new GLWireframeShape2D(descriptor, mutable);
|
||||
return new GLWireframeShape2D(descriptor.getGridGeometry(), mutable);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,17 +28,22 @@ import javax.media.opengl.GL;
|
|||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.geotools.coverage.grid.GeneralGridGeometry;
|
||||
import org.geotools.referencing.operation.DefaultMathTransformFactory;
|
||||
import org.opengis.referencing.operation.MathTransform;
|
||||
import org.opengis.referencing.operation.TransformException;
|
||||
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.viz.core.DrawableString;
|
||||
import com.raytheon.uf.viz.core.IExtent;
|
||||
import com.raytheon.uf.viz.core.IGraphicsTarget.HorizontalAlignment;
|
||||
import com.raytheon.uf.viz.core.IGraphicsTarget.LineStyle;
|
||||
import com.raytheon.uf.viz.core.IGraphicsTarget.VerticalAlignment;
|
||||
import com.raytheon.uf.viz.core.PixelExtent;
|
||||
import com.raytheon.uf.viz.core.drawables.IDescriptor;
|
||||
import com.raytheon.uf.viz.core.drawables.AbstractDescriptor;
|
||||
import com.raytheon.uf.viz.core.drawables.IFont;
|
||||
import com.raytheon.uf.viz.core.drawables.IWireframeShape;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.viz.core.gl.Activator;
|
||||
import com.raytheon.viz.core.gl.GLGeometryObject2D;
|
||||
import com.raytheon.viz.core.gl.GLGeometryObject2D.GLGeometryObjectData;
|
||||
import com.raytheon.viz.core.gl.IGLTarget;
|
||||
|
@ -69,7 +74,7 @@ public class GLWireframeShape2D implements IWireframeShape {
|
|||
/** list of labels to draw */
|
||||
private List<DrawableString> labels;
|
||||
|
||||
private IDescriptor descriptor;
|
||||
private MathTransform worldToTargetGrid;
|
||||
|
||||
private boolean compiled = false;
|
||||
|
||||
|
@ -82,12 +87,22 @@ public class GLWireframeShape2D implements IWireframeShape {
|
|||
GL.GL_VERTEX_ARRAY);
|
||||
geomData.mutable = mutable;
|
||||
geomData.worldExtent = new PixelExtent(gridGeometry.getGridRange());
|
||||
initialize();
|
||||
}
|
||||
|
||||
public GLWireframeShape2D(IDescriptor descriptor, boolean mutable) {
|
||||
this(descriptor.getGridGeometry(), mutable);
|
||||
this.descriptor = descriptor;
|
||||
MathTransform worldToCRS = AbstractDescriptor
|
||||
.getWorldToCRSTransform(gridGeometry);
|
||||
if (worldToCRS != null) {
|
||||
try {
|
||||
MathTransform crsToGrid = gridGeometry.getGridToCRS().inverse();
|
||||
worldToTargetGrid = new DefaultMathTransformFactory()
|
||||
.createConcatenatedTransform(worldToCRS, crsToGrid);
|
||||
} catch (Exception e) {
|
||||
Activator.statusHandler.handle(Priority.PROBLEM,
|
||||
"Error getting transform from base crs to target grid",
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
|
@ -158,16 +173,23 @@ public class GLWireframeShape2D implements IWireframeShape {
|
|||
*/
|
||||
@Override
|
||||
public void addLineSegment(Coordinate[] worldCoords) {
|
||||
if (descriptor == null) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Cannot add coordinate line segment to a wireframe shape that does not have a MapDescriptor.");
|
||||
}
|
||||
|
||||
double screenCoords[][] = new double[worldCoords.length][];
|
||||
for (int i = 0; i < worldCoords.length; ++i) {
|
||||
Coordinate c = worldCoords[i];
|
||||
screenCoords[i] = descriptor
|
||||
.worldToPixel(new double[] { c.x, c.y });
|
||||
if (worldToTargetGrid != null) {
|
||||
try {
|
||||
double[] out = new double[2];
|
||||
worldToTargetGrid.transform(new double[] { c.x, c.y }, 0,
|
||||
out, 0, 1);
|
||||
screenCoords[i] = out;
|
||||
} catch (TransformException e) {
|
||||
// Ignore...
|
||||
}
|
||||
} else {
|
||||
// Assume no conversion needed
|
||||
screenCoords[i] = new double[] { c.x, c.y };
|
||||
}
|
||||
|
||||
}
|
||||
addLineSegment(screenCoords);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.geotools.coverage.grid.GeneralGridGeometry;
|
|||
import org.geotools.coverage.grid.GridGeometry2D;
|
||||
|
||||
import com.raytheon.uf.viz.core.IMesh;
|
||||
import com.raytheon.uf.viz.core.drawables.IDescriptor;
|
||||
import com.raytheon.uf.viz.core.drawables.ext.GraphicsExtension;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.uf.viz.core.map.IMapMeshExtension;
|
||||
|
@ -63,6 +64,20 @@ public class GLMapMeshExtension extends GraphicsExtension<IGLTarget> implements
|
|||
return new GLMesh2DStrips(imageGeometry, targetGeometry);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.raytheon.uf.viz.core.map.IMapMeshExtension#constructMesh(org.geotools
|
||||
* .coverage.grid.GridGeometry2D,
|
||||
* com.raytheon.uf.viz.core.drawables.IDescriptor)
|
||||
*/
|
||||
@Override
|
||||
public IMesh constructMesh(GridGeometry2D imageGeometry,
|
||||
IDescriptor targetDescriptor) throws VizException {
|
||||
return constructMesh(imageGeometry, targetDescriptor.getGridGeometry());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
|
|
@ -24,16 +24,10 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
|||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import org.geotools.coverage.grid.GeneralGridEnvelope;
|
||||
import org.geotools.coverage.grid.GeneralGridGeometry;
|
||||
import org.geotools.coverage.grid.GridGeometry2D;
|
||||
import org.geotools.geometry.GeneralEnvelope;
|
||||
import org.geotools.referencing.crs.DefaultEngineeringCRS;
|
||||
import org.opengis.referencing.crs.CoordinateReferenceSystem;
|
||||
|
||||
import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||
import com.raytheon.uf.common.serialization.adapters.CoordAdapter;
|
||||
import com.raytheon.uf.common.serialization.adapters.GridGeometryAdapter;
|
||||
import com.raytheon.uf.viz.core.PixelExtent;
|
||||
import com.raytheon.uf.viz.core.drawables.AbstractDescriptor;
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
|
@ -65,34 +59,12 @@ public class GraphDescriptor extends AbstractDescriptor implements
|
|||
|
||||
protected int verticalFrameCount = 0;
|
||||
|
||||
@XmlElement
|
||||
@XmlJavaTypeAdapter(value = GridGeometryAdapter.class)
|
||||
protected GeneralGridGeometry geometry;
|
||||
|
||||
public GraphDescriptor() {
|
||||
this(new PixelExtent(0, 1000, 0, 1000));
|
||||
}
|
||||
|
||||
public GraphDescriptor(PixelExtent anExtent) {
|
||||
super();
|
||||
GeneralEnvelope envelope = new GeneralEnvelope(2);
|
||||
envelope.setRange(0, anExtent.getMinX(), anExtent.getMaxX());
|
||||
envelope.setRange(1, anExtent.getMinY(), anExtent.getMaxY());
|
||||
envelope.setCoordinateReferenceSystem(DefaultEngineeringCRS.CARTESIAN_2D);
|
||||
geometry = new GridGeometry2D(new GeneralGridEnvelope(
|
||||
new int[] { 0, 0 }, new int[] { (int) anExtent.getWidth(),
|
||||
(int) anExtent.getHeight() }, false), envelope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoordinateReferenceSystem getCRS() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralGridGeometry getGridGeometry() {
|
||||
return geometry;
|
||||
super(createGridGeometry(anExtent, DefaultEngineeringCRS.CARTESIAN_2D));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,24 +82,4 @@ public class GraphDescriptor extends AbstractDescriptor implements
|
|||
this.location = location;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.viz.core.drawables.IDescriptor#pixelToWorld(double[])
|
||||
*/
|
||||
@Override
|
||||
public double[] pixelToWorld(double[] pixel) {
|
||||
return pixel;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.raytheon.viz.core.drawables.IDescriptor#worldToPixel(double[])
|
||||
*/
|
||||
@Override
|
||||
public double[] worldToPixel(double[] worldPixel) {
|
||||
return worldPixel;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue