private PixelColumn[] SignalToPixelConverter(Plottables.Signal signal, Settings settings) { PixelColumn[] pxCols = new PixelColumn[settings.dataPlotWidth]; // theoretical minimum pixel if X1 were drawn int dataMinPx = (int)(settings.axisX.pxPerUnit * (-settings.axisX.x1)); // step column by column left to right for (int i = 0; i < settings.dataPlotWidth; i++) { // determine what index values of the signal correspond to this pixel column int iLeft = (int)(settings.axisX.unitsPerPx * signal.sampleRateHz * (i - dataMinPx)); int iRight = (int)(iLeft + settings.axisX.unitsPerPx * signal.sampleRateHz); // ensure indexes are valid and skip columns without data iLeft = Math.Max(iLeft, 0); iRight = Math.Min(signal.ys.Length - 1, iRight); iRight = Math.Max(iRight, 0); if (iRight == 0) { continue; } if (iRight < 0 || iLeft > iRight) { continue; } // pull iLeft of this column to the same iRight as the last if (i > 0 && pxCols[i - 1] != null) { iLeft = pxCols[i - 1].iRight - 1; } // determine vertical span of this range double valMin = ArraySubMin(signal.ys, iLeft, iRight); double valMax = ArraySubMax(signal.ys, iLeft, iRight); // TODO: make indexes perfect - they don't always match-up exactly //Console.WriteLine($"Index [{iLeft}:{iRight}] min/max = {valMin}/{valMax}"); // convert this value to a pixel location on screen int pxMin = (int)((settings.axisY.x2 - valMin) * settings.axisY.pxPerUnit) + 1; int pxMax = (int)((settings.axisY.x2 - valMax) * settings.axisY.pxPerUnit) + 1; // populate the object pxCols[i] = new PixelColumn(pxMin, pxMax, iLeft, iRight); } return(pxCols); }
public void EstimateBiasedMillimeterDistances() { if (MillimeterColumnOMM == null) { throw new InvalidOperationException("MillimeterColumnOMM can not be null when calling CalculateWeight"); } if (PixelColumn == null) { throw new InvalidOperationException("PixelColumn can not be null when calling CalculateWeight"); } var millimeterDistancesUnbiased = PixelColumn.Times(Weight); OMMvsEstimateDiff = new DataColumn("Diff", MillimeterColumnOMM.Subtract(millimeterDistancesUnbiased)); Bias = OMMvsEstimateDiff.Average(); MillimeterColumnEstimate = new DataColumn("MillimeterColumnEstimate", millimeterDistancesUnbiased.Select(dist => dist + Bias)); }
public void ListTesting() { try { List <int> dimensions = ReturnDimensions(); Stopwatch sw = new Stopwatch(); BitmapWrapper bm1 = new BitmapWrapper(@"F:\temp\analysis\640x480\test_0.jpg"); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"f:\temp\runtime\listanalysis.txt", true)) { for (int i = 0; i < dimensions.Count; i++) { for (int n = 0; n < 200; n++) { //Array sw.Restart(); PixelColumnArray[] array = new PixelColumnArray[bm1.bitmap.Width]; for (int w = 0; w < bm1.bitmap.Width; w++) { array[w] = new PixelColumnArray(); array[w].Cells = new PixelCellArray[bm1.bitmap.Height]; for (int h = 0; h < bm1.bitmap.Height; h++) { array[w].Cells[h] = new PixelCellArray(); array[w].Cells[h].colour = 11111; } } sw.Stop(); file.WriteLine(i + " - " + n + " - " + " array - " + sw.Elapsed.TotalMilliseconds); //List sw.Restart(); List <PixelColumn> list = new List <PixelColumn>(); for (int w = 0; w < bm1.bitmap.Width; w++) { PixelColumn column = new PixelColumn(); for (int h = 0; h < bm1.bitmap.Height; h++) { PixelCell cell = new PixelCell(); cell.colour = 11111; column.Cells.Add(cell); } list.Add(column); } sw.Stop(); file.WriteLine(i + " - " + n + " - " + " list - " + sw.Elapsed.TotalMilliseconds); } //test iterations } //dimensions } //write to file Assert.IsTrue(true); } catch { Assert.IsTrue(false); } }