Beispiel #1
0
        public frmAbsFlux(TangraConfig.SpectraViewDisplaySettings displaySetting)
            : this()
        {
            m_DisplaySetting = displaySetting;

            m_NewlyOpened = true;
            m_AbsFluxCalibrator = new AbsFluxCalibrator();

            UpdateUIState();
        }
Beispiel #2
0
        public frmAbsFlux(TangraConfig.SpectraViewDisplaySettings displaySetting)
            : this()
        {
            m_DisplaySetting = displaySetting;

            m_NewlyOpened       = true;
            m_AbsFluxCalibrator = new AbsFluxCalibrator();

            UpdateUIState();
        }
        internal SpectroscopyController(Form mainFormView, VideoController videoController)
        {
            m_MainFormView = mainFormView;
            m_VideoController = videoController;
            m_ViewSpectraForm = null;
            SpectraReductionContext = new SpectraReductionContext();

            m_DisplaySettings = new TangraConfig.SpectraViewDisplaySettings();
            m_DisplaySettings.Load();
            m_DisplaySettings.Initialize();
        }
        internal SpectroscopyController(Form mainFormView, VideoController videoController)
        {
            m_MainFormView          = mainFormView;
            m_VideoController       = videoController;
            m_ViewSpectraForm       = null;
            SpectraReductionContext = new SpectraReductionContext();

            m_DisplaySettings = new TangraConfig.SpectraViewDisplaySettings();
            m_DisplaySettings.Load();
            m_DisplaySettings.Initialize();
        }
Beispiel #5
0
        public frmViewSpectra(SpectroscopyController controller, VideoController videoController, TangraConfig.SpectraViewDisplaySettings displaySettings)
            : this()
        {
            m_SpectroscopyController = controller;
            m_DisplaySettings = displaySettings;

            picSpectraGraph.Image = new Bitmap(picSpectraGraph.Width, picSpectraGraph.Height, PixelFormat.Format24bppRgb);
            picSpectra.Image = new Bitmap(picSpectra.Width, picSpectra.Height, PixelFormat.Format24bppRgb);

            m_StateManager = new SpectraViewerStateManager(m_SpectroscopyController, picSpectraGraph, this);
            m_VideoController = videoController;
        }
Beispiel #6
0
        public frmViewSpectra(SpectroscopyController controller, VideoController videoController, TangraConfig.SpectraViewDisplaySettings displaySettings)
            : this()
        {
            m_SpectroscopyController = controller;
            m_DisplaySettings        = displaySettings;

            picSpectraGraph.Image = new Bitmap(picSpectraGraph.Width, picSpectraGraph.Height, PixelFormat.Format24bppRgb);
            picSpectra.Image      = new Bitmap(picSpectra.Width, picSpectra.Height, PixelFormat.Format24bppRgb);

            m_StateManager    = new SpectraViewerStateManager(m_SpectroscopyController, picSpectraGraph, this);
            m_VideoController = videoController;
        }
Beispiel #7
0
 public void SetSpectraViewFormCustomizer(ISpectraViewFormCustomizer spectraViewCustomizer)
 {
     m_SpectraViewCustomizer = spectraViewCustomizer;
     if (spectraViewCustomizer != null)
     {
         m_DisplaySettings = spectraViewCustomizer.FormDisplaySettings;
     }
     else
     {
         m_DisplaySettings = new TangraConfig.SpectraViewDisplaySettings();
         m_DisplaySettings.Load();
         m_DisplaySettings.Initialize();
     }
 }
 public void SetSpectraViewFormCustomizer(ISpectraViewFormCustomizer spectraViewCustomizer)
 {
     m_SpectraViewCustomizer = spectraViewCustomizer;
     if (spectraViewCustomizer != null)
     {
         m_DisplaySettings = spectraViewCustomizer.FormDisplaySettings;
     }
     else
     {
         m_DisplaySettings = new TangraConfig.SpectraViewDisplaySettings();
         m_DisplaySettings.Load();
         m_DisplaySettings.Initialize();
     }
 }
