⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 omgraphicutil.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// **********************************************************************//// <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/j3d/com/bbn/openmap/tools/j3d/OMGraphicUtil.java,v $// $RCSfile: OMGraphicUtil.java,v $// $Revision: 1.4.2.2 $// $Date: 2005/08/11 21:03:16 $// $Author: dietrick $//// **********************************************************************package com.bbn.openmap.tools.j3d;import java.awt.Color;import java.awt.Point;import java.awt.Shape;import java.awt.geom.FlatteningPathIterator;import java.awt.geom.PathIterator;import java.util.HashSet;import java.util.Iterator;import javax.media.j3d.Appearance;import javax.media.j3d.ColoringAttributes;import javax.media.j3d.LineArray;import javax.media.j3d.LineStripArray;import javax.media.j3d.Material;import javax.media.j3d.PolygonAttributes;import javax.media.j3d.Shape3D;import javax.media.j3d.TriangleStripArray;import javax.vecmath.Color3f;import javax.vecmath.Color4b;import javax.vecmath.Point3d;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.omGraphics.OMColor;import com.bbn.openmap.omGraphics.OMGeometryList;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMGraphicList;import com.bbn.openmap.omGraphics.OMGrid;import com.bbn.openmap.omGraphics.grid.GridData;import com.bbn.openmap.omGraphics.grid.OMGridGenerator;import com.bbn.openmap.omGraphics.grid.SimpleColorGenerator;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;import com.sun.j3d.utils.geometry.GeometryInfo;import com.sun.j3d.utils.geometry.NormalGenerator;import com.sun.j3d.utils.geometry.Stripifier;import com.sun.j3d.utils.geometry.Triangulator;/** * This class handles translating OMGraphics into a Java 3D Scene. *  * @author dietrick */public class OMGraphicUtil {    public final static int DEFAULT_NPOINTS_BUFFER_SIZE = 100;    public final static Iterator NULL_ITERATOR = new HashSet().iterator();    /**     * Method takes an OMGraphic, creates one or more Shape3D objects     * out of it, and returns an Iterator containing them.     *      * @param graphic the OMGraphic.     * @return Iterator containing Shape3D objects.     */    public static Iterator createShape3D(OMGraphic graphic) {        return createShape3D(graphic, 0);    }    /**     * Method takes an OMGraphic, creates one or more Shape3D objects     * out of it, and returns an Iterator containing them.     *      * @param graphic the OMGraphic.     * @param baselineHeight the baselined height for all the graphics     *        on the list.     * @return Iterator containing Shape3D objects.     */    public static Iterator createShape3D(OMGraphic graphic,                                         double baselineHeight) {        Debug.message("3detail", "OMGraphicUtil.createShape3D()");        boolean DEBUG_SHAPE = Debug.debugging("3dshape");        if (graphic == null) {            return NULL_ITERATOR;        }        if (graphic instanceof OMGraphicList                && !(graphic instanceof OMGeometryList)) {            HashSet set = new HashSet();            Iterator it = ((OMGraphicList) graphic).iterator();            while (it.hasNext()) {                OMGraphic subgraphic = (OMGraphic) it.next();                Debug.message("3detail",                        "OMGraphicUtil.createShape3D():  recursivly adding list...");                Iterator iterator = createShape3D(subgraphic, baselineHeight);                while (iterator.hasNext()) {                    set.add(iterator.next());                }            }            return set.iterator();        } else {            if (DEBUG_SHAPE) {                Debug.output("OMGraphicUtil.createShape3D():  adding shape...");            }            Shape shape = graphic.getShape();            if (shape != null) {                // Handle the shapes, depending on if they should                // be filled or not...                // First, determine wether this is a line or                // polygon thingy, and set the color accordingly.                // Text should be handled differently - might need                // to render text, and the background block.                if (graphic.shouldRenderFill()) {                    // Do polygons.                    return createShape3D(shape,                            baselineHeight,                            graphic.getFillColor(),                            true);                } else if (graphic.shouldRenderEdge()) {                    // Might as well make sure it's not totally                    // clear before creating lines.                    return createShape3D(shape,                            baselineHeight,                            graphic.getDisplayColor(),                            false);                } else if (DEBUG_SHAPE) {                    Debug.output("OMGraphicUtil.createShape3D(): can't render graphic");                }            } else if (DEBUG_SHAPE) {                Debug.output("OMGraphicUtil.createShape3D(): shape from graphic is null");            }        }        return NULL_ITERATOR;    }    /**     * Create an Iterator containing a set of Shape3D objects, created     * from OMGrid. Currently only works for OMGrids containing     * GridData.Int data.     *      * @param grid the OMGrid to create a 3D terrain object from.     * @param baselineHeight the baselined height for all the values     *        in the grid, if the OMGridGenerator wants to use it.     * @param projection the map projection     * @return an iterator containing all Shape3D objects     */    public static Iterator createShape3D(OMGrid grid, double baselineHeight,                                         Projection projection) {        TriangleStripArray gridStrip;        if (grid.getRenderType() != OMGraphic.RENDERTYPE_LATLON) {            Debug.error("OMGraphicUtil.createShape3D:  can't handle non-LATLON grids yet");            return NULL_ITERATOR;        }        boolean DEBUG = false;        if (Debug.debugging("3dgrid")) {            DEBUG = true;        }        //      if (grid.getGenerator() == null && grid.getFillColor() ==        // OMColor.clear) {        //          return createWireFrame(grid, baselineHeight, projection);        //      }        Color fColor = grid.getFillColor();        Color lColor = grid.getLineColor();        boolean polyline = (fColor == OMColor.clear);        if (DEBUG) {            Debug.output("Polyline = " + polyline);        }        Color3f fillcolor = new Color3f(fColor);        Color3f linecolor = new Color3f(lColor);        int numRows = grid.getRows();        int numCols = grid.getColumns();        // create triangle strip for twist        int stripCount = numRows - 1;        int numberVerticesPerStrip = numCols * 2;        int[] stripCounts = new int[stripCount];        for (int i = 0; i < stripCount; i++) {            stripCounts[i] = numberVerticesPerStrip;        }        LatLonPoint anchorLL = new LatLonPoint(grid.getLatitude(), grid.getLongitude());//        Point anchorP = projection.forward(anchorLL);        float vRes = grid.getVerticalResolution();        float hRes = grid.getHorizontalResolution();        gridStrip = new TriangleStripArray(stripCount * numberVerticesPerStrip, TriangleStripArray.COORDINATES                | TriangleStripArray.COLOR_3 | TriangleStripArray.NORMALS, stripCounts);        // OK, what you want to do is calculate the index of the        // vertices, add the correct multiplication of offsets in        // degree space, and then inverse project that point to get        // the actual coordinates.        Point p = new Point();        int pointer = 0;        GridData gridData = grid.getData();        if (!(gridData instanceof GridData.Int)) {            // Need to fix this to work with all GridData types!            Debug.error("OMGrid.interpValueAt only works for integer data.");        }        int[][] data = ((GridData.Int) gridData).getData();        boolean major = gridData.getMajor();        //         int[][] data = grid.getData();        //         boolean major = grid.getMajor();        int dataPoint;        Color3f color;        SimpleColorGenerator generator = null;        OMGridGenerator tempGen = grid.getGenerator();        if (tempGen instanceof SimpleColorGenerator) {            generator = (SimpleColorGenerator) tempGen;        }        for (int j = 0; j < numRows - 1; j++) {            if (DEBUG) {                Debug.output("Creating strip " + j);            }            // I think the '-' should be '+'... (changed, DFD)            float lat1 = anchorLL.getLatitude() + ((float) j * vRes);            float lat2 = anchorLL.getLatitude() + (((float) j + 1f) * vRes);            for (int k = 0; k < numCols; k++) {                if (DEBUG) {                    Debug.output("   working row " + k);                }                float lon = anchorLL.getLongitude() + ((float) k * hRes);                projection.forward(lat1, lon, p);                if (major) {                    dataPoint = data[k][j];                } else {                    dataPoint = data[j][k];                }                gridStrip.setCoordinate(pointer,                        new Point3d((float) p.getX(), (float) dataPoint, (float) p.getY()));                if (DEBUG) {                    Debug.output("       1st coord " + p.getX() + ", "                            + dataPoint + ", " + p.getY());                }                projection.forward(lat2, lon, p);                if (major) {                    dataPoint = data[k][j + 1];                } else {                    dataPoint = data[j + 1][k];                }                gridStrip.setCoordinate(pointer + 1,                        new Point3d((float) p.getX(), (float) dataPoint, (float) p.getY()));                if (DEBUG) {                    Debug.output("       2nd coord " + p.getX() + ", "                            + dataPoint + ", " + p.getY());                }                // Need the TriangleStripArray.COLOR_3 Attribute set                // above                if (generator == null) {                    if (polyline) {                        color = linecolor;                    } else {                        color = fillcolor;                    }                } else {                    color = new Color3f(new Color(generator.calibratePointValue(dataPoint)));                }                gridStrip.setColor(pointer++, color);                gridStrip.setColor(pointer++, color);                // else                //              pointer += 2;            }        }        Shape3D shape = new Shape3D(gridStrip);        Appearance appear = new Appearance();        PolygonAttributes polyAttrib = new PolygonAttributes();        if (polyline) {            polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE);        }        polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);        appear.setPolygonAttributes(polyAttrib);        shape.setAppearance(appear);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -