Use IPlateTIlePyramid in Hirise (#126)
This commit is contained in:
Родитель
e5a3ef6055
Коммит
5e74703b65
|
@ -1,69 +1,12 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using WWTWebservices;
|
||||
|
||||
namespace WWT.Providers
|
||||
{
|
||||
public abstract partial class HiRise : RequestProvider
|
||||
{
|
||||
private static MD5 md5Hash = MD5.Create();
|
||||
|
||||
public Bitmap DownloadBitmap(string dataset, int level, int x, int y)
|
||||
{
|
||||
string id = "1738422189";
|
||||
switch (dataset)
|
||||
{
|
||||
case "mars_base_map":
|
||||
id = "1738422189";
|
||||
break;
|
||||
case "mars_terrain_color":
|
||||
id = "220581050";
|
||||
break;
|
||||
case "mars_hirise":
|
||||
id = "109459728";
|
||||
break;
|
||||
case "mars_moc":
|
||||
id = "252927426";
|
||||
break;
|
||||
case "mars_historic_green":
|
||||
id = "1194136815";
|
||||
break;
|
||||
case "mars_historic_schiaparelli":
|
||||
id = "1113282550";
|
||||
break;
|
||||
case "mars_historic_lowell":
|
||||
id = "675790761";
|
||||
break;
|
||||
case "mars_historic_antoniadi":
|
||||
id = "1648157275";
|
||||
break;
|
||||
case "mars_historic_mec1":
|
||||
id = "2141096698";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
string filename = String.Format("\\wwtcache\\mars\\{3}\\{0}\\{2}\\{1}_{2}.png", level, x, y,
|
||||
id);
|
||||
string path = String.Format("\\wwtcache\\mars\\{3}\\{0}\\{2}", level, x, y, id);
|
||||
|
||||
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Bitmap(filename);
|
||||
}
|
||||
|
||||
public UInt32 ComputeHash(int level, int x, int y)
|
||||
public uint ComputeHash(int level, int x, int y)
|
||||
{
|
||||
return DirectoryEntry.ComputeHash(level + 128, x, y);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using WWTWebservices;
|
||||
|
||||
|
@ -7,6 +6,11 @@ namespace WWT.Providers
|
|||
{
|
||||
public class HiriseDem2Provider : HiriseDem2
|
||||
{
|
||||
public HiriseDem2Provider(IPlateTilePyramid plateTiles, FilePathOptions options)
|
||||
: base(plateTiles, options)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Run(IWwtContext context)
|
||||
{
|
||||
string query = context.Request.Params["Q"];
|
||||
|
@ -15,63 +19,46 @@ namespace WWT.Providers
|
|||
int tileX = Convert.ToInt32(values[1]);
|
||||
int tileY = Convert.ToInt32(values[2]);
|
||||
|
||||
string wwtTilesDir = ConfigurationManager.AppSettings["WWTTilesDir"];
|
||||
string DSSTileCache = ConfigurationManager.AppSettings["DSSTileCache"];
|
||||
|
||||
DSSTileCache = @"\\wwt-mars\marsroot";
|
||||
|
||||
string filename = String.Format(DSSTileCache + "\\dem\\Merged4\\{0}\\{1}\\DL{0}X{1}Y{2}.dem", level, tileX, tileY);
|
||||
|
||||
string path = String.Format(DSSTileCache + "\\dem\\Merged4\\{0}\\{1}\\", level, tileX, tileY);
|
||||
|
||||
|
||||
string filename = $@"\\wwt-mars\marsroot\dem\Merged4\{level}\{tileX}\DL{level}X{tileX}Y{tileY}.dem";
|
||||
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
Stream stream = File.OpenRead(filename);
|
||||
Stream s = MergeMolaDemTileStream(level, tileX, tileY, stream);
|
||||
|
||||
int length = (int)s.Length;
|
||||
if (length == 0)
|
||||
using (Stream stream = File.OpenRead(filename))
|
||||
using (Stream s = MergeMolaDemTileStream(level, tileX, tileY, stream))
|
||||
{
|
||||
if (s.Length == 0)
|
||||
{
|
||||
context.Response.Clear();
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.Write("No image");
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
|
||||
context.Response.Clear();
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.Write("No image");
|
||||
s.CopyTo(context.Response.OutputStream);
|
||||
context.Response.Flush();
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
byte[] data = new byte[length];
|
||||
s.Read(data, 0, length);
|
||||
context.Response.OutputStream.Write(data, 0, length);
|
||||
context.Response.Flush();
|
||||
context.Response.End();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
|
||||
Stream ss = GetMolaDemTileStream(level, tileX, tileY);
|
||||
|
||||
int len = (int)ss.Length;
|
||||
if (len == 0)
|
||||
using (Stream ss = GetMolaDemTileStream(level, tileX, tileY))
|
||||
{
|
||||
if (ss.Length == 0)
|
||||
{
|
||||
context.Response.Clear();
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.Write("No image");
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
|
||||
context.Response.Clear();
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.Write("No image");
|
||||
ss.CopyTo(context.Response.OutputStream);
|
||||
context.Response.Flush();
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
byte[] data = new byte[len];
|
||||
ss.Read(data, 0, len);
|
||||
context.Response.OutputStream.Write(data, 0, len);
|
||||
context.Response.Flush();
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using WWTWebservices;
|
||||
|
||||
|
@ -7,6 +6,15 @@ namespace WWT.Providers
|
|||
{
|
||||
public class HiriseDem3Provider : RequestProvider
|
||||
{
|
||||
private readonly IPlateTilePyramid _plateTiles;
|
||||
private readonly FilePathOptions _options;
|
||||
|
||||
public HiriseDem3Provider(IPlateTilePyramid plateTiles, FilePathOptions options)
|
||||
{
|
||||
_plateTiles = plateTiles;
|
||||
_options = options;
|
||||
}
|
||||
|
||||
public override void Run(IWwtContext context)
|
||||
{
|
||||
string query = context.Request.Params["Q"];
|
||||
|
@ -15,40 +23,27 @@ namespace WWT.Providers
|
|||
int tileX = Convert.ToInt32(values[1]);
|
||||
int tileY = Convert.ToInt32(values[2]);
|
||||
|
||||
string file = "marsToastDem";
|
||||
string wwtTilesDir = ConfigurationManager.AppSettings["WWTTilesDir"];
|
||||
string DSSTileCache = ConfigurationManager.AppSettings["DSSTileCache"];
|
||||
|
||||
DSSTileCache = @"\\wwt-mars\marsroot";
|
||||
|
||||
string filename = String.Format(DSSTileCache + "\\dem\\Merged4\\{0}\\{1}\\DL{0}X{1}Y{2}.dem", level, tileX, tileY);
|
||||
|
||||
string path = String.Format(DSSTileCache + "\\dem\\Merged4\\{0}\\{1}\\", level, tileX, tileY);
|
||||
|
||||
|
||||
string filename = $@"\\wwt-mars\marsroot\dem\Merged4\{level}\{tileX}\DL{level}X{tileX}Y{tileY}.dem";
|
||||
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
context.Response.ContentType = "image/png";
|
||||
Stream s = PlateFile2.GetFileStream(String.Format(wwtTilesDir + "\\{0}.plate", file), -1, level, tileX, tileY);
|
||||
|
||||
int length = (int)s.Length;
|
||||
if (length == 0)
|
||||
using (Stream s = _plateTiles.GetStream(_options.WwtTilesDir, "marsToastDem.plate", -1, level, tileX, tileY))
|
||||
{
|
||||
if (s.Length == 0)
|
||||
{
|
||||
context.Response.Clear();
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.Write("No image");
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
|
||||
context.Response.Clear();
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.Write("No image");
|
||||
s.CopyTo(context.Response.OutputStream);
|
||||
context.Response.Flush();
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
byte[] data = new byte[length];
|
||||
s.Read(data, 0, length);
|
||||
context.Response.OutputStream.Write(data, 0, length);
|
||||
context.Response.Flush();
|
||||
context.Response.End();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
context.Response.WriteFile(filename);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using WWTWebservices;
|
||||
|
||||
|
@ -7,6 +6,15 @@ namespace WWT.Providers
|
|||
{
|
||||
public class HiriseDemProvider : RequestProvider
|
||||
{
|
||||
private readonly IPlateTilePyramid _plateTiles;
|
||||
private readonly FilePathOptions _options;
|
||||
|
||||
public HiriseDemProvider(IPlateTilePyramid plateTiles, FilePathOptions options)
|
||||
{
|
||||
_plateTiles = plateTiles;
|
||||
_options = options;
|
||||
}
|
||||
|
||||
public override void Run(IWwtContext context)
|
||||
{
|
||||
string query = context.Request.Params["Q"];
|
||||
|
@ -15,40 +23,27 @@ namespace WWT.Providers
|
|||
int tileX = Convert.ToInt32(values[1]);
|
||||
int tileY = Convert.ToInt32(values[2]);
|
||||
|
||||
string file = "marsToastDem";
|
||||
string wwtTilesDir = ConfigurationManager.AppSettings["WWTTilesDir"];
|
||||
string DSSTileCache = ConfigurationManager.AppSettings["DSSTileCache"];
|
||||
|
||||
DSSTileCache = @"\\wwt-mars\marsroot";
|
||||
|
||||
string filename = String.Format(DSSTileCache + "\\dem\\Merged4\\{0}\\{1}\\DL{0}X{1}Y{2}.dem", level, tileX, tileY);
|
||||
|
||||
string path = String.Format(DSSTileCache + "\\dem\\Merged4\\{0}\\{1}\\", level, tileX, tileY);
|
||||
|
||||
|
||||
string filename = $@"\\wwt-mars\marsroot\dem\Merged4\{level}\{tileX}\DL{level}X{tileX}Y{tileY}.dem";
|
||||
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
context.Response.ContentType = "image/png";
|
||||
Stream s = PlateFile2.GetFileStream(String.Format(wwtTilesDir + "\\{0}.plate", file), -1, level, tileX, tileY);
|
||||
|
||||
int length = (int)s.Length;
|
||||
if (length == 0)
|
||||
using (Stream s = _plateTiles.GetStream(_options.WwtTilesDir, $"marsToastDem.plate", -1, level, tileX, tileY))
|
||||
{
|
||||
if (s.Length == 0)
|
||||
{
|
||||
context.Response.Clear();
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.Write("No image");
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
|
||||
context.Response.Clear();
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.Write("No image");
|
||||
s.CopyTo(context.Response.OutputStream);
|
||||
context.Response.Flush();
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
byte[] data = new byte[length];
|
||||
s.Read(data, 0, length);
|
||||
context.Response.OutputStream.Write(data, 0, length);
|
||||
context.Response.Flush();
|
||||
context.Response.End();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
context.Response.WriteFile(filename);
|
||||
|
|
|
@ -6,6 +6,13 @@ namespace WWT.Providers
|
|||
{
|
||||
public class HiriseProvider : HiRise
|
||||
{
|
||||
private readonly IPlateTilePyramid _plateTiles;
|
||||
|
||||
public HiriseProvider(IPlateTilePyramid plateTiles)
|
||||
{
|
||||
_plateTiles = plateTiles;
|
||||
}
|
||||
|
||||
public override void Run(IWwtContext context)
|
||||
{
|
||||
string query = context.Request.Params["Q"];
|
||||
|
@ -20,24 +27,22 @@ namespace WWT.Providers
|
|||
|
||||
UInt32 index = ComputeHash(level, tileX, tileY) % 300;
|
||||
|
||||
|
||||
Stream s = PlateFile2.GetFileStream(String.Format(@"\\wwt-mars\marsroot\hirise\hiriseV5_{0}.plate", index), -1, level, tileX, tileY);
|
||||
|
||||
if (s == null || (int)s.Length == 0)
|
||||
using (Stream s = _plateTiles.GetStream(@"\\wwt-mars\marsroot\hirise", $"hiriseV5_{index}.plate", -1, level, tileX, tileY))
|
||||
{
|
||||
context.Response.Clear();
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.Write("No image");
|
||||
if (s == null || (int)s.Length == 0)
|
||||
{
|
||||
context.Response.Clear();
|
||||
context.Response.ContentType = "text/plain";
|
||||
context.Response.Write("No image");
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
|
||||
s.CopyTo(context.Response.OutputStream);
|
||||
context.Response.Flush();
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
int length = (int)s.Length;
|
||||
byte[] data = new byte[length];
|
||||
s.Read(data, 0, length);
|
||||
context.Response.OutputStream.Write(data, 0, length);
|
||||
context.Response.Flush();
|
||||
context.Response.End();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,6 @@ using WWTWebservices;
|
|||
|
||||
namespace WWT.Providers
|
||||
{
|
||||
|
||||
|
||||
|
||||
public abstract partial class HiriseDem2 : RequestProvider
|
||||
{
|
||||
private static byte[] backslashXIndex = new byte[]
|
||||
|
@ -93,7 +90,16 @@ namespace WWT.Providers
|
|||
14, 13
|
||||
};
|
||||
|
||||
public static Stream GetMolaDemTileStream(int level, int x, int y)
|
||||
private readonly IPlateTilePyramid _plateTiles;
|
||||
private readonly FilePathOptions _options;
|
||||
|
||||
public HiriseDem2(IPlateTilePyramid plateTiles, FilePathOptions options)
|
||||
{
|
||||
_plateTiles = plateTiles;
|
||||
_options = options;
|
||||
}
|
||||
|
||||
public Stream GetMolaDemTileStream(int level, int x, int y)
|
||||
{
|
||||
float[] dataOut = GetMolaDemTile(level, x, y);
|
||||
MemoryStream stream = new MemoryStream();
|
||||
|
@ -109,7 +115,7 @@ namespace WWT.Providers
|
|||
return stream;
|
||||
}
|
||||
|
||||
public static Stream MergeMolaDemTileStream(int level, int x, int y, Stream tile)
|
||||
public Stream MergeMolaDemTileStream(int level, int x, int y, Stream tile)
|
||||
{
|
||||
float[] dataIn = ReadDemStream(tile);
|
||||
|
||||
|
@ -136,7 +142,7 @@ namespace WWT.Providers
|
|||
return stream;
|
||||
}
|
||||
|
||||
private static float[] GetMolaDemTile(int level, int xx, int yy)
|
||||
private float[] GetMolaDemTile(int level, int xx, int yy)
|
||||
{
|
||||
float[] data = GetMolaDEMTileRaw(level, xx, yy);
|
||||
|
||||
|
@ -253,9 +259,10 @@ namespace WWT.Providers
|
|||
return demArray[(16 - y) * 17 + x];
|
||||
}
|
||||
|
||||
private static float[] GetMolaDEMTileRaw(int level, int x, int y)
|
||||
private float[] GetMolaDEMTileRaw(int level, int x, int y)
|
||||
{
|
||||
Stream stream = PlateFile2.GetFileStream(@"D:\WWTTiles\marsToastDem.plate", -1, level, x, y);
|
||||
Stream stream = _plateTiles.GetStream(_options.WwtTilesDir, "marsToastDem.plate", -1, level, x, y);
|
||||
|
||||
if (stream != null)
|
||||
{
|
||||
return ReadDemStream(stream);
|
||||
|
@ -276,7 +283,5 @@ namespace WWT.Providers
|
|||
br.Close();
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
using Castle.DynamicProxy.Contributors;
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using WWTWebservices;
|
||||
using Xunit;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using WWTWebservices;
|
||||
|
||||
namespace WWT.Providers.Tests
|
||||
{
|
||||
public class HiriseDem3ProviderTests : ProviderTests<HiriseDem3Provider>
|
||||
{
|
||||
protected override Action<IResponse> NullStreamResponseHandler => null;
|
||||
|
||||
protected override Action<IResponse> StreamExceptionResponseHandler => null;
|
||||
|
||||
protected override Stream GetStreamFromPlateTilePyramid(IPlateTilePyramid plateTiles, int level, int x, int y)
|
||||
=> plateTiles.GetStream(Options.WwtTilesDir, "marsToastDem.plate", -1, level, x, y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using WWTWebservices;
|
||||
|
||||
namespace WWT.Providers.Tests
|
||||
{
|
||||
public class HiriseDemProviderTests : ProviderTests<HiriseDemProvider>
|
||||
{
|
||||
protected override Action<IResponse> NullStreamResponseHandler => null;
|
||||
|
||||
protected override Action<IResponse> StreamExceptionResponseHandler => null;
|
||||
|
||||
protected override Stream GetStreamFromPlateTilePyramid(IPlateTilePyramid plateTiles, int level, int x, int y)
|
||||
=> plateTiles.GetStream(Options.WwtTilesDir, "marsToastDem.plate", -1, level, x, y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using WWTWebservices;
|
||||
using Xunit;
|
||||
|
||||
namespace WWT.Providers.Tests
|
||||
{
|
||||
public class HiriseProviderTests : ProviderTests<HiriseProvider>
|
||||
{
|
||||
protected override int MaxLevel => 18;
|
||||
|
||||
protected override Action<IResponse> StreamExceptionResponseHandler => null;
|
||||
|
||||
protected override void ExpectedResponseAboveMaxLevel(IResponse response)
|
||||
{
|
||||
Assert.Empty(response.OutputStream.ToArray());
|
||||
}
|
||||
|
||||
protected override Stream GetStreamFromPlateTilePyramid(IPlateTilePyramid plateTiles, int level, int x, int y)
|
||||
{
|
||||
var index = DirectoryEntry.ComputeHash(level + 128, x, y) % 300;
|
||||
|
||||
return plateTiles.GetStream(@"\\wwt-mars\marsroot\hirise", $"hiriseV5_{index}.plate", -1, level, x, y);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ namespace WWT.Providers.Tests
|
|||
|
||||
protected FilePathOptions Options { get; }
|
||||
|
||||
protected abstract int MaxLevel { get; }
|
||||
protected virtual int MaxLevel => -1;
|
||||
|
||||
protected virtual Action<IResponse> StreamExceptionResponseHandler { get; } = response =>
|
||||
{
|
||||
|
@ -75,7 +75,9 @@ namespace WWT.Providers.Tests
|
|||
[Fact]
|
||||
public void ErrorInStream()
|
||||
{
|
||||
foreach (var level in Enumerable.Range(0, MaxLevel))
|
||||
var maxLevel = MaxLevel < 0 ? 10 : MaxLevel;
|
||||
|
||||
foreach (var level in Enumerable.Range(0, maxLevel))
|
||||
{
|
||||
// Arrange
|
||||
var data = _fixture.CreateMany<byte>().ToArray();
|
||||
|
@ -166,6 +168,11 @@ namespace WWT.Providers.Tests
|
|||
[Fact]
|
||||
public void AboveMaxLevel()
|
||||
{
|
||||
if (MaxLevel < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var level in GetLevelsAboveMax())
|
||||
{
|
||||
// Arrange
|
||||
|
|
Загрузка…
Ссылка в новой задаче