Ejemplo n.º 1
0
        public static void MakeThumbnail(Bitmap imgOrig, string hashID)
        {
            string path = WWTUtil.GetCurrentConfigShare("DSSTileCache", true) + "\\imagesTiler\\thumbnails\\";

            string filename = path + hashID + ".jpg";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            if (!File.Exists(filename))
            {
                try
                {
                    Bitmap bmpThumb = new Bitmap(96, 45);

                    Graphics g = Graphics.FromImage(bmpThumb);

                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                    double imageAspect = ((double)imgOrig.Width) / (imgOrig.Height);

                    double clientAspect = ((double)bmpThumb.Width) / bmpThumb.Height;

                    int cw = bmpThumb.Width;
                    int ch = bmpThumb.Height;

                    if (imageAspect < clientAspect)
                    {
                        ch = (int)((double)cw / imageAspect);
                    }
                    else
                    {
                        cw = (int)((double)ch * imageAspect);
                    }

                    int       cx       = (bmpThumb.Width - cw) / 2;
                    int       cy       = ((bmpThumb.Height - ch) / 2);  // - 1;
                    Rectangle destRect = new Rectangle(cx, cy, cw, ch); //+ 1);

                    Rectangle srcRect = new Rectangle(0, 0, imgOrig.Width, imgOrig.Height);
                    g.DrawImage(imgOrig, destRect, srcRect, System.Drawing.GraphicsUnit.Pixel);
                    g.Dispose();
                    GC.SuppressFinalize(g);
                    bmpThumb.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
                    bmpThumb.Dispose();
                }
                catch
                {
                    Bitmap   bmp = new Bitmap(96, 45);
                    Graphics g   = Graphics.FromImage(bmp);
                    g.Clear(Color.Blue);


                    bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
                    bmp.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        public Bitmap DownloadBitmap(string dataset, int level, int x, int y)
        {
            string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true);
            string id           = "1738422189";
            string type         = ".png";

            switch (dataset)
            {
            case "mars_base_map":
                id = "1738422189";
                break;

            case "mars_terrain_color":
                id = "220581050";
                break;

            case "mars_hirise":
                id   = "109459728";
                type = ".auto";
                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(DSSTileCache + "\\wwtcache\\mars\\{3}\\{0}\\{2}\\{1}_{2}.png", level, x, y,
                                            id);
            string path = String.Format(DSSTileCache + "\\wwtcache\\mars\\{3}\\{0}\\{2}", level, x, y, id);


            if (!File.Exists(filename))
            {
                return(null);
            }

            return(new Bitmap(filename));
        }
        public override void Run(IWwtContext context)
        {
            string guid;

            if (context.Request.Params["GUID"] != null)
            {
                guid = context.Request.Params["GUID"];
            }
            else
            {
                context.Response.End();
                return;
            }
            string tourcache     = ConfigurationManager.AppSettings["WWTTOURCACHE"];
            string localDir      = tourcache;
            string filename      = WWTUtil.GetCurrentConfigShare("WWTToursTourFileUNC", true) + String.Format(@"\{0}_AuthorThumb.bin", guid);
            string localfilename = localDir + String.Format(@"\{0}_AuthorThumb.bin", guid);

            if (!File.Exists(localfilename))
            {
                try
                {
                    if (File.Exists(filename))
                    {
                        if (!Directory.Exists(localDir))
                        {
                            Directory.CreateDirectory(localDir);
                        }
                        File.Copy(filename, localfilename);
                    }
                }
                catch
                {
                }
            }

            if (File.Exists(localfilename))
            {
                try
                {
                    context.Response.ContentType = "image/png";
                    context.Response.WriteFile(localfilename);
                    return;
                }
                catch
                {
                }
            }
            else
            {
                context.Response.Status = "404 Not Found";
            }
        }
Ejemplo n.º 4
0
        public override void Run(IWwtContext context)
        {
            string name = context.Request.Params["name"];
            string type = context.Request.Params["class"];
            string path = WWTUtil.GetCurrentConfigShare("DSSTileCache", true) + "\\imagesTiler\\thumbnails\\";

            string filename = path + name + ".jpg";

            if (File.Exists(filename))
            {
                context.Response.WriteFile(filename);
                context.Response.End();
            }
        }
Ejemplo n.º 5
0
        public override void Run(IWwtContext context)
        {
            string query = context.Request.Params["Q"];

            string[] values = query.Split(',');
            int      level  = Convert.ToInt32(values[0]);
            int      tileX  = Convert.ToInt32(values[1]);
            int      tileY  = Convert.ToInt32(values[2]);

            string file         = "marsToastDem";
            string wwtTilesDir  = ConfigurationManager.AppSettings["WWTTilesDir"];
            string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true);

            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);



            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)
                {
                    context.Response.Clear();
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("No image");
                    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);
        }
        public override void Run(IWwtContext context)
        {
            string query = context.Request.Params["Q"];

            string[] values = query.Split(',');
            int      level  = Convert.ToInt32(values[0]);
            int      tileX  = Convert.ToInt32(values[1]);
            int      tileY  = Convert.ToInt32(values[2]);

            //string wwtTilesDir = ConfigurationManager.AppSettings["WWTTilesDir"];
            string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true);

            string filename = String.Format(DSSTileCache + "\\wwtcache\\mars\\dem\\{0}\\{2}\\{1}_{2}.dem", level, tileX, tileY);
            string path     = String.Format(DSSTileCache + "\\wwtcache\\mars\\dem\\{0}\\{2}", level, tileX, tileY);



            if (!File.Exists(filename))
            {
                try
                {
                    if (!Directory.Exists(filename))
                    {
                        Directory.CreateDirectory(path);
                    }

                    WebClient webclient = new WebClient();

                    string url = string.Format("http://wwt.nasa.gov/wwt/p/mars_toast_dem_32f/{0}/{1}/{2}.toast_dem_v1", level, tileX, tileY);

                    webclient.DownloadFile(url, filename);
                }
                catch
                {
                    context.Response.StatusCode = 404;
                    return;
                }
            }

            context.Response.Write("ok");
        }
