rpfgenerator.java
来自「world wind java sdk 源码」· Java 代码 · 共 515 行 · 第 1/2 页
JAVA
515 行
/* Copyright (C) 2001, 2007 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved. */package gov.nasa.worldwind.layers.rpf;import gov.nasa.worldwind.avlist.*;import gov.nasa.worldwind.formats.rpf.*;import gov.nasa.worldwind.formats.wvt.*;import gov.nasa.worldwind.geom.*;import gov.nasa.worldwind.util.*;import java.awt.*;import java.awt.geom.*;import java.awt.image.*;import java.io.*;import java.net.*;import java.util.*;/** * @author brownrigg * @version $Id: RPFGenerator.java 6800 2008-09-24 01:14:07Z rick $ */class RPFGenerator{ @SuppressWarnings({"FieldCanBeLocal"}) private final RPFFileIndex fileIndex; private final FrameFile[] frameFiles; private final Sector globalBounds; private final AbsentResourceList absentFrames; // Wavelet parameters. private final int smallImageSize; private final int preloadRes; // Configuration property keys. public static final String RPF_FILE_INDEX = "RPFGenerator.RPFFileIndex"; public static final String WAVELET_IMAGE_THRESHOLD = "RPFGenerator.WaveletImageThreshold"; public static final String WAVELET_PRELOAD_SIZE = "RPFGenerator.WaveletPreloadSize"; public RPFGenerator(AVList params) { if (params == null) { String message = Logging.getMessage("nullValue.AVListIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } params = initParams(params.copy()); this.fileIndex = (RPFFileIndex) params.getValue(RPF_FILE_INDEX); this.frameFiles = loadFrameFiles(this.fileIndex); this.globalBounds = computeGlobalBounds(this.fileIndex); this.absentFrames = new AbsentResourceList(-1, -1); this.smallImageSize = (Integer) params.getValue(WAVELET_IMAGE_THRESHOLD); this.preloadRes = (Integer) params.getValue(WAVELET_PRELOAD_SIZE); } private static AVList initParams(AVList params) { if (params == null) { String message = Logging.getMessage("nullValue.AVListIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (params.getValue(RPF_FILE_INDEX) == null) { String message = "RPFFileIndex is null"; Logging.logger().severe(message); throw new IllegalArgumentException(message); } Object o = params.getValue(WAVELET_IMAGE_THRESHOLD); if (o == null || !(o instanceof Integer)) params.setValue(WAVELET_IMAGE_THRESHOLD, 256); o = params.getValue(WAVELET_PRELOAD_SIZE); if (o == null || !(o instanceof Integer) || !WWMath.isPowerOfTwo((Integer) o)) params.setValue(WAVELET_PRELOAD_SIZE, 32); return params; } public Sector getGlobalBounds() { return this.globalBounds; } public RPFServiceInstance getServiceInstance() { return new RPFServiceInstance(); } private FrameFile[] loadFrameFiles(RPFFileIndex fileIndex) { Collection<FrameFile> list = new ArrayList<FrameFile>(); long frameId = -1; RPFFileIndex.Table fileTable = fileIndex.getRPFFileTable(); if (fileTable != null) { for (RPFFileIndex.Record record : fileTable.getRecords()) { ++frameId; RPFFileIndex.RPFFileRecord rpfRecord = (RPFFileIndex.RPFFileRecord) record; long rpfKey = record.getKey(); long waveletKey = rpfRecord.getWaveletSecondaryKey(); Sector sector = rpfRecord.getSector(); if (rpfKey != -1 && waveletKey != -1 && sector != null) { File rpfFile = fileIndex.getRPFFile(rpfKey); File waveletFile = fileIndex.getWaveletFile(waveletKey); list.add(new FrameFile(frameId, rpfFile, waveletFile, sector)); } else { String message = "Ignoring frame file: " + (rpfKey != -1 ? fileIndex.getRPFFile(rpfKey).getPath() : "?"); Logging.logger().fine(message); } } } FrameFile[] array = new FrameFile[list.size()]; list.toArray(array); return array; } // // Find the global bounds for this collection of frame files (i.e., the union of their Sectors). // private Sector computeGlobalBounds(RPFFileIndex fileIndex) { Sector gb = null; if (fileIndex != null && fileIndex.getIndexProperties() != null) gb = fileIndex.getIndexProperties().getBoundingSector(); if (gb == null) gb = Sector.EMPTY_SECTOR; return gb; } // ----------------------------------------------- // class FrameFile // // A small private class to bundle info about framefiles. // Public access to fields is intentional. // private static class FrameFile { public long id; public File rpfFile; public File waveletFile; public Sector sector; public WaveletCodec codec; public RPFFrameFilename frameFile; public RPFFrameTransform transform; public FrameFile(long id, File rpfFile, File waveletFile, Sector sector) { this.id = id; this.rpfFile = rpfFile; this.waveletFile = waveletFile; this.sector = sector; this.frameFile = RPFFrameFilename.parseFilename(rpfFile.getName().toUpperCase()); } public RPFFrameTransform getFrameTransform() { if (this.transform == null) { RPFDataSeries dataSeries = RPFDataSeries.dataSeriesFor(this.frameFile.getDataSeriesCode()); this.transform = RPFFrameTransform.createFrameTransform(this.frameFile.getZoneCode(), dataSeries.rpfDataType, dataSeries.scaleOrGSD); } return this.transform; } public int getFrameNumber() { return frameFile.getFrameNumber(); } } // -------------------------------------------- // class ServiceInstance // // Used to manage per-request state. // public class RPFServiceInstance { public static final String BBOX = "bbox"; public static final String WIDTH = "width"; public static final String HEIGHT = "height"; public RPFServiceInstance() {} public BufferedImage serviceRequest(AVList params) throws IOException { if (params == null) { String message = Logging.getMessage("nullValue.AVListIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } String message = this.validate(params); if (message != null) { Logging.logger().severe(message); throw new IllegalArgumentException(message); } try { Sector reqSector = (Sector) params.getValue(BBOX); int reqWidth = (Integer) params.getValue(WIDTH); int reqHeight = (Integer) params.getValue(HEIGHT); BufferedImage reqImage = new BufferedImage(reqWidth, reqHeight, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D g2d = (Graphics2D) reqImage.getGraphics(); int numFramesInRequest = 0; for (FrameFile frame : RPFGenerator.this.frameFiles) { try { // The call to getSector() can throw an exception if the file is // named with an inappropriate frameNumber for the dataseries/zone. // We don't want these to short circuit the entire request, so // trap any such occurances and ignore 'em. if (!reqSector.intersects(frame.sector)) continue; } catch (Exception e) { /* ignore this framefile */ String msg = String.format("Exception while computing frame bounds: %s", frame.rpfFile); Logging.logger().log(java.util.logging.Level.SEVERE, msg, e); markFrameFileAbsent(frame); continue; } if (RPFGenerator.this.isFrameFileAbsent(frame)) continue; Sector frameSector = frame.sector; // find size of the frame's footprint at the requested image resolution... int footprintX = (int) (frameSector.getDeltaLonDegrees() * reqImage.getWidth() / reqSector.getDeltaLonDegrees()); int footprintY = (int) (frameSector.getDeltaLatDegrees() * reqImage.getHeight() / reqSector.getDeltaLatDegrees()); // Depending upon footprint, either get image from it RPF framefile, or reconstruct // it from a wavelet encoding. BufferedImage sourceImage; if (footprintX > smallImageSize || footprintY > smallImageSize)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?