📄 dtedframe.java
字号:
} int[] ret = new int[4]; float ullat_index = (upper - dsi.sw_lat) * 36000F / uhl.lat_post_interval; float ullon_index = (left - dsi.sw_lon) * 36000F / uhl.lon_post_interval; float lrlat_index = (lower - dsi.sw_lat) * 36000F / uhl.lat_post_interval; float lrlon_index = (right - dsi.sw_lon) * 36000F / uhl.lon_post_interval; ret[0] = (int) Math.round(ullon_index); ret[1] = (int) Math.round(lrlat_index); ret[2] = (int) Math.round(lrlon_index); ret[3] = (int) Math.round(ullat_index); if (ret[0] < 0) ret[0] = 0; if (ret[0] > uhl.num_lon_lines - 2) ret[0] = uhl.num_lon_lines - 2; if (ret[1] < 0) ret[1] = 0; if (ret[1] > uhl.num_lat_points - 2) ret[1] = uhl.num_lat_points - 2; if (ret[2] < 0) ret[2] = 0; if (ret[2] > uhl.num_lon_lines - 2) ret[2] = uhl.num_lon_lines - 2; if (ret[3] < 0) ret[3] = 0; if (ret[3] > uhl.num_lat_points - 2) ret[3] = uhl.num_lat_points - 2; return ret; } /** * Return a two dimensional array of posts between lat lons. * * @param ullat upper latitude in decimal degrees. * @param ullon left longitude in decimal degrees. * @param lrlat lower latitude in decimal degrees. * @param lrlon right longitude in decimal degrees. * @return array of elevations in meters. The spacing of the posts * depends on the DTED level. */ public short[][] getElevations(float ullat, float ullon, float lrlat, float lrlon) { int[] indexes = getIndexesFromLatLons(ullat, ullon, lrlat, lrlon); return getElevations(indexes[0], indexes[1], indexes[2], indexes[3]); } /** * Return a two dimensional array of posts between lat lons. * Assumes that the indexes are checked to not exceed their bounds * as defined in the file. getIndexesFromLatLons() checks this. * * @param startx starting index (left) of the greater matrix to * make the left side of the returned matrix. * @param starty starting index (lower) of the greater matrix to * make the bottom side of the returned matrix. * @param endx ending index (right) of the greater matrix to make * the left side of the returned matrix. * @param endy ending index (top) of the greater matrix to make * the top side of the returned matrix. * @return array of elevations in meters. The spacing of the posts * depends on the DTED level. */ public short[][] getElevations(int startx, int starty, int endx, int endy) { int upper = endy; int lower = starty; int right = endx; int left = startx; // Since matrix indexes depend on these being in the right // order, we'll double check and flip values, just to make // sure lower is lower, and higher is higher. if (startx > endx) { right = startx; left = endx; } if (starty > endy) { upper = starty; lower = endy; } short[][] matrix = new short[right - left + 1][upper - lower + 1]; int matrixColumn = 0; for (int x = left; x <= right; x++) { if (elevations[x] == null) read_data_record(x); System.arraycopy(elevations[x], lower, matrix[matrixColumn], 0, (upper - lower + 1)); matrixColumn++; } return matrix; } ////////////////// // Internal methods ////////////////// /** * A try at interoplating the corners of the surrounding posts, * given a lat lon. Called from a function where the data for the * lon has been read in. */ private float resolve_four_points(int ul, int ur, int lr, int ll, float lat_index, float lon_index) { float top_avg = ((lon_index - new Double(Math.floor(lon_index)).floatValue()) * (float) (ur - ul)) + ul; float bottom_avg = ((lon_index - new Double(Math.floor(lon_index)).floatValue()) * (float) (lr - ll)) + ll; float right_avg = ((lat_index - new Double(Math.floor(lat_index)).floatValue()) * (float) (ur - lr)) + lr; float left_avg = ((lat_index - new Double(Math.floor(lat_index)).floatValue()) * (float) (ul - ll)) / 100.0F + ll; float lon_avg = ((lat_index - new Double(Math.floor(lat_index)).floatValue()) * (top_avg - bottom_avg)) + bottom_avg; float lat_avg = ((lon_index - new Double(Math.floor(lon_index)).floatValue()) * (right_avg - left_avg)) + left_avg; float result = (lon_avg + lat_avg) / 2.0F; return result; } /** * Reads one longitude line of posts. Assumes that the binFile is * valid. * * @return true if the column of data was successfully read */ protected boolean read_data_record(int lon_index) { try { if (binFile == null) if (!reopen()) return false; // Set to beginning of file section, then skip to index // data // 12 = 1+3+2+2+4 = counts and checksum // 2*uhl....size of elevation post space binFile.seek(UHL_SIZE + DSI_SIZE + ACC_SIZE + (lon_index * (12 + (2 * uhl.num_lat_points)))); /*int sent = */binFile.read(); binFile.skipBytes(3); // 3 byte data_block_count /*short lon_count = */binFile.readShort(); /*short lat_count = */binFile.readShort(); // Allocate the rows of the row elevations[lon_index] = new short[uhl.num_lat_points]; for (int j = 0; j < uhl.num_lat_points; j++) elevations[lon_index][j] = binFile.readShort(); } catch (IOException e3) { Debug.error("DTEDFrame.RDR: Error reading file."); e3.printStackTrace(); elevations[lon_index] = null; return false; } catch (FormatException f) { Debug.error("DTEDFrame.RDR: File IO Format error!"); elevations[lon_index] = null; return false; } return true; } /** * Read all the elevation posts, at one time. Assumes that the * file is open and ready. * * @return true if the elevation columns were read. */ protected boolean read_data_records() { boolean ret = true; for (int lon_index = 0; lon_index < uhl.num_lon_lines; lon_index++) { if (read_data_record(lon_index) == false) ret = false; } return ret; } /** * Sets the subframe array. Blows away any images that may already * be there. */ public void initSubframes(int numHorizSubframes, int numVertSubframes) { number_horiz_subframes = numHorizSubframes; number_vert_subframes = numVertSubframes; subframes = new DTEDFrameSubframe[numHorizSubframes][numVertSubframes]; if (Debug.debugging("dted")) { Debug.output("///////// DTEDFrame: subframe array initialized, " + numHorizSubframes + "x" + numVertSubframes); } } /** * If you just want to get an image for the DTEDFrame, then call * this. One OMRaster for the entire DTEDFrame will be returned, * with the default rendering parameters (Colored shading) and the * default colortable. Use the other getOMRaster method if you * want something different. This method actually calls that other * method, so read the documentation for that as well. * * @param proj EqualArc projection to use to create image. * @return raster image to display in OpenMap. */ public OMRaster getOMRaster(EqualArc proj) { return getOMRaster(null, null, proj); } /** * If you just want to get an image for the DTEDFrame, then call * this. One OMRaster for the entire DTEDFrame will be returned. * In the DTEDFrameSubframeInfo, you need to set the color type * and all the parameters that are assiociated with the rendering * parameters. The projection parameters of the DFSI (image * height, width, pixel intervals) will be set in this method * based on the projection. If you want a different sized image, * scale the thing you get back from this method, or change the * scale of the projection that is passed in. Calling this method * will cause the DTEDFrame subframe cache to reset itself to hold * one subframe covering the entire frame. Just so you know. * * @param dfsi the DTEDFrameSubframeInfo describing the subframe. * @param colortable the colortable to use when building the * image. * @return raster image to display in OpenMap. * @param proj EqualArc projection to use to create image. */ public OMRaster getOMRaster(DTEDFrameSubframeInfo dfsi, DTEDFrameColorTable colortable, EqualArc proj) { if (proj == null) { Debug.error("DTEDFrame.getOMRaster: need projection to create image."); return null; } if (colortable == null) { colortable = new DTEDFrameColorTable(); } if (dfsi == null) { dfsi = new DTEDFrameSubframeInfo(DTEDFrameSubframe.COLOREDSHADING, DTEDFrameSubframe.DEFAULT_BANDHEIGHT, DTEDFrameSubframe.LEVEL_1, // Doesn't // matter DTEDFrameSubframe.DEFAULT_SLOPE_ADJUST); } dfsi.xPixInterval = 360 / proj.getXPixConstant(); //degrees/pixel dfsi.yPixInterval = 90 / proj.getYPixConstant(); dfsi.height = (int) (1 / dfsi.yPixInterval); dfsi.width = (int) (1 / dfsi.xPixInterval); // Will trigger the right thing in getSubframeOMRaster; subframes = null; return getSubframeOMRaster(dfsi, colortable); } /** * Return the subframe image as described in the * DTEDFrameSubframeInfo. This is called by the DTEDCacheHandler, * which has in turn set the DTEDFrameSubframeInfo parameters to * match the projection parameters. This turns out to be kinda * important. * * @param dfsi the DTEDFrameSubframeInfo describing the subframe. * @param colortable the colortable to use when building the * image. * @return raster image to display in OpenMap. */ public OMRaster getSubframeOMRaster(DTEDFrameSubframeInfo dfsi, DTEDFrameColorTable colortable) { if (!frame_is_valid) return null; OMRaster raster = null; if (dfsi.viewType == DTEDFrameSubframe.NOSHADING) return null; if (dfsi.viewType == DTEDFrameSubframe.COLOREDSHADING) colortable.setGreyScale(false); else colortable.setGreyScale(true); float lat_origin = dfsi.lat; float lon_origin = dfsi.lon; if (subframes == null) { // Need to set a couple of things up if the DTEDFrameCache // isn't being used to set up the subframe information in // the dfsi. initSubframes(1, 1); // NOTE!! The algorithm uses the cordinates of the top // left corner as a reference!!!!!!!! lat_origin = dsi.lat_origin + 1; lon_origin = dsi.lon_origin; } DTEDFrameSubframe subframe = subframes[dfsi.subx][dfsi.suby]; if (Debug.debugging("dteddetail")) { Debug.output("Subframe lat/lon => lat= " + lat_origin + " vs. " + dfsi.lat + " lon= " + lon_origin + " vs. " + dfsi.lon + " subx = " + dfsi.subx + " suby = " + dfsi.suby); Debug.output("Height/width of subframe => height= " + dfsi.height + " width= " + dfsi.width); } if (subframe != null) { // The subframe section will not be null, because it is // created when the subframe is. if (subframe.image != null && subframe.si.equals(dfsi)) { // IF there is an image in the cache and the drawing // parameters are correct raster = subframe.image; if (Debug.debugging("dted")) Debug.output("######## DTEDFrame: returning cached subframe"); return raster; } if (Debug.debugging("dted")) { Debug.output(" *** DTEDFrame: changing image of cached subframe"); } if (subframe.image == null) { if (Debug.debugging("dted")) { Debug.output(" +++ DTEDFrame: creating subframe image"); } if (dfsi.colorModel == OMRasterObject.COLORMODEL_DIRECT) subframe.image = new OMRaster(lat_origin, lon_origin, dfsi.width, dfsi.height, new int[dfsi.height * dfsi.width]); else subframe.image = new OMRaster(lat_origin, lon_origin, dfsi.width, dfsi.height, null, colortable.colors, 255); } // If there is an image, the types are different and it // needs to be // redrawn subframe.si = dfsi.makeClone(); } else { if (Debug.debugging("dted")) { Debug.output(" +++ DTEDFrame: creating subframe"); } subframes[dfsi.subx][dfsi.suby] = new DTEDFrameSubframe(dfsi); subframe = subframes[dfsi.subx][dfsi.suby]; if (dfsi.colorModel == OMRasterObject.COLORMODEL_DIRECT) { subframe.image = new OMRaster(lat_origin, lon_origin, dfsi.width, dfsi.height, new int[dfsi.height * dfsi.width]); } else { subframe.image = new OMRaster(lat_origin, lon_origin, dfsi.width, dfsi.height, null, colortable.colors, 255); } } raster = subframe.image; // lat/lon_post_intervals are *10 too big - // extra 0 in // 36000 to counteract
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -