internal bool ScaleSpectraByZeroOrderImagePosition() { if (m_CurrentSpectra != null && m_Configuration != null && m_Configuration.IsCalibrated) { m_SpectraCalibrator = new SpectraCalibrator(m_CurrentSpectra); return(m_SpectraCalibrator.LoadCalibration(m_Configuration)); } return(false); }
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); }
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); }
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 string ExportToDat(MasterSpectra spectra) { SpectraCalibrator calibrator = GetSpectraCalibrator(); var bld = new StringBuilder(); AddDatExportHeader(bld, spectra); foreach (SpectraPoint point in spectra.Points) { float wavelength = calibrator.ResolveWavelength(point.PixelNo); if (wavelength < 0) { continue; } bld.AppendFormat("{0}\t{1}\r\n", wavelength, point.RawValue); } return(bld.ToString()); }
internal void SetMasterSpectra(MasterSpectra masterSpectra, string fileName) { m_Spectra = masterSpectra; m_StateManager.SetMasterSpectra(masterSpectra); hsbSlidingWindow.Minimum = 0; hsbSlidingWindow.Maximum = Math.Max(1, m_Spectra.RawMeasurements.Count - 50); hsbSlidingWindow.Value = 0; if (masterSpectra.ProcessingInfo.GaussianBlur10Fwhm.HasValue) { m_StateManager.ApplyGaussianBlur(masterSpectra.ProcessingInfo.GaussianBlur10Fwhm.Value / 10.0f); } if (masterSpectra.IsCalibrated()) { SpectraCalibrator calibrator = m_SpectroscopyController.GetSpectraCalibrator(); calibrator.Reset(); if (calibrator.LoadCalibration(masterSpectra.Calibration)) { m_StateManager.ChangeState <SpectraViewerStateCalibrated>(); } } else if (m_SpectroscopyController.HasCalibratedConfiguration()) { if (m_SpectroscopyController.ScaleSpectraByZeroOrderImagePosition()) { m_StateManager.ChangeState <SpectraViewerStateCalibrated>(); } } if (fileName != null) { Text = string.Format("Spectra Viewer - {0}", Path.GetFileName(fileName)); } else { Text = "Spectra Viewer"; } }
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); } }
internal bool ScaleSpectraByZeroOrderImagePosition() { if (m_CurrentSpectra != null && m_Configuration != null && m_Configuration.IsCalibrated) { m_SpectraCalibrator = new SpectraCalibrator(m_CurrentSpectra); return m_SpectraCalibrator.LoadCalibration(m_Configuration); } return false; }