Skip to content

Commit

Permalink
engine: guess an appropriate zoom level when going to an imageset-as-…
Browse files Browse the repository at this point in the history
…layer
  • Loading branch information
pkgw committed Aug 31, 2021
1 parent af549c8 commit aeb5dc0
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 30 deletions.
88 changes: 60 additions & 28 deletions engine/wwtlib/Imageset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace wwtlib
{
public class Imageset : IThumbnail
{
// This is probably an `object` and not `WcsImage` for historical reasons?
private object wcsImage;

public object WcsImage
Expand Down Expand Up @@ -88,7 +89,7 @@ public ProjectionType Projection
get { return projection; }
set { projection = value; }
}

private string referenceFrame;

public string ReferenceFrame
Expand Down Expand Up @@ -139,7 +140,7 @@ public double WidthFactor

public int GetHashCode()
{

return Util.GetHashCode(Url);
}

Expand Down Expand Up @@ -304,8 +305,8 @@ public ImageSetType DataSetType
node.Attributes.GetNamedItem("").Value,
Convert.ToDouble(node.Attributes.GetNamedItem("").Value),
Convert.ToInt32(node.Attributes.GetNamedItem("").Value),
* */
string altUrl = "";

Expand Down Expand Up @@ -354,7 +355,7 @@ public static Imageset FromXMLNode(XmlNode node)
BandPass bandPass = BandPass.Visible;

bandPass = (BandPass)Enums.Parse("BandPass",node.Attributes.GetNamedItem("BandPass").Value);

int wf = 1;
if (node.Attributes.GetNamedItem("WidthFactor") != null)
{
Expand All @@ -364,7 +365,7 @@ public static Imageset FromXMLNode(XmlNode node)
if (node.Attributes.GetNamedItem("Generic") == null || !bool.Parse(node.Attributes.GetNamedItem("Generic").Value.ToString()))
{
projection = (ProjectionType)Enums.Parse("ProjectionType", node.Attributes.GetNamedItem("Projection").Value);

string fileType = node.Attributes.GetNamedItem("FileType").Value.ToString();
if (!fileType.StartsWith("."))
{
Expand Down Expand Up @@ -642,16 +643,16 @@ public Imageset StockImageSet
// if (left == null ^ right == null)
// {
// return false;
// }
// return (left.Url.GetHashCode() == right.Url.GetHashCode());
// }
// return (left.Url.GetHashCode() == right.Url.GetHashCode());
//}

//public static bool operator !=(ImageSet left, ImageSet right)
//{
// if (left == right )
// {
// return false;
// }
// }
// if ( left == null ^ right == null)
// {
// return true;
Expand Down Expand Up @@ -684,7 +685,7 @@ public bool Equals(object obj)
Imageset b = (Imageset)obj;

return (Util.GetHashCode(b.Url) == Util.GetHashCode(this.Url) && b.DataSetType == this.DataSetType && b.BandPass == this.BandPass && b.Generic == this.Generic);

}

private Matrix3d matrix;
Expand Down Expand Up @@ -767,7 +768,7 @@ public static Imageset CreateGeneric(ImageSetType dataSetType, BandPass bandPass
temp.rotation = 0;
//todo add scale
temp.thumbnailUrl = "";

temp.matrix = Matrix3d.Identity;
temp.matrix.Multiply(Matrix3d.RotationX((((temp.Rotation)) / 180f * Math.PI)));
temp.matrix.Multiply(Matrix3d.RotationZ(((temp.CenterY) / 180f * Math.PI)));
Expand Down Expand Up @@ -831,8 +832,6 @@ public bool IsMandelbrot
}
}



public static Imageset Create(string name, string url, ImageSetType dataSetType, BandPass bandPass, ProjectionType projection, int imageSetID, int baseLevel, int levels, int tileSize, double baseTileDegrees, string extension, bool bottomsUp, string quadTreeMap, double centerX, double centerY, double rotation, bool sparse, string thumbnailUrl, bool defaultSet, bool elevationModel, int wf, double offsetX, double offsetY, string credits, string creditsUrl, string demUrlIn, string alturl, double meanRadius, string referenceFrame)
{
Imageset temp = new Imageset();
Expand Down Expand Up @@ -876,28 +875,61 @@ public void SetInitialParameters(string name, string url, ImageSetType dataSetTy
this.ComputeMatrix();
}

// Ideally, imagesets will be associated with Places that specify
// exactly how the view should be set up when "going to" them, but
// sometimes (especially research datasets) we're interested in deriving
// a reasonable zoom setting without that extra information. The returned value
// isn't going to be perfect but it should hopefully be OK.

private const double FOV_FACTOR = 1.7;

// URL parameters
//{0} ImageSetID
//{1} level
//{2} x tile id
//{3} y tile id
//{4} quadtree address (VE style)
//{5} quadtree address (Google maps style)
//{6} top left corner RA
//{7} top left corner Dec
//{8} bottom right corner RA
//{9} bottom right corner dec
//{10} bottom left corner RA
//{11} bottom left corner dec
//{12} top right corner RA
//{13} top right corner dec
internal double GuessZoomSetting(double currentZoom)
{
double zoom = currentZoom;

// ScriptSharp has an issue here. Maybe because we have a field name
// matching a class name? Right now the only implementation of
// WcsImage is FitsImage so we can get away with this:
WcsImage aswcs = this.wcsImage as FitsImage;

if (Projection == ProjectionType.SkyImage) {
// Untiled SkyImage: basetiledegrees is degrees per pixel
if (aswcs != null) {
zoom = BaseTileDegrees * aswcs.SizeY * 6 * FOV_FACTOR;
}
} else if (aswcs != null) {
zoom = aswcs.ScaleY * aswcs.SizeY * 6 * FOV_FACTOR;
} else {
// Tiled. basetiledegrees is angular height of whole image after
// power-of-2 padding.
zoom = BaseTileDegrees * 6 * FOV_FACTOR;
}

// Only zoom in, not out. Usability-wise this tends to make the most
// sense.

if (zoom > currentZoom) {
zoom = currentZoom;
}

return zoom;
}

// URL parameters
//{0} ImageSetID
//{1} level
//{2} x tile id
//{3} y tile id
//{4} quadtree address (VE style)
//{5} quadtree address (Google maps style)
//{6} top left corner RA
//{7} top left corner Dec
//{8} bottom right corner RA
//{9} bottom right corner dec
//{10} bottom left corner RA
//{11} bottom left corner dec
//{12} top right corner RA
//{13} top right corner dec

#region IThumbnail Members

Expand Down
17 changes: 15 additions & 2 deletions engine/wwtlib/ScriptInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,12 @@ private static ImageSetLayer AddImageSet(string name, bool gotoTarget, ImagesetL

if (gotoTarget)
{
double zoom = imageset.GuessZoomSetting(WWTControl.Singleton.RenderContext.ViewCamera.Zoom);

WWTControl.Singleton.GotoRADecZoom(
imageset.CenterX / 15,
imageset.CenterY,
WWTControl.Singleton.RenderContext.ViewCamera.Zoom,
zoom,
false,
null
);
Expand Down Expand Up @@ -439,15 +441,26 @@ private static ImageSetLayer AddFitsLayer(string url, string name, bool gotoTarg
imageset.WcsImage = wcsImage;
imagesetLayer.ImageSet = imageset;
LayerManager.AddFitsImageSetLayer(imagesetLayer, name);

if (gotoTarget)
{
WWTControl.Singleton.GotoRADecZoom(wcsImage.CenterX / 15, wcsImage.CenterY, 10 * wcsImage.ScaleY * height, false, null);
double zoom = imageset.GuessZoomSetting(WWTControl.Singleton.RenderContext.ViewCamera.Zoom);

WWTControl.Singleton.GotoRADecZoom(
wcsImage.CenterX / 15,
wcsImage.CenterY,
zoom,
false,
null
);
}

if (loaded != null)
{
loaded(imagesetLayer);
}
};

if (string.IsNullOrWhiteSpace(name))
{
name = LayerManager.GetNextFitsName();
Expand Down

0 comments on commit aeb5dc0

Please sign in to comment.