public static SpectralPoint[] ToSpectralPoints(ExperimentEntityDataViewModel data, double[] wavelengthArray) { var spectralPointArray = new SpectralPoint[wavelengthArray.Length]; for (int i = 0; i < wavelengthArray.Length; i++) { spectralPointArray[i] = new SpectralPoint { WaveLength = wavelengthArray[i], DistancedSignal = new Dictionary <double, double>() }; } foreach (var dataItem in data.DataItems.Where(x => x.Distance > 0)) { alglib.spline1dinterpolant s; alglib.spline1dbuildlinear(data.WaveLengthArray, dataItem.IntensityArray, out s); for (int i = 0; i < wavelengthArray.Length; i++) { if (!spectralPointArray[i].DistancedSignal.ContainsKey(dataItem.Distance)) { var value = alglib.spline1dcalc(s, spectralPointArray[i].WaveLength); spectralPointArray[i].DistancedSignal.Add(dataItem.Distance, value); } } } return(spectralPointArray); }
public void TestConstructor() { var point = new SpectralPoint( 0.23.AsIntervalFromZero(), 43.0.AsIntervalFromZero(), 0.5); Assert.AreEqual((0, 0.23), point.Seconds); Assert.AreEqual((0, 43.0), point.Hertz); Assert.AreEqual(0.5, point.Value); }
public void TestEquality() { var a = new SpectralPoint( 0.23.AsIntervalFromZero(), 43.0.AsIntervalFromZero(), 0.5); var b = new SpectralPoint( 0.23.AsIntervalFromZero(), 43.0.AsIntervalFromZero(), 0.5); Assert.IsTrue(a.Equals(b)); }
public void TestToString() { Interval <double> seconds = (1, 5); Interval <double> hertz = (5000, 6000); var test = new SpectralPoint( seconds, hertz, 3); var actual = test.ToString(); Assert.AreEqual( $"SpectralPoint: [1, 5) s, [5000, 6000) Hz, 3 value", actual); }
public void TestHashCode() { var a = new SpectralPoint( 0.23.AsIntervalFromZero(), 43.0.AsIntervalFromZero(), 0.5); var b = new SpectralPoint( 0.23.AsIntervalFromZero(), 43.0.AsIntervalFromZero(), 0.5); var c = new SpectralPoint( 0.231.AsIntervalFromZero(), 43.0.AsIntervalFromZero(), 0.5); Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); Assert.AreNotEqual(a.GetHashCode(), c.GetHashCode()); }
private int AddHelperSpectralPoint(SpectralPoint sp, bool insertIfEqual) { int idx = points.BinarySearch(sp); if (idx < 0) { idx = ~idx; if (idx == points.Count) { points.Add(sp); idx = points.Count - 1; } else points.Insert(idx, sp); } else if (insertIfEqual) points.Insert(idx, sp); return idx; }
public void SetSpectralPoint(SpectralPoint before, SpectralPoint after) { int idxAfter = points.BinarySearch(after); if (idxAfter > -1) { SetSpectralPoint(idxAfter, before); } }
public void SetSpectralPoint(int idx, SpectralPoint sp) { SetSpectralPoint(idx, sp.Lambda, sp.Intensity); }
public void SetSpectralPoint(int idx, double lambda_, double intensity_) { if (Helper.InRange(idx, 0, points.Count - 1)) { SpectralPoint sp_new = new SpectralPoint(lambda_, intensity_); if (idx == lastModifiedIdx) { undo.SetAfter(sp_new); } else { undo = new SpectrumUndo(EAction.Moved, points[idx], sp_new); } //reuse it as a flag.... lastModifiedIdx = -1; //if it's still fits in the same point interval - exchange it if ((idx > 0) && (idx < points.Count - 1)) { int check = CheckInBetween(points[idx - 1], sp_new, points[idx + 1]); if (check == 0) { lastModifiedIdx = idx; points[idx] = sp_new; } } //if not - remove + binary search if (lastModifiedIdx == -1) { points.RemoveAt(idx); lastModifiedIdx = AddHelperSpectralPoint(sp_new, true); } CallSpectrumChanged(); } }
public void DeleteSpectralPoint(SpectralPoint sp) { int idx = points.BinarySearch(sp); if (idx > -1) { DeleteSpectralPoint(idx); } }
public int AddSpectralPoint(SpectralPoint sp) { int idx = AddHelperSpectralPoint(sp, false); CallSpectrumChanged(); undo = new SpectrumUndo(EAction.Added, null, sp); lastModifiedIdx = -1; return idx; }
private Point ConvertSpectrumPoint(SpectralPoint sp) { double width = ClientSize.Width - 2; double height = ClientSize.Height - 2; double minLambda = spectrum.LambdaMin; double maxLambda = spectrum.LambdaMax; double scale = (maxLambda - minLambda) / width; return new Point((int)Math.Round((sp.Lambda - minLambda) / scale), (int)((1 - sp.Intensity) * height)); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); Point p = new Point(e.X, e.Y); if ((interactionMode > EInteractionModes.None) && (interactionMode < EInteractionModes.Add)) idxSpectralPoint = GetSpectralPointUnderCursor(p); if (interactionMode == EInteractionModes.Add) { spNew = PointToSpectralPoint(p); idxSpectralPoint = spectrum.AddSpectralPoint(spNew); spNew = null; Invalidate(); } if (idxSpectralPoint > -1) spOriginal = spectrum.Points[idxSpectralPoint]; if (interactionMode != EInteractionModes.None) if (OnSpectrumBeginChange != null) OnSpectrumBeginChange(); }
public SpectrumUndo(EAction act, SpectralPoint before, SpectralPoint after) { action = act; actionBefore = (before == null) ? null : new SpectralPoint(before); actionAfter = (after == null) ? null : new SpectralPoint(after); }
public void SetAfter(SpectralPoint after) { actionAfter = (after == null) ? null : new SpectralPoint(after); }
private Rectangle SpectralPointToRectangle(SpectralPoint sp) { Point p = ConvertSpectrumPoint(sp); return new Rectangle(p.X - sizePointHalf, p.Y - sizePointHalf, sizePoint, sizePoint); }
private SpectralPoint PointToSpectralPoint(Point p) { SpectralPoint sp = new SpectralPoint(); double width = ClientSize.Width - 2; double height = ClientSize.Height - 2; double minLambda = spectrum.LambdaMin; double maxLambda = spectrum.LambdaMax; double scale = (maxLambda - minLambda) / width; sp.Lambda = p.X * scale + minLambda; sp.Intensity = 1 - (p.Y / height); return sp; }
private int CheckInBetween(SpectralPoint low, SpectralPoint check, SpectralPoint high) { int lowCompare = check.CompareTo(low); if (lowCompare == check.CompareTo(high)) return lowCompare; else return 0; }
private double Interpolate(double lambda, SpectralPoint a, SpectralPoint b) { double x = (lambda - a.Lambda); return a.Intensity + x * (b.Intensity - a.Intensity) / (b.Lambda - a.Lambda); }
protected override void OnMouseMove(MouseEventArgs e) { if (spectrum != null) { Point p = new Point(e.X, e.Y); spNew = PointToSpectralPoint(p); if (showMouseCrosshair) { pointCursor = p; } switch (interactionMode) { case EInteractionModes.Intesity: if (idxSpectralPoint > -1) { spectrum.SetSpectralPointIntensity(idxSpectralPoint, spNew.Intensity); spNew = null; idxSpectralPoint = spectrum.LastModifiedIndex; } break; case EInteractionModes.Lambda: if (idxSpectralPoint > -1) { spectrum.SetSpectralPointLambda(idxSpectralPoint, spNew.Lambda); spNew = null; idxSpectralPoint = spectrum.LastModifiedIndex; } break; case EInteractionModes.IntensityLambda: if (idxSpectralPoint > -1) { spectrum.SetSpectralPoint(idxSpectralPoint, spNew); idxSpectralPoint = spectrum.LastModifiedIndex; spNew = null; } break; case EInteractionModes.Add: case EInteractionModes.Delete: case EInteractionModes.None: default: break; } if (interactionMode != EInteractionModes.None) if (OnSpectrumChanging != null) OnSpectrumChanging(); if ((showMouseCrosshair) || (interactionMode != EInteractionModes.None)) Invalidate(); } }