Beispiel #9
0
        public frmSpectraViewSettings(TangraConfig.SpectraViewDisplaySettings displaySettings, frmViewSpectra frmSpectraView)
        {
            InitializeComponent();

            m_frmSpectraView  = frmSpectraView;
            m_DisplaySettings = displaySettings;

            m_DontApplySettingsBack = true;
            try
            {
                ucColorPickerReferenceStar.SelectedColor = m_DisplaySettings.SpectraLineColor;
                ucColorPickerKnownLine.SelectedColor     = m_DisplaySettings.KnownLineColor;
                ucColorPickerGridLines.SelectedColor     = m_DisplaySettings.GridLinesColor;
                ucColorPickerGridLegend.SelectedColor    = m_DisplaySettings.LegendColor;
                ucColorPickerAperture.SelectedColor      = m_DisplaySettings.SpectraApertureColor;
                ucColorPickerBackground.SelectedColor    = m_DisplaySettings.PlotBackgroundColor;
            }
            finally
            {
                m_DontApplySettingsBack = false;
            }
        }
        public frmSpectraViewSettings(TangraConfig.SpectraViewDisplaySettings displaySettings, frmViewSpectra frmSpectraView)
        {
            InitializeComponent();

            m_frmSpectraView = frmSpectraView;
            m_DisplaySettings = displaySettings;

            m_DontApplySettingsBack = true;
            try
            {
                ucColorPickerReferenceStar.SelectedColor = m_DisplaySettings.SpectraLineColor;
                ucColorPickerKnownLine.SelectedColor = m_DisplaySettings.KnownLineColor;
                ucColorPickerGridLines.SelectedColor = m_DisplaySettings.GridLinesColor;
                ucColorPickerGridLegend.SelectedColor = m_DisplaySettings.LegendColor;
                ucColorPickerAperture.SelectedColor = m_DisplaySettings.SpectraApertureColor;
                ucColorPickerBackground.SelectedColor = m_DisplaySettings.PlotBackgroundColor;
            }
            finally
            {
                m_DontApplySettingsBack = false;
            }
        }
Beispiel #11
0
        private void ShowCommonLines(Graphics g, TangraConfig.SpectraViewDisplaySettings displaySettings)
        {
            SpectraCalibrator calibrator = m_SpectroscopyController.GetSpectraCalibrator();

            SizeF measuredLabel   = g.MeasureString("H", displaySettings.LegendFont);
            float verticalSpacing = measuredLabel.Height * 1.3f;

            for (int i = 0; i < SpectraLineLibrary.CommonLines.Count; i++)
            {
                LineEntry line = SpectraLineLibrary.CommonLines[i];
                float     x2   = 0;

                if (line.IsWideArea)
                {
                    int   pixelNo = calibrator.ResolvePixelNo(line.FromWavelength);
                    float x1      = GetMouseXFromSpectraPixel(pixelNo);
                    pixelNo = calibrator.ResolvePixelNo(line.ToWavelength);
                    x2      = GetMouseXFromSpectraPixel(pixelNo);

                    g.FillRectangle(displaySettings.KnownLineBrush, x1, i * verticalSpacing + 2 * BORDER_GAP, x2 - x1, m_View.Height - i * verticalSpacing - 2 * BORDER_GAP - Y_AXIS_WIDTH);
                    g.FillRectangle(displaySettings.KnownLineBrush, x1, m_View.Height - 10, x2 - x1, m_View.Height);
                }
                else
                {
                    int pixelNo = calibrator.ResolvePixelNo(line.FromWavelength);
                    x2 = GetMouseXFromSpectraPixel(pixelNo);

                    g.DrawLine(displaySettings.KnownLinePen, x2, i * verticalSpacing + 2 * BORDER_GAP, x2, m_View.Height - Y_AXIS_WIDTH);
                    g.DrawLine(displaySettings.KnownLinePen, x2, m_View.Height - 10, x2, m_View.Height);
                }

                g.DrawString(line.Designation != null
                    ? string.Format("{0} ({1})", line.Element, line.Designation)
                                        : line.Element, displaySettings.LegendFont, displaySettings.KnownLineLabelBrush, x2 + 3, i * verticalSpacing + 2 * BORDER_GAP);
            }
        }
