Example #1
0
        public double GetScaledAltitudeForLatLong(double viewLat, double viewLong)
        {
            Imageset layer = BackgroundImageset;

            if (layer == null)
            {
                return(0);
            }

            int maxX = GetTilesXForLevel(layer, layer.BaseLevel);
            int maxY = GetTilesYForLevel(layer, layer.BaseLevel);

            for (int x = 0; x < maxX; x++)
            {
                for (int y = 0; y < maxY; y++)
                {
                    Tile tile = TileCache.GetTile(layer.BaseLevel, x, y, layer, null);
                    if (tile != null)
                    {
                        if (tile.IsPointInTile(viewLat, viewLong))
                        {
                            return(tile.GetSurfacePointAltitude(viewLat, viewLong, false));
                        }
                    }
                }
            }
            return(0);
        }
Example #2
0
        public double GetAltitudeForLatLongForPlanet(int planetID, double viewLat, double viewLong)
        {
            Imageset layer = WWTControl.Singleton.GetImagesetByName(Planets.GetNameFrom3dId(planetID));

            if (layer == null)
            {
                return(0);
            }

            int maxX = GetTilesXForLevel(layer, layer.BaseLevel);
            int maxY = GetTilesYForLevel(layer, layer.BaseLevel);

            for (int x = 0; x < maxX; x++)
            {
                for (int y = 0; y < maxY; y++)
                {
                    Tile tile = TileCache.GetTile(layer.BaseLevel, x, y, layer, null);
                    if (tile != null)
                    {
                        if (tile.IsPointInTile(viewLat, viewLong))
                        {
                            return(tile.GetSurfacePointAltitude(viewLat, viewLong, true));
                        }
                    }
                }
            }
            return(0);
        }
Example #3
0
        private Tile GetTileAtLatLong(double viewLat, double viewLong)
        {
            Imageset layer = BackgroundImageset;

            if (layer == null)
            {
                return(null);
            }

            int maxX = GetTilesXForLevel(layer, layer.BaseLevel);
            int maxY = GetTilesYForLevel(layer, layer.BaseLevel);

            for (int x = 0; x < maxX; x++)
            {
                for (int y = 0; y < maxY; y++)
                {
                    Tile tile = TileCache.GetTile(layer.BaseLevel, x, y, layer, null);
                    if (tile != null)
                    {
                        if (tile.IsPointInTile(viewLat, viewLong))
                        {
                            return(tile);
                        }
                    }
                }
            }
            return(null);
        }
Example #4
0
        public void Show(Vector2d position)
        {
            tile = (SkyImageTile)TileCache.GetTile(0, 0, 0, layer.ImageSet, null);

            DivElement picker   = Document.GetElementById <DivElement>("histogram");
            DivElement closeBtn = Document.GetElementById <DivElement>("histogramClose");

            /////////////picker.ClassName = "histogram";
            picker.Style.Display = "block";
            picker.Style.Left    = position.X.ToString() + "px";
            picker.Style.Top     = position.Y.ToString() + "px";

            SelectedCurveStyle = (int)image.lastScale;


            dropDown = Document.GetElementById <SelectElement>("ScaleTypePicker");

            dropDown.AddEventListener("change", CurveStyleSelected, false);
            dropDown.AddEventListener("click", IgnoreMe, true);
            CanvasElement canvas = Document.GetElementById <CanvasElement>("graph");

            canvas.AddEventListener("mousedown", MouseDown, false);
            canvas.AddEventListener("mousemove", mousemove, false);
            canvas.AddEventListener("mouseup", mouseup, false);
            closeBtn.AddEventListener("click", Close, true);

            Draw();
        }
 public override void RequestImage()
 {
     fitsImage = dataset.WcsImage as FitsImage;
     if (fitsImage != null)
     {
         texReady       = true;
         Downloading    = false;
         errored        = fitsImage.errored;
         RequestPending = false;
         TileCache.RemoveFromQueue(this.Key, true);
         if (RenderContext.UseGlVersion2)
         {
             MakeTexture();
             ReadyToRender = true;
         }
         else
         {
             bmp           = fitsImage.GetBitmap();
             texture2d     = bmp.GetTexture();
             ReadyToRender = true;
         }
     }
     else
     {
         base.RequestImage();
     }
 }
