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

📄 surfacecontourlineset.java

📁 world wind java sdk 源码
💻 JAVA
字号:
package gov.nasa.worldwind.render;

import gov.nasa.worldwind.geom.Sector;
import gov.nasa.worldwind.pick.Pickable;
import gov.nasa.worldwind.util.Logging;

import java.util.*;
import java.util.List;
import java.awt.*;

/**
 * Renders a set of contour lines on the terrain at given elevations. The contour line set extent
 * can be bounded by a <code>Sector</code>.
 *
 * @author Patrick Murris
 * @version $Id: SurfaceContourLineSet.java 10106 2009-04-11 00:36:50Z dcollins $
 */
public class SurfaceContourLineSet implements PreRenderable, Pickable, Renderable
{
    private Sector sector;
    private List<SurfaceContourLine> lines = new ArrayList<SurfaceContourLine>();
    private ShapeAttributes defaultAttributes = new BasicShapeAttributes();
    protected List<SurfaceShape> surfaceShapes = new ArrayList<SurfaceShape>();
    protected TiledSurfaceObjectRenderer renderer = new TiledSurfaceObjectRenderer();
    private boolean enabled = true;

    public SurfaceContourLineSet(double[] elevations, Sector sector)
    {
        this.sector = sector;

        // Init default attributes
        this.defaultAttributes.setDrawInterior(false);
        this.defaultAttributes.setOutlineMaterial(Material.CYAN);

        // Create contour lines
        for (double elevation : elevations)
        {
            SurfaceContourLine scl = new SurfaceContourLine();
            scl.setAttributes(this.getAttributes(elevation));
            scl.setElevation(elevation);
            scl.setSector(sector);
            this.lines.add(scl);
        }
    }

    public boolean isEnabled()
    {
        return this.enabled;
    }

    public void setEnabled(boolean state)
    {
        this.enabled = state;
    }

    protected ShapeAttributes getAttributes(double elevation)
    {
        return this.defaultAttributes;
    }

    public void preRender(DrawContext dc)
    {
        if (this.isValid(dc))
        {
            this.assembleShapes(dc);
            if (this.surfaceShapes.size() > 0)
            {
                this.renderer.setSurfaceObjects(this.surfaceShapes);
                this.renderer.preRender(dc);
            }
        }
    }

    public void pick(DrawContext dc, Point pickPoint)
    {
        if (this.isValid(dc) && this.surfaceShapes.size() > 0)
            this.renderer.pick(dc, pickPoint, null);
    }

    public void render(DrawContext dc)
    {
        if (this.isValid(dc) && this.surfaceShapes.size() > 0)
            this.renderer.render(dc);
    }

    protected boolean isValid(DrawContext dc)
    {
        if (dc == null)
        {
            String message = Logging.getMessage("nullValue.DrawContextIsNull");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }

        if (!this.isEnabled())
            return false;

        if (!this.sector.intersects(dc.getVisibleSector()))
            return false;

        return true;
    }

    protected void assembleShapes(DrawContext dc)
    {
        this.surfaceShapes.clear();

        for (SurfaceContourLine scl : this.lines)
        {
            List<SurfaceShape> shapes = scl.getSurfaceShapes(dc);
            if (shapes != null)
                this.surfaceShapes.addAll(shapes);

        }
    }
    
}

⌨️ 快捷键说明

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