Beispiel #12
0
        private void DrawXAxis(Graphics g, float scaleX, int width, float Y_AXIS_LEGEND_WIDTH, float y0, float y1, TangraConfig.SpectraViewDisplaySettings displaySetting)
        {
            float horizontalSpace = width - 2 * PADDING - Y_AXIS_LEGEND_WIDTH;

            int[] minorTicks          = new[] { 20, 50, 100, 100, 500, 500 };
            int[] xInterval           = new [] { 100, 200, 500, 1000, 2000, 5000 };
            SizeF size                = g.MeasureString("5000", displaySetting.LegendFont);
            int   INTERVAL            = 5000;
            int   MINOR_TICK_INTERVAL = 500;

            for (int i = 0; i < xInterval.Length; i++)
            {
                INTERVAL            = xInterval[i];
                MINOR_TICK_INTERVAL = minorTicks[i];
                int numTicks = (Context.ToWavelength - Context.FromWavelength) / INTERVAL;
                if (size.Width * 1.3f * numTicks < horizontalSpace)
                {
                    break;
                }
            }

            for (int w = INTERVAL * ((Context.FromWavelength / INTERVAL) - 1); w < Context.ToWavelength + INTERVAL; w += INTERVAL)
            {
                if (w < Context.FromWavelength)
                {
                    continue;
                }
                string markStr = w.ToString();
                size = g.MeasureString(markStr, displaySetting.LegendFont);
                float tickPos = (float)(PADDING + Y_AXIS_LEGEND_WIDTH + (w - Context.FromWavelength) * scaleX);
                if (tickPos - size.Width / 2.0f < PADDING + Y_AXIS_LEGEND_WIDTH)
                {
                    continue;
                }
                if (tickPos + size.Width / 2.0f > width - PADDING)
                {
                    break;
                }

                g.DrawLine(displaySetting.GridLinesPen, tickPos, y0, tickPos, y0 - LONG_MARK);
                g.DrawLine(displaySetting.GridLinesPen, tickPos, y1, tickPos, y1 + LONG_MARK);

                g.DrawString(markStr, displaySetting.LegendFont, displaySetting.LegendBrush, tickPos - size.Width / 2.0f, y0 + LONG_MARK);
            }

            for (int w = INTERVAL * ((Context.FromWavelength / INTERVAL) - 1); w < Context.ToWavelength + INTERVAL; w += MINOR_TICK_INTERVAL)
            {
                if (w < Context.FromWavelength)
                {
                    continue;
                }
                if (w % INTERVAL == 0)
                {
                    continue;
                }

                float tickPos = (PADDING + Y_AXIS_LEGEND_WIDTH + (w - Context.FromWavelength) * scaleX);
                if (tickPos < PADDING + Y_AXIS_LEGEND_WIDTH)
                {
                    continue;
                }
                if (tickPos > width - PADDING)
                {
                    break;
                }

                g.DrawLine(displaySetting.GridLinesPen, tickPos, y0, tickPos, y0 - SHORT_MARK);
                g.DrawLine(displaySetting.GridLinesPen, tickPos, y1, tickPos, y1 + SHORT_MARK);
            }
        }
