📄 profilegenerator.java
字号:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/terrain/ProfileGenerator.java,v $// $RCSfile: ProfileGenerator.java,v $// $Revision: 1.6.2.2 $// $Date: 2005/08/09 21:17:47 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.terrain;import java.awt.*;import java.awt.event.*;import java.util.*;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.image.AcmeGifFormatter;import com.bbn.openmap.dataAccess.dted.DTEDFrameCache;import com.bbn.openmap.layer.util.stateMachine.*;import com.bbn.openmap.omGraphics.*;import com.bbn.openmap.proj.*;import com.bbn.openmap.util.Debug;/** * This tool lets the user draw a line on the map, and then presents * the profile of the path in a GIF picture. The line can be drawn in * a series if clicks, or the mouse button can be held down as the * mouse is dragged around. The lines are drawn as great circle lines, * which represent the straight geographical line between clicks. * * <P> * The profile tool uses the ProfileStateMachine, and the Profile * States, to keep track of the proper actions and reactions of user * input. */public class ProfileGenerator implements TerrainTool { /** The color of the line that is drawn on the screen. */ Color toolColor = new Color(255, 0, 0); /** The state machine for user gestures. */ protected ProfileStateMachine stateMachine; /** The layer that the tool is serving. */ protected TerrainLayer layer; /** The list of graphics to draw. Contains the drawn line. */ protected OMGraphicList graphics = new OMGraphicList(); /** * Array of LatLonPoints. The points are the clicked points, and * the points in between, on a great circle. Have to figure these * points out, and not rely only on the poly line points, because * we need to get the elevations for all the points for the * profile. */ public Vector coords; /** * These are the raw x-y points of the gestures, for the great * circle line points, too. These are used to construct the * profile image. An array of java.awt.Points. */ public Vector xypoints; /** * The line drawn on the screen representing the profile line * path. */ public OMPoly profileLine; /** * General gesture tracking, Used to track the last place of * interest on the screen for the creation of hte profile. */ MouseEvent lastMouse; /** * A copy of the most current projection to use to update the * drawn line. */ Projection proj; public ProfileGenerator(TerrainLayer tLayer) { layer = tLayer; init(); } public synchronized OMGraphicList getGraphics() { profileLine.setLocation(setLLPoints(), OMGraphic.RADIANS); profileLine.generate(proj); return graphics; } /** * Create the line object, the state machine, and the vectors used * to keep track of the line being drawn. */ public void init() { lastMouse = null; coords = new Vector(); xypoints = new Vector(); profileLine = new OMPoly(setLLPoints(), OMGraphic.RADIANS, OMGraphic.LINETYPE_GREATCIRCLE); profileLine.setLinePaint(toolColor); graphics.add(profileLine); // System.loadLibrary("com_bbn_openmap_terrain_ProfileGenerator"); stateMachine = new ProfileStateMachine(this); } /** * Clears the line from the screen, and resets the state machine. */ public void reset() { coords.removeAllElements(); xypoints.removeAllElements(); profileLine.setLocation(setLLPoints(), OMGraphic.RADIANS); stateMachine.reset(); layer.repaint(); lastMouse = null; } public void setScreenParameters(Projection p) { proj = p; graphics.generate(p); } /** * Returns a set of lat lon points that represent the line as it * was drawn. The lat lon points are in an array of floats, that * alternate, lat, lon, etc. */ public float[] setLLPoints() { float[] points; int num_points = coords.size(); if (num_points <= 1) { points = new float[4]; if (num_points == 0) { points[0] = 0f; points[1] = -6f; } else { points[0] = ((LatLonPoint) coords.elementAt(0)).radlat_; points[1] = ((LatLonPoint) coords.elementAt(0)).radlon_; } points[2] = points[0]; points[3] = points[1]; } else { points = new float[coords.size() * 2]; for (int i = 0; i < coords.size(); i++) { points[i * 2] = ((LatLonPoint) coords.elementAt(i)).radlat_; points[(i * 2) + 1] = ((LatLonPoint) coords.elementAt(i)).radlon_; } } return points; } /** * Returns the current state of the state machine. */ public State getState() { return stateMachine.getState(); } /** * Creates the line points for the path drawn on the screen, and * collects the elevation values for those points. Makes the call * to write the new gif file to disk. */ public void createProfileImage() { Debug.message("terrain", "ProfileGenerator:createProfileImage(): Creating image"); if (layer == null || layer.frameCache == null) { Debug.error("ProfileGenerator: can't access the DTED data through the terrain layer."); return; } // Set the final line, as it was drawn. profileLine.setLocation(setLLPoints(), OMGraphic.RADIANS); int total_distance = 0; int[] distances = new int[xypoints.size()]; Point tmpPoint1, tmpPoint2; distances[0] = 0; for (int j = 1; j < xypoints.size(); j++) { tmpPoint1 = (Point) xypoints.elementAt(j); tmpPoint2 = (Point) xypoints.elementAt(j - 1); // Needed for the GIF, the number of pixels (distance) // between points of the line. The distances array is the // distance between this point and the next in the xy // point array. distances[j] = TerrainLayer.numPixelsBetween(tmpPoint1.x, tmpPoint1.y, tmpPoint2.x, tmpPoint2.y); total_distance += distances[j]; } int tmp = 0; int max = 0; int[] heights = new int[xypoints.size()]; // Go through the points and get the heights for (int i = 0; i < heights.length; i++) { LatLonPoint llp = ((LatLonPoint) coords.elementAt(i)); // Ask the cache for the elevation tmp = layer.frameCache.getElevation(llp.getLatitude(), llp.getLongitude()); if (tmp == DTEDFrameCache.NO_DATA) tmp = -1; if (tmp > max)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -