📄 abstractairspace.java
字号:
/*
Copyright (C) 2001, 2008 United States Government as represented by
the Administrator of the National Aeronautics and Space Administration.
All Rights Reserved.
*/
package gov.nasa.worldwind.render.airspaces;
import gov.nasa.worldwind.*;
import gov.nasa.worldwind.avlist.*;
import gov.nasa.worldwind.cache.*;
import gov.nasa.worldwind.geom.*;
import gov.nasa.worldwind.globes.Globe;
import gov.nasa.worldwind.render.*;
import gov.nasa.worldwind.util.*;
import java.util.*;
/**
* @author dcollins
* @version $Id: AbstractAirspace.java 10899 2009-05-06 01:02:39Z dcollins $
*/
public abstract class AbstractAirspace extends AVListImpl implements Airspace, Movable
{
protected static final String ARC_SLICES = "ArcSlices";
protected static final String DISABLE_TERRAIN_CONFORMANCE = "DisableTerrainConformance";
protected static final String EXPIRY_TIME = "ExpiryTime";
protected static final String GEOMETRY_CACHE_NAME = "Airspace Geometry";
protected static final String GEOMETRY_CACHE_KEY = Geometry.class.getName();
protected static final String GLOBE_KEY = "GlobeKey";
protected static final String LENGTH_SLICES = "LengthSlices";
protected static final String LOOPS = "Loops";
protected static final String PILLARS = "Pillars";
protected static final String SLICES = "Slices";
protected static final String SPLIT_THRESHOLD = "SplitThreshold";
protected static final String STACKS = "Stacks";
protected static final String SUBDIVISIONS = "Subdivisions";
protected static final String VERTICAL_EXAGGERATION = "VerticalExaggeration";
private static final long DEFAULT_GEOMETRY_CACHE_SIZE = 16777216L; // 16 megabytes
private boolean visible = true;
private AirspaceAttributes attributes;
private double lowerAltitude = 0.0;
private double upperAltitude = 1.0;
private boolean lowerTerrainConforming = false;
private boolean upperTerrainConforming = false;
private boolean enableLevelOfDetail = true;
private Collection<DetailLevel> detailLevels = new TreeSet<DetailLevel>();
// Geometry computation and rendering support.
private AirspaceRenderer renderer = new AirspaceRenderer();
private GeometryBuilder geometryBuilder = new GeometryBuilder();
// Extent support.
private Extent extent;
private boolean extentOutOfDate = true;
private Object extentGlobeKey;
// Geometry update support.
private long expiryTime = -1L;
private long minExpiryTime = 2000L;
private long maxExpiryTime = 6000L;
private static Random rand = new Random();
// Elevation lookup map.
private Map<LatLon, Double> elevationMap = new HashMap<LatLon, Double>();
public AbstractAirspace(AirspaceAttributes attributes)
{
if (attributes == null)
{
String message = "nullValue.AirspaceAttributesIsNull";
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
this.attributes = attributes;
if (!WorldWind.getMemoryCacheSet().containsCache(GEOMETRY_CACHE_KEY))
{
long size = Configuration.getLongValue(AVKey.AIRSPACE_GEOMETRY_CACHE_SIZE, DEFAULT_GEOMETRY_CACHE_SIZE);
MemoryCache cache = new BasicMemoryCache((long) (0.85 * size), size);
cache.setName(GEOMETRY_CACHE_NAME);
WorldWind.getMemoryCacheSet().addCache(GEOMETRY_CACHE_KEY, cache);
}
}
public AbstractAirspace()
{
this(new BasicAirspaceAttributes());
}
public boolean isVisible()
{
return this.visible;
}
public void setVisible(boolean visible)
{
this.visible = visible;
}
public AirspaceAttributes getAttributes()
{
return this.attributes;
}
public void setAttributes(AirspaceAttributes attributes)
{
if (attributes == null)
{
String message = "nullValue.AirspaceAttributesIsNull";
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
this.attributes = attributes;
}
/**
* Returns the altitude limits.
*
* @return an array of two values indicating the lower and upper altitude limits, respectively.
*/
public double[] getAltitudes()
{
double[] array = new double[2];
array[0] = this.lowerAltitude;
array[1] = this.upperAltitude;
return array;
}
protected double[] getAltitudes(double verticalExaggeration)
{
double[] array = this.getAltitudes();
array[0] = array[0] * verticalExaggeration;
array[1] = array[1] * verticalExaggeration;
return array;
}
/**
* Set the upper and lower altitude limits.
*
* @param lowerAltitude the lower altitude limit, in meters relative to mean sea level
* @param upperAltitude the upper altitude limit, in meters relative to mean sea level
*/
public void setAltitudes(double lowerAltitude, double upperAltitude)
{
this.lowerAltitude = lowerAltitude;
this.upperAltitude = upperAltitude;
this.setExtentOutOfDate();
}
public void setAltitude(double altitude)
{
this.setAltitudes(altitude, altitude);
}
/**
* Returns the value of the terrain-conforming attribute.
*
* @return the value of the terrain-conforming attribute. A valud of true indicates the object is
* terrain-conforming, a value of false indicates that it's not.
*/
public boolean[] isTerrainConforming()
{
boolean[] array = new boolean[2];
array[0] = this.lowerTerrainConforming;
array[1] = this.upperTerrainConforming;
return array;
}
/**
* Sets the value of the terrain-conforming attribute.
*
* @param lowerTerrainConformant the value of the lower altitude terrain-conforming attribute.
* A value of true indicates the object's lower altitude is terrain-conforming,
* a value of false indicates that it's not.
* @param upperTerrainConformant the value of the upper altitude terrain-conforming attribute.
* A value of true indicates the object's upper altitude is terrain-conforming,
* a value of false indicates that it's not.
*/
public void setTerrainConforming(boolean lowerTerrainConformant, boolean upperTerrainConformant)
{
this.lowerTerrainConforming = lowerTerrainConformant;
this.upperTerrainConforming = upperTerrainConformant;
this.setExtentOutOfDate();
}
public boolean isAirspaceCollapsed()
{
return this.lowerAltitude == this.upperAltitude && this.lowerTerrainConforming == this.upperTerrainConforming;
}
public void setTerrainConforming(boolean terrainConformant)
{
this.setTerrainConforming(terrainConformant, terrainConformant);
}
public boolean isEnableLevelOfDetail()
{
return this.enableLevelOfDetail;
}
public void setEnableLevelOfDetail(boolean enableLevelOfDetail)
{
this.enableLevelOfDetail = enableLevelOfDetail;
}
public Iterable<DetailLevel> getDetailLevels()
{
return this.detailLevels;
}
public void setDetailLevels(Collection<DetailLevel> detailLevels)
{
this.detailLevels.clear();
this.addDetailLevels(detailLevels);
}
protected void addDetailLevels(Collection<DetailLevel> newDetailLevels)
{
if (newDetailLevels != null)
for (DetailLevel level : newDetailLevels)
if (level != null)
this.detailLevels.add(level);
}
public boolean isAirspaceVisible(DrawContext dc)
{
if (dc == null)
{
String message = Logging.getMessage("nullValue.DrawContextIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (dc.getView() == null)
{
String message = "nullValue.DrawingContextViewIsNull";
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
Extent extent = this.getExtent(dc);
return extent != null && extent.intersects(dc.getView().getFrustumInModelCoordinates());
}
public Extent getExtent(DrawContext dc)
{
if (dc == null)
{
String message = Logging.getMessage("nullValue.DrawContextIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (dc.getGlobe() == null)
{
String message = Logging.getMessage("nullValue.DrawingContextGlobeIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
Object globeKey = dc.getGlobe().getStateKey(dc);
if (this.extentOutOfDate
|| this.extent == null
|| this.extentGlobeKey == null
|| !this.extentGlobeKey.equals(globeKey))
{
this.extent = this.doComputeExtent(dc);
this.extentOutOfDate = false;
this.extentGlobeKey = globeKey;
}
return this.extent;
}
protected boolean isExtentOutOfDate()
{
return this.extentOutOfDate;
}
protected void setExtentOutOfDate()
{
this.extentOutOfDate = true;
}
public AirspaceRenderer getRenderer()
{
return this.renderer;
}
protected void setRenderer(AirspaceRenderer renderer)
{
if (renderer == null)
{
String message = "nullValue.AirspaceRendererIsNull";
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
this.renderer = renderer;
}
public void render(DrawContext dc)
{
if (dc == null)
{
String message = Logging.getMessage("nullValue.DrawContextIsNull");
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
if (!this.isVisible())
return;
if (!this.isAirspaceVisible(dc))
return;
this.doRender(dc);
}
public void renderGeometry(DrawContext dc, String drawStyle)
{
if (dc == null)
{
String message = Logging.getMessage("nullValue.DrawContextIsNull");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -