Esempio n. 1
0
        public override void MouseClick(ObjectClickEventArgs e)
        {
            if (m_State == FittingsState.Configuring)
            {
                m_OSDExcluderTool.MouseClick(e);
            }
            if (m_State == FittingsState.Solved)
            {
                IStarMap starMap = AstrometryContext.Current.StarMap;
                if (starMap != null)
                {
                    int            x, y;
                    StarMapFeature feature = starMap.GetFeatureInRadius(e.Pixel.X, e.Pixel.Y, 5);
                    if (feature != null)
                    {
                        x = feature.GetCenter().X;
                        y = feature.GetCenter().Y;
                    }
                    else
                    {
                        x = e.Pixel.X;
                        y = e.Pixel.Y;
                    }

                    int searchArea = Control.ModifierKeys == Keys.Shift ? 5 : 10;

                    PSFFit     psfFit;
                    ImagePixel pixelCent = starMap.GetPSFFit(x, y, searchArea, out psfFit);
                    if (pixelCent != null && pixelCent != ImagePixel.Unspecified)
                    {
                        PlateConstStarPair          selectedPair = null;
                        LeastSquareFittedAstrometry astrometry   = FittedAstrometryFromUserSelectedFitGrade();
                        if (astrometry != null)
                        {
                            foreach (PlateConstStarPair pair in astrometry.FitInfo.AllStarPairs)
                            {
                                if (Math.Abs(pair.x - pixelCent.X) < 2 &&
                                    Math.Abs(pair.y - pixelCent.Y) < 2)
                                {
                                    selectedPair = pair;
                                    break;
                                }
                            }
                        }

                        DrawHighResFeature(pixelCent, selectedPair, astrometry);
                    }
                    else
                    {
                        ClearZoomImage();
                    }
                }
            }
        }
Esempio n. 2
0
        internal void SelectStar(PlateConstStarPair selectedPair, PSFFit psfFit)
        {
            if (selectedPair != null)
            {
                lblStarNo.Text = selectedPair.StarNo.ToString();
                lblRA.Text     = AstroConvert.ToStringValue(selectedPair.RADeg / 15.0, "HH MM SS.TT");
                lblDE.Text     = AstroConvert.ToStringValue(selectedPair.DEDeg, "+DD MM SS.T");
                lblX.Text      = selectedPair.x.ToString("0.00");
                lblY.Text      = selectedPair.y.ToString("0.00");
                lblResRA.Text  = string.Format("{0}\"", selectedPair.FitInfo.ResidualRAArcSec.ToString("0.00"));
                lblResDE.Text  = string.Format("{0}\"", selectedPair.FitInfo.ResidualDEArcSec.ToString("0.00"));

                m_SelectedPSF = psfFit;
            }
            else
            {
                m_SelectedPSF = null;
            }

            pnlSelectedStar.Visible = selectedPair != null;
        }
Esempio n. 3
0
        public override void MouseMove(Point location)
        {
            IStarMap map = AstrometryContext.Current.StarMap;

            if (map == null)
            {
                return;
            }

            bool nearbyStarFound = false;

            AstrometricState state = AstrometryContext.Current.AstrometricState;

            if (state != null)
            {
                if (state.AstrometricFit != null)
                {
                    for (int radius = 1; radius < 8; radius++)
                    {
                        ImagePixel centroid = map.GetCentroid(location.X, location.Y, radius);
                        if (centroid == null)
                        {
                            continue;
                        }


                        foreach (PlateConstStarPair star in state.AstrometricFit.FitInfo.AllStarPairs)
                        {
                            if (Math.Abs(star.x - centroid.XDouble) < radius &&
                                Math.Abs(star.y - centroid.YDouble) < radius)
                            {
                                m_Object = star;

                                nearbyStarFound = true;
                                break;
                            }
                        }

                        if (nearbyStarFound)
                        {
                            break;
                        }
                    }

                    if (!nearbyStarFound)
                    {
                        m_State = SelectObjectState.NoObject;
                    }
                    else
                    {
                        m_State = SelectObjectState.ObjectLocked;
                    }


                    if (m_AstrometricState.MeasuringState == AstrometryInFramesState.Ready)
                    {
                        double ra, de;
                        state.AstrometricFit.GetRADEFromImageCoords(location.X, location.Y, out ra, out de);

                        string moreInfo = string.Format("RA={0} DE={1}", AstroConvert.ToStringValue(ra / 15, "HHhMMmSS.Ts"), AstroConvert.ToStringValue(de, "+DD°MM'SS\""));
                        m_VideoController.DisplayCursorPositionDetails(location, moreInfo);
                    }
                }
                else
                {
                    StarMapFeature nearbyFeature = map.GetFeatureInRadius(location.X, location.Y, 8);
                    nearbyStarFound = nearbyFeature != null && nearbyFeature.PixelCount > 4;
                }

                m_VideoController.SetPictureBoxCursor(nearbyStarFound ? Cursors.Hand : (state.ManualStarIdentificationMode ? Cursors.Cross : Cursors.Default));
            }
        }