Beispiel #13
0
        private void DrawYAxis(Graphics g, float scaleY, int height, float X_AXIS_LEGEND_HEIGHT, float x0, float x1, double maxFlux, double interval, double minorTicksinterval, string labelFormat, TangraConfig.SpectraViewDisplaySettings displaySetting)
        {
            bool zeroMark = true;

            for (double f = 0; f < maxFlux; f += interval)
            {
                string markStr = zeroMark ? "0" : f.ToString(labelFormat);

                zeroMark = false;

                SizeF size    = g.MeasureString(markStr, displaySetting.LegendFont);
                float tickPos = (float)(height - PADDING - X_AXIS_LEGEND_HEIGHT - f * scaleY);
                if (tickPos > height - X_AXIS_LEGEND_HEIGHT - PADDING)
                {
                    continue;
                }

                g.DrawLine(displaySetting.GridLinesPen, x0, tickPos, x0 + LONG_MARK, tickPos);
                g.DrawLine(displaySetting.GridLinesPen, x1, tickPos, x1 - LONG_MARK, tickPos);

                g.DrawString(markStr, displaySetting.LegendFont, displaySetting.LegendBrush, x0 - size.Width - LONG_MARK, tickPos - size.Height / 2.0f);
            }

            for (double f = 0; f < maxFlux; f += minorTicksinterval)
            {
                float tickPos = (float)(height - PADDING - X_AXIS_LEGEND_HEIGHT - f * scaleY);

                g.DrawLine(displaySetting.GridLinesPen, x0, tickPos, x0 + SHORT_MARK, tickPos);
                g.DrawLine(displaySetting.GridLinesPen, x1, tickPos, x1 - SHORT_MARK, tickPos);
            }
        }
Beispiel #14
0
        private void ComputeYAxisLabelScale(Graphics g, int height, float X_AXIS_LEGEND_HEIGHT, int topHeaderHeight, double maxFlux, TangraConfig.SpectraViewDisplaySettings displaySetting, out double interval, out double minorTickInterval, out string labelFormat)
        {
            float verticalSpace = height - 2 * PADDING - X_AXIS_LEGEND_HEIGHT - topHeaderHeight;

            var probeIntervals = new List <decimal>();
            var minorTicks     = new List <decimal>();

            if (PlotContext.ObservedFlux)
            {
                int maxPower = (int)Math.Ceiling(Math.Log10(maxFlux));

                for (int i = 0; i <= maxPower; i++)
                {
                    int factor = (int)Math.Round(Math.Pow(10, i));
                    probeIntervals.Add(1 * factor);
                    probeIntervals.Add(2 * factor);
                    probeIntervals.Add(5 * factor);

                    int factorMinorTick = (int)Math.Round(Math.Pow(10, i - 1));
                    minorTicks.Add(2 * factorMinorTick);
                    minorTicks.Add(5 * factorMinorTick);
                    minorTicks.Add(10 * factorMinorTick);
                }
                labelFormat = "";
            }
            else
            {
                probeIntervals.AddRange(new[] { 2E-16M, 5E-16M, 1E-15M, 2E-15M, 5E-15M, 5E-14M, 2E-14M, 5E-14M, 1E-13M, 2E-13M, 5E-13M, 1E-12M, 2E-12M, 5E-12M, 1E-11M });
                minorTicks.AddRange(new decimal[] { 1E-15M, 2E-15M, 5E-15M, 1E-14M, 2E-14M, 5E-14M, 1E-13M, 2E-13M, 5E-13M, 1E-12M, 2E-12M, 5E-12M, 1E-11M, 2E-11M, 5E-11M });
                labelFormat = "E1";
            }

            SizeF size = g.MeasureString("1234", displaySetting.LegendFont);

            interval          = 0;
            minorTickInterval = 0;

            for (int i = 0; i < probeIntervals.Count; i++)
            {
                interval          = (double)probeIntervals[i];
                minorTickInterval = (double)minorTicks[i];
                int numTicks = (int)Math.Ceiling(maxFlux / interval);
                if (size.Height * 3f * numTicks < verticalSpace)
                {
                    break;
                }
            }
        }
