Issue #704 fixes to random resources and optimization of radar projection transforms

Former-commit-id: 7619165ce45efe9dbad045adfaaf978acee782be
This commit is contained in:
Ben Steffensmeier 2012-06-20 18:07:17 -05:00
parent d317777ee6
commit 601d46661c
4 changed files with 60 additions and 54 deletions

View file

@ -32,8 +32,6 @@ import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.rsc.AbstractRequestableResourceData;
import com.raytheon.uf.viz.core.rsc.AbstractVizResource;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.viz.core.status.StatusConstants;
import com.raytheon.uf.viz.ncwf.Activator;
/**
* The ResourceData for Ncwf resources
@ -52,11 +50,12 @@ import com.raytheon.uf.viz.ncwf.Activator;
*/
@XmlAccessorType(XmlAccessType.NONE)
public class NcwfPolygonResourceData extends AbstractRequestableResourceData {
private static final transient IUFStatusHandler statusHandler = UFStatus.getHandler(NcwfPolygonResourceData.class);
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(NcwfPolygonResourceData.class);
@XmlAttribute
private String name;
@Override
public boolean equals(Object obj) {
if (!super.equals(obj)) {
@ -65,13 +64,13 @@ public class NcwfPolygonResourceData extends AbstractRequestableResourceData {
if (obj instanceof NcwfPolygonResourceData == false) {
return false;
}
NcwfPolygonResourceData other = (NcwfPolygonResourceData) obj;
if (other.name.equals(name)) {
if (!other.name.equals(name)) {
return false;
}
return true;
}
@ -100,7 +99,5 @@ public class NcwfPolygonResourceData extends AbstractRequestableResourceData {
public void setName(String name) {
this.name = name;
}
}

View file

@ -43,6 +43,7 @@ import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.datastorage.records.ByteDataRecord;
import com.raytheon.uf.common.geospatial.MapUtil;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.viz.core.DrawableString;
import com.raytheon.uf.viz.core.IExtent;
import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.IGraphicsTarget.HorizontalAlignment;
@ -556,26 +557,18 @@ public class RedbookFrame implements IRenderable {
if (!symbols) {
IFont font = redbookResource.getRenderingFont();
Rectangle2D bounds = target.getStringBounds(font, s);
DrawableString dstring = new DrawableString(s, this.redbookResource
.getCapability(ColorableCapability.class).getColor());
dstring.setCoordinates(x, y);
dstring.font = font;
dstring.horizontalAlignment = HorizontalAlignment.LEFT;
dstring.verticallAlignment = top ? VerticalAlignment.TOP
: VerticalAlignment.BOTTOM;
Rectangle2D bounds = target.getStringsBounds(dstring);
if (blanked) {
double yext = y + bounds.getHeight() * yRatio * (top ? 1 : -1);
PixelExtent pe = new PixelExtent(x, x + bounds.getWidth()
* xRatio, Math.min(y, yext) + yRatio, Math.max(y, yext)
+ yRatio);
target.drawShadedRect(pe, new RGB(0, 0, 0),
paintProps.getAlpha(), null);
dstring.textStyle = TextStyle.BLANKED;
}
target.drawString(
font,
s,
x,
y,
0.0,
TextStyle.NORMAL,
this.redbookResource.getCapability(
ColorableCapability.class).getColor(),
HorizontalAlignment.LEFT, top ? VerticalAlignment.TOP
: VerticalAlignment.BOTTOM, null);
target.drawStrings(dstring);
return bounds.getWidth() * xRatio;
} else {
double width = s.length() * 12 * xRatio * magnification;

View file

@ -78,25 +78,17 @@ public class AzimuthRangeMapProjection extends ObliqueStereographic {
return super.inverseTransformNormalized(x, y, dest);
}
protected double normalizeAngle(double rangeLow, double rangeHigh,
double angle) {
while (angle < rangeLow) {
angle += 360;
}
while (angle > rangeHigh) {
angle -= 360;
}
return angle;
}
@Override
protected Point2D transformNormalized(double lon, double lat, Point2D dest)
throws ProjectionException {
Point2D tmp = new Point2D.Double();
super.transformNormalized(lon, lat, tmp);
double azimuth = Math.toDegrees(Math.atan2(tmp.getX(), tmp.getY()));
double range = scaleFactor * semiMajor
* Math.hypot(tmp.getX(), tmp.getY());
double x = tmp.getX();
double y = tmp.getY();
double azimuth = Math.toDegrees(Math.atan2(x, y));
// Math.hypot is more accurate than the sqrt approach but much much
// slower.
double range = scaleFactor * semiMajor * Math.sqrt(x * x + y * y);
if (dest != null) {
dest.setLocation(azimuth, range);
return dest;

View file

@ -106,24 +106,48 @@ public class RadialBinMapProjection extends AzimuthRangeMapProjection {
@Override
protected Point2D transformNormalized(double lon, double lat, Point2D dest)
throws ProjectionException {
if (dest == null) {
dest = new Point2D.Double();
}
Point2D tmp = new Point2D.Double();
tmp = super.transformNormalized(lon, lat, tmp);
double az = tmp.getX();
double ran = tmp.getY();
// System.out.println(ran);
double radial = Double.NaN;
double bin = ran / flatBinLength;
float nextAngle = normalAngleData[0] + 360;
az = normalizeAngle(normalAngleData[0], nextAngle, az);
for (int i = normalAngleData.length - 1; i >= 0; i -= 1) {
float prevAngle = normalAngleData[i];
if (prevAngle <= az && nextAngle > az) {
radial = (i) + (az - prevAngle) / (nextAngle - prevAngle);
break;
}
prevAngle = nextAngle;
float firstAngle = normalAngleData[0];
float lastAngle = normalAngleData[normalAngleData.length - 1];
// normalize the range for az
while (az < firstAngle) {
az += 360;
}
while (az > firstAngle + 360) {
az -= 360;
}
if (az >= lastAngle) {
// special case of az is not between two normalizedAngles
double radial = normalAngleData.length - 1 + (az - lastAngle)
/ (firstAngle + 360 - lastAngle);
dest.setLocation(radial, bin);
} else {
// start off with a guess for the index
int index = (int) ((az - firstAngle) * (normalAngleData.length - 1) / (lastAngle - firstAngle));
// increase index if we guessed to low
float nextAngle = normalAngleData[index];
while (nextAngle <= az) {
index += 1;
nextAngle = normalAngleData[index];
}
index -= 1;
// decrease index if we guessed to high.
float prevAngle = normalAngleData[index];
while (prevAngle > az) {
nextAngle = prevAngle;
prevAngle = normalAngleData[--index];
}
// interpolate a result.
double radial = index + (az - prevAngle) / (nextAngle - prevAngle);
dest.setLocation(radial, bin);
}
dest.setLocation(radial, bin);
return dest;
}