Esempio n. 4
0
        public void DrawCatalogStarsFit(Graphics g)
        {
            if (m_CatalogueStars == null)
            {
                m_LimitMag = -100;
                return;
            }

            bool hasManualStars =
                m_Is3StarIdMode &&
                m_UserStarIdentification != null &&
                m_UserStarIdentification.Count > 0;

            LeastSquareFittedAstrometry astrometry = null;

            astrometry = FittedAstrometryFromUserSelectedFitGrade();
            IAstrometricFit fit = null;

            if (astrometry != null)
            {
                fit = astrometry;
            }
            else
            {
                fit = m_SolvedPlate;
            }

            if (fit != null)
            {
                double limitMag = (astrometry != null && astrometry.FitInfo.AllStarPairs.Count > 0)
                                        ? astrometry.FitInfo.AllStarPairs.Max(p => p.Mag)
                                        : m_LimitMag;

                foreach (IStar star in m_CatalogueStars)
                {
                    if (star.Mag > limitMag)
                    {
                        continue;
                    }

                    double x, y;
                    fit.GetImageCoordsFromRADE(star.RADeg, star.DEDeg, out x, out y);

                    Pen   starPen     = catalogStarPen;
                    Brush labelBruish = catalogBrushUnrecognized;

                    if (astrometry != null)
                    {
                        PlateConstStarPair pair = astrometry.FitInfo.AllStarPairs.Find((p) => p.StarNo == star.StarNo);

                        if (pair != null && pair.FitInfo.UsedInSolution)
                        {
                            starPen     = referenceStarPen;
                            labelBruish = catalogBrushReference;
                        }
                        else if (pair != null && pair.FitInfo.ExcludedForHighResidual)
                        {
                            starPen     = rejectedStarPen;
                            labelBruish = catalogBrushRejected;
                        }
                        else
                        {
                            starPen     = unrecognizedStarPen;
                            labelBruish = catalogBrushUnrecognized;
                        }

                        if (pair != null)
                        {
                            g.DrawLine(starPen, (float)x, (float)y, (float)pair.x, (float)pair.y);
                        }
                    }

                    if (!m_Is3StarIdMode || astrometry != null)
                    {
                        float rad = (float)GetStarDiameter(m_LimitMag, 5, star.Mag) / 2;
                        g.DrawEllipse(starPen, (float)x - rad, (float)y - rad, 2 * rad, 2 * rad);
                    }

                    if (m_ShowLabels || m_ShowMagnitudes)
                    {
                        string label;
                        if (m_ShowLabels && m_ShowMagnitudes)
                        {
                            label = string.Format("{0} ({1}m)", star.GetStarDesignation(0), star.Mag);
                        }
                        else if (m_ShowLabels)
                        {
                            label = string.Format("{0}", star.GetStarDesignation(0));
                        }
                        else
                        {
                            label = string.Format("{0}m", star.Mag);
                        }

                        g.DrawString(label, m_StarInfoFont, labelBruish, (float)x + 10, (float)y + 10);
                    }
                }

                if (m_Is3StarIdMode && astrometry == null)
                {
                    // Draw all features from the starMap (unless the configuration has been solved)
                    if (AstrometryContext.Current.StarMap != null)
                    {
                        foreach (StarMapFeature feature in AstrometryContext.Current.StarMap.Features)
                        {
                            ImagePixel center = feature.GetCenter();

                            PSFFit psfFit;
                            AstrometryContext.Current.StarMap.GetPSFFit(center.X, center.Y, PSFFittingMethod.NonLinearAsymetricFit, out psfFit);

#if ASTROMETRY_DEBUG
                            PSFFit psfFit2;
                            AstrometryContext.Current.StarMap.GetPSFFit(center.X, center.Y, PSFFittingMethod.NonLinearFit, out psfFit2);
                            double elong     = psfFit.RX0 / psfFit.RY0;
                            double elongPerc = Math.Abs(1 - elong) * 100;
                            Trace.WriteLine(string.Format("({0:0}, {1:0}) Rx = {2:0.00} Ry = {3:0.00}, e = {4:0.000} ({5:0}%), FWHMxy = {6:0.0} | FWHMxx = {7:0.0}",
                                                          center.X, center.Y, psfFit.RX0, psfFit.RY0, elong, elongPerc,
                                                          psfFit.FWHM, psfFit2.FWHM));
#endif
                            Pen pen = catalogStarPen;

#if ASTROMETRY_DEBUG
                            if (psfFit.FWHM < TangraConfig.Settings.Astrometry.MinReferenceStarFWHM ||
                                psfFit.FWHM > TangraConfig.Settings.Astrometry.MaxReferenceStarFWHM ||
                                psfFit.ElongationPercentage > TangraConfig.Settings.Astrometry.MaximumPSFElongation)
                            {
                                pen = rejectedStarPen;
                            }
#endif

                            g.DrawLine(pen, (float)center.XDouble - 9, (float)center.YDouble, (float)center.XDouble - 5, (float)center.YDouble);
                            g.DrawLine(pen, (float)center.XDouble + 5, (float)center.YDouble, (float)center.XDouble + 9, (float)center.YDouble);
                            g.DrawLine(pen, (float)center.XDouble, (float)center.YDouble - 9, (float)center.XDouble, (float)center.YDouble - 5);
                            g.DrawLine(pen, (float)center.XDouble, (float)center.YDouble + 5, (float)center.XDouble, (float)center.YDouble + 9);
                        }
                    }
                }
                else
                {
                    if (m_Grid)
                    {
                        DrawEquatorialGrid(g);
                    }
                }

                #region Draw the manual single star identification
                if (hasManualStars)
                {
                    foreach (PSFFit psf in m_UserStarIdentification.Keys)
                    {
                        IStar star = m_UserStarIdentification[psf];

                        float rad = (float)GetStarDiameter(m_LimitMag, 5, star.Mag) / 2;

                        g.DrawEllipse(Pens.DarkRed, (float)psf.XCenter - rad, (float)psf.YCenter - rad, 2 * rad, 2 * rad);
                        g.DrawEllipse(Pens.DarkRed, (float)psf.XCenter - rad - 2, (float)psf.YCenter - rad - 2, 2 * rad + 4, 2 * rad + 4);
                    }
                }
                #endregion ;
            }

            UpdateToolControlDisplay();
        }