Beispiel #15
0
        internal void PlotCalibration(Graphics g, int width, int height, int topHeaderHeight, TangraConfig.SpectraViewDisplaySettings displaySetting)
        {
            List <AbsFluxSpectra> plotObjects = m_SpectraList.Where(x => x.IsComplete && x.PlotSpectra).ToList();

            double maxFlux = double.MinValue;

            Func <int, List <double> > fluxFunc;
            Func <int, List <double> > fluxResidualFunc;

            if (PlotContext.ObservedFlux)
            {
                fluxFunc         = x => plotObjects[x].ObservedFluxes;
                fluxResidualFunc = x => plotObjects[x].Residuals;
            }
            else
            {
                fluxFunc         = x => plotObjects[x].AbsoluteFluxes;
                fluxResidualFunc = x => plotObjects[x].Residuals;
            }

            for (int j = 0; j < plotObjects.Count; j++)
            {
                double max = fluxFunc(j).Max();
                if (plotObjects[j].IsStandard && plotObjects[j].AverageBiasPercentage < 0)
                {
                    max = max * (1 + Math.Abs(plotObjects[j].AverageBiasPercentage));
                }
                else if (plotObjects[j].IsStandard && plotObjects[j].AverageBiasPercentage > 0)
                {
                    max = max * (1 + Math.Abs(plotObjects[j].AverageBiasPercentage));
                }

                if (max > maxFlux)
                {
                    maxFlux = max;
                }
            }

            SizeF size = g.MeasureString("1234", displaySetting.LegendFont);

            float X_AXIS_LEGEND_HEIGHT = size.Height * 1.5f;

            double yInterval;
            double yMinorTickInterval;
            string labelFormat;

            ComputeYAxisLabelScale(g, height, X_AXIS_LEGEND_HEIGHT, topHeaderHeight, maxFlux, displaySetting, out yInterval, out yMinorTickInterval, out labelFormat);
            size = g.MeasureString(((int)maxFlux).ToString(labelFormat), displaySetting.LegendFont);

            float Y_AXIS_LEGEND_WIDTH = size.Width * 1.5f;

            // Scale
            float scaleY = (float)((height - topHeaderHeight - 2 * PADDING - X_AXIS_LEGEND_HEIGHT - LONG_MARK) / maxFlux);
            float scaleX = ((width - 2 * PADDING - Y_AXIS_LEGEND_WIDTH) * 1.0f / (Context.ToWavelength - Context.FromWavelength));


            g.DrawRectangle(displaySetting.GridLinesPen,
                            PADDING + Y_AXIS_LEGEND_WIDTH,
                            PADDING + topHeaderHeight,
                            width - 2 * PADDING - Y_AXIS_LEGEND_WIDTH,
                            height - topHeaderHeight - 2 * PADDING - X_AXIS_LEGEND_HEIGHT);

            PointF prevPoint;
            PointF prevPointO;

            for (int j = 0; j < plotObjects.Count; j++)
            {
                prevPoint  = PointF.Empty;
                prevPointO = PointF.Empty;

                int objIndex   = plotObjects[j].Number - 1;
                Pen absFluxPen = objIndex >= 0 && objIndex < displaySetting.AbsFluxPen.Length
                                        ? displaySetting.AbsFluxPen[objIndex]
                                        : displaySetting.AbsFluxPenDefault;

                Pen absFluxObsPen = objIndex >= 0 && objIndex < displaySetting.AbsFluxObsPen.Length
                                        ? displaySetting.AbsFluxObsPen[objIndex]
                                        : displaySetting.AbsFluxObsPenDefault;

                for (int i = 0; i < fluxFunc(j).Count; i++)
                {
                    double flux       = fluxFunc(j)[i];
                    double wavelength = plotObjects[j].ResolvedWavelengths[i];

                    if (wavelength >= Context.FromWavelength && wavelength <= Context.ToWavelength && !double.IsNaN(flux))
                    {
                        float x = (float)(PADDING + Y_AXIS_LEGEND_WIDTH + (wavelength - Context.FromWavelength) * scaleX);
                        float y = (float)(height - PADDING - X_AXIS_LEGEND_HEIGHT - flux * scaleY);

                        var thisPoint = new PointF(x, y);

                        if (prevPoint != Point.Empty)
                        {
                            g.DrawLine(absFluxPen, prevPoint, thisPoint);
                        }

                        prevPoint = thisPoint;

                        if (plotObjects[j].IsStandard)
                        {
                            double fluxObs = fluxFunc(j)[i] - fluxResidualFunc(j)[i];

                            if (!double.IsNaN(fluxObs))
                            {
                                float yO         = (float)(height - PADDING - X_AXIS_LEGEND_HEIGHT - fluxObs * scaleY);
                                var   thisPointO = new PointF(x, yO);
                                if (prevPointO != Point.Empty)
                                {
                                    g.DrawLine(absFluxObsPen, prevPointO, thisPointO);
                                }
                                prevPointO = thisPointO;
                            }
                        }
                    }
                }
            }

            DrawXAxis(g, scaleX, width, Y_AXIS_LEGEND_WIDTH, height - X_AXIS_LEGEND_HEIGHT - PADDING, PADDING + topHeaderHeight, displaySetting);
            DrawYAxis(g, scaleY, height, X_AXIS_LEGEND_HEIGHT, PADDING + Y_AXIS_LEGEND_WIDTH, width - PADDING, maxFlux, yInterval, yMinorTickInterval, labelFormat, displaySetting);
        }