Ejemplo n.º 7
0
        public override void Run(IWwtContext context)
        {
            string query = context.Request.Params["Q"];

            string[] values  = query.Split(',');
            int      level   = Convert.ToInt32(values[0]);
            int      tileX   = Convert.ToInt32(values[1]);
            int      tileY   = Convert.ToInt32(values[2]);
            string   dataset = values[3];
            string   id      = dataset;

            string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true);

            string filename = String.Format(DSSTileCache + "\\imagesTiler\\{3}\\{0}\\{2}\\{2}_{1}.png", level, tileX, tileY, id);

            if (!File.Exists(filename))
            {
                context.Response.StatusCode = 404;
                return;
            }

            context.Response.WriteFile(filename);
        }
Ejemplo n.º 8
0
        public override void Run(IWwtContext context)
        {
            string query = context.Request.Params["Q"];

            string[] values = query.Split(',');
            int      level  = Convert.ToInt32(values[0]);
            int      tileX  = Convert.ToInt32(values[1]);
            int      tileY  = Convert.ToInt32(values[2]);

            string filename;
            string path;
            string wwtTilesDir  = ConfigurationManager.AppSettings["WWTTilesDir"];
            string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true);



            filename = String.Format(DSSTileCache + "\\SDSSToast\\{0}\\{2}\\{2}_{1}.png", level, tileX, tileY);
            path     = String.Format(DSSTileCache + "\\SDSSToast\\{0}\\{2}", level, tileX, tileY);

            if (level > 14)
            {
                context.Response.Write("No image");
                context.Response.Close();
                return;
            }

            if (level < 9)
            {
                context.Response.ContentType = "image/png";
                Stream s      = PlateTilePyramid.GetFileStream(wwtTilesDir + "\\sdss_8.plate", level, tileX, tileY);
                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;
            }

            /*
             *     if (!sdssTile )
             *     {
             *         // todo return black tile
             *         using (Bitmap bmp = Bitmap(256, 256))
             *         {
             *             using (Graphics g = Graphics.FromImage(bmp))
             *             {
             *                 g.Clear(Color.Black);
             *             }
             *             bmp.Save(filename);
             *             context.Response.WriteFile(filename);
             *         }
             *         return;
             *     }
             */

            if (File.Exists(filename))
            {
                try
                {
                    context.Response.WriteFile(filename);
                    return;
                }
                catch
                {
                }
            }
            else
            {
                OctTileMap map = new OctTileMap(level, tileX, tileY);

                Int32 sqSide = 256;

                //Vector2d topLeft = map.PointToRaDec(new Vector2d(0, 0))
                //map.PointToRaDec(new Vector2d(0, 1))
                //map.PointToRaDec(new Vector2d(1, 0))
                //map.PointToRaDec(new Vector2d(1, 1))


                // SDSS boundaries
                // RA: 105 deg <-> 270 deg
                // DEC: -3 deg <-> + 75 deg

                if (!(map.raMin > 270 | map.decMax < -3 | map.raMax < 105 | map.decMin > 75))
                {
                    Bitmap     bmpOutput     = new Bitmap(sqSide, sqSide);
                    FastBitmap bmpOutputFast = new FastBitmap(bmpOutput);
                    SdssImage  sdim          = new SdssImage(map.raMin, map.decMax, map.raMax, map.decMin);
                    sdim.LoadImage();
                    sdim.Lock();

                    bmpOutputFast.LockBitmap();
                    // Fill up bmp from sdim

                    Vector2d vxy, vradec;
                    unsafe
                    {
                        PixelData *pPixel;
                        for (int y = 0; y < sqSide; y++)
                        {
                            pPixel = bmpOutputFast[0, y];
                            vxy.Y  = (y / 255.0);
                            for (int x = 0; x < sqSide; x++)
                            {
                                vxy.X  = (x / 255.0);
                                vradec = map.PointToRaDec(vxy);
                                *pPixel = sdim.GetPixelDataAtRaDec(vradec);

                                pPixel++;
                            }
                        }
                    }


                    bmpOutputFast.UnlockBitmap();

                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    bmpOutput.Save(filename, ImageFormat.Png);
                    bmpOutput.Dispose();
                    try
                    {
                        context.Response.WriteFile(filename);
                    }
                    catch
                    {
                    }
                }
                else
                {
                    //context.Response.WriteFile(@"c:\inetpub\cache\empty.png");
                    context.Response.Write("No Image");
                }
            }

            context.Response.End();
        }
Ejemplo n.º 9
0
        public override void Run(IWwtContext context)
        {
            string wwtTilesDir = ConfigurationManager.AppSettings["WWTTilesDir"];
            string dsstoastpng = WWTUtil.GetCurrentConfigShare("DSSTOASTPNG", true);

            string query = context.Request.Params["Q"];

            string[] values = query.Split(',');
            int      level  = Convert.ToInt32(values[0]);
            int      tileX  = Convert.ToInt32(values[1]);
            int      tileY  = Convert.ToInt32(values[2]);

            int    octsetlevel = level;
            string filename;

            if (level > 12)
            {
                context.Response.Write("No image");
                context.Response.Close();
                return;
            }

            if (level < 8)
            {
                context.Response.ContentType = "image/png";
                Stream s      = PlateTilePyramid.GetFileStream(wwtTilesDir + "\\dsstoast.plate", level, tileX, tileY);
                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;
            }
            else
            {
                int    L           = level;
                int    X           = tileX;
                int    Y           = tileY;
                string mime        = "png";
                int    powLev5Diff = (int)Math.Pow(2, L - 5);
                int    X32         = X / powLev5Diff;
                int    Y32         = Y / powLev5Diff;
                filename = string.Format(dsstoastpng + @"\DSS{0}L5to12_x{1}_y{2}.plate", mime, X32, Y32);

                int L5 = L - 5;
                int X5 = X % powLev5Diff;
                int Y5 = Y % powLev5Diff;
                context.Response.ContentType = "image/png";
                Stream s      = PlateTilePyramid.GetFileStream(filename, L5, X5, Y5);
                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;
            }

            // This file has returns which cause this warning to show in the generated files.
            // This should be refactored, but that will be a bigger change.
#pragma warning disable 0162
        }
