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

📄 segmentplanerenderer.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                }            }        }        if (topObject == null)            return;        this.registerPickedObject(dc, topObject, layer);    }    //**************************************************************//    //********************  Axis Label Rendering  ******************//    //**************************************************************//    @SuppressWarnings({"UnusedDeclaration"})    protected void drawAxisLabels(DrawContext dc, SegmentPlane segmentPlane, RenderInfo renderInfo,        java.awt.Point pickPoint, Layer layer)    {        this.drawHorizontalAxisLabels(dc, segmentPlane);        this.drawVerticalAxisLabels(dc, segmentPlane);    }    protected void drawHorizontalAxisLabels(DrawContext dc, SegmentPlane segmentPlane)    {        if (!this.bindLabelAttributes(dc, segmentPlane, SegmentPlane.HORIZONTAL_AXIS_LABELS))            return;        SectorGeometryList sgl = dc.getSurfaceGeometry();        Globe globe = dc.getGlobe();        double[] gridCellSizes = segmentPlane.getGridCellDimensions();        int[] gridCellCounts = new int[2];        double[] gridCellParams = new double[2];        this.computePlaneParameterization(globe, segmentPlane, gridCellCounts, gridCellParams);        int uStacks = gridCellCounts[0];        double uStep = gridCellParams[0];                // Draw the horizontal axis labels. The horizontal axis labels are drawn along the bottom of the plane, but        // are always drawn at or above the surface.        OrderedText[] labels = new OrderedText[uStacks];        for (int ui = 0; ui < uStacks; ui++)        {            double u = clamp(ui * uStep, 0, 1);            double width = ui * gridCellSizes[0];            AVList values = new AVListImpl();            values.setValue(AVKey.WIDTH, width);            Position pos = this.computePositionOnPlane(sgl, globe, segmentPlane, u, 0, true);            double surfaceElevation = this.computeSurfaceElevation(sgl, globe, pos.getLatitude(), pos.getLongitude());            if (pos.getElevation() < surfaceElevation)                pos = new Position(pos, surfaceElevation);            labels[ui] = this.createLabel(dc, segmentPlane, pos, values, SegmentPlane.HORIZONTAL_AXIS_LABELS);        }        java.awt.Rectangle size = this.computeAverageLabelSize(labels, uStacks);        double d = this.computeMinDistanceBetweenLabels(dc, labels, uStacks);        this.drawAxisLabels(dc, labels, 1, uStacks, size.getWidth(), d);    }    protected void drawVerticalAxisLabels(DrawContext dc, SegmentPlane segmentPlane)    {        if (!this.bindLabelAttributes(dc, segmentPlane, SegmentPlane.VERTICAL_AXIS_LABELS))            return;        double[] gridCellSizes = segmentPlane.getGridCellDimensions();        SectorGeometryList sgl = dc.getSurfaceGeometry();        Globe globe = dc.getGlobe();        int[] gridCellCounts = new int[2];        double[] gridCellParams = new double[2];        this.computePlaneParameterization(globe, segmentPlane, gridCellCounts, gridCellParams);        int vStacks = gridCellCounts[1];        double vStep = gridCellParams[1];        // Draw the vertical axis labels. The verical axis labels are drawn along the right side of the plane. Labels        // beneath the terrain are not drawn.        OrderedText[] labels = new OrderedText[vStacks];        for (int vi = 0; vi < vStacks; vi++)        {            double v = clamp(vi * vStep, 0, 1);            double height = vi * gridCellSizes[1];            AVList values = new AVListImpl();            values.setValue(AVKey.HEIGHT, height);            Position pos = this.computePositionOnPlane(sgl, globe, segmentPlane, 1, v, false);            double surfaceElevation = this.computeSurfaceElevation(sgl, globe, pos.getLatitude(), pos.getLongitude());            if (pos.getElevation() < surfaceElevation)                continue;            labels[vi] = this.createLabel(dc, segmentPlane, pos, values, SegmentPlane.VERTICAL_AXIS_LABELS);        }        java.awt.Rectangle size = this.computeAverageLabelSize(labels, vStacks);        double d = this.computeMinDistanceBetweenLabels(dc, labels, vStacks);        this.drawAxisLabels(dc, labels, 1, vStacks, size.getHeight(), d);    }    protected void drawAxisLabels(DrawContext dc, OrderedText[] text, int startPos, int count,        double averageSize, double minDistance)    {        int step = (int) Math.round(1.5 * averageSize / minDistance);        if (step < 1)            step = 1;        for (int i = startPos; i < count; i += step)        {            if (text[i] != null)            {                dc.addOrderedRenderable(text[i]);            }        }    }    //**************************************************************//    //********************  Label Rendering  ***********************//    //**************************************************************//    protected void drawLabel(DrawContext dc, SegmentPlane segmentPlane, Position position, AVList values, Object key)    {        OrderedText orderedText = this.createLabel(dc, segmentPlane, position, values, key);        if (orderedText == null)            return;        dc.addOrderedRenderable(orderedText);    }    protected OrderedText createLabel(DrawContext dc, SegmentPlane segmentPlane, Position position, AVList values,        Object key)    {        SegmentPlaneAttributes.LabelAttributes attributes = segmentPlane.getAttributes().getLabelAttributes(key);        if (attributes == null)            return null;        Vec4 point = dc.getGlobe().computePointFromPosition(position);        double distanceFromEye = dc.getView().getEyePoint().distanceTo3(point);        if (distanceFromEye < attributes.getMinActiveDistance() || distanceFromEye > attributes.getMaxActiveDistance())        {            return null;                    }        Font font = attributes.getFont();        MultiLineTextRenderer textRenderer = this.getTextRendererFor(dc, font);                return new OrderedText(segmentPlane, position, distanceFromEye, values, attributes, textRenderer);    }    protected java.awt.Rectangle computeAverageLabelSize(OrderedText[] text, int textCount)    {        double width = 0;        double height = 0;        int count = 0;        for (int i = 0; i < textCount; i++)        {            if (text[i] != null)            {                java.awt.Rectangle bounds = text[i].textRenderer.getBounds(text[i].getText());                width += bounds.getWidth();                height += bounds.getHeight();                count++;            }        }        if (count > 1)        {            width /= (double) count;            height /= (double) count;        }        return new java.awt.Rectangle((int) width, (int) height);    }    protected double computeMinDistanceBetweenLabels(DrawContext dc, OrderedText[] text, int textCount)    {        double minDistance = Double.MAX_VALUE;        for (int i = 0; i < textCount - 1; i++)        {            if (text[i] != null)            {                for (int j = i + 1; j < textCount; j++)                {                    if (text[j] != null)                    {                        Vec4 v1 = text[i].getScreenPoint(dc);                        Vec4 v2 = text[j].getScreenPoint(dc);                        double d = v1.distanceToSquared3(v2);                        if (d < minDistance)                            minDistance = d;                    }                }            }        }        if (minDistance > 0)            minDistance = Math.sqrt(minDistance);        return minDistance;    }    protected static class OrderedText implements OrderedRenderable    {        protected SegmentPlane segmentPlane;        protected final Position position;        protected final double distanceFromEye;        protected AVList values;        protected SegmentPlaneAttributes.LabelAttributes attributes;        protected MultiLineTextRenderer textRenderer;        public OrderedText(SegmentPlane segmentPlane, Position position, double distanceFromEye, AVList values,            SegmentPlaneAttributes.LabelAttributes attributes, MultiLineTextRenderer textRenderer)        {            this.segmentPlane = segmentPlane;            this.position = position;            this.distanceFromEye = distanceFromEye;            this.values = values;            this.attributes = attributes;            this.textRenderer = textRenderer;        }        public String getText()        {            return this.attributes.getText(this.segmentPlane, this.position, this.values);        }        public double getDistanceFromEye()        {            return this.distanceFromEye;        }        public Vec4 getScreenPoint(DrawContext dc)        {            return dc.getScreenPoint(this.position).add3(attributes.getOffset());        }        public void render(DrawContext dc)        {            OGLStackHandler ogsh = new OGLStackHandler();            this.begin(dc, ogsh);            try            {                this.draw(dc);            }            finally            {                this.end(dc, ogsh);            }        }        public void pick(DrawContext dc, Point pickPoint)        {            // Label text is not pickable.        }        protected void draw(DrawContext dc)        {            String text = this.getText();            if (text == null)                return;            Vec4 point = this.getScreenPoint(dc);            if (point == null)                return;            java.awt.Rectangle viewport = dc.getView().getViewport();            java.awt.Color color = attributes.getColor();            this.textRenderer.getTextRenderer().beginRendering(viewport.width, viewport.height);            this.textRenderer.setTextColor(color);            this.textRenderer.setBackColor(Color.BLACK);            this.drawText(text, point, attributes, this.textRenderer);            this.textRenderer.getTextRenderer().endRendering();        }        protected void begin(DrawContext dc, OGLStackHandler ogsh)        {            GL gl = dc.getGL();            int attribBits = GL.GL_CURRENT_BIT; // For current color.            ogsh.pushAttrib(gl, attribBits);        }        protected void end(DrawContext dc, OGLStackHandler ogsh)        {            GL gl = dc.getGL();            ogsh.pop(gl);        }        protected void drawText(String text, Vec4 screenPoint,            SegmentPlaneAttributes.LabelAttributes attributes, MultiLineTextRenderer mltr)        {            double x = screenPoint.x;            double y = screenPoint.y;            if (attributes != null)            {                String horizontal = attributes.getHorizontalAlignment();                String vertical = attributes.getVerticalAlignment();                java.awt.Rectangle textBounds = mltr.getBounds(text);                double w = textBounds.getWidth();                double h = textBounds.getHeight();                double hw = textBounds.getWidth() / 2.0;                double hh = textBounds.getHeight() / 2.0;                //noinspection StringEquality                if (horizontal == AVKey.LEFT)                {                    // MultiLineTextRenderer anchors text to the upper left corner by default.                }                else //noinspection StringEquality                    if (horizontal == AVKey.CENTER)                {                    x -= hw;                }                else //noinspection StringEquality                    if (horizontal == AVKey.RIGHT)                {                    x -= w;                }                //noinspection StringEquality                if (vertical == AVKey.TOP)                {                    // MultiLineTextRenderer anchors text to the upper left corner by default.                }                else //noinspection StringEquality                    if (vertical == AVKey.CENTER)                {                    y += hh;                }                else //noinspection StringEquality                    if (vertical == AVKey.BOTTOM)                {                    y += h;                }            }            mltr.draw(text, (int) x, (int) y, MultiLineTextRenderer.EFFECT_SHADOW);        }

⌨️ 快捷键说明

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