Beispiel #16
0
        private void DrawAxis(PictureBox picSpectraGraph, Graphics g, RectangleF calibratedGraphArea, TangraConfig.SpectraViewDisplaySettings displaySettings)
        {
            g.DrawRectangle(displaySettings.GridLinesPen, calibratedGraphArea.Left, calibratedGraphArea.Top, calibratedGraphArea.Width, calibratedGraphArea.Height);
            g.DrawRectangle(displaySettings.GridLinesPen, calibratedGraphArea.Left, m_View.Height - 10, calibratedGraphArea.Width, m_View.Height);

            SpectraCalibrator calibrator = m_SpectroscopyController.GetSpectraCalibrator();

            DrawXAxisMarks(g, calibratedGraphArea, calibrator, displaySettings);
            DrawYAxisMarks(g, calibratedGraphArea, picSpectraGraph, displaySettings);
        }
        public void EnsureViewSpectraForm(TangraConfig.SpectraViewDisplaySettings displaySettings)
        {
            EnsureViewSpectraFormClosed();

            m_ViewSpectraForm = new frmViewSpectra(this, m_VideoController, displaySettings);
        }
Beispiel #18
0
        private void DrawYAxisMarks(Graphics g, RectangleF calibratedGraphArea, PictureBox picSpectraGraph, TangraConfig.SpectraViewDisplaySettings displaySettings)
        {
            float maxDisplayedValue = (calibratedGraphArea.Height - BORDER_GAP) / m_YCoeffCalibrated;
            SizeF yLabelSize        = g.MeasureString("9000xx", displaySettings.LegendFont);

            int[] probeIntervals = new[] { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000, 250000, 500000 };

            int probeInt = 100;

            for (int i = 0; i < probeIntervals.Length; i++)
            {
                probeInt = probeIntervals[i];
                float ticks = maxDisplayedValue / probeInt;
                if (ticks > 5 && ticks < 15)
                {
                    break;
                }
            }

            float currYTickPos   = 0;
            int   currYTickValue = 0;

            do
            {
                currYTickPos = picSpectraGraph.Image.Height - BORDER_GAP - m_YCoeffCalibrated * currYTickValue - Y_AXIS_WIDTH;
                string labelCaption = currYTickValue.ToString();
                yLabelSize = g.MeasureString(labelCaption, displaySettings.LegendFont);
                g.DrawLine(displaySettings.GridLinesPen, X_AXIS_WIDTH, currYTickPos, X_AXIS_WIDTH - 6, currYTickPos);
                g.DrawString(labelCaption, displaySettings.LegendFont, displaySettings.LegendBrush, X_AXIS_WIDTH - 12 - yLabelSize.Width, currYTickPos - yLabelSize.Height / 2);
                currYTickValue += probeInt;
            }while (currYTickPos > BORDER_GAP && currYTickValue < maxDisplayedValue);
        }