Ejemplo n.º 10
0
        public override void Run(IWwtContext context)
        {
            {
                //if (context.Request.Cookies["alphakey"] != null && context.Request.Params["wtml"] == null)
                // if (context.Request.Cookies["fullclient"] == null && context.Request.Params["wtml"] == null)
                // {
                //context.Response.Redirect("http://www.worldwidetelescope.org/webclient/default.aspx?wtml="+HttpUtility.UrlEncode(context.Request.Url.ToString().Replace(",","-") +"&wtml=true"));
                //return;
                //}



                if (context.Request.Params["debug"] != null)
                {
                    context.Response.ClearHeaders();
                    context.Response.ContentType = "text/plain";
                }

                string url           = "";
                bool   bgoto         = false;
                bool   reverseparity = false;
                string creditsUrl    = "";
                string credits       = "";
                string thumb         = "";
                double rotation      = 1.0;

                double scale     = 1.0;
                double y         = 0;
                double x         = 0;
                double dec       = 0;
                double ra        = 0;
                string name      = "";
                int    maxLevels = 1;

                if (context.Request.Params["imageurl"] != null)
                {
                    url = context.Request.Params["imageurl"];
                }

                if (String.IsNullOrEmpty(url))
                {
                    url = "http://www.spitzer.caltech.edu/uploaded_files/images/0009/0848/sig12-011.jpg";
                }

                int hashID = _hasher.HashName(url);

                //hashID = 12345;
                string path = WWTUtil.GetCurrentConfigShare("DSSTileCache", true) + "\\imagesTiler\\dowloadImages\\";

                string filename = path + hashID + ".png";

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                if (!File.Exists(filename))
                {
                    WebClient client = new WebClient();
                    client.DownloadFile(url, filename);
                }


                WcsImage wcsImage = WcsImage.FromFile(filename);

                if (wcsImage != null)
                {
                    bool hasAvm = wcsImage.ValidWcs;


                    Bitmap bmp = wcsImage.GetBitmap();
                    wcsImage.AdjustScale(bmp.Width, bmp.Height);

                    MakeThumbnail(bmp, hashID.ToString());

                    name          = wcsImage.Keywords[0];
                    reverseparity = false;
                    creditsUrl    = wcsImage.CreditsUrl;
                    credits       = wcsImage.Copyright;
                    thumb         = "http://www.worldwidetelescope.org/wwtweb/tilethumb.aspx?name=" + hashID;
                    rotation      = wcsImage.Rotation;

                    maxLevels = CalcMaxLevels((int)wcsImage.SizeX, (int)wcsImage.SizeY);
                    scale     = wcsImage.ScaleY * Math.Pow(2, maxLevels) * 256;
                    y         = 0;
                    x         = 0;
                    dec       = wcsImage.CenterY;
                    ra        = wcsImage.CenterX;

                    //if (tileIt)
                    {
                        TileBitmap(bmp, hashID.ToString());
                    }

                    // todo make thumbnail
                    //pl.ThumbNail = UiTools.MakeThumbnail(bmp);


                    bmp.Dispose();
                    GC.SuppressFinalize(bmp);
                    bmp = null;

                    if (context.Request.Params["debug"] != null)
                    {
                        name = context.Request.Params["name"];
                        name = name.Replace(",", "");
                    }


                    if (context.Request.Params["ra"] != null)
                    {
                        ra = Math.Max(0, Math.Min(360.0, Convert.ToDouble(context.Request.Params["ra"])));
                    }


                    if (context.Request.Params["dec"] != null)
                    {
                        dec = Math.Max(-90, Math.Min(90, Convert.ToDouble(context.Request.Params["dec"])));
                    }


                    if (context.Request.Params["x"] != null)
                    {
                        x = Convert.ToDouble(context.Request.Params["x"]);
                    }


                    if (context.Request.Params["y"] != null)
                    {
                        y = Convert.ToDouble(context.Request.Params["y"]);
                    }


                    if (context.Request.Params["scale"] != null)
                    {
                        scale = Convert.ToDouble(context.Request.Params["scale"]) * Math.Pow(2, maxLevels) * 256;
                    }


                    if (context.Request.Params["rotation"] != null)
                    {
                        rotation = Convert.ToDouble(context.Request.Params["rotation"]) - 180;
                    }


                    if (context.Request.Params["thumb"] != null)
                    {
                        thumb = context.Request.Params["thumb"];
                    }


                    if (context.Request.Params["credits"] != null)
                    {
                        credits = context.Request.Params["credits"];
                    }


                    if (context.Request.Params["creditsUrl"] != null)
                    {
                        creditsUrl = context.Request.Params["creditsUrl"];
                    }


                    if (context.Request.Params["reverseparity"] != null)
                    {
                        reverseparity = Convert.ToBoolean(context.Request.Params["reverseparity"]);
                    }


                    if (context.Request.Params["goto"] != null)
                    {
                        bgoto = Convert.ToBoolean(context.Request.Params["goto"]);
                    }

                    if (scale == 0)
                    {
                        scale = .1;
                    }
                    double zoom = scale * 4;

                    //scale = scale / 3600.0;
                    //bgoto = true;

                    string xml = string.Format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Folder Name=\"{0}\" Group=\"{14}\">\n<Place Name=\"{0}\" RA=\"{1}\" Dec=\"{2}\" ZoomLevel=\"{3}\" DataSetType=\"Sky\" Opacity=\"100\" Thumbnail=\"{10}\" Constellation=\"\">\n <ForegroundImageSet>\n <ImageSet DataSetType=\"Sky\" Name=\"{0}\" BandPass=\"Visible\" Url=\"http://www.worldwidetelescope.org/wwtweb/GetTile.aspx?q={{1}},{{2}},{{3}},{8}\" TileLevels=\"{15}\" WidthFactor=\"1\" Rotation=\"{5}\" Projection=\"Tan\" FileType=\".png\" CenterY=\"{2}\" CenterX=\"{9}\" BottomsUp=\"{13}\" OffsetX=\"{6}\" OffsetY=\"{7}\" BaseTileLevel=\"0\" BaseDegreesPerTile=\"{4}\">\n<Credits>{11}</Credits>\n<CreditsUrl>{12}</CreditsUrl>\n<ThumbnailUrl>{10}</ThumbnailUrl>\n</ImageSet>\n</ForegroundImageSet>\n</Place>\n</Folder>", name, ra / 15, dec, zoom, scale, rotation, x, y, hashID, ra, thumb, credits, creditsUrl, reverseparity, "Explorer", maxLevels);

                    context.Response.Write(xml);
                }
            }
        }