Example #6
0
        private void TryGetAllDataInView(Imageset imageset, bool limit, CatalogSpreadSheetLayer catalogSpreadSheetLayer, Action <InViewReturnMessage> onComplete, int i)
        {
            int  maxX = GetTilesXForLevel(imageset, imageset.BaseLevel);
            int  maxY = GetTilesYForLevel(imageset, imageset.BaseLevel);
            bool anyTileStillDownloading = false;

            for (int x = 0; x < maxX; x++)
            {
                for (int y = 0; y < maxY; y++)
                {
                    Tile tile = TileCache.GetTile(imageset.BaseLevel, x, y, imageset, null);
                    if (tile != null)
                    {
                        bool tileAndChildrenReady = ((HealpixTile)tile).GetDataInView(this, limit, catalogSpreadSheetLayer);
                        anyTileStillDownloading = anyTileStillDownloading || !tileAndChildrenReady;
                    }
                    else
                    {
                        anyTileStillDownloading = true;
                    }
                }
            }
            if (anyTileStillDownloading)
            {
                int count = catalogSpreadSheetLayer.Table.Rows.Count;
                if ((count > 10000 || i > 100 * 60 * 5) && limit) // ~5 minutes
                {
                    Script.Literal("console.log('Too Many results - Aborting')");
                    Script.Literal("console.log(count)");
                    InViewReturnMessage returnMessage = new InViewReturnMessage();
                    returnMessage.aborted = true;
                    returnMessage.table   = catalogSpreadSheetLayer.GetTableDataInView();
                    onComplete.Invoke(returnMessage);
                    catalogSpreadSheetLayer.CleanUp();
                }
                else
                {
                    Script.SetTimeout(delegate() { TryGetAllDataInView(imageset, limit, catalogSpreadSheetLayer, onComplete, i); }, 10);
                    if (i % 200 == 0)
                    {
                        Script.Literal("console.log('Waiting for more tiles to load')");
                        Script.Literal("console.log(count)");
                    }
                    i++;
                }
            }
            else
            {
                int count = catalogSpreadSheetLayer.Table.Rows.Count;
                Script.Literal("console.log('Done!')");
                Script.Literal("console.log(count)");
                InViewReturnMessage returnMessage = new InViewReturnMessage();
                returnMessage.aborted = false;
                returnMessage.table   = catalogSpreadSheetLayer.GetTableDataInView();
                onComplete.Invoke(returnMessage);
                catalogSpreadSheetLayer.CleanUp();
            }
        }
Example #7
0
        public static void UpdateImage(ImageSetLayer isl, double z)
        {
            FitsImage    image = isl.ImageSet.WcsImage as FitsImage;
            SkyImageTile Tile  = (SkyImageTile)TileCache.GetTile(0, 0, 0, isl.ImageSet, null);
            double       low   = image.lastBitmapMin;
            double       hi    = image.lastBitmapMax;

            Tile.texture2d = image.GetScaledBitmap(low, hi, image.lastScale, Math.Floor(z * (image.Depth - 1)), null).GetTexture();
        }
Example #8
0
        public static void UpdateScale(ImageSetLayer isl, ScaleTypes scale, double low, double hi)
        {
            FitsImage    image           = isl.ImageSet.WcsImage as FitsImage;
            SkyImageTile Tile            = (SkyImageTile)TileCache.GetTile(0, 0, 0, isl.ImageSet, null);
            int          z               = image.lastBitmapZ;
            string       colorMapperName = image.lastBitmapColorMapperName;

            Tile.texture2d = image.GetScaledBitmap(low, hi, scale, z, colorMapperName).GetTexture();
        }
Example #9
0
 public static void UpdateImage(ImageSetLayer isl, double z)
 {
     if (!RenderContext.UseGlVersion2)
     {
         FitsImageJs  image = isl.ImageSet.WcsImage as FitsImageJs;
         SkyImageTile Tile  = (SkyImageTile)TileCache.GetTile(0, 0, 0, isl.ImageSet, null);
         Tile.texture2d = image.GetBitmap().GetTexture();
     }
 }
Example #10
0
 public static void UpdateColorMapper(ImageSetLayer isl, string colorMapperName)
 {
     isl.ImageSet.FitsProperties.ColorMapName = colorMapperName;
     if (!RenderContext.UseGlVersion2)
     {
         FitsImageJs  image = isl.ImageSet.WcsImage as FitsImageJs;
         SkyImageTile Tile  = (SkyImageTile)TileCache.GetTile(0, 0, 0, isl.ImageSet, null);
         Tile.texture2d = image.GetBitmap().GetTexture();
     }
 }
Example #11
0
        public virtual void RequestImage()
        {
            if (Dataset.WcsImage != null)
            {
                texReady       = true;
                Downloading    = false;
                errored        = false;
                ReadyToRender  = true;
                RequestPending = false;
                TileCache.RemoveFromQueue(this.Key, true);
                return;
            }

            if (!Downloading && !ReadyToRender)
            {
                Downloading = true;
                texture     = (ImageElement)Document.CreateElement("img");
                CrossDomainImage xdomimg = (CrossDomainImage)(object)texture;

                texture.AddEventListener("load", delegate(ElementEvent e)
                {
                    texReady       = true;
                    Downloading    = false;
                    errored        = false;
                    ReadyToRender  = texReady && (DemReady || !demTile);
                    RequestPending = false;
                    TileCache.RemoveFromQueue(this.Key, true);
                    MakeTexture();
                }, false);

                texture.AddEventListener("error", delegate(ElementEvent e)
                {
                    if (!texture.HasAttribute("proxyattempt"))
                    {
                        texture.Src = Util.GetProxiedUrl(URL);
                        texture.SetAttribute("proxyattempt", true);
                    }
                    else
                    {
                        Downloading    = false;
                        ReadyToRender  = false;
                        errored        = true;
                        RequestPending = false;
                        TileCache.RemoveFromQueue(this.Key, true);
                    }
                }, false);

                xdomimg.crossOrigin = "anonymous";
                texture.Src         = this.URL.Replace("cdn.", "www.");
                //texture.Src = "dss.png";

                // TODO add event listener for failed!
            }
        }
Example #12
0
 public static void UpdateScale(ImageSetLayer isl, ScaleTypes scale, double low, double hi)
 {
     isl.ImageSet.FitsProperties.ScaleType = scale;
     isl.ImageSet.FitsProperties.LowerCut  = low;
     isl.ImageSet.FitsProperties.UpperCut  = hi;
     if (!RenderContext.UseGlVersion2)
     {
         FitsImageJs  image = isl.ImageSet.WcsImage as FitsImageJs;
         SkyImageTile Tile  = (SkyImageTile)TileCache.GetTile(0, 0, 0, isl.ImageSet, null);
         Tile.texture2d = image.GetBitmap().GetTexture();
     }
 }