Beispiel #19
0
        private void DrawXAxisMarks(Graphics g, RectangleF calibratedGraphArea, SpectraCalibrator calibrator, TangraConfig.SpectraViewDisplaySettings displaySettings)
        {
            // Draw X axis marks, from 0, every 250 A with a label every 1000 A/2000 A
            int   pixel0        = calibrator.ResolvePixelNo(0);
            int   pixel1000     = calibrator.ResolvePixelNo(1000);
            float mousePosX0    = GetMouseXFromSpectraPixel(pixel0);
            float mousePosX1000 = GetMouseXFromSpectraPixel(pixel1000);
            float scalePer1000  = (mousePosX1000 - mousePosX0);
            SizeF xLabelSize    = g.MeasureString("9000xx", displaySettings.LegendFont);

            int labelIncrement = 1000;

            if (xLabelSize.Width < scalePer1000 / 4)
            {
                labelIncrement = 250;
            }
            else if (xLabelSize.Width < scalePer1000 / 2)
            {
                labelIncrement = 500;
            }
            else if (xLabelSize.Width >= scalePer1000 / 2 && xLabelSize.Width < scalePer1000)
            {
                labelIncrement = 1000;
            }
            else if (xLabelSize.Width >= scalePer1000 && xLabelSize.Width < 2 * scalePer1000)
            {
                labelIncrement = 2000;
            }

            float maxWaveLengthInSeries = m_MasterSpectra.Points[m_MasterSpectra.Points.Count - 1].Wavelength;
            int   currWaveLength        = 0;
            float currXTickPos          = GetMouseXFromSpectraPixel(calibrator.ResolvePixelNo(currWaveLength));

            do
            {
                int tickSize = currWaveLength % 1000 == 0 ? 6 : 3;
                g.DrawLine(displaySettings.GridLinesPen, currXTickPos, m_View.Height - 10, currXTickPos, m_View.Height - 10 - tickSize);
                g.DrawLine(displaySettings.GridLinesPen, currXTickPos, YMax, currXTickPos, YMax + tickSize);

                if (currWaveLength % labelIncrement == 0)
                {
                    string labelText = currWaveLength.ToString(CultureInfo.CurrentCulture);
                    xLabelSize = g.MeasureString(labelText, displaySettings.LegendFont);
                    g.DrawString(labelText, displaySettings.LegendFont, displaySettings.LegendBrush, currXTickPos - (xLabelSize.Width / 2f), m_View.Height - 35);
                }

                currWaveLength += 250;
                currXTickPos    = GetMouseXFromSpectraPixel(calibrator.ResolvePixelNo(currWaveLength));
            }while (currXTickPos < calibratedGraphArea.Width + X_AXIS_WIDTH && currWaveLength < maxWaveLengthInSeries + 1);
        }
        internal void DisplaySpectra(MasterSpectra masterSpectra, TangraConfig.PersistedConfiguration configuration, TangraConfig.SpectraViewDisplaySettings displaySettings, string fileName = null)
        {
            EnsureViewSpectraForm(displaySettings);

            m_CurrentSpectra    = masterSpectra;
            m_Configuration     = configuration;
            m_SpectraCalibrator = new SpectraCalibrator(masterSpectra);

            m_ViewSpectraForm.SetMasterSpectra(masterSpectra, fileName);
            m_ViewSpectraForm.StartPosition = FormStartPosition.CenterParent;
            m_ViewSpectraForm.Show(m_MainFormView);
        }
