* "Outer Space" values.
*
*/
protected OMRaster buildRaster() {
// initialize the return
OMRaster ret = null;
Projection projection = getProjection();
// work with the slopeMap
if (slopeMap != null) {
// compute our deltas
int pixelColumns = projection.getWidth();
int pixelRows = projection.getHeight();
// create int array to hold colors
int[] colors = new int[pixelColumns * pixelRows];
// compute scalers for lat/lon indicies
float yPixPerDataPt = (float) bufferHeight / 180F;
float xPixPerDataPt = (float) bufferWidth / 360F;
// starting and ending indices
int sx = 0, sy = 0, ex = pixelColumns, ey = pixelRows;
// handle CADRG
if (projection instanceof CADRG) {
// get corners
LatLonPoint ul = projection.getUpperLeft();
LatLonPoint lr = projection.getLowerRight();
// set start/end indicies
Point ulp = projection.forward(ul);
Point lrp = projection.forward(lr);
sx = (int) ulp.getX();
ex = (int) lrp.getX();
sy = (int) ulp.getY();
ey = (int) lrp.getY();
}
// get the center lat/lon (used by the HACK, see above in
// method description)
LatLonPoint center = projection.getCenter();
LatLonPoint llp = new LatLonPoint();
// build array
float lat;
float lon;
int lat_idx;
int lon_idx;
float latWt;
float lonWt;
// offset
int ofs;
int ofsRight;
int ofsDown;
int ofsDownRight;
for (int y = sy; y < ey; y++) {
// process each column
for (int x = sx; x < ex; x++) {
// inverse project x,y to lon,lat
projection.inverse(x, y, llp);
// get point values
lat = llp.getLatitude();
lon = llp.getLongitude();
// check
if (lon < 0.) {
lon += 360.;
}
// find indicies
lat_idx = (int) ((90. - lat) * yPixPerDataPt);
lon_idx = (int) (lon * xPixPerDataPt);
// most pixels fall between data points. The data
// point originally used is the one immediately
// above and to the left of the pixel. The amount
// by which the pixel is offset from the data
// point can be used to weight the elevation
// contribution of the four data points
// surrounding the pixel ie. the weights. The
// truncated decimal part of the index computation
// is the weight.
latWt = ((90f - lat) * yPixPerDataPt) - (float) lat_idx;
lonWt = (lon * xPixPerDataPt) - (float) lon_idx;
// offsets of the four surrounding data points.
ofs = lon_idx + lat_idx * bufferWidth;
ofsRight = ofs + 1;
if (lat_idx+1 < bufferHeight) {
ofsDown = lon_idx + (1 + lat_idx) * bufferWidth;
} else {
ofsDown = ofs;
}
ofsDownRight = ofsDown + 1;
// make a color
int idx = 0;
int gray = 0;
short el = 0;
byte sl = 0;
try {
try {
float ulwt = (1f - lonWt + 1f - latWt);
float urwt = (lonWt + 1f - latWt);
float llwt = (1f - lonWt + latWt);
float lrwt = (lonWt + latWt);
// get elevation
el =
(short) ((float) dataBuffer[ofs] * ulwt
+ (float) dataBuffer[ofsRight] * urwt
+ (float) dataBuffer[ofsDown] * llwt
+ (float) dataBuffer[ofsDownRight] * lrwt);
// slope
sl =
(byte) ((float) slopeMap[ofs] * ulwt
+ (float) slopeMap[ofsRight] * urwt
+ (float) slopeMap[ofsDown] * llwt
+ (float) slopeMap[ofsDownRight] * lrwt);
float exagFactor = 1f/ (el > 0?1.5f:3f);
el = (short)((float)el * exagFactor);
sl = (byte)((float)sl * exagFactor);
// bad index
} catch (ArrayIndexOutOfBoundsException e) {
Debug.error(e.toString() + ":" +
ofs + " limit=" +
dataBuffer.length);
}
// our index
idx = y * pixelColumns + x;
// create a color
Color pix = null;
if (viewType == SLOPESHADING) {
// HACK (see method description above)
if ((llp.getLatitude() == center.getLatitude())
&& (llp.getLongitude() == center.getLongitude()))
gray = 0;
else
gray = 127 + sl;
pix = new Color(gray, gray, gray, opaqueness);
} else if (viewType == COLOREDSHADING) {
// HACK (see method description above)
if ((llp.getLatitude() == center.getLatitude())
&& (llp.getLongitude() == center.getLongitude()))
pix = new Color(0, 0, 0, opaqueness);
else
pix = getColor(el, sl);
}
// set
colors[idx] = pix.getRGB();
}
// tried to set a bad color level
catch (IllegalArgumentException e) {
Debug.error(e.toString() + ":" + gray);
}
// bad index
catch (ArrayIndexOutOfBoundsException e) {
Debug.error(e.toString() + ":" + idx);
}
}
}
// create the raster
ret = new OMRaster(0, 0, pixelColumns, pixelRows, colors);
}
// return or raster
return ret;