Esempio n. 5
0
        public override void PostDraw(Graphics g)
        {
            if (m_CatalogueStars == null)
            {
                if (AstrometryContext.Current.StarMap != null)
                {
                    foreach (StarMapFeature feature in AstrometryContext.Current.StarMap.Features)
                    {
                        ImagePixel center = feature.GetCenter();

                        g.DrawEllipse(Pens.Red, center.X - 2, center.Y - 2, 5, 5);
                    }
                }
            }
            else if (m_CatalogueStars != null && m_State == FittingsState.Configuring)
            {
                if (m_SolvedPlate != null && m_PlateCalibrator.ConstantsSolver != null)
                {
                    foreach (IStar star in m_CatalogueStars)
                    {
                        if (star.Mag > m_LimitMag)
                        {
                            continue;
                        }

                        double x, y;
                        m_SolvedPlate.GetImageCoordsFromRADE(star.RADeg, star.DEDeg, out x, out y);

                        PlateConstStarPair pair = m_PlateCalibrator.ConstantsSolver.Pairs.FirstOrDefault((p) => p.StarNo == star.StarNo);

                        Pen starPen = catalogStarPen;
                        if (pair == null)
                        {
                            starPen = rejectedStarPen;
                        }
                        else if (!pair.FitInfo.ExcludedForHighResidual)
                        {
                            starPen = referenceStarPen;

                            if (AstrometryContext.Current.StarMap != null)
                            {
                                StarMapFeature feature =
                                    AstrometryContext.Current.StarMap.Features.FirstOrDefault((f) => f.FeatureId == pair.FeatureId);
                                if (feature != null)
                                {
                                    g.DrawLine(Pens.Beige, (float)x, (float)y, (float)feature.GetCenter().XDouble,
                                               (float)feature.GetCenter().YDouble);
                                }
                            }
                        }

                        g.DrawLine(starPen, (float)x - 3, (float)y, (float)x + 3, (float)y);
                        g.DrawLine(starPen, (float)x, (float)y - 3, (float)x, (float)y + 3);
                    }
                }
            }
            else
            {
                DrawCatalogStarsFit(g);
            }

            g.Save();
        }