Beispiel #21
0
        public void DrawSpectra(PictureBox picSpectra, PictureBox picSpectraGraph, bool drawPixels, TangraConfig.SpectraViewDisplaySettings displaySettings)
        {
            PointF prevPoint    = PointF.Empty;
            bool   isCalibrated = m_SpectroscopyController.IsCalibrated();
            int    xAxisOffset  = isCalibrated ? X_AXIS_WIDTH : 0;
            int    yAxisOffset  = isCalibrated ? Y_AXIS_WIDTH : 0;
            float  xCoeff       = isCalibrated ? m_XCoeffCalibrated : m_XCoeff;
            float  yCoeff       = isCalibrated ? m_YCoeffCalibrated : m_YCoeff;

            int   pixelArrWidth  = m_MasterSpectra.Pixels.GetLength(0);
            int   pixelArrHeight = m_MasterSpectra.Pixels.GetLength(1);
            float xCoeffPixels   = picSpectra.Image.Width * 1f / pixelArrWidth;
            float yCoeffPixels   = picSpectra.Image.Height * 1f / pixelArrHeight;

            using (Graphics g = Graphics.FromImage(picSpectra.Image))
                using (Graphics g2 = Graphics.FromImage(picSpectraGraph.Image))
                {
                    g2.Clear(displaySettings.PlotBackgroundColor);

                    if (m_CurrentState != null)
                    {
                        m_CurrentState.PreDraw(g2);
                    }

                    if (m_ShowCommonLines && isCalibrated)
                    {
                        ShowCommonLines(g2, displaySettings);
                    }

                    #region Clear both ends of the stipes spectra
                    float xStripsBeg = xAxisOffset + xCoeff * (m_MasterSpectra.Points[0].PixelNo - m_XOffset) - 1;
                    float xStripsEnd = xAxisOffset + xCoeff * (m_MasterSpectra.Points[m_MasterSpectra.Points.Count - 1].PixelNo - m_XOffset) + 1;
                    if (xStripsBeg > 0)
                    {
                        g.FillRectangle(displaySettings.GreyBrushes[0], 0, 0, xStripsBeg, picSpectra.Height);
                    }
                    if (xStripsEnd < picSpectra.Width)
                    {
                        g.FillRectangle(displaySettings.GreyBrushes[0], xStripsBeg, 0, picSpectra.Width - xStripsBeg, picSpectra.Height);
                    }
                    #endregion

                    RectangleF calibratedGraphArea = new RectangleF(X_AXIS_WIDTH, BORDER_GAP, m_View.Width - X_AXIS_WIDTH - BORDER_GAP, m_View.Height - Y_AXIS_WIDTH - BORDER_GAP);

                    for (int i = 0; i < m_MasterSpectra.Points.Count; i++)
                    {
                        SpectraPoint point = m_MasterSpectra.Points[i];

                        byte  clr = (byte)(Math.Max(0, Math.Min(255, Math.Round(point.ProcessedValue * m_ColorCoeff))));
                        float x   = xAxisOffset + xCoeff * (point.PixelNo - m_XOffset);
                        if (x >= 0)
                        {
                            if (drawPixels)
                            {
                                for (int y = 0; y < pixelArrHeight; y++)
                                {
                                    byte  pixClr = (byte)(Math.Max(0, Math.Min(255, Math.Round(m_MasterSpectra.Pixels[i, y] * m_ColorCoeff))));
                                    float xx     = xAxisOffset + i * xCoeffPixels;
                                    float yy     = y * yCoeffPixels;
                                    g.FillRectangle(displaySettings.GreyBrushes[pixClr], xx, yy, 1, 1);
                                }
                            }
                            else
                            {
                                g.FillRectangle(displaySettings.GreyBrushes[clr], x, 0, xCoeff, picSpectra.Height);
                            }

                            PointF graphPoint = new PointF(x, picSpectraGraph.Image.Height - BORDER_GAP - (float)Math.Round(point.ProcessedValue * yCoeff) - yAxisOffset);
                            if (prevPoint != PointF.Empty)
                            {
                                if (!isCalibrated || (prevPoint.X > calibratedGraphArea.Left && prevPoint.X < calibratedGraphArea.Right && graphPoint.X > calibratedGraphArea.Left && graphPoint.X < calibratedGraphArea.Right))
                                {
                                    g2.DrawLine(displaySettings.SpectraPen, prevPoint, graphPoint);
                                }
                            }
                            prevPoint = graphPoint;
                        }
                    }

                    g2.FillRectangle(SystemBrushes.ControlDark, X_AXIS_WIDTH, 0, m_View.Width - X_AXIS_WIDTH - BORDER_GAP + 1, BORDER_GAP);

                    if (m_CurrentState != null)
                    {
                        m_CurrentState.PostDraw(g2);
                    }

                    if (isCalibrated)
                    {
                        DrawAxis(picSpectraGraph, g2, calibratedGraphArea, displaySettings);
                    }

                    g.Save();
                    g2.Save();
                }

            picSpectra.Invalidate();
            picSpectraGraph.Invalidate();
        }