Ejemplo n.º 11
0
        public override void Run(IWwtContext context)
        {
            string query = context.Request.Params["Q"];

            string[] values  = query.Split(',');
            int      level   = Convert.ToInt32(values[0]);
            int      tileX   = Convert.ToInt32(values[1]);
            int      tileY   = Convert.ToInt32(values[2]);
            string   dataset = values[3];
            string   id      = "nothing";

            string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true);

            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(DSSTileCache + "\\wwtcache\\mars\\{3}\\{0}\\{2}\\{1}_{2}.png", level, tileX, tileY, id);
            string path     = String.Format(DSSTileCache + "\\wwtcache\\mars\\{3}\\{0}\\{2}", level, tileX, tileY, id);


            if (!File.Exists(filename))
            {
                //try
                //{
                //    if (!Directory.Exists(filename))
                //    {
                //        Directory.CreateDirectory(path);
                //    }

                //    WebClient webclient = new WebClient();

                //    string url = string.Format("http://wwt.nasa.gov/wwt/p/{0}/{1}/{2}/{3}{4}", dataset, level, tileX, tileY, type);

                //    webclient.DownloadFile(url, filename);
                //}
                //catch
                // {
                context.Response.StatusCode = 404;
                return;
                // }
            }

            context.Response.WriteFile(filename);
        }
Ejemplo n.º 12
0
        public override void Run(IWwtContext context)
        {
            string wwtTilesDir = ConfigurationManager.AppSettings["WWTTilesDir"];
            string dsstoastpng = WWTUtil.GetCurrentConfigShare("DSSTOASTPNG", true);

            string query = context.Request.Params["Q"];

            string[] values = query.Split(',');
            int      level  = Convert.ToInt32(values[0]);
            int      tileX  = Convert.ToInt32(values[1]);
            int      tileY  = Convert.ToInt32(values[2]);

            int    octsetlevel = level;
            string filename;

            if (level > 20)
            {
                context.Response.Write("No image");
                context.Response.Close();
                return;
            }

            if (level < 8)
            {
                context.Response.ContentType = "image/png";
                Stream s      = PlateTilePyramid.GetFileStream(wwtTilesDir + "\\BmngMerBase.plate", level, tileX, tileY);
                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;
            }
            else if (level < 10)
            {
                int    L           = level;
                int    X           = tileX;
                int    Y           = tileY;
                string mime        = "png";
                int    powLev5Diff = (int)Math.Pow(2, L - 2);
                int    X32         = X / powLev5Diff;
                int    Y32         = Y / powLev5Diff;
                filename = string.Format(wwtTilesDir + @"\BmngMerL2X{1}Y{2}.plate", mime, X32, Y32);

                int L5 = L - 2;
                int X5 = X % powLev5Diff;
                int Y5 = Y % powLev5Diff;
                context.Response.ContentType = "image/png";
                Stream s      = PlateTilePyramid.GetFileStream(filename, L5, X5, Y5);
                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;
            }

            System.Net.WebClient client = new System.Net.WebClient();


            string url = String.Format("http://a{0}.ortho.tiles.virtualearth.net/tiles/a{1}.jpeg?g=15", WWTUtil.GetServerID(tileX, tileY), WWTUtil.GetTileID(tileX, tileY, level, false));

            byte[] dat = client.DownloadData(url);


            client.Dispose();

            context.Response.OutputStream.Write(dat, 0, dat.Length);
        }