Example #13
0
 public override void RequestImage()
 {
     if (IsCatalogTile)
     {
         if (!Downloading && !ReadyToRender)
         {
             Downloading = true;
             catalogData = new WebFile(this.URL);
             catalogData.OnStateChange = LoadCatalogData;
             catalogData.Send();
         }
     }
     else if (GetHipsFileExtention() == ".fits")
     {
         if (!Downloading && !ReadyToRender)
         {
             Downloading = true;
             if (RenderContext.UseGlVersion2)
             {
                 fitsImage = new FitsImageTile(dataset, URL, delegate(WcsImage wcsImage)
                 {
                     Downloading = false;
                     errored     = fitsImage.errored;
                     TileCache.RemoveFromQueue(this.Key, true);
                     if (!fitsImage.errored)
                     {
                         texReady       = true;
                         ReadyToRender  = texReady && (DemReady || !demTile);
                         RequestPending = false;
                         MakeTexture();
                     }
                 });
             }
             else
             {
                 FitsImageJs image = FitsImageJs.CreateHipsTile(dataset, URL, delegate(WcsImage wcsImage)
                 {
                     texReady       = true;
                     Downloading    = false;
                     errored        = false;
                     ReadyToRender  = texReady && (DemReady || !demTile);
                     RequestPending = false;
                     TileCache.RemoveFromQueue(this.Key, true);
                     texture2d = wcsImage.GetBitmap().GetTexture();
                 });
             }
         }
     }
     else
     {
         base.RequestImage();
     }
 }
Example #14
0
        public bool GetDataInView(RenderContext renderContext, bool limit, CatalogSpreadSheetLayer catalogSpreadSheetLayer)
        {
            if (!ReadyToRender)
            {
                if (!errored)
                {
                    RequestImage();
                    if (limit)
                    {
                        return(false);
                    }
                }
                else if (Level >= 3) //Level 0-2 sometimes deleted in favor of allsky.jpg/tsv
                {
                    return(true);
                }
            }

            bool allChildrenReady  = true;
            bool anyChildInFrustum = false;
            int  childIndex        = 0;

            for (int y1 = 0; y1 < 2; y1++)
            {
                for (int x1 = 0; x1 < 2; x1++)
                {
                    if (Level < dataset.Levels)
                    {
                        if (children[childIndex] == null)
                        {
                            children[childIndex] = TileCache.GetTile(Level + 1, x1, y1, dataset, this);
                        }

                        if (children[childIndex].IsTileInFrustum(renderContext.Frustum))
                        {
                            anyChildInFrustum = true;
                            allChildrenReady  = allChildrenReady && ((HealpixTile)children[childIndex]).GetDataInView(renderContext, limit, catalogSpreadSheetLayer);
                        }
                    }

                    childIndex++;
                }
            }
            if (anyChildInFrustum)
            {
                catalogSpreadSheetLayer.AddTileRows(Key, catalogRows);
            }
            return(allChildrenReady && !Downloading);
        }
Example #15
0
        public void DrawImageSet(Imageset imageset, double opacity)
        {
            int maxX = GetTilesXForLevel(imageset, imageset.BaseLevel);
            int maxY = GetTilesYForLevel(imageset, imageset.BaseLevel);

            for (int x = 0; x < maxX; x++)
            {
                for (int y = 0; y < maxY; y++)
                {
                    Tile tile = TileCache.GetTile(imageset.BaseLevel, x, y, imageset, null);
                    if (tile != null)
                    {
                        tile.Draw3D(this, opacity);
                    }
                }
            }
        }
Example #16
0
        private int ComputeAccomidation()
        {
            int accVal = 0;

            if (!useAccomidation)
            {
                return(0);
            }



            //Bottom
            Tile top = TileCache.GetCachedTile(Level, tileX, tileY + 1, dataset, this);

            if (top == null || top.RenderedAtOrBelowGeneration < CurrentRenderGeneration - 2)
            {
                accVal += 1;
            }

            //right
            Tile right = TileCache.GetCachedTile(Level, tileX + 1, tileY, dataset, this);

            if (right == null || right.RenderedAtOrBelowGeneration < CurrentRenderGeneration - 2)
            {
                accVal += 2;
            }

            //top
            Tile bottom = TileCache.GetCachedTile(Level, tileX, tileY - 1, dataset, this);

            if (bottom == null || bottom.RenderedAtOrBelowGeneration < CurrentRenderGeneration - 2)
            {
                accVal += 4;
            }
            //left
            Tile left = TileCache.GetCachedTile(Level, tileX - 1, tileY, dataset, this);

            if (left == null || left.RenderedAtOrBelowGeneration < CurrentRenderGeneration - 2)
            {
                accVal += 8;
            }

            return(accVal);
        }
