コード例 #1
0
        private void HistogramView_MouseMove(object sender, MouseEventArgs e)
        {
            switch (dragType)
            {
                case DragType.Low:
                    lowPosition = Math.Min(255, Math.Max(0, e.X));
                    break;
                case DragType.High:
                    highPosition = Math.Min(255, Math.Max(0, e.X));
                    break;
                case DragType.Range:
                    lowPosition = downPosition;
                    highPosition = Math.Min(255, Math.Max(0, e.X));
                    break;
                case DragType.Center:
                    int hWidth = Math.Abs(highPosition-lowPosition)/2;
                    int adCenter = Math.Min(255 - hWidth, Math.Max(hWidth, e.X));
                    int moved = center - adCenter;
                    lowPosition -= moved;
                    highPosition -= moved;
                    break;
                case DragType.None:
                    return;
                default:
                    break;
            }
            center = (lowPosition + highPosition) / 2;
            HistogramView.Refresh();
            double factor = (image.MaxVal - image.MinVal) / 256.0;
            double low = image.MinVal + (lowPosition * factor);
            double hi = image.MinVal + (highPosition * factor);

            this.Tile = (SkyImageTile)TileCache.GetTile(Tile.Level, Tile.X, Tile.Y, Tile.Dataset, null);
            updateTimer.Enabled = false;
            updateTimer.Enabled = true;
            image.lastMax = highPosition;
            image.lastMin = lowPosition;
        }
コード例 #2
0
        public bool MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (Earth3d.MainWindow.StudyImageset == null)
            {
                return(false);
            }
            if (dragging)
            {
                Tile root = TileCache.GetTile(0, 0, 0, Earth3d.MainWindow.StudyImageset, null);
                root.CleanUpGeometryRecursive();

                bool twoRoots = false;

                if (Earth3d.MainWindow.StudyImageset.Projection == ProjectionType.Tangent && Earth3d.MainWindow.StudyImageset.WidthFactor == 1)
                {
                    twoRoots = true;
                }

                if (anchored)
                {
                    if (root is SkyImageTile)
                    {
                        SkyImageTile tile   = (SkyImageTile)root;
                        Coordinates  point2 = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y);


                        WcsFitter fitter = new WcsFitter(tile.Width, tile.Height);
                        fitter.AddPoint(anchoredPoint1, anchorPoint1);
                        fitter.AddPoint(point2, anchorPoint2);
                        fitter.Solve();
                        Earth3d.MainWindow.StudyImageset.BaseTileDegrees = fitter.Solution.Scale;
                        Earth3d.MainWindow.StudyImageset.Rotation        = (fitter.Solution.Rotation);
                        Earth3d.MainWindow.StudyImageset.CenterX         = (fitter.Solution.CenterX * 15);
                        Earth3d.MainWindow.StudyImageset.CenterY         = fitter.Solution.CenterY;
                        Earth3d.MainWindow.StudyImageset.OffsetX         = fitter.Solution.OffsetX;
                        Earth3d.MainWindow.StudyImageset.OffsetY         = fitter.Solution.OfsetY;
                    }
                    else
                    {
                        Coordinates downPoint = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y);
                        double      len       = anchoredPoint1.Distance(downPoint);
                        double      angle     = anchoredPoint1.Angle(downPoint) / RC;
                        Earth3d.MainWindow.Text = String.Format("Angle = {0}", angle);
                        Earth3d.MainWindow.StudyImageset.BaseTileDegrees = startScale * (len / startLength);
                        Earth3d.MainWindow.StudyImageset.Rotation        = startRotation - (angle - startAngle);
                    }
                }
                else
                {
                    double factor = 1.0;
                    if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt)
                    {
                        factor = .01;
                    }

                    if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
                    {
                        double rotation = (pntDown.X - e.Location.X) / 50.0;
                        rotation *= factor;
                        Earth3d.MainWindow.StudyImageset.Rotation += rotation;
                        Earth3d.MainWindow.StudyImageset.Rotation  = Earth3d.MainWindow.StudyImageset.Rotation % 360;
                    }
                    else if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
                    {
                        double scale = 1.0 + (((pntDown.X - e.Location.X) / 500.0) * factor);
                        Earth3d.MainWindow.StudyImageset.BaseTileDegrees *= scale;
                        if (Earth3d.MainWindow.StudyImageset.BaseTileDegrees > 180)
                        {
                            Earth3d.MainWindow.StudyImageset.BaseTileDegrees = 180;
                        }
                    }
                    else
                    {
                        double moveX = (pntDown.X - e.Location.X) * Earth3d.MainWindow.GetPixelScaleX(true);
                        double moveY = (pntDown.Y - e.Location.Y) * Earth3d.MainWindow.GetPixelScaleY();
                        Earth3d.MainWindow.StudyImageset.CenterX += moveX;
                        Earth3d.MainWindow.StudyImageset.CenterY += moveY;
                    }
                    pntDown = e.Location;
                }

                if (twoRoots)
                {
                    Tile root2 = TileCache.GetTile(0, 1, 0, Earth3d.MainWindow.StudyImageset, null);
                    root2.CleanUpGeometryRecursive();
                }
            }
            return(false);
        }
