/// <summary> /// Constructor. /// </summary> /// <param name="tile">TerrainTile to be cached.</param> public TerrainTileCacheEntry(TerrainTile tile) { m_terrainTile = tile; }
/// <summary> /// Builds a terrain array with specified boundaries /// </summary> /// <param name="north">North edge in decimal degrees.</param> /// <param name="south">South edge in decimal degrees.</param> /// <param name="west">West edge in decimal degrees.</param> /// <param name="east">East edge in decimal degrees.</param> /// <param name="samples"></param> public override TerrainTile GetElevationArray(float north, float south, float west, float east, int samples) { TerrainTile res = null; if (m_higherResolutionSubsets != null) { // TODO: Support more than 1 level of higher resolution sets and allow user selections foreach (TerrainAccessor higherResSub in m_higherResolutionSubsets) { if (north <= higherResSub.North && south >= higherResSub.South && west >= higherResSub.West && east <= higherResSub.East) { res = higherResSub.GetElevationArray(north, south, west, east, samples); return(res); } } } res = new TerrainTile(m_terrainTileService); res.North = north; res.South = south; res.West = west; res.East = east; res.SamplesPerTile = samples; res.IsInitialized = true; res.IsValid = true; float samplesPerDegree = (samples / (north - south)); float latrange = Math.Abs(north - south); float lonrange = Math.Abs(east - west); TerrainTileCacheEntry ttce = null; res.ElevationData = new List <float>(samples * samples); if (samplesPerDegree < 3.0) { return(null); } float scaleFactor = 1.0f / (samples - 1); float curLat, curLon; for (int y = 0; y < samples; y++) { for (int x = 0; x < samples; x++) { curLat = north - scaleFactor * latrange * x; curLon = west + scaleFactor * lonrange * y; if (ttce == null || curLat < ttce.TerrainTile.South || curLat > ttce.TerrainTile.North || curLon < ttce.TerrainTile.West || curLon > ttce.TerrainTile.East) { TerrainTile tt = m_terrainTileService.GetTerrainTile(curLat, curLon, samplesPerDegree); ttce = (TerrainTileCacheEntry)m_tileCache[tt.TerrainTileFilePath]; if (ttce == null) { ttce = new TerrainTileCacheEntry(tt); AddToCache(ttce); } if (!ttce.TerrainTile.IsInitialized) { ttce.TerrainTile.Initialize(); } ttce.LastAccess = DateTime.Now; if (!tt.IsValid) { res.IsValid = false; } } res.ElevationData.Add(ttce.TerrainTile.GetElevationAt(curLat, curLon)); } } return(res); }