Example #17
0
        public void RequestDem()
        {
            if (!ReadyToRender && !demDownloading)
            {
                demTile        = true;
                demDownloading = true;

                callCount++;
                XMLHttpRequest2 xhr = new XMLHttpRequest2();
                xhr.AddEventListener("load", delegate(ElementEvent e)
                {
                    DemReady       = true;
                    demDownloading = false;
                    ReadyToRender  = texReady && (DemReady || !demTile);
                    RequestPending = false;
                    try
                    {
                        demFile = new Float32Array(xhr.Response);
                    }
                    catch
                    {
                    }

                    TileCache.RemoveFromQueue(this.Key, true);
                }, false);

                xhr.AddEventListener("error", delegate(ElementEvent e)
                {
                    demDownloading = false;
                    DemReady       = false;
                    ReadyToRender  = false;
                    errored        = true;
                    RequestPending = false;
                    TileCache.RemoveFromQueue(this.Key, true);
                }, false);

                xhr.Open(HttpVerb.Get, DemURL /*.Replace("cdn.", "www.")*/, true);
                xhr.ResponseType = "arraybuffer";
                xhr.Send();
                // TODO add event listener for failed!
            }
        }
Example #18
0
 private void LoadCatalogData()
 {
     if (catalogData.State == StateType.Error)
     {
         RequestPending = false;
         Downloading    = false;
         errored        = true;
         TileCache.RemoveFromQueue(this.Key, true);
     }
     else if (catalogData.State == StateType.Received)
     {
         ExtractCatalogTileRows();
         texReady       = true;
         Downloading    = false;
         errored        = false;
         ReadyToRender  = true;
         RequestPending = false;
         TileCache.RemoveFromQueue(this.Key, true);
     }
 }
Example #19
0
 public void FileStateChange()
 {
     if (webFile.State == StateType.Error)
     {
         Downloading    = false;
         ReadyToRender  = false;
         errored        = true;
         RequestPending = false;
         TileCache.RemoveFromQueue(this.Key, true);
     }
     else if (webFile.State == StateType.Received)
     {
         texReady       = true;
         Downloading    = false;
         errored        = false;
         ReadyToRender  = texReady && (DemReady || !demTile);
         RequestPending = false;
         TileCache.RemoveFromQueue(this.Key, true);
         LoadData(webFile.GetText());
     }
 }
Example #20
0
        public virtual bool Draw3D(RenderContext renderContext, double opacity)
        {
            //         CanvasContext2D device = renderContext.Device;



            RenderedGeneration = CurrentRenderGeneration;
            TilesTouched++;
            AccessCount = TileCache.AccessID++;

            if (errored)
            {
                return(false);
            }

            int xMax = 2;

            InViewFrustum = true;

            if (!ReadyToRender)
            {
                TileCache.AddTileToQueue(this);
                //RequestImage();
                return(false);
            }

            bool transitioning = false;

            int childIndex = 0;

            int yOffset = 0;

            if (dataset.Mercator || dataset.BottomsUp)
            {
                yOffset = 1;
            }
            int xOffset = 0;

            //      try
            {
                bool anythingToRender = false;
                bool childRendered    = false;
                for (int y1 = 0; y1 < 2; y1++)
                {
                    for (int x1 = 0; x1 < xMax; x1++)
                    {
                        //  if (level < (demEnabled ? 12 : dataset.Levels))
                        if (Level < dataset.Levels)
                        {
                            // make children
                            if (children[childIndex] == null)
                            {
                                children[childIndex] = TileCache.GetTile(Level + 1, tileX * 2 + ((x1 + xOffset) % 2), tileY * 2 + ((y1 + yOffset) % 2), dataset, this);
                            }

                            if (children[childIndex].IsTileInFrustum(renderContext.Frustum))
                            {
                                InViewFrustum = true;
                                if (children[childIndex].IsTileBigEnough(renderContext))
                                {
                                    renderChildPart[childIndex].TargetState = !children[childIndex].Draw3D(renderContext, opacity);
                                    if (renderChildPart[childIndex].TargetState)
                                    {
                                        childRendered = true;
                                    }
                                }
                                else
                                {
                                    renderChildPart[childIndex].TargetState = true;
                                }
                            }
                            else
                            {
                                renderChildPart[childIndex].TargetState = renderChildPart[childIndex].State = false;
                            }

                            //if (renderChildPart[childIndex].TargetState == true || !blendMode)
                            //{
                            //    renderChildPart[childIndex].State = renderChildPart[childIndex].TargetState;
                            //}
                            if (renderChildPart[childIndex].TargetState != renderChildPart[childIndex].State)
                            {
                                transitioning = true;
                            }
                        }
                        else
                        {
                            renderChildPart[childIndex].State = true;
                        }

                        if (renderChildPart[childIndex].State == true)
                        {
                            anythingToRender = true;
                        }

                        childIndex++;
                    }
                }

                if (childRendered || anythingToRender)
                {
                    RenderedAtOrBelowGeneration = CurrentRenderGeneration;
                    if (Parent != null)
                    {
                        Parent.RenderedAtOrBelowGeneration = RenderedAtOrBelowGeneration;
                    }
                }

                if (!anythingToRender)
                {
                    return(true);
                }

                if (!CreateGeometry(renderContext))
                {
                    return(false);
                }

                TilesInView++;


                accomidation = ComputeAccomidation();
                for (int i = 0; i < 4; i++)
                {
                    if (renderChildPart[i].TargetState)
                    {
                        RenderPart(renderContext, i, (opacity / 100), false);
                    }
                }
            }
            //         catch
            {
            }
            return(true);
        }