コード例 #3
0
        public bool MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (Earth3d.MainWindow.StudyImageset == null)
            {
                mouseDown = false;
                return(false);
            }
            Tile root = TileCache.GetTile(0, 0, 0, Earth3d.MainWindow.StudyImageset, null);

            if (root == null)
            {
                mouseDown = false;
                return(false);
            }
            if (e.Button == MouseButtons.Right && (root is SkyImageTile))
            {
                anchored = !anchored;
                popup.SetPivotMode(anchored);
                if (anchored)
                {
                    anchoredPoint1 = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y);
                    TourPlace place = new TourPlace("", anchoredPoint1.Dec, anchoredPoint1.RA, Classification.Unidentified, "UMA", ImageSetType.Sky, -1);
                    Earth3d.MainWindow.SetLabelText(place, false);
                    if (root is TangentTile)
                    {
                        TangentTile tile   = (TangentTile)root;
                        Vector3d    vector = tile.TransformPoint(12, 12);
                        vector = Coordinates.GeoTo3dDouble(anchoredPoint1.Lat, anchoredPoint1.Lng);
                        double x;
                        double y;
                        tile.UnTransformPoint(vector, out x, out y);
                    }
                    else if (root is SkyImageTile)
                    {
                        SkyImageTile tile = (SkyImageTile)root;
                        anchorPoint1 = tile.GetImagePixel(anchoredPoint1);
                    }
                }
                mouseDown = true;
                return(true);
            }
            else if (e.Button == MouseButtons.Left)
            {
                dragging = true;
                pntDown  = e.Location;
                if (anchored)
                {
                    if (root is TangentTile)
                    {
                        startRotation = Earth3d.MainWindow.StudyImageset.Rotation;
                        startCenterX  = Earth3d.MainWindow.StudyImageset.OffsetX;
                        startCenterY  = Earth3d.MainWindow.StudyImageset.OffsetY;
                        startScale    = Earth3d.MainWindow.StudyImageset.BaseTileDegrees;
                        Coordinates downPoint = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y);
                        startLength = anchoredPoint1.Distance(downPoint);
                        startAngle  = anchoredPoint1.Angle(downPoint) / RC;
                    }
                    else if (root is SkyImageTile)
                    {
                        SkyImageTile tile = (SkyImageTile)root;
                        anchoredPoint2 = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y);
                        anchorPoint2   = tile.GetImagePixel(anchoredPoint2);
                    }
                }
                mouseDown = true;
                return(true);
            }
            else
            {
                mouseDown = false;
                return(false);
            }
        }
