Class KMLRegion
- java.lang.Object
-
- gov.nasa.worldwind.util.xml.AbstractXMLEventParser
-
- gov.nasa.worldwind.ogc.kml.KMLAbstractObject
-
- gov.nasa.worldwind.ogc.kml.KMLRegion
-
- All Implemented Interfaces:
MessageListener
,XMLEventParser
public class KMLRegion extends KMLAbstractObject
Represents the KML Region element and provides access to its contents. Regions define an area of interest described by a geographic bounding box and an optional minimum and maximum altitude.Bounding Box
A Region's bounding box controls when the Region is active by defining a volume that must intersect the viewing frustum. The bounding box is computed according to thealtitudeMode
attribute of a Region's geographicLatLonAltBox
as follows:- clampToGround (default): The bounding box encloses the terrain surface in the sector
defined by the north, south, east, and west limits of this Region's
LatLonAltBox
. - relativeToGround: The bounding box encloses the volume in the sector defined by the north,
south, east, and west limits of the Region's
LatLonAltBox
, and who's upper and lower altitude are specified by its minAltitude and maxAltitude, relative to ground level. - absolute: The
bounding box encloses the volume in the sector defined by the north, south, east, and west limits of the Region's
LatLonAltBox
, and who's upper and lower altitude are specified by its minAltitude and maxAltitude, relative to mean sea level.
Level of Detail
A Region's level of detail determines when it is active by defining an upper and lower boundary on the Region's screen area or the Region's distance to the view. The level of detail is computed according to thealtitudeMode
attribute of a Region's geographicLatLonAltBox
as follows:- clampToGround (default): The level of detail is determined by computing the distance from
the eye point and Region sector, scaling the distance by the
KMLTraversalContext's
detail hint, then comparing that scaled distance to the Region's min and max pixel sizes in meters (the Region sector's area divided byminLodPixels
andmaxLodPixels
, respectively). The Region is active when the scaled distance is less than or equal to the min pixel size in meters and greater than the max pixel size in meters. The detail hint may be specified by callingsetDetailHint
on the top levelKMLRoot
(the KMLRoot loaded by the application). - relativeToGround: The level of detail is determined by computing the
number of pixels the Region occupies on screen, and comparing that pixel count to the Region's
minLodPixels
andmaxLodPixels
. The Region is active when the pixel count is greater or equal tominLodPixels
and less thanmaxLodPixels
. - absolute: The
level of detail is determined by computing the number of pixels the Region occupies on screen, and comparing that
pixel count to the Region's
minLodPixels
andmaxLodPixels
. The Region is active when the pixel count is greater or equal tominLodPixels
and less thanmaxLodPixels
.
In order to prevent Regions with adjacent level of detail ranges from activating at the same time, Region gives priority to higher level of detail ranges. For example, suppose that two KML features representing different detail levels of a Collada model have Regions with LOD range 100-200 and 200-300. Region avoids activating both features in the event that both their level of detail criteria are met by giving priority to the second range: 200-300.
KML Feature Hierarchies
When a Region is attached to a KML feature, the feature and its descendants are displayed only when the Region is active. A Region is active when its bounding box is in view and its level of detail criteria are met. Region provides theisActive
method for determining if a Region is active for a specifiedDrawContext
.Regions do not apply directly to KML containers, because a descendant feature can override the container's Region with its own Region. If a feature does not specify a Region it inherits the Region of its nearest ancestor. Since a child feature's Region may be larger or have a less restrictive level of detail range than its ancestor's Region, the visibility of an entire KML feature tree cannot be determined based on a container's Region. Instead, visibility must be determined at each leaf feature.
Limitations
The Region bounding box must lie between -90 to 90 degrees latitude, and -180 to 180 degrees longitude. Regions that span the date line are currently not supported.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
KMLRegion.RegionData
RegionData
holds a Region's computed data used during a single call toRegion.isActive
, and is unique to a particularGlobe
.
-
Field Summary
Fields Modifier and Type Field Description protected KMLRegion.RegionData
currentData
Identifies the active globe-dependent data for the current invocation ofisActive
.protected static int
DEFAULT_DATA_GENERATION_INTERVAL
The default time in milliseconds aRegionData
element may exist in this Region'sregionDataCache
before it must be regenerated: 6 seconds.protected static double
DEFAULT_DETAIL_HINT_ORIGIN
The default value that configures KML scene resolution to screen resolution as the viewing distance changes: 2.8.protected static int
DEFAULT_UNUSED_DATA_LIFETIME
The default time in milliseconds aRegionData
element may exist in this Region'sregionDataCache
without being used before it is evicted: 1 minute.protected double
detailHintOrigin
The default value that configures KML scene resolution to screen resolution as the viewing distance changes.protected long
maxExpiryTime
The maximum lifespan of this Region's computed data, in milliseconds.protected long
minExpiryTime
The minimum lifespan of this Region's computed data, in milliseconds.protected ShapeDataCache
regionDataCache
Holds globe-dependent computed Region data.-
Fields inherited from class gov.nasa.worldwind.ogc.kml.KMLAbstractObject
MSG_BOX_CHANGED, MSG_GEOMETRY_CHANGED, MSG_LINK_CHANGED, MSG_STYLE_CHANGED, MSG_TIME_CHANGED, MSG_VIEW_CHANGED
-
Fields inherited from class gov.nasa.worldwind.util.xml.AbstractXMLEventParser
CHARACTERS_CONTENT, fields, namespaceURI, parent
-
-
Constructor Summary
Constructors Constructor Description KMLRegion(java.lang.String namespaceURI)
Creates a newKMLRegion
with the specified namespace URI, but otherwise does nothing.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyChange(KMLAbstractObject sourceValues)
protected KMLRegion.RegionData
createCacheEntry(DrawContext dc)
Creates and returns a newRegionData
instance specific to this Region instance.protected void
doMakeAbsoluteRegionData(DrawContext dc, KMLLatLonAltBox box)
Produces theExtent
and theSector
for this Region.protected void
doMakeClampToGroundRegionData(DrawContext dc, KMLLatLonAltBox box)
Produces theExtent
and theSector
for this Region.protected void
doMakeRegionData(DrawContext dc)
Produces the data used to determine whether this Region is active for the specifiedDrawContext
.protected void
doMakeRelativeToGroundRegionData(DrawContext dc, KMLLatLonAltBox box)
Produces theExtent
and theSector
for this Region.protected KMLRegion.RegionData
getCurrentData()
Returns the data cache entry for the current invocation ofisActive
.protected double
getDetailFactor(KMLTraversalContext tc)
Indicates the detail factor that configures KML scene resolution to screen resolution as the viewing distance changes.KMLLatLonAltBox
getLatLonAltBox()
Indicates the bounding box that must be in view for this this Region to be considered active.KMLLod
getLod()
Indicates the level of detail criteria that must be satisfied for this Region to be considered active.protected boolean
intersectsFrustum(DrawContext dc)
Indicates whether this Region intersects the viewing frustum for the specifiedDrawContext
.boolean
isActive(KMLTraversalContext tc, DrawContext dc)
Indicates whether this Region is active on the specifiedDrawContext
.protected boolean
isRegionActive(KMLTraversalContext tc, DrawContext dc)
Indicates whether this Region is active on the specifiedDrawContext
.protected boolean
isRegionVisible(DrawContext dc)
Indicates whether this Region is visible for the specifiedDrawContext
.protected boolean
isSectorSupported(Sector sector)
Determines if a Sector is supported by this Region implementation.protected void
makeRegionData(DrawContext dc)
Produces the data used to determine whether this Region is active for the specifiedDrawContext
.protected boolean
meetsAbsoluteLodCriteria(KMLTraversalContext tc, DrawContext dc, KMLLod lod)
Indicates whether the specifiedDrawContext
meets this Region's level of detail criteria.protected boolean
meetsClampToGroundLodCriteria(KMLTraversalContext tc, DrawContext dc, KMLLod lod)
Indicates whether the specifiedDrawContext
meets this Region's level of detail criteria.protected boolean
meetsLodCriteria(KMLTraversalContext tc, DrawContext dc)
Indicates whether the specifiedDrawContext
meets this Region's level of detail criteria.protected boolean
meetsRelativeToGroundLodCriteria(KMLTraversalContext tc, DrawContext dc, KMLLod lod)
Indicates whether the specifiedDrawContext
meets this Region's level of detail criteria.protected boolean
meetsScreenAreaCriteria(DrawContext dc, KMLLod lod)
Indicates whether this Region's projected screen area on the specifiedDrawContext
is in the range specified bylod
.protected boolean
mustRegenerateData(DrawContext dc)
Indicates whether this Region's data must be recomputed, either as a result of a change in theGlobe's
state or the expiration of the geometry regeneration interval.void
onChange(Message msg)
protected void
reset()
-
Methods inherited from class gov.nasa.worldwind.ogc.kml.KMLAbstractObject
getId, getRoot, getTargetId, onMessage
-
Methods inherited from class gov.nasa.worldwind.util.xml.AbstractXMLEventParser
allocate, doAddCharacters, doAddEventAttribute, doAddEventContent, doParseEventAttributes, doParseEventContent, freeResources, getAConstructor, getCharacters, getField, getField, getFields, getNamespaceURI, getParent, hasField, hasField, hasFields, mergeFields, newInstance, overrideFields, parse, parseCharacterContent, removeField, setField, setField, setFields, setNamespaceURI, setParent
-
-
-
-
Field Detail
-
DEFAULT_DATA_GENERATION_INTERVAL
protected static final int DEFAULT_DATA_GENERATION_INTERVAL
The default time in milliseconds aRegionData
element may exist in this Region'sregionDataCache
before it must be regenerated: 6 seconds.- See Also:
- Constant Field Values
-
DEFAULT_UNUSED_DATA_LIFETIME
protected static final int DEFAULT_UNUSED_DATA_LIFETIME
The default time in milliseconds aRegionData
element may exist in this Region'sregionDataCache
without being used before it is evicted: 1 minute.- See Also:
- Constant Field Values
-
DEFAULT_DETAIL_HINT_ORIGIN
protected static final double DEFAULT_DETAIL_HINT_ORIGIN
The default value that configures KML scene resolution to screen resolution as the viewing distance changes: 2.8.- See Also:
- Constant Field Values
-
maxExpiryTime
protected long maxExpiryTime
The maximum lifespan of this Region's computed data, in milliseconds. Initialized toDEFAULT_DATA_GENERATION_INTERVAL
.
-
minExpiryTime
protected long minExpiryTime
The minimum lifespan of this Region's computed data, in milliseconds. Initialized toDEFAULT_DATA_GENERATION_INTERVAL - 1000
.
-
regionDataCache
protected ShapeDataCache regionDataCache
Holds globe-dependent computed Region data. One entry per globe encountered duringisActive
. Initialized to a newShapeDataCache
withmaxTimeSinceLastUsed
set toDEFAULT_UNUSED_DATA_LIFETIME
.
-
currentData
protected KMLRegion.RegionData currentData
Identifies the active globe-dependent data for the current invocation ofisActive
. The active data is drawn from theregionDataCache
at the beginning of theisActive
method.
-
detailHintOrigin
protected double detailHintOrigin
The default value that configures KML scene resolution to screen resolution as the viewing distance changes. TheKMLRoot's
detail hint specifies deviations from this default. InitiallyDEFAULT_DETAIL_HINT_ORIGIN
.
-
-
Constructor Detail
-
KMLRegion
public KMLRegion(java.lang.String namespaceURI)
Creates a newKMLRegion
with the specified namespace URI, but otherwise does nothing. The new Region has no bounding box and no level of detail range.- Parameters:
namespaceURI
- the qualifying namespace URI. May benull
to indicate no namespace qualification.
-
-
Method Detail
-
getLatLonAltBox
public KMLLatLonAltBox getLatLonAltBox()
Indicates the bounding box that must be in view for this this Region to be considered active. May benull
.- Returns:
- this Region's geographic bounding box, or
null
indicating that this Region has no bounding box restriction.
-
getLod
public KMLLod getLod()
Indicates the level of detail criteria that must be satisfied for this Region to be considered active. May benull
.- Returns:
- this Region's level of detail range, or
null
indicating that this Region has no level of detail restriction.
-
isActive
public boolean isActive(KMLTraversalContext tc, DrawContext dc)
Indicates whether this Region is active on the specifiedDrawContext
. A Region is active if its bounding box intersects the viewing frustum, and its level of detail criteria are met for the specified traversal context and draw context.This always returns
true
if this Region has no bounding box, or if its bounding box is in the viewing frustum and this Region has no lod criteria.- Parameters:
tc
- the current KML traversal context.dc
- theDrawContext
used to determine whether this Region is active.- Returns:
true
if this Region is active; otherwisefalse
.- Throws:
java.lang.IllegalArgumentException
- if either theKMLTraversalContext
or theDrawContext
isnull
.
-
makeRegionData
protected void makeRegionData(DrawContext dc)
Produces the data used to determine whether this Region is active for the specifiedDrawContext
. This attempts to re-useRegionData
already been calculated this frame, or previously calculatedRegionData
that is still valid and has not expired. This method is called byisActive
prior to determining if this Region is actually active.- Parameters:
dc
- the current draw context.- See Also:
isActive(gov.nasa.worldwind.ogc.kml.impl.KMLTraversalContext, gov.nasa.worldwind.render.DrawContext)
-
getCurrentData
protected KMLRegion.RegionData getCurrentData()
Returns the data cache entry for the current invocation ofisActive
.- Returns:
- the data cache entry for the current invocation of
isActive
.
-
createCacheEntry
protected KMLRegion.RegionData createCacheEntry(DrawContext dc)
Creates and returns a newRegionData
instance specific to this Region instance.- Parameters:
dc
- the current draw context.- Returns:
- data cache entry for the state in the specified draw context.
-
mustRegenerateData
protected boolean mustRegenerateData(DrawContext dc)
Indicates whether this Region's data must be recomputed, either as a result of a change in theGlobe's
state or the expiration of the geometry regeneration interval.A
must be current when this method is called.KMLRegion.RegionData
- Parameters:
dc
- the current draw context.- Returns:
true
if this Region's data must be regenerated, otherwisefalse
.
-
doMakeRegionData
protected void doMakeRegionData(DrawContext dc)
Produces the data used to determine whether this Region is active for the specifiedDrawContext
. This method is called bymakeRegionData
upon determining that the current RegionData must be recomputed, either as a result of a change in theGlobe's
state or the expiration of the geometry regeneration interval. A
must be current when this method is called.KMLRegion.RegionData
- Parameters:
dc
- the current draw context.- See Also:
makeRegionData(gov.nasa.worldwind.render.DrawContext)
-
doMakeClampToGroundRegionData
protected void doMakeClampToGroundRegionData(DrawContext dc, KMLLatLonAltBox box)
Produces theExtent
and theSector
for this Region. Assumes this region's altitude mode isclampToGround
. A
must be current when this method is called.KMLRegion.RegionData
- Parameters:
dc
- the current draw context.box
- the Region's geographic bounding box.
-
doMakeRelativeToGroundRegionData
protected void doMakeRelativeToGroundRegionData(DrawContext dc, KMLLatLonAltBox box)
Produces theExtent
and theSector
for this Region. Assumes this region's altitude mode isrelativeToGround
. A
must be current when this method is called.KMLRegion.RegionData
- Parameters:
dc
- the current draw context.box
- the Region's geographic bounding box.
-
doMakeAbsoluteRegionData
protected void doMakeAbsoluteRegionData(DrawContext dc, KMLLatLonAltBox box)
Produces theExtent
and theSector
for this Region. Assumes this region's altitude mode isabsolute
. A
must be current when this method is called.KMLRegion.RegionData
- Parameters:
dc
- the current draw context.box
- the Region's geographic bounding box.
-
isSectorSupported
protected boolean isSectorSupported(Sector sector)
Determines if a Sector is supported by this Region implementation. This implementation does not support sectors with latitude values outside of [-90, 90], or longitude values outside of [-180, 180].- Parameters:
sector
- Sector to test.- Returns:
true
ifsector
is with [-90, 90] latitude and [-180, 180] longitude.
-
isRegionActive
protected boolean isRegionActive(KMLTraversalContext tc, DrawContext dc)
Indicates whether this Region is active on the specifiedDrawContext
. A Region is active if its bounding box intersects the viewing frustum, and its level of detail criteria are met for the specified traversal context and draw context. This is called byisActive
and its return value may be cached during a single frame.- Parameters:
tc
- the current KML traversal context.dc
- theDrawContext
used to determine whether this Region is active.- Returns:
true
if this Region is active; otherwisefalse
.
-
isRegionVisible
protected boolean isRegionVisible(DrawContext dc)
Indicates whether this Region is visible for the specifiedDrawContext
. If this Region'saltitudeMode
isclampToGround
, this Region is considered visible if its sector intersects theDrawContext's
visible sector and its frustum intersects theDrawContext's
viewing frustum. Otherwise, this Region is considered visible its frustum intersects theDrawContext's
viewing frustum.- Parameters:
dc
- theDrawContext
used to test this Region for visibility.- Returns:
true
if this Region is visible, otherwisefalse
.
-
intersectsFrustum
protected boolean intersectsFrustum(DrawContext dc)
Indicates whether this Region intersects the viewing frustum for the specifiedDrawContext
. A
must be current when this method is called.KMLRegion.RegionData
This returns
true
if this Region has no bounding box, or if its bounding box cannot be computed for any reason.- Parameters:
dc
- theDrawContext
who's frustum is tested against this Region's bounding box.- Returns:
true
if this Region's bounding box intersects theDrawContext's
frustum, otherwisefalse
.
-
meetsLodCriteria
protected boolean meetsLodCriteria(KMLTraversalContext tc, DrawContext dc)
Indicates whether the specifiedDrawContext
meets this Region's level of detail criteria. A
must be current when this method is called.KMLRegion.RegionData
This returns
true
if this Region has no level of criteria, or if its level of detail cannot be compared against the bounding box for any reason.- Parameters:
tc
- the current KML traversal context.dc
- theDrawContext
to test.- Returns:
true
if theDrawContext's
meets this Region's level of detail criteria, otherwisefalse
.
-
meetsClampToGroundLodCriteria
protected boolean meetsClampToGroundLodCriteria(KMLTraversalContext tc, DrawContext dc, KMLLod lod)
Indicates whether the specifiedDrawContext
meets this Region's level of detail criteria. Assumes this region's altitude mode isclampToGround
. A
must be current when this method is called.KMLRegion.RegionData
- Parameters:
tc
- the current KML traversal context.dc
- theDrawContext
to test.lod
- the level of detail criteria that must be met.- Returns:
true
if theDrawContext's
meets this Region's level of detail criteria, otherwisefalse
.
-
meetsRelativeToGroundLodCriteria
protected boolean meetsRelativeToGroundLodCriteria(KMLTraversalContext tc, DrawContext dc, KMLLod lod)
Indicates whether the specifiedDrawContext
meets this Region's level of detail criteria. Assumes this region's altitude mode isrelativeToGround
. A
must be current when this method is called.KMLRegion.RegionData
- Parameters:
tc
- the current KML traversal context.dc
- theDrawContext
to test.lod
- the level of detail criteria that must be met.- Returns:
true
if theDrawContext's
meets this Region's level of detail criteria, otherwisefalse
.
-
meetsAbsoluteLodCriteria
protected boolean meetsAbsoluteLodCriteria(KMLTraversalContext tc, DrawContext dc, KMLLod lod)
Indicates whether the specifiedDrawContext
meets this Region's level of detail criteria. Assumes this region's altitude mode isabsolute
. A
must be current when this method is called.KMLRegion.RegionData
- Parameters:
tc
- the current KML traversal context.dc
- theDrawContext
to test.lod
- the level of detail criteria that must be met.- Returns:
true
if theDrawContext's
meets this Region's level of detail criteria, otherwisefalse
.
-
meetsScreenAreaCriteria
protected boolean meetsScreenAreaCriteria(DrawContext dc, KMLLod lod)
Indicates whether this Region's projected screen area on the specifiedDrawContext
is in the range specified bylod
.- Parameters:
dc
- theDrawContext
to test.lod
- the level of detail criteria that must be met.- Returns:
true
if this Region's screen area meets the level of detail criteria, otherwisefalse
.
-
getDetailFactor
protected double getDetailFactor(KMLTraversalContext tc)
Indicates the detail factor that configures KML scene resolution to screen resolution as the viewing distance changes. This returns the Region'sdetailHintOrigin
plus theKMLTraversalContext's
detail hint.- Parameters:
tc
- the KML traversal context that specifies the detail hint.- Returns:
- this Region's
detailHintOrigin
plus the traversal context'sdetailHintOrigin
.
-
applyChange
public void applyChange(KMLAbstractObject sourceValues)
- Overrides:
applyChange
in classKMLAbstractObject
-
onChange
public void onChange(Message msg)
- Overrides:
onChange
in classKMLAbstractObject
-
reset
protected void reset()
-
-