Example #21
0
        public virtual void RequestImage()
        {
            if (Dataset.WcsImage != null)
            {
                texReady       = true;
                Downloading    = false;
                errored        = false;
                ReadyToRender  = true;
                RequestPending = false;
                TileCache.RemoveFromQueue(this.Key, true);
                return;
            }

            if (!Downloading && !ReadyToRender)
            {
                Downloading = true;
                texture     = (ImageElement)Document.CreateElement("img");
                CrossDomainImage xdomimg = (CrossDomainImage)(object)texture;

                texture.AddEventListener("load", delegate(ElementEvent e)
                {
                    texReady       = true;
                    Downloading    = false;
                    errored        = false;
                    ReadyToRender  = texReady && (DemReady || !demTile);
                    RequestPending = false;
                    TileCache.RemoveFromQueue(this.Key, true);
                    MakeTexture();
                }, false);

                texture.AddEventListener("error", delegate(ElementEvent e)
                {
                    if (!texture.HasAttribute("proxyattempt"))
                    {
                        texture.SetAttribute("proxyattempt", true);

                        // NOTE: `this.URL` is dynamically generated using
                        // URLHelpers.rewrite(). Say that we request tiles from
                        // example.com, which requires CORS proxying. Say also
                        // that this callback is called for a request to a tile
                        // that should in fact be available. If a different
                        // request fails before this callback is called,
                        // activateProxy() will be called on the example.com
                        // domain, making it so that `this.URL` in the following
                        // call goes through the proxy, making it so that
                        // `new_url` is null, making it so that this tile is
                        // erroneously marked as failed when it should not be.
                        // The solution: make sure to check proxy activation
                        // with the *original* request URL, `texture.Src`, not
                        // the one that may have been updated, `this.URL`.
                        string new_url = URLHelpers.singleton.activateProxy(texture.Src);

                        if (new_url != null)
                        {  // null => don't bother: we know that the proxy won't help
                            texture.Src = new_url;
                            return;
                        }
                    }

                    Downloading    = false;
                    ReadyToRender  = false;
                    errored        = true;
                    RequestPending = false;
                    TileCache.RemoveFromQueue(this.Key, true);
                }, false);

                xdomimg.crossOrigin = "anonymous";
                texture.Src         = this.URL;
            }
        }
Example #22
0
        public void DrawCatalogTile(RenderContext renderContext, double opacity)
        {
            RenderedGeneration = CurrentRenderGeneration;
            TilesTouched++;

            InViewFrustum = true;
            bool onlyDrawChildren = false;

            if (!ReadyToRender)
            {
                if (!errored)
                {
                    TileCache.AddTileToQueue(this);
                    return;
                }

                if (errored && Level < 3) //Level 0-2 sometimes deleted in favor of allsky.jpg/tsv
                {
                    onlyDrawChildren = true;
                }
                else
                {
                    return;
                }
            }

            bool anyChildInFrustum = false;
            int  childIndex        = 0;

            for (int y1 = 0; y1 < 2; y1++)
            {
                for (int x1 = 0; x1 < 2; x1++)
                {
                    if (Level < dataset.Levels)
                    {
                        if (children[childIndex] == null)
                        {
                            children[childIndex] = TileCache.GetTile(Level + 1, x1, y1, dataset, this);
                        }

                        if (children[childIndex].IsTileInFrustum(renderContext.Frustum))
                        {
                            InViewFrustum     = true;
                            anyChildInFrustum = true;
                            if (children[childIndex].IsTileBigEnough(renderContext) || onlyDrawChildren)
                            {
                                ((HealpixTile)children[childIndex]).DrawCatalogTile(renderContext, opacity);
                            }
                            else
                            {
                                ((HealpixTile)children[childIndex]).RemoveCatalogTile();
                            }
                        }
                        else
                        {
                            ((HealpixTile)children[childIndex]).RemoveCatalogTile();
                        }
                    }

                    childIndex++;
                }
            }
            if (Level == 0 && !anyChildInFrustum && !onlyDrawChildren)
            {
                RemoveCatalogTile();
            }
            else if (anyChildInFrustum)
            {
                TilesInView++;
                AddCatalogTile();
            }
        }
Example #23
0
        public override void RequestImage()
        {
            fitsImage = dataset.WcsImage as FitsImage;
            if (fitsImage != null)
            {
                texReady       = true;
                Downloading    = false;
                errored        = fitsImage.errored;
                RequestPending = false;
                TileCache.RemoveFromQueue(this.Key, true);
                if (RenderContext.UseGlVersion2)
                {
                    MakeTexture();
                    ReadyToRender = true;
                }
                else
                {
                    bmp           = fitsImage.GetBitmap();
                    texture2d     = bmp.GetTexture();
                    ReadyToRender = true;
                }
            }
            else if (dataset.Extension == ".fits" && dataset.WcsImage == null)
            {
                if (!Downloading && !ReadyToRender)
                {
                    Downloading = true;
                    if (RenderContext.UseGlVersion2)
                    {
                        fitsImage = new FitsImageTile(dataset, URL, delegate(WcsImage wcsImage)
                        {
                            Downloading = false;
                            errored     = fitsImage.errored;
                            TileCache.RemoveFromQueue(this.Key, true);
                            if (!fitsImage.errored)
                            {
                                // For a non-HiPS tiled FITS, this is our
                                // mechanism for notifying the layer creator
                                // that the initial FITS data have loaded and
                                // the FitsProperties can be trusted.
                                if (Level == 0)
                                {
                                    dataset.FitsProperties.FireMainImageLoaded(fitsImage);
                                }

                                texReady       = true;
                                ReadyToRender  = texReady && (DemReady || !demTile);
                                RequestPending = false;
                                MakeTexture();
                                ReadyToRender = true;
                            }
                        });
                    }
                    else
                    {
                        fitsImage = FitsImageJs.CreateTiledFits(dataset, URL, delegate(WcsImage wcsImage)
                        {
                            if (Level == 0)
                            {
                                dataset.FitsProperties.FireMainImageLoaded(fitsImage);
                            }

                            texReady       = true;
                            Downloading    = false;
                            errored        = fitsImage.errored;
                            ReadyToRender  = texReady && (DemReady || !demTile);
                            RequestPending = false;
                            TileCache.RemoveFromQueue(this.Key, true);
                            bmp           = wcsImage.GetBitmap();
                            texture2d     = bmp.GetTexture();
                            ReadyToRender = true;
                        });
                    }
                }
            }
            else
            {
                base.RequestImage();
            }
        }