コード例 #4
0
        public static Tile GetTileFromWeb(Tile retTile, bool Initialize)
        {
            WebClient Client = null;

            if (retTile.Dataset.Projection == ProjectionType.SkyImage && retTile.Dataset.Url.EndsWith("/screenshot.png"))
            {
                SkyImageTile tile = retTile as SkyImageTile;
                Client = new WebClient();
                string url = tile.URL;
                tile.ImageData        = Client.DownloadData(url);
                retTile.DemReady      = true;
                retTile.FileExists    = true;
                retTile.ReadyToRender = true;
                retTile.TextureReady  = true;

                //retTile.CreateGeometry(Tile.prepDevice);
                Client.Dispose();
                return(retTile);
            }

            Tile parent = retTile.Parent;

            if (retTile.DemEnabled && (parent == null || (parent != null && parent.DemGeneration == 0)))
            {
                GetDemTileFromWeb(retTile);
            }
            else
            {
                retTile.DemReady = true;
            }

            if (retTile.Dataset.WcsImage != null && retTile.Dataset.WcsImage is FitsImage)
            {
                retTile.TextureReady = true;
                InitializeTile(retTile);
                return(retTile);
            }


            string directory = retTile.Directory;

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

            string filename = retTile.FileName;

            Client = new WebClient();

            FileInfo fi     = new FileInfo(filename);
            bool     exists = fi.Exists;

            if (exists)
            {
                if (fi.Length != 8 && fi.Length < 100 || retTile.Volitile)
                {
                    try
                    {
                        File.Delete(filename);
                    }
                    catch
                    {
                    }
                    exists = false;
                }
            }


            if (!exists)
            {
                try
                {
                    if (retTile.Dataset.IsMandelbrot)
                    {
                        retTile.ComputeMandel();
                        fi     = new FileInfo(filename);
                        exists = fi.Exists;
                    }
                    else
                    {
                        Client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");
                        string url = retTile.URL;
                        if (string.IsNullOrEmpty(url))
                        {
                            retTile.errored = true;
                        }
                        else
                        {
                            string dlFile = string.Format("{0}.tmp{1}", filename, NodeID);



                            Client.DownloadFile(CacheProxy.GetCacheUrl(url), dlFile);
                            try
                            {
                                if (File.Exists(dlFile))
                                {
                                    if (File.Exists(filename))
                                    {
                                        File.Delete(filename);
                                    }
                                    File.Move(dlFile, filename);
                                }
                            }
                            catch
                            {
                                //   UiTools.ShowMessageBox("File Download collision catch");
                            }
                            fi     = new FileInfo(filename);
                            exists = fi.Exists;
                        }
                        // Code for drawing tile it onto tile for debuggin
                        //if (retTile.Dataset.Projection == ProjectionType.Toast)
                        //{
                        //    //Bitmap bmpText = new Bitmap(filename);
                        //    Bitmap bmpText = UiTools.LoadBitmap(filename);
                        //    Graphics g = Graphics.FromImage(bmpText);
                        //    g.DrawString(retTile.Key, UiTools.StandardRegular, UiTools.StadardTextBrush, new RectangleF(0, 0, 255, 255), UiTools.StringFormatCenterCenter);
                        //    g.Flush();
                        //    g.Dispose();
                        //    bmpText.Save(filename);

                        //    bmpText.Dispose();
                        //}
                    }
                }
                catch
                {
                    //todo retry login on non - HTTP failuers.
                    if (Earth3d.Logging)
                    {
                        Earth3d.WriteLogMessage("Tile Download: Exception");
                    }
                    retTile.errored = true;
                }
            }
            try
            {
                if (exists)
                {
                    if (fi.Length < 100 || (fi.Length == 1033))
                    {
                        retTile.errored = true;
                        return(retTile);
                    }
                }

                // todo 3d Cities remove support for 3d Cities for now
                if (retTile.Dataset.Projection == ProjectionType.Mercator && Properties.Settings.Default.Show3dCities)
                {
                    string tileID = retTile.GetTileID();

                    //check coverage cache before downloading
                    int gen = CoverageMap.GetCoverage(tileID);
                    if (gen > 0)
                    {
                        //try downloading mesh
                        try
                        {
                            string meshFilename = retTile.FileName + ".mesh";

                            if (!File.Exists(meshFilename))
                            {
                                Client.Headers.Add("User-Agent", "Win8Microsoft.BingMaps.3DControl/2.214.2315.0 (;;;;x64 Windows RT)");

                                string dlFile = string.Format("{0}.tmp{1}", meshFilename, NodeID);


                                Client.DownloadFile(string.Format("http://ak.t{1}.tiles.virtualearth.net/tiles/mtx{0}?g={2}", tileID, Tile.GetServerID(retTile.X, retTile.Y), gen.ToString()), dlFile);

                                try
                                {
                                    if (File.Exists(dlFile))
                                    {
                                        if (File.Exists(meshFilename))
                                        {
                                            File.Delete(meshFilename);
                                        }
                                        File.Move(dlFile, meshFilename);
                                    }
                                }
                                catch
                                {
                                    //  UiTools.ShowMessageBox("File Download collision catch");
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }

                retTile.FileExists = true;

                retTile.TextureReady = true;


                if (Initialize)
                {
                    InitializeTile(retTile);
                }
            }
            catch (System.Exception)
            {
                if (Earth3d.Logging)
                {
                    Earth3d.WriteLogMessage("Tile Initialize: Exception");
                }
                retTile.errored = true;
            }

            return(retTile);
        }