Ejemplo n.º 13
0
        public override void Run(IWwtContext context)
        {
            string query = context.Request.Params["Q"];

            string[] values  = query.Split(',');
            int      level   = Convert.ToInt32(values[0]);
            int      tileX   = Convert.ToInt32(values[1]);
            int      tileY   = Convert.ToInt32(values[2]);
            string   dataset = values[3];
            string   id      = "nothing";

            string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true);

            switch (dataset)
            {
            case "mars_base_map":
                if (level < 18)
                {
                    // context.Response.ContentType = "image/png";

                    Stream s = PlateFile2.GetFileStream(@"\\wwt-mars\marsroot\MARSBASEMAP\marsbasemap.plate", -1, level, tileX, tileY);

                    if (s == null || (int)s.Length == 0)
                    {
                        context.Response.Clear();
                        context.Response.ContentType = "text/plain";
                        context.Response.Write("No image");
                        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;
                }
                break;

            case "mars_terrain_color":
                id = "220581050";
                break;

            case "mars_hirise":
                if (level < 19)
                {
                    context.Response.ContentType = "image/png";

                    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)
                    {
                        context.Response.Clear();
                        context.Response.ContentType = "text/plain";
                        context.Response.Write("No image");
                        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;
                }

                break;

            case "mars_moc":
                if (level < 18)
                {
                    context.Response.ContentType = "image/png";

                    UInt32 index = ComputeHash(level, tileX, tileY) % 400;

                    Stream s = PlateFile2.GetFileStream(String.Format(@"\\wwt-mars\marsroot\moc\mocv5_{0}.plate", index), -1, level, tileX, tileY);

                    if (s == null || (int)s.Length == 0)
                    {
                        context.Response.Clear();
                        context.Response.ContentType = "text/plain";
                        context.Response.Write("No image");
                        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;
                }
                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(DSSTileCache + "\\wwtcache\\mars\\{3}\\{0}\\{2}\\{1}_{2}.png", level, tileX, tileY, id);
            string path     = String.Format(DSSTileCache + "\\wwtcache\\mars\\{3}\\{0}\\{2}", level, tileX, tileY, id);


            if (!File.Exists(filename))
            {
                //try
                //{
                //    if (!Directory.Exists(filename))
                //    {
                //        Directory.CreateDirectory(path);
                //    }

                //    WebClient webclient = new WebClient();

                //    string url = string.Format("http://wwt.nasa.gov/wwt/p/{0}/{1}/{2}/{3}{4}", dataset, level, tileX, tileY, type);

                //    webclient.DownloadFile(url, filename);
                //}
                //catch
                // {
                context.Response.StatusCode = 404;
                return;
                // }
            }

            context.Response.WriteFile(filename);
        }
Ejemplo n.º 14
0
 public override void Run(IWwtContext context)
 {
     context.Response.Write(WWTUtil.GetCurrentConfigShare("DSSTOASTPNG", true));
 }
Ejemplo n.º 15
0
        public void TileBitmap(Bitmap bmp, string ID)
        {
            string baseDirectory = WWTUtil.GetCurrentConfigShare("DSSTileCache", true) + "\\imagesTiler\\";
            int    width         = bmp.Width;
            int    height        = bmp.Height;
            double aspect        = (double)width / (double)height;

            string testFile = String.Format(@"{0}\{1}\0\0\0_0.png", baseDirectory, ID);

            if (File.Exists(testFile))
            {
                return;
            }

            //narrower
            int levels    = 1;
            int maxHeight = 256;
            int maxWidth  = 512;
            int xOffset   = 0;
            int yOffset   = 0;

            do
            {
                if (aspect < 2)
                {
                    if (maxHeight >= height)
                    {
                        break;
                    }
                }
                else
                {
                    if (maxWidth >= width)
                    {
                        break;
                    }
                }
                levels++;
                maxHeight *= 2;
                maxWidth  *= 2;
            } while (true);

            xOffset = (maxWidth - width) / 2;
            yOffset = (maxHeight - height) / 2;

            if (Directory.Exists(String.Format(@"{0}\{1})", baseDirectory, ID)))
            {
                Directory.Delete(String.Format(@"{0}\{1})", baseDirectory, ID), true);
            }
            Directory.CreateDirectory(String.Format(@"{0}\{1}", baseDirectory, ID));

            int l = levels;

            int gridX        = 256;
            int gridY        = 256;
            int currentLevel = 0;

            while (l > 0)
            {
                l--;
                currentLevel = l;
                string levelDir = String.Format(@"{0}\{1}\{2}", baseDirectory, ID, l.ToString());
                Directory.CreateDirectory(levelDir);

                int tilesX = 2 * (int)Math.Pow(2, l);
                int tilesY = (int)Math.Pow(2, l);

                for (int y = 0; y < tilesY; y++)
                {
                    string dirName = levelDir + @"\" + y.ToString();
                    Directory.CreateDirectory(dirName);

                    for (int x = 0; x < tilesX; x++)
                    {
                        if ((((x + 1) * gridX) > xOffset) && (((y + 1) * gridX) > yOffset) &&
                            (((x) * gridX) < (xOffset + width)) && (((y) * gridX) < (yOffset + height)))
                        {
                            Bitmap   bmpTile = new Bitmap(256, 256);
                            Graphics gfx     = Graphics.FromImage(bmpTile);
                            gfx.DrawImage(bmp, new Rectangle(0, 0, 256, 256),
                                          new Rectangle((x * gridX) - xOffset, (y * gridX) - yOffset, gridX, gridX),
                                          GraphicsUnit.Pixel);
                            //gfx.Flush(FlushIntention.Sync);
                            gfx.Dispose();
                            string fileOut = dirName + @"\" + y.ToString() + "_" + x.ToString() + ".png";
                            bmpTile.Save(fileOut, System.Drawing.Imaging.ImageFormat.Png);
                            bmpTile.Dispose();
                        }
                    }
                }

                gridX *= 2;
                gridY *= 2;
            }
        }
Ejemplo n.º 16
0
        public override void Run(IWwtContext context)
        {
            if (context.Request.UserAgent.ToLower().Contains("wget"))
            {
                context.Response.Write("You are not allowed to bulk download imagery thru the tile service. Please contact [email protected] for more information.");
                context.Response.End();
                return;
            }



            string query = context.Request.Params["Q"];

            string[] values = query.Split(',');
            //++
            // 2014-09-26 security fix.
            //
            int level = 0;
            int tileX = 0;
            int tileY = 0;

            try
            {
                level = Convert.ToInt32(values[0]);
                tileX = Convert.ToInt32(values[1]);
                tileY = Convert.ToInt32(values[2]);
            }
            catch
            {
                context.Response.Write("Invalid query string.");
                context.Response.End();
                return;
            }

            string filename;
            string path;

            string wwtTilesDir  = ConfigurationManager.AppSettings["WWTTilesDir"];
            string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true);



            filename = String.Format(DSSTileCache + "\\SDSSToast12\\{0}\\{2}\\{2}_{1}.png", level, tileX, tileY);
            path     = String.Format(DSSTileCache + "\\SDSSToast12\\{0}\\{2}", level, tileX, tileY);

            if (level > 14)
            {
                context.Response.Write("No image");
                context.Response.End();
                return;
            }

            if (level < 8)
            {
                context.Response.ContentType = "image/png";
                Stream s      = PlateTilePyramid.GetFileStream(wwtTilesDir + "\\sdssdr12_7.plate", level, tileX, tileY);
                int    length = (int)s.Length;
                if (length == 0)
                {
                    context.Response.Clear();
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("No image");
                    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;
            }


            if (File.Exists(filename))
            {
                try
                {
                    context.Response.WriteFile(filename);
                    return;
                }
                catch
                {
                }
            }
            else
            {
                OctTileMap map = new OctTileMap(level, tileX, tileY);

                Int32 sqSide = 256;

                Bitmap     bmpOutput     = new Bitmap(sqSide, sqSide);
                FastBitmap bmpOutputFast = new FastBitmap(bmpOutput);
                SdssImage  sdim          = new SdssImage(map.raMin, map.decMax, map.raMax, map.decMin, true);
                sdim.LoadImage();

                if (sdim.image != null)
                {
                    sdim.Lock();

                    bmpOutputFast.LockBitmap();
                    // Fill up bmp from sdim

                    Vector2d vxy, vradec;
                    unsafe
                    {
                        PixelData *pPixel;
                        for (int y = 0; y < sqSide; y++)
                        {
                            pPixel = bmpOutputFast[0, y];
                            vxy.Y  = (y / 255.0);
                            for (int x = 0; x < sqSide; x++)
                            {
                                vxy.X  = (x / 255.0);
                                vradec = map.PointToRaDec(vxy);
                                *pPixel = sdim.GetPixelDataAtRaDec(vradec);

                                pPixel++;
                            }
                        }
                    }

                    sdim.Unlock();
                    sdim.image.Dispose();

                    bmpOutputFast.UnlockBitmap();
                }
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                bmpOutput.Save(filename, ImageFormat.Png);
                bmpOutput.Dispose();
                try
                {
                    context.Response.WriteFile(filename);
                }
                catch
                {
                }
            }

            context.Response.End();
        }
Ejemplo n.º 17
0
        public override void Run(IWwtContext context)
        {
            string query = context.Request.Params["Q"];

            string[] values = query.Split(',');
            int      level  = Convert.ToInt32(values[0]);
            int      tileX  = Convert.ToInt32(values[1]);
            int      tileY  = Convert.ToInt32(values[2]);

            string wwtTilesDir = ConfigurationManager.AppSettings["WWTTilesDir"];
            string wwtgalexdir = WWTUtil.GetCurrentConfigShare("WWTGALEXDIR", true);


            if (level > 10)
            {
                context.Response.Clear();
                context.Response.ContentType = "text/plain";
                context.Response.Write("No image");
                context.Response.End();
                return;
            }

            if (level < 9)
            {
                try
                {
                    context.Response.ContentType = "image/png";
                    Stream s      = PlateTilePyramid.GetFileStream(wwtTilesDir + "\\GalexBoth_L0to8_x0_y0.plate", level, tileX, tileY);
                    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;
                }
                catch
                {
                    context.Response.Clear();
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("No image");
                    context.Response.End();
                    return;
                }
            }
            else
            {
                try
                {
                    int L           = level;
                    int X           = tileX;
                    int Y           = tileY;
                    int powLev3Diff = (int)Math.Pow(2, L - 3);
                    int X8          = X / powLev3Diff;
                    int Y8          = Y / powLev3Diff;
                    var filename    = string.Format(wwtgalexdir + @"\GalexBoth_L3to10_x{0}_y{1}.plate", X8, Y8);

                    int L3 = L - 3;
                    int X3 = X % powLev3Diff;
                    int Y3 = Y % powLev3Diff;
                    context.Response.ContentType = "image/png";
                    Stream s      = PlateTilePyramid.GetFileStream(filename, L3, X3, Y3);
                    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;
                }
                catch
                {
                    context.Response.Clear();
                    context.Response.ContentType = "text/plain";
                    context.Response.Write("No image");
                    context.Response.End();
                    return;
                }
            }

            // This file has returns which cause this warning to show in the generated files.
            // This should be refactored, but that will be a bigger change.
#pragma warning disable 0162
        }
Ejemplo n.º 18
0
        public override void Run(IWwtContext context)
        {
            string query = context.Request.Params["Q"];

            string[] values = query.Split(',');
            int      level  = Convert.ToInt32(values[0]);
            int      tileX  = Convert.ToInt32(values[1]);
            int      tileY  = Convert.ToInt32(values[2]);

            string filename;
            string path;
            Bitmap b            = null;
            string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true);
            string webDir       = ConfigurationManager.AppSettings["WWTWEBDIR"];


            filename = String.Format(DSSTileCache + "\\wwtcache\\mandel\\level{0}\\{2}\\{1}_{2}.png", level, tileX, tileY);
            path     = String.Format(DSSTileCache + "\\wwtcache\\mandel\\level{0}\\{2}", level, tileX, tileY);

            if ((level < 32) && File.Exists(filename))
            {
                try
                {
                    context.Response.WriteFile(filename);
                }
                catch
                {
                    b = null;
                }
            }
            else
            {
                double tileWidth = (4 / (Math.Pow(2, level)));
                double Sy        = ((double)tileY * tileWidth) - 2;
                double Fy        = Sy + tileWidth;
                double Sx        = ((double)tileX * tileWidth) - 4;
                double Fx        = Sx + tileWidth;


                context.Response.Clear();

                Color[] cs = new Color[256];
                {
                    try
                    {
                        Color[] c = new Color[256];
                        System.IO.StreamReader sr = new System.IO.StreamReader(webDir + @"\wwtweb\colors.map");
                        //System.IO.StreamReader sr = new System.IO.StreamReader(@"colors.map");
                        ArrayList lines = new ArrayList();
                        string    line  = sr.ReadLine();
                        while (line != null)
                        {
                            lines.Add(line);
                            line = sr.ReadLine();
                        }
                        int i = 0;
                        for (i = 0; i < Math.Min(256, lines.Count); i++)
                        {
                            string curC = (string)lines[i];
                            Color  temp = Color.FromArgb(int.Parse(curC.Split(' ')[0]), int.Parse(curC.Split(' ')[1]), int.Parse(curC.Split(' ')[2]));
                            c[i] = temp;
                        }
                        for (int j = i; j < 256; j++)
                        {
                            c[j] = Color.White;
                        }
                        cs = c;
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Invalid ColorMap file.", ex);
                    }
                }

                int MAXITER = 100 + level * 100;

                b = new Bitmap(256, 256);
                double x, y, x1, y1, xx, xmin, xmax, ymin, ymax = 0.0;
                int    looper, s, z = 0;
                double intigralX, intigralY = 0.0;
                xmin      = Sx;
                ymin      = Sy;
                xmax      = Fx;
                ymax      = Fy;
                intigralX = (xmax - xmin) / 256;
                intigralY = (ymax - ymin) / 256;
                x         = xmin;
                for (s = 0; s < 256; s++)
                {
                    y = ymin;
                    for (z = 0; z < 256; z++)
                    {
                        x1     = 0;
                        y1     = 0;
                        looper = 0;
                        while (looper < MAXITER && ((x1 * x1) + (y1 * y1)) < 4)
                        {
                            looper++;
                            xx = (x1 * x1) - (y1 * y1) + x;
                            y1 = 2 * x1 * y1 + y;
                            x1 = xx;
                        }
                        double perc = looper / (256.0);
                        int    val  = looper % 254;
                        b.SetPixel(s, z, looper == MAXITER ? Color.Black : cs[val]);
                        y += intigralY;
                    }
                    x += intigralX;
                }

                if (level < 32)
                {
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    b.Save(filename);
                }
                b.Save(context.Response.OutputStream, ImageFormat.Png);
                b.Dispose();
            }

            context.Response.End();
        }
Ejemplo n.º 19
0
        public override void Run(IWwtContext context)
        {
            string wwtTilesDir  = ConfigurationManager.AppSettings["WWTTilesDir"];
            string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true);
            string query        = context.Request.Params["Q"];

            string[] values   = query.Split(',');
            int      level    = Convert.ToInt32(values[0]);
            int      tileX    = Convert.ToInt32(values[1]);
            int      tileY    = Convert.ToInt32(values[2]);
            string   filename = String.Format(DSSTileCache + "\\EarthBlend\\level{0}\\{2}\\{1}_{2}.jpg", level, tileX, tileY);
            string   path     = String.Format(DSSTileCache + "\\EarthBlend\\level{0}\\{2}", level, tileX, tileY);

            if (level > 20)
            {
                context.Response.Write("No image");
                context.Response.Close();
                return;
            }

            if (level < 8)
            {
                context.Response.ContentType = "image/png";
                Stream s      = PlateTilePyramid.GetFileStream(wwtTilesDir + "\\BmngMerBase.plate", level, tileX, tileY);
                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;
            }
            else if (level == 8)
            {
                int    L           = level;
                int    X           = tileX;
                int    Y           = tileY;
                string mime        = "png";
                int    powLev5Diff = (int)Math.Pow(2, L - 2);
                int    X32         = X / powLev5Diff;
                int    Y32         = Y / powLev5Diff;
                filename = string.Format(wwtTilesDir + @"\BmngMerL2X{1}Y{2}.plate", mime, X32, Y32);

                int L5 = L - 2;
                int X5 = X % powLev5Diff;
                int Y5 = Y % powLev5Diff;
                context.Response.ContentType = "image/png";
                Stream s      = PlateTilePyramid.GetFileStream(filename, L5, X5, Y5);
                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;
            }
            else if (level == 9)
            {
                if (!File.Exists(filename))
                {
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    int    L             = level;
                    int    X             = tileX;
                    int    Y             = tileY;
                    string mime          = "png";
                    int    powLev5Diff   = (int)Math.Pow(2, L - 2);
                    int    X32           = X / powLev5Diff;
                    int    Y32           = Y / powLev5Diff;
                    string platefilename = string.Format(wwtTilesDir + @"\BmngMerL2X{1}Y{2}.plate", mime, X32, Y32);

                    int L5 = L - 2;
                    int X5 = X % powLev5Diff;
                    int Y5 = Y % powLev5Diff;

                    float[][] ptsArray =
                    {
                        new float[] { 1, 0, 0,    0, 0 },
                        new float[] { 0, 1, 0,    0, 0 },
                        new float[] { 0, 0, 1,    0, 0 },
                        new float[] { 0, 0, 0, 0.5f, 0 },
                        new float[] { 0, 0, 0,    0, 1 }
                    };
                    ColorMatrix     clrMatrix     = new ColorMatrix(ptsArray);
                    ImageAttributes imgAttributes = new ImageAttributes();
                    imgAttributes.SetColorMatrix(clrMatrix,
                                                 ColorMatrixFlag.Default,
                                                 ColorAdjustType.Bitmap);
                    context.Response.ContentType = "image/png";
                    Stream s = PlateTilePyramid.GetFileStream(platefilename, L5, X5, Y5);

                    Bitmap   bmp = new Bitmap(s);
                    Graphics g   = Graphics.FromImage(bmp);
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                    string   tempName = WWTUtil.DownloadVeTile(level, tileX, tileY, false);
                    FileInfo fi       = new FileInfo(tempName);
                    if (fi.Length != 0 && fi.Length != 1033)
                    {
                        Bitmap temp = new Bitmap(tempName);

                        g.DrawImage(temp, new Rectangle(0, 0, 256, 256), 0, 0, 256, 256, GraphicsUnit.Pixel, imgAttributes);
                        temp.Dispose();
                    }
                    g.Dispose();
                    bmp.Save(filename, ImageFormat.Jpeg);
                    bmp.Dispose();
                }

                context.Response.WriteFile(filename);
                return;
            }


            System.Net.WebClient client = new System.Net.WebClient();


            string url = String.Format("http://a{0}.ortho.tiles.virtualearth.net/tiles/a{1}.jpeg?g=15", WWTUtil.GetServerID(tileX, tileY), WWTUtil.GetTileID(tileX, tileY, level, false));

            byte[] dat = client.DownloadData(url);


            client.Dispose();

            context.Response.OutputStream.Write(dat, 0, dat.Length);
        }