Example #24
0
        public virtual void RequestImage()
        {
            if (dataset.Extension.ToLowerCase().IndexOf("fits") > -1)
            {
                if (!Downloading && !ReadyToRender)
                {
                    Downloading = true;
                    if (RenderContext.UseGlVersion2)
                    {
                        fitsImage = new FitsImageTile(dataset, URL, delegate(WcsImage wcsImage)
                        {
                            Downloading = false;
                            errored     = fitsImage.errored;
                            TileCache.RemoveFromQueue(this.Key, true);
                            if (!fitsImage.errored)
                            {
                                // For a non-HiPS tiled FITS, this is our
                                // mechanism for notifying the layer creator
                                // that the initial FITS data have loaded and
                                // the FitsProperties can be trusted.
                                if (Level == 0)
                                {
                                    dataset.FitsProperties.FireMainImageLoaded(fitsImage);
                                    fitsImage.ApplyDisplaySettings();
                                }
                                texReady       = true;
                                ReadyToRender  = texReady && (DemReady || !demTile);
                                RequestPending = false;
                                MakeTexture();
                            }
                        });
                    }
                    else
                    {
                        fitsImage = FitsImageJs.CreateTiledFits(dataset, URL, delegate(WcsImage wcsImage)
                        {
                            if (Level == 0)
                            {
                                dataset.FitsProperties.FireMainImageLoaded(fitsImage);
                            }
                            texReady       = true;
                            Downloading    = false;
                            errored        = fitsImage.errored;
                            ReadyToRender  = texReady && (DemReady || !demTile);
                            RequestPending = false;
                            TileCache.RemoveFromQueue(this.Key, true);
                            texture2d = wcsImage.GetBitmap().GetTexture();
                        });
                    }
                }
            }
            else
            {
                if (Dataset.WcsImage != null)
                {
                    texReady       = true;
                    Downloading    = false;
                    errored        = false;
                    ReadyToRender  = true;
                    RequestPending = false;
                    TileCache.RemoveFromQueue(this.Key, true);
                    return;
                }

                if (!Downloading && !ReadyToRender)
                {
                    Downloading = true;
                    texture     = (ImageElement)Document.CreateElement("img");
                    CrossDomainImage xdomimg = (CrossDomainImage)(object)texture;

                    texture.AddEventListener("load", delegate(ElementEvent e)
                    {
                        texReady       = true;
                        Downloading    = false;
                        errored        = false;
                        ReadyToRender  = texReady && (DemReady || !demTile);
                        RequestPending = false;
                        TileCache.RemoveFromQueue(this.Key, true);
                        MakeTexture();
                    }, false);

                    texture.AddEventListener("error", delegate(ElementEvent e)
                    {
                        if (!texture.HasAttribute("proxyattempt"))
                        {
                            texture.SetAttribute("proxyattempt", true);

                            // NOTE: `this.URL` is dynamically generated using
                            // URLHelpers.rewrite(). Say that we request tiles from
                            // example.com, which requires CORS proxying. Say also
                            // that this callback is called for a request to a tile
                            // that should in fact be available. If a different
                            // request fails before this callback is called,
                            // activateProxy() will be called on the example.com
                            // domain, making it so that `this.URL` in the following
                            // call goes through the proxy, making it so that
                            // `new_url` is null, making it so that this tile is
                            // erroneously marked as failed when it should not be.
                            // The solution: make sure to check proxy activation
                            // with the *original* request URL, `texture.Src`, not
                            // the one that may have been updated, `this.URL`.
                            string new_url = URLHelpers.singleton.activateProxy(texture.Src);

                            if (new_url != null)
                            {  // null => don't bother: we know that the proxy won't help
                                texture.Src = new_url;
                                return;
                            }
                        }

                        Downloading    = false;
                        ReadyToRender  = false;
                        errored        = true;
                        RequestPending = false;
                        TileCache.RemoveFromQueue(this.Key, true);
                    }, false);

                    xdomimg.crossOrigin = "anonymous";
                    texture.Src         = this.URL;
                }
            }
        }
