private void PlotPanel(PaintEventArgs e, LensRayTransferFunction.VariableParameter shownParam) { base.OnPaint(e); Graphics g = e.Graphics; // scale drawing area to [0; sampleCount-1] x [0; 1] g.ScaleTransform(e.ClipRectangle.Width / (float)sampleCount, -e.ClipRectangle.Height); g.TranslateTransform(0, -1); g.Clear(Color.White); var values = SelectRayParameterDimension(outgoingRays, shownParam).ToList(); double?lastValue = null; Pen linePen = new Pen(Color.Black, 40 / (float)e.ClipRectangle.Height); for (int i = 0; i < values.Count; i++) { var value = values[i]; if (value.HasValue) { g.FillRectangle(Brushes.LightBlue, i, 0, 1, (float)value.Value); } else { g.FillRectangle(Brushes.LightSalmon, i, 0, 1, 1); } if ((lastValue != null) && (value != null)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawLine(linePen, i - 0.5f, (float)lastValue.Value, i + 0.5f, (float)value.Value); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; } lastValue = value; } }
/// <summary> /// Create a one-dimensional list of value of particular dimension /// from the list with all dimensions. Eg. select only list of /// direction phi's. /// </summary> /// <param name="rays"></param> /// <param name="?"></param> /// <returns></returns> private IEnumerable <double?> SelectRayParameterDimension( IList <LensRayTransferFunction.Parameters> rays, LensRayTransferFunction.VariableParameter dimension) { return(rays.Select((ray) => (ray != null) ? (double?)ray[dimension] : null)); }