Ejemplo n.º 20
0
        public override void Run(IWwtContext context)
        {
            string query = "";

            if (context.Request.Params["Q"] != null)
            {
                query = context.Request.Params["Q"];
            }
            else
            {
                context.Response.Write("No image");
                context.Response.End();
                return;
            }

            string veKey = query;

            int level = 0;
            int tileX = 0;
            int tileY = 0;

            level = WWTUtil.GetTileAddressFromVEKey(veKey, out tileX, out tileY);


            string filename;
            string path;

            string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true);

            filename = String.Format(DSSTileCache + "\\VE\\level{0}\\{2}\\{1}_{2}.jpg", level, tileX, tileY);
            path     = String.Format(DSSTileCache + "\\VE\\level{0}\\{2}", level, tileX, tileY);


            if (level > 20)
            {
                context.Response.Write("No image");
                context.Response.Close();
                return;
            }


            if (!File.Exists(filename))
            {
                if (level == 8 || level == 13)
                {
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    WWTUtil.DownloadVeTile(level, tileX, tileY, true);

                    float[][] ptsArray =
                    {
                        new float[] { 1, 0, 0,    0, 0 },
                        new float[] { 0, 1, 0,    0, 0 },
                        new float[] { 0, 0, 1,    0, 0 },
                        new float[] { 0, 0, 0, 0.5f, 0 },
                        new float[] { 0, 0, 0,    0, 1 }
                    };
                    ColorMatrix     clrMatrix     = new ColorMatrix(ptsArray);
                    ImageAttributes imgAttributes = new ImageAttributes();
                    imgAttributes.SetColorMatrix(clrMatrix,
                                                 ColorMatrixFlag.Default,
                                                 ColorAdjustType.Bitmap);
                    Bitmap   bmp = new Bitmap(WWTUtil.DownloadVeTile(level, tileX, tileY, true));
                    Graphics g   = Graphics.FromImage(bmp);
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    for (int y = 0; y < 2; y++)
                    {
                        for (int x = 0; x < 2; x++)
                        {
                            string   tempName = WWTUtil.DownloadVeTile(level + 1, tileX * 2 + x, tileY * 2 + y, false);
                            FileInfo fi       = new FileInfo(tempName);
                            if (fi.Length != 0 && fi.Length != 1033)
                            {
                                Bitmap temp = new Bitmap(tempName);

                                g.DrawImage(temp, new Rectangle(x * 128, y * 128, 128, 128), 0, 0, 256, 256, GraphicsUnit.Pixel, imgAttributes);
                            }
                        }
                    }
                    g.Dispose();
                    bmp.Save(filename, ImageFormat.Jpeg);
                    bmp.Dispose();
                }
                else
                {
                    WWTUtil.DownloadVeTile(level, tileX, tileY, false);
                }
            }
            try
            {
                context.Response.WriteFile(filename);
            }
            catch
            {
            }
            context.Response.End();
        }