Esempio n. 6
0
        // TODO: Use the imeplementation in the MainForm instead
        private void DrawHighResFeature(ImagePixel pixel, PlateConstStarPair selectedPair, LeastSquareFittedAstrometry astrometry)
        {
            int x0 = pixel.X;
            int y0 = pixel.Y;

            if (x0 < 15)
            {
                x0 = 15;
            }
            if (y0 < 15)
            {
                y0 = 15;
            }
            if (x0 > AstrometryContext.Current.FullFrame.Width - 15)
            {
                x0 = AstrometryContext.Current.FullFrame.Width - 15;
            }
            if (y0 > AstrometryContext.Current.FullFrame.Height - 15)
            {
                y0 = AstrometryContext.Current.FullFrame.Height - 15;
            }

            int bytes;
            int bytesPerPixel;
            int selIdx;

            Bitmap featureBitmap = new Bitmap(31 * 8, 31 * 8, PixelFormat.Format24bppRgb);

            m_VideoController.UpdateZoomedImage(featureBitmap, pixel);

            BitmapData zoomedData = featureBitmap.LockBits(new Rectangle(0, 0, 31 * 8, 31 * 8), ImageLockMode.ReadWrite, featureBitmap.PixelFormat);

            try
            {
                bytes = zoomedData.Stride * featureBitmap.Height;
                byte[] zoomedValues = new byte[bytes];

                Marshal.Copy(zoomedData.Scan0, zoomedValues, 0, bytes);

                bytesPerPixel = AstrometryContext.Current.BytesPerPixel;

                byte saturatedR = TangraConfig.Settings.Color.Saturation.R;
                byte saturatedG = TangraConfig.Settings.Color.Saturation.G;
                byte saturatedB = TangraConfig.Settings.Color.Saturation.B;

                selIdx = 0;
                for (int y = 0; y < 31; y++)
                {
                    for (int x = 0; x < 31; x++)
                    {
                        for (int i = 0; i < 8; i++)
                        {
                            for (int j = 0; j < 8; j++)
                            {
                                int zoomedX = 8 * x + i;
                                int zoomedY = 8 * y + j;

                                int zoomedIdx = zoomedData.Stride * zoomedY + zoomedX * bytesPerPixel;

                                if (zoomedValues[zoomedIdx] > TangraConfig.Settings.Photometry.Saturation.Saturation8Bit)
                                {
                                    // Saturation detected
                                    zoomedValues[zoomedIdx]     = saturatedR;
                                    zoomedValues[zoomedIdx + 1] = saturatedG;
                                    zoomedValues[zoomedIdx + 2] = saturatedB;
                                }
                            }
                        }

                        selIdx++;
                    }
                }

                Marshal.Copy(zoomedValues, 0, zoomedData.Scan0, bytes);
            }
            finally
            {
                featureBitmap.UnlockBits(zoomedData);
            }

            Pen starPen = catalogStarPen;

            double xFitUnscaled = pixel.XDouble;
            double yFitUnscaled = pixel.YDouble;

            if (selectedPair != null && selectedPair.FitInfo.UsedInSolution)
            {
                starPen = referenceStarPen;
                astrometry.GetImageCoordsFromRADE(selectedPair.RADeg, selectedPair.DEDeg, out xFitUnscaled, out yFitUnscaled);
            }
            else if (selectedPair != null && selectedPair.FitInfo.ExcludedForHighResidual)
            {
                starPen = rejectedStarPen;
                astrometry.GetImageCoordsFromRADE(selectedPair.RADeg, selectedPair.DEDeg, out xFitUnscaled, out yFitUnscaled);
            }
            else
            {
                starPen = unrecognizedStarPen;
            }

            double xFit = (8 * (xFitUnscaled - x0 + 16)) - 4;
            double yFit = (8 * (yFitUnscaled - y0 + 16)) - 4;
        }