Example #25
0
        public override bool Draw3D(RenderContext renderContext, double opacity)
        {
            if (IsCatalogTile)
            {
                DrawCatalogTile(renderContext, opacity);
                return(true);
            }
            RenderedGeneration = CurrentRenderGeneration;
            TilesTouched++;

            InViewFrustum = true;
            bool onlyDrawChildren = false;

            if (!ReadyToRender)
            {
                if (!errored)
                {
                    TileCache.AddTileToQueue(this);
                    return(false);
                }

                if (errored && Level < 3) //Level 0-2 sometimes deleted in favor of allsky.jpg/tsv
                {
                    onlyDrawChildren = true;
                }
                else
                {
                    return(false);
                }
            }


            //if (!CreateGeometry(renderContext))
            //{
            //    if (Level > 2)
            //    {
            //        return false;
            //    }
            //}

            int partCount = this.TriangleCount;

            TrianglesRendered += partCount;

            bool anythingToRender = false;
            bool childRendered    = false;
            int  childIndex       = 0;

            for (int y1 = 0; y1 < 2; y1++)
            {
                for (int x1 = 0; x1 < 2; x1++)
                {
                    if (Level < dataset.Levels)
                    {
                        // make children
                        if (children[childIndex] == null)
                        {
                            children[childIndex] = TileCache.GetTile(Level + 1, x1, y1, dataset, this);
                        }

                        if (children[childIndex].IsTileInFrustum(renderContext.Frustum))
                        {
                            InViewFrustum = true;
                            if (children[childIndex].IsTileBigEnough(renderContext) || onlyDrawChildren)
                            {
                                //renderChildPart[childIndex].TargetState = true;
                                renderChildPart[childIndex].TargetState = !children[childIndex].Draw3D(renderContext, opacity);
                                if (renderChildPart[childIndex].TargetState)
                                {
                                    childRendered = true;
                                }
                            }
                            else
                            {
                                renderChildPart[childIndex].TargetState = true;
                            }
                        }
                        else
                        {
                            renderChildPart[childIndex].TargetState = renderChildPart[childIndex].State = false;
                        }
                    }
                    else
                    {
                        renderChildPart[childIndex].State = true;
                    }

                    ////if(childIndex != 0)
                    ////{
                    ////    renderChildPart[childIndex].TargetState = true;
                    ////    anythingToRender = true;
                    ////}

                    if (renderChildPart[childIndex].State == true)
                    {
                        anythingToRender = true;
                    }

                    childIndex++;
                }
            }

            if (childRendered || anythingToRender)
            {
                RenderedAtOrBelowGeneration = CurrentRenderGeneration;
                if (Parent != null)
                {
                    Parent.RenderedAtOrBelowGeneration = RenderedAtOrBelowGeneration;
                }
            }
            if (!anythingToRender)
            {
                return(true);
            }

            if (!CreateGeometry(renderContext))
            {
                return(false);
            }

            if (onlyDrawChildren)
            {
                return(true);
            }

            TilesInView++;

            for (int i = 0; i < 4; i++)
            {
                if (renderChildPart[i].TargetState)
                {
                    RenderPart(renderContext, i, opacity / 100, false);
                }
            }

            return(true);
        }
        private void InitializeGrids()
        {
            vertexList           = new List <PositionTexture>();
            childTriangleList    = new List <Triangle> [4];
            childTriangleList[0] = new List <Triangle>();
            childTriangleList[1] = new List <Triangle>();
            childTriangleList[2] = new List <Triangle>();
            childTriangleList[3] = new List <Triangle>();

            bounds = new PositionTexture[9];

            if (Level > 0)
            {
                // Set in constuctor now
                //ToastTile parent = (ToastTile)TileCache.GetTile(level - 1, x / 2, y / 2, dataset, null);
                if (Parent == null)
                {
                    Parent = TileCache.GetTile(Level - 1, tileX / 2, tileY / 2, dataset, null);
                }

                ToastTile parent = (ToastTile)Parent;

                int xIndex = tileX % 2;
                int yIndex = tileY % 2;

                if (Level > 1)
                {
                    backslash = parent.backslash;
                }
                else
                {
                    backslash = xIndex == 1 ^ yIndex == 1;
                }


                bounds[0 + 3 * 0] = parent.bounds[xIndex + 3 * yIndex].Copy();
                bounds[1 + 3 * 0] = Midpoint(parent.bounds[xIndex + 3 * yIndex], parent.bounds[xIndex + 1 + 3 * yIndex]);
                bounds[2 + 3 * 0] = parent.bounds[xIndex + 1 + 3 * yIndex].Copy();
                bounds[0 + 3 * 1] = Midpoint(parent.bounds[xIndex + 3 * yIndex], parent.bounds[xIndex + 3 * (yIndex + 1)]);

                if (backslash)
                {
                    bounds[1 + 3 * 1] = Midpoint(parent.bounds[xIndex + 3 * yIndex], parent.bounds[xIndex + 1 + 3 * (yIndex + 1)]);
                }
                else
                {
                    bounds[1 + 3 * 1] = Midpoint(parent.bounds[xIndex + 1 + 3 * yIndex], parent.bounds[xIndex + 3 * (yIndex + 1)]);
                }

                bounds[2 + 3 * 1] = Midpoint(parent.bounds[xIndex + 1 + 3 * yIndex], parent.bounds[xIndex + 1 + 3 * (yIndex + 1)]);
                bounds[0 + 3 * 2] = parent.bounds[xIndex + 3 * (yIndex + 1)].Copy();
                bounds[1 + 3 * 2] = Midpoint(parent.bounds[xIndex + 3 * (yIndex + 1)], parent.bounds[xIndex + 1 + 3 * (yIndex + 1)]);
                bounds[2 + 3 * 2] = parent.bounds[xIndex + 1 + 3 * (yIndex + 1)].Copy();

                bounds[0 + 3 * 0].Tu = 0 * uvMultiple;
                bounds[0 + 3 * 0].Tv = 0 * uvMultiple;
                bounds[1 + 3 * 0].Tu = .5f * uvMultiple;
                bounds[1 + 3 * 0].Tv = 0 * uvMultiple;
                bounds[2 + 3 * 0].Tu = 1 * uvMultiple;
                bounds[2 + 3 * 0].Tv = 0 * uvMultiple;

                bounds[0 + 3 * 1].Tu = 0 * uvMultiple;
                bounds[0 + 3 * 1].Tv = .5f * uvMultiple;
                bounds[1 + 3 * 1].Tu = .5f * uvMultiple;
                bounds[1 + 3 * 1].Tv = .5f * uvMultiple;
                bounds[2 + 3 * 1].Tu = 1 * uvMultiple;
                bounds[2 + 3 * 1].Tv = .5f * uvMultiple;

                bounds[0 + 3 * 2].Tu = 0 * uvMultiple;
                bounds[0 + 3 * 2].Tv = 1 * uvMultiple;
                bounds[1 + 3 * 2].Tu = .5f * uvMultiple;
                bounds[1 + 3 * 2].Tv = 1 * uvMultiple;
                bounds[2 + 3 * 2].Tu = 1 * uvMultiple;
                bounds[2 + 3 * 2].Tv = 1 * uvMultiple;

                vertexList.Add(bounds[0 + 3 * 0]);
                vertexList.Add(bounds[1 + 3 * 0]);
                vertexList.Add(bounds[2 + 3 * 0]);
                vertexList.Add(bounds[0 + 3 * 1]);
                vertexList.Add(bounds[1 + 3 * 1]);
                vertexList.Add(bounds[2 + 3 * 1]);
                vertexList.Add(bounds[0 + 3 * 2]);
                vertexList.Add(bounds[1 + 3 * 2]);
                vertexList.Add(bounds[2 + 3 * 2]);



                if (backslash)
                {
                    childTriangleList[0].Add(Triangle.Create(4, 1, 0));
                    childTriangleList[0].Add(Triangle.Create(3, 4, 0));
                    childTriangleList[1].Add(Triangle.Create(5, 2, 1));
                    childTriangleList[1].Add(Triangle.Create(4, 5, 1));
                    childTriangleList[2].Add(Triangle.Create(7, 4, 3));
                    childTriangleList[2].Add(Triangle.Create(6, 7, 3));
                    childTriangleList[3].Add(Triangle.Create(8, 5, 4));
                    childTriangleList[3].Add(Triangle.Create(7, 8, 4));
                }
                else
                {
                    childTriangleList[0].Add(Triangle.Create(3, 1, 0));
                    childTriangleList[0].Add(Triangle.Create(4, 1, 3));
                    childTriangleList[1].Add(Triangle.Create(4, 2, 1));
                    childTriangleList[1].Add(Triangle.Create(5, 2, 4));
                    childTriangleList[2].Add(Triangle.Create(6, 4, 3));
                    childTriangleList[2].Add(Triangle.Create(7, 4, 6));
                    childTriangleList[3].Add(Triangle.Create(7, 5, 4));
                    childTriangleList[3].Add(Triangle.Create(8, 5, 7));
                }
            }
            else
            {
                bounds[0 + 3 * 0] = PositionTexture.Create(0, -1, 0, 0, 0);
                bounds[1 + 3 * 0] = PositionTexture.Create(0, 0, 1, .5f, 0);
                bounds[2 + 3 * 0] = PositionTexture.Create(0, -1, 0, 1, 0);
                bounds[0 + 3 * 1] = PositionTexture.Create(-1, 0, 0, 0, .5f);
                bounds[1 + 3 * 1] = PositionTexture.Create(0, 1, 0, .5f, .5f);
                bounds[2 + 3 * 1] = PositionTexture.Create(1, 0, 0, 1, .5f);
                bounds[0 + 3 * 2] = PositionTexture.Create(0, -1, 0, 0, 1);
                bounds[1 + 3 * 2] = PositionTexture.Create(0, 0, -1, .5f, 1);
                bounds[2 + 3 * 2] = PositionTexture.Create(0, -1, 0, 1, 1);

                vertexList.Add(bounds[0 + 3 * 0]);
                vertexList.Add(bounds[1 + 3 * 0]);
                vertexList.Add(bounds[2 + 3 * 0]);
                vertexList.Add(bounds[0 + 3 * 1]);
                vertexList.Add(bounds[1 + 3 * 1]);
                vertexList.Add(bounds[2 + 3 * 1]);
                vertexList.Add(bounds[0 + 3 * 2]);
                vertexList.Add(bounds[1 + 3 * 2]);
                vertexList.Add(bounds[2 + 3 * 2]);

                childTriangleList[0].Add(Triangle.Create(3, 1, 0));
                childTriangleList[0].Add(Triangle.Create(4, 1, 3));
                childTriangleList[1].Add(Triangle.Create(5, 2, 1));
                childTriangleList[1].Add(Triangle.Create(4, 5, 1));
                childTriangleList[2].Add(Triangle.Create(7, 4, 3));
                childTriangleList[2].Add(Triangle.Create(6, 7, 3));
                childTriangleList[3].Add(Triangle.Create(7, 5, 4));
                childTriangleList[3].Add(Triangle.Create(8, 5, 7));
                // Setup default matrix of points.
            }
        }