Ejemplo n.º 21
0
        public override void Run(IWwtContext context)
        {
            string query = context.Request.Params["Q"];
            bool   debug = context.Request.Params["debug"] != null;

            string[] values  = query.Split(',');
            int      level   = Convert.ToInt32(values[0]);
            int      tileX   = Convert.ToInt32(values[1]);
            int      tileY   = Convert.ToInt32(values[2]);
            string   wmsUrl  = values[3];
            string   dirPart = _hasher.HashName(wmsUrl).ToString();
            string   filename;
            string   path;

            string DSSTileCache = WWTUtil.GetCurrentConfigShare("DSSTileCache", true);

            filename = String.Format(DSSTileCache + "\\WMS\\{3}\\{0}\\{2}\\{2}_{1}.png", level, tileX, tileY, dirPart);
            path     = String.Format(DSSTileCache + "\\WMS\\{3}\\{0}\\{2}", level, tileX, tileY, dirPart);

            if (level > 15)
            {
                context.Response.Write("No image");
                context.Response.End();
                return;
            }



            if (File.Exists(filename))
            {
                try
                {
                    context.Response.WriteFile(filename);
                    return;
                }
                catch
                {
                }
            }
            else

            {
                ToastTileMap map = new ToastTileMap(level, tileX, tileY);

                Int32 sqSide = 256;


                Bitmap     bmpOutput     = new Bitmap(sqSide, sqSide);
                FastBitmap bmpOutputFast = new FastBitmap(bmpOutput);
                WMSImage   sdim          = new WMSImage(map.raMin, map.decMax, map.raMax, map.decMin);
                if (debug)
                {
                    context.Response.Clear();
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(sdim.LoadImage(wmsUrl, true, ImageSource.MarsAsu));
                    context.Response.End();
                    return;
                }
                sdim.LoadImage(wmsUrl, false, ImageSource.MarsAsu);
                sdim.Lock();

                bmpOutputFast.LockBitmap();
                // Fill up bmp from sdim
                // context.Response.Clear();
                //  context.Response.ContentType = "text/plain";
                Vector2d vxy, vradec;
                unsafe
                {
                    for (int y = 0; y < sqSide; y++)
                    {
                        var pPixel = bmpOutputFast[0, y];
                        vxy.Y = (y / 255.0);
                        for (int x = 0; x < sqSide; x++)
                        {
                            vxy.X  = (x / 255.0);
                            vradec = map.PointToRaDec(vxy.X, vxy.Y);
                            *pPixel = sdim.GetPixelDataAtRaDec(vradec);

                            //context.Response.Write(sdim.GetPixelDataAtRaDecString(vradec));
                            //context.Response.Write("\n");

                            pPixel++;
                        }
                    }
                }
                //   context.Response.End();

                //sdim.Unlock();
                bmpOutputFast.UnlockBitmap();

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                bmpOutput.Save(filename, ImageFormat.Png);
                bmpOutput.Dispose();
                try
                {
                    context.Response.WriteFile(filename);
                }
                catch
                {
                }
            }

            context.Response.End();
        }